public Sub ConnectPage()
' see below for the native Java code function loadPixelsFromImage
Dim NativeMe As JavaObject = Me
MyClickPic = NativeMe.RunMethod("loadPixelsFromImage", Array(File.Combine(File.DirApp, "appimageclick.png")))
' we create our canvas
Dim myCanvas As ABMCanvas
myCanvas.Initialize(page, "myCanvas", ABM.COLOR_BLACK, "", 1280, 800, True)
page.Cell(1,1).AddComponent(myCanvas)
' set the fixed height 1px from the bottom to make it 'full window'
page.Row(1).SetFixedHeightFromBottom(1,False)
' add the background from our loaded image in BuildPage() AddCanvasImage
Dim bg As ABMCanvasObject
bg.InitializeAsRectangle(page, "bg",0,0,1024,569,False)
bg.drawImage("background", 0,0)
myCanvas.AddObject(bg)
' the 'labels' that we need on the canvas
Dim HomeLabel As ABMCanvasObject
' the +(225/2) etc is to determine the center position
HomeLabel.InitializeAsRectangle(page, "HomeLabel", 15+(225/2),200+(100/2), 225, 100, False)
DrawLabel(HomeLabel, "SFDigitalReadout", 130, "#ADFF2F", "00")
myCanvas.AddObject(HomeLabel)
Dim TimerLabel As ABMCanvasObject
TimerLabel.InitializeAsRectangle(page, "TimerLabel", 440+(400/2),90+(90/2), 400, 90, False)
DrawLabel(TimerLabel, "SFDigitalReadout", 130, "#ADFF2F", "00:00:00")
myCanvas.AddObject(TimerLabel)
Dim StartStopLabel As ABMCanvasObject
StartStopLabel.InitializeAsRectangle(page, "StartStopLabel", 450+(380/2),200+(70/2), 390, 70, False)
DrawLabel(StartStopLabel, "arial", 40, "#000000", "Start Clock")
myCanvas.AddObject(StartStopLabel)
' important
myCanvas.Refresh
' refresh the page
page.Refresh
' Tell the browser we finished loading
page.FinishedLoading
' restoring the navigation bar position
page.RestoreNavigationBarPosition
End Sub
#end region
' helper method to draw the ABMCanvasObject
Sub DrawLabel(LabelObject As ABMCanvasObject, Font As String, Size As Int, Color As String, Text As String)
LabelObject.Clear
LabelObject.font(Font, Size)
LabelObject.textBaseline(ABM.CANVAS_TEXTBASELINE_MIDDLE)
LabelObject.textAlign(ABM.CANVAS_TEXTALIGN_CENTER)
LabelObject.fillStyleColor(Color)
LabelObject.fillText(Text, 0, 0)
End Sub
' Here we map the real clicked position with the position on our 'Click map'
Sub myCanvas_CanvasUp(x As Int, y As Int)
Dim myCanvas As ABMCanvas = page.Component("myCanvas")
Log(x & " " & y & ":" & MyClickPic(x,y))
Select Case MyClickPic(x,y)
Case -65281
Log("home up")
HomeScore = HomeScore + 1
Dim HomeScoreStr As String = HomeScore
If HomeScoreStr.Length = 1 Then HomeScoreStr = "0" & HomeScoreStr
Dim HomeLabel As ABMCanvasObject = myCanvas.GetObject("HomeLabel")
DrawLabel(HomeLabel, "SFDigitalReadout", 130, "#ADFF2F", HomeScoreStr)
HomeLabel.Refresh
Case -1.6776961E7
Log("home down")
HomeScore = HomeScore - 1
Dim HomeScoreStr As String = HomeScore
If HomeScoreStr.Length = 1 Then HomeScoreStr = "0" & HomeScoreStr
Dim HomeLabel As ABMCanvasObject = myCanvas.GetObject("HomeLabel")
DrawLabel(HomeLabel, "SFDigitalReadout", 130, "#ADFF2F", HomeScoreStr)
HomeLabel.Refresh
Case -16711681
Dim StartStopLabel As ABMCanvasObject = myCanvas.GetObject("StartStopLabel")
If GameStart > 0 Then
GameTimer.Enabled = False
GameStart = 0
DrawLabel(StartStopLabel, "arial", 40, "#000000", "Start Clock")
Else
GameTimer.Initialize("GameTimer", 1000)
GameTimer.Enabled = True
GameStart = DateTime.Now
DrawLabel(StartStopLabel, "arial", 40, "#000000", "Stop Clock")
End If
StartStopLabel.Refresh
End Select
myCanvas.Refresh
End Sub
Sub GameTimer_Tick
Dim GameNow As Long = DateTime.Now
Dim GameTime As String
Dim p As Period = DateUtils.PeriodBetween(GameStart, GameNow)
If p.Hours > 9 Then
GameTime = p.Hours & ":"
Else
GameTime = "0" & p.Hours & ":"
End If
If p.Minutes > 9 Then
GameTime = GameTime & p.Minutes & ":"
Else
GameTime = GameTime & "0" & p.minutes & ":"
End If
If p.Seconds > 9 Then
GameTime = GameTime & p.seconds
Else
GameTime = GameTime & "0" & p.seconds
End If
Dim myCanvas As ABMCanvas = page.Component("myCanvas")
Dim TimerLabel As ABMCanvasObject = myCanvas.GetObject("TimerLabel")
DrawLabel(TimerLabel, "SFDigitalReadout", 130, "#ADFF2F", GameTime)
TimerLabel.Refresh
myCanvas.Refresh
End Sub