Advertisement
glitchdetector

[GML] draw_text_multicolor

Aug 27th, 2014
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///draw_text_multicolor(x,y,string)
  2. //
  3. // argument0 (x): The initial X position of the text
  4. // argument1 (y): The initial Y position of the text
  5. // argument2 (string): The formatted string to draw
  6. //
  7. // Written by GlitchDetector
  8.  
  9. // Initialize the string variables
  10. var full_string,current_string;
  11. full_string    = argument[2]
  12. current_string = ""
  13.  
  14. // Initialize the positional variables
  15. var pos_x,pos_y,pos_x_start,pos_y_start;
  16. pos_x       = argument[0]
  17. pos_y       = argument[1]
  18. pos_x_start = pos_x
  19. pos_y_start = pos_y
  20.  
  21. // Initialize the string length variables
  22. var string_len,full_len;
  23. string_len = string_length(full_string)
  24. full_len   = string_len
  25.  
  26. // Store the original color so we can reset it after the drawing is complete
  27. var default_color;
  28. default_color = draw_get_color()
  29.  
  30. while( string_len >= 1 ) {
  31.  
  32.   // Get the first letter in the string
  33.   current_string = string_copy(full_string,1,1)
  34.  
  35.   // Delete the first letter in the full string
  36.   full_string    = string_delete(full_string,1,1)
  37.   string_len     = string_length(full_string)
  38.  
  39.   // Check the content of the current letter
  40.   switch( current_string ){
  41.  
  42.     // If it matches the symbol, set the color
  43.     // ^ turns the color black
  44.     case "^":
  45.       draw_set_color(c_black)
  46.     break;
  47.  
  48.     // | turns the color red
  49.     case "|":
  50.       draw_set_color(c_red)
  51.     break;
  52.  
  53.     // \ turns the color green
  54.     case "\":
  55.       draw_set_color(c_green)
  56.     break;
  57.  
  58.     //Here is a template for you to use
  59.     case "":
  60.       draw_set_color(c_white)
  61.     break;
  62.  
  63.     // Newline symbol
  64.     case "#":
  65.       pos_y += string_height("o")
  66.       pos_x = pos_x_start
  67.     break;
  68.  
  69.     // If the letter is not listed above, draw it
  70.     default:
  71.       draw_text(pos_x,pos_y,current_string)
  72.       pos_x += string_width(current_string)
  73.     break;
  74.  
  75.   }
  76.  
  77. }
  78.  
  79. // Reset the color to the original one
  80. draw_set_color(default_color)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement