GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 Re: Script Submission » Super Script Compilation(105 Scripts)! » 2013-11-16 09:33:28

Thank you Fatal, this compilation will be quite useful. your contribution is greatly appreciated. biggrin

#2 Re: Script Submission » draw_text_rtf » 2013-05-28 13:31:30

I do not have a website at the moment. That line was not intended for more names to be added to the ds_list. If an initialize script is going to be added to this, then I would also use surfaces instead of rendering the text each time. I am trying to provide a single script with as much functionality as possible without requiring initialization or outside scripts. A world of things could be done with this if it was multi script, but my concept was to make a simple plug and play style script for less experienced users to avoid complication and confusion. Please feel free to build an "advanced mode" multi script if you desire. I'm sure people would like that also. sub strings that are longer then the initial string just terminate after the end of the initial string as far as I have ever come across with gm, but please double check that for me.

#3 Re: Script Submission » draw_text_rtf » 2013-05-26 16:00:22

Thank you for the info. I'm not one for importing or exporting scripts since I usually build them for my own use. That is unfortunate that they can not manage a way to show the arguments, wish I could see what they were doing behind the scenes, maybe one day I'll help them build the software and be able to tinker with the UI a bit. But for now, back to making games smile

#4 Re: Script Submission » draw_text_rtf » 2013-05-26 10:37:17

If your happy with its current state, then I will be focusing on my other projects.

I do have a question for you though....why do you have "#define draw_text_rtf" in your initial code?

I have been looking for something that shows the user the scripts arguments. As far as I am aware, there is no #define or /// for scripts to show something in the object when using the script. it currently shows "script_name(...)" but I would like it to show something like "script_name(argument0_name, argument1_name, .etc.)"

Do you know if there is something that does this? I'm considering turning in a suggestion about it.

#5 Re: Script Submission » HSV_shift » 2013-05-25 23:04:27

I will update the code. thanks for the advice. I didn't realize GM already did this and also used the mod before the addition. I should have used parenthesis (I know better), but I made this on the fly for a bug report a while ago while i was at work (i made it on my phone.) I should have looked over it again before posting it. either way, i will update the code. thanks xot

#6 Script Submission » HSV_shift » 2013-05-25 15:00:36

Miah_84
Replies: 4
Expand/*
Original script by Miah_84. This script may be used or modified freely, no attribution needed.

HSV_shift(CurrentColor,HueShift,SaturationShift,ValueShift)

Description: Shifts current color using Hue,Saturation,Value shifts

Returns: A shifted color

Example: ShiftedColor = HSV_shift(c_red,201,97,64)

argument0 = color to be shifted
argument1 = hue shift
argument2 = saturation shift
argument3 = value shift
*/

c = argument0;
h = argument1;
s = argument2;
v = argument3;

new_c = make_color_hsv((color_get_hue(c)+h) & 255, (color_get_saturation(c)+s) & 255, (color_get_value(c)+v) & 255)

return new_c;

#7 Re: Script Submission » draw_text_rtf » 2013-05-25 13:00:26

Implemented Underline. Please check over the formatting/layout/description of the local variables so that it is consistent with the way you make your scripts. what else are we trying to add to this? I think we have covered several things already and I am not sure what else to add now. Thanks for the suggestion csanyk, this has been a fun side project. 

Expand/*
Original draw_text_rtf script by Miah_84.  Additions by csanyk.  This script may be used or modified freely, no attribution needed.

draw_text_rtf(x, y, string, regular_font, bold_font, italic_font, bold_italic_font)

Description: Draws a formatted string using BBCode-like syntax for internal formatting within the string.

Returns: void

Caution:  Only works for halign==left.  Not intended to draw centered or right-aligned text.


argument0 = the x position of the string
argument1 = the y position of the string
argument2 = the string.
argument3 = the regular font
argument4 = the bold font
argument5 = the italic font
argument6 = the bold italic font

The string may contain the following syntax:

[b]bold text[/b]
[i]italic text[/i]
[c=RRGGBB]colored text[/c]
[c=c_NamedColor]colored text using named color[/c] (IMPORTANT: c_NamedColor is UPPER/lower CASE SENSITIVE. see the MSDN list here: http://i.msdn.microsoft.com/dynimg/IC210551.png)
[u]underlined text[/u]
*/

/*
local var definitions

next_x, next_y      : the x and y position of the next substring of the formatted RTF draw
rtf_x, rtf_y        : the x and y position of the rtf string
str                 : the raw rtf string, with syntax formatting awaiting parsing;
f_r, f_b, f_i, f_bi : the index of regular, bold, italic, and bold italic fonts
mode                : a control flag that sets the mode that the parser is currently operating in, eg regular, bold, italic, bold&italic
original_color      : temp storage of the original drawing color, so that the function can revert back to it when needed
i, j                : for loop iterator, re-used several times throughout the function
sc3                 : a lowercase length-3 substring of str, used to parse tags of the formatting syntax
sc4                 : a lowercase length-4 substring of str, used to parse tags of the formatting syntax
sc5                 : a lowercase length-5 substring of str, used to parse tags of the formatting syntax
sc6                 : a lowercase length-6 substring of str, used to parse tags of the formatting syntax
sa, sb              : sub-strings of str, which when concatenated together, yield a string equal to str,
//                    omitting a formatting tag.
//                    Used in building the parsed rtf string
h_r, h_g, h_b       : the hex values of a RGB color, broken into the red, green, and blue values
d_r, d_g, d_b       : the dec values of a RGB color, broken into the red, green, and blue values
rgb                 : sub-strings of str to get values for r,g,b
r,g,b               : sub-strings of rgb for individual red, green, blue values
p1, p2              : the first and second digits of a 2-digit hex value for a given RGB color channel
w                   : "which" color does the hex belong to. A temporary variable used to build the color for the color markup syntax
col_map             : a ds_map of the rtf string containing info about the color formatting
rtf_map             : a ds_map of the rtf string containing info about the bold and italic formatting
names               : a ds_list of the names used for c_NamedColor
hv                  : a ds_list of the hex values associated with the names ds_list
cn                  : a substring of str that gets the c_NamedColor value
hex_str             : a string from ds_list hv that corresponds with c_NamedColor from the ds_list names
ul                  : "underline" boolean for use with [u] and [/u] to be used in ul_map
ul_map              : a ds_map for the underline variable that keeps a list of underline

The ds_maps are used in the last for loop to actually build the markup sentence. Each character is assigned a color and font style using these. this helps to layout the placement for the next character and provide the correct color and format for each character.
*/
var next_x, next_y, rtf_x, rtf_y, str, f_r, f_b, f_i, f_bi, mode, original_color, c, i, j, sc3, sc4, sc5, sc6, sa, sb, h_r, h_b, h_g, d_r, d_g, d_g, p1, p2, w, rgb, r, g, b, names, hv, cn, hex_str, ul, ul_map;

next_x = 0;
next_y = 0;

rtf_x  = argument0;
rtf_y  = argument1;
str    = argument2;

f_r    = argument3;
f_b    = argument4;
f_i    = argument5;
f_bi   = argument6;


//modes
//1 = reg
//2 = bold
//3 = italic
//4 = bold & italic
mode     = 1;
original_color = draw_get_color();
c        = original_color;
rtf_map  = ds_map_create();
col_map  = ds_map_create();
ul       = false; 
ul_map   = ds_map_create();
names    = ds_list_create();
hv       = ds_list_create(); 

ds_list_add(names,"c_AliceBlue");ds_list_add(names,"c_AntiqueWhite");ds_list_add(names,"c_Aqua");ds_list_add(names,"c_Aquamarine");ds_list_add(names,"c_Azure");ds_list_add(names,"c_Beige");ds_list_add(names,"c_Bisque");ds_list_add(names,"c_Black");ds_list_add(names,"c_BlanchedAlmond");ds_list_add(names,"c_Blue");ds_list_add(names,"c_BlueViolet");ds_list_add(names,"c_Brown");ds_list_add(names,"c_BurlyWood");ds_list_add(names,"c_CadetBlue");ds_list_add(names,"c_Chatreuse");ds_list_add(names,"c_Chocolate");ds_list_add(names,"c_Coral");ds_list_add(names,"c_CornFlowerBlue");ds_list_add(names,"c_Cornsilk");ds_list_add(names,"c_Crimson");ds_list_add(names,"c_Cyan");ds_list_add(names,"c_DarkBlue");ds_list_add(names,"c_DarkCyan");ds_list_add(names,"c_DarkGoldenrod");ds_list_add(names,"c_DarkGrey");ds_list_add(names,"c_DarkGreen");ds_list_add(names,"c_DarkKhaki");ds_list_add(names,"c_DarkMagenta");ds_list_add(names,"c_DarkOliveGreen");ds_list_add(names,"c_DarkOrange");ds_list_add(names,"c_DarkOrchid");ds_list_add(names,"c_DarkRed");ds_list_add(names,"c_DarkSalmon");ds_list_add(names,"c_DarkSeaGreen");ds_list_add(names,"c_DarkSlateBlue");ds_list_add(names,"c_DarkSlateGrey");ds_list_add(names,"c_DarkTurquoise");ds_list_add(names,"c_DarkViolet");ds_list_add(names,"c_DeepPink");ds_list_add(names,"c_DeepSkyBlue");ds_list_add(names,"c_DimGrey");ds_list_add(names,"c_DodgerBlue");ds_list_add(names,"c_Firebrick");ds_list_add(names,"c_FloralWhite");ds_list_add(names,"c_ForestGreen");ds_list_add(names,"c_Fuchsia");ds_list_add(names,"c_Gainsboro");ds_list_add(names,"c_GhostWhite");ds_list_add(names,"c_Gold");ds_list_add(names,"c_Goldenrod");ds_list_add(names,"c_Grey");ds_list_add(names,"c_Green");ds_list_add(names,"c_GreenYellow");ds_list_add(names,"c_Honeydew");ds_list_add(names,"c_HotPink");ds_list_add(names,"c_IndianRed");ds_list_add(names,"c_Indigo");ds_list_add(names,"c_Ivory");ds_list_add(names,"c_Khaki");ds_list_add(names,"c_Lavender");ds_list_add(names,"c_LavenderBlush");ds_list_add(names,"c_LawnGreen");ds_list_add(names,"c_LemonChiffon");ds_list_add(names,"c_LightBlue");ds_list_add(names,"c_LightCoral");ds_list_add(names,"c_LightCyan");ds_list_add(names,"c_LightGoldenrodYellow");ds_list_add(names,"c_LigntGray");ds_list_add(names,"c_LightGreen");ds_list_add(names,"c_LightPink");ds_list_add(names,"c_LightSalmon");ds_list_add(names,"c_LightSeaGreen");ds_list_add(names,"c_LightSkyBlue");ds_list_add(names,"c_LightSlateGrey");ds_list_add(names,"c_LightSteelBlue");ds_list_add(names,"c_LightYellow");ds_list_add(names,"c_Lime");ds_list_add(names,"c_LimeGreen");ds_list_add(names,"c_Linen");ds_list_add(names,"c_Magenta");ds_list_add(names,"c_Maroon");ds_list_add(names,"c_MediumAquamarine");ds_list_add(names,"c_MediumBlue");ds_list_add(names,"c_MediumOrchid");ds_list_add(names,"c_MediumPurple");ds_list_add(names,"c_MediumSeaGreen");ds_list_add(names,"c_MediumSlateBlue");ds_list_add(names,"c_MediumSpringGreen");ds_list_add(names,"c_MediumTurquoise");ds_list_add(names,"c_MediumVioletRed");ds_list_add(names,"c_MidnightBlue");ds_list_add(names,"c_MintCream");ds_list_add(names,"c_MistyRose");ds_list_add(names,"c_Moccasin");ds_list_add(names,"c_NavajoWhite");ds_list_add(names,"c_Navy");ds_list_add(names,"c_OldLace");ds_list_add(names,"c_Olive");ds_list_add(names,"c_OliveDrab");ds_list_add(names,"c_Orange");ds_list_add(names,"c_OrangeRed");ds_list_add(names,"c_Orchid");ds_list_add(names,"c_PaleGoldenrod");ds_list_add(names,"c_PaleGreen");ds_list_add(names,"c_PaleTurquoise");ds_list_add(names,"c_PaleVioletRed");ds_list_add(names,"c_PapayaWhip");ds_list_add(names,"c_PeachPuff");ds_list_add(names,"c_Peru");ds_list_add(names,"c_Pink");ds_list_add(names,"c_Plum");ds_list_add(names,"c_PowderBlue");ds_list_add(names,"c_Purple");ds_list_add(names,"c_Red");ds_list_add(names,"c_RosyBrown");ds_list_add(names,"c_RoyalBlue");ds_list_add(names,"c_SaddleBrown");ds_list_add(names,"c_Salmon");ds_list_add(names,"c_SandyBrown");ds_list_add(names,"c_SeaGreen");ds_list_add(names,"c_SeaShell");ds_list_add(names,"c_Sienna");ds_list_add(names,"c_Silver");ds_list_add(names,"c_SkyBlue");ds_list_add(names,"c_SlateBlue");ds_list_add(names,"c_SlateGrey");ds_list_add(names,"c_Snow");ds_list_add(names,"c_SpringGreen");ds_list_add(names,"c_SteelBlue");ds_list_add(names,"c_Tan");ds_list_add(names,"c_Teal");ds_list_add(names,"c_Thistle");ds_list_add(names,"c_Tomato");ds_list_add(names,"c_Turquoise");ds_list_add(names,"c_Violet");ds_list_add(names,"c_Wheat");ds_list_add(names,"c_White");ds_list_add(names,"c_WhiteSmoke");ds_list_add(names,"c_Yellow");ds_list_add(names,"c_YellowGreen")
ds_list_add(hv,"F0F8FF");ds_list_add(hv,"FAEBD7");ds_list_add(hv,"00FFFF");ds_list_add(hv,"7FFFD4");ds_list_add(hv,"F0FFFF");ds_list_add(hv,"F5F5DC");ds_list_add(hv,"FFE4C4");ds_list_add(hv,"000000");ds_list_add(hv,"FFEBCD");ds_list_add(hv,"0000FF");ds_list_add(hv,"8A3BE2");ds_list_add(hv,"A52A2A");ds_list_add(hv,"DEB887");ds_list_add(hv,"5F9EA0");ds_list_add(hv,"7FFF00");ds_list_add(hv,"D2691E");ds_list_add(hv,"FF7F50");ds_list_add(hv,"6495ED");ds_list_add(hv,"FFF8DC");ds_list_add(hv,"DC143C");ds_list_add(hv,"00FFFF");ds_list_add(hv,"00008B");ds_list_add(hv,"008B8B");ds_list_add(hv,"B8860B");ds_list_add(hv,"A9A9A9");ds_list_add(hv,"006400");ds_list_add(hv,"BDB76B");ds_list_add(hv,"8B008B");ds_list_add(hv,"556B2F");ds_list_add(hv,"FF8C00");ds_list_add(hv,"9932CC");ds_list_add(hv,"8B0000");ds_list_add(hv,"E9967A");ds_list_add(hv,"8FBC8F");ds_list_add(hv,"483D8B");ds_list_add(hv,"2F4F4F");ds_list_add(hv,"00CED1");ds_list_add(hv,"9400D3");ds_list_add(hv,"FF1493");ds_list_add(hv,"00BFFF");ds_list_add(hv,"696969");ds_list_add(hv,"1E90FF");ds_list_add(hv,"B22222");ds_list_add(hv,"FFFAF0");ds_list_add(hv,"228B22");ds_list_add(hv,"FF00FF");ds_list_add(hv,"DCDCDC");ds_list_add(hv,"F8F8FF");ds_list_add(hv,"FFD700");ds_list_add(hv,"DAA520");ds_list_add(hv,"808080");ds_list_add(hv,"008000");ds_list_add(hv,"ADFF2F");ds_list_add(hv,"F0FFF0");ds_list_add(hv,"FF69B4");ds_list_add(hv,"CD5C5C");ds_list_add(hv,"4B008C");ds_list_add(hv,"FFFFF0");ds_list_add(hv,"F0E68C");ds_list_add(hv,"E6E6FA");ds_list_add(hv,"FFF0F5");ds_list_add(hv,"7CFC00");ds_list_add(hv,"FFFACD");ds_list_add(hv,"ADD8E6");ds_list_add(hv,"F08080");ds_list_add(hv,"E0FFFF");ds_list_add(hv,"FAFAD2");ds_list_add(hv,"D3D3D3");ds_list_add(hv,"90EE90");ds_list_add(hv,"FFB6C1");ds_list_add(hv,"FFA07A");ds_list_add(hv,"20B2AA");ds_list_add(hv,"87CEFA");ds_list_add(hv,"778899");ds_list_add(hv,"B0C4DE");ds_list_add(hv,"FFFFE0");ds_list_add(hv,"00FF00");ds_list_add(hv,"32CD32");ds_list_add(hv,"FAF0E6");ds_list_add(hv,"FF00FF");ds_list_add(hv,"800000");ds_list_add(hv,"66CDAA");ds_list_add(hv,"0000CD");ds_list_add(hv,"BA55D3");ds_list_add(hv,"9370DB");ds_list_add(hv,"3CB371");ds_list_add(hv,"7B68EE");ds_list_add(hv,"00FA9A");ds_list_add(hv,"48D1CC");ds_list_add(hv,"C71585");ds_list_add(hv,"191970");ds_list_add(hv,"F5FFFA");ds_list_add(hv,"FFE4E1");ds_list_add(hv,"FFFE4B5");ds_list_add(hv,"FFDEAD");ds_list_add(hv,"000080");ds_list_add(hv,"FDF5E6");ds_list_add(hv,"808000");ds_list_add(hv,"6B8E23");ds_list_add(hv,"FFA500");ds_list_add(hv,"FF4500");ds_list_add(hv,"DA70D6");ds_list_add(hv,"EEE8AA");ds_list_add(hv,"98FB98");ds_list_add(hv,"AFEEEE");ds_list_add(hv,"DB7093");ds_list_add(hv,"FFEFD5");ds_list_add(hv,"FFDAB9");ds_list_add(hv,"CD8D3F");ds_list_add(hv,"FFC0CB");ds_list_add(hv,"DDA0DD");ds_list_add(hv,"B0E0E6");ds_list_add(hv,"800080");ds_list_add(hv,"FF000");ds_list_add(hv,"BC8F8F");ds_list_add(hv,"4169E1");ds_list_add(hv,"8B4513");ds_list_add(hv,"FA8072");ds_list_add(hv,"F4A460");ds_list_add(hv,"2E8B57");ds_list_add(hv,"FFF5EE");ds_list_add(hv,"A0522D");ds_list_add(hv,"C0C0C0");ds_list_add(hv,"87CEEB");ds_list_add(hv,"6A5ACD");ds_list_add(hv,"708090");ds_list_add(hv,"FFFAFA");ds_list_add(hv,"00FF7F");ds_list_add(hv,"4682B4");ds_list_add(hv,"D2B4EC");ds_list_add(hv,"008080");ds_list_add(hv,"D88FD8");ds_list_add(hv,"FF6347");ds_list_add(hv,"40E0D0");ds_list_add(hv,"EE82EE");ds_list_add(hv,"F5DEB3");ds_list_add(hv,"FFFFFF");ds_list_add(hv,"F5F5F5");ds_list_add(hv,"FFFF00");ds_list_add(hv,"9ACD32")


for(i = 0; i <= string_length(str); i++){
    sc3 = string_lower(string_copy(str, i, 3));
    sc4 = string_lower(string_copy(str, i, 4));
    sc5 = string_lower(string_copy(str, i, 5));
    sc6 = string_lower(string_copy(str, i ,6));
    if(sc3 == "[b]"){
        if(mode == 1){mode = 2;}
        if(mode == 3){mode = 4;}
        sa = string_copy(str, 0, i-1);
        sb = string_copy(str, i+3, string_length(str) - i - 2);
        str = sa + sb;
        i--;
    }
    if(sc4 = "[/b]"){
        if(mode == 2){mode = 1;}
        if(mode == 4){mode = 3;}
        sa = string_copy(str, 0, i-1);
        sb = string_copy(str, i+4, string_length(str) - i - 3);
        str = sa + sb;
        i--;
    }
    if(sc3 == "[i]"){
        if(mode == 1){mode = 3;}
        if(mode == 2){mode = 4;}
        sa = string_copy(str, 0, i-1);
        sb = string_copy(str, i+3, string_length(str) - i - 2);
        str = sa + sb;
        i--;
    }
    if(sc4 == "[/i]"){
        if(mode == 3){mode=1;}
        if(mode == 4){mode=2;}
        sa = string_copy(str, 0, i-1);
        sb = string_copy(str, i+4, string_length(str) - i - 3);
        str = sa + sb;
        i--;
    }
    ds_map_add(col_map, i - 1, c);
    if(sc3 == "[c=" && sc5 != "[c=c_"){
        h_r = string_copy(str, i + 3, 2);
        h_g = string_copy(str, i + 5, 2);
        h_b = string_copy(str, i + 7, 2);
        for(j = 0; j <= 2; j++){
            switch(j){
                case 0: w = h_r; break;
                case 1: w = h_g; break;
                case 2: w = h_b; break;
            }
            p1 = string_lower(string_char_at(w, 1));
            if(p1 == "a"){p1 = "10";}
            if(p1 == "b"){p1 = "11";}
            if(p1 == "c"){p1 = "12";}
            if(p1 == "d"){p1 = "13";}
            if(p1 == "e"){p1 = "14";}
            if(p1 == "f"){p1 = "15";}
            dec = real(p1) * 16;
            p2 = string_lower(string_char_at(w, 2));
            if(p2 == "a"){p2 = "10";}
            if(p2 == "b"){p2 = "11";}
            if(p2 == "c"){p2 = "12";}
            if(p2 == "d"){p2 = "13";}
            if(p2 == "e"){p2 = "14";}
            if(p2 == "f"){p2 = "15";}
            dec += real(p2);
            switch(j){
                case 0: d_r = dec; break;
                case 1: d_g = dec; break;
                case 2: d_b = dec; break;
            }
        }
        c = make_color_rgb(d_r, d_g, d_b);
        ds_map_replace(col_map, i, c);
        str = string_replace(str,"[c=" + h_r + h_g + h_b + "]", ""); //only replaces the first one, not all
        i--;
    }
    if(sc5 == "[c=c_"){
     cn = string_copy(str,i,32)//random length, long enough to cover all names
     
     cn = string_replace(cn,"[c=","")
     cn = string_copy(cn,0,string_pos("]",cn)-1)
     
     for(j=0;j<ds_list_size(names);j++){
      if(cn == ds_list_find_value(names,j)){
       hex_str = ds_list_find_value(hv,j)
      }
     }
        h_r = string_copy(hex_str, 1, 2);
        h_g = string_copy(hex_str, 3, 2);
        h_b = string_copy(hex_str, 5, 2);
        for(j = 0; j <= 2; j++){
            switch(j){
                case 0: w = h_r; break;
                case 1: w = h_g; break;
                case 2: w = h_b; break;
            }
            p1 = string_lower(string_char_at(w, 1));
            if(p1 == "a"){p1 = "10";}
            if(p1 == "b"){p1 = "11";}
            if(p1 == "c"){p1 = "12";}
            if(p1 == "d"){p1 = "13";}
            if(p1 == "e"){p1 = "14";}
            if(p1 == "f"){p1 = "15";}
            dec = real(p1) * 16;
            p2 = string_lower(string_char_at(w, 2));
            if(p2 == "a"){p2 = "10";}
            if(p2 == "b"){p2 = "11";}
            if(p2 == "c"){p2 = "12";}
            if(p2 == "d"){p2 = "13";}
            if(p2 == "e"){p2 = "14";}
            if(p2 == "f"){p2 = "15";}
            dec += real(p2);
            switch(j){
                case 0: d_r = dec; break;
                case 1: d_g = dec; break;
                case 2: d_b = dec; break;
            }
        }
        c = make_color_rgb(d_r, d_g, d_b);
        ds_map_replace(col_map, i, c);
        str = string_replace(str,"[c=" + cn + "]", ""); //only replaces the first one, not all
        i--;     
    }
    if(sc4 == "[/c]"){
        c = original_color;
        ds_map_replace(col_map, i, c);
        sa = string_copy(str, 0, i - 1);
        sb = string_copy(str, i + 4, string_length(str) - i - 3);
        str = sa + sb;
        i--;
    }
    if(sc5 == "[rgb="){
        rgb = string_copy(str,i,17)
        rgb = string_copy(rgb,0,string_pos("]",rgb)-1)
        rgb = string_replace(rgb,"[rgb=","")
        r = string_copy(rgb,0,string_pos(",",rgb)-1)
        rgb = string_replace(rgb,r+",","")
        g = string_copy(rgb,0,string_pos(",",rgb)-1)
        rgb = string_replace(rgb,g+",","")
        b = rgb
        c = make_color_rgb(real(r), real(g), real(b));
        ds_map_replace(col_map, i, c);
        str = string_replace(str,"[rgb=" + r + "," + g + "," + b + "]", ""); //only replaces the first one, not all
        i--;
    }
    if(sc6 == "[/rgb]"){
        c = original_color;
        ds_map_replace(col_map, i, c);
        sa = string_copy(str, 0, i - 1);
        sb = string_copy(str, i + 6, string_length(str) - i - 5);
        str = sa + sb;
        i--;
    }
    ds_map_add(rtf_map, i, mode);
    ds_map_add(ul_map,i,ul);
    if(sc3 == "[u]"){
        ds_map_replace(ul_map,i,!ul);
        ul = !ul;
        sa = string_copy(str, 0, i-1);
        sb = string_copy(str, i+3, string_length(str) - i - 2);
        str = sa + sb;
        i--;
    }
    if(sc4 == "[/u]"){
        ds_map_replace(ul_map,i,!ul);
        ul = !ul;
        sa = string_copy(str, 0, i-1);
        sb = string_copy(str, i+4, string_length(str) - i - 3);
        str = sa + sb;
        i--;
    }
}

for(i = 1; i <= string_length(str); i++){
    if(string_copy(str, i, 1) == "#"){next_x = 0; next_y += string_height("#");}
    draw_set_color(ds_map_find_value(col_map, i));
    if(ds_map_find_value(ul_map,i)){
     draw_line(rtf_x + next_x, rtf_y + next_y + string_height("|"), rtf_x + next_x + string_width(string_copy(str,i,1)), rtf_y + next_y + string_height("|"))
    }
    switch(ds_map_find_value(rtf_map, i)){
        case 1:
        draw_set_font(f_r);
        draw_text(rtf_x + next_x, rtf_y + next_y, string_copy(str, i, 1));
        next_x += string_width(string_copy(str, i, 1));
        break;
        case 2:
        draw_set_font(f_b);
        draw_text(rtf_x + next_x, rtf_y + next_y, string_copy(str, i, 1));
        next_x += string_width(string_copy(str, i, 1));
        break;
        case 3:
        draw_set_font(f_i);
        draw_text(rtf_x + next_x, rtf_y + next_y, string_copy(str, i, 1));
        next_x += string_width(string_copy(str, i, 1));
        break;
        case 4:
        draw_set_font(f_bi);
        draw_text(rtf_x + next_x, rtf_y + next_y, string_copy(str, i, 1));
        next_x += string_width(string_copy(str, i, 1));
        break;
    }//end switch
}

//reset color
draw_set_color(original_color);
//free up the ds_maps and ds_lists
ds_map_destroy(rtf_map);
ds_map_destroy(col_map);
ds_map_destroy(ul_map);
ds_list_destroy(names);
ds_list_destroy(hv);

#8 Re: Script Submission » draw_text_rtf » 2013-05-25 12:13:19

I am looking at the potential of surfaces with this. do either of you know if there is a function that can check if a variable is a surface or if it was even declared? for example:

Expandif(surface_was_created(rtf_surf) = false){ //looking for something like this
 if(is_declared(rtf_surf) = false){//looking for something like this also
  //initialize the surface
 }
}else{
 if(surface_exists(rtf_surf)){ //was the surface already created?
  //draw the surface. saves processing
 }else{
  //make/rebuild the surface 
 }
}

surface_exists() does not do what im looking for and i dont think they have built something to do this. This would allow for the script to not have to require a previously initialized rtf_surf = surface_create(blah)

#9 Re: Script Submission » draw_text_rtf » 2013-05-24 21:03:16

Here is the one that includes the [c=c_NamedColor]. Please double check that I formatted all the things how you normally do and added all the description. I tried to get them all, but i might have overlooked something.

Expand/*
Original draw_text_rtf script by Miah_84.  Additions by csanyk.  This script may be used or modified freely, no attribution needed.

draw_text_rtf(x, y, string, regular_font, bold_font, italic_font, bold_italic_font)

Description: Draws a formatted string using BBCode-like syntax for internal formatting within the string.

Returns: void

Caution:  Only works for halign==left.  Not intended to draw centered or right-aligned text.


argument0 = the x position of the string
argument1 = the y position of the string
argument2 = the string.
argument3 = the regular font
argument4 = the bold font
argument5 = the italic font
argument6 = the bold italic font

The string may contain the following syntax:

[b]bold text[/b]
[i]italic text[/i]
[c=RRGGBB]colored text[/c]
[c=c_NamedColor]colored text using named color[/c] (IMPORTANT: c_NamedColor is UPPER/lower CASE SENSITIVE. see the MSDN list here: http://i.msdn.microsoft.com/dynimg/IC210551.png)
*/

/*
local var definitions

next_x, next_y      : the x and y position of the next substring of the formatted RTF draw
rtf_x, rtf_y        : the x and y position of the rtf string
str                 : the raw rtf string, with syntax formatting awaiting parsing;
f_r, f_b, f_i, f_bi : the index of regular, bold, italic, and bold italic fonts
mode                : a control flag that sets the mode that the parser is currently operating in, eg regular, bold, italic, bold&italic
original_color      : temp storage of the original drawing color, so that the function can revert back to it when needed
i, j                : for loop iterator, re-used several times throughout the function
sc3                 : a lowercase length-3 substring of str, used to parse tags of the formatting syntax
sc4                 : a lowercase length-4 substring of str, used to parse tags of the formatting syntax
sc5                 : a lowercase length-5 substring of str, used to parse tags of the formatting syntax
sc6                 : a lowercase length-6 substring of str, used to parse tags of the formatting syntax
sa, sb              : sub-strings of str, which when concatenated together, yield a string equal to str,
//                    omitting a formatting tag.
//                    Used in building the parsed rtf string
h_r, h_g, h_b       : the hex values of a RGB color, broken into the red, green, and blue values
d_r, d_g, d_b       : the dec values of a RGB color, broken into the red, green, and blue values
rgb                 : sub-strings of str to get values for r,g,b
r,g,b               : sub-strings of rgb for individual red, green, blue values
p1, p2              : the first and second digits of a 2-digit hex value for a given RGB color channel
w                   : "which" color does the hex belong to. A temporary variable used to build the color for the color markup syntax
col_map             : a ds_map of the rtf string containing info about the color formatting
rtf_map             : a ds_map of the rtf string containing info about the bold and italic formatting
names               : a ds_list of the names used for c_NamedColor
hv                  : a ds_list of the hex values associated with the names ds_list
cn                  : a substring of str that gets the c_NamedColor value
hex_str             : a string from ds_list hv that corresponds with c_NamedColor from the ds_list names

The ds_maps are used in the last for loop to actually build the markup sentence. Each character is assigned a color and font style using these. this helps to layout the placement for the next character and provide the correct color for each character.
*/
var next_x, next_y, rtf_x, rtf_y, str, f_r, f_b, f_i, f_bi, mode, original_color, c, i, j, sc3, sc4, sc5, sc6, sa, sb, h_r, h_b, h_g, d_r, d_g, d_g, p1, p2, w, rgb, r, g, b, names, hv, cn, hex_str;

next_x = 0;
next_y = 0;

rtf_x  = argument0;
rtf_y  = argument1;
str    = argument2;

f_r    = argument3;
f_b    = argument4;
f_i    = argument5;
f_bi   = argument6;

//modes
//1 = reg
//2 = bold
//3 = italic
//4 = bold & italic
mode     = 1;
original_color = draw_get_color();
c        = original_color;
rtf_map  = ds_map_create();
col_map  = ds_map_create();
names    = ds_list_create();
hv       = ds_list_create(); //hex values

ds_list_add(names,"c_AliceBlue");ds_list_add(names,"c_AntiqueWhite");ds_list_add(names,"c_Aqua");ds_list_add(names,"c_Aquamarine");ds_list_add(names,"c_Azure");ds_list_add(names,"c_Beige");ds_list_add(names,"c_Bisque");ds_list_add(names,"c_Black");ds_list_add(names,"c_BlanchedAlmond");ds_list_add(names,"c_Blue");ds_list_add(names,"c_BlueViolet");ds_list_add(names,"c_Brown");ds_list_add(names,"c_BurlyWood");ds_list_add(names,"c_CadetBlue");ds_list_add(names,"c_Chatreuse");ds_list_add(names,"c_Chocolate");ds_list_add(names,"c_Coral");ds_list_add(names,"c_CornFlowerBlue");ds_list_add(names,"c_Cornsilk");ds_list_add(names,"c_Crimson");ds_list_add(names,"c_Cyan");ds_list_add(names,"c_DarkBlue");ds_list_add(names,"c_DarkCyan");ds_list_add(names,"c_DarkGoldenrod");ds_list_add(names,"c_DarkGrey");ds_list_add(names,"c_DarkGreen");ds_list_add(names,"c_DarkKhaki");ds_list_add(names,"c_DarkMagenta");ds_list_add(names,"c_DarkOliveGreen");ds_list_add(names,"c_DarkOrange");ds_list_add(names,"c_DarkOrchid");ds_list_add(names,"c_DarkRed");ds_list_add(names,"c_DarkSalmon");ds_list_add(names,"c_DarkSeaGreen");ds_list_add(names,"c_DarkSlateBlue");ds_list_add(names,"c_DarkSlateGrey");ds_list_add(names,"c_DarkTurquoise");ds_list_add(names,"c_DarkViolet");ds_list_add(names,"c_DeepPink");ds_list_add(names,"c_DeepSkyBlue");ds_list_add(names,"c_DimGrey");ds_list_add(names,"c_DodgerBlue");ds_list_add(names,"c_Firebrick");ds_list_add(names,"c_FloralWhite");ds_list_add(names,"c_ForestGreen");ds_list_add(names,"c_Fuchsia");ds_list_add(names,"c_Gainsboro");ds_list_add(names,"c_GhostWhite");ds_list_add(names,"c_Gold");ds_list_add(names,"c_Goldenrod");ds_list_add(names,"c_Grey");ds_list_add(names,"c_Green");ds_list_add(names,"c_GreenYellow");ds_list_add(names,"c_Honeydew");ds_list_add(names,"c_HotPink");ds_list_add(names,"c_IndianRed");ds_list_add(names,"c_Indigo");ds_list_add(names,"c_Ivory");ds_list_add(names,"c_Khaki");ds_list_add(names,"c_Lavender");ds_list_add(names,"c_LavenderBlush");ds_list_add(names,"c_LawnGreen");ds_list_add(names,"c_LemonChiffon");ds_list_add(names,"c_LightBlue");ds_list_add(names,"c_LightCoral");ds_list_add(names,"c_LightCyan");ds_list_add(names,"c_LightGoldenrodYellow");ds_list_add(names,"c_LigntGray");ds_list_add(names,"c_LightGreen");ds_list_add(names,"c_LightPink");ds_list_add(names,"c_LightSalmon");ds_list_add(names,"c_LightSeaGreen");ds_list_add(names,"c_LightSkyBlue");ds_list_add(names,"c_LightSlateGrey");ds_list_add(names,"c_LightSteelBlue");ds_list_add(names,"c_LightYellow");ds_list_add(names,"c_Lime");ds_list_add(names,"c_LimeGreen");ds_list_add(names,"c_Linen");ds_list_add(names,"c_Magenta");ds_list_add(names,"c_Maroon");ds_list_add(names,"c_MediumAquamarine");ds_list_add(names,"c_MediumBlue");ds_list_add(names,"c_MediumOrchid");ds_list_add(names,"c_MediumPurple");ds_list_add(names,"c_MediumSeaGreen");ds_list_add(names,"c_MediumSlateBlue");ds_list_add(names,"c_MediumSpringGreen");ds_list_add(names,"c_MediumTurquoise");ds_list_add(names,"c_MediumVioletRed");ds_list_add(names,"c_MidnightBlue");ds_list_add(names,"c_MintCream");ds_list_add(names,"c_MistyRose");ds_list_add(names,"c_Moccasin");ds_list_add(names,"c_NavajoWhite");ds_list_add(names,"c_Navy");ds_list_add(names,"c_OldLace");ds_list_add(names,"c_Olive");ds_list_add(names,"c_OliveDrab");ds_list_add(names,"c_Orange");ds_list_add(names,"c_OrangeRed");ds_list_add(names,"c_Orchid");ds_list_add(names,"c_PaleGoldenrod");ds_list_add(names,"c_PaleGreen");ds_list_add(names,"c_PaleTurquoise");ds_list_add(names,"c_PaleVioletRed");ds_list_add(names,"c_PapayaWhip");ds_list_add(names,"c_PeachPuff");ds_list_add(names,"c_Peru");ds_list_add(names,"c_Pink");ds_list_add(names,"c_Plum");ds_list_add(names,"c_PowderBlue");ds_list_add(names,"c_Purple");ds_list_add(names,"c_Red");ds_list_add(names,"c_RosyBrown");ds_list_add(names,"c_RoyalBlue");ds_list_add(names,"c_SaddleBrown");ds_list_add(names,"c_Salmon");ds_list_add(names,"c_SandyBrown");ds_list_add(names,"c_SeaGreen");ds_list_add(names,"c_SeaShell");ds_list_add(names,"c_Sienna");ds_list_add(names,"c_Silver");ds_list_add(names,"c_SkyBlue");ds_list_add(names,"c_SlateBlue");ds_list_add(names,"c_SlateGrey");ds_list_add(names,"c_Snow");ds_list_add(names,"c_SpringGreen");ds_list_add(names,"c_SteelBlue");ds_list_add(names,"c_Tan");ds_list_add(names,"c_Teal");ds_list_add(names,"c_Thistle");ds_list_add(names,"c_Tomato");ds_list_add(names,"c_Turquoise");ds_list_add(names,"c_Violet");ds_list_add(names,"c_Wheat");ds_list_add(names,"c_White");ds_list_add(names,"c_WhiteSmoke");ds_list_add(names,"c_Yellow");ds_list_add(names,"c_YellowGreen")
ds_list_add(hv,"F0F8FF");ds_list_add(hv,"FAEBD7");ds_list_add(hv,"00FFFF");ds_list_add(hv,"7FFFD4");ds_list_add(hv,"F0FFFF");ds_list_add(hv,"F5F5DC");ds_list_add(hv,"FFE4C4");ds_list_add(hv,"000000");ds_list_add(hv,"FFEBCD");ds_list_add(hv,"0000FF");ds_list_add(hv,"8A3BE2");ds_list_add(hv,"A52A2A");ds_list_add(hv,"DEB887");ds_list_add(hv,"5F9EA0");ds_list_add(hv,"7FFF00");ds_list_add(hv,"D2691E");ds_list_add(hv,"FF7F50");ds_list_add(hv,"6495ED");ds_list_add(hv,"FFF8DC");ds_list_add(hv,"DC143C");ds_list_add(hv,"00FFFF");ds_list_add(hv,"00008B");ds_list_add(hv,"008B8B");ds_list_add(hv,"B8860B");ds_list_add(hv,"A9A9A9");ds_list_add(hv,"006400");ds_list_add(hv,"BDB76B");ds_list_add(hv,"8B008B");ds_list_add(hv,"556B2F");ds_list_add(hv,"FF8C00");ds_list_add(hv,"9932CC");ds_list_add(hv,"8B0000");ds_list_add(hv,"E9967A");ds_list_add(hv,"8FBC8F");ds_list_add(hv,"483D8B");ds_list_add(hv,"2F4F4F");ds_list_add(hv,"00CED1");ds_list_add(hv,"9400D3");ds_list_add(hv,"FF1493");ds_list_add(hv,"00BFFF");ds_list_add(hv,"696969");ds_list_add(hv,"1E90FF");ds_list_add(hv,"B22222");ds_list_add(hv,"FFFAF0");ds_list_add(hv,"228B22");ds_list_add(hv,"FF00FF");ds_list_add(hv,"DCDCDC");ds_list_add(hv,"F8F8FF");ds_list_add(hv,"FFD700");ds_list_add(hv,"DAA520");ds_list_add(hv,"808080");ds_list_add(hv,"008000");ds_list_add(hv,"ADFF2F");ds_list_add(hv,"F0FFF0");ds_list_add(hv,"FF69B4");ds_list_add(hv,"CD5C5C");ds_list_add(hv,"4B008C");ds_list_add(hv,"FFFFF0");ds_list_add(hv,"F0E68C");ds_list_add(hv,"E6E6FA");ds_list_add(hv,"FFF0F5");ds_list_add(hv,"7CFC00");ds_list_add(hv,"FFFACD");ds_list_add(hv,"ADD8E6");ds_list_add(hv,"F08080");ds_list_add(hv,"E0FFFF");ds_list_add(hv,"FAFAD2");ds_list_add(hv,"D3D3D3");ds_list_add(hv,"90EE90");ds_list_add(hv,"FFB6C1");ds_list_add(hv,"FFA07A");ds_list_add(hv,"20B2AA");ds_list_add(hv,"87CEFA");ds_list_add(hv,"778899");ds_list_add(hv,"B0C4DE");ds_list_add(hv,"FFFFE0");ds_list_add(hv,"00FF00");ds_list_add(hv,"32CD32");ds_list_add(hv,"FAF0E6");ds_list_add(hv,"FF00FF");ds_list_add(hv,"800000");ds_list_add(hv,"66CDAA");ds_list_add(hv,"0000CD");ds_list_add(hv,"BA55D3");ds_list_add(hv,"9370DB");ds_list_add(hv,"3CB371");ds_list_add(hv,"7B68EE");ds_list_add(hv,"00FA9A");ds_list_add(hv,"48D1CC");ds_list_add(hv,"C71585");ds_list_add(hv,"191970");ds_list_add(hv,"F5FFFA");ds_list_add(hv,"FFE4E1");ds_list_add(hv,"FFE4B5");ds_list_add(hv,"FFDEAD");ds_list_add(hv,"000080");ds_list_add(hv,"FDF5E6");ds_list_add(hv,"808000");ds_list_add(hv,"6B8E23");ds_list_add(hv,"FFA500");ds_list_add(hv,"FF4500");ds_list_add(hv,"DA70D6");ds_list_add(hv,"EEE8AA");ds_list_add(hv,"98FB98");ds_list_add(hv,"AFEEEE");ds_list_add(hv,"DB7093");ds_list_add(hv,"FFEFD5");ds_list_add(hv,"FFDAB9");ds_list_add(hv,"CD8D3F");ds_list_add(hv,"FFC0CB");ds_list_add(hv,"DDA0DD");ds_list_add(hv,"B0E0E6");ds_list_add(hv,"800080");ds_list_add(hv,"FF000");ds_list_add(hv,"BC8F8F");ds_list_add(hv,"4169E1");ds_list_add(hv,"8B4513");ds_list_add(hv,"FA8072");ds_list_add(hv,"F4A460");ds_list_add(hv,"2E8B57");ds_list_add(hv,"FFF5EE");ds_list_add(hv,"A0522D");ds_list_add(hv,"C0C0C0");ds_list_add(hv,"87CEEB");ds_list_add(hv,"6A5ACD");ds_list_add(hv,"708090");ds_list_add(hv,"FFFAFA");ds_list_add(hv,"00FF7F");ds_list_add(hv,"4682B4");ds_list_add(hv,"D2B48C");ds_list_add(hv,"008080");ds_list_add(hv,"D88FD8");ds_list_add(hv,"FF6347");ds_list_add(hv,"40E0D0");ds_list_add(hv,"EE82EE");ds_list_add(hv,"F5DEB3");ds_list_add(hv,"FFFFFF");ds_list_add(hv,"F5F5F5");ds_list_add(hv,"FFFF00");ds_list_add(hv,"9ACD32")


for(i = 0; i <= string_length(str); i++){
    sc3 = string_lower(string_copy(str, i, 3));
    sc4 = string_lower(string_copy(str, i, 4));
    sc5 = string_lower(string_copy(str, i, 5));
    sc6 = string_lower(string_copy(str, i ,6));
    if(sc3 == "[b]"){
        if(mode == 1){mode = 2;}
        if(mode == 3){mode = 4;}
        sa = string_copy(str, 0, i-1);
        sb = string_copy(str, i+3, string_length(str) - i - 2);
        str = sa + sb;
        i--;
    }
    if(sc4 = "[/b]"){
        if(mode == 2){mode = 1;}
        if(mode == 4){mode = 3;}
        sa = string_copy(str, 0, i-1);
        sb = string_copy(str, i+4, string_length(str) - i - 3);
        str = sa + sb;
        i--;
    }
    if(sc3 == "[i]"){
        if(mode == 1){mode = 3;}
        if(mode == 2){mode = 4;}
        sa = string_copy(str, 0, i-1);
        sb = string_copy(str, i+3, string_length(str) - i - 2);
        str = sa + sb;
        i--;
    }
    if(sc4 == "[/i]"){
        if(mode == 3){mode=1;}
        if(mode == 4){mode=2;}
        sa = string_copy(str, 0, i-1);
        sb = string_copy(str, i+4, string_length(str) - i - 3);
        str = sa + sb;
        i--;
    }
    ds_map_add(col_map, i - 1, c);
    if(sc3 == "[c=" && sc5 != "[c=c_"){
        h_r = string_copy(str, i + 3, 2);
        h_g = string_copy(str, i + 5, 2);
        h_b = string_copy(str, i + 7, 2);
        for(j = 0; j <= 2; j++){
            switch(j){
                case 0: w = h_r; break;
                case 1: w = h_g; break;
                case 2: w = h_b; break;
            }
            p1 = string_lower(string_char_at(w, 1));
            if(p1 == "a"){p1 = "10";}
            if(p1 == "b"){p1 = "11";}
            if(p1 == "c"){p1 = "12";}
            if(p1 == "d"){p1 = "13";}
            if(p1 == "e"){p1 = "14";}
            if(p1 == "f"){p1 = "15";}
            dec = real(p1) * 16;
            p2 = string_lower(string_char_at(w, 2));
            if(p2 == "a"){p2 = "10";}
            if(p2 == "b"){p2 = "11";}
            if(p2 == "c"){p2 = "12";}
            if(p2 == "d"){p2 = "13";}
            if(p2 == "e"){p2 = "14";}
            if(p2 == "f"){p2 = "15";}
            dec += real(p2);
            switch(j){
                case 0: d_r = dec; break;
                case 1: d_g = dec; break;
                case 2: d_b = dec; break;
            }
        }
        c = make_color_rgb(d_r, d_g, d_b);
        ds_map_replace(col_map, i, c);
        str = string_replace(str,"[c=" + h_r + h_g + h_b + "]", ""); //only replaces the first one, not all
        i--;
    }
    if(sc5 == "[c=c_"){
     cn = string_copy(str,i,32)//random length, long enough to cover all names
     
     cn = string_replace(cn,"[c=","")
     cn = string_copy(cn,0,string_pos("]",cn)-1)

     for(j=0;j<ds_list_size(names);j++){
      if(cn == ds_list_find_value(names,j)){
       hex_str = ds_list_find_value(hv,j)
      }
     }
        h_r = string_copy(hex_str, 1, 2);
        h_g = string_copy(hex_str, 3, 2);
        h_b = string_copy(hex_str, 5, 2);
        for(j = 0; j <= 2; j++){
            switch(j){
                case 0: w = h_r; break;
                case 1: w = h_g; break;
                case 2: w = h_b; break;
            }
            p1 = string_lower(string_char_at(w, 1));
            if(p1 == "a"){p1 = "10";}
            if(p1 == "b"){p1 = "11";}
            if(p1 == "c"){p1 = "12";}
            if(p1 == "d"){p1 = "13";}
            if(p1 == "e"){p1 = "14";}
            if(p1 == "f"){p1 = "15";}
            dec = real(p1) * 16;
            p2 = string_lower(string_char_at(w, 2));
            if(p2 == "a"){p2 = "10";}
            if(p2 == "b"){p2 = "11";}
            if(p2 == "c"){p2 = "12";}
            if(p2 == "d"){p2 = "13";}
            if(p2 == "e"){p2 = "14";}
            if(p2 == "f"){p2 = "15";}
            dec += real(p2);
            switch(j){
                case 0: d_r = dec; break;
                case 1: d_g = dec; break;
                case 2: d_b = dec; break;
            }
        }
        c = make_color_rgb(d_r, d_g, d_b);
        ds_map_replace(col_map, i, c);
        str = string_replace(str,"[c=" + cn + "]", ""); //only replaces the first one, not all
        i--;     
    }
    if(sc4 == "[/c]"){
        c = original_color;
        ds_map_replace(col_map, i, c);
        sa = string_copy(str, 0, i - 1);
        sb = string_copy(str, i + 4, string_length(str) - i - 3);
        str = sa + sb;
        i--;
    }
    if(sc5 == "[rgb="){
        rgb = string_copy(str,i,17)
        rgb = string_copy(rgb,0,string_pos("]",rgb)-1)
        rgb = string_replace(rgb,"[rgb=","")
        r = string_copy(rgb,0,string_pos(",",rgb)-1)
        rgb = string_replace(rgb,r+",","")
        g = string_copy(rgb,0,string_pos(",",rgb)-1)
        rgb = string_replace(rgb,g+",","")
        b = rgb
        c = make_color_rgb(real(r), real(g), real(b));
        ds_map_replace(col_map, i, c);
        str = string_replace(str,"[rgb=" + r + "," + g + "," + b + "]", ""); //only replaces the first one, not all
        i--;
    }
    if(sc6 == "[/rgb]"){
        c = original_color;
        ds_map_replace(col_map, i, c);
        sa = string_copy(str, 0, i - 1);
        sb = string_copy(str, i + 6, string_length(str) - i - 5);
        str = sa + sb;
        i--;
    }
    ds_map_add(rtf_map, i, mode);
}

for(i = 1; i <= string_length(str); i++){
    if(string_copy(str, i, 1) == "#"){next_x = 0; next_y += string_height("#");}
    draw_set_color(ds_map_find_value(col_map, i));
    switch(ds_map_find_value(rtf_map, i)){
        case 1:
        draw_set_font(f_r);
        draw_text(rtf_x + next_x, rtf_y + next_y, string_copy(str, i, 1));
        next_x += string_width(string_copy(str, i, 1));
        break;
        case 2:
        draw_set_font(f_b);
        draw_text(rtf_x + next_x, rtf_y + next_y, string_copy(str, i, 1));
        next_x += string_width(string_copy(str, i, 1));
        break;
        case 3:
        draw_set_font(f_i);
        draw_text(rtf_x + next_x, rtf_y + next_y, string_copy(str, i, 1));
        next_x += string_width(string_copy(str, i, 1));
        break;
        case 4:
        draw_set_font(f_bi);
        draw_text(rtf_x + next_x, rtf_y + next_y, string_copy(str, i, 1));
        next_x += string_width(string_copy(str, i, 1));
        break;
    }//end switch
}

//reset color
draw_set_color(original_color);
//free up the ds_maps and ds_lists
ds_map_destroy(rtf_map);
ds_map_destroy(col_map);
ds_list_destroy(names);
ds_list_destroy(hv);

#10 Re: Script Submission » draw_text_rtf » 2013-05-24 19:40:38

IMPORTANT >>>>>> I MADE A MISTAKE IN THE HEXTODEC TRANSLATION. THE P1 SHOULD BE MULTIPLIED BY 16, AND P2 SHOULD NOT. PLEASE FIX THIS IN YOUR PREVIOUS POSTS

MSDN wasnt matching because i'm a goof. I was grabbing the hex wrong in my project. FFAABB for example was showing R: FF G: FA B: AA ...i did a single advance instead of a double...the MSDN and GM do match. I will implement this probably tonight. namespace wont be an issue since GM uses all lowercase such as c_red and this code will be case sensitive so c_Red (we will need to explain that this is case sensitive in the example/description area). here is the project that i made to test this

I DIDN'T DESTROY THE LISTS OR DECLARE ANYTHING BECAUSE THIS WAS A TEST PROJECT

Object1 create:

Expandnames = ds_list_create() // c_blah name
hv = ds_list_create() //hex value for c_blah
ds_list_add(names,"c_ALiceBlue");ds_list_add(names,"c_AntiqueWhite");ds_list_add(names,"c_Aqua");ds_list_add(names,"c_Aquamarine");ds_list_add(names,"c_Azure");ds_list_add(names,"c_Beige");ds_list_add(names,"c_Bisque");ds_list_add(names,"c_Black");ds_list_add(names,"c_BlanchedAlmond");ds_list_add(names,"c_Blue");ds_list_add(names,"c_BlueViolet");ds_list_add(names,"c_Brown");ds_list_add(names,"c_BurlyWood");ds_list_add(names,"c_CadetBlue");ds_list_add(names,"c_Chatreuse");ds_list_add(names,"c_Chocolate");ds_list_add(names,"c_Coral");ds_list_add(names,"c_CornFlowerBlue");ds_list_add(names,"c_Cornsilk");ds_list_add(names,"c_Crimson");ds_list_add(names,"c_Cyan");ds_list_add(names,"c_DarkBlue");ds_list_add(names,"c_DarkCyan");ds_list_add(names,"c_DarkGoldenrod");ds_list_add(names,"c_DarkGrey");ds_list_add(names,"c_DarkGreen");ds_list_add(names,"c_DarkKhaki");ds_list_add(names,"c_DarkMagenta");ds_list_add(names,"c_DarkOliveGreen");ds_list_add(names,"c_DarkOrange");ds_list_add(names,"c_DarkOrchid");ds_list_add(names,"c_DarkRed");ds_list_add(names,"c_DarkSalmon");ds_list_add(names,"c_DarkSeaGreen");ds_list_add(names,"c_DarkSlateBlue");ds_list_add(names,"c_DarkSlateGrey");ds_list_add(names,"c_DarkTurquoise");ds_list_add(names,"c_DarkViolet");ds_list_add(names,"c_DeepPink");ds_list_add(names,"c_DeepSkyBlue");ds_list_add(names,"c_DimGrey");ds_list_add(names,"c_DodgerBlue");ds_list_add(names,"c_Firebrick");ds_list_add(names,"c_FloralWhite");ds_list_add(names,"c_ForestGreen");ds_list_add(names,"c_Fuchsia");ds_list_add(names,"c_Gainsboro");ds_list_add(names,"c_GhostWhite");ds_list_add(names,"c_Gold");ds_list_add(names,"c_Goldenrod");ds_list_add(names,"c_Grey");ds_list_add(names,"c_Green");ds_list_add(names,"c_GreenYellow");ds_list_add(names,"c_Honeydew");ds_list_add(names,"c_HotPink");ds_list_add(names,"c_IndianRed");ds_list_add(names,"c_Indigo");ds_list_add(names,"c_Ivory");ds_list_add(names,"c_Khaki");ds_list_add(names,"c_Lavender");ds_list_add(names,"c_LavenderBlush");ds_list_add(names,"c_LawnGreen");ds_list_add(names,"c_LemonChiffon");ds_list_add(names,"c_LightBlue");ds_list_add(names,"c_LightCoral");ds_list_add(names,"c_LightCyan");ds_list_add(names,"c_LightGoldenrodYellow");ds_list_add(names,"c_LigntGray");ds_list_add(names,"c_LightGreen");ds_list_add(names,"c_LightPink");ds_list_add(names,"c_LightSalmon");ds_list_add(names,"c_LightSeaGreen");ds_list_add(names,"c_LightSkyBlue");ds_list_add(names,"c_LightSlateGrey");ds_list_add(names,"c_LightSteelBlue");ds_list_add(names,"c_LightYellow");ds_list_add(names,"c_Lime");ds_list_add(names,"c_LimeGreen");ds_list_add(names,"c_Linen");ds_list_add(names,"c_Magenta");ds_list_add(names,"c_Maroon");ds_list_add(names,"c_MediumAquamarine");ds_list_add(names,"c_MediumBlue");ds_list_add(names,"c_MediumOrchid");ds_list_add(names,"c_MediumPurple");ds_list_add(names,"c_MediumSeaGreen");ds_list_add(names,"c_MediumSlateBlue");ds_list_add(names,"c_MediumSpringGreen");ds_list_add(names,"c_MediumTurquoise");ds_list_add(names,"c_MediumVioletRed");ds_list_add(names,"c_MidnightBlue");ds_list_add(names,"c_MintCream");ds_list_add(names,"c_MistyRose");ds_list_add(names,"c_Moccasin");ds_list_add(names,"c_NavajoWhite");ds_list_add(names,"c_Navy");ds_list_add(names,"c_OldLace");ds_list_add(names,"c_Olive");ds_list_add(names,"c_OliveDrab");ds_list_add(names,"c_Orange");ds_list_add(names,"c_OrangeRed");ds_list_add(names,"c_Orchid");ds_list_add(names,"c_PaleGoldenrod");ds_list_add(names,"c_PaleGreen");ds_list_add(names,"c_PaleTurquoise");ds_list_add(names,"c_PaleVioletRed");ds_list_add(names,"c_PapayaWhip");ds_list_add(names,"c_PeachPuff");ds_list_add(names,"c_Peru");ds_list_add(names,"c_Pink");ds_list_add(names,"c_Plum");ds_list_add(names,"c_PowderBlue");ds_list_add(names,"c_Purple");ds_list_add(names,"c_Red");ds_list_add(names,"c_RosyBrown");ds_list_add(names,"c_RoyalBlue");ds_list_add(names,"c_SaddleBrown");ds_list_add(names,"c_Salmon");ds_list_add(names,"c_SandyBrown");ds_list_add(names,"c_SeaGreen");ds_list_add(names,"c_SeaShell");ds_list_add(names,"c_Sienna");ds_list_add(names,"c_Silver");ds_list_add(names,"c_SkyBlue");ds_list_add(names,"c_SlateBlue");ds_list_add(names,"c_SlateGrey");ds_list_add(names,"c_Snow");ds_list_add(names,"c_SpringGreen");ds_list_add(names,"c_SteelBlue");ds_list_add(names,"c_Tan");ds_list_add(names,"c_Teal");ds_list_add(names,"c_Thistle");ds_list_add(names,"c_Tomato");ds_list_add(names,"c_Turquoise");ds_list_add(names,"c_Violet");ds_list_add(names,"c_Wheat");ds_list_add(names,"c_White");ds_list_add(names,"c_WhiteSmoke");ds_list_add(names,"c_Yellow");ds_list_add(names,"c_YellowGreen")
ds_list_add(hv,"F0F8FF");ds_list_add(hv,"FAEBD7");ds_list_add(hv,"00FFFF");ds_list_add(hv,"7FFFD4");ds_list_add(hv,"F0FFFF");ds_list_add(hv,"F5F5DC");ds_list_add(hv,"FFE4C4");ds_list_add(hv,"000000");ds_list_add(hv,"FFEBCD");ds_list_add(hv,"0000FF");ds_list_add(hv,"8A3BE2");ds_list_add(hv,"A52A2A");ds_list_add(hv,"DEB887");ds_list_add(hv,"5F9EA0");ds_list_add(hv,"7FFF00");ds_list_add(hv,"D2691E");ds_list_add(hv,"FF7F50");ds_list_add(hv,"6495ED");ds_list_add(hv,"FFF8DC");ds_list_add(hv,"DC143C");ds_list_add(hv,"00FFFF");ds_list_add(hv,"00008B");ds_list_add(hv,"008B8B");ds_list_add(hv,"B8860B");ds_list_add(hv,"A9A9A9");ds_list_add(hv,"006400");ds_list_add(hv,"BDB76B");ds_list_add(hv,"8B008B");ds_list_add(hv,"556B2F");ds_list_add(hv,"FF8C00");ds_list_add(hv,"9932CC");ds_list_add(hv,"8B0000");ds_list_add(hv,"E9967A");ds_list_add(hv,"8FBC8F");ds_list_add(hv,"483D8B");ds_list_add(hv,"2F4F4F");ds_list_add(hv,"00CED1");ds_list_add(hv,"9400D3");ds_list_add(hv,"FF1493");ds_list_add(hv,"00BFFF");ds_list_add(hv,"696969");ds_list_add(hv,"1E90FF");ds_list_add(hv,"B22222");ds_list_add(hv,"FFFAF0");ds_list_add(hv,"228B22");ds_list_add(hv,"FF00FF");ds_list_add(hv,"DCDCDC");ds_list_add(hv,"F8F8FF");ds_list_add(hv,"FFD700");ds_list_add(hv,"DAA520");ds_list_add(hv,"808080");ds_list_add(hv,"008000");ds_list_add(hv,"ADFF2F");ds_list_add(hv,"F0FFF0");ds_list_add(hv,"FF69B4");ds_list_add(hv,"CD5C5C");ds_list_add(hv,"4B008C");ds_list_add(hv,"FFFFF0");ds_list_add(hv,"F0E68C");ds_list_add(hv,"E6E6FA");ds_list_add(hv,"FFF0F5");ds_list_add(hv,"7CFC00");ds_list_add(hv,"FFFACD");ds_list_add(hv,"ADD8E6");ds_list_add(hv,"F08080");ds_list_add(hv,"E0FFFF");ds_list_add(hv,"FAFAD2");ds_list_add(hv,"D3D3D3");ds_list_add(hv,"90EE90");ds_list_add(hv,"FFB6C1");ds_list_add(hv,"FFA07A");ds_list_add(hv,"20B2AA");ds_list_add(hv,"87CEFA");ds_list_add(hv,"778899");ds_list_add(hv,"B0C4DE");ds_list_add(hv,"FFFFE0");ds_list_add(hv,"00FF00");ds_list_add(hv,"32CD32");ds_list_add(hv,"FAF0E6");ds_list_add(hv,"FF00FF");ds_list_add(hv,"800000");ds_list_add(hv,"66CDAA");ds_list_add(hv,"0000CD");ds_list_add(hv,"BA55D3");ds_list_add(hv,"9370DB");ds_list_add(hv,"3CB371");ds_list_add(hv,"7B68EE");ds_list_add(hv,"00FA9A");ds_list_add(hv,"48D1CC");ds_list_add(hv,"C71585");ds_list_add(hv,"191970");ds_list_add(hv,"F5FFFA");ds_list_add(hv,"FFE4E1");ds_list_add(hv,"FFE4B5");ds_list_add(hv,"FFDEAD");ds_list_add(hv,"000080");ds_list_add(hv,"FDF5E6");ds_list_add(hv,"808000");ds_list_add(hv,"6B8E23");ds_list_add(hv,"FFA500");ds_list_add(hv,"FF4500");ds_list_add(hv,"DA70D6");ds_list_add(hv,"EEE8AA");ds_list_add(hv,"98FB98");ds_list_add(hv,"AFEEEE");ds_list_add(hv,"DB7093");ds_list_add(hv,"FFEFD5");ds_list_add(hv,"FFDAB9");ds_list_add(hv,"CD8D3F");ds_list_add(hv,"FFC0CB");ds_list_add(hv,"DDA0DD");ds_list_add(hv,"B0E0E6");ds_list_add(hv,"800080");ds_list_add(hv,"FF000");ds_list_add(hv,"BC8F8F");ds_list_add(hv,"4169E1");ds_list_add(hv,"8B4513");ds_list_add(hv,"FA8072");ds_list_add(hv,"F4A460");ds_list_add(hv,"2E8B57");ds_list_add(hv,"FFF5EE");ds_list_add(hv,"A0522D");ds_list_add(hv,"C0C0C0");ds_list_add(hv,"87CEEB");ds_list_add(hv,"6A5ACD");ds_list_add(hv,"708090");ds_list_add(hv,"FFFAFA");ds_list_add(hv,"00FF7F");ds_list_add(hv,"4682B4");ds_list_add(hv,"D2B48C");ds_list_add(hv,"008080");ds_list_add(hv,"D88FD8");ds_list_add(hv,"FF6347");ds_list_add(hv,"40E0D0");ds_list_add(hv,"EE82EE");ds_list_add(hv,"F5DEB3");ds_list_add(hv,"FFFFFF");ds_list_add(hv,"F5F5F5");ds_list_add(hv,"FFFF00");ds_list_add(hv,"9ACD32")
item = 0

Object1 draw

Expandh_r = string_copy(ds_list_find_value(hv,item), 1, 2);
        h_g = string_copy(ds_list_find_value(hv,item), 3, 2);
        h_b = string_copy(ds_list_find_value(hv,item), 5, 2);
        for(j = 0; j <= 2; j++){
            switch(j){
                case 0: w = h_r; break;
                case 1: w = h_g; break;
                case 2: w = h_b; break;
            }
            p1 = string_lower(string_char_at(w, 1));
            if(p1 == "a"){p1 = "10";}
            if(p1 == "b"){p1 = "11";}
            if(p1 == "c"){p1 = "12";}
            if(p1 == "d"){p1 = "13";}
            if(p1 == "e"){p1 = "14";}
            if(p1 == "f"){p1 = "15";}
            dec = real(p1)*16; 
            p2 = string_lower(string_char_at(w, 2));
            if(p2 == "a"){p2 = "10";}
            if(p2 == "b"){p2 = "11";}
            if(p2 == "c"){p2 = "12";}
            if(p2 == "d"){p2 = "13";}
            if(p2 == "e"){p2 = "14";}
            if(p2 == "f"){p2 = "15";}
            dec += real(p2);
            switch(j){
                case 0: d_r = dec; break;
                case 1: d_g = dec; break;
                case 2: d_b = dec; break;
            }
        }
        c = make_color_rgb(d_r, d_g, d_b);


draw_set_color(c)
draw_rectangle(100,100,300,300,false)

draw_set_color(c_black)
draw_text(10,16,"item: " + string(item))
draw_text(10,32,"name: " + string(ds_list_find_value(names,item)))
draw_text(10,48,"hex: " + string(ds_list_find_value(hv,item)))
draw_text(10,64,"RGB: " + string(d_r) + "," + string(d_g) + "," + string(d_b))

draw_rectangle(100,100,300,300,true)

Object1 Left_Press

Expanditem -= 1
if(item=-1){item=ds_list_size(names)-1}

Object1 Right Press

Expanditem += 1
if(item>=ds_list_size(names)){item=0}

#11 Re: Script Submission » draw_text_rtf » 2013-05-24 02:18:56

I have implemented [RGB=blah,blah,blah] and I started working on the [c=c_ColorName] section and I was getting my color codes from http://i.msdn.microsoft.com/dynimg/IC210551.png for this, but several are not coming up correctly in GM. look at DodgeBlue for example (1E90FF) it is nothing like the MSDN color.  Some are perfect, but some are way off. any suggestions? Im thinking about visually comparing the MSDN and omitting the ones that don't match correctly. Below is the code that I have put together so far, which includes the [RGB]

<code omitted to save scrolling since csanyk post it again below>

SIDE NOTE: looks like they have finally brought back array sizes using array_length_1d(), array_length_2d() in version 1.1.1008 beta. soon i will be able to use arrays properly again, that could end up being quite useful here at some point.

#12 Re: Script Submission » draw_text_rtf » 2013-05-24 00:07:36

That's not a bad idea, but I'm going to try a different approach to this. let me see what i can manage. also, using hextodec() could be done, but i was originally trying to make this not dependent on any other scripts for two reason..... first, its easier to track problems/follow flow in 1 script. second, i dont know who made the hextodec or if they allow it for commercial use/ royalty free use, so this prevents any questionable issues for users that want to make this part of a commercial game. the last thing i want is for a script i make to depend on someone else giving their consent if someone can use something or not. I feel that if i take the time to make it all in one then there is no worry or question about this for anyone.

#13 Re: Script Submission » draw_text_rtf » 2013-05-23 17:10:41

Line and lines can be removed,  I overlooked them.

Here are the :? You have. You basically got them already.

w is used as "which" color does the hex belong to. A temp variable.

col map and rtf map are used in the last for loop to actually build the markup sentence. Each character is assigned a color and font style using these. this helps to layout the placement for the next character and provide the correct color for each character.

#14 Re: Script Submission » draw_text_rtf » 2013-05-23 13:34:03

Csanyk, A set of arrays/ds_list will be fine for color names and still allow for [c= instead of [c_name= . I will read more through your post when I have a little more time

Board footer

Powered by FluxBB