Reduce undo label updater amount.

This commit is contained in:
MakhamDev 2023-10-04 16:28:13 +07:00
parent ac723d1dca
commit b368270cac
8 changed files with 97 additions and 56 deletions

View file

@ -121,15 +121,11 @@ function buttonInstant(spr, _x, _y, _w, _h, _m, _act, _hvr, _tip = "", _icon = n
if(spr) draw_sprite_stretched(spr, 1, _x, _y, _w, _h);
if(_tip != "") TOOLTIP = _tip;
if(mouse_press(mb_left, _act))
res = 2;
if(mouse_press(mb_right, _act))
res = 3;
if(mouse_press(mb_left, _act)) res = 2;
if(mouse_press(mb_right, _act)) res = 3;
if(mouse_release(mb_left, _act))
res = -2;
if(mouse_release(mb_right, _act))
res = -3;
if(mouse_release(mb_left, _act)) res = -2;
if(mouse_release(mb_right, _act)) res = -3;
if(spr && mouse_click(mb_left, _act)) {
draw_sprite_stretched(spr, 2, _x, _y, _w, _h);

View file

@ -52,7 +52,7 @@ function FileObject(_name, _path) constructor {
}
static getSpr = function() {
if(sprite_exists(spr)) return spr;
if(spr != -1) return spr;
if(sprFetchID != noone) return -1;
if(array_length(spr_path) == 0) {
@ -93,9 +93,9 @@ function FileObject(_name, _path) constructor {
static getMetadata = function() {
retrive_data = true;
if(!file_exists(path)) return noone;
if(meta != noone) return meta;
if(meta == undefined) return noone;
if(!file_exists(path)) return noone;
meta = new MetaDataManager();
@ -212,13 +212,12 @@ function DirectoryObject(name, path) constructor {
}
}
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text_inner);
if(ds_list_empty(subDir))
draw_sprite_ui_uniform(THEME.folder_content, parent.context == self, _x + ui(16), _y + hg / 2 - 1, 1, COLORS.collection_folder_empty);
else
draw_sprite_ui_uniform(THEME.folder_content, open, _x + ui(16), _y + hg / 2 - 1, 1, COLORS.collection_folder_nonempty);
draw_set_text(f_p0, fa_left, fa_center, COLORS._main_text_inner);
draw_text(_x + ui(32), _y + hg / 2, name);
hh += hg;
_y += hg;

View file

@ -26,6 +26,7 @@ function line_get_width(txt, font = noone, offset = 0) {
function ui(val) {
gml_pragma("forceinline");
return val * UI_SCALE;
}
#endregion

View file

@ -261,6 +261,7 @@ function recordAction(_type, _object, _data = -1) {
actions[i].destroy();
}
PANEL_MENU.undoUpdate();
return act;
}
@ -276,6 +277,7 @@ function UNDO() {
Render();
ds_stack_push(REDO_STACK, actions);
PANEL_MENU.undoUpdate();
}
function REDO() {
@ -290,4 +292,5 @@ function REDO() {
Render();
ds_stack_push(UNDO_STACK, actions);
PANEL_MENU.undoUpdate();
}

View file

@ -32,6 +32,10 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
inputs[| 11] = nodeValue("Alpha", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1 )
.setDisplay(VALUE_DISPLAY.slider);
inputs[| 12] = nodeValue("Frames animation", self, JUNCTION_CONNECT.input, VALUE_TYPE.boolean, false );
inputs[| 13] = nodeValue("Animation speed", self, JUNCTION_CONNECT.input, VALUE_TYPE.float, 1 );
outputs[| 0] = nodeValue("Surface out", self, JUNCTION_CONNECT.output, VALUE_TYPE.surface, noone);
frame_renderer_x = 0;
@ -74,12 +78,10 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
var _fr_x = 8 - frame_renderer_x;
var _fr_y = 4;
var surfs = outputs[| 0].getValue();
var surfs = output_surface;
var _del = noone;
if(!is_array(surfs)) surfs = [ surfs ];
for( var i = 0, n = array_length(surfs); i < n; i++ ) {
for( var i = 0, n = attributes.frames; i < n; i++ ) {
var _surf = surfs[i];
if(!is_surface(_surf)) continue;
@ -91,7 +93,7 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
var _sx = _fr_x;
var _sy = _fr_y + _fr_h / 2 - _sh * _ss / 2;
draw_surface_ext(_surf, _sx, _sy, _ss, _ss, 0, c_white, 1);
draw_surface_ext(_surf, _sx, _sy, _ss, _ss, 0, c_white, 0.75);
draw_set_color(i == preview_index? COLORS._main_accent : COLORS.panel_toolbar_outline);
draw_rectangle(_sx, _sy, _sx + _sw * _ss, _sy + _sh * _ss, true);
@ -143,7 +145,7 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
}); #endregion
input_display_list = [
["Output", false], 0, frame_renderer,
["Output", false], 0, frame_renderer, 12, 13,
["Brush", false], 6, 2, 1, 11,
["Fill", false], 3, 4,
["Display", false], 8, 10, 9,
@ -152,6 +154,7 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
attributes.frames = 1;
attribute_surface_depth();
output_surface = [ surface_create_empty(1, 1) ];
canvas_surface = [ surface_create_empty(1, 1) ];
canvas_buffer = [ buffer_create(1 * 1 * 4, buffer_fixed, 2) ];
@ -838,6 +841,23 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
mouse_holding = false;
}
}
if(brush_sizing) {
var s = brush_sizing_s + (_mx - brush_sizing_mx) / 16;
s = max(1, s);
inputs[| 2].setValue(s);
if(mouse_release(mb_right))
brush_sizing = false;
} else if(mouse_press(mb_right, active) && key_mod_press(SHIFT) && !is_surface(_brush)) {
brush_sizing = true;
brush_sizing_s = _siz;
brush_sizing_mx = _mx;
brush_sizing_my = _my;
brush_sizing_dx = mouse_cur_x;
brush_sizing_dy = mouse_cur_y;
}
#endregion
} else if(isUsingTool("Fill") || (DRAGGING && DRAGGING.type == "Color")) { #region
var fill = DRAGGING? mouse_release(mb_left, active) : mouse_press(mb_left, active);
@ -901,12 +921,16 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
} else
draw_point_size(mouse_cur_x, mouse_cur_y, _siz, _brush);
} else if(isUsingTool("Rectangle")) {
if(mouse_holding)
if(brush_sizing)
draw_point_size(brush_sizing_dx, brush_sizing_dy, _siz, _brush);
else if(mouse_holding)
draw_rect_size(mouse_pre_x, mouse_pre_y, mouse_cur_x, mouse_cur_y, _siz, isUsingTool("Rectangle", 1), _brush);
else
draw_point_size(mouse_cur_x, mouse_cur_y, _siz, _brush);
} else if(isUsingTool("Ellipse")) {
if(mouse_holding)
if(brush_sizing)
draw_point_size(brush_sizing_dx, brush_sizing_dy, _siz, _brush);
else if(mouse_holding)
draw_ellp_size(mouse_pre_x, mouse_pre_y, mouse_cur_x, mouse_cur_y, _siz, isUsingTool("Ellipse", 1), _brush);
else
draw_point_size(mouse_cur_x, mouse_cur_y, _siz, _brush);
@ -955,11 +979,23 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
previewing = 1;
} #endregion
static step = function() { #region
var fram = attributes.frames;
var anim = getInputData(12);
inputs[| 12].setVisible(fram > 1);
inputs[| 13].setVisible(fram > 1 && anim);
update_on_frame = fram > 1 && anim;
} #endregion
static update = function(frame = PROJECT.animator.current_frame) { #region
var _dim = getInputData(0);
var _bg = getInputData(8);
var _bga = getInputData(9);
var _bgr = getInputData(10);
var _anim = getInputData(12);
var _anims = getInputData(13);
var cDep = attrDepth();
apply_surfaces();
@ -980,28 +1016,36 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
draw_surface_stretched_ext(_bg, 0, 0, _dim[0], _dim[1], c_white, _bga);
draw_surface_safe(_canvas_surface, 0, 0);
surface_reset_shader();
outputs[| 0].setValue(_outSurf);
} else {
if(!is_array(_outSurf))
_outSurf = array_create(attributes.frames);
else if(array_length(_outSurf) != attributes.frames)
array_resize(_outSurf, attributes.frames);
if(!is_array(output_surface))
output_surface = array_create(attributes.frames);
else if(array_length(output_surface) != attributes.frames)
array_resize(output_surface, attributes.frames);
for( var i = 0; i < attributes.frames; i++ ) {
var _canvas_surface = getCanvasSurface(i);
_outSurf[i] = surface_verify(_outSurf[i], _dim[0], _dim[1], cDep);
output_surface[i] = surface_verify(output_surface[i], _dim[0], _dim[1], cDep);
surface_set_shader(_outSurf[i], noone,, BLEND.alpha);
surface_set_shader(output_surface[i], noone,, BLEND.alpha);
if(_bgr && is_surface(_bg))
draw_surface_stretched_ext(_bg, 0, 0, _dim[0], _dim[1], c_white, _bga);
draw_surface_safe(_canvas_surface, 0, 0);
surface_reset_shader();
}
}
outputs[| 0].setValue(_outSurf);
if(_anim) {
var _fr_index = safe_mod(PROJECT.animator.current_frame * _anims, attributes.frames);
outputs[| 0].setValue(output_surface[_fr_index]);
} else
outputs[| 0].setValue(output_surface);
}
} #endregion
static getPreviewValues = function() { return output_surface; }
static doSerialize = function(_map) { #region
surface_store_buffers();
var _buff = array_create(attributes.frames);

View file

@ -164,7 +164,7 @@ function Node_Seperate_Shape(_x, _y, _group = noone) : Node(_x, _y, _group) cons
}
_atlas[i] = [l, t, r, b];
_atlas[i] = new SurfaceAtlas(_outSurf, [ r.x + _spac, r.y + _spac ]);
//_atlas[i] = new SurfaceAtlas(_outSurf, [ r.x + _spac, r.y + _spac ]);
shader_set_surface("original", _inSurf);
shader_set_f("color", red, green, blue, alpha);

View file

@ -30,7 +30,7 @@ function Panel_Collection() : PanelContent() constructor {
updated_prog = 0;
data_path = "";
static initMenu = function() {
static initMenu = function() { #region
if(_menu_node == noone) return;
var meta = _menu_node.getMetadata();
@ -117,7 +117,7 @@ function Panel_Collection() : PanelContent() constructor {
}));
}
}
}
} #endregion
initMenu();
search_string = "";
@ -128,7 +128,7 @@ function Panel_Collection() : PanelContent() constructor {
tb_search.auto_update = true;
contentView = 0;
contentPane = new scrollPane(content_w - ui(6), content_h, function(_y, _m) {
contentPane = new scrollPane(content_w - ui(6), content_h, function(_y, _m) { #region
draw_clear_alpha(COLORS._main_text_inner, 0);
var nodes = search_string == ""? context.content : search_list;
@ -298,9 +298,9 @@ function Panel_Collection() : PanelContent() constructor {
}
return hh;
});
}); #endregion
folderPane = new scrollPane(group_w - ui(8), content_h, function(_y, _m) {
folderPane = new scrollPane(group_w - ui(8), content_h, function(_y, _m) { #region
draw_clear_alpha(COLORS.panel_bg_clear, 0);
draw_sprite_stretched(THEME.ui_panel_bg, 1, ui(8), 0, folderPane.surface_w - ui(8), folderPane.surface_h);
var hh = ui(8);
@ -313,32 +313,32 @@ function Panel_Collection() : PanelContent() constructor {
}
return hh;
});
}); #endregion
function onFocusBegin() { PANEL_COLLECTION = self; }
function onResize() {
function onResize() { #region
initSize();
folderPane.resize(group_w - ui(8), content_h);
contentPane.resize(content_w - ui(6), content_h);
}
} #endregion
function setContext(cont) {
function setContext(cont) { #region
context = cont;
contentPane.scroll_y_raw = 0;
contentPane.scroll_y_to = 0;
}
} #endregion
function refreshContext() {
function refreshContext() { #region
if(mode == 0) context.scan([ ".json", ".pxcc" ]);
else if(mode == 1) context.scan([ ".png", ".jpg", ".gif" ]);
if(STEAM_ENABLED)
steamUCGload();
}
} #endregion
function drawContent(panel) {
function drawContent(panel) { #region
draw_clear_alpha(COLORS.panel_bg_clear, 0);
var content_y = ui(48);
@ -465,5 +465,5 @@ function Panel_Collection() : PanelContent() constructor {
tb_search.draw(tb_x, tb_y, tb_w, TEXTBOX_HEIGHT, search_string, [mx, my]);
}
}
} #endregion
}

View file

@ -280,9 +280,9 @@ function Panel_Menu() : PanelContent() constructor {
} else {
var act = ds_stack_top(UNDO_STACK);
if(array_length(act) > 1)
txt = __txt("Undo") + " " + string(array_length(act)) + " " + __txt("Actions");
txt = $"{__txt("Undo")} {array_length(act)} {__txt("Actions")}";
else
txt = __txt("Undo") + " " + act[0].toString();
txt = $"{__txt("Undo")} {act[0]}";
}
menus[1][1][0].active = !ds_stack_empty(UNDO_STACK);
@ -293,9 +293,9 @@ function Panel_Menu() : PanelContent() constructor {
} else {
var act = ds_stack_top(REDO_STACK);
if(array_length(act) > 1)
txt = __txt("Redo") + " " + string(array_length(act)) + " " + __txt("Actions");
txt = $"{__txt("Redo")} {array_length(act)} {__txt("Actions")}";
else
txt = __txt("Redo") + " " + act[0].toString();
txt = $"{__txt("Redo")} {act[0]}";
}
menus[1][1][1].active = !ds_stack_empty(REDO_STACK);
@ -718,7 +718,5 @@ function Panel_Menu() : PanelContent() constructor {
draw_text(tx0 + ui(8), tby0 + th / 2, tc);
}
#endregion
undoUpdate();
}
}