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
217
218
219
220
221
222
223
224
225
226
227
|
#include "templateviewelement.h"
#include "../config.h"
cTemplateViewElement::cTemplateViewElement(void) {
debugTokens = false;
parameters = NULL;
containerX = 0;
containerY = 0;
containerWidth = 0;
containerHeight = 0;
pixOffset = -1;
pixmapIterator = NULL;
currentNode = NULL;
}
cTemplateViewElement::~cTemplateViewElement(void) {
if (parameters)
delete parameters;
for (vector<cTemplatePixmapNode*>::iterator it = viewPixmapNodes.begin(); it != viewPixmapNodes.end(); it++) {
delete (*it);
}
}
void cTemplateViewElement::SetContainer(int x, int y, int width, int height) {
containerX = x;
containerY = y;
containerWidth = width;
containerHeight = height;
}
void cTemplateViewElement::SetGlobals(cGlobals *globals) {
this->globals = globals;
for (vector<cTemplatePixmapNode*>::iterator pix = viewPixmapNodes.begin(); pix != viewPixmapNodes.end(); pix++) {
(*pix)->SetGlobals(globals);
}
}
void cTemplateViewElement::SetParameters(vector<pair<string, string> > ¶ms) {
parameters = new cTemplateFunction(ftViewElement);
parameters->SetGlobals(globals);
parameters->SetParameters(params);
}
bool cTemplateViewElement::CalculateParameters(void) {
if (!parameters)
return true;
bool paramsValid = true;
parameters->SetContainer(containerX, containerY, containerWidth, containerHeight);
parameters->SetGlobals(globals);
paramsValid = parameters->CalculateParameters();
parameters->ParseParameters();
return paramsValid;
}
bool cTemplateViewElement::CalculatePixmapParameters(void) {
bool paramsValid = true;
for (vector<cTemplatePixmapNode*>::iterator pix = viewPixmapNodes.begin(); pix != viewPixmapNodes.end(); pix++) {
(*pix)->SetContainer(containerX, containerY, containerWidth, containerHeight);
(*pix)->SetGlobals(globals);
paramsValid = paramsValid && (*pix)->CalculateParameters();
}
return paramsValid;
}
bool cTemplateViewElement::CalculatePixmapParametersList(int orientation, int numElements) {
bool paramsValid = true;
for (vector<cTemplatePixmapNode*>::iterator pix = viewPixmapNodes.begin(); pix != viewPixmapNodes.end(); pix++) {
(*pix)->SetContainer(containerX, containerY, containerWidth, containerHeight);
(*pix)->SetGlobals(globals);
if (orientation == orHorizontal) {
if (numElements > 0) {
int width = containerWidth / numElements;
(*pix)->SetWidth(width);
}
} else if (orientation == orVertical) {
if (numElements > 0) {
int height = containerHeight / numElements;
(*pix)->SetHeight(height);
}
}
paramsValid = paramsValid && (*pix)->CalculateParameters();
}
return paramsValid;
}
int cTemplateViewElement::GetNumericParameter(eParamType type) {
if (!parameters)
return -1;
return parameters->GetNumericParameter(type);
}
int cTemplateViewElement::GetNumPixmaps(void) {
int numPixmaps = 0;
for (vector<cTemplatePixmapNode*>::iterator pix = viewPixmapNodes.begin(); pix != viewPixmapNodes.end(); pix++) {
numPixmaps += (*pix)->NumPixmaps();
}
return numPixmaps;
};
void cTemplateViewElement::InitPixmapNodeIterator(void) {
pixmapNodeIterator = viewPixmapNodes.begin();
}
cTemplatePixmapNode *cTemplateViewElement::GetNextPixmapNode(void) {
if (pixmapNodeIterator == viewPixmapNodes.end())
return NULL;
cTemplatePixmapNode *pix = *pixmapNodeIterator;
pixmapNodeIterator++;
return pix;
}
void cTemplateViewElement::InitPixmapIterator(void) {
pixmapNodeIterator = viewPixmapNodes.begin();
if (pixmapNodeIterator == viewPixmapNodes.end())
return;
if (!(*pixmapNodeIterator)->IsContainer()) {
//first node is a pixmap, use this
pixmapIterator = dynamic_cast<cTemplatePixmap*>(*pixmapNodeIterator);
return;
}
//first node is a container, so fetch first pixmap of this container
currentNode = dynamic_cast<cTemplatePixmapContainer*>(*pixmapNodeIterator);
currentNode->InitIterator();
pixmapIterator = currentNode->GetNextPixmap();
}
cTemplatePixmap *cTemplateViewElement::GetNextPixmap(void) {
if (!pixmapIterator)
return NULL;
cTemplatePixmap *current = pixmapIterator;
//set next pixmap
if (!currentNode) {
//last node was a pixmap
pixmapNodeIterator++;
if (pixmapNodeIterator == viewPixmapNodes.end()) {
pixmapIterator = NULL;
return current;
}
if (!(*pixmapNodeIterator)->IsContainer()) {
//node is a pixmap, use this
pixmapIterator = dynamic_cast<cTemplatePixmap*>(*pixmapNodeIterator);
return current;
}
//node is a container, so fetch first pixmap of this container
currentNode = dynamic_cast<cTemplatePixmapContainer*>(*pixmapNodeIterator);
currentNode->InitIterator();
pixmapIterator = currentNode->GetNextPixmap();
} else {
pixmapIterator = currentNode->GetNextPixmap();
if (pixmapIterator) {
return current;
}
currentNode = NULL;
pixmapNodeIterator++;
if (pixmapNodeIterator == viewPixmapNodes.end()) {
pixmapIterator = NULL;
return current;
}
if (!(*pixmapNodeIterator)->IsContainer()) {
//node is a pixmap, use this
pixmapIterator = dynamic_cast<cTemplatePixmap*>(*pixmapNodeIterator);
return current;
}
//node is a container, so fetch first pixmap of this container
currentNode = dynamic_cast<cTemplatePixmapContainer*>(*pixmapNodeIterator);
currentNode->InitIterator();
pixmapIterator = currentNode->GetNextPixmap();
}
return current;
}
cTemplateFunction *cTemplateViewElement::GetFunction(string name) {
InitPixmapIterator();
cTemplatePixmap *pix = NULL;
while (pix = GetNextPixmap()) {
pix->InitFunctionIterator();
cTemplateFunction *func = NULL;
while(func = pix->GetNextFunction()) {
if (func->GetType() == ftDrawText) {
string funcName = func->GetParameter(ptName);
if (!funcName.compare(name))
return func;
} else {
continue;
}
}
}
return NULL;
}
bool cTemplateViewElement::Execute(void) {
if (!parameters)
return true;
return parameters->DoExecute();
}
bool cTemplateViewElement::Detach(void) {
if (!parameters)
return false;
int detached = parameters->GetNumericParameter(ptDetached);
if (detached == 1)
return true;
return false;
}
string cTemplateViewElement::GetMode(void) {
if (!parameters)
return "";
return parameters->GetParameter(ptMode);
}
bool cTemplateViewElement::DebugTokens(void) {
if (!parameters)
return false;
return parameters->DoDebug();
}
void cTemplateViewElement::Debug(void) {
esyslog("skindesigner: viewelement container size x: %d, y: %d, width: %d, height %d", containerX, containerY, containerWidth, containerHeight);
if (parameters)
parameters->Debug();
return;
for (vector<cTemplatePixmapNode*>::iterator it = viewPixmapNodes.begin(); it != viewPixmapNodes.end(); it++) {
(*it)->Debug();
}
}
|