Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // draw_text_col(x, y, text, line)
- var col_prev = draw_get_color();
- var breaks = ds_list_create();
- var strings = ds_list_create();
- var colors = ds_list_create();
- // Parse strings and colors
- for (var i = 0; i <= string_length(argument2); i += 1) {
- // Get the color
- if (string_char_at(argument2, i) == "[" && string_char_at(argument2, i + 1) == "c"
- && string_char_at(argument2, i + 2) == " ") {
- i += 3;
- // 3 values: R, G, B
- var col;
- col[2] = -1;
- col[1] = -1;
- col[0] = -1;
- // Get color
- repeat (3) {
- var col_tmp = "";
- // Skip multiple spaces
- while (string_char_at(argument2, i) == " ") i += 1;
- while (ord(string_char_at(argument2, i)) >= ord("0") && ord(string_char_at(argument2, i)) <= ord("9")) {
- col_tmp += string_char_at(argument2, i);
- i += 1;
- }
- i += 1;
- // Skip multiple spaces
- while (string_char_at(argument2, i) == " ") i += 1;
- // Assign temporary values
- if (col[0] == -1) col[0] = real(col_tmp);
- else if (col[1] == -1) col[1] = real(col_tmp);
- else if (col[2] == -1) col[2] = real(col_tmp);
- }
- ds_list_add(colors, make_color_rgb(col[0], col[1], col[2])); // Create color from temp values
- col[0] = -1;
- col[1] = -1;
- col[2] = -1;
- // Get associated string(s)
- var text_tmp = "";
- while (i <= string_length(argument2) && string_char_at(argument2, i) != "[") {
- if (string_char_at(argument2, i) == "#") {
- ds_list_add(strings, text_tmp);
- ds_list_add(breaks, ds_list_size(strings));
- ds_list_add(colors, colors[| ds_list_size(colors) - 1]);
- text_tmp = "";
- }
- else
- text_tmp += string_char_at(argument2, i);
- i += 1;
- }
- ds_list_add(strings, text_tmp);
- i -= 1; // Prepare for next color(eventually)
- }
- }
- // Take a moment to contemplate how beautyful life is
- // Setup
- var text_x = argument0;
- var text_y = argument1;
- var line = argument3;
- var h = string_height("l") * (1 + 0.1 * line);
- var p = 0;
- // Draw
- for (var i = 0; i < ds_list_size(strings); i++) {
- if (i == breaks[| p]) { // New line
- text_y += h;
- text_x = argument0;
- p += 1;
- }
- draw_set_color(colors[| i]);
- draw_text(text_x, text_y, strings[| i]);
- text_x += string_width(strings[| i]);
- }
- // Reset color
- draw_set_color(col_prev);
- // Clean
- ds_list_destroy(colors);
- ds_list_destroy(strings);
- ds_list_destroy(breaks);
- // I <3 U
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement