Color picker, theme crash

This commit is contained in:
Tanasart 2023-06-19 20:28:30 +02:00
parent 8dab2d8fba
commit 60e24c0bf7
15 changed files with 177 additions and 61 deletions

Binary file not shown.

View File

@ -12,6 +12,7 @@ event_inherited();
previous_color = c_black;
selector = new colorSelector();
drop_target = noone;
function setDefault(color) {
selector.setColor(color);

View File

@ -16,6 +16,7 @@ function __Bone(parent = noone, distance = 0, direction = 0, angle = 0, length =
static addChild = function(bone) {
array_push(childs, bone);
bone.parent = self;
return self;
}
@ -47,22 +48,29 @@ function __Bone(parent = noone, distance = 0, direction = 0, angle = 0, length =
if(parent != noone) {
var aa = (hovering != noone && hovering[0] == self && hovering[1] == 2)? 1 : 0.75;
draw_set_color(COLORS._main_accent);
if(!parent_anchor && parent.parent != noone) {
var _p = parent.getPoint(0, 0);
_p.x = _x + _p.x * _s;
_p.y = _y + _p.y * _s;
draw_line_dashed(_p.x, _p.y, p0.x, p0.y, 1);
}
draw_set_alpha(aa);
draw_line_width2(p0.x, p0.y, p1.x, p1.y, 6, 2);
draw_set_alpha(1.00);
if(edit && distance_to_line(_mx, _my, p0.x, p0.y, p1.x, p1.y) <= 6)
if(edit && distance_to_line(_mx, _my, p0.x, p0.y, p1.x, p1.y) <= 6) //drag bone
hover = [ self, 2 ];
if(!parent_anchor) {
if(edit && point_in_circle(_mx, _my, p0.x, p0.y, ui(12))) {
draw_sprite_colored(THEME.anchor_selector, 0, p0.x, p0.y);
if(edit && point_in_circle(_mx, _my, p0.x, p0.y, ui(12))) { //drag head
draw_sprite_colored(THEME.anchor_selector, 0, p0.x, p0.y);
hover = [ self, 0 ];
} else
draw_sprite_colored(THEME.anchor_selector, 2, p0.x, p0.y);
}
if(edit && point_in_circle(_mx, _my, p1.x, p1.y, ui(12))) {
if(edit && point_in_circle(_mx, _my, p1.x, p1.y, ui(12))) { //drag tail
draw_sprite_colored(THEME.anchor_selector, 0, p1.x, p1.y);
hover = [ self, 1 ];
} else

View File

@ -7,6 +7,9 @@ function buttonColor(_onApply, dialog = noone) : widget() constructor {
onColorPick = function() {
var dialog = dialogCall(o_dialog_color_selector, WIN_W / 2, WIN_H / 2);
dialog.selector.dropper_active = true;
dialog.selector.dropper_close = true;
dialog.drop_target = self;
dialog.selector.onApply = onApply;
dialog.onApply = onApply;
}
@ -36,6 +39,7 @@ function buttonColor(_onApply, dialog = noone) : widget() constructor {
dialog.selector.onApply = apply;
dialog.onApply = apply;
dialog.interactable = interactable;
dialog.drop_target = self;
if(parentDialog)
parentDialog.addChildren(dialog);
@ -48,8 +52,19 @@ function buttonColor(_onApply, dialog = noone) : widget() constructor {
h = _h;
current_color = toNumber(_color);
b_picker.setActiveFocus(hover, active);
b_picker.draw(_x + _w - ui(32), _y + _h / 2 - ui(16), ui(32), ui(32), _m, THEME.button_hide);
if(interactable) {
b_picker.setActiveFocus(hover, active);
b_picker.draw(_x + _w - ui(32), _y + _h / 2 - ui(16), ui(32), ui(32), _m, THEME.button_hide);
b_picker.icon_blend = c_white;
b_picker.icon_index = 0;
if(instance_exists(o_dialog_color_selector) && o_dialog_color_selector.selector.dropper_active && o_dialog_color_selector.drop_target != noone) {
if(o_dialog_color_selector.drop_target == self) {
b_picker.icon_blend = COLORS._main_accent;
b_picker.icon_index = 1;
} else
b_picker.icon_blend = COLORS._main_icon;
}
}
var _cw = _w - ui(40);
var hoverRect = point_in_rectangle(_m[0], _m[1], _x, _y, _x + _cw, _y + _h);

View File

@ -7,6 +7,15 @@
#endregion
function loadColor(theme = "default") {
CDEF = {};
COLORS = {};
THEME_VALUE = {};
_loadColor("default", true);
_loadColor(theme);
}
function _loadColor(theme = "default", replace = false) {
var dirr = DIRECTORY + "themes/" + theme;
var path = dirr + "/values.json";
var pathO = dirr + "/override.json";
@ -26,7 +35,8 @@ function loadColor(theme = "default") {
var clrs = json_try_parse(s);
var valkeys = variable_struct_get_names(clrs.values);
THEME_VALUE = clrs.values;
if(replace) THEME_VALUE = clrs.values;
else struct_override(THEME_VALUE, clrs.values);
var defkeys = variable_struct_get_names(clrs.define);
COLOR_KEYS = defkeys;

View File

@ -112,13 +112,15 @@ function colorSelector(onApply = noone) constructor {
static drawDropper = function(instance) {
if(mouse_press(mb_left)) {
setColor(dropper_color);
if(dropper_active == true && dropper_close)
if(dropper_close)
instance_destroy(instance);
dropper_active = false;
}
if(mouse_press(mb_right))
if(dropper_active == true) instance_destroy(instance);
if(dropper_active == true && mouse_press(mb_right))
instance_destroy(instance);
if(keyboard_check_released(vk_alt))
instance_destroy(instance);
var dx = mouse_mx + ui(36);
var dy = mouse_my + ui(36);

View File

@ -33,8 +33,8 @@
VERSION = 1145;
SAVEFILE_VERSION = 1440;
VERSION_STRING = "1.14.5";
BUILD_NUMBER = 114500;
VERSION_STRING = "1.14.5n1";
BUILD_NUMBER = 114501;
globalvar NODES, NODE_MAP, APPEND_MAP, NODE_NAME_MAP;
globalvar HOTKEYS, HOTKEY_CONTEXT, NODE_INSTANCES;

View File

@ -23,6 +23,7 @@ function Node_Armature(_x, _y, _group = noone) : Node(_x, _y, _group) constructo
tools = [
new NodeTool( "Add bones", THEME.path_tools_transform ),
new NodeTool( "Remove bones", THEME.path_tools_transform ),
new NodeTool( "Detach bones", THEME.path_tools_transform ),
];
anchor_selecting = noone;
@ -35,15 +36,27 @@ function Node_Armature(_x, _y, _group = noone) : Node(_x, _y, _group) constructo
static drawOverlay = function(active, _x, _y, _s, _mx, _my, _snx, _sny) {
anchor_selecting = attributes.bones.draw(active, _x, _y, _s, _mx, _my, true, anchor_selecting);
//if(is_array(anchor_selecting)) print(anchor_selecting[1])
var mx = (_mx - _x) / _s;
var my = (_my - _y) / _s;
if(builder_bone != noone) {
//draw_set_color(COLORS._main_accent);
//draw_circle(_x + builder_sx * _s, _y + builder_sy * _s, 8, false);
var dir = point_direction(builder_sx, builder_sy, mx, my);
var dis = point_distance(builder_sx, builder_sy, mx, my);
if(!key_mod_press(ALT)) {
if(builder_type == 2) {
var bx = builder_sx + (mx - builder_mx) / _s;
var by = builder_sy + (my - builder_my) / _s;
if(!builder_bone.parent_anchor) {
builder_bone.direction = point_direction(0, 0, bx, by);
builder_bone.distance = point_distance( 0, 0, bx, by);
}
} else if(key_mod_press(ALT)) {
if(builder_type == 0) {
var bo = builder_bone.getPoint(builder_bone.length, builder_bone.angle);
@ -52,8 +65,8 @@ function Node_Armature(_x, _y, _group = noone) : Node(_x, _y, _group) constructo
var bn = builder_bone.getPoint(0, 0);
builder_bone.angle = point_direction(bo.x, bo.y, bn.x, bn.y);
builder_bone.length = point_distance( bo.x, bo.y, bn.x, bn.y);
builder_bone.angle = point_direction(bn.x, bn.y, bo.x, bo.y);
builder_bone.length = point_distance( bn.x, bn.y, bo.x, bo.y);
} else if(builder_type == 1) {
var chs = [];
for( var i = 0; i < array_length(builder_bone.childs); i++ ) {
@ -79,17 +92,6 @@ function Node_Armature(_x, _y, _group = noone) : Node(_x, _y, _group) constructo
} else if(builder_type == 1) {
builder_bone.angle = dir;
builder_bone.length = dis;
} else if(builder_type == 2) {
var bo = builder_bone.getPoint(0, 0);
var bx = bo.x + (mx - builder_mx) / _s;
var by = bo.y + (my - builder_my) / _s;
if(builder_bone.parent_anchor) {
} else {
builder_bone.direction = point_direction(builder_sx, builder_sy, bx, by);
builder_bone.distance = point_distance( builder_sx, builder_sy, bx, by);
}
}
}
@ -109,8 +111,47 @@ function Node_Armature(_x, _y, _group = noone) : Node(_x, _y, _group) constructo
builder_type = 1;
builder_sx = mx;
builder_sy = my;
} else if(anchor_selecting[1] == 2) {
var _pr = anchor_selecting[0];
var _md = new __Bone(noone, 0, 0, _pr.angle, _pr.length / 2);
_pr.length = _md.length;
for( var i = 0; i < array_length(_pr.childs); i++ )
_md.addChild(_pr.childs[i]);
_pr.childs = [];
_pr.addChild(_md);
}
}
} else if(isUsingTool(1)) { //remover
if(anchor_selecting != noone && anchor_selecting[0].parent != noone && mouse_press(mb_left, active)) {
var _bone = anchor_selecting[0];
var _par = _bone.parent;
if(anchor_selecting[1] == 2) {
array_remove(_par.childs, _bone);
for( var i = 0; i < array_length(_bone.childs); i++ ) {
var _ch = _bone.childs[i];
_par.addChild(_ch);
}
}
}
} else if(isUsingTool(2)) { //detach
if(anchor_selecting != noone && anchor_selecting[0].parent_anchor && anchor_selecting[1] == 2 && mouse_press(mb_left, active)) {
builder_bone = anchor_selecting[0];
builder_type = anchor_selecting[1];
var par = builder_bone.parent;
builder_bone.parent_anchor = false;
builder_bone.distance = par.length;
builder_bone.direction = par.angle;
builder_sx = lengthdir_x(par.length, par.angle);
builder_sy = lengthdir_y(par.length, par.angle);
builder_mx = mx;
builder_my = my;
}
} else { //mover
if(anchor_selecting != noone && mouse_press(mb_left, active)) {
builder_bone = anchor_selecting[0];
@ -125,12 +166,15 @@ function Node_Armature(_x, _y, _group = noone) : Node(_x, _y, _group) constructo
builder_sx = orig.x;
builder_sy = orig.y;
} else if(builder_type == 2) {
var _par = builder_bone.parent;
var orig = _par.getPoint(_par.length, _par.angle);
builder_sx = orig.x;
builder_sy = orig.y;
builder_mx = mx;
builder_my = my;
if(builder_bone.parent_anchor) {
builder_bone = noone;
} else {
var par = builder_bone.parent;
builder_sx = lengthdir_x(builder_bone.distance, builder_bone.direction);
builder_sy = lengthdir_y(builder_bone.distance, builder_bone.direction);
builder_mx = mx;
builder_my = my;
}
}
}
}

View File

@ -619,7 +619,7 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
var comp = buffer_compress(surface_buffer, 0, buffer_get_size(surface_buffer));
var enc = buffer_base64_encode(comp, 0, buffer_get_size(comp));
_map[? "surface"] = enc;
_map.surface = enc;
}
static doApplyDeserialize = function() {

View File

@ -261,8 +261,8 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor {
addNodeObject(transform, "Nine Slice", s_node_9patch, "Node_9Slice", [1, Node_9Slice], ["9 slice", "splice"], "Cut image into 3x3 parts, and scale/repeat only the middle part.");
addNodeObject(transform, "Padding", s_node_padding, "Node_Padding", [1, Node_Padding],, "Make image bigger by adding space in 4 directions.");
//ds_list_add(transform, "Armature");
//addNodeObject(transform, "Armature Create", s_node_compose, "Node_Armature", [1, Node_Armature], ["rigging", "bone"], "");
ds_list_add(transform, "Armature");
addNodeObject(transform, "Armature Create", s_node_compose, "Node_Armature", [1, Node_Armature], ["rigging", "bone"], "");
var filter = ds_list_create();
addNodeCatagory("Filter", filter);
@ -646,8 +646,7 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor {
}
function graphFocusNode(node) {
if(!PANEL_INSPECTOR.locked)
PANEL_INSPECTOR.inspecting = node;
PANEL_INSPECTOR.setInspecting(node);
ds_list_clear(PANEL_GRAPH.nodes_select_list);
PANEL_GRAPH.node_focus = node;
PANEL_GRAPH.fullView();
@ -670,7 +669,6 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor {
function nodeGetData(str) {
var strs = string_splice(str, ".");
var _val = 0;
if(array_length(strs) == 0) return 0;
@ -691,7 +689,7 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor {
var node = NODE_NAME_MAP[? key];
var map = noone;
switch(strs[1]) {
switch(string_lower(strs[1])) {
case "inputs" :
case "input" :
map = node.inputMap;
@ -703,7 +701,7 @@ function NodeObject(_name, _spr, _node, _create, tags = []) constructor {
default : return 0;
}
var _junc_key = strs[2];
var _junc_key = string_lower(strs[2]);
var _junc = ds_map_try_get(map, _junc_key, noone);
if(_junc == noone) return 0;

View File

@ -355,7 +355,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
_initName = _name;
name = __txt_junction_name(instanceof(node), type, index, _name);
name = _name;
internalName = string_replace_all(_name, " ", "_");
internalName = string_lower(string_replace_all(_name, " ", "_"));
if(struct_has(node, "inputMap")) {
if(_connect == JUNCTION_CONNECT.input) node.inputMap[? internalName] = self;
@ -1239,7 +1239,7 @@ function NodeValue(_name, _node, _connect, _type, _value, _tooltip = "") constru
}
if(_valueFrom == value_from) {
print("whaT")
print("whaT");
return false;
}

View File

@ -498,7 +498,7 @@ function Panel(_parent, _x, _y, _w, _h) constructor {
foc = FOCUS == self;
var cc = FOCUS == self? COLORS._main_accent : COLORS.panel_tab;
draw_sprite_stretched_ext(THEME.ui_panel_tab, 1 + (FOCUS == self), _tbx, tby, tbw, _tdh, cc, 1);
if(!foc) tab_cover = BBOX().fromWH(tsx + _tbx, tsy + tby + tbh - ui(2), tbw, THEME_VALUE.panel_tab_extend);
tab_cover = BBOX().fromWH(tsx + _tbx, tsy + tby + tbh - ui(3), tbw, THEME_VALUE.panel_tab_extend);
} else {
var cc = COLORS.panel_tab_inactive;
if(HOVER == self && _hov)
@ -531,13 +531,12 @@ function Panel(_parent, _x, _y, _w, _h) constructor {
}
}
var cc = foc? COLORS.panel_bg_clear_inner : COLORS._main_text_sub;
if(icn != noone) {
draw_sprite_ui(icn, 0, _tbx + ui(8 + 8), tab_height / 2 + ui(1),,,, cc);
draw_sprite_ui(icn, 0, _tbx + ui(8 + 8), tab_height / 2 + ui(1),,,, foc? COLORS.panel_tab_icon : COLORS._main_text_sub);
_tbx += ui(20);
}
draw_set_text(f_p3, fa_left, fa_bottom, cc);
draw_set_text(f_p3, fa_left, fa_bottom, foc? COLORS.panel_tab_text : COLORS._main_text_sub);
draw_text_add(_tbx + ui(8), tab_height - ui(4), txt);
tbx += tbw + ui(2);
@ -560,12 +559,11 @@ function Panel(_parent, _x, _y, _w, _h) constructor {
draw_sprite_stretched_ext(THEME.ui_panel_tab, 2, _tbx, tby, tbw, tbh, COLORS._main_accent, 1);
var cc = COLORS.panel_bg_clear_inner;
if(icn != noone) {
draw_sprite_ui(icn, 0, _tbx + ui(8 + 8), tab_height / 2 + ui(1),,,, cc);
draw_sprite_ui(icn, 0, _tbx + ui(8 + 8), tab_height / 2 + ui(1),,,, COLORS.panel_tab_icon);
_tbx += ui(20);
}
draw_set_text(f_p3, fa_left, fa_bottom, COLORS.panel_bg_clear_inner);
draw_set_text(f_p3, fa_left, fa_bottom, COLORS.panel_tab_text);
draw_text_add(_tbx + ui(8), tab_height - ui(4), txt);
if(tab_hold_state == 0) {
@ -640,7 +638,7 @@ function Panel(_parent, _x, _y, _w, _h) constructor {
draw_surface_safe(content_surface, tx, ty);
draw_sprite_stretched(THEME.ui_panel_fg, 0, tx + padding, ty + padding, _tw, _th);
draw_sprite_bbox(THEME.ui_panel_tab, 3, tab_cover);
if(FOCUS == self && parent != noone) {
draw_sprite_stretched_ext(THEME.ui_panel_active, 0, tx + padding, ty + padding, tw - padding * 2, th - padding * 2, COLORS._main_accent, 1);

View File

@ -510,7 +510,7 @@ function Panel_Graph() : PanelContent() constructor {
menuItem(__txtx("panel_graph_inspector_panel", "Send to new inspector"), function() {
var pan = panelAdd("Panel_Inspector", true);
pan.destroy_on_click_out = false;
pan.content.inspecting = node_hover;
pan.content.setInspecting(node_hover);
pan.content.locked = true;
}));

View File

@ -55,6 +55,9 @@ function Panel_Inspector() : PanelContent() constructor {
prop_page_button.fColor = COLORS._main_text_sub;
prop_page = 0;
picker_index = 0;
picker_change = false;
current_meta = -1;
meta_tb[0] = new textArea(TEXTBOX_INPUT.text, function(str) { current_meta.description = str; });
meta_tb[1] = new textArea(TEXTBOX_INPUT.text, function(str) { current_meta.author = str; });
@ -98,6 +101,19 @@ function Panel_Inspector() : PanelContent() constructor {
}),
]
function setInspecting(inspecting) {
if(locked) return;
self.inspecting = inspecting;
if(inspecting != noone)
inspecting.onInspect();
contentPane.scroll_y = 0;
contentPane.scroll_y_to = 0;
picker_index = 0;
}
function onFocusBegin() { PANEL_INSPECTOR = self; }
function onResize() {
@ -154,7 +170,7 @@ function Panel_Inspector() : PanelContent() constructor {
for( var j = 0; j < array_length(meta.displays); j++ ) {
var display = meta.displays[j];
draw_set_text(f_p0, fa_left, fa_top, COLORS._main_text);
draw_set_text(f_p0, fa_left, fa_top, COLORS._main_text_inner);
draw_text_add(ui(16), yy, __txt(display[0]));
yy += line_get_height() + ui(6);
hh += line_get_height() + ui(6);
@ -339,6 +355,10 @@ function Panel_Inspector() : PanelContent() constructor {
return hh;
}
var color_picker_selecting = noone;
var color_picker_index = 0;
var pickers = [];
for(var i = 0; i < amo; i++) {
var yy = hh + _y;
@ -443,6 +463,17 @@ function Panel_Inspector() : PanelContent() constructor {
}
}
if(jun.connect_type == JUNCTION_CONNECT.input && jun.type == VALUE_TYPE.color && jun.display_type == VALUE_DISPLAY._default) {
pickers[color_picker_index] = jun;
if(color_picker_index == picker_index) {
if(ALT == KEYBOARD_STATUS.down)
jun.editWidget.onColorPick();
color_picker_selecting = jun;
}
color_picker_index++;
}
if(_hover && point_in_rectangle(_m[0], _m[1], ui(4), _selY, contentPane.surface_w - ui(4), _selY + _selH)) {
_HOVERING_ELEMENT = jun;
@ -517,6 +548,21 @@ function Panel_Inspector() : PanelContent() constructor {
}
}
if(color_picker_selecting == noone)
picker_selecting = 0;
if(key_mod_press(ALT) && color_picker_index) {
var _p = picker_index;
if(mouse_wheel_down()) picker_index = safe_mod(picker_index + 1 + color_picker_index, color_picker_index);
if(mouse_wheel_up()) picker_index = safe_mod(picker_index - 1 + color_picker_index, color_picker_index);
if(_p != picker_index) {
instance_destroy(o_dialog_color_selector);
pickers[picker_index].editWidget.onColorPick();
}
}
if(prop_dragging) {
if(DRAGGING == noone && point_distance(prop_sel_drag_x, prop_sel_drag_y, mouse_mx, mouse_my) > 16) {
prop_dragging.dragValue();
@ -657,12 +703,7 @@ function Panel_Inspector() : PanelContent() constructor {
contentPane.setActiveFocus(pFOCUS, pHOVER);
contentPane.draw(ui(16), top_bar_h, mx - ui(16), my - top_bar_h);
if(!locked && PANEL_GRAPH.node_focus && inspecting != PANEL_GRAPH.node_focus) {
inspecting = PANEL_GRAPH.node_focus;
if(inspecting != noone)
inspecting.onInspect();
contentPane.scroll_y = 0;
contentPane.scroll_y_to = 0;
}
if(!locked && PANEL_GRAPH.node_focus && inspecting != PANEL_GRAPH.node_focus)
setInspecting(PANEL_GRAPH.node_focus);
}
}

View File

@ -52,8 +52,7 @@ function Panel_Nodes() : PanelContent() constructor {
else if(mouse_press(mb_left)) {
if(isGroup)
node_collapse[? node.node_id] = !node_collapse[? node.node_id];
if(!PANEL_INSPECTOR.locked)
PANEL_INSPECTOR.inspecting = node;
PANEL_INSPECTOR.setInspecting(node);
ds_list_clear(PANEL_GRAPH.nodes_select_list);
PANEL_GRAPH.node_focus = node;
}