'Code module
#Region Project Attributes
#ApplicationLabel: B4i Example
#Version: 1.0.0
'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
#iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
#iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
#Target: iPhone, iPad
#ATSEnabled: True
#MinVersion: 7
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public App As Application
Public NavControl As NavigationController
Private Page1 As Page
Dim x1, x2, y1, y2, Radius, LineWidth As Float
Dim LineColor As Int
Dim rect1 As Rect
Private pnlGraph As Panel
Private cvsPage, cvsGraph As Canvas
End Sub
Private Sub Application_Start (Nav As NavigationController)
'SetDebugAutoFlushLogs(True) 'Uncomment if program crashes before all logs are printed.
NavControl = Nav
Page1.Initialize("Page1")
Page1.Title = "Page 1"
Page1.RootPanel.Color = Colors.White
NavControl.ShowPage(Page1)
'load the layout file
Page1.RootPanel.LoadLayout("Main")
' show page 1
NavControl.ShowPage(Page1)
Radius = Floor(LineWidth / 2)
LineColor = Colors.Magenta
rect1.Initialize(0, 0, pnlGraph.Width, pnlGraph.Height)
End Sub
Private Sub Page1_Resize(Width As Int, Height As Int)
' initialize the Canvas for the activity
cvsPage.Initialize(Page1.RootPanel)
' initialize the Canvas for the pnlGraph panel
cvsGraph.Initialize(pnlGraph)
' call the Drawing routine
'Drawing 'not used
End Sub
Private Sub Application_Background
End Sub
Private Sub Drawing
' draw a horizontal line onto the Page
'cvsPage.DrawLine(20, 20, 160, 20, Colors.Red, 3)
' draw a horizontal line onto pnlGraph
'cvsGraph.DrawLine(20, 20, 160, 20, Colors.Red, 3)
'cvsPage.Refresh
'cvsGraph.Refresh
End Sub
'Draw a cross on the reference point
Private Sub DrawCross(x As Int, y As Int, l As Int)
'cvsGraph.DrawLine(x - l, y, x + l, y, Colors.Red, 1)
'cvsGraph.DrawLine(x, y - l, x, y +l, Colors.Red, 1)
End Sub
Sub pnlGraph_Touch(Action As Int, X As Float, Y As Float)
Select Action
'Case Activity.ACTION_DOWN 'used in B4A
Case 0 'B4i
x1 = X
y1 = Y
cvsGraph.DrawCircle(x1, y1, Radius, LineColor, True, 1)
rect1.Left = x1 - Radius
rect1.Top = y1 - Radius
rect1.Right = rect1.Left + LineWidth
rect1.Bottom = rect1.Top + LineWidth
'pnlGraph.Invalidate2(rect1) 'b4A
cvsPage.Refresh 'b4i
cvsGraph.Refresh 'b4i
'Case Activity.ACTION_MOVE
Case 1
x2 = X
y2 = Y
cvsGraph.DrawCircle(x1, y1, Radius, LineColor, True, 1)
cvsGraph.DrawLine(x1, y1, x2, y2, LineColor, LineWidth)
rect1.Left = Min(x1, x2) - Radius
rect1.Top = Min(y1, y2) - Radius
rect1.Right = Max(x1, x2) + LineWidth
rect1.Bottom = Max(y1, y2) + LineWidth
'pnlGraph.Invalidate2(rect1)
cvsPage.Refresh
cvsGraph.Refresh
x1 = x2
y1 = y2
End Select
End Sub