Stuff by David
All my stuff in one place!
Home/News
Videos
Applications
Games
Resources
About me
Minecraft Note Block Studio tutorials
The Poptart Tragedy
Building songs in Minecraft
Redstone Display Maker tutorial
Auto closing wooden door!
View all...
Minecraft Note Block Studio
Redstone Display Maker
Minecraft Redstone Simulator
The ultimate D&D to GML converter
Image to RTF converter
View all...
Chaos
Die
View all...
Game Maker examples
Labyrinth generator and solver
Tetris
Text editor
Inventory and item engine
View all...
Game Maker scripts
GML syntax coloring in-game
Change colors of certain words in a text
Center the text in the built-in dialogues
Upgrade of keyboard_string
View all...
<
Previous
|
All scripts
|
Next
>
GML syntax coloring in-game
Please enable javascript to view this.
/* CALL: draw_gml(x,y,str) INFO: Draw GML on the screen, where the color and font is automaticly set when encountering comments, functions, variables, constants etc. ARGUMENTS: x = The x position to draw the gml y = The y position to draw the gml str = The GML to draw NOTE: The output will not be affected by horizontal or vertical aligns. The draw_gml_get_type script will be needed. RETURNS: Nothing. WRITTEN BY: Davve http://www.stuffbydavid.com No credit needed if used, but it would be appreciated. */ var xx, yy, str, font, color, prevcol, pos, dx, dy, check, length, current, next, drawstr, type, typec, typef, checkpos; xx = argument0; yy = argument1; str = argument2; font[0] = fnt_gml_normal; font[1] = fnt_gml_italic; font[2] = fnt_gml_bold; color[0] = 0; //Normal text color[1] = 0; //Statements, loops and various others color[2] = 128; //Built-in constant color[3] = 16711680; //Built-in variables color[4] = 8404992; //Resources color[5] = 8388608; //Functions and scripts color[6] = 32768; //Comments color[7] = 16711680; //Values prevcol = draw_get_color(); length = string_length(str); dx = 0; dy = 0; check = 0; for (pos = 1; pos <= length; pos += 1) { current = string_char_at(str, pos); next = string_char_at(str, pos + 1); drawstr = ''; typec = 0; typef = 0; if (check == 0) { if (string_letters(current) != '' || current == '_') { check = 1; } if (current == '/' && next == '/') { check = 2; } if (current == '/' && next == '*') { check = 3; } if (current == '"') { check = 4; current = ''; } if (current == "'") { check = 5; current = ''; } if (string_digits(current) != '') { check = 6; } if (current == '$') { check = 7; } if (current == '{' || current == '}') { typec = 1; typef = 2; } if (check == 0) { drawstr = current; } else { checkpos = pos; } } switch (check) { case 1: { if ((string_lettersdigits(next) == '' && next != '_') || pos == length) { drawstr = string_copy(str, checkpos, pos - checkpos + 1); type = draw_gml_get_type(drawstr); if (next == '(' && type == 0) type = 5; typec = type; if (typec == 1) typef = 2; check = 0; } break; } case 2: { if (next == chr(10) || pos == length) { drawstr = string_copy(str, checkpos, pos - checkpos + 1); typec = 6; typef = 1; check = 0; } break; } case 3: { if (current == chr(10) || pos == length) { drawstr = string_copy(str, checkpos, pos - checkpos + 1); checkpos = pos + 1; typec = 6; typef = 1; } if (current == '*' && next == '/') { pos += 1; drawstr = string_copy(str, checkpos, pos - checkpos + 1); typec = 6; typef = 1; check = 0; } break; } case 4: { if (current == chr(10)) { drawstr = string_copy(str, checkpos, pos - checkpos + 1); checkpos = pos + 1; typec = 7; typef = 0; } else if (current == '"' || pos == length) { drawstr = string_copy(str, checkpos, pos - checkpos + 1); typec = 7; check = 0; } break; } case 5: { if (current == chr(10)) { drawstr = string_copy(str, checkpos, pos - checkpos + 1); checkpos = pos + 1; typec = 7; typef = 0; } else if (current == "'" || pos == length) { drawstr = string_copy(str, checkpos, pos - checkpos + 1); typec = 7; check = 0; } break; } case 6: { if ((string_digits(next) == '' && next != '.') || pos == length) { drawstr = string_copy(str, checkpos, pos - checkpos + 1); typec = 7; check = 0; } break; } case 7: { if ((string_digits(next) == '' && next != 'A' && next != 'B' && next != 'C' && next != 'D' && next != 'E' && next != 'F') || pos == length) { drawstr = string_copy(str, checkpos, pos - checkpos + 1); typec = 7; check = 0; } break; } } if (drawstr != '') { drawstr = string_replace_all(drawstr, '#', '\#'); draw_set_color(color[typec]); draw_set_font(font[typef]); draw_text(xx + dx, yy + dy, drawstr); dx += string_width(drawstr); if (current == chr(10)) { dx = 0; dy += string_height(' '); } } } draw_set_color(prevcol);
Comments
Constructive criticism is always welcome!
Please enable JavaScript to view comments.