B4J Question B4J BreadBoard to B4X Code Module Help ???

KiloBravo

Active Member
Licensed User
I am stuck on this "project" I took the below project and I am trying to convert it to a B4X project.
B4J Breadboard by Use Wonder

Wonder uses B4J and creates the canvas as a Node. (Everything Works Great)

I followed Erel's example and created a Class Module, "cust_grd.bas". The layout file "GridPanel" contains one view of a Pane, "pnlGrid".

The issue seems to be in Wonder's example he draws the Grid Cells and uses the code below which is commented with my substitution for B4X code.
B4X:
 'cvs.DrawRect(gX, gY, testGrid.gridStep, testGrid.gridStep, colorMap.Get(testGrid.matrix(x, y)), True, 0)

R.Initialize(gX,gY,testGrid.gridStep, testGrid.gridStep)     
cvs.DrawRect(R, colorMap.Get(testGrid.matrix(x, y)), True, 0)

I have this in Class_Globals
Dim R As B4XRect

Also, I am not sure what this line does in the InitializeGrid Sub ?
B4X:
Dim matrix(sizeX, sizeY) As Int : testGrid.matrix = matrix

So far I have it somewhat working. It draws the grid if I initializes it with ( InitializeGrid(0, 0, 20) )
But, I am only able to draw colors and fill/clear the Grid Block in the upper right Block at 0,0. I uploaded my "project" as a zip file.
It does log all the Grid Coordinates correctly, but does not fill in the blocks with a color other than bock 0,0.

My attached code has comments from the differences from his project to mine as well as my message test logging to try and fix my code.

I am pretty sure it is the way the grid coordinates are different and calculated between B4J and B4X or the creation of the B4Xrect.

This is my first B4J project and it looks like I picked a good one. I have spent hours trying to get it to work.
Any suggestions would be appreciated. Thanks !
 

Attachments

  • bb_kzb01.zip
    108.2 KB · Views: 206

KiloBravo

Active Member
Licensed User
BreadBoard.png

The way the original B4J node version works is above. It Creates a Canvas Node.
If you left click and drag the mouse it fills the grid blocks with Green. If you left click on a grid block it fills that block with Blue.
If you right click or right click and drag the mouse it "clears" the color from the grid blocks.
Any mouse "event" logs the grid coordinates to the log.
 
Upvote 0

KiloBravo

Active Member
Licensed User
BB_B4Xview.PNG


I recreated it in B4X with a Layout and a with a Code Module consisting of a pane/panel. Then a B4xcavas in that Pane/panel view. My implementation is supposed to work the same way.
But it currently ONLY fills the Grid Block at 0,0 with color on the B4Xcanvas. (But it does not fill the grid block completely)
The LOG is showing the correct mouse coordinates for the Grid Blocks. But none of them display any color, except 0,0.

Eventually I want the grid to represent something in the real world and be able to navigate a robot to a grid coordinate by clicking on that block, or have the robot navigate to a grid block and display it's progress on the grid map. All of which I could probably implement now (being very optimistic !) with what I have in B4J and an esp8266 with B4R.
But I wanted to make it cross platform so it would Run on a laptop, tablet or phone.
 
Upvote 0
Top