My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#include "LayDes.h"

struct EnumProperty : public EditorProperty<DropList> {
virtual void SetData(const Value& v);
virtual String Save() const { return ~editor; }
virtual void Read(CParser& p) { SetData(ReadPropertyParam(p)); }

EnumProperty(VectorMap<String, String>& e) {
Add(editor.HSizePos(100, 2).TopPos(2));
for(int i = 0; i < e.GetCount(); i++)
editor.Add(e.GetKey(i), e[i]);
SetData(defval = e.GetKey(0));
}
};

void EnumProperty::SetData(const Value& v)
{
if(!editor.HasKey(v))
editor.Add(v, v);
editor <<= v;
}

bool ParseTemplate(String& type, String& temp)
{
int q = type.Find('<');
if(q < 0)
return false;
temp = type.Mid(q + 1);
type.Trim(q);
q = temp.Find('>');
if(q >= 0)
temp.Trim(q);
Swap(temp, type);
return true;
}

void LayoutItem::Create(const String& _type)
{
Invalidate();
property.Clear();
type = _type;
pos.x = Ctrl::PosLeft(0, 10);
pos.y = Ctrl::PosTop(0, 10);
String tp = type;
String tm;
if(ParseTemplate(tp, tm))
CreateProperties(tm, 0);
CreateProperties(tp, 1);
}

void LayoutItem::CreateProperties(const String& classname, int level)
{
int q = LayoutTypes().Find(classname);
if(q < 0)
q = LayoutTypes().Find("Unknown");
if(q < 0)
return;
const LayoutType& c = LayoutTypes()[q];
for(int i = 0; i < c.property.GetCount(); i++) {
const TypeProperty& r = c.property[i];
if(IsNull(r.type))
CreateProperties(r.name, level + 1);
else {
ItemProperty *n = ItemProperty::Create(r.type);
if(!n) {
q = LayoutEnums().Find(r.type);
if(q >= 0)
n = new EnumProperty(LayoutEnums()[q]);
}
if(!n)
n = new RawProperty;
n->SetCharset(charset);
int q = -1;
for(int i = 0; i < property.GetCount(); i++)
if(r.name == property[i].name)
q = i;
int l = q >= 0 ? property[q].level : level + r.level;
ItemProperty& ip = q >= 0 ? property.Set(q, n) : property.Add(n);
ip.level = l;
ip.name = r.name;
if(!IsNull(r.defval))
try {
CParser p(r.defval);
ip.Read(p);
ip.defval = ~ip;
}
catch(CParser::Error e) {
PutConsole(e + "\n");
}
else
ip.defval = ~ip;
ip.help = r.help;
}
}
}

void LayoutItem::SetCharset(byte cs)
{
charset = cs;
for(int i = 0; i < property.GetCount(); i++)
property[i].SetCharset(charset);
}

void LayoutItem::ReadProperties(CParser& p, bool addunknown)
{
do {
if(p.Id("LeftPosZ") || p.Id("LeftPos")) {
Point pt = ReadPoint(p);
pos.x = Ctrl::PosLeft(pt.x, pt.y);
}
else
if(p.Id("RightPosZ") || p.Id("RightPos")) {
Point pt = ReadPoint(p);
pos.x = Ctrl::PosRight(pt.x, pt.y);
}
else
if(p.Id("HSizePosZ") || p.Id("HSizePos")) {
Point pt = ReadPoint(p);
pos.x = Ctrl::PosSize(pt.x, pt.y);
}
else
if(p.Id("HCenterPosZ") || p.Id("HCenterPos")) {
Point pt = ReadPoint(p);
pos.x = Ctrl::PosCenter(pt.x, pt.y);
}
else
if(p.Id("TopPosZ") || p.Id("TopPos")) {
Point pt = ReadPoint(p);
pos.y = Ctrl::PosLeft(pt.x, pt.y);
}
else
if(p.Id("BottomPosZ") || p.Id("BottomPos")) {
Point pt = ReadPoint(p);
pos.y = Ctrl::PosRight(pt.x, pt.y);
}
else
if(p.Id("VSizePosZ") || p.Id("VSizePos")) {
Point pt = ReadPoint(p);
pos.y = Ctrl::PosSize(pt.x, pt.y);
}
else
if(p.Id("VCenterPosZ") || p.Id("VCenterPos")) {
Point pt = ReadPoint(p);
pos.y = Ctrl::PosCenter(pt.x, pt.y);
}
else {
String name = p.ReadId();
int q = FindProperty(name);
if(q < 0)
if(addunknown) {
q = property.GetCount();
ItemProperty& new_prop = property.Add(new RawProperty);
new_prop.SetCharset(charset);
new_prop.name = name;
}
else {
p.PassChar('(');
ReadPropertyParam(p);
p.PassChar(')');
}
if(q >= 0) {
ItemProperty& ip = property[q];
ip.SetCharset(charset);
p.PassChar('(');
ip.Read(p);
p.PassChar(')');
}
}
}
while(p.Char('.'));
}

