2022-01-13 05:24:03 +01:00
|
|
|
function rotatorRange(_onModify) constructor {
|
|
|
|
active = false;
|
|
|
|
hover = false;
|
|
|
|
|
|
|
|
onModify = _onModify;
|
|
|
|
|
|
|
|
dragging = -1;
|
|
|
|
drag_sv = 0;
|
|
|
|
drag_sa = 0;
|
2022-11-21 06:38:44 +01:00
|
|
|
drag_sc = 0;
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-01-24 02:21:25 +01:00
|
|
|
static draw = function(_x, _y, _data, _m) {
|
2022-11-03 11:44:49 +01:00
|
|
|
var knob_y = _y + ui(48);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_sprite_ui_uniform(THEME.rotator_bg, 0, _x, knob_y);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
#region draw arc
|
|
|
|
var hover_arc = false;
|
|
|
|
var diss = point_distance(_m[0], _m[1], _x, knob_y);
|
2022-11-18 03:20:31 +01:00
|
|
|
if(diss >= ui(32) && diss <= ui(40) || dragging == 2)
|
2022-01-13 05:24:03 +01:00
|
|
|
hover_arc = true;
|
|
|
|
|
2022-11-01 03:06:03 +01:00
|
|
|
var ans = _data[0] % 360;
|
|
|
|
var ane = _data[1] % 360;
|
|
|
|
|
|
|
|
var diff = ane >= ans? ane - ans : ane + 360 - ans;
|
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_color(COLORS.widget_rotator_range);
|
2022-11-01 03:06:03 +01:00
|
|
|
for(var i = 0; i < abs(diff); i += 4) {
|
|
|
|
var as = ans + i * sign(diff);
|
|
|
|
var ae = ans + (i + 4) * sign(diff);
|
|
|
|
|
2022-11-03 11:44:49 +01:00
|
|
|
var sx = _x + lengthdir_x(ui(36), as);
|
|
|
|
var sy = knob_y + lengthdir_y(ui(36), as);
|
|
|
|
var ex = _x + lengthdir_x(ui(36), ae);
|
|
|
|
var ey = knob_y + lengthdir_y(ui(36), ae);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_alpha(0.5 + 0.5 * hover_arc);
|
2022-11-03 11:44:49 +01:00
|
|
|
draw_line_width(sx, sy, ex, ey, ui(8));
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_alpha(1);
|
|
|
|
|
2022-11-03 11:44:49 +01:00
|
|
|
draw_circle(ex, ey, ui(4), 0);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
var px, py;
|
|
|
|
|
|
|
|
for(var i = 0; i < 2; i++) {
|
2022-11-03 11:44:49 +01:00
|
|
|
px[i] = _x + lengthdir_x(ui(36), _data[i]);
|
|
|
|
py[i] = knob_y + lengthdir_y(ui(36), _data[i]);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_sprite_ui_uniform(THEME.rotator_knob, 0, px[i], py[i]);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(dragging > -1) {
|
|
|
|
var val = point_direction(_x, knob_y, _m[0], _m[1]);
|
|
|
|
if(keyboard_check(vk_control)) val = round(val / 15) * 15;
|
|
|
|
|
|
|
|
var delta = angle_difference(point_direction(_x, knob_y, _m[0], _m[1]), drag_sa);
|
|
|
|
var val, real_val;
|
|
|
|
|
|
|
|
if(dragging == 2) {
|
|
|
|
real_val[0] = round(delta + drag_sv[0]);
|
|
|
|
val = keyboard_check(vk_control)? round(real_val[0] / 15) * 15 : real_val[0];
|
|
|
|
onModify(0, val);
|
|
|
|
|
|
|
|
real_val[1] = round(delta + drag_sv[1]);
|
|
|
|
val = keyboard_check(vk_control)? round(real_val[1] / 15) * 15 : real_val[1];
|
|
|
|
onModify(1, val);
|
|
|
|
|
|
|
|
UNDO_HOLDING = true;
|
|
|
|
} else {
|
2022-11-21 06:38:44 +01:00
|
|
|
var _o = _data[dragging];
|
2022-01-13 05:24:03 +01:00
|
|
|
real_val = round(delta + drag_sv);
|
|
|
|
val = keyboard_check(vk_control)? round(real_val / 15) * 15 : real_val;
|
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_sprite_ui_uniform(THEME.rotator_knob, 1, px[dragging], py[dragging]);
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
if(_data[dragging] != val) {
|
|
|
|
onModify(dragging, val);
|
2022-11-21 06:38:44 +01:00
|
|
|
|
|
|
|
if(keyboard_check(vk_alt)) {
|
|
|
|
var dt = val - _o;
|
|
|
|
onModify(!dragging, _data[!dragging] - dt);
|
|
|
|
}
|
|
|
|
|
2022-01-13 05:24:03 +01:00
|
|
|
UNDO_HOLDING = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
drag_sv = real_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 = -1;
|
|
|
|
UNDO_HOLDING = false;
|
|
|
|
}
|
|
|
|
} else if(hover) {
|
|
|
|
for(var i = 0; i < 2; i++) {
|
2022-11-03 11:44:49 +01:00
|
|
|
if(point_in_circle(_m[0], _m[1], px[i], py[i], ui(10))) {
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_sprite_ui_uniform(THEME.rotator_knob, 1, px[i], py[i]);
|
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 = i;
|
|
|
|
drag_sv = _data[i];
|
|
|
|
drag_sa = point_direction(_x, knob_y, _m[0], _m[1]);
|
2022-11-21 06:38:44 +01:00
|
|
|
drag_sc = lerp_angle(_data[0], _data[1], 0.5);
|
2022-01-13 05:24:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-10 05:06:01 +01:00
|
|
|
if(dragging == -1 && hover_arc && mouse_press(mb_left, active)) {
|
2022-01-13 05:24:03 +01:00
|
|
|
dragging = 2;
|
|
|
|
drag_sv = _data;
|
|
|
|
drag_sa = point_direction(_x, knob_y, _m[0], _m[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-18 03:20:31 +01:00
|
|
|
draw_set_text(f_p0, fa_center, fa_center, COLORS._main_text);
|
2022-11-03 11:44:49 +01:00
|
|
|
draw_text(_x, knob_y - ui(12), string(_data[0]));
|
|
|
|
draw_text(_x, knob_y + ui(12), string(_data[1]));
|
2022-01-13 05:24:03 +01:00
|
|
|
|
|
|
|
active = false;
|
|
|
|
hover = false;
|
|
|
|
}
|
|
|
|
}
|