- [ScrollPane] Add scrolling support for pen input.

This commit is contained in:
Tanasart 2024-07-17 14:02:36 +07:00
parent 16dd84477d
commit 07d18167bc
7 changed files with 229 additions and 194 deletions

View file

@ -21,12 +21,10 @@ function checkBoxActive(_onClick) : widget() constructor {
var bx = x + w / 2 - bw / 2;
var by = y;
draw_sprite_stretched_ext(spr, _value, bx - 8, by - 8, bw + 16, bh + 16, c_white, 1);
draw_sprite_stretched_ext(spr, _value, bx - 8, by - 8, bw + 16, bh + 16);
if(hover && point_in_rectangle(_m[0], _m[1], bx, by, bx + bw, by + bh)) {
BLEND_ADD
draw_sprite_stretched_ext(THEME.slider_def, 3, bx, by, bw, bh, COLORS._main_icon_dark, 1);
BLEND_NORMAL
draw_sprite_stretched_add(spr, _value, bx - 8, by - 8, bw + 16, bh + 16, COLORS._main_icon_dark);
if(mouse_press(mb_left, active))
trigger();
@ -39,16 +37,11 @@ function checkBoxActive(_onClick) : widget() constructor {
draw_text_add(bx + bw / 2, by + bh / 2, _value? "ACTIVE" : "INACTIVE");
if(WIDGET_CURRENT == self)
draw_sprite_stretched_ext(THEME.widget_selecting, 0, bx - ui(3), by - ui(3), bw + ui(6), bh + ui(6), COLORS._main_accent, 1);
draw_sprite_stretched_ext(THEME.widget_selecting, 0, bx - ui(3), by - ui(3), bw + ui(6), bh + ui(6), COLORS._main_accent);
resetFocus();
return h;
}
static clone = function() { #region
var cln = new checkBoxActive(onClick);
return cln;
} #endregion
static clone = function() { return new checkBoxActive(onClick); }
}

View file

@ -2380,15 +2380,11 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor {
jun.value_to = [];
}
for( var i = 0; i < ds_list_size(inputs); i++ )
inputs[| i].destroy();
for( var i = 0; i < ds_list_size(outputs); i++ )
outputs[| i].destroy();
for( var i = 0; i < ds_list_size( inputs); i++ ) inputs[| i].destroy();
for( var i = 0; i < ds_list_size(outputs); i++ ) outputs[| i].destroy();
onDestroy();
if(group) group.refreshNodes();
if(group) group.refreshNodes();
if(record) recordAction(ACTION_TYPE.node_delete, self);
RENDER_ALL_REORDER

View file

@ -1,12 +1,12 @@
function Node_Path_Array(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
name = "Path Array";
setDimension(96, 48);;
name = "Path Combine";
setDimension(96, 48);
cached_pos = ds_map_create();
outputs[| 0] = nodeValue("Path array", self, JUNCTION_CONNECT.output, VALUE_TYPE.pathnode, self);
outputs[| 0] = nodeValue("Combined Path", self, JUNCTION_CONNECT.output, VALUE_TYPE.pathnode, self);
static createNewInput = function() { #region
static createNewInput = function() {
var index = ds_list_size(inputs);
inputs[| index] = nodeValue("Path", self, JUNCTION_CONNECT.input, VALUE_TYPE.pathnode, noone )
@ -15,16 +15,16 @@ function Node_Path_Array(_x, _y, _group = noone) : Node(_x, _y, _group) construc
return inputs[| index];
} setDynamicInput(1, true, VALUE_TYPE.pathnode);
static getLineCount = function() { #region
static getLineCount = function() {
var l = 0;
for( var i = input_fix_len; i < ds_list_size(inputs); i += data_length ) {
var _path = getInputData(i);
l += struct_has(_path, "getLineCount")? _path.getLineCount() : 1;
}
return l;
} #endregion
}
static getSegmentCount = function(ind = 0) { #region
static getSegmentCount = function(ind = 0) {
for( var i = input_fix_len; i < ds_list_size(inputs); i += data_length ) {
var _path = getInputData(i);
var lc = struct_has(_path, "getLineCount")? _path.getLineCount() : 1;
@ -34,9 +34,9 @@ function Node_Path_Array(_x, _y, _group = noone) : Node(_x, _y, _group) construc
}
return 0;
} #endregion
}
static getLength = function(ind = 0) { #region
static getLength = function(ind = 0) {
for( var i = input_fix_len; i < ds_list_size(inputs); i += data_length ) {
var _path = getInputData(i);
var lc = struct_has(_path, "getLineCount")? _path.getLineCount() : 1;
@ -46,9 +46,9 @@ function Node_Path_Array(_x, _y, _group = noone) : Node(_x, _y, _group) construc
}
return 0;
} #endregion
}
static getAccuLength = function(ind = 0) { #region
static getAccuLength = function(ind = 0) {
for( var i = input_fix_len; i < ds_list_size(inputs); i += data_length ) {
var _path = getInputData(i);
var lc = struct_has(_path, "getLineCount")? _path.getLineCount() : 1;
@ -58,9 +58,9 @@ function Node_Path_Array(_x, _y, _group = noone) : Node(_x, _y, _group) construc
}
return 0;
} #endregion
}
static getPointRatio = function(_rat, ind = 0) { #region
static getPointRatio = function(_rat, ind = 0) {
for( var i = input_fix_len; i < ds_list_size(inputs); i += data_length ) {
var _path = getInputData(i);
var lc = struct_has(_path, "getLineCount")? _path.getLineCount() : 1;
@ -70,9 +70,9 @@ function Node_Path_Array(_x, _y, _group = noone) : Node(_x, _y, _group) construc
}
return new __vec2();
} #endregion
}
static getPointDistance = function(_dist, ind = 0) { #region
static getPointDistance = function(_dist, ind = 0) {
for( var i = input_fix_len; i < ds_list_size(inputs); i += data_length ) {
var _path = getInputData(i);
var lc = struct_has(_path, "getLineCount")? _path.getLineCount() : 1;
@ -82,9 +82,9 @@ function Node_Path_Array(_x, _y, _group = noone) : Node(_x, _y, _group) construc
}
return new __vec2();
} #endregion
}
static getBoundary = function(ind = 0) { #region
static getBoundary = function(ind = 0) {
for( var i = input_fix_len; i < ds_list_size(inputs); i += data_length ) {
var _path = getInputData(i);
var lc = struct_has(_path, "getLineCount")? _path.getLineCount() : 1;
@ -94,19 +94,19 @@ function Node_Path_Array(_x, _y, _group = noone) : Node(_x, _y, _group) construc
}
return 0;
} #endregion
}
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
for( var i = input_fix_len; i < ds_list_size(inputs); i += data_length ) {
var _path = getInputData(i);
if(!struct_has(_path, "drawOverlay")) continue;
if(_path && struct_has(_path, "drawOverlay")) _path.drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
}
} #endregion
}
static update = function(frame = CURRENT_FRAME) { #region
static update = function(frame = CURRENT_FRAME) {
ds_map_clear(cached_pos);
outputs[| 0].setValue(self);
} #endregion
}
}