int LayoutItem::FindProperty(const String& s) const
{
for(int i = 0; i < property.GetCount(); i++)
if(property[i].name == s)
return i;
return -1;
}

String LayoutItem::SaveProperties() const
{
String out;
Vector<int> o = GetSortOrder(property, FieldRelation(&ItemProperty::level, StdLess<int>()));
for(int i = 0; i < o.GetCount(); i++) {
const ItemProperty& ip = property[o[i]];
if(ip.GetData() != ip.defval)
out << '.' << ip.name << '(' << ip.Save() << ')';
}
switch(pos.x.GetAlign()) {
case Ctrl::LEFT: out << Format(".LeftPosZ(%d, %d)", pos.x.GetA(), pos.x.GetB()); break;
case Ctrl::RIGHT: out << Format(".RightPosZ(%d, %d)", pos.x.GetA(), pos.x.GetB()); break;
case Ctrl::SIZE: out << Format(".HSizePosZ(%d, %d)", pos.x.GetA(), pos.x.GetB()); break;
case Ctrl::CENTER: out << Format(".HCenterPosZ(%d, %d)", pos.x.GetB(), pos.x.GetA()); break;
}
switch(pos.y.GetAlign()) {
case Ctrl::TOP: out << Format(".TopPosZ(%d, %d)", pos.y.GetA(), pos.y.GetB()); break;
case Ctrl::BOTTOM: out << Format(".BottomPosZ(%d, %d)", pos.y.GetA(), pos.y.GetB()); break;
case Ctrl::SIZE: out << Format(".VSizePosZ(%d, %d)", pos.y.GetA(), pos.y.GetB()); break;
case Ctrl::CENTER: out << Format(".VCenterPosZ(%d, %d)", pos.y.GetB(), pos.y.GetA()); break;
}
out.Remove(0);
return out;
}

String LayoutItem::Save(int i) const
{
String out;
if(type.IsEmpty())
out << "\tUNTYPED(";
else
out << "\tITEM(" << type << ", ";
String var = variable.IsEmpty() ? Format("dv___%d", i) : variable;
out << var << ", " << SaveProperties() << ")\r\n";
return out;
}

void LayoutItem::UnknownPaint(Draw& w)
{
DrawFrame(w, 0, 0, csize.cx, csize.cy, SColorShadow);
int q = FindProperty("SetLabel");
if(q >= 0 && IsString(~property[q]))
DrawSmartText(w, 0, 0, csize.cx, ToUtf8((WString)~property[q]));
Size tsz = GetTextSize(type, Arial(11));
w.DrawRect(csize.cx - tsz.cx, csize.cy - tsz.cy, tsz.cx, tsz.cy, SColorShadow);
w.DrawText(csize.cx - tsz.cx, csize.cy - tsz.cy, type, Arial(11), SColorLight);
}

void LayoutItem::CreateMethods(EscValue& ctrl, const String& type, bool copy) const
{
int q = LayoutTypes().Find(type);
if(q < 0)
q = LayoutTypes().Find("Unknown");
if(q < 0)
return;
const LayoutType& m = LayoutTypes()[q];
for(q = 0; q < m.property.GetCount(); q++)
if(IsNull(m.property[q].type))
CreateMethods(ctrl, m.property[q].name, copy);
for(q = 0; q < m.methods.GetCount(); q++) {
ctrl.MapSet(m.methods.GetKey(q), m.methods[q]);
if(copy)
ctrl.MapSet("Ctrl" + m.methods.GetKey(q), m.methods[q]);
}
}

