Sub Globals
Dim bgd As Panel : Dim G As Gestures
Dim Label1 As Label : Dim TouchMap As Map
Type Point(Id As Int, prevX As Int, prevY As Int)
Dim Canvas As Canvas : Dim RowHeight As Int
Dim TextSize As Float: TextSize = 18
Dim TextRect As Rect
'--------- new ---------'
Dim BrushSize As Int
Dim BrushX As Int
Dim BrushY As Int
Dim MinInterFingerDist As Int
Dim BrushDistance As Int
End Sub
Sub Activity_Create(FirstTime As Boolean)
bgd.Initialize("")'Create a panel and add it to the activity
Activity.AddView(bgd, 0, 0, 100%x, 100%y)
Canvas.Initialize(bgd)
G.SetOnTouchListener(bgd, "GesturesTouch")'Add a listener for this panel
TouchMap.Initialize
RowHeight = Canvas.MeasureStringHeight("M", Typeface.DEFAULT, TextSize) + 5dip
TextRect.Initialize(0, 0, 120dip, 20dip + RowHeight * 10)
Activity.AddMenuItem("Clear", "mnuClear")
BrushSize=2 : MinInterFingerDist=60
End Sub
Sub mnuClear_Click
Dim r As Rect
r.Initialize(0, 0, 100%x, 100%y)
Canvas.DrawRect(r, Colors.Transparent, True, 0) 'erase everything
bgd.Invalidate
End Sub
Sub GesturesTouch(View As Object, PointerID As Int, Action As Int, X As Float, Y As Float) As Boolean
Dim p As Point
Dim px, py As Int
Dim s As String
Canvas.DrawRect(TextRect, Colors.Transparent, True, 0) 'Clear the previous text
Select Action
Case g.ACTION_DOWN,g.ACTION_POINTER_DOWN 'New Point is assigned to the new touch
p.Id = PointerID : TouchMap.Put(PointerID, p)
Case g.ACTION_POINTER_UP
TouchMap.Remove(PointerId)
Case g.ACTION_UP
TouchMap.Clear 'This is the end of this gesture
Case g.ACTION_MOVE
If Pointerid=1 Then
[COLOR="SeaGreen"]p = TouchMap.GetValueAt(1) : px = g.GetX(p.id) : py = g.GetY(p.id)
BrushDistance= Sqrt((pX-BrushX)*(pX-BrushX)+(pY-Brushy)*(pY-Brushy))
If BrushDistance<MinInterFingerDist Then
BrushSize=1
Else
BrushSize=(BrushDistance-MinInterFingerDist)/10
End If
s = p.Id & ": " & px & " x " & py & "//" & BrushDistance & " - " & BrushSize
Canvas.DrawText(s, 10dip, 20dip , Typeface.DEFAULT, TextSize, Colors.white, "LEFT")[/COLOR]
Else
[COLOR="Olive"]p = TouchMap.GetValueAt(0) : px = g.GetX(p.id) : py = g.GetY(p.id)
s = p.Id & ": " & px & " x " & py
Canvas.DrawText(s, 10dip, 20dip + RowHeight , Typeface.DEFAULT, TextSize, Colors.white, "LEFT")
If p.prevX > 0 AND p.prevY > 0 Then
Canvas.DrawLine(p.prevX, p.prevY, px, py, Colors.red, BrushSize)
End If
p.prevX = px : p.prevY = py
BrushX = px : BrushY = py[/COLOR]
End If
End Select
bgd.Invalidate
Return True
End Sub