File: color.cpp

package info (click to toggle)
freespace2 24.2.0%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,716 kB
  • sloc: cpp: 595,001; ansic: 21,741; python: 1,174; sh: 457; makefile: 248; xml: 181
file content (73 lines) | stat: -rw-r--r-- 1,460 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

#include "color.h"

namespace scripting {
namespace api {

ADE_OBJ(l_Color, color, "color", "A color value");

// That member syntax is pretty weird to be honest...
static int colorVarHelper(lua_State* L, ubyte color::*member)
{
	color* clr = nullptr;
	float newVal = -1.0f;

	if (!ade_get_args(L, "o|f", l_Color.GetPtr(&clr), &newVal)) {
		return ade_set_args(L, "f", -1.0f);
	}

	if (ADE_SETTING_VAR) {
		if (newVal < 0.0f || newVal > 255.0f) {
			LuaError(L, "Invalid color value %f!", newVal);
			CLAMP(newVal, 0.0f, 255.0f);
		}

		clr->*member = static_cast<ubyte>(newVal);
	}

	return ade_set_args(L, "i", clr->*member);
}

ADE_VIRTVAR(Red,
	l_Color,
	"number",
	"The 'red' value of the color in the range from 0 to 255",
	"number",
	"The 'red' value")
{
	return colorVarHelper(L, &color::red);
}

ADE_VIRTVAR(Green,
	l_Color,
	"number",
	"The 'green' value of the color in the range from 0 to 255",
	"number",
	"The 'green' value")
{
	return colorVarHelper(L, &color::green);
}

ADE_VIRTVAR(Blue,
	l_Color,
	"number",
	"The 'blue' value of the color in the range from 0 to 255",
	"number",
	"The 'blue' value")
{
	return colorVarHelper(L, &color::blue);
}

ADE_VIRTVAR(Alpha,
	l_Color,
	"number",
	"The 'alpha' or opacity value of the color in the range from 0 to 255. 0 is totally transparent, 255 is completely "
	"opaque.",
	"number",
	"The 'alpha' value")
{
	return colorVarHelper(L, &color::alpha);
}

} // namespace api
} // namespace scripting