There is one.I don't see a Canvas component in B4i like B4A has.
You don't see it in the designer because it is not a View, it is an object linked to a view the same as in B4A.When you say there is a canvas in B4i, why don’t I see one in the designer?
'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
Sub pnlGraph_Touch(Action As Int, X As Float, Y As Float)
Select Action
'Case Activity.ACTION_DOWN 'used in B4A
Case pnlGraph.TOUCH_ACTION_DOWN
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.Invalidate
'Case Activity.ACTION_MOVE
Case pnlGraph.TOUCH_ACTION_MOVE
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.Invalidate
x1 = x2
y1 = y2
End Select
End Sub
pScreenHeight = GetDeviceLayoutValues.Height
pScreenWidth = GetDeviceLayoutValues.Width
'..
pnlGraph.Width = pScreenWidth * 1.0
pnlGraph.Height = pScreenHeight * 0.80
pnlGraph.Width = Width * 1.0
pnlGraph.Height = Height* 0.80
Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private xui As XUI
Private pnlGraph As B4XView
Private cvsGraph As B4XCanvas
Private x1, x2, y1, y2, Radius, LineWidth As Float
Private LineColor As Int
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Main") 'Load the layout file.
MainForm.Show
cvsGraph.Initialize(pnlGraph)
LineColor = xui.Color_Blue
Radius = 2dip
LineWidth = 5dip
End Sub
'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Private Sub pnlGraph_Touch(Action As Int, X As Float, Y As Float)
Select Action
Case pnlGraph.TOUCH_ACTION_DOWN
x1 = X
y1 = Y
cvsGraph.DrawCircle(x1, y1, Radius, LineColor, True, 1)
cvsGraph.Invalidate
Case pnlGraph.TOUCH_ACTION_MOVE
x2 = X
y2 = Y
cvsGraph.DrawCircle(x1, y1, Radius, LineColor, True, 1)
cvsGraph.DrawLine(x1, y1, x2, y2, LineColor, LineWidth)
cvsGraph.Invalidate
x1 = x2
y1 = y2
End Select
End Sub
LineColor = xui.Color_Blue
Radius = 2dip
LineWidth = 5dip
Thank you very much Erel and Klaus. I've made all the changes you've both pointed out. I can now see lines when I finger draw!
As the attachment shows, the black lines I added to show my finger movement downward. The red is what the code is drawing. The middle black line down is again my finger movement and the red line to its right is what the code is doing. There is an offset somehow and it gets more offset (to the right) the further to the right I touch and move.
I'm not sure why I'm getting this offset. I looked at the code (correctly saved .zip file attached) but I can't figure out what is causing it.
Private Sub Page1_Resize(Width As Int, Height As Int)
'cvsPage.Initialize(Page1.RootPanel)
'cvsGraph.Resize(Width, Height)
pnlGraph.Top = Height * 0.20
pnlGraph.Left = 0
pnlGraph.Width = Width
pnlGraph.Height = Height * 0.56
cvsGraph.Initialize(pnlGraph)
'Msgbox("Grn 121.9 * Twr 118.5 * App 125.5"& CRLF & "Grn 121.9 * Twr 118.5 * App 125.5", "KMEM")
Drawing
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?