Hi, i'm new in using b4a , is there a way in drawing a sudoku board(grids) that can handle input?,
I tried drawing the board using canvas on my first attempt and labels +panels on my second attempt.
i'm having trouble making it recognized touch or click events... and also if you have any tips on displaying the numbers on the board that would be nice....
Here is what I use:
A square panel (named board), with lines drawn on it to create the matrix:
B4X:
Sub draw_board
cnvs.Initialize(cover)
For i = 0 To 3
cnvs.DrawLine(0, ystep*3*i, board.Width, ystep*3*i, Colors.Red, 3)
cnvs.DrawLine(xstep*3*i, 0 ,xstep*3*i, board.Height, Colors.Red, 3)
Next
For i = 0 To 9
cnvs.DrawLine(0, ystep*i, board.Width, ystep*i, Colors.black, 1)
cnvs.DrawLine(xstep*i, 0 , xstep*i, board.Height, Colors.black, 1)
Next
cnvs.Initialize(board)
End Sub
When you touch a cell on the board, you use this to define the cell:
B4X:
Sub board_Touch (Action As Int, X As Float, Y As Float)
Select Action
Case Activity.ACTION_DOWN
Dim st As String
sel_i = X/xstep
sel_j = Y/ystep
sel_pnl.Left = sel_i * xstep
sel_pnl.Top = sel_j * ystep
st = a(sel_i,sel_j)
...
sel_pnl is a colored panel with size of a square which jumps on top of the selected square.
Setting the number to a cell is done by buttons outside of the board.