- [Preference] Fix spacing error when searching hotkey.

This commit is contained in:
Tanasart 2024-06-30 16:18:48 +07:00
parent 3b76ff571c
commit d10aa6818e
9 changed files with 238 additions and 198 deletions

View file

@ -737,15 +737,16 @@ event_inherited();
draw_set_text(f_p0, fa_left, fa_top); draw_set_text(f_p0, fa_left, fa_top);
var yy = _y + ui(8); var yy = _y + ui(8);
var ind = 0; var th = line_get_height(f_p0);
var ind = 0;
var sect = []; var sect = [];
var psect = ""; var psect = "";
for( var i = 0, n = ds_list_size(pref_hot); i < n; i++ ) { for( var i = 0, n = ds_list_size(pref_hot); i < n; i++ ) {
var _pref = pref_hot[| i]; var _pref = pref_hot[| i];
var th = line_get_height();
var _yy = yy + hh;
var name = _pref[0]; var name = _pref[0];
var val = _pref[1]; var val = _pref[1];
val = is_method(val)? val() : PREFERENCES[$ val]; val = is_method(val)? val() : PREFERENCES[$ val];
@ -753,12 +754,11 @@ event_inherited();
if(search_text != "" && string_pos(string_lower(search_text), string_lower(name)) == 0) if(search_text != "" && string_pos(string_lower(search_text), string_lower(name)) == 0)
continue; continue;
if(ind % 2 == 0) if(ind++ % 2 == 0)
draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, 0, yy + hh - padd, draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, 0, _yy - padd, sp_hotkey.surface_w, th + padd * 2, COLORS.dialog_preference_prop_bg, 1);
sp_hotkey.surface_w, th + padd * 2, COLORS.dialog_preference_prop_bg, 1);
draw_set_text(f_p0, fa_left, fa_top, COLORS._main_text); draw_set_text(f_p0, fa_left, fa_top, COLORS._main_text);
draw_text_add(ui(24), yy + hh, _pref[0]); draw_text_add(ui(24), _yy, _pref[0]);
_pref[2].setFocusHover(sFOCUS, sHOVER && sp_hotkey.hover); _pref[2].setFocusHover(sFOCUS, sHOVER && sp_hotkey.hover);
@ -766,15 +766,17 @@ event_inherited();
var widget_h = th + (padd - ui(4)) * 2; var widget_h = th + (padd - ui(4)) * 2;
var widget_x = x1 - ui(4) - widget_w; var widget_x = x1 - ui(4) - widget_w;
var widget_y = yy + hh - ui(4); var widget_y = _yy - ui(4);
var params = new widgetParam(widget_x, widget_y, widget_w, widget_h, val, {}, _m, sp_hotkey.x, sp_hotkey.y); var params = new widgetParam(widget_x, widget_y, widget_w, widget_h, val, {}, _m, sp_hotkey.x, sp_hotkey.y);
var th = _pref[2].drawParam(params) ?? 0; var _th = _pref[2].drawParam(params) ?? 0;
hh += th + padd + ui(8); hh += _th + padd + ui(8);
ind++;
} }
th = line_get_height(f_p1);
ind = 0;
for(var j = 0; j < ds_list_size(HOTKEY_CONTEXT); j++) { for(var j = 0; j < ds_list_size(HOTKEY_CONTEXT); j++) {
var ll = HOTKEYS[? HOTKEY_CONTEXT[| j]]; var ll = HOTKEYS[? HOTKEY_CONTEXT[| j]];
@ -787,6 +789,7 @@ event_inherited();
var dkey = key.dKey; var dkey = key.dKey;
var dmod = key.dModi; var dmod = key.dModi;
var _yy = yy + hh;
if(search_text != "" && string_pos(string_lower(search_text), string_lower(name)) == 0) if(search_text != "" && string_pos(string_lower(search_text), string_lower(name)) == 0)
continue; continue;
@ -796,76 +799,38 @@ event_inherited();
var _grp = group == ""? __txt("Global") : group; var _grp = group == ""? __txt("Global") : group;
draw_set_text(f_p0b, fa_left, fa_top, COLORS._main_text_sub); draw_set_text(f_p0b, fa_left, fa_top, COLORS._main_text_sub);
draw_text_add(ui(8), yy + hh, _grp); draw_text_add(ui(8), _yy, _grp);
array_push(sect, [ _grp, sp_hotkey, hh + ui(12) ]); array_push(sect, [ _grp, sp_hotkey, hh + ui(12) ]);
if(yy + hh >= 0 && section_current == "") if(_yy >= 0 && section_current == "")
section_current = psect; section_current = psect;
psect = _grp; psect = _grp;
hh += string_height("l") + ui(16); ind = 0;
hh += string_height("l") + ui(16);
currGroup = group; currGroup = group;
} }
if(i % 2 == 0) { var _yy = yy + hh;
draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, 0, yy + hh - padd,
sp_hotkey.surface_w, th + padd * 2, COLORS.dialog_preference_prop_bg, 1);
}
var _lb_y = yy + hh + ui(4); if(ind++ % 2 == 0)
draw_set_text(f_p0, fa_left, fa_top, COLORS._main_text); draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, 0, _yy - padd, sp_hotkey.surface_w, th + padd * 2, COLORS.dialog_preference_prop_bg, 1);
var _lb_y = _yy;
draw_set_text(f_p1, fa_left, fa_top, COLORS._main_text);
draw_text_add(ui(24), _lb_y, name); draw_text_add(ui(24), _lb_y, name);
var dk = key_get_name(key.key, key.modi); var dk = key_get_name(key.key, key.modi);
var kw = string_width(dk); var kw = string_width(dk);
if(hk_editing == key) { if(hk_editing == key) {
var _mod_prs = 0;
if(keyboard_check(vk_control)) _mod_prs |= MOD_KEY.ctrl;
if(keyboard_check(vk_shift)) _mod_prs |= MOD_KEY.shift;
if(keyboard_check(vk_alt)) _mod_prs |= MOD_KEY.alt;
if(keyboard_check_pressed(vk_escape)) {
key.key = 0;
key.modi = 0;
PREF_SAVE();
} else if(keyboard_check_pressed(vk_anykey)) {
key.modi = _mod_prs;
key.key = 0;
var press = false;
for(var a = 0; a < array_length(vk_list); a++) {
if(!keyboard_check_pressed(vk_list[a])) continue;
key.key = vk_list[a];
press = true;
break;
}
if(!press) {
var k = ds_map_find_first(global.KEY_STRING_MAP);
var amo = ds_map_size(global.KEY_STRING_MAP);
repeat(amo) {
if(!keyboard_check_pressed(k)) {
k = ds_map_find_next(global.KEY_STRING_MAP, k);
continue;
}
key.key = k;
press = true;
break;
}
}
PREF_SAVE();
}
dk = key_get_name(key.key, key.modi); dk = key_get_name(key.key, key.modi);
kw = string_width(dk); kw = string_width(dk);
draw_sprite_stretched(THEME.button_hide, 2, key_x1 - ui(40) - kw, yy + hh, kw + ui(32), th); draw_sprite_stretched(THEME.button_hide, 2, key_x1 - ui(40) - kw, _yy, kw + ui(32), th);
} else { } else {
var bx = key_x1 - ui(40) - kw; var bx = key_x1 - ui(40) - kw;
var by = yy + hh; var by = _yy;
if(buttonInstant(THEME.button_hide, bx, by, kw + ui(32), th, _m, sFOCUS, sHOVER && sp_hotkey.hover) == 2) { if(buttonInstant(THEME.button_hide, bx, by, kw + ui(32), th, _m, sFOCUS, sHOVER && sp_hotkey.hover) == 2) {
hk_editing = key; hk_editing = key;
keyboard_lastchar = pkey; keyboard_lastchar = pkey;
@ -875,15 +840,15 @@ event_inherited();
var cc = (key.key == 0 && key.modi == MOD_KEY.none)? COLORS._main_text_sub : COLORS._main_text; var cc = (key.key == 0 && key.modi == MOD_KEY.none)? COLORS._main_text_sub : COLORS._main_text;
if(hk_editing == key) cc = COLORS._main_text_accent; if(hk_editing == key) cc = COLORS._main_text_accent;
draw_set_text(f_p0, fa_right, fa_top, cc); draw_set_text(f_p1, fa_right, fa_top, cc);
draw_text_add(key_x1 - ui(24), _lb_y, dk); draw_text_add(key_x1 - ui(24), _lb_y, dk);
if(key.key != dkey || key.modi != dmod) { if(key.key != dkey || key.modi != dmod) {
modified = true; modified = true;
var bx = x1 - ui(32); var bx = x1 - ui(32);
var by = yy + hh; var by = _yy;
if(buttonInstant(THEME.button_hide, bx, by, ui(24), ui(24), _m, sFOCUS, sHOVER && sp_hotkey.hover, __txt("Reset"), THEME.refresh_16) == 2) { if(buttonInstant(THEME.button_hide, bx, by, ui(24), ui(24), _m, sFOCUS, sHOVER && sp_hotkey.hover, __txt("Reset"), THEME.refresh_16) == 2) {
key.key = dkey; key.key = dkey;
key.modi = dmod; key.modi = dmod;
PREF_SAVE(); PREF_SAVE();
@ -901,33 +866,34 @@ event_inherited();
var keys = struct_get_names(HOTKEYS_CUSTOM); var keys = struct_get_names(HOTKEYS_CUSTOM);
for( var i = 0, n = array_length(keys); i < n; i++ ) { for( var i = 0, n = array_length(keys); i < n; i++ ) {
var _key = keys[i]; var _key = keys[i];
var hotkeys = struct_get_names(HOTKEYS_CUSTOM[$ _key]); var hotkeys = struct_get_names(HOTKEYS_CUSTOM[$ _key]);
var _key_t = string_title(string_replace(_key, "Node_", ""));
var _key_t = string_title(string_replace(_key, "Node_", "")); var _yy = yy + hh;
draw_set_text(f_p0b, fa_left, fa_top, COLORS._main_text_sub); draw_set_text(f_p0b, fa_left, fa_top, COLORS._main_text_sub);
draw_text_add(ui(8), yy + hh, _key_t); draw_text_add(ui(8), _yy, _key_t);
array_push(sect, [ "- " + _key_t, sp_hotkey, hh + ui(12) ]); array_push(sect, [ "- " + _key_t, sp_hotkey, hh + ui(12) ]);
if(yy + hh >= 0 && section_current == "")
if(_yy >= 0 && section_current == "")
section_current = psect; section_current = psect;
psect = "- " + _key_t; psect = "- " + _key_t;
hh += string_height("l") + ui(16); hh += string_height("l") + ui(16);
ind = 0;
for( var j = 0, m = array_length(hotkeys); j < m; j++ ) { for( var j = 0, m = array_length(hotkeys); j < m; j++ ) {
var _hotkey = hotkeys[j]; var _hotkey = hotkeys[j];
var hotkey = HOTKEYS_CUSTOM[$ _key][$ _hotkey]; var hotkey = HOTKEYS_CUSTOM[$ _key][$ _hotkey];
var name = __txt(_hotkey); var name = __txt(_hotkey);
var pkey = hotkey.key; var pkey = hotkey.getName();
var _yy = yy + hh;
if(j % 2 == 0) { if(ind++ % 2 == 0)
draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, 0, yy + hh - padd, draw_sprite_stretched_ext(THEME.ui_panel_bg, 0, 0, _yy - padd, sp_hotkey.surface_w, th + padd * 2, COLORS.dialog_preference_prop_bg, 1);
sp_hotkey.surface_w, th + padd * 2, COLORS.dialog_preference_prop_bg, 1);
}
var _lb_y = yy + hh + ui(4); var _lb_y = _yy;
draw_set_text(f_p0, fa_left, fa_top, COLORS._main_text); draw_set_text(f_p1, fa_left, fa_top, COLORS._main_text);
draw_text_add(ui(24), _lb_y, name); draw_text_add(ui(24), _lb_y, name);
var kw = string_width(pkey); var kw = string_width(pkey);
@ -935,36 +901,31 @@ event_inherited();
var key = hotkey; var key = hotkey;
if(hk_editing == key) { if(hk_editing == key) {
if(keyboard_check_pressed(vk_escape)) { draw_sprite_stretched(THEME.button_hide, 2, key_x1 - ui(40) - kw, _yy, kw + ui(32), th);
key.key = "";
PREF_SAVE();
} else if(keyboard_check_pressed(vk_anykey)) {
key.key = string_upper(keyboard_lastchar);
PREF_SAVE();
}
draw_sprite_stretched(THEME.button_hide, 2, key_x1 - ui(40) - kw, yy + hh, kw + ui(32), th);
} else { } else {
var bx = key_x1 - ui(40) - kw; var bx = key_x1 - ui(40) - kw;
var by = yy + hh; var by = _yy;
if(buttonInstant(THEME.button_hide, bx, by, kw + ui(32), th, _m, sFOCUS, sHOVER && sp_hotkey.hover) == 2) { if(buttonInstant(THEME.button_hide, bx, by, kw + ui(32), th, _m, sFOCUS, sHOVER && sp_hotkey.hover) == 2) {
hk_editing = key; hk_editing = key;
keyboard_lastchar = pkey; keyboard_lastchar = key.key;
} }
} }
var cc = (hotkey.key == "")? COLORS._main_text_sub : COLORS._main_text; var cc = (hotkey.key == "")? COLORS._main_text_sub : COLORS._main_text;
if(hk_editing == key) cc = COLORS._main_text_accent; if(hk_editing == key) cc = COLORS._main_text_accent;
draw_set_text(f_p0, fa_right, fa_top, cc); draw_set_text(f_p1, fa_right, fa_top, cc);
draw_text_add(key_x1 - ui(24), _lb_y, pkey); draw_text_add(key_x1 - ui(24), _lb_y, pkey);
if(key.key != key.dkey) { if(key.key != key.dKey || key.modi != key.dModi) {
modified = true; modified = true;
var bx = x1 - ui(32); var bx = x1 - ui(32);
var by = yy + hh; var by = _yy;
if(buttonInstant(THEME.button_hide, bx, by, ui(24), ui(24), _m, sFOCUS, sHOVER && sp_hotkey.hover, __txt("Reset"), THEME.refresh_16) == 2) { if(buttonInstant(THEME.button_hide, bx, by, ui(24), ui(24), _m, sFOCUS, sHOVER && sp_hotkey.hover, __txt("Reset"), THEME.refresh_16) == 2) {
key.key = key.dkey; key.key = key.dKey;
key.modi = key.dModi;
PREF_SAVE(); PREF_SAVE();
} }
@ -974,6 +935,48 @@ event_inherited();
} }
} }
if(hk_editing != noone) {
var _mod_prs = 0;
if(keyboard_check(vk_control)) _mod_prs |= MOD_KEY.ctrl;
if(keyboard_check(vk_shift)) _mod_prs |= MOD_KEY.shift;
if(keyboard_check(vk_alt)) _mod_prs |= MOD_KEY.alt;
if(keyboard_check_pressed(vk_escape)) {
hk_editing.key = 0;
hk_editing.modi = 0;
PREF_SAVE();
} else if(keyboard_check_pressed(vk_anykey)) {
hk_editing.modi = _mod_prs;
hk_editing.key = 0;
var press = false;
for(var a = 0; a < array_length(vk_list); a++) {
if(!keyboard_check_pressed(vk_list[a])) continue;
hk_editing.key = vk_list[a];
press = true;
break;
}
if(!press) {
var k = ds_map_find_first(global.KEY_STRING_MAP);
var amo = ds_map_size(global.KEY_STRING_MAP);
repeat(amo) {
if(!keyboard_check_pressed(k)) {
k = ds_map_find_next(global.KEY_STRING_MAP, k);
continue;
}
hk_editing.key = k;
press = true;
break;
}
}
PREF_SAVE();
}
}
//if(modified) { //if(modified) {
// var bx = x1 - ui(32); // var bx = x1 - ui(32);
// var by = yy + ui(2); // var by = yy + ui(2);

View file

@ -54,7 +54,9 @@
#region Set up #region Set up
var t = current_time; var t = current_time;
PREF_LOAD();
if(!IS_CMD) { __initHotKey(); log_message("SESSION", $"> init Hotkeys | complete in {get_timer() - t}"); t = get_timer(); }
PREF_LOAD(); log_message("SESSION", $"> init Preferences | complete in {get_timer() - t}"); t = get_timer();
var dir = string(DIRECTORY) + "log"; var dir = string(DIRECTORY) + "log";
directory_verify(dir); directory_verify(dir);

View file

@ -43,15 +43,6 @@ function canvas_tool_brush(brush, eraser = false) : canvas_tool() constructor {
mouse_cur_x = mouse_pre_draw_x + _ddx - sign(_ddx); mouse_cur_x = mouse_pre_draw_x + _ddx - sign(_ddx);
mouse_cur_y = mouse_pre_draw_y + _ddy - sign(_ddy); mouse_cur_y = mouse_pre_draw_y + _ddy - sign(_ddy);
// var aa = point_direction(mouse_pre_draw_x, mouse_pre_draw_y, mouse_cur_x, mouse_cur_y);
// var dd = point_distance(mouse_pre_draw_x, mouse_pre_draw_y, mouse_cur_x, mouse_cur_y);
// var _a = round(aa / 45) * 45;
// dd = dd * dcos(_a - aa);
// mouse_cur_x = mouse_pre_draw_x + lengthdir_x(dd, _a);
// mouse_cur_y = mouse_pre_draw_y + lengthdir_y(dd, _a);
} }
} }

View file

@ -1,77 +1,110 @@
#region #region
globalvar HOTKEYS_CUSTOM; globalvar HOTKEYS_CUSTOM;
HOTKEYS_CUSTOM = {
"Node_Canvas": {
"Selection": new hotkeySimple("S"),
"Magic Selection": new hotkeySimple("W"),
"Pencil": new hotkeySimple("B"),
"Eraser": new hotkeySimple("E"),
"Rectangle": new hotkeySimple("N"),
"Ellipse": new hotkeySimple("M"),
"Fill": new hotkeySimple("G"),
"Freeform": new hotkeySimple("Q"),
},
"Node_Mesh_Warp": {
"Edit control point": new hotkeySimple("V"),
"Pin mesh": new hotkeySimple("P"),
"Mesh edit": new hotkeySimple("M"),
"Anchor remove": new hotkeySimple("E"),
},
"Node_Armature": {
"Move": new hotkeySimple("V"),
"Scale": new hotkeySimple("S"),
"Add bones": new hotkeySimple("A"),
"Remove bones": new hotkeySimple("E"),
"Detach bones": new hotkeySimple("D"),
"IK": new hotkeySimple("K"),
},
"Node_Path": {
"Transform": new hotkeySimple("T"),
"Anchor add / remove": new hotkeySimple("A"),
"Edit Control point": new hotkeySimple("C"),
"Draw path": new hotkeySimple("B"),
"Rectangle path": new hotkeySimple("N"),
"Circle path": new hotkeySimple("M"),
},
"Node_Rigid_Object": {
"Mesh edit": new hotkeySimple("A"),
"Anchor remove": new hotkeySimple("E"),
},
"Node_Strand_Create": {
"Push": new hotkeySimple("P"),
"Comb": new hotkeySimple("C"),
"Stretch": new hotkeySimple("S"),
"Shorten": new hotkeySimple("D"),
"Grab": new hotkeySimple("G"),
},
"Node_Path_Anchor": {
"Adjust control point": new hotkeySimple("A"),
},
"Node_3D_Object": {
"Transform": new hotkeySimple("G"),
"Rotate": new hotkeySimple("R"),
"Scale": new hotkeySimple("S"),
},
"Node_3D_Camera": {
"Move Target": new hotkeySimple("T"),
},
};
function getToolHotkey(_group, _key, _def = "") { function __initHotKey() {
HOTKEYS_CUSTOM = {
"Node_Canvas": {
"Selection": new hotkeySimple("S"),
"Magic Selection": new hotkeySimple("W"),
"Pencil": new hotkeySimple("B"),
"Eraser": new hotkeySimple("E"),
"Rectangle": new hotkeySimple("N"),
"Ellipse": new hotkeySimple("M"),
"Curve": new hotkeySimple(""),
"Freeform": new hotkeySimple("Q"),
"Fill": new hotkeySimple("G"),
"Outline": new hotkeySimple("O", MOD_KEY.shift),
"Extrude": new hotkeySimple("E", MOD_KEY.shift),
"Inset": new hotkeySimple("I", MOD_KEY.shift),
"Skew": new hotkeySimple("S", MOD_KEY.shift),
},
"Node_Mesh_Warp": {
"Edit control point": new hotkeySimple("V"),
"Pin mesh": new hotkeySimple("P"),
"Mesh edit": new hotkeySimple("M"),
"Anchor remove": new hotkeySimple("E"),
},
"Node_Armature": {
"Move": new hotkeySimple("V"),
"Scale": new hotkeySimple("S"),
"Add bones": new hotkeySimple("A"),
"Remove bones": new hotkeySimple("E"),
"Detach bones": new hotkeySimple("D"),
"IK": new hotkeySimple("K"),
},
"Node_Path": {
"Transform": new hotkeySimple("T"),
"Anchor add / remove": new hotkeySimple("A"),
"Edit Control point": new hotkeySimple("C"),
"Draw path": new hotkeySimple("B"),
"Rectangle path": new hotkeySimple("N"),
"Circle path": new hotkeySimple("M"),
},
"Node_Rigid_Object": {
"Mesh edit": new hotkeySimple("A"),
"Anchor remove": new hotkeySimple("E"),
},
"Node_Strand_Create": {
"Push": new hotkeySimple("P"),
"Comb": new hotkeySimple("C"),
"Stretch": new hotkeySimple("S"),
"Shorten": new hotkeySimple("D"),
"Grab": new hotkeySimple("G"),
},
"Node_Path_Anchor": {
"Adjust control point": new hotkeySimple("A"),
},
"Node_3D_Object": {
"Transform": new hotkeySimple("G"),
"Rotate": new hotkeySimple("R"),
"Scale": new hotkeySimple("S"),
},
"Node_3D_Camera": {
"Move Target": new hotkeySimple("T"),
},
};
}
function getToolHotkey(_group, _key) {
INLINE INLINE
if(!struct_has(HOTKEYS_CUSTOM, _group)) return _def; if(!struct_has(HOTKEYS_CUSTOM, _group)) return noone;
var _grp = HOTKEYS_CUSTOM[$ _group]; var _grp = HOTKEYS_CUSTOM[$ _group];
if(!struct_has(_grp, _key)) return _def; if(!struct_has(_grp, _key)) return noone;
return _grp[$ _key].key;
return _grp[$ _key];
} }
#endregion #endregion
#region hotkeys #region hotkeys
function hotkeySimple(_key) constructor { function hotkeySimple(_key, modi = MOD_KEY.none) constructor {
self.key = _key; self.key = key_get_index(_key);
dkey = _key; self.modi = modi;
dKey = key;
dModi = modi;
static isPressing = function() {
if(is_string(key)) key = key_get_index(key);
return key == noone? false : key_press(key, modi);
}
static getName = function() {
if(is_string(key)) key = key_get_index(key);
return key_get_name(key, modi);
}
} }
function hotkeyObject(_context, _name, _key, _mod = MOD_KEY.none, _action = noone) constructor { function hotkeyObject(_context, _name, _key, _mod = MOD_KEY.none, _action = noone) constructor {
@ -97,10 +130,8 @@
} }
function addHotkey(_context, _name, _key, _mod, _action) { function addHotkey(_context, _name, _key, _mod, _action) {
if(is_string(_key)) { if(is_string(_key))
var ind = key_get_index(_key); _key = key_get_index(_key);
_key = ind? ind : ord(_key);
}
var key = new hotkeyObject(_context, _name, _key, _mod, _action); var key = new hotkeyObject(_context, _name, _key, _mod, _action);

View file

@ -73,18 +73,21 @@
global.KEY_STRING_MAP[? 223] = "`" // actually ` but that needs to be escaped global.KEY_STRING_MAP[? 223] = "`" // actually ` but that needs to be escaped
function key_get_index(key) { function key_get_index(key) {
if(key == "") return noone;
var k = ds_map_find_first(global.KEY_STRING_MAP); var k = ds_map_find_first(global.KEY_STRING_MAP);
repeat(ds_map_size(global.KEY_STRING_MAP)) { repeat(ds_map_size(global.KEY_STRING_MAP)) {
if(global.KEY_STRING_MAP[? k] == key) return k; if(global.KEY_STRING_MAP[? k] == key) return k;
k = ds_map_find_next(global.KEY_STRING_MAP, k); k = ds_map_find_next(global.KEY_STRING_MAP, k);
} }
return false;
return ord(key);
} }
#endregion #endregion
#region get name #region get name
function key_get_name(_key, _mod) { function key_get_name(_key, _mod) {
if(_key == 0 && _mod == MOD_KEY.none) if(_key <= 0 && _mod == MOD_KEY.none)
return ""; return "";
var dk = ""; var dk = "";
@ -120,11 +123,11 @@
case vk_f10 : dk += "F10"; break; case vk_f10 : dk += "F10"; break;
case vk_f11 : dk += "F11"; break; case vk_f11 : dk += "F11"; break;
case vk_f12 : dk += "F12"; break; case vk_f12 : dk += "F12"; break;
case -1 : break;
default : default :
if(ds_map_exists(global.KEY_STRING_MAP, _key)) if(ds_map_exists(global.KEY_STRING_MAP, _key))
dk += global.KEY_STRING_MAP[? _key]; dk += global.KEY_STRING_MAP[? _key];
else else if(_key > 0)
dk += ansi_char(_key); dk += ansi_char(_key);
break; break;
} }

View file

@ -366,10 +366,10 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
rightTools_not_selection = [ rightTools_not_selection = [
-1, -1,
new NodeTool( "Outline", THEME.canvas_tools_outline, self ).setToolObject( new canvas_tool_with_selector(rightTools_selection[3]) ), new NodeTool( "Outline", THEME.canvas_tools_outline).setContext(self).setToolObject( new canvas_tool_with_selector(rightTools_selection[3]) ),
new NodeTool( "Extrude", THEME.canvas_tools_extrude, self ).setToolObject( new canvas_tool_with_selector(rightTools_selection[4]) ), new NodeTool( "Extrude", THEME.canvas_tools_extrude).setContext(self).setToolObject( new canvas_tool_with_selector(rightTools_selection[4]) ),
new NodeTool( "Inset", THEME.canvas_tools_inset, self ).setToolObject( new canvas_tool_with_selector(rightTools_selection[5]) ), new NodeTool( "Inset", THEME.canvas_tools_inset ).setContext(self).setToolObject( new canvas_tool_with_selector(rightTools_selection[5]) ),
new NodeTool( "Skew", THEME.canvas_tools_skew, self ).setToolObject( new canvas_tool_with_selector(rightTools_selection[6]) ), new NodeTool( "Skew", THEME.canvas_tools_skew ).setContext(self).setToolObject( new canvas_tool_with_selector(rightTools_selection[6]) ),
]; ];
rightTools_brush = [ rightTools_brush = [
@ -975,9 +975,7 @@ function Node_Canvas(_x, _y, _group = noone) : Node(_x, _y, _group) constructor
if(_bgDim) { if(_bgDim) {
var _bgDim = _bg; var _bgDim = _bg;
if(is_array(_bgDim) && !array_empty(_bgDim)) _bgDim = _bg[0]; if(is_array(_bgDim) && !array_empty(_bgDim)) _bgDim = _bg[0];
if(is_surface(_bgDim)) _dim = surface_get_dimension(_bgDim);
if(is_surface(_bgDim))
_dim = [ surface_get_width_safe(_bgDim), surface_get_height_safe(_bgDim) ];
} }
attributes.dimension = _dim; attributes.dimension = _dim;
apply_surfaces(); apply_surfaces();

View file

@ -1,5 +1,7 @@
function NodeTool(name, spr, context = instanceof(other)) constructor { function NodeTool(name, spr, contextString = instanceof(other)) constructor {
ctx = context; ctx = contextString;
context = noone;
self.name = name; self.name = name;
self.spr = spr; self.spr = spr;
@ -12,12 +14,9 @@ function NodeTool(name, spr, context = instanceof(other)) constructor {
toolFn = noone; toolFn = noone;
toolFnParam = {}; toolFnParam = {};
static checkHotkey = function() { static checkHotkey = function() { INLINE return getToolHotkey(ctx, name); }
INLINE
return getToolHotkey(ctx, name);
}
static setContext = function(context) { self.context = context; return self; }
static setToolObject = function(toolObject) { self.toolObject = toolObject; return self; } static setToolObject = function(toolObject) { self.toolObject = toolObject; return self; }
static setToolFn = function(toolFn) { self.toolFn = toolFn; return self; } static setToolFn = function(toolFn) { self.toolFn = toolFn; return self; }
@ -29,7 +28,8 @@ function NodeTool(name, spr, context = instanceof(other)) constructor {
var _nme = getName(index); var _nme = getName(index);
var _key = checkHotkey(); var _key = checkHotkey();
return _key == ""? _nme : new tooltipHotkey(_nme).setKey(_key); if(_key == noone) return _nme;
return new tooltipHotkey(_nme).setKey(_key.getName());
} }
static setSetting = function(sets) { array_push(settings, sets); return self; } static setSetting = function(sets) { array_push(settings, sets); return self; }
@ -55,8 +55,8 @@ function NodeTool(name, spr, context = instanceof(other)) constructor {
static toggle = function(index = 0) { static toggle = function(index = 0) {
if(toolFn != noone) { if(toolFn != noone) {
if(subtools == 0) toolFn(ctx); if(subtools == 0) toolFn(context);
else toolFn[index](ctx); else toolFn[index](context);
return; return;
} }
@ -76,18 +76,23 @@ function NodeTool(name, spr, context = instanceof(other)) constructor {
onToggle(); onToggle();
var _obj = getToolObject(); var _obj = getToolObject();
if(_obj) _obj.init(ctx); if(_obj) _obj.init(context);
} }
static toggleKeyboard = function() { static toggleKeyboard = function() {
HOTKEY_BLOCK = true;
if(subtools == 0) { if(subtools == 0) {
PANEL_PREVIEW.tool_current = PANEL_PREVIEW.tool_current == self? noone : self; PANEL_PREVIEW.tool_current = PANEL_PREVIEW.tool_current == self? noone : self;
} else if(PANEL_PREVIEW.tool_current != self) { } else if(PANEL_PREVIEW.tool_current != self) {
PANEL_PREVIEW.tool_current = self; PANEL_PREVIEW.tool_current = self;
selecting = 0; selecting = 0;
} else if(selecting == subtools - 1) { } else if(selecting == subtools - 1) {
PANEL_PREVIEW.tool_current = noone; PANEL_PREVIEW.tool_current = noone;
selecting = 0; selecting = 0;
} else } else
selecting++; selecting++;

View file

@ -1601,7 +1601,7 @@ function Panel_Preview() : PanelContent() constructor {
if(thov && point_in_rectangle(_mx, _my, _x0, _y0 + 1, _x1, _y1 - 1)) if(thov && point_in_rectangle(_mx, _my, _x0, _y0 + 1, _x1, _y1 - 1))
tool_hovering = tool; tool_hovering = tool;
if(tool.subtools > 0 && _tool == tool) { #region subtools if(tool.subtools > 0 && _tool == tool) { #region hovering subtools
var s_ww = tool_size * tool.subtools; var s_ww = tool_size * tool.subtools;
var s_hh = tool_size; var s_hh = tool_size;
draw_sprite_stretched(THEME.menu_bg, 0, _x0 - pd, _y0 - pd, s_ww + pd * 2, s_hh + pd * 2); draw_sprite_stretched(THEME.menu_bg, 0, _x0 - pd, _y0 - pd, s_ww + pd * 2, s_hh + pd * 2);
@ -1636,6 +1636,7 @@ function Panel_Preview() : PanelContent() constructor {
if(point_in_rectangle(_mx, _my, _x0, _y0 + 1, _x0 + s_ww, _y1 - 1)) if(point_in_rectangle(_mx, _my, _x0, _y0 + 1, _x0 + s_ww, _y1 - 1))
tool_hovering = tool; tool_hovering = tool;
#endregion #endregion
} else { #region single tools } else { #region single tools
if(tool_hovering == tool) { if(tool_hovering == tool) {
draw_sprite_stretched(THEME.button_hide, 1, _x0 + pd, _y0 + pd, tool_size - pd * 2, tool_size - pd * 2); draw_sprite_stretched(THEME.button_hide, 1, _x0 + pd, _y0 + pd, tool_size - pd * 2, tool_size - pd * 2);
@ -1648,7 +1649,7 @@ function Panel_Preview() : PanelContent() constructor {
if(pFOCUS && WIDGET_CURRENT == noone) { if(pFOCUS && WIDGET_CURRENT == noone) {
var _key = tool.checkHotkey(); var _key = tool.checkHotkey();
if(keyboard_check_pressed(ord(string(i + 1))) || (_key != "" && keyboard_check_pressed(ord(_key)))) if(keyboard_check_pressed(ord(string(i + 1))) || (_key != noone && _key.isPressing()))
tool.toggleKeyboard(); tool.toggleKeyboard();
} }
@ -1712,7 +1713,7 @@ function Panel_Preview() : PanelContent() constructor {
if(thov && point_in_rectangle(_mx, _my, _x0, _y0 + 1, _x1, _y1 - 1)) if(thov && point_in_rectangle(_mx, _my, _x0, _y0 + 1, _x1, _y1 - 1))
tool_hovering = tool; tool_hovering = tool;
if(tool.subtools > 0 && _tool == tool) { #region subtools if(tool.subtools > 0 && _tool == tool) { #region hovering subtools
var stool = tool.spr; var stool = tool.spr;
var s_ww = tool_size * tool.subtools; var s_ww = tool_size * tool.subtools;
@ -1760,6 +1761,12 @@ function Panel_Preview() : PanelContent() constructor {
tool.toggle(); tool.toggle();
} }
if(pFOCUS && WIDGET_CURRENT == noone) {
var _key = tool.checkHotkey();
if(keyboard_check_pressed(ord(string(i + 1))) || (_key != noone && _key.isPressing()))
tool.toggleKeyboard();
}
if(tool_current == tool) { if(tool_current == tool) {
draw_sprite_stretched_ext(THEME.button_hide, 2, _x0 + pd, _y0 + pd, tool_size - pd * 2, tool_size - pd * 2, COLORS.panel_preview_grid, 1); draw_sprite_stretched_ext(THEME.button_hide, 2, _x0 + pd, _y0 + pd, tool_size - pd * 2, tool_size - pd * 2, COLORS.panel_preview_grid, 1);
draw_sprite_stretched_ext(THEME.button_hide, 3, _x0 + pd, _y0 + pd, tool_size - pd * 2, tool_size - pd * 2, COLORS._main_accent, 1); draw_sprite_stretched_ext(THEME.button_hide, 3, _x0 + pd, _y0 + pd, tool_size - pd * 2, tool_size - pd * 2, COLORS._main_accent, 1);

View file

@ -2,7 +2,7 @@ function tooltipHotkey(text, context = "", name = "") constructor {
self.text = text; self.text = text;
self.hotkey = find_hotkey(context, name); self.hotkey = find_hotkey(context, name);
keyStr = hotkey? key_get_name(hotkey.key, hotkey.modi) : ""; keyStr = hotkey? key_get_name(hotkey.key, hotkey.modi) : "";
static setKey = function(key) { keyStr = key; return self; } static setKey = function(key) { keyStr = key; return self; }