Skip to content

Instantly share code, notes, and snippets.

@BenDol
Last active May 7, 2020 22:30
Show Gist options
  • Save BenDol/7ddf4960c959aeaf7693d239db34780e to your computer and use it in GitHub Desktop.
Save BenDol/7ddf4960c959aeaf7693d239db34780e to your computer and use it in GitHub Desktop.
My Gamemaker Widget System
// Create Event
// mouse events are handled in our event block
// left press (called when the widget is pressed, accounting for depth)
mouse_register(MouseEvent.left_press, self);
// hovering support (called when the mouse hovers the widget, accounting for depth)
mouse_register(MouseEvent.enter, self);
mouse_register(MouseEvent.leave, self);
// apply scrolling support (essentially changes the scroll_pos up or down)
mouse_register(MouseEvent.wheel_up, self);
mouse_register(MouseEvent.wheel_down, self);
minimap = widget_create(obj_minimap);
minimap.target = this;
minimap.anchor = Anchor.right; // anchors our positioning to the right of our parent
with (obj_gui_canvas) {
widget_child_add(other.minimap);
}
// Note: the depth of GUI widgets are managed based on its placement index that can be changed.
// see end
panel = widget_create(obj_panel, 100, 200);
panel.padding = 20; // applies padding_left/top/bottom/right
panel.anchor = Anchor.right; // anchors our positioning to the right of our parent
panel.bg_color = c_red; // background rect color
with (obj_gui_canvas) {
widget_child_add(other.panel);
}
var panel1 = widget_create(obj_panel, 80, 50);
panel1.bg_color = c_blue; // background rect color
panel1.overflow = true; // allows us to overflow our boundaries
with (bpanel) {
widget_child_add(panel1);
}
var panel2 = widget_create(obj_panel, 80, 110);
panel2.bg_color = c_green; // background rect color
panel2.overflow = true; // allows us to overflow our boundaries
with (bpanel) {
widget_child_add(this.panel1);
}
with(panel) {
widget_set_depth_front(); // brings the panel to the front of render list (so the back of the list i.e. rendered last)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment