Pixel-Composer/scripts/buttonAnchor/buttonAnchor.gml

57 lines
1.2 KiB
Plaintext
Raw Normal View History

2023-11-07 06:01:38 +01:00
function buttonAnchor(_onClick) : widget() constructor {
onClick = _onClick;
index = 4;
2024-05-17 15:25:01 +02:00
click = true;
2023-11-07 06:01:38 +01:00
center = true;
context = noone;
2023-11-07 06:01:38 +01:00
static drawParam = function(params) {
return draw(params.x, params.y, params.w, params.h, params.m);
}
2024-03-31 05:36:11 +02:00
static draw = function(_x, _y, _w, _h, _m, spr = THEME.button_def, blend = c_white) {
2023-11-07 06:01:38 +01:00
x = _x;
y = _y;
w = _w;
h = _h;
var cx = x + w / 2;
var cy = y + h / 2;
2024-03-28 14:18:02 +01:00
hovering = false;
2023-11-07 06:01:38 +01:00
2024-05-17 15:25:01 +02:00
var spacing = 9;
2023-11-07 06:01:38 +01:00
for( var i = -1; i <= 1; i++ )
for( var j = -1; j <= 1; j++ ) {
if(!center && i == 0 && j == 0) continue;
2024-05-17 15:25:01 +02:00
var _bx = cx + j * spacing;
var _by = cy + i * spacing;
var _in = (i + 1) * 3 + (j + 1);
var _fil = is_array(index)? index[_in] : _in == index;
2023-11-07 06:01:38 +01:00
var hov = hover && point_in_rectangle(_m[0], _m[1], _bx - 4, _by - 4, _bx + 4, _by + 4);
var cc = hov? COLORS._main_accent : COLORS._main_icon;
2024-05-17 15:25:01 +02:00
var aa = 0.75 + (_fil || hov) * 0.25;
2023-11-07 06:01:38 +01:00
2024-05-17 15:25:01 +02:00
draw_sprite_ext(THEME.prop_anchor, _fil, _bx, _by, 1, 1, 0, cc, aa);
2023-11-07 06:01:38 +01:00
2024-03-28 14:18:02 +01:00
if(hov) {
hovering = true;
if(mouse_click(mb_left, active))
onClick(_in);
}
2023-11-07 06:01:38 +01:00
}
resetFocus();
return _h;
}
2024-03-31 11:10:14 +02:00
static clone = function() { #region
2024-05-17 15:25:01 +02:00
var cln = new buttonAnchor(onClick);
2024-03-31 11:10:14 +02:00
return cln;
} #endregion
2023-11-07 06:01:38 +01:00
}