EscValue LayoutItem::CreateEsc() const
{
EscValue ctrl;
String tp = type;
String tm;
if(ParseTemplate(tp, tm)) {
CreateMethods(ctrl, tp, true);
if(ctrl.IsMap())
ctrl.MapSet("CtrlPaint", ctrl.MapGet("Paint"));
CreateMethods(ctrl, tm, false);
}
else
CreateMethods(ctrl, tp, false);
for(int q = 0; q < property.GetCount(); q++) {
EscValue w;
const Value& v = ~property[q];
if(v.Is<Font>()) {
Font fnt = v;
if(fnt.GetHeight())
fnt.Height(Ctrl::VertLayoutZoom(fnt.GetHeight()));
w = EscFont(fnt);
}
if(IsString(v))
w = (WString)v;
if(IsNumber(v))
w = (double)v;
if(v.Is<Color>())
w = EscColor(v);
ctrl.MapSet(property[q].name, w);
}
ctrl.MapSet("type", (WString)type);
ctrl.MapSet("GetSize", ReadLambda(Format("() { return Size(%d, %d); }", csize.cx, csize.cy)));
ctrl.MapSet("GetRect", ReadLambda(Format("() { return Rect(0, 0, %d, %d); }", csize.cx, csize.cy)));
return ctrl;
}

EscValue LayoutItem::ExecuteMethod(const char *method, Vector<EscValue>& arg) const
{
try {
EscValue self = CreateEsc();
return ::Execute(UscGlobal(), &self, method, arg, 50000);
}
catch(CParser::Error& e) {
PutConsole(e + "\n");
}
return EscValue();
}

EscValue LayoutItem::ExecuteMethod(const char *method) const
{
Vector<EscValue> arg;
return ExecuteMethod(method, arg);
}

Size LayoutItem::GetMinSize()
{
return SizeEsc(ExecuteMethod("GetMinSize"));
}

Size LayoutItem::GetStdSize()
{
return SizeEsc(ExecuteMethod("GetStdSize"));
}

void LayoutItem::Paint(Draw& w, Size sz, bool sample)
{
if(csize != sz) {
csize = sz;
DrawingDraw dw(csize);
int q = LayoutTypes().Find(type);
if(q < 0)
q = LayoutTypes().Find("Unknown");
if(q < 0)
UnknownPaint(dw);
else {
try {
EscValue ctrl = CreateEsc();
if(ctrl.MapGet("Paint").IsLambda()) {
if(sample) {
ctrl.MapSet("SetLabel", (WString)type);
Vector<EscValue> arg;
::Execute(UscGlobal(), &ctrl, "Sample", arg, 50000);
}
Vector<EscValue> arg;
EscValue draw;
new EscDraw(draw, dw);
arg.Add(draw);
::Execute(UscGlobal(), &ctrl, "Paint", arg, 50000);
}
else
UnknownPaint(dw);
cache = dw;
}
catch(CParser::Error e) {
PutConsole(e);
DrawingDraw edw;
edw.DrawRect(0, 0, csize.cx, csize.cy, Red);
edw.DrawText(2, 2, e, Arial(11).Bold(), Yellow);
cache = edw;
}
}
}
w.DrawDrawing(sz, cache);
}

Image GetTypeIcon(const String& type, int cx, int cy, int i, Color bg)
{
ASSERT(i >= 0 && i < 2);
int q = LayoutTypes().Find(type);
if(q < 0)
return Null;
LayoutType& p = LayoutTypes()[q];
Image& icon = p.icon[i];
if(p.iconsize[i] != Size(cx, cy)) {
p.iconsize[i] = Size(cx, cy);
LayoutItem m;
m.Create(type);
Size stdsize = m.GetStdSize();
if(stdsize.cx == 0 || stdsize.cy == 0)
return Null;

ImageDraw w(stdsize);
w.DrawRect(stdsize, bg);
m.Paint(w, stdsize, true);
if(stdsize.cx * cy > stdsize.cy * cx)
cy = stdsize.cy * cx / stdsize.cx;
else
cx = stdsize.cx * cy / stdsize.cy;
icon = Rescale(w, cx, cy);
}
return icon;
}

Change log

r4399 by cxl on Jan 11, 2012   Diff
.ide cosmetics
Go to: 
Project members, sign in to write a code review

Older revisions

r281 by mdelfede on Jun 7, 2008   Diff
changed svn layout
r216 by mdelfede on Apr 17, 2008   Diff
new uvs2 releases : uppsrc-2516
tutorial-38  examples-140
reference-110
r64 by unodgs on Nov 8, 2007   Diff
Update to 711-dev1
All revisions of this file

File info

Size: 9538 bytes, 378 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting