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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
#include "globals.h"
#include "SkinOptions.h"
#include <utf8_helpers.h>
SkinOption::SkinOption(const char *aName)
: name(aName), type(CHECKBOX), valueCheckbox(false), valueNumber(0),
onChangeCallback(NULL), onChangeCallbackParam(NULL),
minValue(MININT), maxValue(MAXINT)
{
description = Utf8ToTchar(aName);
}
SkinOption::~SkinOption()
{
}
const char * SkinOption::getName() const
{
return name.c_str();
}
SkinOptionType SkinOption::getType() const
{
return type;
}
void SkinOption::setType(SkinOptionType type)
{
if (this->type == type)
return;
this->type = type;
fireOnChange();
}
const TCHAR * SkinOption::getDescription() const
{
return description.c_str();
}
void SkinOption::setDescription(const TCHAR * description)
{
if (this->description == description)
return;
this->description = description;
fireOnChange();
}
int SkinOption::getMax() const
{
return maxValue;
}
void SkinOption::setMax(int max)
{
this->maxValue = max;
setValueNumber(valueNumber);
}
int SkinOption::getMin() const
{
return minValue;
}
void SkinOption::setMin(int min)
{
this->minValue = min;
setValueNumber(valueNumber);
}
bool SkinOption::getValueCheckbox() const
{
return valueCheckbox;
}
void SkinOption::setValueCheckbox(bool value)
{
if (valueCheckbox == value)
return;
valueCheckbox = value;
fireOnChange();
}
int SkinOption::getValueNumber() const
{
return max(minValue, min(maxValue, valueNumber));
}
void SkinOption::setValueNumber(int value)
{
value = max(minValue, min(maxValue, value));
if (value == valueNumber)
return;
valueNumber = value;
fireOnChange();
}
const TCHAR * SkinOption::getValueText() const
{
return valueText.c_str();
}
void SkinOption::setValueText(const TCHAR * value)
{
if (valueText == value)
return;
valueText = value;
fireOnChange();
}
void SkinOption::setOnChangeCallback(SkinOptionCallback cb, void *param /*= NULL*/)
{
onChangeCallback = cb;
onChangeCallbackParam = param;
}
void SkinOption::fireOnChange()
{
if (onChangeCallback != NULL)
onChangeCallback(onChangeCallbackParam, this);
}
SkinOptions::SkinOptions()
: onAddRemoveCallback(NULL), onAddRemoveCallbackParam(NULL),
onChangeCallback(NULL), onChangeCallbackParam(NULL)
{
}
SkinOptions::~SkinOptions()
{
for(unsigned int i = 0; i < options.size(); i++)
delete options[i];
options.clear();
}
bool SkinOptions::addOption(SkinOption *opt)
{
_ASSERT(opt != NULL);
_ASSERT(opt->getName() != NULL);
if (getOption(opt->getName()) != NULL)
return false;
opt->setOnChangeCallback(onChangeCallback, onChangeCallbackParam);
options.push_back(opt);
fireOnAddRemove(opt);
return true;
}
SkinOption * SkinOptions::getOption(const char *name) const
{
_ASSERT(name != NULL);
for(unsigned int i = 0; i < options.size(); i++)
{
SkinOption *opt = options[i];
if (strcmp(opt->getName(), name) == 0)
return opt;
}
return NULL;
}
SkinOption * SkinOptions::getOption(unsigned int pos) const
{
if (pos >= options.size())
return NULL;
return options[pos];
}
unsigned int SkinOptions::getNumOptions() const
{
return options.size();
}
void SkinOptions::clearOptions()
{
if (options.size() <= 0)
return;
for(unsigned int i = 0; i < options.size(); i++)
{
fireOnAddRemove(options[i]);
delete options[i];
}
options.clear();
}
void SkinOptions::setOnOptionAddRemoveCallback(SkinOptionCallback cb, void *param /*= NULL*/)
{
onAddRemoveCallback = cb;
onAddRemoveCallbackParam = param;
}
void SkinOptions::setOnOptionChangeCallback(SkinOptionCallback cb, void *param /*= NULL*/)
{
onChangeCallback = cb;
onChangeCallbackParam = param;
for(unsigned int i = 0; i < options.size(); i++)
options[i]->setOnChangeCallback(cb, param);
}
void SkinOptions::fireOnAddRemove(SkinOption *opt)
{
if (onAddRemoveCallback != NULL)
onAddRemoveCallback(onAddRemoveCallbackParam, opt);
}
|