Skip to content

Commit

Permalink
| Added support for GUI layer cursor location to shape cursor getter …
Browse files Browse the repository at this point in the history
…methods
  • Loading branch information
Mtax-Development committed Oct 3, 2021
1 parent 3c855ee commit ee19db5
Show file tree
Hide file tree
Showing 5 changed files with 280 additions and 60 deletions.
68 changes: 56 additions & 12 deletions scripts/Circle/Circle.gml
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,12 @@ function Circle() constructor
}

// @argument {int} device?
// @argument {bool} GUI?
// @returns {bool}
// @description Check if the system cursor is over this Shape.
static cursorOver = function(_device)
// If the device is specified, the position of the cursor on the GUI
// layer can be used.
static cursorOver = function(_device, _GUI = false)
{
var _cursor_x, _cursor_y;

Expand All @@ -178,19 +181,30 @@ function Circle() constructor
}
else
{
_cursor_x = device_mouse_x(_device);
_cursor_y = device_mouse_y(_device);
if (_GUI)
{
_cursor_x = device_mouse_x_to_gui(_device);
_cursor_y = device_mouse_y_to_gui(_device);
}
else
{
_cursor_x = device_mouse_x(_device);
_cursor_y = device_mouse_y(_device);
}
}

return point_in_circle(_cursor_x, _cursor_y, location.x, location.y, radius);
}

// @argument {constant:mb_*} button
// @argument {int} device?
// @argument {bool} GUI?
// @returns {bool}
// @description Check if the system cursor is over this Shape while its specified
// mouse button is pressed or held.
static cursorHold = function(_button, _device)
// If the device is specified, the position of the cursor on the GUI
// layer can be used.
static cursorHold = function(_button, _device, _GUI = false)
{
var _cursor_x, _cursor_y;

Expand All @@ -201,8 +215,16 @@ function Circle() constructor
}
else
{
_cursor_x = device_mouse_x(_device);
_cursor_y = device_mouse_y(_device);
if (_GUI)
{
_cursor_x = device_mouse_x_to_gui(_device);
_cursor_y = device_mouse_y_to_gui(_device);
}
else
{
_cursor_x = device_mouse_x(_device);
_cursor_y = device_mouse_y(_device);
}
}

if (point_in_circle(_cursor_x, _cursor_y, location.x, location.y, radius))
Expand All @@ -218,10 +240,13 @@ function Circle() constructor

// @argument {constant:mb_*} button
// @argument {int} device?
// @argument {bool} GUI?
// @returns {bool}
// @description Check if the system cursor is over this Shape while its specified
// mouse button was pressed in this frame.
static cursorPressed = function(_button, _device)
// If the device is specified, the position of the cursor on the GUI
// layer can be used.
static cursorPressed = function(_button, _device, _GUI = false)
{
var _cursor_x, _cursor_y;

Expand All @@ -232,8 +257,16 @@ function Circle() constructor
}
else
{
_cursor_x = device_mouse_x(_device);
_cursor_y = device_mouse_y(_device);
if (_GUI)
{
_cursor_x = device_mouse_x_to_gui(_device);
_cursor_y = device_mouse_y_to_gui(_device);
}
else
{
_cursor_x = device_mouse_x(_device);
_cursor_y = device_mouse_y(_device);
}
}

if (point_in_circle(_cursor_x, _cursor_y, location.x, location.y, radius))
Expand All @@ -250,10 +283,13 @@ function Circle() constructor

// @argument {constant:mb_*} button
// @argument {int} device?
// @argument {bool} GUI?
// @returns {bool}
// @description Check if the system cursor is over this Shape while the specified
// mouse button was released in this frame.
static cursorReleased = function(_button, _device)
// If the device is specified, the position of the cursor on the GUI
// layer can be used.
static cursorReleased = function(_button, _device, _GUI = false)
{
var _cursor_x, _cursor_y;

Expand All @@ -264,8 +300,16 @@ function Circle() constructor
}
else
{
_cursor_x = device_mouse_x(_device);
_cursor_y = device_mouse_y(_device);
if (_GUI)
{
_cursor_x = device_mouse_x_to_gui(_device);
_cursor_y = device_mouse_y_to_gui(_device);
}
else
{
_cursor_x = device_mouse_x(_device);
_cursor_y = device_mouse_y(_device);
}
}

if (point_in_circle(_cursor_x, _cursor_y, location.x, location.y, radius))
Expand Down
68 changes: 56 additions & 12 deletions scripts/Point/Point.gml
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,12 @@ function Point() constructor
}

// @argument {int} device?
// @argument {bool} GUI?
// @returns {bool}
// @description Check if the cursor is over this Shape.
static cursorOver = function(_device)
// If the device is specified, the position of the cursor on the GUI
// layer can be used.
static cursorOver = function(_device, _GUI = false)
{
var _cursor_x, _cursor_y;

Expand All @@ -154,19 +157,30 @@ function Point() constructor
}
else
{
_cursor_x = device_mouse_x(_device);
_cursor_y = device_mouse_y(_device);
if (_GUI)
{
_cursor_x = device_mouse_x_to_gui(_device);
_cursor_y = device_mouse_y_to_gui(_device);
}
else
{
_cursor_x = device_mouse_x(_device);
_cursor_y = device_mouse_y(_device);
}
}

return ((_cursor_x == location.x) and (_cursor_y == location.y));
}

// @argument {constant:mb_*} button
// @argument {int} device?
// @argument {bool} GUI?
// @returns {bool}
// @description Check if the cursor is over this Shape while its specified mouse
// button is pressed or held.
static cursorHold = function(_button, _device)
// If the device is specified, the position of the cursor on the GUI
// layer can be used.
static cursorHold = function(_button, _device, _GUI = false)
{
var _cursor_x, _cursor_y;

Expand All @@ -177,8 +191,16 @@ function Point() constructor
}
else
{
_cursor_x = device_mouse_x(_device);
_cursor_y = device_mouse_y(_device);
if (_GUI)
{
_cursor_x = device_mouse_x_to_gui(_device);
_cursor_y = device_mouse_y_to_gui(_device);
}
else
{
_cursor_x = device_mouse_x(_device);
_cursor_y = device_mouse_y(_device);
}
}

if ((_cursor_x == location.x) and (_cursor_y == location.y))
Expand All @@ -194,10 +216,13 @@ function Point() constructor

// @argument {constant:mb_*} button
// @argument {int} device?
// @argument {bool} GUI?
// @returns {bool}
// @description Check if the cursor is over this Shape while its specified mouse
// button was pressed in this frame.
static cursorPressed = function(_button, _device)
// If the device is specified, the position of the cursor on the GUI
// layer can be used.
static cursorPressed = function(_button, _device, _GUI = false)
{
var _cursor_x, _cursor_y;

Expand All @@ -208,8 +233,16 @@ function Point() constructor
}
else
{
_cursor_x = device_mouse_x(_device);
_cursor_y = device_mouse_y(_device);
if (_GUI)
{
_cursor_x = device_mouse_x_to_gui(_device);
_cursor_y = device_mouse_y_to_gui(_device);
}
else
{
_cursor_x = device_mouse_x(_device);
_cursor_y = device_mouse_y(_device);
}
}

if ((_cursor_x == location.x) and (_cursor_y == location.y))
Expand All @@ -226,10 +259,13 @@ function Point() constructor

// @argument {constant:mb_*} button
// @argument {int} device?
// @argument {bool} GUI?
// @returns {bool}
// @description Check if the cursor is over this Shape while the specified mouse
// button was released in this frame.
static cursorReleased = function(_button, _device)
// If the device is specified, the position of the cursor on the GUI
// layer can be used.
static cursorReleased = function(_button, _device, _GUI = false)
{
var _cursor_x, _cursor_y;

Expand All @@ -240,8 +276,16 @@ function Point() constructor
}
else
{
_cursor_x = device_mouse_x(_device);
_cursor_y = device_mouse_y(_device);
if (_GUI)
{
_cursor_x = device_mouse_x_to_gui(_device);
_cursor_y = device_mouse_y_to_gui(_device);
}
else
{
_cursor_x = device_mouse_x(_device);
_cursor_y = device_mouse_y(_device);
}
}

if ((_cursor_x == location.x) and (_cursor_y == location.y))
Expand Down
Loading

0 comments on commit ee19db5

Please sign in to comment.