Here is the first gestures program I wrote.. very crude.. it puts a label on the screen. You can touch anywhere on the screen and move your finger.. the label moves the same amount and direction you move your finger.
I would like to use gesture and modify toucho1. The app will have 5 buttons. How do I know which button has been selected and dragged.?
Thanks:sign0085:
Search the forums for "Sender".
Private Sub whichButton
innerView = Sender
btnIndex = innerView.Tag 'btnIndex is the x.y index of the button
For x = 0 To 2
For y = 0 To 2
If btnIndex.x = x AND btnIndex.y = y Then
Log(x & ":" & y)
End If
Next
Next
End Sub
Sub Initialize(Activity As Activity, v As View, Index As Indices)
innerView = v
innerView.Tag = Index
panel1.Initialize("")
panel1.Color = Colors.Transparent
Activity.AddView(panel1, v.Left, v.Top, v.Width, v.Height)
ACTION_DOWN = Activity.ACTION_DOWN
ACTION_MOVE = Activity.ACTION_MOVE
ACTION_UP = Activity.ACTION_UP
Dim r As Reflector
r.Target = panel1
r.SetOnTouchListener("Panel1_Touch") 'why reflection instead of the regular Panel_Touch event? Good question which deserves a forum thread of its own (not related to classes)...
End Sub
Sub Initialize(Activity As Activity, v As View, tag As Int, diceImg As Bitmap)
innerView = v
bMap = diceImg
bTag = tag
panel1.Initialize("")
panel1.Color = Colors.Transparent
Activity.AddView(panel1, v.Left, v.Top, v.Width, v.Height)
ACTION_DOWN = Activity.ACTION_DOWN
ACTION_MOVE = Activity.ACTION_MOVE
ACTION_UP = Activity.ACTION_UP
Dim r As Reflector
r.Target = panel1
r.SetOnTouchListener("Panel1_Touch") 'why reflection instead of the regular Panel_Touch event? Good question which deserves a forum thread of its own (not related to classes)...
End Sub
Private Sub Panel1_Touch (o As Object, ACTION As Int, x As Float, y As Float, motion As Object) As Boolean
If ACTION = ACTION_DOWN Then
downx = x
downy = y
Log("On click: " & bMap)
CallSub3(Me, "insertPanelImage", bTag, bMap)
Else
innerView.Left = innerView.Left + x - downx
innerView.Top = innerView.Top + y - downy
panel1.Left = innerView.Left
panel1.Top = innerView.Top
End If
Return True
End Sub
Sub insertPanelImage(btnTag As Int, btnMap As Bitmap)
Log("On insertPanelImage: " & btnMap)
CallSub3(Main, "updatePanelIcon", btnTag, btnMap)
CallSub2(Main, "ChangePanel", btnTag)
End Sub
Sub drawBtnDice
Dim i, j, x, y, rndDice(9) As Int
Dim bufferIcon() As Byte
Dim bmpIcon As Bitmap
For i = 0 To 8
rndDice(i) = i
Next
storyClass.ShuffleArray(rndDice)
Dim dv(9) As DraggableView
For y = 0 To 2
For x = 0 To 2
Dim b As Button
b.Initialize("") 'No event name added because draggable views event will not be raised
Activity.AddView(b,offsetX + x * (btnWidth + 15dip), offsetY + y * (btnWidth + 1dip), btnWidth, btnWidth)
btnDice(x, y) = b 'store a reference to this view
'We have 9 dices and each dice can have one of the six possible icons
rndNumber2 = Rnd(0, 6)
cursorStory = sqlStory.ExecQuery("SELECT * FROM story WHERE rowid=" & iconID(rndDice(j), rndNumber2))
cursorStory.Position = 0
bufferIcon = cursorStory.GetBlob("icon")
cursorStory.Close
Dim iconIS As InputStream
iconIS.InitializeFromBytesArray(bufferIcon, 0, bufferIcon.Length)
bmpIcon.Initialize2(iconIS)
iconIS.Close
'Initialize draggable view
dv(j).Initialize(Activity, b, j, bmpIcon)
'Initialize animation scale center
diceAnim(x, y).InitializeScaleCenter("", 0, 0, 1, 1, b)
'Set animation length
diceAnim(x, y).Duration = 500
diceAnim(x, y).start(btnDice(x, y))
'btnDice(x, y).Visible = True
btnDice(x, y).SetBackgroundImage(bmpIcon)
'Play sound
sndPPop(j) = SP.Play(sndLPop(j), 1, 1, 1, 0, 1)
storyClass.Wait(j)
j = j + 1
Next
Next
End Sub
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?