Just getting started and trying to rapidly learn things. I’m not new to programming, but confused by some things that seem they should be simple and accessible that I’m having to dive for.
I’m trying to build sort of an inventory type system - I have a canvas, and I’ve been able to draw a semi-transparent grid. I’ve been able to adjust the transparency and color of the grid. Awesome.
Now, I just want to draw a selection rectangle around the current cell on the 32x32px grid, which would be wherever the mouse is placed.
I’ve tried individual integers and Point for the trackingPosition x/y. I tried adding a mouse move event in my canvas and updating tracking position there, then in the paint event, draw the rectangle based on the tracking variables. They are always zero.
I guess my issue is something simple - how do I detect the mouse position relative to the canvas to populate those trackingPosition variables so that I can draw a selection rectangle under the mouse? I feel like I’m missing something incredibly elementary here.
I’m generally starting even simpler than that. I just eventually want to draw a rectangle at the 32x32px grid cell over which the mouse hovers as a starting point. Right now, I’m just trying to draw a 32x32 pixel rectangle at the mouse position on the canvas, sort of following if my mouse is in the canvas, and I’ll do the math to snap to normalized position once I get anything happening. But right now, nothing draws.
What event can I use to be checking if the mouse is with in the canvas like this, and get its position which I can then pass to the Paint event?
The usual reason, at least for people new to Xojo, is Scope. People typically declare local variables in their event code and set them. Those variables go out of scope and are destroyed as soon as the event finishes. You need to add properties to the window and use those.
Another common error is to have properties on the window, but then define variables with the same name in the event code. In that case, since the local variables are closer in scope than the window properties, the local variables are used by the event code, leaving the window properties unchanged.
Just a wild guess based on your description of the problem.