'Events declarations
#Event: Click
#Event: LongClick
#Event: CheckedChange(Checked As Boolean)
#RaisesSynchronousEvents: Click
#RaisesSynchronousEvents: LongClick
#RaisesSynchronousEvents: CheckedChange
#DesignerProperty: Key: BooleanExample, DisplayName: Show Seconds, FieldType: Boolean, DefaultValue: True
#DesignerProperty: Key: TextColor, DisplayName: Text Color, FieldType: Color, DefaultValue: 0xFFFFFFFF, Description: Text color
#DesignerProperty: Key: ImageViewProperties, DisplayName: ImageView Properties, FieldType: Boolean, DefaultValue: True, Description: Test test
Sub Class_Globals
Private mEventName As String 'ignore
Private mCallBack As Object 'ignore
Public mBase As B4XView
Public mKnob As B4XView
'Type PositionData2 (PressedX As Int, PressedY As Int, Angle As Float )
Private xui As XUI 'ignore
Public Tag As Object
Private fx As JFX
Private mLeft, mTop, mWidth, mHeight As Int
Private mParent As B4XView
End Sub
Public Sub Initialize (Callback As Object, EventName As String)
mEventName = EventName
mCallBack = Callback
Log ("Initialize")
End Sub
'Base type must be Object
Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
'we use a Dummy obkect to get the Tag property and the Parent.
Private mDummy As B4XView
mDummy = Base
mLeft = mDummy.Left
mTop = mDummy.Top
mWidth = mDummy.Width
mHeight = mDummy.Height
Tag = mDummy.Tag
' mBackgroundColor = xui.PaintOrColorToColor(Props.Get("BackgroundColor"))
'we create a new mBase object to get the Touch event
mBase = xui.CreatePanel("mBase")
mParent = mDummy.Parent
mParent.AddView(mBase, mLeft, mTop, mWidth, mHeight)
mBase.Tag = Me
Dim pd As PositionData
pd.PressedX=0
pd.PressedY=0
pd.Angle=0
Dim imgv As ImageView
imgv.Initialize("imgv")
mBase.AddView(imgv,0,0,mWidth,mHeight)
mKnob = imgv
'mKnob.SetBitmap(xui.LoadBitmap(File.DirAssets, "chickenknob black.png"))
mKnob.SetBitmap(RotateBitmap(xui.LoadBitmap(File.DirAssets, "chickenknob black.png"), 0))
mKnob.Tag=pd
'we remove the mDumm / Base object, no more needed
mDummy.RemoveViewFromParent
Log ("DesignerCreateView")
InitClass
End Sub
Sub RotateBitmap (bmp As B4XBitmap, Degrees As Float) As B4XBitmap
Dim cvs As B4XCanvas
Dim panel As B4XView = xui.CreatePanel("")
panel.SetLayoutAnimated(0, 0, 0, bmp.Width, bmp.Height)
cvs.Initialize(panel)
cvs.DrawBitmapRotated(bmp, cvs.TargetRect, Degrees)
cvs.Invalidate
Dim b As B4XBitmap = cvs.CreateBitmap
cvs.Release
'Log("2: " & Degrees)
Return b
End Sub
Private Sub InitClass
End Sub
Private Sub mBase_Touch (Action As Int, X As Float, Y As Float)
Select Action
Case mBase.TOUCH_ACTION_DOWN
Log("Action DOWN")
'Dim view As B4XView = Sender
Dim pd As PositionData = mKnob.Tag
pd.PressedX = X
pd.PressedY = Y
mKnob.SetBitmap(RotateBitmap(xui.LoadBitmap(File.DirAssets, "chickenknob black.png"), pd.Angle Mod 360))
mKnob.Tag = pd
Log("PRESS: " & pd.Angle)
Case mBase.TOUCH_ACTION_UP
Log ("Action UP")
'Dim view As B4XView = Sender
Dim pd As PositionData = mKnob.Tag
pd.Angle= pd.Angle+(X-pd.PressedX) Mod 360
mKnob.Tag = pd
mKnob.SetBitmap(RotateBitmap(xui.LoadBitmap(File.DirAssets, "chickenknob black.png"), pd.Angle Mod 360))
Log("RELEA: " & pd.Angle)
Case mBase.TOUCH_ACTION_MOVE
Dim pd As PositionData = mKnob.Tag
Dim ParentX As Int = X
Dim ParentY As Int = Y
'pd.Angle=pd.Angle+(ParentX-pd.PressedX)
'Log("2: " & Value)
mKnob.SetBitmap(RotateBitmap(xui.LoadBitmap(File.DirAssets, "chickenknob black.png"), pd.Angle+(ParentX-pd.PressedX) Mod 360))
Log ("Action MOVE: X,Y =" & X & "," & Y )
End Select
End Sub
Private Sub Base_Resize (Width As Double, Height As Double)
End Sub