2023-01-17 08:11:55 +01:00
|
|
|
function rotator(_onModify, _step = -1) : widget() constructor {
|
2022-01-13 05:24:03 +01:00
|
|
|
onModify = _onModify;
|
2022-12-16 09:18:09 +01:00
|
|
|
step = _step;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-03-05 07:16:44 +01:00
|
|
|
scale = 1;
|
2022-01-13 05:24:03 +01:00
|
|
|
dragging = false;
|
|
|
|
drag_sv = 0;
|
|
|
|
drag_sa = 0;
|
|
|
|
real_val = 0;
|
|
|
|
|
2023-03-05 07:16:44 +01:00
|
|
|
spr_bg = THEME.rotator_bg;
|
|
|
|
spr_knob = THEME.rotator_knob;
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
tb_value = new textBox(TEXTBOX_INPUT.number, onModify);
|
2023-02-14 05:32:32 +01:00
|
|
|
tb_value.slidable = true;
|
|
|
|
tb_value.slide_speed = 1;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-01-25 06:49:00 +01:00
|
|
|
static setInteract = function(interactable = noone) {
|
|
|
|
self.interactable = interactable;
|
|
|
|
tb_value.interactable = interactable;
|
|
|
|
}
|
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
static register = function(parent = noone) {
|
|
|
|
tb_value.register(parent);
|
|
|
|
}
|
|
|
|
|
2023-03-05 07:16:44 +01:00
|
|
|
static draw = function(_x, _y, _data, _m, draw_tb = true) {
|
2023-01-17 08:11:55 +01:00
|
|
|
x = _x;
|
|
|
|
y = _y;
|
|
|
|
w = 0;
|
2023-06-23 15:39:24 +02:00
|
|
|
h = ui(64);
|
2023-01-17 08:11:55 +01:00
|
|
|
|
2023-06-04 12:38:40 +02:00
|
|
|
if(!is_real(_data)) return;
|
2023-06-23 15:39:24 +02:00
|
|
|
var knob_y = _y + h / 2;
|
|
|
|
var _r = ui(28);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-03-05 07:16:44 +01:00
|
|
|
if(draw_tb) {
|
2023-06-21 20:36:53 +02:00
|
|
|
tb_value.setFocusHover(active, hover);
|
2023-03-05 07:16:44 +01:00
|
|
|
tb_value.draw(_x + ui(64), knob_y - ui(17), ui(64), TEXTBOX_HEIGHT, _data, _m);
|
|
|
|
}
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-06-23 15:39:24 +02:00
|
|
|
draw_sprite(spr_bg, 0, _x, knob_y);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-06-23 15:39:24 +02:00
|
|
|
draw_set_color(COLORS.widget_rotator_guide);
|
|
|
|
draw_line(_x, knob_y, _x + lengthdir_x(ui(20), _data) - 1, knob_y + lengthdir_y(ui(20), _data) - 1);
|
|
|
|
|
|
|
|
var px = _x + lengthdir_x(_r, _data);
|
|
|
|
var py = knob_y + lengthdir_y(_r, _data);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
if(dragging) {
|
|
|
|
var delta = angle_difference(point_direction(_x, knob_y, _m[0], _m[1]), drag_sa);
|
|
|
|
var val;
|
|
|
|
var real_val = round(delta + drag_sv);
|
|
|
|
|
2022-12-22 03:09:55 +01:00
|
|
|
if(key_mod_press(CTRL))
|
2022-01-13 05:24:03 +01:00
|
|
|
val = round(real_val / 15) * 15;
|
|
|
|
else
|
|
|
|
val = real_val;
|
|
|
|
|
2022-12-16 09:18:09 +01:00
|
|
|
if(step != -1)
|
|
|
|
val = round(real_val / step) * step;
|
|
|
|
|
2023-06-23 15:39:24 +02:00
|
|
|
draw_sprite(spr_knob, 1, px, py);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
if(val != drag_sv) {
|
2023-02-14 05:32:32 +01:00
|
|
|
if(onModify(val))
|
|
|
|
UNDO_HOLDING = true;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
drag_sa = point_direction(_x, knob_y, _m[0], _m[1]);
|
|
|
|
drag_sv = real_val;
|
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
if(mouse_release(mb_left)) {
|
2022-01-13 05:24:03 +01:00
|
|
|
dragging = false;
|
2022-12-16 09:18:09 +01:00
|
|
|
UNDO_HOLDING = false;
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2023-06-23 15:39:24 +02:00
|
|
|
} else if(hover && point_in_circle(_m[0], _m[1], _x, knob_y, _r + ui(16))) {
|
|
|
|
draw_sprite(spr_knob, 1, px, py);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-12-10 05:06:01 +01:00
|
|
|
if(mouse_press(mb_left, active)) {
|
2022-01-13 05:24:03 +01:00
|
|
|
dragging = true;
|
|
|
|
drag_sv = _data;
|
|
|
|
drag_sa = point_direction(_x, knob_y, _m[0], _m[1]);
|
|
|
|
}
|
|
|
|
} else {
|
2023-06-23 15:39:24 +02:00
|
|
|
draw_sprite(spr_knob, 0, px, py);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
2023-06-23 15:39:24 +02:00
|
|
|
//draw_set_text(f_p0, fa_center, fa_center, COLORS._main_text);
|
|
|
|
//draw_text(_x, knob_y, string(_data));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2023-01-17 08:11:55 +01:00
|
|
|
resetFocus();
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
}
|