Pixel-Composer/scripts/rotatorRange/rotatorRange.gml

135 lines
3.8 KiB
Plaintext
Raw Normal View History

2023-01-17 08:11:55 +01:00
function rotatorRange(_onModify) : widget() constructor {
2022-01-13 05:24:03 +01:00
onModify = _onModify;
2023-12-05 09:51:24 +01:00
dragging_index = -1;
dragging = noone;
2022-01-13 05:24:03 +01:00
drag_sv = 0;
drag_dat = [ 0, 0 ];
2022-01-13 05:24:03 +01:00
2024-02-10 07:03:50 +01:00
knob_hovering = noone;
2024-03-27 11:51:14 +01:00
tb_min = new textBox(TEXTBOX_INPUT.number, function(val) { return onModify(0, val); } ).setSlidable([ 0.1, 15 ], true); tb_min.hide = true;
tb_max = new textBox(TEXTBOX_INPUT.number, function(val) { return onModify(1, val); } ).setSlidable([ 0.1, 15 ], true); tb_max.hide = true;
2023-01-17 08:11:55 +01:00
2023-12-05 09:51:24 +01:00
static setInteract = function(interactable = noone) { #region
2023-01-25 06:49:00 +01:00
self.interactable = interactable;
tb_min.interactable = interactable;
tb_max.interactable = interactable;
2023-12-05 09:51:24 +01:00
} #endregion
2023-01-25 06:49:00 +01:00
2023-12-05 09:51:24 +01:00
static register = function(parent = noone) { #region
2023-01-25 06:49:00 +01:00
tb_min.register(parent);
tb_max.register(parent);
2023-12-05 09:51:24 +01:00
} #endregion
2023-01-25 06:49:00 +01:00
2024-03-28 14:18:02 +01:00
static isHovering = function() { return dragging || tb_min.hovering || tb_max.hovering; }
2023-12-05 09:51:24 +01:00
static drawParam = function(params) { #region
2024-03-27 11:51:14 +01:00
setParam(params);
tb_min.setParam(params);
tb_max.setParam(params);
2024-03-26 04:03:45 +01:00
return draw(params.x, params.y, params.w, params.h, params.data, params.m);
2023-12-05 09:51:24 +01:00
} #endregion
2023-07-30 19:56:53 +02:00
2024-03-26 04:03:45 +01:00
static draw = function(_x, _y, _w, _h, _data, _m) { #region
2023-01-17 08:11:55 +01:00
x = _x;
y = _y;
2023-07-30 19:56:53 +02:00
w = _w;
2024-03-26 04:03:45 +01:00
h = _h;
2023-07-30 19:56:53 +02:00
2023-06-04 12:38:40 +02:00
if(!is_real(_data[0])) return;
if(!is_real(_data[1])) return;
2023-08-24 11:59:05 +02:00
2024-03-26 04:03:45 +01:00
var _r = _h;
2024-03-29 05:20:49 +01:00
var _drawRot = _w - _r > ui(64);
var _tx = _drawRot? _x + _r + ui(4) : _x;
var _tw = _drawRot? _w - _r - ui(4) : _w;
2022-01-13 05:24:03 +01:00
2024-03-26 04:03:45 +01:00
draw_sprite_stretched_ext(THEME.textbox, 3, _tx, _y, _tw, _h, c_white, 1);
draw_sprite_stretched_ext(THEME.textbox, 0, _tx, _y, _tw, _h, c_white, 0.5 + 0.5 * interactable);
2023-01-17 08:11:55 +01:00
2024-03-29 05:20:49 +01:00
_tw /= 2;
2023-01-17 08:11:55 +01:00
2024-03-26 04:03:45 +01:00
tb_min.setFocusHover(active, hover);
2024-03-29 05:20:49 +01:00
tb_min.draw(_tx, _y, _tw, _h, _data[0], _m);
2023-06-23 15:39:24 +02:00
2024-03-26 04:03:45 +01:00
tb_max.setFocusHover(active, hover);
2024-03-29 05:20:49 +01:00
tb_max.draw(_tx + _tw, _y, _tw, _h, _data[1], _m);
2023-06-23 15:39:24 +02:00
2024-03-29 05:20:49 +01:00
if(_drawRot) {
var _kx = _x + _r / 2;
var _ky = _y + _r / 2;
var _kr = (_r - ui(12)) / 2;
var _kc = COLORS._main_icon;
2022-01-13 05:24:03 +01:00
2024-03-29 05:20:49 +01:00
if(dragging_index) {
_kc = COLORS._main_icon_light;
2022-01-13 05:24:03 +01:00
2024-03-29 05:20:49 +01:00
var val = point_direction(_kx, _ky, _m[0], _m[1]);
if(key_mod_press(CTRL)) val = round(val / 15) * 15;
2022-01-13 05:24:03 +01:00
2024-03-29 05:20:49 +01:00
var val, real_val;
var modi = false;
2022-01-13 05:24:03 +01:00
2024-03-29 05:20:49 +01:00
real_val[0] = round(dragging.delta_acc + drag_sv[0]);
real_val[1] = round(dragging.delta_acc + drag_sv[1]);
2022-01-13 05:24:03 +01:00
2024-03-29 05:20:49 +01:00
val = key_mod_press(CTRL)? round(real_val[0] / 15) * 15 : real_val[0];
modi |= onModify(0, val);
2022-01-13 05:24:03 +01:00
2024-03-29 05:20:49 +01:00
val = key_mod_press(CTRL)? round(real_val[1] / 15) * 15 : real_val[1];
modi |= onModify(1, val);
2022-11-21 06:38:44 +01:00
2024-03-29 05:20:49 +01:00
if(modi) UNDO_HOLDING = true;
MOUSE_BLOCK = true;
2024-01-16 11:00:39 +01:00
2024-03-29 05:20:49 +01:00
if(mouse_check_button_pressed(mb_right)) {
for( var i = 0; i < 2; i++ ) onModify(i, drag_dat[i]);
2024-03-29 05:20:49 +01:00
instance_destroy(rotator_Rotator);
dragging = noone;
dragging_index = -1;
UNDO_HOLDING = false;
2024-01-16 11:00:39 +01:00
2024-03-29 05:20:49 +01:00
} else if(mouse_release(mb_left)) {
instance_destroy(rotator_Rotator);
dragging = noone;
dragging_index = -1;
UNDO_HOLDING = false;
}
2024-02-10 07:03:50 +01:00
2024-03-29 05:20:49 +01:00
} else if(hover && point_in_rectangle(_m[0], _m[1], _x, _y, _x + _r, _y + _r)) {
_kc = COLORS._main_icon_light;
2024-03-26 04:03:45 +01:00
2024-03-29 05:20:49 +01:00
if(mouse_press(mb_left, active)) {
dragging_index = 1;
drag_sv = [ _data[0], _data[1] ];
drag_dat = [ _data[0], _data[1] ];
dragging = instance_create(0, 0, rotator_Rotator).init(_m, _kx, _ky);
}
2022-01-13 05:24:03 +01:00
}
2024-03-29 05:20:49 +01:00
draw_set_color(CDEF.main_dkgrey);
draw_circle_angle(_kx, _ky, _kr, _data[0], _data[1], 32);
2024-03-26 04:03:45 +01:00
2024-03-29 05:20:49 +01:00
shader_set(sh_widget_rotator_range);
shader_set_f("side", _r);
shader_set_color("color", _kc);
shader_set_f("angle", degtorad(_data[0]), degtorad(_data[1]));
2024-02-10 07:03:50 +01:00
2024-03-29 05:20:49 +01:00
draw_sprite_stretched(s_fx_pixel, 0, _x, _y, _r, _r);
shader_reset();
}
2024-03-26 04:03:45 +01:00
2023-01-17 08:11:55 +01:00
resetFocus();
2023-07-30 19:56:53 +02:00
return h;
2023-12-05 09:51:24 +01:00
} #endregion
2024-03-31 11:10:14 +02:00
static clone = function() { #region
var cln = new rotatorRange(onModify);
return cln;
} #endregion
2022-01-13 05:24:03 +01:00
}