mirror of
https://github.com/Ttanasart-pt/Pixel-Composer.git
synced 2024-12-25 22:46:19 +01:00
- [Text area] Add syntax highlighting for single line comment.
This commit is contained in:
parent
ee7d0901dc
commit
043bc5eba9
4 changed files with 49 additions and 33 deletions
Binary file not shown.
|
@ -15,33 +15,38 @@ var constant = ["MATRIX_VIEW", "MATRIX_PROJECTION", "MATRIX_WORLD", "MATRIX_WORL
|
||||||
for( var i = 0, n = array_length(constant); i < n; i++ )
|
for( var i = 0, n = array_length(constant); i < n; i++ )
|
||||||
global.glsl_constant[? constant[i]] = 1;
|
global.glsl_constant[? constant[i]] = 1;
|
||||||
|
|
||||||
global.HLSL_BREAK_TOKEN = [" ", "(", ")", "[", "]", "{", "}", ".", ",", ";", "+", "-", "*", "/", "^", "="];
|
global.HLSL_BREAK_TOKEN = [" ", "(", ")", "[", "]", "{", "}", ".", ",", ";", "+", "-", "*", "/", "^", "=", "//"];
|
||||||
|
|
||||||
function hlsl_token_splice(str) {
|
function hlsl_token_splice(str) {
|
||||||
var st = [];
|
var st = [];
|
||||||
var ss = str;
|
var ss = str;
|
||||||
var sp;
|
var sp, cc, del;
|
||||||
var cc;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
sp = 999999;
|
sp = 999999;
|
||||||
|
del = "";
|
||||||
|
|
||||||
for( var i = 0, n = array_length(global.HLSL_BREAK_TOKEN); i < n; i++ ) {
|
for( var i = 0, n = array_length(global.HLSL_BREAK_TOKEN); i < n; i++ ) {
|
||||||
var _pos = string_pos(global.HLSL_BREAK_TOKEN[i], ss);
|
var _del = global.HLSL_BREAK_TOKEN[i];
|
||||||
if(_pos != 0) sp = min(sp, _pos);
|
var _pos = string_pos(_del, ss);
|
||||||
|
|
||||||
|
if(_pos != 0 && _pos < sp || (_pos == sp && string_length(del) < string_length(_del))) {
|
||||||
|
sp = _pos;
|
||||||
|
del = _del;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sp == 999999) { //no delim left
|
if(del == "") { //no delim left
|
||||||
array_push(st, ss);
|
array_push(st, ss);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ss = string_copy(ss, 1, sp - 1);
|
var _ss = string_copy(ss, 1, sp - 1);
|
||||||
array_push(st, _ss);
|
array_push(st, _ss);
|
||||||
|
array_push(st, del);
|
||||||
|
|
||||||
cc = string_char_at(ss, sp);
|
var dl = string_length(del);
|
||||||
array_push(st, cc);
|
ss = string_copy(ss, sp + dl, string_length(ss) - sp - dl + 1);
|
||||||
|
|
||||||
ss = string_copy(ss, sp + 1, string_length(ss) - sp);
|
|
||||||
} until(sp == 0);
|
} until(sp == 0);
|
||||||
|
|
||||||
return st;
|
return st;
|
||||||
|
@ -51,14 +56,19 @@ function draw_code_hlsl(_x, _y, str) {
|
||||||
var tx = _x;
|
var tx = _x;
|
||||||
var ty = _y;
|
var ty = _y;
|
||||||
var words = hlsl_token_splice(str);
|
var words = hlsl_token_splice(str);
|
||||||
|
var comment = false;
|
||||||
|
|
||||||
for( var j = 0; j < array_length(words); j++ ) {
|
for( var j = 0; j < array_length(words); j++ ) {
|
||||||
var word = words[j];
|
var word = words[j];
|
||||||
var wordNoS = string_trim(word);
|
var wordNoS = string_trim(word);
|
||||||
|
|
||||||
|
if(wordNoS == "//") comment = true;
|
||||||
|
|
||||||
draw_set_color(COLORS._main_text);
|
draw_set_color(COLORS._main_text);
|
||||||
|
|
||||||
if(word == "(" || word == ")" || word == "[" || word == "]" || word == "{" || word == "}")
|
if(comment)
|
||||||
|
draw_set_color(COLORS.lua_highlight_comment);
|
||||||
|
else if(word == "(" || word == ")" || word == "[" || word == "]" || word == "{" || word == "}")
|
||||||
draw_set_color(COLORS.lua_highlight_bracklet);
|
draw_set_color(COLORS.lua_highlight_bracklet);
|
||||||
else if(ds_map_exists(global.glsl_reserved, word))
|
else if(ds_map_exists(global.glsl_reserved, word))
|
||||||
draw_set_color(COLORS.lua_highlight_keyword);
|
draw_set_color(COLORS.lua_highlight_keyword);
|
||||||
|
|
|
@ -8,33 +8,38 @@ var reserved = ["and", "break", "do", "else", "elseif", "end", "false",
|
||||||
for( var i = 0, n = array_length(reserved); i < n; i++ )
|
for( var i = 0, n = array_length(reserved); i < n; i++ )
|
||||||
global.lua_reserved[? reserved[i]] = 1;
|
global.lua_reserved[? reserved[i]] = 1;
|
||||||
|
|
||||||
global.CODE_BREAK_TOKEN = [" ", "(", ")", "[", "]", "{", "}", ",", ";", "+", "-", "*", "/", "^", "="];
|
global.CODE_BREAK_TOKEN = [" ", "(", ")", "[", "]", "{", "}", ",", ";", "+", "-", "*", "/", "^", "=", "--"];
|
||||||
|
|
||||||
function lua_token_splice(str) {
|
function lua_token_splice(str) {
|
||||||
var st = [];
|
var st = [];
|
||||||
var ss = str;
|
var ss = str;
|
||||||
var sp;
|
var sp, cc, del;
|
||||||
var cc;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
sp = 999999;
|
sp = 999999;
|
||||||
|
del = "";
|
||||||
|
|
||||||
for( var i = 0, n = array_length(global.CODE_BREAK_TOKEN); i < n; i++ ) {
|
for( var i = 0, n = array_length(global.CODE_BREAK_TOKEN); i < n; i++ ) {
|
||||||
var _pos = string_pos(global.CODE_BREAK_TOKEN[i], ss);
|
var _del = global.CODE_BREAK_TOKEN[i];
|
||||||
if(_pos != 0) sp = min(sp, _pos);
|
var _pos = string_pos(_del, ss);
|
||||||
|
|
||||||
|
if(_pos != 0 && _pos < sp || (_pos == sp && string_length(del) < string_length(_del))) {
|
||||||
|
sp = _pos;
|
||||||
|
del = _del;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sp == 999999) { //no delim left
|
if(del == "") { //no delim left
|
||||||
array_push(st, ss);
|
array_push(st, ss);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ss = string_copy(ss, 1, sp - 1);
|
var _ss = string_copy(ss, 1, sp - 1);
|
||||||
array_push(st, _ss);
|
array_push(st, _ss);
|
||||||
|
array_push(st, del);
|
||||||
|
|
||||||
cc = string_char_at(ss, sp);
|
var dl = string_length(del);
|
||||||
array_push(st, cc);
|
ss = string_copy(ss, sp + dl, string_length(ss) - sp - dl + 1);
|
||||||
|
|
||||||
ss = string_copy(ss, sp + 1, string_length(ss) - sp);
|
|
||||||
} until(sp == 0);
|
} until(sp == 0);
|
||||||
|
|
||||||
return st;
|
return st;
|
||||||
|
@ -47,6 +52,7 @@ function draw_code_lua(_x, _y, str) {
|
||||||
var isStr = true;
|
var isStr = true;
|
||||||
var strSpl = string_splice(str, "\"");
|
var strSpl = string_splice(str, "\"");
|
||||||
var amo = array_length(strSpl);
|
var amo = array_length(strSpl);
|
||||||
|
var comment = false;
|
||||||
var word;
|
var word;
|
||||||
|
|
||||||
for( var i = 0; i < amo; i++ ) {
|
for( var i = 0; i < amo; i++ ) {
|
||||||
|
@ -71,8 +77,12 @@ function draw_code_lua(_x, _y, str) {
|
||||||
word = words[j];
|
word = words[j];
|
||||||
var wordNoS = string_trim(word);
|
var wordNoS = string_trim(word);
|
||||||
|
|
||||||
|
if(wordNoS == "//") comment = true;
|
||||||
|
|
||||||
draw_set_color(COLORS._main_text);
|
draw_set_color(COLORS._main_text);
|
||||||
if(word == "(" || word == ")" || word == "[" || word == "]" || word == "{" || word == "}")
|
if(comment)
|
||||||
|
draw_set_color(COLORS.lua_highlight_comment);
|
||||||
|
else if(word == "(" || word == ")" || word == "[" || word == "]" || word == "{" || word == "}")
|
||||||
draw_set_color(COLORS.lua_highlight_bracklet);
|
draw_set_color(COLORS.lua_highlight_bracklet);
|
||||||
else if(ds_map_exists(global.lua_reserved, word))
|
else if(ds_map_exists(global.lua_reserved, word))
|
||||||
draw_set_color(COLORS.lua_highlight_keyword);
|
draw_set_color(COLORS.lua_highlight_keyword);
|
||||||
|
|
|
@ -580,16 +580,12 @@ function textArea(_input, _onModify) : textInput(_input, _onModify) constructor
|
||||||
draw_text_path(ch_x, ch_y, _str);
|
draw_text_path(ch_x, ch_y, _str);
|
||||||
break;
|
break;
|
||||||
case TEXT_AREA_FORMAT.codeLUA :
|
case TEXT_AREA_FORMAT.codeLUA :
|
||||||
if(syntax_highlight)
|
if(syntax_highlight) draw_code_lua(ch_x, ch_y, _str);
|
||||||
draw_code_lua(ch_x, ch_y, _str);
|
else draw_text_add(ch_x, ch_y, _str);
|
||||||
else
|
|
||||||
draw_text_add(ch_x, ch_y, _str);
|
|
||||||
break;
|
break;
|
||||||
case TEXT_AREA_FORMAT.codeHLSL :
|
case TEXT_AREA_FORMAT.codeHLSL :
|
||||||
if(syntax_highlight)
|
if(syntax_highlight) draw_code_hlsl(ch_x, ch_y, _str);
|
||||||
draw_code_hlsl(ch_x, ch_y, _str);
|
else draw_text_add(ch_x, ch_y, _str);
|
||||||
else
|
|
||||||
draw_text_add(ch_x, ch_y, _str);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue