14.09.2015, 17:33
(
Last edited by IllidanS4; 18/12/2016 at 11:22 AM.
)
i_colors
Download
This is a little include I made to make working with colors easier. It includes basic functions to operate with colors on the component level, as well as color blending and conversions. It also introduces a new way to use colors in SA-MP messages, allowing nested colors.Download
Functions
Color components
pawn Code:
stock CreateColorComponentsArray(color)
pawn Code:
stock GetColorComponentsArray(color, components[4 char])
pawn Code:
stock CreateColor(components[4 char])
pawn Code:
stock GetColorComponents(color, &r=0, &g=0, &b=0, &a=0)
pawn Code:
stock CreateColorRGBA(r, g, b, a=0xFF)
Hex tools
pawn Code:
stock ishex(c)
pawn Code:
stock hexval(string[])
pawn Code:
stock hexchar(i)
Color strings
pawn Code:
stock InsertColorString(string[], col)
pawn Code:
stock GetColorCode(col)
pawn Code:
stock ReformatColorTags(color, string[], size = sizeof(string))
pawn Code:
stock RemoveRedundantColors(color, string[])
pawn Code:
stock ReplaceColorParentheses(string[], left='[', right=']')
pawn Code:
stock IsColorCode(string[])
Color operations
pawn Code:
stock RGBAtoARGB(col)
pawn Code:
stock ARGBtoRGBA(col)
pawn Code:
stock CompareColorsRGB(col1, col2)
pawn Code:
stock BlendColors(col1, col2, Float:t)
Nested color codes
ReformatColorTags parses a string looking for all color codes in the format "{RRGGBB{", remembering the current color of the string. After it finds the color code, it looks for a "}}" and replaces it with the original color code.
Example:
pawn Code:
new str[144] = "This is a {FFFF00{highlighted}} value.";
ReformatColorTags(0xFFFFFF00, str);
Multiple color levels are also allowed, like "White {FF0000{ Red {00FF00{ Green {0000FF{ Blue }} Green }} Red }} White".