注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

沉默蜂B4A安卓编程

国内资料最全的B4A资料库

 
 
 

日志

 
 

连续旋钮(二)  

2015-09-30 12:15:11|  分类: B.图形 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
'类模块 Knob.bas
'Class module
#Event: AngleChanged (Delta As Int)
Sub Class_Globals
Private EventName As String
Private CallBack As Object
Private radius As Float
Private cvs As Canvas
Private bmp As Bitmap
Private startAngle As Float
Private currentAngle As Float
Private destRect As Rect
Private pnl As Panel
End Sub

Public Sub Initialize (vCallback As Object, vEventName As String)
EventName = vEventName
CallBack = vCallback
End Sub

Public Sub DesignerCreateView(base As Panel, lbl As Label, props As Map)
base.Width = Max(base.Width, base.Height)
base.Height = base.Width
pnl.Initialize("")
Dim r As Reflector
r.Target = pnl
r.SetOnTouchListener("pnl_Touch")
base.AddView(pnl, 0, 0, base.Width, base.Height)
radius = base.Width / 2
Dim bd As BitmapDrawable = base.Background
cvs.Initialize(base)
bmp = bd.Bitmap
destRect.Initialize(0, 0, radius * 2, radius * 2)
End Sub

Sub pnl_Touch  (viewtag As Object, action As Int, X As Float, Y As Float, motionevent As Object) As Boolean
If action = 0 Then 'ACTION_DOWN
startAngle = ATan2(X - radius, Y - radius)
Else If action = 2 Then 'ACTION_MOVE
Dim angle As Float = ATan2(X - radius, Y - radius)
currentAngle = currentAngle - angle + startAngle
Dim delta As Int = (startAngle - angle) * 180 / cPI
If delta > 180 Then 
delta = delta - 360
Else If delta < -180 Then
delta = delta + 360
End If
CallSubDelayed2(CallBack, EventName & "_AngleChanged", delta)
startAngle = angle
cvs.DrawBitmapRotated(bmp, Null, destRect, currentAngle * 180 / cPI)
pnl.Invalidate
End If
Return True
End Sub

  评论这张
 
阅读(94)| 评论(1)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017