Windows point_in_rectangle

Chaser

Member
any reason why this isn't working for me? one works one doesn't, same thing, very annoying. :)
obj_display

Create event:
global.download = false;
global.download2 = false;

Step Event:
mousex = window_mouse_get_x();
mousey = window_mouse_get_y();

Draw_GUI Event:
draw_rectangle_color(550,740,750,706,c_white,c_red,c_green,c_blue,false);
if point_in_rectangle(mousex, mousey,550,740,750,706)
{
global.download = true;
}
else
if !point_in_rectangle(mousex, mousey,550,740,750,706)
{
global.download = false;
}

Draw_event:
draw_set_font(font0);
draw_set_colour(c_white)
draw_text(0,0,"" +string(global.download);
draw_text(0,10,"" +string(global.download2);

Above code works :)
Below code doesn't :(

draw_rectangle_color(114,128,180,146,c_white,c_red,c_green,c_blue,false);
if point_in_rectangle(mousex, mousey,114,128,180,146)
{
global.download2 = true;
}
else
if !point_in_rectangle(mousex, mousey,114,128,180,146)
{
global.download2 = false;
}

I find it weird, maybe i'm missing something.
Rectangle boxes are drawn fine, even when i display the co-ordinates of the mouse X & Y on screen, it shows that its inside the rectangle, but just doesn't register like the first box. I'm baffled.
 
Last edited:

Simon Gust

Member
Do not check for rectangles that have inverted coordinates.
x1 should by smaller than x2
y1 should be smaller than y2
 
Also, please, for the sake of optimization, do not check things twice when you don't have to. You only need the "else" part of the statement. There's no need to check if the point is not in the rectangle as that's why the "else" statement was triggered to begin with.




You can also condense it down to:
Code:
global.download = point_in_rectangle(mousex,mousey,114,128,180,146);
 
Top