- [scatter] anchor point

This commit is contained in:
Tanasart 2024-10-03 17:20:00 +07:00
parent 4e0d0a552f
commit db1af35899
14 changed files with 124 additions and 121 deletions

View file

@ -1,6 +1,6 @@
/// @description init
#region pos
var hght = line_get_height(f_p0, 8);
var hght = line_get_height(font, 8);
var hh = array_length(arrayBox.data) * hght;
dialog_h = min(max_h, hh);

View file

@ -2,21 +2,23 @@
event_inherited();
#region
max_h = 640;
align = fa_left;
draggable = false;
destroy_on_click_out = true;
max_h = 640;
align = fa_left;
draggable = false;
selecting = -1;
font = f_p1;
arrayBox = noone;
anchor = ANCHOR.top | ANCHOR.left;
sc_content = new scrollPane(0, 0, function(_y, _m) {
draw_clear_alpha(COLORS.panel_bg_clear, 0);
var hght = line_get_height(f_p0, 8);
var _h = array_length(arrayBox.data) * hght;
var _dw = sc_content.surface_w;
draw_clear(COLORS.panel_bg_clear);
var hght = line_get_height(font, 8);
var _h = array_length(arrayBox.data) * hght;
var _dw = sc_content.surface_w;
var array = arrayBox.arraySet;
for(var i = 0; i < array_length(arrayBox.data); i++) {
@ -48,13 +50,12 @@ event_inherited();
}
}
var bs = ui(22);
var bs = hght - ui(8);
draw_sprite_stretched(THEME.checkbox_def, ind, ui(20) - bs / 2, yc - bs / 2, bs, bs);
if(exists)
draw_sprite_stretched_ext(THEME.checkbox_def, 2, ui(20) - bs / 2, yc - bs / 2, bs, bs, COLORS._main_accent, 1);
if(exists) draw_sprite_stretched_ext(THEME.checkbox_def, 2, ui(20) - bs / 2, yc - bs / 2, bs, bs, COLORS._main_accent, 1);
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text);
draw_text_cut(ui(40), yc, arrayBox.data[i], _dw);
draw_set_text(font, fa_left, fa_center, COLORS._main_text);
draw_text(ui(40), yc, arrayBox.data[i]);
}
if(sFOCUS) {

View file

@ -1,17 +1,10 @@
function nodeValue_Vector(_name, _node, _value, _data = {}) {
var _len = array_length(_value);
switch(_len) {
case 2 : return new NodeValue_Vec2(_name, _node, _value, _data);
case 3 : return new NodeValue_Vec3(_name, _node, _value, _data);
case 4 : return new NodeValue_Vec4(_name, _node, _value, _data);
}
return new NodeValue_Array(_name, _node, _value, "", _len);
return new NodeValue_Array(_name, _node, _value, "", -1);
}
function NodeValue_Array(_name, _node, _value, _tooltip = "", _length = 2) : NodeValue(_name, _node, CONNECT_TYPE.input, VALUE_TYPE.float, _value, _tooltip) constructor {
type_array = 1;
def_length = _length;
/////============== GET =============
@ -22,9 +15,11 @@ function NodeValue_Array(_name, _node, _value, _tooltip = "", _length = 2) : Nod
var _d = array_get_depth(val);
if(_d == 0) return array_create(def_length, val);
if(_d == 1) return array_verify(val, def_length);
if(_d == 2) return array_map(val, function(v, i) /*=>*/ {return array_verify(v, def_length)});
if(def_length > -1) {
if(_d == 0) return array_create(def_length, val);
if(_d == 1) return array_verify(val, def_length);
if(_d == 2) return array_map(val, function(v, i) /*=>*/ {return array_verify(v, def_length)});
}
return val;
}

View file

@ -24,10 +24,8 @@ function line_get_width(txt, font = noone, offset = 0) {
#macro TEXTBOX_HEIGHT line_get_height(f_p1, 6)
#macro BUTTON_HEIGHT line_get_height(f_p1, 12)
function ui(val) {
INLINE
return round(val * UI_SCALE);
}
function ui(val) { INLINE return round(val * UI_SCALE); }
function _ui(val) { INLINE return val / UI_SCALE; }
function resetScale(scale, willResize = false) {
if(PREFERENCES.display_scaling == scale) return;

View file

@ -116,7 +116,7 @@
#macro DELTA_TIME delta_time / 1_000_000
#macro INLINE gml_pragma("forceinline");
#macro IS is_instanceof
#macro is is_instanceof
#macro CONF_TESTING false
globalvar TESTING, TEST_ERROR;

View file

@ -139,14 +139,13 @@ function Node_Array(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
}
static update = function(frame = CURRENT_FRAME) {
var spd = getInputData(1);
var _typ = getType();
var res = [];
var ind = 0;
var spd = getInputData(1);
for( var i = input_fix_len; i < array_length(inputs); i++ ) {
var val = getInputData(i);
// if(is_array(val)) val = array_clone(val);
if(is_array(val) && spd) array_append(res, val);
else array_push(res, val);

View file

@ -452,6 +452,7 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor {
}
static refreshDynamicDisplay = function() {
if(array_empty(input_display_dynamic)) return;
array_resize(input_display_list, array_length(input_display_list_raw));
var _amo = getInputAmount();

View file

@ -122,7 +122,7 @@ function Node_Repeat(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co
newOutput(0, nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone));
typeList = [ "Transform", "Blending" ];
typeList = [ "Linear Transform", "Blending" ];
static createNewInput = function() {
var _index = array_length(inputs);
@ -163,6 +163,9 @@ function Node_Repeat(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co
newInput(_index + 14, nodeValue_Surface("Selection surface", self, noone));
newInput(_index + 15, nodeValue_Float("Strength", self, 0))
.setDisplay(VALUE_DISPLAY.slider, { range : [ -1, 1, 0.01 ] });
refreshDynamicDisplay();
return inputs[_index];
}
@ -229,7 +232,7 @@ function Node_Repeat(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co
input_display_dynamic = [
["Selection", false], 1, 9, 10, 11, 12, 13, 14,
["Effects", false], 0, 2, 3, 4, 5, 6, 7, 8,
["Effects", false], 0, 2, 3, 4, 5, 6, 7, 8, 15,
];
input_display_list = [
@ -245,7 +248,7 @@ function Node_Repeat(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co
animator_renderer,
];
setDynamicInput(15, false);
setDynamicInput(16, false);
attribute_surface_depth();
attribute_interpolation();
@ -360,6 +363,7 @@ function Node_Repeat(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co
inputs[_ind + 6].setVisible(_prop == 0);
inputs[_ind + 7].setVisible(_prop == 1);
inputs[_ind + 8].setVisible(_prop == 1);
// inputs[_ind + 15].setVisible(_prop == 2);
inputs[_ind + 9].setVisible(_selc == 1);
inputs[_ind + 10].setVisible(_selc == 0);
@ -506,6 +510,7 @@ function Node_Repeat(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co
var _an_sfal = _data[_ii + 12];
var _an_sfcr = _data[_ii + 13];
var _an_ssrf = _data[_ii + 14];
// var _an_strn = _data[_ii + 15];
var _inf = 0;
var _ax = 0, _ay = 0;
@ -531,54 +536,55 @@ function Node_Repeat(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) co
_inf = eval_curve_x(_an_sfcr, _inf);
if(_inf == 0) continue;
if(_an_prop == 0) { // transform
_x += _inf * _an_posi[0];
_y += _inf * _an_posi[1];
var _dr = _inf * _an_rota;
if(_dr != 0) {
_a.rot += _dr;
switch(_an_prop) {
case 0 : // transform
_x += _inf * _an_posi[0];
_y += _inf * _an_posi[1];
if(_an_anct == 0) { // global
_ax = _an_ancp[0];
_ay = _an_ancp[1];
var _dr = _inf * _an_rota;
if(_dr != 0) {
_a.rot += _dr;
} else if(_an_anct == 1) { // local
_ax = _x + _an_ancp[0] * _sw;
_ay = _y + _an_ancp[1] * _sh;
if(_an_anct == 0) { // global
_ax = _an_ancp[0];
_ay = _an_ancp[1];
} else if(_an_anct == 1) { // local
_ax = _x + _an_ancp[0] * _sw;
_ay = _y + _an_ancp[1] * _sh;
}
__temp_p = point_rotate(_x, _y, _ax, _ay, _dr, __temp_p);
_x = __temp_p[0];
_y = __temp_p[1];
}
__temp_p = point_rotate(_x, _y, _ax, _ay, _dr, __temp_p);
_x = __temp_p[0];
_y = __temp_p[1];
}
var _dsx = _inf * _an_scal[0];
var _dsy = _inf * _an_scal[1];
if(_dsx != 0 || _dsy != 0) {
if(_an_anct == 0) { // global
_ax = _an_ancp[0];
_ay = _an_ancp[1];
var _dsx = _inf * _an_scal[0];
var _dsy = _inf * _an_scal[1];
if(_dsx != 0 || _dsy != 0) {
if(_an_anct == 0) { // global
_ax = _an_ancp[0];
_ay = _an_ancp[1];
} else if(_an_anct == 1) { // local
_ax = _x + (_an_ancp[0] - .5) * _sw;
_ay = _y + (_an_ancp[1] - .5) * _sh;
}
} else if(_an_anct == 1) { // local
_ax = _x + (_an_ancp[0] - .5) * _sw;
_ay = _y + (_an_ancp[1] - .5) * _sh;
_a.sx += _inf * _an_scal[0];
_a.sy += _inf * _an_scal[1];
_x += _dsx * (_x - _ax);
_y += _dsy * (_y - _ay);
}
break;
_a.sx += _inf * _an_scal[0];
_a.sy += _inf * _an_scal[1];
_x += _dsx * (_x - _ax);
_y += _dsy * (_y - _ay);
}
} else if(_an_prop == 1) { // blending
_a.color = merge_color(_a.color, _an_colr, _inf);
_a.alpha += _inf * _an_alph;
case 1 :
_a.color = merge_color(_a.color, _an_colr, _inf);
_a.alpha += _inf * _an_alph;
break;
}
}

View file

@ -9,7 +9,6 @@ enum NODE_SCATTER_DIST {
function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor {
name = "Scatter";
batch_output = false;
dimension_index = 1;
newInput(0, nodeValue_Surface("Surface in", self));
@ -55,8 +54,8 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
newInput(16, nodeValue_Bool("Multiply alpha", self, true));
newInput(17, nodeValue_Text("Use value", self, [ "Scale" ], "Apply the third value in each data point (if exist) on given properties."))
.setDisplay(VALUE_DISPLAY.text_array, { data: [ "Scale", "Rotation", "Color" ] });
newInput(17, nodeValue_Text("Use extra value", self, [ "Scale" ], "Apply the third value in each data point (if exist) on given properties."))
.setDisplay(VALUE_DISPLAY.text_array, { data: [ "Scale", "Rotation", "Color" ] });
newInput(18, nodeValue_Enum_Scroll("Blend mode", self, 0, [ "Normal", "Add", "Max" ]));
@ -108,6 +107,25 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
newInput(39, nodeValue_Range("Shift radial", self, [ 0, 0 ]));
newInput(40, nodeValue_Vec2("Anchor", self, [ 0.5, 0.5 ]))
.setDisplay(VALUE_DISPLAY.vector, {
side_button : new buttonAnchor(function(ind) {
switch(ind) {
case 0 : inputs[40].setValue([ 0.0, 0.0 ]); break;
case 1 : inputs[40].setValue([ 0.5, 0.0 ]); break;
case 2 : inputs[40].setValue([ 1.0, 0.0 ]); break;
case 3 : inputs[40].setValue([ 0.0, 0.5 ]); break;
case 4 : inputs[40].setValue([ 0.5, 0.5 ]); break;
case 5 : inputs[40].setValue([ 1.0, 0.5 ]); break;
case 6 : inputs[40].setValue([ 0.0, 1.0 ]); break;
case 7 : inputs[40].setValue([ 0.5, 1.0 ]); break;
case 8 : inputs[40].setValue([ 1.0, 1.0 ]); break;
}
})
});
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
newOutput(0, nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone));
@ -120,7 +138,7 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
["Surfaces", true], 0, 1, 15, 24, 25, 26, 27,
["Scatter", false], 6, 5, 13, 14, 17, 9, 31, 2, 30, 35,
["Path", false], 19, 38, 20, 21, 22,
["Position", false], 33, 36, 37, 39,
["Position", false], 40, 33, 36, 37, 39,
["Rotation", false], 7, 4, 32,
["Scale", false], 3, 8, 34,
["Render", false], 18, 11, 28, 12, 16, 23,
@ -218,13 +236,8 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
////=========== PROCESS ===========
static processData = function(_outSurf, _data, _output_index, _array_index) {
if(_output_index == 1) return scatter_data;
static processData = function(_outData, _data, _output_index, _array_index) {
var _inSurf = _data[0];
if(_inSurf == 0)
return;
var _dim = _data[1];
var _amount = _data[2];
var _scale = _data[3];
@ -271,15 +284,18 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
var posExt = _data[37];
var pthSpac = _data[38];
var shfRad = _data[39];
var anchor = _data[40];
var _in_w, _in_h;
var _outSurf = _outData[0];
var vSca = array_exists(useV, "Scale");
var vRot = array_exists(useV, "Rotation");
var vCol = array_exists(useV, "Color");
var surfArray = is_array(_inSurf);
if(surfArray && array_empty(_inSurf)) return;
if(surfArray && array_empty(_inSurf)) return _outData;
#region cache value
ds_map_clear(surface_size_map);
@ -302,11 +318,9 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
var _posDist = [];
if(_dist == NODE_SCATTER_DIST.map) {
if(!is_surface(_distMap))
return _outSurf;
// if(scatter_map != _distMap || scatter_maps != seed || scatter_mapa != _amount)
scatter_mapp = get_points_from_dist(_distMap, _amount, seed);
return _outData;
scatter_mapp = get_points_from_dist(_distMap, _amount, seed);
scatter_map = _distMap;
scatter_maps = seed;
scatter_mapa = _amount;
@ -321,7 +335,7 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
} else if(_dist == NODE_SCATTER_DIST.path) { // Path
var path_valid = path != noone && struct_has(path, "getPointRatio");
if(!path_valid) return _outSurf;
if(!path_valid) return _outData;
var _pathProgress = 0;
var path_amount = struct_has(path, "getLineCount")? path.getLineCount() : 1;
@ -539,8 +553,8 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
if(surfArray) {
switch(_arr) {
case 1 : ind = safe_mod(i, _arrLen); break;
case 2 : ind = irandom(_arrLen - 1); break;
case 1 : ind = safe_mod(i, _arrLen); break;
case 2 : ind = irandom(_arrLen - 1); break;
case 3 : ind = array_safe_get_fast(arrId, i, 0); break;
case 4 : if(useArrTex) ind = colorBrightness(surface_get_pixel(arrTex, _x, _y)) * (_arrLen - 1); break;
}
@ -571,11 +585,15 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
var sw = dim[0];
var sh = dim[1];
var _shf_x = sw * _scx * anchor[0];
var _shf_y = sh * _scy * anchor[1];
if(_r == 0) {
_x -= sw * _scx / 2;
_y -= sh * _scy / 2;
_x -= _shf_x;
_y -= _shf_y;
} else {
_p = point_rotate(_x - sw / 2 * _scx, _y - sh * _scy / 2, _x, _y, _r, _p);
_p = point_rotate(_x - _shf_x, _y - _shf_y, _x, _y, _r, _p);
_x = _p[0];
_y = _p[1];
}
@ -622,7 +640,7 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
}
array_resize(_sct, _sct_len);
if(sortY) array_sort(_sct, function(a1, a2) { return a1.y - a2.y; });
if(sortY) array_sort(_sct, function(a1, a2) /*=>*/ {return a1.y - a2.y});
for( var i = 0; i < _sct_len; i++ ) {
var _atl = _sct[i];
@ -659,6 +677,6 @@ function Node_Scatter(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c
scatter_data = _sct;
return _outSurf;
return [ _outSurf, _sct ];
}
}

View file

@ -150,26 +150,8 @@ function Node_Transform(_x, _y, _group = noone) : Node_Processor(_x, _y, _group)
}
static step = function() {
var pos = getSingleValue(2);
var anc = getSingleValue(3);
var _b = inputs[3].editWidget.side_button;
var _a = anc[0] * 2 + anc[1] * 20;
switch(_a) {
case 0 : _b.index = 0; break;
case 1 : _b.index = 1; break;
case 2 : _b.index = 2; break;
case 10 : _b.index = 3; break;
case 11 : _b.index = 4; break;
case 12 : _b.index = 5; break;
case 20 : _b.index = 6; break;
case 21 : _b.index = 7; break;
case 22 : _b.index = 8; break;
default : _b.index = -1;
}
if(!PROJECT.animator.frame_progress) return;
var pos = getSingleValue(2);
if(IS_FIRST_FRAME) {
vel = 0;

View file

@ -383,11 +383,11 @@
cont.split = _panel.split;
if(_panel.split == "h") {
ind = _panel.childs[1].w < _panel.childs[0].w;
cont.width = _panel.childs[ind].w * (_panel.childs[ind].x == _panel.x? 1 : -1);
cont.width = _ui(_panel.childs[ind].w * (_panel.childs[ind].x == _panel.x? 1 : -1));
} else {
ind = _panel.childs[1].h < _panel.childs[0].h;
cont.width = _panel.childs[ind].h * (_panel.childs[ind].y == _panel.y? 1 : -1);
cont.width = _ui(_panel.childs[ind].h * (_panel.childs[ind].y == _panel.y? 1 : -1));
}
ind = _panel.childs[1].x == _panel.x && _panel.childs[1].y == _panel.y;

View file

@ -862,7 +862,7 @@ function Panel_Inspector() : PanelContent() constructor {
while(j < _len) {
var j_jun = _inspecting.input_display_list[j];
if(is_array(j_jun)) break;
if(IS(j_jun, Inspector_Spacer) && !j_jun.coll) break;
if(is(j_jun, Inspector_Spacer) && !j_jun.coll) break;
j++;
}

View file

@ -50,6 +50,7 @@ function textArrayBox(arraySet, data, onModify = noone) : widget() constructor {
with(dialogCall(o_dialog_arrayBox, _rx + _x, _ry + _y + th)) {
arrayBox = other;
dialog_w = other.w;
font = other.font;
}
}
} else if(!hide)
@ -69,7 +70,7 @@ function textArrayBox(arraySet, data, onModify = noone) : widget() constructor {
}
draw_sprite_stretched_ext(THEME.s_box_r5_clr, 0, tx, ty, ww, hh, COLORS._main_icon, 1);
draw_text(tx + ui(8), ty + hh / 2, arraySet[i]);
draw_text_add(tx + ui(8), ty + hh / 2, arraySet[i]);
tx += ww + ui(2);
}

View file

@ -114,6 +114,8 @@ function vectorBox(_size, _onModify, _unit = noone) : widget() constructor {
if((_w - _bs) / sz > ui(48)) {
if(side_button) {
if(is(side_button, buttonAnchor))
side_button.index = round(array_safe_get(_data, 0) * 2 + array_safe_get(_data, 1) * 6);
side_button.setFocusHover(active, hover);
side_button.draw(_x + _w - _bs, _y + _h / 2 - _bs / 2, _bs, _bs, _m, THEME.button_hide);
_w -= _bs + ui(4);
@ -139,7 +141,7 @@ function vectorBox(_size, _onModify, _unit = noone) : widget() constructor {
onModify(_data[0], 1);
}
}
_x += _bs + ui(4);
_w -= _bs + ui(4);
}