Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*----------------------------------------------------------------------------*-
- ==========================
- y_colours - X11 colours!
- ==========================
- Description:
- This holds the colour information that used to be part of the text system
- but which is far more useful than just for text. This now supports the full
- set of X11 colours, both by name and by definition. You can also define
- your own if you so choose (up to 32 - should be enough given that this
- includes the X11 colours).
- Legal:
- Version: MPL 1.1
- The contents of this file are subject to the Mozilla Public License Version
- 1.1 (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
- http://www.mozilla.org/MPL/
- Software distributed under the License is distributed on an "AS IS" basis,
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- for the specific language governing rights and limitations under the
- License.
- The Original Code is the SA:MP script information include.
- The Initial Developer of the Original Code is Alex "Y_Less" Cole.
- Portions created by the Initial Developer are Copyright (C) 2008
- the Initial Developer. All Rights Reserved.
- Contributors:
- ZeeX, koolk
- Thanks:
- Peter, Cam - Support.
- ZeeX - Very productive conversations.
- g_aSlice - More conversations.
- RyDeR` - Idea for hash colours.
- [FeK]DraKiNs - Idea for end colour.
- koolk - IsPlayerinAreaEx code.
- TheAlpha - Danish translation.
- breadfish - German translation.
- Fireburn - Dutch translation.
- yom - French translation.
- 50p - Polish translation.
- Zamaroht - Spanish translation.
- Dracoblue, sintax, mabako, Xtreme, other coders - Producing other modes
- for me to strive to better.
- Pixels^ - Running XScripters where the idea was born.
- Matite - Pestering me to release it and using it.
- Very special thanks to:
- Thiadmer - PAWN.
- Kye/Kalcor - SA:MP.
- SA:MP Team past, present and future - SA:MP.
- Version:
- 1.0
- Changelog:
- 29/11/10:
- Added the ability to use "X11" prefixes in strings.
- Added colourspace resolution for converting {FF0000} to ~r~.
- 25/11/10:
- First version.
- -*----------------------------------------------------------------------------*/
- #include <YSI\internal\y_version>
- #include <YSI\y_stringhash>
- #include <YSI\y_debug>
- #if !defined MAX_TEXT_COLOURS
- #define MAX_TEXT_COLOURS (32)
- #endif
- #if !defined NO_X11_COLOURS && !defined NO_X11_COLORS
- #define _YSI_USE_X11 true
- #else
- #define _YSI_USE_X11 false
- #endif
- #define MK_RGB(%0,%1,%2) ((%0)<<24|(%1)<<16|(%2)<<8)
- #define SAMP_GAME_TEXT MK_RGB(144, 98, 16)
- #define SAMP_GAME_TEXT_ MK_RGB(144, 98, 16)
- #define SAMP_GAME_TEXT_H MK_RGB(216, 147, 24)
- #define SAMP_GAME_TEXT_HH MK_RGB(255, 255, 54)
- #define SAMP_GAME_TEXT_R MK_RGB(180, 25, 29)
- #define SAMP_GAME_TEXT_RH MK_RGB(255, 37, 43)
- #define SAMP_GAME_TEXT_RHH MK_RGB(255, 55, 64)
- #define SAMP_GAME_TEXT_RHHH MK_RGB(255, 82, 96)
- #define SAMP_GAME_TEXT_RHHHH MK_RGB(255, 123, 144)
- #define SAMP_GAME_TEXT_RHHHHH MK_RGB(255, 184, 216)
- #define SAMP_GAME_TEXT_G MK_RGB( 54, 104, 44)
- #define SAMP_GAME_TEXT_GH MK_RGB( 81, 156, 66)
- #define SAMP_GAME_TEXT_GHH MK_RGB(121, 234, 99)
- #define SAMP_GAME_TEXT_GHHH MK_RGB(181, 255, 148)
- #define SAMP_GAME_TEXT_GHHHH MK_RGB(255, 255, 222)
- #define SAMP_GAME_TEXT_B MK_RGB( 50, 60, 127)
- #define SAMP_GAME_TEXT_BH MK_RGB( 75, 90, 190)
- #define SAMP_GAME_TEXT_BHH MK_RGB(112, 135, 255)
- #define SAMP_GAME_TEXT_BHHH MK_RGB(168, 202, 255)
- #define SAMP_GAME_TEXT_Y MK_RGB(226, 192, 99)
- #define SAMP_GAME_TEXT_YH MK_RGB(255, 255, 148)
- #define SAMP_GAME_TEXT_YHH MK_RGB(255, 255, 222) // Also in green
- #define SAMP_GAME_TEXT_P MK_RGB(168, 110, 252)
- #define SAMP_GAME_TEXT_PH MK_RGB(252, 165, 255)
- #define SAMP_GAME_TEXT_PHH MK_RGB(255, 247, 255)
- #define SAMP_GAME_TEXT_W MK_RGB(255, 255, 255)
- #define SAMP_GAME_TEXT_L MK_RGB( 0, 0, 0)
- #define COLOUR_NAME_HASH(%0) YHash((%0),false,hash_bernstein)
- #define COLOR_NAME_HASH COLOUR_NAME_HASH
- //#include <YSI\internal\y_colourparse>
- #if _YSI_USE_X11
- #include <YSI\internal\y_x11def>
- #endif
- enum e_COLOUR_TYPE
- {
- colour_samp,
- colour_game_text,
- colour_text_draw,
- colour_text_draw_ex,
- colour_scm,
- colour_scm_pre_3c
- }
- #define e_COLOR_TYPE e_COLOUR_TYPE
- #define color_samp colour_samp
- #define color_game_text colour_game_text
- #define color_text_draw colour_text_draw
- #define color_text_draw_accurate colour_text_draw_accurate
- #define colour_scm colour_scm
- #define colour_scm_pre_3c colour_scm_pre_3c
- #if _YSI_USE_X11
- static stock Colours_DoHashParse(const str[], &idx)
- {
- #include <YSI\internal\y_x11parse>
- #pragma tabsize 4
- return -1;
- }
- #endif
- // This function takes a string input and returns the colour in any format
- // following it.
- stock Colours_Resolve(const input[], &idx, &bool:fade, &steps, pt = false)
- {
- new
- ch = input[idx],
- start = idx,
- delim;
- steps = 1;
- switch (ch)
- {
- case '#':
- {
- // Hash colours introduced by RyDeR`.
- if (fade)
- {
- fade = false;
- }
- ++start;
- if (input[start] == '\0')
- {
- ++idx;
- return -1;
- }
- // Try and find the named colour.
- #if _YSI_USE_X11
- if (!strcmp(input[start], "X11", true, 3))
- {
- start += 3;
- if (input[start] == ' ' || input[start] == '_')
- {
- ++start;
- }
- }
- delim = Colours_DoHashParse(input[start], start);
- if (delim != -1)
- {
- idx = start;
- return delim;
- }
- //return Colours_DoHashParse(input, idx);
- #endif
- ++idx;
- // Need to accept 3 and 6 character hex codes.
- delim = 0;
- //idx = start;
- while ((ch = input[start++] | 0x20))
- {
- if ('0' <= ch <= '9')
- {
- delim = (delim << 4) | (ch - '0');
- }
- else if ('a' <= ch <= 'f')
- {
- delim = (delim << 4) | (ch - 'a' + 10);
- }
- else
- {
- if (start - idx == 6)
- {
- idx += 6;
- return delim;
- }
- else if (start - idx >= 3)
- {
- // Convert to 3 digit hex.
- // First strip off excess.
- delim >>>= 4 * (start - idx - 4);
- idx += 3;
- // Then dupilcate each value.
- return ((delim & 0x0F00) * 0x1100) | ((delim & 0x00F0) * 0x0110) | ((delim & 0x000F) * 0x0011);
- }
- --idx;
- return -1;
- }
- if (start - idx == 6)
- {
- idx += 6;
- return delim;
- }
- }
- // Should never be reached.
- return -1;
- }
- case '~': // Game Text style information
- {
- if (fade)
- {
- // These never start and always close fades.
- fade = false;
- }
- return Colours_GTToSAMP(input, idx);
- }
- case '(': // Bracket
- {
- if (pt)
- {
- delim = ')';
- }
- else
- {
- return -1;
- }
- }
- case '{': // Brace
- {
- delim = '}';
- }
- default:
- {
- return -1;
- }
- }
- switch ((ch = input[++start]))
- {
- case '>':
- {
- // Start of a fade.
- if (!fade)
- {
- fade = true;
- }
- ch = input[++start];
- if (ch == '[')
- {
- steps = 0;
- while ((ch = input[++start]))
- {
- // Parse the number of steps to use.
- if (ch == ']')
- {
- ch = input[++start];
- break;
- }
- else if ('0' <= ch <= '9')
- {
- steps = (steps * 10) + (ch - '0');
- }
- else
- {
- return -1;
- }
- }
- }
- }
- case '<':
- {
- // End of a fade.
- if (fade)
- {
- fade = false;
- }
- ch = input[++start];
- }
- }
- // Close colours introduced by [FeK]DraKiNs.
- if (ch == '/')
- {
- // Close colour.
- while ((ch = input[++start]))
- {
- if (ch == delim)
- {
- break;
- }
- }
- // End of the current colour.
- idx = start + 1;
- return 0xF0000000;
- }
- // Finally we can get the real colour.
- new
- tot = 0,
- bool:num = true,
- cur = start;
- //idx = start;
- while (ch)
- {
- if (ch == delim)
- {
- break;
- }
- new
- ch2 = ch | 0x20;
- if (num)
- {
- // Check if it's still a valid HEX digit and increment.
- if ('0' <= ch <= '9')
- {
- tot = (tot << 4) | (ch - '0');
- }
- else if ('a' <= ch2 <= 'f')
- {
- tot = (tot << 4) | (ch2 - 'a' + 10);
- }
- else if (('g' <= ch2 <= 'z') || ch == '_' || ch == ' ')
- {
- // No, but still a valid identifier.
- num = false;
- }
- else
- {
- return -1;
- }
- }
- else if (!(('0' <= ch <= '9') || ('a' <= ch2 <= 'z') || ch == '_' || ch == ' '))
- {
- // Not a valid identifier character.
- idx = start;
- return -1;
- }
- ch = input[++cur];
- }
- //while ((ch = input[++idx]));
- if (ch == '\0')
- {
- // Not a valid end.
- return -1;
- }
- ++cur;
- idx = cur;
- if (cur == start + 1)
- {
- return -1;
- }
- if (num)
- {
- // The input was a number.
- return tot & 0x00FFFFFF;
- }
- // The input was a string.
- //if (input[start] | 0x20 == 'x' && input[start + 1] == '1' && input[start + 2] == '1')
- #if _YSI_USE_X11
- if (!strcmp(input[start], "X11", true, 3))
- {
- if (input[start + 3] == ' ' || input[start + 3] == '_')
- {
- delim = GetColourHash(YHash(input[start + 4], false, hash_bernstein, cur - start - 5), 1);
- }
- else
- {
- delim = GetColourHash(YHash(input[start + 3], false, hash_bernstein, cur - start - 4), 1);
- }
- }
- else
- #endif
- {
- delim = GetColourHash(YHash(input[start], false, hash_bernstein, cur - start - 1), 1);
- }
- #pragma tabsize 4
- if (delim)
- {
- return delim >>> 8;
- }
- return -1;
- /*else
- {
- return GetColourHash(YHash(input[start], false, hash_bernstein, cur - start - 1), 0) >>> 8;
- }*/
- }
- stock Colours_AddSAMPChange(output[], &idx, rem, cur, nu)
- {
- if (cur == nu)
- {
- return 2;
- }
- #if defined Y_COLOUR_APPROXIMATE || defined Y_COLOR_APPROXIMATE
- if (-0x5 <= ((nu & 0x0FF) - (cur & 0xFF)) <= 0x5)
- {
- if (-0x500 <= ((nu & 0xFF00) - (cur & 0xFF00)) <= 0x500)
- {
- if (-0x50000 <= ((nu & 0xFF0000) - (cur & 0xFF0000)) <= 0x50000)
- {
- // Haven't changed the colour.
- return 1;
- }
- }
- }
- #endif
- // Need to add an update.
- if (rem <= 8)
- {
- // Not enough space.
- return -1;
- }
- format(output[idx], rem, "{%06x}", nu);
- idx += 8;
- // Added to output.
- return 0;
- }
- stock bool:Colours_AddGTChange(output[], &idx, rem, cur, nu)
- {
- // Add the GT text to change from the current colour to the new colour.
- new
- t = nu & 0xFF,
- o = cur & 0xFF;
- // Get the base colour.
- nu >>>= 8;
- cur >>>= 8;
- if (t == 'x' && o == 'y')
- {
- // Original. Have to use yellow instead (though red is closer to the
- // plain original colour). I tried to find a way to replicate the basic
- // orange but there is no way...
- t == 'y';
- nu = 0;
- }
- if (t == o)
- {
- // Stayed the same or will now stay the same.
- if (nu == cur)
- {
- return true;
- }
- if (nu > cur)
- {
- // Same colour, just lighter.
- do
- {
- if (rem <= 3)
- {
- return false;
- }
- // Add a fader.
- //output[idx] = '~';
- //output[idx + 1] = 'h';
- //output[idx + 2] = '~';
- strcat(output, "~h~", rem);
- rem -= 3;
- idx += 3;
- --nu;
- }
- while (nu > cur);
- return true;
- }
- // Same colour but darker - need to reset.
- }
- if (rem <= 3)
- {
- return false;
- }
- // Add the base colour.
- output[idx] = '~';
- output[idx + 1] = t;
- output[idx + 2] = '~';
- rem -= 3;
- idx += 3;
- while (nu)
- {
- if (rem <= 3)
- {
- return false;
- }
- // Add a fader.
- //output[idx] = '~';
- //output[idx + 1] = 'h';
- //output[idx + 2] = '~';
- strcat(output, "~h~", rem);
- rem -= 3;
- idx += 3;
- --nu;
- }
- return true;
- }
- #define _COLOUR_GT_SPACE_DEF_0(%0) SAMP_GAME_TEXT_%0
- #define _COLOUR_GT_SPACE_DEF_1(%0) SAMP_GAME_TEXT_%0H
- #define _COLOUR_GT_SPACE_DEF_2(%0) SAMP_GAME_TEXT_%0HH
- #define _COLOUR_GT_SPACE_DEF_3(%0) SAMP_GAME_TEXT_%0HHH
- #define _COLOUR_GT_SPACE_DEF_4(%0) SAMP_GAME_TEXT_%0HHHH
- #define _COLOUR_GT_SPACE_DEF_5(%0) SAMP_GAME_TEXT_%0HHHHH
- #define _COLOUR_GT_SPACE(%0,%1) {('%0'|0x20)|(%1<<8),_COLOUR_GT_SPACE_DEF_%1(%0)>>>24,_COLOUR_GT_SPACE_DEF_%1(%0)>>16&0xFF,_COLOUR_GT_SPACE_DEF_%1(%0)>>8&0xFF}
- #define _COLOUR_GT_SPACE_N(%1) {'x'|(%1<<8),_COLOUR_GT_SPACE_DEF_%1()>>>24,_COLOUR_GT_SPACE_DEF_%1()>>16&0xFF,_COLOUR_GT_SPACE_DEF_%1()>>8&0xFF}
- #define COLOUR_FLOAT_INFINITY (Float:0x7F800000)
- static stock Colours_SAMPToGT(colour)
- {
- // Find the closest matching game text colour to the given SA:MP colour.
- static const
- sc_aColours[][4] =
- {
- // These can't be used as you can't set text to them. You can
- // however use them at the start by not changing.
- _COLOUR_GT_SPACE_N(0), _COLOUR_GT_SPACE_N(1),
- _COLOUR_GT_SPACE_N(2),
- _COLOUR_GT_SPACE(R,0), _COLOUR_GT_SPACE(R,1),
- _COLOUR_GT_SPACE(R,2), _COLOUR_GT_SPACE(R,3),
- _COLOUR_GT_SPACE(R,4), _COLOUR_GT_SPACE(R,5),
- _COLOUR_GT_SPACE(G,0), _COLOUR_GT_SPACE(G,1),
- _COLOUR_GT_SPACE(G,2), _COLOUR_GT_SPACE(G,3),
- //_COLOUR_GT_SPACE(G,4), // Don't want this twice (see Y2).
- _COLOUR_GT_SPACE(B,0), _COLOUR_GT_SPACE(B,1),
- _COLOUR_GT_SPACE(B,2), _COLOUR_GT_SPACE(B,3),
- _COLOUR_GT_SPACE(Y,0), _COLOUR_GT_SPACE(Y,1),
- _COLOUR_GT_SPACE(Y,2),
- _COLOUR_GT_SPACE(P,0), _COLOUR_GT_SPACE(P,1),
- _COLOUR_GT_SPACE(P,2),
- _COLOUR_GT_SPACE(W,0),
- _COLOUR_GT_SPACE(L,0)
- };
- new
- Float:dist = COLOUR_FLOAT_INFINITY,
- found = '\0',
- r = colour >> 16,
- g = colour >> 8 & 0xFF,
- b = colour & 0xFF,
- Float:tr, Float:tg, Float:tb, Float:cur;
- for (new i = 0; i < sizeof (sc_aColours); ++i)
- {
- tr = r - sc_aColours[i][1];
- tg = g - sc_aColours[i][2];
- tb = b - sc_aColours[i][3];
- cur = (tr * tr) + (tg * tg) + (tb * tb);
- if (cur < dist)
- {
- // This may sometimes give odd results in fades for draw results.
- dist = cur;
- found = sc_aColours[i][0];
- }
- }
- return found;
- }
- static stock Colours_GTToSAMP(const str[], &idx)
- {
- new
- cur = idx;
- if (str[cur] == '~')
- {
- // Check the colour is correctly ended.
- new
- t = str[++cur];
- if (str[++cur] != '~')
- {
- return -1;
- }
- ++cur;
- // Get the number of ~h~s after the colour.
- new
- c = 0;
- while (str[cur] == '~')
- {
- if (str[cur + 1] | 0x20 == 'h' && str[cur + 2] == '~')
- {
- ++c;
- cur += 3;
- }
- }
- idx = cur;
- // Return the correct colour for the given string.
- switch (t)
- {
- case 'b':
- {
- switch (c)
- {
- case 0:
- return SAMP_GAME_TEXT_B >>> 8;
- case 1:
- return SAMP_GAME_TEXT_BH >>> 8;
- case 2:
- return SAMP_GAME_TEXT_BHH >>> 8;
- case 3:
- return SAMP_GAME_TEXT_BHHH >>> 8;
- default:
- return SAMP_GAME_TEXT_W >>> 8;
- }
- }
- case 'g':
- {
- switch (c)
- {
- case 0:
- return SAMP_GAME_TEXT_G >>> 8;
- case 1:
- return SAMP_GAME_TEXT_GH >>> 8;
- case 2:
- return SAMP_GAME_TEXT_GHH >>> 8;
- case 3:
- return SAMP_GAME_TEXT_GHHH >>> 8;
- case 4:
- return SAMP_GAME_TEXT_GHHHH >>> 8;
- default:
- return SAMP_GAME_TEXT_W >>> 8;
- }
- }
- case 'h':
- {
- switch (c)
- {
- case 0:
- return SAMP_GAME_TEXT_H >>> 8;
- case 1:
- return SAMP_GAME_TEXT_HH >>> 8;
- default:
- return SAMP_GAME_TEXT_W >>> 8;
- }
- }
- case 'l':
- {
- return SAMP_GAME_TEXT_L >>> 8;
- }
- case 'p':
- {
- switch (c)
- {
- case 0:
- return SAMP_GAME_TEXT_P >>> 8;
- case 1:
- return SAMP_GAME_TEXT_PH >>> 8;
- case 2:
- return SAMP_GAME_TEXT_PHH >>> 8;
- default:
- return SAMP_GAME_TEXT_W >>> 8;
- }
- }
- case 'r':
- {
- switch (c)
- {
- case 0:
- return SAMP_GAME_TEXT_R >>> 8;
- case 1:
- return SAMP_GAME_TEXT_RH >>> 8;
- case 2:
- return SAMP_GAME_TEXT_RHH >>> 8;
- case 3:
- return SAMP_GAME_TEXT_RHHH >>> 8;
- case 4:
- return SAMP_GAME_TEXT_RHHHH >>> 8;
- case 5:
- return SAMP_GAME_TEXT_RHHHHH >>> 8;
- default:
- return SAMP_GAME_TEXT_W >>> 8;
- }
- }
- case 'w':
- {
- return SAMP_GAME_TEXT_W >>> 8;
- }
- case 'y':
- {
- switch (c)
- {
- case 0:
- return SAMP_GAME_TEXT_Y >>> 8;
- case 1:
- return SAMP_GAME_TEXT_YH >>> 8;
- case 2:
- return SAMP_GAME_TEXT_YHH >>> 8;
- default:
- return SAMP_GAME_TEXT_W >>> 8;
- }
- }
- default:
- {
- // Return the fact there is a different GT sequence but keep a
- // record of the number of hs which came after it to avoid
- // excess processing.
- //idx -= (c + 1) * 3;
- return 0x0F000000 | t | (c << 8);
- }
- }
- }
- return -1;
- }
- /*static stock Colours_DoTextSAMP(const input[], output[], offset, size)
- {
- if (offset == 0)
- {
- // Get the next possible start point.
- new
- lastspace = -1,
- startc = strfind(input, "("),
- starts = strfind(input, "{"),
- startg = strfind(input, "~"),
- idx = 0;
- if (startc == -1) startc = cellmax;
- if (starts == -1) starts = cellmax;
- if (startg == -1) startg = cellmax;
- while (idx < size)
- {
- if (startc < startg)
- {
- if (startc < starts)
- {
- // startc lowest. This is client style brackets.
- // We need to check for valid format.
- new
- curc,
- idx = startc + 1;
- if (input[idx] == '>')
- {
- // The start of a fade.
- ++idx;
- curc = Colour_Resolve(input, ')', idx);
- }
- else
- {
- curc = Colour_Resolve(input, ')', idx);
- }
- continue;
- }
- }
- else if (starts < startg)
- {
- // starts lowest. This is SA:MP style braces.
- continue;
- }
- // startg lowest. This is game text style tildas.
- switch (input[startg + 1])
- {
- case 'b':
- case 'g':
- case 'h':
- case 'l':
- case 'r':
- case 'p':
- case 'w':
- case 'y':
- // Colours.
- case 'n':
- // Need to handle this.
- case 'a':
- case 'd':
- case 'k':
- case 'u':
- case '<':
- case '>':
- case '1':
- case ']':
- // Symbols.
- default:
- return -1;
- }
- }
- }
- //else
- //{
- //}
- }
- #define Colors_DoText Colours_DoText
- stock Colours_DoText(const input[], output[], offset = -1, e_COLOUR_TYPE:type = colour_samp, size = sizeof (output))
- {
- switch ()
- {
- case colour_samp:
- return Colours_DoTextSAMP(input, output, offset, size);
- case colour_game_text:
- return Colours_DoTextGT(input, output, offset, size);
- case colour_text_draw:
- return Colours_DoTextTD(input, output, offset, size);
- //case colour_text_draw_ex:
- // return Colours_DoTextTDX();
- default:
- return -1;
- }
- }*/
- #if _YSI_USE_X11
- #include <YSI\internal\y_x11def>
- #endif
- static stock
- YSI_g_sColours[MAX_TEXT_COLOURS][2];
- #define SetColor SetColour
- stock SetColour(const name[], color)
- {
- #if _YSI_USE_X11
- //if (name[0] | 0x20 == 'x' && name[1] == '1' && name[2] == '1')
- if (!strcmp(name, "X11", true, 3))
- {
- if (name[3] == ' ' || name[3] == '_')
- {
- return SetColourHash(COLOUR_NAME_HASH(name[4]), color);
- }
- else
- {
- return SetColourHash(COLOUR_NAME_HASH(name[3]), color);
- }
- }
- else
- #endif
- {
- return SetColourHash(COLOUR_NAME_HASH(name), color);
- }
- }
- #define SetColorHash SetColourHash
- stock SetColourHash(hash, color)
- {
- color &= 0xFFFFFF00;
- #if _YSI_USE_X11
- new
- id = GetColourHash(hash);
- if (id != 0)
- {
- for (new i = 0; i != MAX_TEXT_COLOURS; ++i)
- {
- new
- iColor = YSI_g_sColours[i][0];
- if (iColor == hash)
- {
- YSI_g_sColours[i][1] = color;
- return i;
- }
- else if (iColor == 0)
- {
- // Tried to rename an X11 colour.
- return -1;
- }
- }
- }
- #endif
- for (new i = 0; i != MAX_TEXT_COLOURS; ++i)
- {
- new
- iColor = YSI_g_sColours[i][0];
- if (iColor == hash || iColor == 0)
- {
- YSI_g_sColours[i][0] = hash;
- YSI_g_sColours[i][1] = color;
- return i;
- }
- }
- return -1;
- }
- // This now uses REVERSE bernstein hash for switch compatibility.
- #define GetColor GetColour
- stock GetColour(const name[], alpha = 0xAA)
- {
- //if (name[0] | 0x20 == 'x' && name[1] == '1' && name[2] == '2')
- #if _YSI_USE_X11
- if (!strcmp(name, "X11", true, 3))
- {
- if (name[3] == ' ' || name[3] == '_')
- {
- return GetColourHash(COLOUR_NAME_HASH(name[4]), alpha);
- }
- else
- {
- return GetColourHash(COLOUR_NAME_HASH(name[3]), alpha);
- }
- }
- else
- #endif
- {
- return GetColourHash(COLOUR_NAME_HASH(name), alpha);
- }
- }
- #define GetColorHash GetColourHash
- stock GetColourHash(hash, alpha = 0xAA)
- {
- alpha &= 0xFF;
- // Do the REVERSE hash from YHash
- #if _YSI_USE_X11
- #include <YSI\internal\y_x11switch>
- #endif
- // Do the default code here.
- for (new i = 0; i != MAX_TEXT_COLOURS; ++i)
- {
- new
- iColor = YSI_g_sColours[i][0];
- if (iColor == hash)
- {
- return alpha | YSI_g_sColours[i][1];
- }
- else if (iColor == 0)
- {
- return 0;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement