Skip to content

Commit

Permalink
Common - Add colour conversion functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Drofseh committed Sep 23, 2024
1 parent 9a6b78e commit 4b5aca9
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 0 deletions.
6 changes: 6 additions & 0 deletions addons/common/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ class CfgFunctions {
PATHTO_FNC(compileFinal);
PATHTO_FNC(createUUID);
PATHTO_FNC(escapeRegex);
PATHTO_FNC(colorHEXtoDecimal);
PATHTO_FNC(colorHEXAtoDecimal);
PATHTO_FNC(colorAHEXtoDecimal);
PATHTO_FNC(colorRGBtoDecimal);
PATHTO_FNC(colorRGBAtoDecimal);
PATHTO_FNC(colorARGBtoDecimal);
};

class Broken {
Expand Down
35 changes: 35 additions & 0 deletions addons/common/fnc_colorAHEXtoDecimal.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_colorAHEXtoDecimal
Description:
Converts a hexidecimal coded color with transparency to the ingame decimal color format.
Parameters:
_hexString - A hexidecimal color code, "AARRGGBB" with or without a leading # <STRING>
Returns:
Ingame color format <ARRAY>
Examples:
(begin example)
"AABA2619" call CBA_fnc_colorAHEXtoDecimal
(end)
Author:
Lambda.Tiger & drofseh
---------------------------------------------------------------------------- */
SCRIPT(colorAHEXtoDecimal);

params [["_hexString", "00000000", [""]]];

_hexString = ((toUpperANSI _hexString) trim ["#", 0]) regexReplace ["[^0-9A-F]", "0"];

private _values = _hexString splitString "";

[
call compile ("0x"+_values#2+_values#3),
call compile ("0x"+_values#4+_values#5),
call compile ("0x"+_values#6+_values#7),
call compile ("0x"+_values#0+_values#1)
] call test_fnc_colorRGBAtoDecimal;
28 changes: 28 additions & 0 deletions addons/common/fnc_colorARGBtoDecimal.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_colorARGBtoDecimal
Description:
Converts an ARGB coded color with transparency to the ingame decimal color format.
Parameters:
_alpha - The alpha/transparency channel, 0-255 <NUMBER>
_red - The red channel, 0-255 <NUMBER>
_green - The green channel, 0-255 <NUMBER>
_blue - The blue channel, 0-255 <NUMBER>
Returns:
Ingame color format <ARRAY>
Examples:
(begin example)
[255,186,38,25] call CBA_fnc_colorARGBtoDecimal
(end)
Author:
drofseh & Lambda.Tiger
---------------------------------------------------------------------------- */
SCRIPT(colorARGBtoDecimal);

params [["_alpha", 0, [0]],["_red", 0, [0]],["_green", 0, [0]],["_blue", 0, [0]]];
[_red,_green,_blue,_alpha] apply {(0 max _x min 255)/255}
35 changes: 35 additions & 0 deletions addons/common/fnc_colorHEXAtoDecimal.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_colorHEXAtoDecimal
Description:
Converts a hexidecimal coded color with transparency to the ingame decimal color format.
Parameters:
_hexString - A hexidecimal color code, "RRGGBBAA" with or without a leading # <STRING>
Returns:
Ingame color format <ARRAY>
Examples:
(begin example)
"BA2619AA" call CBA_fnc_colorHEXAtoDecimal
(end)
Author:
Lambda.Tiger & drofseh
---------------------------------------------------------------------------- */
SCRIPT(colorHEXAtoDecimal);

params [["_hexString", "00000000", [""]]];

_hexString = ((toUpperANSI _hexString) trim ["#", 0]) regexReplace ["[^0-9A-F]", "0"];

private _values = _hexString splitString "";

[
call compile ("0x"+_values#0+_values#1),
call compile ("0x"+_values#2+_values#3),
call compile ("0x"+_values#4+_values#5),
call compile ("0x"+_values#6+_values#7)
] call test_fnc_colorRGBAtoDecimal;
34 changes: 34 additions & 0 deletions addons/common/fnc_colorHEXtoDecimal.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_colorHEXtoDecimal
Description:
Converts a hexidecimal coded color without transparency to the ingame decimal color format.
Parameters:
_hexString - A hexidecimal color code, "RRGGBB" with or without a leading # <STRING>
Returns:
Ingame color format <ARRAY>
Examples:
(begin example)
"BA2619" call CBA_fnc_colorHEXtoDecimal
(end)
Author:
Lambda.Tiger & drofseh
---------------------------------------------------------------------------- */
SCRIPT(colorHEXtoDecimal);

params [["_hexString", "000000", [""]]];

_hexString = ((toUpperANSI _hexString) trim ["#", 0]) regexReplace ["[^0-9A-F]", "0"];

private _values = _hexString splitString "";

[
call compile ("0x"+_values#0+_values#1),
call compile ("0x"+_values#2+_values#3),
call compile ("0x"+_values#4+_values#5)
] call test_fnc_colorRGBtoDecimal;
28 changes: 28 additions & 0 deletions addons/common/fnc_colorRGBAtoDecimal.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_colorRGBAtoDecimal
Description:
Converts an RGBA coded color with transparency to the ingame decimal color format.
Parameters:
_red - The red channel, 0-255 <NUMBER>
_green - The green channel, 0-255 <NUMBER>
_blue - The blue channel, 0-255 <NUMBER>
_alpha - The alpha/transparency channel, 0-255 <NUMBER>
Returns:
Ingame color format <ARRAY>
Examples:
(begin example)
[186,38,25,255] call CBA_fnc_colorRGBAtoDecimal
(end)
Author:
drofseh & Lambda.Tiger
---------------------------------------------------------------------------- */
SCRIPT(colorRGBAtoDecimal);

params [["_red", 0, [0]],["_green", 0, [0]],["_blue", 0, [0]],["_alpha", 0, [0]]];
[_red,_green,_blue,_alpha] apply {(0 max _x min 255)/255}
27 changes: 27 additions & 0 deletions addons/common/fnc_colorRGBtoDecimal.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "script_component.hpp"
/* ----------------------------------------------------------------------------
Function: CBA_fnc_colorRGBtoDecimal
Description:
Converts an RGB coded color without transparency to the ingame decimal color format.
Parameters:
_red - The red channel, 0-255 <NUMBER>
_green - The green channel, 0-255 <NUMBER>
_blue - The blue channel, 0-255 <NUMBER>
Returns:
Ingame color format <ARRAY>
Examples:
(begin example)
[186,38,25] call test_fnc_colorRGBtoDecimal
(end)
Author:
drofseh & Lambda.Tiger
---------------------------------------------------------------------------- */
SCRIPT(colorRGBtoDecimal);

params [["_red", 0, [0]],["_green", 0, [0]],["_blue", 0, [0]]];
[_red,_green,_blue] apply {(0 max _x min 255)/255}

0 comments on commit 4b5aca9

Please sign in to comment.