2024-03-27 11:51:14 +01:00
|
|
|
#region global
|
|
|
|
global.glsl_reserved = ds_map_create();
|
|
|
|
global.glsl_constant = ds_map_create();
|
2023-09-07 20:59:14 +02:00
|
|
|
|
2024-03-27 11:51:14 +01:00
|
|
|
var hlsl_reserved = ["int", "float", "float2", "float3", "float4", "float3x3", "float4x4", "Texture2D", "SamplerState", "uniform",
|
|
|
|
"gl_position", "gm_Matrices", "gl_FragColor", "gm_BaseTexture",
|
|
|
|
"and", "break", "do", "else", "end", "false",
|
|
|
|
"for", "function", "if", "in", "local", "nil", "not",
|
|
|
|
"or", "repeat", "return", "then", "true", "until", "while"];
|
2023-09-07 20:59:14 +02:00
|
|
|
|
2024-03-27 11:51:14 +01:00
|
|
|
for( var i = 0, n = array_length(hlsl_reserved); i < n; i++ )
|
|
|
|
global.glsl_reserved[? hlsl_reserved[i]] = 1;
|
2023-09-07 20:59:14 +02:00
|
|
|
|
2024-03-27 11:51:14 +01:00
|
|
|
var constant = ["MATRIX_VIEW", "MATRIX_PROJECTION", "MATRIX_WORLD", "MATRIX_WORLD_VIEW", "MATRIX_WORLD_VIEW_PROJECTION" ];
|
2023-09-07 20:59:14 +02:00
|
|
|
|
2024-03-27 11:51:14 +01:00
|
|
|
for( var i = 0, n = array_length(constant); i < n; i++ )
|
|
|
|
global.glsl_constant[? constant[i]] = 1;
|
2023-09-07 20:59:14 +02:00
|
|
|
|
2024-03-27 11:51:14 +01:00
|
|
|
global.HLSL_BREAK_TOKEN = [" ", "(", ")", "[", "]", "{", "}", ".", ",", ";", "+", "-", "*", "/", "^", "=", "//"];
|
|
|
|
#endregion
|
2023-09-17 13:23:24 +02:00
|
|
|
|
2024-03-27 11:51:14 +01:00
|
|
|
function hlsl_token_splice(str) { #region
|
2023-09-17 13:23:24 +02:00
|
|
|
var st = [];
|
|
|
|
var ss = str;
|
2023-11-07 12:07:17 +01:00
|
|
|
var sp, cc, del;
|
2023-09-17 13:23:24 +02:00
|
|
|
|
|
|
|
do {
|
2023-11-07 12:07:17 +01:00
|
|
|
sp = 999999;
|
|
|
|
del = "";
|
|
|
|
|
2023-09-17 13:23:24 +02:00
|
|
|
for( var i = 0, n = array_length(global.HLSL_BREAK_TOKEN); i < n; i++ ) {
|
2023-11-07 12:07:17 +01:00
|
|
|
var _del = global.HLSL_BREAK_TOKEN[i];
|
|
|
|
var _pos = string_pos(_del, ss);
|
|
|
|
|
|
|
|
if(_pos != 0 && _pos < sp || (_pos == sp && string_length(del) < string_length(_del))) {
|
|
|
|
sp = _pos;
|
|
|
|
del = _del;
|
|
|
|
}
|
2023-09-17 13:23:24 +02:00
|
|
|
}
|
|
|
|
|
2023-11-07 12:07:17 +01:00
|
|
|
if(del == "") { //no delim left
|
2023-09-17 13:23:24 +02:00
|
|
|
array_push(st, ss);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ss = string_copy(ss, 1, sp - 1);
|
|
|
|
array_push(st, _ss);
|
2023-11-07 12:07:17 +01:00
|
|
|
array_push(st, del);
|
2023-09-17 13:23:24 +02:00
|
|
|
|
2023-11-07 12:07:17 +01:00
|
|
|
var dl = string_length(del);
|
|
|
|
ss = string_copy(ss, sp + dl, string_length(ss) - sp - dl + 1);
|
2023-09-17 13:23:24 +02:00
|
|
|
} until(sp == 0);
|
|
|
|
|
|
|
|
return st;
|
2024-03-27 11:51:14 +01:00
|
|
|
} #endregion
|
2023-09-17 13:23:24 +02:00
|
|
|
|
2024-03-27 11:51:14 +01:00
|
|
|
function draw_code_hlsl(_x, _y, str) { #region
|
2023-09-07 20:59:14 +02:00
|
|
|
var tx = _x;
|
|
|
|
var ty = _y;
|
2023-11-07 12:07:17 +01:00
|
|
|
var words = hlsl_token_splice(str);
|
2023-09-07 20:59:14 +02:00
|
|
|
|
|
|
|
for( var j = 0; j < array_length(words); j++ ) {
|
|
|
|
var word = words[j];
|
|
|
|
var wordNoS = string_trim(word);
|
|
|
|
|
2024-03-27 11:51:14 +01:00
|
|
|
if(wordNoS == "//") __code_draw_comment = true;
|
2023-11-07 12:07:17 +01:00
|
|
|
|
2024-03-27 11:51:14 +01:00
|
|
|
if(__code_draw_comment)
|
2023-11-07 12:07:17 +01:00
|
|
|
draw_set_color(COLORS.lua_highlight_comment);
|
2024-03-27 11:51:14 +01:00
|
|
|
|
2023-11-07 12:07:17 +01:00
|
|
|
else if(word == "(" || word == ")" || word == "[" || word == "]" || word == "{" || word == "}")
|
2023-09-07 20:59:14 +02:00
|
|
|
draw_set_color(COLORS.lua_highlight_bracklet);
|
2024-03-27 11:51:14 +01:00
|
|
|
|
2023-09-07 20:59:14 +02:00
|
|
|
else if(ds_map_exists(global.glsl_reserved, word))
|
|
|
|
draw_set_color(COLORS.lua_highlight_keyword);
|
2024-03-27 11:51:14 +01:00
|
|
|
|
2023-09-07 20:59:14 +02:00
|
|
|
else if(wordNoS == string_decimal(wordNoS) || ds_map_exists(global.glsl_constant, word))
|
|
|
|
draw_set_color(COLORS.lua_highlight_number);
|
2024-03-27 11:51:14 +01:00
|
|
|
|
|
|
|
else if(j < array_length(words) - 1)
|
2023-09-07 20:59:14 +02:00
|
|
|
if(words[j + 1] == "(") draw_set_color(COLORS.lua_highlight_function);
|
2024-03-27 11:51:14 +01:00
|
|
|
|
|
|
|
else
|
|
|
|
draw_set_color(COLORS._main_text);
|
2023-09-07 20:59:14 +02:00
|
|
|
|
|
|
|
draw_text_add(tx, ty, word);
|
|
|
|
tx += string_width(word);
|
|
|
|
}
|
2024-03-27 11:51:14 +01:00
|
|
|
} #endregion
|