From 741a77c8a7760dd27c67dd42c952696fd2f210a7 Mon Sep 17 00:00:00 2001 From: Tanasart Date: Sun, 2 Jun 2024 09:15:18 +0700 Subject: [PATCH] - [IsoSurf] Add per surface offset property. --- scripts/draw_rect_border/draw_rect_border.gml | 17 +++ scripts/dynaSurf_iso/dynaSurf_iso.gml | 12 +-- scripts/node_data/node_data.gml | 23 ++-- scripts/node_isosurf/node_isosurf.gml | 101 ++++++++++++++++-- scripts/node_value/node_value.gml | 13 +++ scripts/panel_inspector/panel_inspector.gml | 4 +- scripts/surfaceBox/surfaceBox.gml | 12 ++- 7 files changed, 153 insertions(+), 29 deletions(-) diff --git a/scripts/draw_rect_border/draw_rect_border.gml b/scripts/draw_rect_border/draw_rect_border.gml index f70401c2e..2eddbc5e6 100644 --- a/scripts/draw_rect_border/draw_rect_border.gml +++ b/scripts/draw_rect_border/draw_rect_border.gml @@ -1,6 +1,23 @@ function draw_rectangle_border(x1, y1, x2, y2, thick) { + INLINE draw_line_width(x1 - thick / 2, y1, x2 + thick / 2, y1, thick); draw_line_width(x1 - thick / 2, y2, x2 + thick / 2, y2, thick); draw_line_width(x1, y1 - thick / 2, x1, y2 + thick / 2, thick); draw_line_width(x2, y1 - thick / 2, x2, y2 + thick / 2, thick); +} + +function ui_rect(x1, y1, x2, y2, color, alpha = 1) { + INLINE draw_sprite_stretched_ext(THEME.menu_button_mask, 1, x1, y1, x2 - x1, y2 - y1, color, 1); +} + +function ui_rect_wh(x1, y1, w, h, color, alpha = 1) { + INLINE draw_sprite_stretched_ext(THEME.menu_button_mask, 1, x1, y1, w, h, color, 1); +} + +function ui_fill_rect(x1, y1, x2, y2, color, alpha = 1) { + INLINE draw_sprite_stretched_ext(THEME.menu_button_mask, 0, x1, y1, x2 - x1, y2 - y1, color, 1); +} + +function ui_fill_rect_wh(x1, y1, w, h, color, alpha = 1) { + INLINE draw_sprite_stretched_ext(THEME.menu_button_mask, 0, x1, y1, w, h, color, 1); } \ No newline at end of file diff --git a/scripts/dynaSurf_iso/dynaSurf_iso.gml b/scripts/dynaSurf_iso/dynaSurf_iso.gml index 950dac398..3e47d69b8 100644 --- a/scripts/dynaSurf_iso/dynaSurf_iso.gml +++ b/scripts/dynaSurf_iso/dynaSurf_iso.gml @@ -23,12 +23,12 @@ function dynaSurf_iso() : dynaSurf() constructor { static draw = function(_x = 0, _y = 0, _xs = 1, _ys = 1, _rot = 0, _col = c_white, _alp = 1) { var _ind = getIndex(_rot); var _surf = array_get(surfaces, _ind); - var _offx = array_get(offsetx, _ind); - var _offy = array_get(offsety, _ind); + var _offx = array_get(offsetx, _ind) * _xs; + var _offy = array_get(offsety, _ind) * _ys; var _pos = getAbsolutePos(_x, _y, _xs, _ys, _rot); - draw_surface_ext_safe(_surf, _pos[0] + _offx, _pos[1] + _offy, _xs, _ys, 0, _col, _alp); + draw_surface_ext_safe(_surf, _pos[0] - _offx, _pos[1] - _offy, _xs, _ys, 0, _col, _alp); } static drawTile = function(_x = 0, _y = 0, _xs = 1, _ys = 1, _col = c_white, _alp = 1) { @@ -39,10 +39,10 @@ function dynaSurf_iso() : dynaSurf() constructor { static drawPart = function(_l, _t, _w, _h, _x, _y, _xs = 1, _ys = 1, _rot = 0, _col = c_white, _alp = 1) { var _ind = getIndex(_rot); var _surf = array_get(surfaces, _ind); - var _offx = array_get(offsetx, _ind); - var _offy = array_get(offsety, _ind); + var _offx = array_get(offsetx, _ind) * _xs; + var _offy = array_get(offsety, _ind) * _ys; - draw_surface_part_ext_safe(_surf, _l, _t, _w, _h, _x + _offx, _y + _offy, _xs, _ys, 0, _col, _alp); + draw_surface_part_ext_safe(_surf, _l, _t, _w, _h, _x - _offx, _y - _offy, _xs, _ys, 0, _col, _alp); } static clone = function() { diff --git a/scripts/node_data/node_data.gml b/scripts/node_data/node_data.gml index db27c90df..f371c6bfd 100644 --- a/scripts/node_data/node_data.gml +++ b/scripts/node_data/node_data.gml @@ -1529,7 +1529,12 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor { var _sw = __preview_sw; var _sh = __preview_sh; var _ss = min(bbox.w / _sw, bbox.h / _sh); - draw_surface_ext_safe(preview_surface, bbox.xc - _sw * _ss / 2, bbox.yc - _sh * _ss / 2, _ss, _ss); + + var _ps = preview_surface; + if(is_struct(_ps) && is_instanceof(_ps, dynaSurf)) + _ps = array_safe_get_fast(_ps.surfaces, 0, noone); + + draw_surface_ext_safe(_ps, bbox.xc - _sw * _ss / 2, bbox.yc - _sh * _ss / 2, _ss, _ss); } #endregion static getNodeDimension = function(showFormat = true) { #region @@ -1738,15 +1743,15 @@ function Node(_x, _y, _group = noone) : __Node_Base(_x, _y) constructor { static getPreviewValues = function() { #region if(preview_channel >= ds_list_size(outputs)) return noone; - switch(outputs[| preview_channel].type) { - case VALUE_TYPE.surface : - case VALUE_TYPE.dynaSurface : - break; - default : - return noone; - } + var _type = outputs[| preview_channel].type; + if(_type != VALUE_TYPE.surface && _type != VALUE_TYPE.dynaSurface) + return noone; - return outputs[| preview_channel].getValue(); + var val = outputs[| preview_channel].getValue(); + if(is_struct(val) && is_instanceof(val, dynaSurf)) + val = array_safe_get_fast(val.surfaces, 0, noone); + + return val; } #endregion static getPreviewBoundingBox = function() { #region diff --git a/scripts/node_isosurf/node_isosurf.gml b/scripts/node_isosurf/node_isosurf.gml index 861db6cea..d4a87052a 100644 --- a/scripts/node_isosurf/node_isosurf.gml +++ b/scripts/node_isosurf/node_isosurf.gml @@ -1,7 +1,8 @@ function Node_IsoSurf(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) constructor { name = "IsoSurf"; - inputs[| 0] = nodeValue("Direction", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 4); + inputs[| 0] = nodeValue("Direction", self, JUNCTION_CONNECT.input, VALUE_TYPE.integer, 4) + .setRange(1, undefined); inputs[| 1] = nodeValue("Surfaces", self, JUNCTION_CONNECT.input, VALUE_TYPE.surface, noone) .setVisible(true, true) @@ -20,6 +21,7 @@ function Node_IsoSurf(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c outputs[| 0] = nodeValue("IsoSurf", self, JUNCTION_CONNECT.output, VALUE_TYPE.dynaSurface, noone); + knob_select = noone; knob_hover = noone; knob_dragging = noone; drag_sv = 0; @@ -65,17 +67,26 @@ function Node_IsoSurf(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c draw_surface_ext(_surf, _knx - _sw * _ss / 2, _kny - _sh * _ss / 2, _ss, _ss, 0, c_white, 1); } - draw_set_color(COLORS._main_text_sub); - draw_rectangle(_knx - 16, _kny - 16, _knx + 16, _kny + 16, true); + var cc = COLORS._main_icon; + if(i == knob_hover) cc = COLORS._main_icon_light; + if(i == knob_select) cc = COLORS._main_accent; + + ui_rect_wh(_knx - 20, _kny - 20, 40, 40, cc); + + if(point_in_rectangle(_m[0], _m[1], _knx - 20, _kny - 20, _knx + 20, _kny + 20)) + _khover = i; } knob_hover = _khover; + if(mouse_press(mb_left, _focus) && point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + hh)) + knob_select = knob_hover; + if(knob_dragging == noone) { if(knob_hover >= 0 && mouse_press(mb_left, _focus)) { knob_dragging = knob_hover; drag_sv = _angle[knob_hover]; - drag_sa = _angle[knob_hover]; + drag_sa = point_direction(_kx, _ky, _m[0], _m[1]); } } else { var delta = angle_difference(point_direction(_kx, _ky, _m[0], _m[1]), drag_sa); @@ -92,21 +103,97 @@ function Node_IsoSurf(_x, _y, _group = noone) : Node_Processor(_x, _y, _group) c return hh; }); #endregion + offsetRenderer = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) { #region + var hh = ui(160); + var _surfs = getInputData(1); + var _offs = getInputData(4); + + draw_sprite_stretched_ext(THEME.ui_panel_bg, 1, _x, _y, _w, hh, COLORS.node_composite_bg_blend, 1); + + if(!is_array(_surfs) || !is_array(_offs)) return hh; + if(knob_select == noone) return hh; + + var surf = array_safe_get(_surfs, knob_select); + if(!is_surface(surf)) return hh; + + var amo = array_length(_surfs); + var _off = array_safe_get(_offs, knob_select); + + var pd = ui(8); + var sw = _w - pd * 2; + var sh = hh - pd * 2; + var srw = surface_get_width(surf); + var srh = surface_get_height(surf); + var ss = min((sw - pd) / srw, (sh - pd) / srh); + + var sx = _x + _w / 2 - srw * ss / 2; + var sy = _y + hh / 2 - srh * ss / 2; + + ui_fill_rect_wh(sx, sy, srw * ss, srh * ss, CDEF.main_dkblack); + draw_surface_ext(surf, sx, sy, ss, ss, 0, c_white, 1); + + if(point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + hh)) { + var _mx = clamp(value_snap((_m[0] - sx) / ss, 0.5), 0, srw); + var _my = clamp(value_snap((_m[1] - sy) / ss, 0.5), 0, srh); + + draw_set_text(f_p3, fa_right, fa_bottom, COLORS._main_text_sub); + draw_text(_x + _w - 4, _y + hh - 4, $"{_mx}, {_my}"); + + var _ox = sx + _mx * ss - 1; + var _oy = sy + _my * ss - 1; + + draw_set_color(CDEF.main_dkgrey); + draw_line(sx, _oy, sx + srw * ss, _oy); + draw_line(_ox, sy, _ox, sy + srh * ss); + + if(mouse_click(mb_left, _focus)) { + _offs[knob_select][0] = _mx; + _offs[knob_select][1] = _my; + + inputs[| 4].setValue(_offs); + } + } + + ui_rect_wh(sx, sy, srw * ss, srh * ss, COLORS._main_icon); + + if(!is_array(_off)) return hh; + var _ox = sx + _off[0] * ss - 1; + var _oy = sy + _off[1] * ss - 1; + + draw_set_color(c_white); + draw_line_width(_ox - 4, _oy, _ox + 4, _oy, 2); + draw_line_width(_ox, _oy - 4, _ox, _oy + 4, 2); + + return hh; + }); #endregion + input_display_list = [ - ["Iso", false], 0, 2, angle_renderer, + ["Iso", false], 0, 2, angle_renderer, offsetRenderer, ["Data", false], 1, 4, ]; + static resetOffset = function() { + var _amo = getInputData(0); + var _off = array_create(_amo); + + for( var i = 0, n = _amo; i < n; i++ ) + _off[i] = [ 0, 0 ]; + + inputs[| 4].setValue(_off); + } + static onValueUpdate = function(index) { if(index != 0) return; var _amo = getInputData(0); + var _off = getInputData(4); + var _ang = array_create(_amo); - var _off = array_create(_amo); + array_resize(_off, _amo); for( var i = 0, n = _amo; i < n; i++ ) { _ang[i] = 360 * (i / _amo); - _off[i] = [ 0, 0 ]; + _off[i] = array_verify(_off[i], 2); } inputs[| 3].setValue(_ang); diff --git a/scripts/node_value/node_value.gml b/scripts/node_value/node_value.gml index 1ec596bac..e93307b76 100644 --- a/scripts/node_value/node_value.gml +++ b/scripts/node_value/node_value.gml @@ -125,6 +125,9 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru node.input_value_map[$ internalName] = _value; __curr_get_val = [ 0, 0 ]; + + value_range_min = undefined; + value_range_max = undefined; #endregion #region ---- draw ---- @@ -302,6 +305,13 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru return self; } #endregion + static setRange = function(_min, _max) { #region + value_range_min = _min; + value_range_max = _max; + + return self; + } #endregion + static rejectArray = function() { #region accept_array = false; return self; @@ -1041,6 +1051,9 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru value[i] = clamp(value[i], 0, 8192); } + if(value_range_min != undefined) value = max(value, value_range_min); + if(value_range_max != undefined) value = min(value, value_range_max); + return value; } #endregion diff --git a/scripts/panel_inspector/panel_inspector.gml b/scripts/panel_inspector/panel_inspector.gml index 6414c1422..0a62fc6f5 100644 --- a/scripts/panel_inspector/panel_inspector.gml +++ b/scripts/panel_inspector/panel_inspector.gml @@ -833,7 +833,7 @@ function Panel_Inspector() : PanelContent() constructor { prop_highlight = noone; } - return hh + ui(64); + return hh; } #endregion contentPane = new scrollPane(content_w, content_h, function(_y, _m) { #region @@ -880,7 +880,7 @@ function Panel_Inspector() : PanelContent() constructor { _hh += _h; } - return _hh; + return _hh + ui(64); }); #endregion function propSelectCopy() { #region diff --git a/scripts/surfaceBox/surfaceBox.gml b/scripts/surfaceBox/surfaceBox.gml index 7886005ce..e8ed4226d 100644 --- a/scripts/surfaceBox/surfaceBox.gml +++ b/scripts/surfaceBox/surfaceBox.gml @@ -86,9 +86,12 @@ function surfaceBox(_onModify, def_path = "") : widget() constructor { if(is_instanceof(_surface, __d3dMaterial)) _surface = _surface.surface; - if(is_surface(_surface)) { - var sfw = surface_get_width_safe(_surface); - var sfh = surface_get_height_safe(_surface); + if(is_instanceof(_surface, dynaSurf)) + _surface = array_safe_get_fast(_surface.surfaces, 0, noone); + + if(surface_exists(_surface)) { + var sfw = surface_get_width(_surface); + var sfh = surface_get_height(_surface); var ss = min(sw / sfw, sh / sfh); var _sx = sx0 + sw / 2 - ss * sfw / 2; var _sy = sy0 + sh / 2 - ss * sfh / 2; @@ -114,8 +117,7 @@ function surfaceBox(_onModify, def_path = "") : widget() constructor { draw_text_add(sx1 - ui(3), sy1 + ui(1), _txt); } - draw_set_color(COLORS.widget_surface_frame); - draw_rectangle(sx0, sy0, sx1 - 1, sy1 - 1, true); + ui_rect(sx0, sy0, sx1, sy1, COLORS.widget_surface_frame); if(_type == VALUE_TYPE.surface) draw_sprite_ui_uniform(THEME.scroll_box_arrow, 0, _x + _w - min(_h / 2, ui(20)), _y + _h / 2, min(1, _h / 64), COLORS._main_icon, 0.5 + 0.5 * interactable);