0
I’m trying to solve a problem, create a rectangle and create 4 points for 4 directions. And by clicking and dragging increase the size of it, I even made a code but it’s not perfect.
// Create Event
rect = {
X: 256,
Y: 256,
W: 256,
H: 128
}
mx = 0;
my = 0;
offsetx = 0;
offsety = 0;
pointScale = [];
Up_Arrow = false;
Dn_Arrow = false;
L_Arrow = false;
R_Arrow = false;
dragging = false;
#define step
// step event code
#define draw
// draw event code
if mouse_check_button_released(mb_left) && (dragging) {
dragging = false;
Up_Arrow = false;
Dn_Arrow = false;
L_Arrow = false;
R_Arrow = false;
}
draw_rectangle(rect.X,rect.Y,rect.X + rect.W,rect.Y + rect.H, true)
pointScale[0] = {X : (rect.X + rect.W/2), Y : rect.Y - 32}
pointScale[1] = {X : (rect.X + rect.W/2), Y : rect.Y + rect.H + 32}
pointScale[2] = {X : rect.X - 32, Y : (rect.Y + rect.H/2)}
pointScale[3] = {X : rect.X + rect.W + 32, Y : (rect.Y + rect.H/2)}
for (var i = 0; i < 4; i++) {
draw_circle(pointScale[i].X,pointScale[i].Y,8,false)
if point_in_circle(mouse_x,mouse_y,pointScale[i].X,pointScale[i].Y,8) && mouse_check_button(mb_left) {
dragging = true;
window_set_cursor(cr_drag);
trace(string(i))
}
}
var oldy = rect.Y + rect.H;
var oldh = rect.Y;
var oldx = rect.X + rect.W;
var oldw = rect.X;
if (Up_Arrow) {
rect.Y = my
rect.H = oldy - my
}
else if (Dn_Arrow) {
rect.H = my - oldh
}
else if (L_Arrow) {
rect.X = mx
rect.W = oldx - mx
}
else if (R_Arrow) {
rect.W = mx - oldw
}
mx = mouse_x;
my = mouse_y;
if (dragging) {
if point_in_circle(mouse_x,mouse_y,pointScale[0].X,pointScale[0].Y,8) Up_Arrow = true // UP
if point_in_circle(mouse_x,mouse_y,pointScale[1].X,pointScale[1].Y,8) Dn_Arrow = true // DOWN
if point_in_circle(mouse_x,mouse_y,pointScale[2].X,pointScale[2].Y,8) L_Arrow = true // LEFT
if point_in_circle(mouse_x,mouse_y,pointScale[3].X,pointScale[3].Y,8) R_Arrow = true // RIGHT
}
I was using the https://yal.cc/r/gml/ to test the code...
The code until it works but not in the way I wanted. Because by clicking on certain directions without dragging the rectangle already increases in size.