Pixel-Composer/scripts/sliderRange/sliderRange.gml

92 lines
3.0 KiB
Plaintext
Raw Normal View History

2024-03-24 04:58:08 +01:00
function sliderRange(_step, _int, _range, _onModify) : widget() constructor {
stepSize = _step;
2024-03-31 11:10:14 +02:00
slide_range = _range;
2024-03-24 04:58:08 +01:00
isInt = _int;
2024-03-31 11:10:14 +02:00
curr_range = [ _range[0], _range[1] ];
2022-01-13 05:24:03 +01:00
onModify = _onModify;
2024-07-26 09:38:39 +02:00
tb_value_min = new textBox(TEXTBOX_INPUT.number, function(val) /*=>*/ {return onModify(clamp(val, curr_range[0], curr_range[1]), 0)})
2024-07-28 13:55:57 +02:00
.setSlideType(_int).setSlideStep(_step).setSlideRange(_range[0], _range[1]);
2024-07-26 09:38:39 +02:00
tb_value_max = new textBox(TEXTBOX_INPUT.number, function(val) /*=>*/ {return onModify(clamp(val, curr_range[0], curr_range[1]), 1)})
2024-07-28 13:55:57 +02:00
.setSlideType(_int).setSlideStep(_step).setSlideRange(_range[0], _range[1]);
2022-01-13 05:24:03 +01:00
2024-03-24 04:58:08 +01:00
tb_value_min.hide = true;
tb_value_max.hide = true;
2023-02-14 05:32:32 +01:00
static setInteract = function(interactable = noone) {
2023-01-25 06:49:00 +01:00
self.interactable = interactable;
tb_value_min.interactable = interactable;
tb_value_max.interactable = interactable;
}
2023-01-25 06:49:00 +01:00
static register = function(parent = noone) {
2023-01-17 08:11:55 +01:00
tb_value_min.register(parent);
tb_value_max.register(parent);
}
2023-01-17 08:11:55 +01:00
2024-03-28 14:18:02 +01:00
static isHovering = function() { return tb_value_min.hovering || tb_value_max.hovering; }
static drawParam = function(params) {
2024-03-27 11:51:14 +01:00
setParam(params);
tb_value_min.setParam(params);
tb_value_max.setParam(params);
2024-03-26 04:03:45 +01:00
2023-07-30 19:56:53 +02:00
return draw(params.x, params.y, params.w, params.h, params.data, params.m);
}
2023-07-30 19:56:53 +02:00
static draw = function(_x, _y, _w, _h, _data, _m) {
2023-01-17 08:11:55 +01:00
x = _x;
y = _y;
w = _w;
h = _h;
2023-12-05 09:51:24 +01:00
if(!is_real(_data[0])) return h;
if(!is_real(_data[1])) return h;
2023-01-17 08:11:55 +01:00
draw_sprite_stretched_ext(THEME.textbox, 3, _x, _y, _w, _h, boxColor, 1);
2022-01-13 05:24:03 +01:00
2024-03-24 04:58:08 +01:00
var _minn = slide_range[0];
var _maxx = slide_range[1];
var _rang = abs(_maxx - _minn);
var _currMin = min(_data[0], _data[1]);
var _currMax = max(_data[0], _data[1]);
if(tb_value_min.sliding != 2 && tb_value_max.sliding != 2) {
curr_range[0] = (_currMin >= _minn)? _minn : _minn - ceil(abs(_currMin - _minn) / _rang) * _rang;
curr_range[1] = (_currMax <= _maxx)? _maxx : _maxx + ceil(abs(_currMax - _maxx) / _rang) * _rang;
2023-12-05 09:51:24 +01:00
}
2024-03-24 04:58:08 +01:00
var lx = _w * ((_currMin ) - curr_range[0]) / (curr_range[1] - curr_range[0]);
2024-03-24 04:58:08 +01:00
var lw = _w * ((_currMax - _currMin) - curr_range[0]) / (curr_range[1] - curr_range[0]);
2023-12-05 09:51:24 +01:00
draw_sprite_stretched_ext(THEME.textbox, 4, _x + lx, _y, lw, _h, boxColor, 1);
2022-01-13 05:24:03 +01:00
2024-03-24 04:58:08 +01:00
var tb_w = _w / 2;
2022-01-13 05:24:03 +01:00
2024-07-26 09:38:39 +02:00
if(tb_value_min.selecting || tb_value_max.selecting)
draw_sprite_stretched_ext(THEME.textbox, 1, _x, _y, _w, _h, boxColor, 1);
2024-07-26 09:38:39 +02:00
else
draw_sprite_stretched_ext(THEME.textbox, 0, _x, _y, _w, _h, boxColor, 0.5 + 0.5 * interactable);
2022-01-13 05:24:03 +01:00
tb_value_min.curr_range[0] = curr_range[0];
tb_value_min.curr_range[1] = curr_range[1];
2024-03-24 04:58:08 +01:00
tb_value_min.setFocusHover(active, hover);
tb_value_min.draw(_x, _y, tb_w, _h, _data[0], _m);
tb_value_max.curr_range[0] = curr_range[0];
tb_value_max.curr_range[1] = curr_range[1];
2024-03-24 04:58:08 +01:00
tb_value_max.setFocusHover(active, hover);
tb_value_max.draw(_x + tb_w, _y, tb_w, _h, _data[1], _m);
2023-07-30 19:56:53 +02:00
return h;
}
2024-03-31 11:10:14 +02:00
static clone = function() {
2024-03-31 11:10:14 +02:00
var cln = new sliderRange(stepSize, isInt, slide_range, onModify);
return cln;
}
2022-01-13 05:24:03 +01:00
}