View file

@ -10,7 +10,7 @@ function L_Turtle(x = 0, y = 0, ang = 90, w = 1, color = c_white, itr = 0) const
static clone = function() { return new L_Turtle(x, y, ang, w, color, itr); }
}
function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
function Node_Path_L_System(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "L System";
setDimension(96, 48);
@ -95,7 +95,6 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const
["Properties", false], 0, 1, 7,
["Rules", false], 3, 4, rule_renderer, 5,
];
lines = [];
attributes.rule_length_limit = 10000;
array_push(attributeEditors, "L System");
@ -106,9 +105,6 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const
triggerRender();
}) ]);
current_length = 0;
boundary = new BoundingBox();
cache_data = {
start : "",
rules : {},
@ -147,14 +143,17 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const
if(index > input_fix_len && !LOADING && !APPENDING)
refreshDynamicInput();
}
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
inputs[| 2].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
var _out = getSingleValue(0, preview_index, true);
if(!is_struct(_out)) return;
draw_set_color(COLORS._main_accent);
for( var i = 0, n = array_length(lines); i < n; i++ ) {
var p0 = lines[i][0];
var p1 = lines[i][1];
for( var i = 0, n = array_length(_out.lines); i < n; i++ ) {
var p0 = _out.lines[i][0];
var p1 = _out.lines[i][1];
var x0 = p0[0];
var y0 = p0[1];
@ -170,44 +169,54 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const
}
}
static getLineCount = function() { return array_length(lines); }
static getSegmentCount = function() { return 1; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static getLength = function() { return current_length; }
static getAccuLength = function() { return [ 0, current_length ]; }
static getWeightDistance = function (_dist, _ind = 0) {
return getWeightRatio(_dist / current_length, _ind);
function Path_LSystem() constructor {
lines = [];
current_length = 0;
boundary = new BoundingBox();
static getLineCount = function() { return array_length(lines); }
static getSegmentCount = function() { return 1; }
static getLength = function() { return current_length; }
static getAccuLength = function() { return [ 0, current_length ]; }
static getWeightDistance = function (_dist, _ind = 0) {
return getWeightRatio(_dist / current_length, _ind);
}
static getWeightRatio = function (_rat, _ind = 0) {
var _p0 = lines[_ind][0];
var _p1 = lines[_ind][1];
if(!is_array(_p0) || array_length(_p0) < 2) return 1;
if(!is_array(_p1) || array_length(_p1) < 2) return 1;
return lerp(_p0[2], _p1[2], _rat);
}
static getPointRatio = function(_rat, _ind = 0, out = undefined) {
if(out == undefined) out = new __vec2(); else { out.x = 0; out.y = 0; }
var _p0 = lines[_ind][0];
var _p1 = lines[_ind][1];
if(!is_array(_p0) || array_length(_p0) < 2) return out;
if(!is_array(_p1) || array_length(_p1) < 2) return out;
out.x = lerp(_p0[0], _p1[0], _rat);
out.y = lerp(_p0[1], _p1[1], _rat);
return out;
}
static getPointDistance = function(_dist, _ind = 0, out = undefined) { return getPointRatio(_dist / current_length, _ind, out); }
static getBoundary = function() { return boundary; }
}
static getWeightRatio = function (_rat, _ind = 0) {
var _p0 = lines[_ind][0];
var _p1 = lines[_ind][1];
if(!is_array(_p0) || array_length(_p0) < 2) return 1;
if(!is_array(_p1) || array_length(_p1) < 2) return 1;
return lerp(_p0[2], _p1[2], _rat);
}
static getPointRatio = function(_rat, _ind = 0, out = undefined) {
if(out == undefined) out = new __vec2(); else { out.x = 0; out.y = 0; }
var _p0 = lines[_ind][0];
var _p1 = lines[_ind][1];
if(!is_array(_p0) || array_length(_p0) < 2) return out;
if(!is_array(_p1) || array_length(_p1) < 2) return out;
out.x = lerp(_p0[0], _p1[0], _rat);
out.y = lerp(_p0[1], _p1[1], _rat);
return out;
}
static getPointDistance = function(_dist, _ind = 0, out = undefined) { return getPointRatio(_dist / current_length, _ind, out); }
static getBoundary = function() { return boundary; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static l_system = function(_start, _rules, _end_rule, _iteration, _seed) {
if(isEqual(cache_data.rules, _rules, true)
@ -261,26 +270,29 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const
return cache_data.result;
}
static update = function() {
var _len = getInputData(0);
var _ang = getInputData(1);
var _pos = getInputData(2);
var _itr = getInputData(3);
var _sta = getInputData(4);
var _end = getInputData(5);
var _san = getInputData(6);
var _sad = getInputData(7);
__curr_path = noone;
static processData = function(_outSurf, _data, _output_index, _array_index) {
var _len = _data[0];
var _ang = _data[1];
var _pos = _data[2];
var _itr = _data[3];
var _sta = _data[4];
var _end = _data[5];
var _san = _data[6];
var _sad = _data[7];
lineq = ds_queue_create();
random_set_seed(_sad);
current_length = _len;
__curr_path = new Path_LSystem();
__curr_path.current_length = _len;
if(ds_list_size(inputs) < input_fix_len + 2) return;
if(ds_list_size(inputs) < input_fix_len + 2) return __curr_path;
var rules = {};
for( var i = input_fix_len; i < ds_list_size(inputs); i += data_length ) {
var _name = getInputData(i + 0);
var _rule = getInputData(i + 1);
var _name = _data[i + 0];
var _rule = _data[i + 1];
if(_name == "") continue;
if(!struct_has(rules, _name))
@ -290,11 +302,11 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const
}
l_system(_sta, rules, _end, _itr, _sad);
itr = _itr;
ang = _ang;
len = _len;
st = ds_stack_create();
t = new L_Turtle(_pos[0], _pos[1], _san);
itr = _itr;
ang = _ang;
len = _len;
st = ds_stack_create();
t = new L_Turtle(_pos[0], _pos[1], _san);
maxItr = 0;
string_foreach(cache_data.result, function(_ch, _) {
@ -348,22 +360,22 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const
ds_stack_destroy(st);
boundary = new BoundingBox();
__curr_path.boundary = new BoundingBox();
__curr_path.lines = array_create(ds_queue_size(lineq));
lines = array_create(ds_queue_size(lineq));
var i = 0;
var a = ds_queue_size(lineq);
repeat(a) {
var _l = ds_queue_dequeue(lineq);
lines[i++] = _l;
boundary.addPoint(_l[0][0], _l[0][1], _l[1][0], _l[1][1]);
__curr_path.lines[i++] = _l;
__curr_path.boundary.addPoint(_l[0][0], _l[0][1], _l[1][0], _l[1][1]);
}
ds_queue_destroy(lineq);
outputs[| 0].setValue(self);
return __curr_path;
}
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {

View file

@ -1,4 +1,4 @@
function Node_Path_Scatter(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
function Node_Path_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "Scatter Path";
setDimension(96, 48);
@ -47,90 +47,94 @@ function Node_Path_Scatter(_x, _y, _group = noone) : Node(_x, _y, _group) constr
["Scale", false], 4, 6,
];
cached_pos = ds_map_create();
line_amount = 0;
paths = [];
segment_counts = [];
line_lengths = [];
accu_lengths = [];
__temp_p = [ 0, 0 ];
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
var _path = getInputData(0);
var _path = getSingleValue(0);
if(_path && struct_has(_path, "drawOverlay")) _path.drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
var _path = getInputData(1);
var _path = getSingleValue(1);
if(_path && struct_has(_path, "drawOverlay")) _path.drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
}
static getLineCount = function() { return line_amount; }
static getSegmentCount = function(ind = 0) { return array_safe_get_fast(segment_counts, ind); }
static getLength = function(ind = 0) { return array_safe_get_fast(line_lengths, ind); }
static getAccuLength = function(ind = 0) { return array_safe_get_fast(accu_lengths, ind); }
static getPointRatio = function(_rat, ind = 0, out = undefined) {
if(out == undefined) out = new __vec2(); else { out.x = 0; out.y = 0; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Path_Scatter() constructor {
line_amount = 0;
paths = [];
segment_counts = [];
line_lengths = [];
accu_lengths = [];
var _path = array_safe_get_fast(paths, ind, 0);
if(_path == 0) return out;
__temp_p = [ 0, 0 ];
var _pathObj = _path.path;
if(!is_struct(_pathObj) || !struct_has(_pathObj, "getPointRatio"))
static getLineCount = function() { return line_amount; }
static getSegmentCount = function(ind = 0) { return array_safe_get_fast(segment_counts, ind); }
static getLength = function(ind = 0) { return array_safe_get_fast(line_lengths, ind); }
static getAccuLength = function(ind = 0) { return array_safe_get_fast(accu_lengths, ind); }
static getPointRatio = function(_rat, ind = 0, out = undefined) {
if(out == undefined) out = new __vec2(); else { out.x = 0; out.y = 0; }
var _path = array_safe_get_fast(paths, ind, 0);
if(_path == 0) return out;
var _pathObj = _path.path;
if(!is_struct(_pathObj) || !struct_has(_pathObj, "getPointRatio"))
return out;
var _ind = _path.index;
var _ori = _path.ori;
var _pos = _path.pos;
var _rot = _path.rot;
var _rotW = _path.rotW;
var _sca = _path.sca;
var _trm = _path.trim;
var _flip = _path.flip;
_rat *= _trm;
out = _pathObj.getPointRatio(_rat, _ind, out);
var _px = out.x - _ori[0];
var _py = out.y - _ori[1];
if(_flip && angle_difference(_rotW, 90) < 0)
_px = -_px;
__temp_p = point_rotate(_px, _py, 0, 0, _rot, __temp_p);
out.x = _pos[0] + __temp_p[0] * _sca;
out.y = _pos[1] + __temp_p[1] * _sca;
return out;
var _ind = _path.index;
var _ori = _path.ori;
var _pos = _path.pos;
var _rot = _path.rot;
var _rotW = _path.rotW;
var _sca = _path.sca;
var _trm = _path.trim;
var _flip = _path.flip;
_rat *= _trm;
out = _pathObj.getPointRatio(_rat, _ind, out);
var _px = out.x - _ori[0];
var _py = out.y - _ori[1];
if(_flip && angle_difference(_rotW, 90) < 0)
_px = -_px;
__temp_p = point_rotate(_px, _py, 0, 0, _rot, __temp_p);
out.x = _pos[0] + __temp_p[0] * _sca;
out.y = _pos[1] + __temp_p[1] * _sca;
return out;
}
static getPointDistance = function(_dist, ind = 0, out = undefined) { return getPointRatio(_dist / getLength(ind), ind, out); }
static getBoundary = function(ind = 0) {
var _path = getInputData(0);
return struct_has(_path, "getBoundary")? _path.getBoundary(ind) : new BoundingBox( 0, 0, 1, 1 );
}
static getPointDistance = function(_dist, ind = 0, out = undefined) { return getPointRatio(_dist / getLength(ind), ind, out); }
static getBoundary = function(ind = 0) {
var _path = getInputData(0);
return struct_has(_path, "getBoundary")? _path.getBoundary(ind) : new BoundingBox( 0, 0, 1, 1 );
}
}
static update = function() {
ds_map_clear(cached_pos);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static processData = function(_outSurf, _data, _output_index, _array_index) {
var path_base = getInputData(0);
var path_scat = getInputData(1);
var _range = getInputData(2);
var _repeat = getInputData(3);
var _scale = getInputData(4);
var _seed = getInputData(5);
var _sca_wid = getInputData(6);
var _rotation = getInputData(7);
var _distrib = getInputData(8);
var _trim = getInputData(9);
var _trim_rng = getInputData(10);
var _flip = getInputData(11);
var _resetOri = getInputData(12);
var path_base = _data[ 0];
var path_scat = _data[ 1];
var _range = _data[ 2];
var _repeat = _data[ 3];
var _scale = _data[ 4];
var _seed = _data[ 5];
var _sca_wid = _data[ 6];
var _rotation = _data[ 7];
var _distrib = _data[ 8];
var _trim = _data[ 9];
var _trim_rng = _data[10];
var _flip = _data[11];
var _resetOri = _data[12];
if(path_base == noone) return;
if(path_scat == noone) return;
var _scattered = new Path_Scatter();
if(path_base == noone) return _scattered;
if(path_scat == noone) return _scattered;
var p = new __vec2();
random_set_seed(_seed);
@ -138,16 +142,16 @@ function Node_Path_Scatter(_x, _y, _group = noone) : Node(_x, _y, _group) constr
var _line_amounts = path_scat.getLineCount();
var _ind = 0;
line_amount = _repeat * _line_amounts;
paths = array_create(line_amount);
segment_counts = array_create(line_amount);
line_lengths = array_create(line_amount);
accu_lengths = array_create(line_amount);
_scattered.line_amount = _repeat * _line_amounts;
_scattered.paths = array_create(_scattered.line_amount);
_scattered.segment_counts = array_create(_scattered.line_amount);
_scattered.line_lengths = array_create(_scattered.line_amount);
_scattered.accu_lengths = array_create(_scattered.line_amount);
var ori, pos;
var _prog_raw, _prog;
var x0, y0, x1, y1;
var _dir, _sca, _rot, _rotW, _trm;
var x0, y0, x1, y1;
for (var i = 0; i < _repeat; i++) {
@ -194,7 +198,7 @@ function Node_Path_Scatter(_x, _y, _group = noone) : Node(_x, _y, _group) constr
_dir = point_direction(x0, y0, x1, y1);
_dir += _rot;
paths[_ind] = {
_scattered.paths[_ind] = {
path : path_scat,
index : k,
ori : ori,
@ -215,15 +219,15 @@ function Node_Path_Scatter(_x, _y, _group = noone) : Node(_x, _y, _group) constr
for (var j = 0, m = array_length(_accu_lengths); j < m; j++)
_accu_lengths[j] *= _sca;
segment_counts[_ind] = _segment_counts;
line_lengths[_ind] = _line_lengths;
accu_lengths[_ind] = _accu_lengths;
_scattered.segment_counts[_ind] = _segment_counts;
_scattered.line_lengths[_ind] = _line_lengths;
_scattered.accu_lengths[_ind] = _accu_lengths;
_ind++;
}
}
outputs[| 0].setValue(self);
return _scattered;
}
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {

View file

@ -889,7 +889,7 @@ function __initNodes() {
addNodeObject(values, "Path", s_node_path, "Node_Path", [1, Node_Path]);
addNodeObject(values, "Smooth Path", s_node_path_smooth, "Node_Path_Smooth", [1, Node_Path_Smooth], ["path smooth"]).setVersion(11640);
addNodeObject(values, "Path Anchor", s_node_path_anchor, "Node_Path_Anchor", [1, Node_Path_Anchor]).setVersion(1140);
addNodeObject(values, "Path Array", s_node_path_array, "Node_Path_Array", [1, Node_Path_Array], ["array path"]).setVersion(1137);
addNodeObject(values, "Path Combine", s_node_path_array, "Node_Path_Array", [1, Node_Path_Array], ["array path"]).setVersion(1137);
addNodeObject(values, "Sample Path", s_node_path_sample, "Node_Path_Sample", [1, Node_Path_Sample], ["path sample"], "Sample a 2D position from a path");
addNodeObject(values, "Blend Path", s_node_path_blend, "Node_Path_Blend", [1, Node_Path_Blend],, "Blend between 2 paths.");
addNodeObject(values, "Remap Path", s_node_path_map, "Node_Path_Map_Area", [1, Node_Path_Map_Area],, "Scale path to fit a given area.").setVersion(1130);

View file

@ -24,6 +24,11 @@ function scrollPane(_w, _h, ondraw) : widget() constructor {
is_scrolling = false;
scroll_ms = 0;
pen_scrolling = false;
pen_scroll_my = 0;
pen_scroll_sy = 0;
pen_scroll_py = 0;
static resize = function(_w, _h) {
w = _w;
h = _h;
@ -31,18 +36,19 @@ function scrollPane(_w, _h, ondraw) : widget() constructor {
surface_h = _h;
}
static setScroll = function(_scroll_y) { #region
static setScroll = function(_scroll_y) {
INLINE
scroll_y_to = clamp(_scroll_y, -content_h, 0);
} #endregion
}
static draw = function(x, y, _mx = mouse_mx - x, _my = mouse_my - y) {
self.x = x;
self.y = y;
var mx = _mx, my = _my;
hover &= point_in_rectangle(mx, my, 0, 0, surface_w, surface_h);
hover &= pen_scrolling != 2;
surface = surface_verify(surface, surface_w, surface_h);
surface_set_target(surface);
@ -65,9 +71,33 @@ function scrollPane(_w, _h, ondraw) : widget() constructor {
if(mouse_wheel_down()) scroll_y_to -= scroll_step * SCROLL_SPEED;
if(mouse_wheel_up()) scroll_y_to += scroll_step * SCROLL_SPEED;
}
scroll_lock = false;
if(hover && PEN_USE && mouse_press(mb_left)) {
pen_scrolling = 1;
pen_scroll_my = 0;
}
if(pen_scrolling == 1) {
pen_scroll_my += PEN_Y_DELTA;
if(abs(pen_scroll_my) > 16)
pen_scrolling = 2;
if(mouse_release(mb_left)) pen_scrolling = 0;
} else if(pen_scrolling == 2) {
scroll_y_to = clamp(scroll_y_to + PEN_Y_DELTA * 2, -content_h, 0);
scroll_y_raw = scroll_y_to;
scroll_y = round(scroll_y_raw);
pen_scroll_py = abs(PEN_Y_DELTA) > abs(pen_scroll_py)? PEN_Y_DELTA : lerp_float(pen_scroll_py, PEN_Y_DELTA, 10);
if(mouse_release(mb_left)) pen_scrolling = 0;
} else {
pen_scroll_py = lerp_float(pen_scroll_py, 0, 30, 1);
scroll_y_to += pen_scroll_py;
}
if(show_scroll && (abs(content_h) > 0 || always_scroll)) {
var scr_w = sprite_get_width(THEME.ui_scrollbar);
draw_scroll(x + w - scr_w, y + ui(6), true, surface_h - ui(12), -scroll_y / content_h, surface_h / (surface_h + content_h),