• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker best way for calculating widget resizing?

S

Shadowblitz16

Guest
I have two questions..

1. does anybody have an idea how to handle diagonal resizing in this code? I don't want to handle them separately but somehow combine the side resizing.
Code:
/// @description WWidget step event
// You can write your code in this editor

if (is_clickable && is_clicked)
    if (on_clicked != -1) script_execute(on_clicked);
  
if (is_resizing)
    if (on_resize != -1) script_execute(on_resize);
  
if (is_floatable && is_floated)
    if (on_float != -1) script_execute(on_float);
  
if (is_movable && is_moved)
    if (on_move != -1) script_execute(on_move);
      

var x1 = x;
var y1 = y;
var x2 = x+width;
var y2 = y+height;

var vcol = (mouse_y >= y1 && mouse_y <= y2);
var hcol = (mouse_x >= x1 && mouse_x <= x2);


var top     = (mouse_y >= y1 + 2 && mouse_y <= y1 + 4);
var bottom  = (mouse_y >= y2 + 2 && mouse_y <= y2 + 4);
var left    = (mouse_x >= x1 + 2 && mouse_x <= x1 + 4);
var right   = (mouse_x >= x2 + 2 && mouse_x <= x2 + 4);
  
if (is_resizable && !is_resizing)
{
    window_set_cursor(cr_arrow);

    //Vertical
    if (hcol && top)
    {
        window_set_cursor(cr_size_ns);
        if (mouse_check_button_pressed(mb_left))
        {
            type_resize = 1; //Top
            is_resizing = true;
        }
    }
    if (hcol && bottom)
    {
        window_set_cursor(cr_size_ns);
        if (mouse_check_button_pressed(mb_left))
        {
            type_resize = 2; //Bottom
            is_resizing = true;  
        }
    }
  
    //Horizontal
    if (vcol && left)
    {
        window_set_cursor(cr_size_we);
        if (mouse_check_button_pressed(mb_left))
        {
            type_resize = 3; //Left
            is_resizing = true;
        }
    }
    if (vcol && right)
    {
        window_set_cursor(cr_size_we);
        if (mouse_check_button_pressed(mb_left))
        {
            type_resize = 4; //Right
            is_resizing = true;
        }
    }
}
2. does anybody know how to make my width and height in case 1 and 3 increase while I the x and y decreases?

Code:
switch (type_resize)
{
    case 1:   //Resizing window up
        y      =  Mouse.y
        //I need to adjust the height so that the widget doesn't appear to move
        break;
    case 2:   //Resizing window down
        height = (Mouse.y - y);
        break;
    case 3:  //Resizing window left
        x      = (Mouse.x)
        //I need to adjust the width so that the widget doesn't appear to move
        break;
    case 4:   //Resizing window right
        width = (Mouse.x - x);
        break;
}
 
Last edited by a moderator:
Top