Is it possible to freehand draw with the mouse? Just like a pen/brush tool.
I have a blackboard on one of my backbrounds and I was wondering if I could make that "area" paintable when you use the chalk on it.
I can do without that, but it defiinitely would be funny!
Thank you!
Something like this:
function room_RepExec()
{
if (Mouse.IsButtonDown(eMouseLeft))
{
DrawingSurface* ds = Room.GetDrawingSurfaceForBackground();
ds.DrawingColor = Game.GetColorFromRGB(255,255,255);
ds.DrawRectangle(mouse.x - 2, mouse.y - 2, mouse.x + 2, mouse.y + 2);
ds.Release();
}
}
That was easy! Thank you very much.
Now I'm getting greedy... Would it be possible to specify which surfaces you can draw onto and which ones not? Like... Using regions or whatever?
Sure; for a rectangular blackboard you can do a simple coordinate check.
if (mouse.x < 123 || mouse.x > 234) return; // exit function if mouse is outside bounds, same for y
For an irregular shape you can use a region:
if (Region.GetAtScreenXY(mouse.x, mouse.y) != region[1]) return; // exit if mouse is outside region #1
You'd put either line(s) anywhere before the drawing commands.
Of course! Pretty obvious! I should stop and think a little before asking.
Thanks again!
Ok, I want to take it further... What if I want to check if a certain area has being written on?
For example: I want to make a puzzel where you cross out a swastika gfraffiti. How could I know if x% of that region is covered with "paint"?
A simple way is to count the pixels while you're doing the drawing. Assuming that you're drawing single white pixels, you can check if the pixel is already white before drawing it onto the surface. If it isn't, count up an integer variable.
int x = mouse.x, y = mouse.y;
if (ds.GetPixel(x, y) != 15) {
ds.DrawPixel(x, y);
paintedPixels++;
}
The percentage can now be calculated using (paintedPixels * 100) / totalPixels
Once again: thank you!
I am amazed about how simple the code is!