Primitive drawing - how to draw with mouse

I want to draw a square on the screen where I clicked. I’m using Primitive Drawing tool for that. But I can draw only one square. When I clicked in the other place the previous square just disappears. So, how to make it stay on the screen?
Here is my event sheet:

The problem is: GD replaces the old variable “x” and “y” values with the new ones, so you have only two values to draw, and one instruction to draw; The drawers don’t remember old draws, you have to add a draw action every frame for every draw :neutral_face:

Ok, I think I can help you, check this out:
RectangleDraw.gdg (22.4 KB)
De/activate the first and second event to check both of them work: The first one add a new variable to a struct with each click (each variable of the struct stands for a rectangle), then one DrawerObject draw a rectangle for each variable in the struct. The second add a new DrawerObject with each click and save some values on it (object variable), then each DrawerObject draw its rectangle in function of its own variables :ugeek:

Excuse me if the first option (with struct variables) is a bit complex (you know I like the complex things) :smiling_imp:
The second option with multiple drawer objects is a bit easier :wink:

Yes, complicated… but it works. :slight_smile:
And thanks for example of using structure variables! Couldn’t figure it out on my own.
I just curious about if these methods would be too demanding on the computer memory. As I understood you need to keep in a memory coordinates of Every created object on the screen. And color… and other possible attributes…
In another post you recommended to use a panel sprite for drawing. Will it be less memory consuming? Still you’ll end up with a bunch of panel sprites which could slow down the program, I think.
The goal is just to draw with mouse/keys simple shapes/scribble on the screen or make a pixel art drawing. Maybe GD is not suitable for this kind of stuff. The python’s turtle is perfect for this. The Scratch’s drawing tool is less capable but still usable too. In the CC’s example you can draw on the canvas, resize it and save the resulting picture.

First of all, check this, it’s possible:
DrawerSystem.rar (7.24 KB)

Yeah, I recommended panel sprites because you wanted control over it (drag-and-drop basically)… but “opening my mind” ( :laughing: ) now I could even think in drag-and-drop over struct variables *1
About the memory consuming: The order could be: Structure (bad performance) → Multiple Drawers → Panels/Sprites *2

Yes, multiple draws should work :wink:
If you need to move the shapes (basic control), structures could work.
If you need to rotate them (high control), you’ll need sprites.

*1- To check if the mouse is over a rectangle (the four points in the struct variable) you can test StartX<MouseX<EndX and StartY<MouseY<EndY , then you can modify the struct rectangle’s points in function of the mouse’s movement.
*2- I don’t know how much information the DrawerObject keeps, but probably the structure I used in the example, with extra variables as FillColor, BorderColor, Opacity, etc would take less memory. But changing every frame the properties of the only DrawerObject to work with each structure variable will lost performance. Then Panel Sprites and Sprites (again probably) keeps a lot more information than a Drawer, so you better option (if you don’t need high control) is with multiple drawers, then you could need structures/sprites/panel sprites if you need nice thinks like basic control, automatisms, and so on.

Brilliant, as usual. :slight_smile: Thanks!

Awesome Lizard-13, I’ve added your (impressive!) Drawer system as an example for the next release of GD :smiley:

Ok! and thanks :slight_smile: