- Joined
- Oct 12, 2011
- Messages
- 3,449
An end-user purposed snippet. To ease you in using colors, save them for later use as well as modifying their compositions easily.
Demo:
JASS:
library QuickColor requires HexString
/*
[Snippet] Quick Color v1.0
by Quilnez
Small snippet for basic color needs. Would ease you in using
colors as well as getting/modifying their compositions.
Requires:
HexString | hiveworkshop.com/forums/jass-resources-412/snippet-hexstring-248993/
Limitations:
- Can't use "alpha", "red", "green", and "blue" as
variable name (case sensitive)
- Must be declared outside library/scope
- Can only be used as a global variable
Example:
Create a red color named "RED"
//! runtextmacro CreateQuickColor("RED", "FFFF0000")
Usage
call BJDebugMsg(RED + "some string")
Getting compositions
call SetUnitVertexColor(someunit, RED.red, RED.green, RED.blue, RED.alpha)
Modifying compositions
set RED.alpha = 0
set RED.red = 0
set RED.green = 0
set RED.blue = 0
*/
//! textmacro CreateQuickColor takes NAME, CODE
scope QuickColor$NAME$
globals
string $NAME$ = "|C$CODE$"
endglobals
struct $NAME$ extends array
private static integer a
private static integer r
private static integer g
private static integer b
private static method trunc takes integer i returns integer
if i > 255 then
return 255
elseif i < 0 then
return 0
endif
return i
endmethod
static constant method operator alpha takes nothing returns integer
return a
endmethod
static method operator alpha= takes integer value returns nothing
set a = trunc(value)
set $NAME$ = SubString($NAME$,0,2)+I2HS(a,true)+SubString($NAME$,4,10)
endmethod
static constant method operator red takes nothing returns integer
return r
endmethod
static method operator red= takes integer value returns nothing
set r = trunc(value)
set $NAME$ = SubString($NAME$,0,4)+I2HS(r,true)+SubString($NAME$,6,10)
endmethod
static constant method operator green takes nothing returns integer
return g
endmethod
static method operator green= takes integer value returns nothing
set g = trunc(value)
set $NAME$ = SubString($NAME$,0,6)+I2HS(g,true)+SubString($NAME$,8,10)
endmethod
static constant method operator blue takes nothing returns integer
return b
endmethod
static method operator blue= takes integer value returns nothing
set b = trunc(value)
set $NAME$ = SubString($NAME$,0,8)+I2HS(b, true)
endmethod
private static method onInit takes nothing returns nothing
set a = HS2I(SubString($NAME$,2,4))
set r = HS2I(SubString($NAME$,4,6))
set g = HS2I(SubString($NAME$,6,8))
set b = HS2I(SubString($NAME$,8,10))
endmethod
endstruct
endscope
//! endtextmacro
endlibrary
Demo:
JASS:
//! runtextmacro CreateQuickColor("RED", "FFFF0000")
scope test initializer init
private function init takes nothing returns nothing
call BJDebugMsg(RED+"1234567890|R")
call BJDebugMsg("alpha: " + I2S(RED.alpha))
call BJDebugMsg("red: " + I2S(RED.red))
call BJDebugMsg("green: " + I2S(RED.green))
call BJDebugMsg("blue: " + I2S(RED.blue))
endfunction
endscope
Last edited: