mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-12-25 06:26:42 +01:00
- [L-system] Add a warning when providing invalid glyph and when trying to pop an empty stack.
This commit is contained in:
parent
687013714d
commit
663dc2ec2f
8 changed files with 86 additions and 54 deletions
Binary file not shown.
|
@ -58,7 +58,7 @@ event_inherited();
|
|||
category_width = maxLen + ui(56);
|
||||
#endregion
|
||||
|
||||
function rightClick(node) { #region
|
||||
function rightClick(node) {
|
||||
if(!is_instanceof(node, NodeObject)) return;
|
||||
|
||||
node_menu_selecting = node;
|
||||
|
@ -76,9 +76,9 @@ event_inherited();
|
|||
];
|
||||
|
||||
menuCall("add_node_window_manu",,, menu,, node_menu_selecting);
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function filtered(node) { #region
|
||||
function filtered(node) {
|
||||
if(!node_show_connectable) return true;
|
||||
if(node_called == noone && junction_hovering == noone) return true;
|
||||
if(!struct_has(node, "node")) return true;
|
||||
|
@ -129,9 +129,9 @@ event_inherited();
|
|||
}
|
||||
|
||||
return false;
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function buildNode(_node, _param = {}) { #region
|
||||
function buildNode(_node, _param = {}) {
|
||||
instance_destroy();
|
||||
instance_destroy(o_dialog_menubox);
|
||||
|
||||
|
@ -278,7 +278,7 @@ event_inherited();
|
|||
}
|
||||
}
|
||||
}
|
||||
} #endregion
|
||||
}
|
||||
|
||||
catagory_pane = new scrollPane(category_width, dialog_h - ui(66), function(_y, _m) { #region catagory_pane
|
||||
draw_clear_alpha(COLORS._main_text, 0);
|
||||
|
@ -813,7 +813,9 @@ event_inherited();
|
|||
var grid_size = ui(64);
|
||||
var grid_width = ui(80);
|
||||
var grid_space = ui(16);
|
||||
|
||||
|
||||
var highlight = PREFERENCES.dialog_add_node_search_high;
|
||||
|
||||
if(equation) { #region
|
||||
var eq = string_replace(search_string, "=", "");
|
||||
|
||||
|
@ -934,13 +936,19 @@ event_inherited();
|
|||
|
||||
draw_set_text(f_p2, fa_center, fa_top, COLORS._main_text);
|
||||
var _qhh = string_height_ext(_query, -1, grid_width);
|
||||
if(_drw) _qhh = draw_text_match_ext(_boxx + grid_size / 2, _nmy, _query, grid_width, search_string);
|
||||
if(_drw) {
|
||||
if(highlight) _qhh = draw_text_match_ext(_boxx + grid_size / 2, _nmy, _query, grid_width, search_string);
|
||||
else draw_text_ext( _boxx + grid_size / 2, _nmy, _query, -1, grid_width);
|
||||
}
|
||||
_nmy += _qhh;
|
||||
_nmh += _qhh;
|
||||
|
||||
} else {
|
||||
draw_set_text(f_p2, fa_center, fa_top, COLORS._main_text);
|
||||
if(_drw) _nmh = draw_text_match_ext(_boxx + grid_size / 2, _nmy, _name, grid_width, search_string);
|
||||
if(_drw) {
|
||||
if(highlight) _nmh = draw_text_match_ext(_boxx + grid_size / 2, _nmy, _name, grid_width, search_string);
|
||||
else draw_text_ext( _boxx + grid_size / 2, _nmy, _name, -1, grid_width);
|
||||
}
|
||||
}
|
||||
|
||||
name_height = max(name_height, _nmh);
|
||||
|
@ -1035,7 +1043,8 @@ event_inherited();
|
|||
}
|
||||
|
||||
draw_set_text(f_p2, fa_left, fa_center, COLORS._main_text);
|
||||
draw_text_match(list_height + ui(40), yy + list_height / 2, _node.getName(), search_string);
|
||||
if(highlight) draw_text_match(list_height + ui(40), yy + list_height / 2, _node.getName(), search_string);
|
||||
else draw_text( list_height + ui(40), yy + list_height / 2, _node.getName());
|
||||
}
|
||||
|
||||
if(node_focusing == i) search_pane.scroll_y_to = -max(0, hh - search_pane.h);
|
||||
|
|
|
@ -10,6 +10,11 @@ if !ready exit;
|
|||
WIDGET_CURRENT = tb_search;
|
||||
tb_search.setFocusHover(sFOCUS, sHOVER);
|
||||
|
||||
var tw = dialog_w - ui(96);
|
||||
var th = ui(32);
|
||||
var tx = dialog_x + ui(14);
|
||||
var ty = dialog_y + ui(14);
|
||||
|
||||
if(search_string == "") {
|
||||
catagory_pane.setFocusHover(sFOCUS, sHOVER);
|
||||
catagory_pane.draw(dialog_x + ui(14), dialog_y + ui(52));
|
||||
|
@ -24,12 +29,13 @@ if !ready exit;
|
|||
draw_sprite_stretched(THEME.ui_panel_bg, 1, dialog_x + ui(14), dialog_y + ui(52), dialog_w - ui(28), dialog_h - ui(66));
|
||||
search_pane.setFocusHover(sFOCUS, sHOVER);
|
||||
search_pane.draw(dialog_x + ui(16), dialog_y + ui(52));
|
||||
|
||||
tw -= ui(32);
|
||||
}
|
||||
|
||||
var tw = dialog_w - ui(96);
|
||||
if(node_called != noone || junction_hovering != noone)
|
||||
tw -= ui(32);
|
||||
tb_search.draw(dialog_x + ui(14), dialog_y + ui(14), tw, ui(32), search_string, mouse_ui);
|
||||
if(node_called != noone || junction_hovering != noone) tw -= ui(32);
|
||||
|
||||
tb_search.draw(tx, ty, tw, th, search_string, mouse_ui);
|
||||
|
||||
var bx = dialog_x + dialog_w - ui(44);
|
||||
var by = dialog_y + ui(16);
|
||||
|
@ -50,10 +56,16 @@ if !ready exit;
|
|||
var txt = node_show_connectable? __txtx("add_node_show_connect", "Showing connectable") : __txtx("add_node_show_all", "Showing all");
|
||||
var cc = node_show_connectable? COLORS._main_accent : COLORS._main_icon;
|
||||
bx -= ui(32);
|
||||
var b = buttonInstant(THEME.button_hide, bx, by, ui(28), ui(28), mouse_ui, sFOCUS, sHOVER, txt, THEME.filter_type, node_show_connectable, cc);
|
||||
if(b == 2)
|
||||
if(buttonInstant(THEME.button_hide, bx, by, ui(28), ui(28), mouse_ui, sFOCUS, sHOVER, txt, THEME.filter_type, node_show_connectable, cc) == 2)
|
||||
node_show_connectable = !node_show_connectable;
|
||||
}
|
||||
|
||||
if(search_string != "") {
|
||||
var txt = __txtx("add_node_highlight", "Hightlight Query");
|
||||
bx -= ui(32);
|
||||
if(buttonInstant(THEME.button_hide, bx, by, ui(28), ui(28), mouse_ui, sFOCUS, sHOVER, txt, THEME.add_node_search_high, PREFERENCES.dialog_add_node_search_high, COLORS._main_icon) == 2)
|
||||
PREFERENCES.dialog_add_node_search_high = !PREFERENCES.dialog_add_node_search_high;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region tooltip
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
"$GMObject":"",
|
||||
"%Name":"o_dialog_add_node",
|
||||
"eventList":[
|
||||
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":64,"eventType":8,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
|
||||
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":0,"eventType":0,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
|
||||
{"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":0,"eventType":1,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
|
||||
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":64,"eventType":8,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
|
||||
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":0,"eventType":0,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
|
||||
{"$GMEvent":"","%Name":"","collisionObjectId":null,"eventNum":0,"eventType":1,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",},
|
||||
],
|
||||
"managed":true,
|
||||
"name":"o_dialog_add_node",
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
function L_Turtle(x = 0, y = 0, ang = 90, w = 1, color = c_white) constructor { #region
|
||||
self.x = x;
|
||||
self.y = y;
|
||||
self.ang = ang;
|
||||
self.w = w;
|
||||
function L_Turtle(x = 0, y = 0, ang = 90, w = 1, color = c_white) constructor {
|
||||
self.x = x;
|
||||
self.y = y;
|
||||
self.ang = ang;
|
||||
self.w = w;
|
||||
self.color = color;
|
||||
|
||||
static clone = function() { return new L_Turtle(x, y, ang, w, color); }
|
||||
} #endregion
|
||||
}
|
||||
|
||||
function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) constructor {
|
||||
name = "L System";
|
||||
|
@ -45,7 +45,7 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const
|
|||
|
||||
outputs[| 0] = nodeValue("Path", self, JUNCTION_CONNECT.output, VALUE_TYPE.pathnode, self);
|
||||
|
||||
rule_renderer = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) { #region
|
||||
rule_renderer = new Inspector_Custom_Renderer(function(_x, _y, _w, _m, _hover, _focus) {
|
||||
rule_renderer.x = _x;
|
||||
rule_renderer.y = _y;
|
||||
rule_renderer.w = _w;
|
||||
|
@ -85,7 +85,7 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const
|
|||
_name.editWidget.register(parent);
|
||||
_rule.editWidget.register(parent);
|
||||
}
|
||||
}); #endregion
|
||||
});
|
||||
|
||||
input_display_list = [
|
||||
["Origin", false], 2, 6,
|
||||
|
@ -107,15 +107,15 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const
|
|||
boundary = new BoundingBox();
|
||||
|
||||
cache_data = {
|
||||
start: "",
|
||||
rules: {},
|
||||
end_rule: "",
|
||||
iteration: 0,
|
||||
seed: 0,
|
||||
result: ""
|
||||
start : "",
|
||||
rules : {},
|
||||
end_rule : "",
|
||||
iteration : 0,
|
||||
seed : 0,
|
||||
result : ""
|
||||
}
|
||||
|
||||
static refreshDynamicInput = function() { #region
|
||||
static refreshDynamicInput = function() {
|
||||
var _l = ds_list_create();
|
||||
|
||||
for( var i = 0; i < input_fix_len; i++ )
|
||||
|
@ -138,14 +138,14 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const
|
|||
inputs = _l;
|
||||
|
||||
createNewInput();
|
||||
} #endregion
|
||||
}
|
||||
|
||||
static onValueUpdate = function(index) { #region
|
||||
static onValueUpdate = function(index) {
|
||||
if(index > input_fix_len && !LOADING && !APPENDING)
|
||||
refreshDynamicInput();
|
||||
}
|
||||
|
||||
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) { #region
|
||||
static drawOverlay = function(hover, active, _x, _y, _s, _mx, _my, _snx, _sny) {
|
||||
inputs[| 2].drawOverlay(hover, active, _x, _y, _s, _mx, _my, _snx, _sny);
|
||||
|
||||
draw_set_color(COLORS._main_accent);
|
||||
|
@ -165,7 +165,7 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const
|
|||
|
||||
draw_line(x0, y0, x1, y1);
|
||||
}
|
||||
} #endregion
|
||||
}
|
||||
|
||||
static getLineCount = function() { return array_length(lines); }
|
||||
static getSegmentCount = function() { return 1; }
|
||||
|
@ -173,11 +173,11 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const
|
|||
static getLength = function() { return current_length; }
|
||||
static getAccuLength = function() { return [ 0, current_length ]; }
|
||||
|
||||
static getWeightDistance = function (_dist, _ind = 0) { #region
|
||||
static getWeightDistance = function (_dist, _ind = 0) {
|
||||
return getWeightRatio(_dist / current_length, _ind);
|
||||
} #endregion
|
||||
}
|
||||
|
||||
static getWeightRatio = function (_rat, _ind = 0) { #region
|
||||
static getWeightRatio = function (_rat, _ind = 0) {
|
||||
var _p0 = lines[_ind][0];
|
||||
var _p1 = lines[_ind][1];
|
||||
|
||||
|
@ -185,9 +185,9 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const
|
|||
if(!is_array(_p1) || array_length(_p1) < 2) return 1;
|
||||
|
||||
return lerp(_p0[2], _p1[2], _rat);
|
||||
} #endregion
|
||||
}
|
||||
|
||||
static getPointRatio = function(_rat, _ind = 0, out = undefined) { #region
|
||||
static getPointRatio = function(_rat, _ind = 0, out = undefined) {
|
||||
if(out == undefined) out = new __vec2(); else { out.x = 0; out.y = 0; }
|
||||
|
||||
var _p0 = lines[_ind][0];
|
||||
|
@ -200,13 +200,13 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const
|
|||
out.y = lerp(_p0[1], _p1[1], _rat);
|
||||
|
||||
return out;
|
||||
} #endregion
|
||||
}
|
||||
|
||||
static getPointDistance = function(_dist, _ind = 0, out = undefined) { return getPointRatio(_dist / current_length, _ind, out); }
|
||||
|
||||
static getBoundary = function() { return boundary; }
|
||||
|
||||
static l_system = function(_start, _rules, _end_rule, _iteration, _seed) { #region
|
||||
static l_system = function(_start, _rules, _end_rule, _iteration, _seed) {
|
||||
if(isEqual(cache_data.rules, _rules, true)
|
||||
&& cache_data.start == _start
|
||||
&& cache_data.end_rule == _end_rule
|
||||
|
@ -256,9 +256,9 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const
|
|||
}
|
||||
|
||||
return cache_data.result;
|
||||
} #endregion
|
||||
}
|
||||
|
||||
static update = function() { #region
|
||||
static update = function() {
|
||||
var _len = getInputData(0);
|
||||
var _ang = getInputData(1);
|
||||
var _pos = getInputData(2);
|
||||
|
@ -267,7 +267,7 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const
|
|||
var _end = getInputData(5);
|
||||
var _san = getInputData(6);
|
||||
var _sad = getInputData(7);
|
||||
lineq = ds_queue_create();
|
||||
lineq = ds_queue_create();
|
||||
|
||||
random_set_seed(_sad);
|
||||
current_length = _len;
|
||||
|
@ -304,10 +304,12 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const
|
|||
t.x = nx;
|
||||
t.y = ny;
|
||||
break;
|
||||
|
||||
case "G":
|
||||
t.x = t.x + lengthdir_x(len, t.ang);
|
||||
t.y = t.y + lengthdir_y(len, t.ang);
|
||||
break;
|
||||
|
||||
case "f":
|
||||
var nx = t.x + lengthdir_x(len * frac(itr), t.ang);
|
||||
var ny = t.y + lengthdir_y(len * frac(itr), t.ang);
|
||||
|
@ -317,14 +319,21 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const
|
|||
t.x = nx;
|
||||
t.y = ny;
|
||||
break;
|
||||
|
||||
case "+": t.ang += ang; break;
|
||||
case "-": t.ang -= ang; break;
|
||||
case "|": t.ang += 180; break;
|
||||
|
||||
case "[": ds_stack_push(st, t.clone()); break;
|
||||
case "]": t = ds_stack_pop(st); break;
|
||||
case "]":
|
||||
if(ds_stack_empty(st)) noti_warning("L-system: Trying to pop an empty stack. Make sure that all close brackets ']' has a corresponding open bracket '['.");
|
||||
else t = ds_stack_pop(st);
|
||||
break;
|
||||
|
||||
case ">": t.w += 0.1; break;
|
||||
case "<": t.w -= 0.1; break;
|
||||
|
||||
default : noti_warning($"L-system: Invalid rule '{_ch}'");
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -344,7 +353,7 @@ function Node_Path_L_System(_x, _y, _group = noone) : Node(_x, _y, _group) const
|
|||
ds_queue_destroy(lineq);
|
||||
|
||||
outputs[| 0].setValue(self);
|
||||
} #endregion
|
||||
}
|
||||
|
||||
static onDrawNode = function(xx, yy, _mx, _my, _s, _hover, _focus) {
|
||||
var bbox = drawGetBbox(xx, yy, _s);
|
||||
|
|
|
@ -57,6 +57,7 @@
|
|||
|
||||
PREFERENCES.dialog_add_node_w = 532;
|
||||
PREFERENCES.dialog_add_node_h = 400;
|
||||
PREFERENCES.dialog_add_node_search_high = true;
|
||||
|
||||
PREFERENCES.add_node_remember = true;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"$GMScript":"v1",
|
||||
"$GMScript":"",
|
||||
"%Name":"preferences",
|
||||
"isCompatibility":false,
|
||||
"isDnD":false,
|
||||
|
|
|
@ -129,7 +129,7 @@ function draw_text_match(_x, _y, _text, _search) {
|
|||
} else
|
||||
draw_set_color(cc);
|
||||
|
||||
draw_text(xx, yy, ch);
|
||||
draw_text(ceil(xx), ceil(yy), ch);
|
||||
xx += string_width(ch);
|
||||
j++;
|
||||
}
|
||||
|
@ -149,12 +149,13 @@ function draw_text_match_ext(_x, _y, _text, _w, _search) {
|
|||
var line_w = 0;
|
||||
var words = string_split(_text, " ");
|
||||
var amo = array_length(words);
|
||||
var spw = string_width(" ");
|
||||
|
||||
for( var i = 0; i < amo; i++ ) {
|
||||
var wr = words[i] + " ";
|
||||
var ww = string_width(wr);
|
||||
|
||||
if(line_w + ww > _w) {
|
||||
if(line_w + ww - spw > _w) {
|
||||
array_push(lines, line);
|
||||
line = wr;
|
||||
line_w = ww;
|
||||
|
@ -215,7 +216,7 @@ function draw_text_match_ext(_x, _y, _text, _w, _search) {
|
|||
} else
|
||||
draw_set_color(cc);
|
||||
|
||||
draw_text(xx, yy, ch);
|
||||
draw_text(ceil(xx), ceil(yy), ch);
|
||||
xx += string_width(ch);
|
||||
j++;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue