'Class module
Sub Class_Globals
Dim Gest As Gestures
Dim LNStart As Int
Dim Cnv As Canvas
Dim Rect, PnlRect As Rect
Dim CB As Bitmap
Dim IBH, IBW As Float
Dim LastX, LastY, LastLen As Float
Dim PnlColor As Long
Dim Act As Activity
Dim WasMulti As Boolean
End Sub
Public Sub Initialize(Bmp As Bitmap, Pnl As Panel, C As Int, A As Activity)
Dim bmpAsp As Float, pnlAsp As Float
CB = Bmp
PnlColor = C
Act = A
PnlRect.Initialize(Pnl.left, Pnl.Top,Pnl.Left + Pnl.Width, Pnl.Top + Pnl.Height)
Gest.SetOnTouchListener(Pnl, "pnl_gesture")
pnlAsp = Pnl.Width / Pnl.Height
bmpAsp = CB.Width / CB.Height
If bmpAsp >= pnlAsp Then
IBH = (Pnl.Width / bmpAsp)
IBW = Pnl.Width
Rect.Initialize(0, (Pnl.Height-IBH)/2, Pnl.Width, IBH + ((Pnl.Height-IBH)/2))
Else
IBH=Pnl.Height
IBW=(Pnl.Height * bmpAsp)
Rect.Initialize((Pnl.Width-IBW)/2, 0, IBW + ((Pnl.Width-IBW)/2), Pnl.Height)
End If
Cnv.Initialize(Pnl)
Cnv.DrawBitmap(CB, Null,Rect)
End Sub
Sub ResizeBmp(Amt As Float)
Cnv.DrawColor(PnlColor)
Act.Invalidate2(PnlRect)
Rect.Initialize(Rect.Left, Rect.Top,Rect.Left + (IBW * Amt), Rect.Top + (IBH * Amt))
Cnv.DrawBitmap(CB,Null,Rect)
Act.Invalidate2(Rect)
'Act.Invalidate
End Sub
Sub MoveBmp(L As Float, T As Float)
Cnv.DrawColor(PnlColor)
Act.Invalidate2(PnlRect)
Rect.Initialize(L, T, L + IBW, T + IBH)
Cnv.DrawBitmap(CB, Null, Rect)
Act.Invalidate2(Rect)
End Sub
Sub pnl_gesture(o As Object, ptrID As Int, action As Int, X As Float, y As Float) As Boolean
Dim LN As Int, X0,X1,Y0,Y1 As Float ', a As String, v As Panel
Dim Amt As Float
Select action
Case Gest.ACTION_DOWN
LNStart = 0
LastX = X - Rect.Left: LastY=y - Rect.Top
Case Gest.ACTION_MOVE
If Gest.GetPointerCount = 2 Then
X0 = Gest.GetX(Gest.GetPointerID(0)): Y0 = Gest.Gety(Gest.GetPointerID(0))
X1 = Gest.GetX(Gest.GetPointerID(1)): Y1 = Gest.Gety(Gest.GetPointerID(1))
LN = Sqrt(((X0-X1)*(X0-X1))+((Y0-Y1)*(Y0-Y1)))
If LNStart = 0 Then LNStart = LN
If LastLen <> 0 Then ResizeBmp(LN/LNStart)
LastLen = LN
WasMulti = True
Else If Gest.GetPointerCount = 1 Then
If Not(WasMulti) Then
If LastX + LastY <> 0 Then
MoveBmp((X - LastX), (y - LastY))
End If
End If
End If
End Select
If action = Gest.ACTION_UP Then
IBW = Rect.Right-Rect.Left
IBH = Rect.Bottom-Rect.Top
LastX = 0: LastY = 0
LastLen = 0
WasMulti=False
End If
Return True ' need to return true otherwise we don't get any other events in the gesture
End Sub