Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: BowsetteGamer on Sat 29/06/2024 01:06:30

Title: Is it possible to configure a GUI that can be moved with the cursor?
Post by: BowsetteGamer on Sat 29/06/2024 01:06:30
Hello guys, how are you?
I don't know if this is possible, but I've looked at the GUI properties and I haven't really understood what they say or... I may need to create some code that I don't understand. But what I need is that you can move a GUI with the mouse cursor just as you move desktop windows, for example the calculator, a notepad and that, a GUI that can be moved with the cursor.

Please guys help me...  ???  ???  ???
Title: Re: Is it possible to configure a GUI that can be moved with the cursor?
Post by: Snarky on Sat 29/06/2024 09:50:24
You would need to detect that the mouse button is held down over the GUI (Mouse.IsButtonDown), and change the GUI's coordinates as the mouse coordinates change (all in repeatedly_execute_always).

It shouldn't be too hard, but you can also check out https://www.adventuregamestudio.co.uk/forums/modules-plugins-tools/module-dragdrop-1-1-0-helps-to-drag-things-around-your-ags-game!/
Title: Re: Is it possible to configure a GUI that can be moved with the cursor?
Post by: Khris on Sat 29/06/2024 12:25:46
Add a new script module, then put this as the header:

struct Draggable {
  import static void Activate(Label* label);
};

and this in the main script:
Label* labels[100];
int label_count;

static void Draggable::Activate(Label* label) {
  labels[label_count] = label;
  label_count++;
}

GUI* theGUI;
bool dragging;
int ox, oy;

void on_event(EventType event, int data) {
 
  int mx = mouse.x, my = mouse.y;
 
  if (event == eEventGUIMouseDown) {
    GUIControl* gc = GUIControl.GetAtScreenXY(mx, my);
    if (gc) {
      Label* lbl = gc.AsLabel;
      for (int i = 0; i < label_count; i++) {
        if (labels[i] == lbl) {
          theGUI = lbl.OwningGUI;
          dragging = true;
          ox = mx - theGUI.X;
          oy = my - theGUI.Y;
        }
      }
    }
  }
  if (event == eEventGUIMouseUp) {
    if (dragging) dragging = false;
  }
 
}

void repeatedly_execute_always() {
  if (dragging) {
    theGUI.X = mouse.x - ox;
    theGUI.Y = mouse.y - oy;
  }
}

Now put a label at the top of the GUI (this acts as handle) and call
  Draggable.Activate(lblDragMe);passing the label in a suitable place like game_start or the first room's room_Load.