/
Area.hpp
459 lines (414 loc) · 17.3 KB
/
Area.hpp
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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
//
// AmigaOS MUI C++ wrapper
//
// (c) 2022-2024 TDolphin
//
#pragma once
#include "Notify.hpp"
#include "ValueTypes/Area/Font.hpp"
#include "ValueTypes/Area/Frame.hpp"
#include "ValueTypes/Area/InputMode.hpp"
#include "ValueTypes/Area/PointerType.hpp"
#include "ValueTypes/ImageOrBackground.hpp"
#undef Enable
#undef Disable
namespace MUI
{
#ifndef __MORPHOS__
struct Dim
{
long width;
long height;
Dim(const unsigned long value);
};
#endif
class Area : public Notify
{
public:
Area(const Object *pMuiObject)
: Notify(pMuiObject)
{
}
Area(const Root &root)
: Notify(root.muiObject())
{
}
// instanceOf
const static std::string className;
static inline bool instanceOf(Object *pMuiObject)
{
return MUI::instanceOf(pMuiObject, className.c_str());
}
// is/get/set (attributes), all setters return object reference
/// @brief [ @b MUIA_BottomEdge ]
long getBottomEdge() const;
/// @brief [ @b MUIA_ContextMenu ]
Object *getContextMenu() const;
#ifdef MUIA_ContextMenuHook
/// @brief [ @b MUIA_ContextMenuHook ]
Hook *getContextMenuHook() const;
#endif
/// @brief [ @b MUIA_ContextMenuTrigger ]
Object *getContextMenuTrigger() const;
/// @brief [ @b MUIA_ControlChar ]
char getControlChar() const;
/// @brief [ @b MUIA_CycleChain ]
long getCycleChain() const;
/// @brief [ @b MUIA_Disabled ]
bool isDisabled() const;
/// @brief [ @b MUIA_DoubleBuffer ]
bool isDoubleBuffer() const;
/// @brief [ @b MUIA_DoubleClick ]
bool isDoubleClick() const;
/// @brief [ @b MUIA_Draggable ]
bool isDraggable() const;
/// @brief [ @b MUIA_Dropable ]
bool isDropable() const;
/// @brief [ @b MUIA_Floating ]
bool isFloating() const;
/// @brief [ @b MUIA_Font ]
TextFont *getFont() const;
/// @brief [ @b MUIA_FrameDynamic ]
bool isFrameDynamic() const;
/// @brief [ @b MUIA_FrameTitle ]
std::string getFrameTitle() const;
/// @brief [ @b MUIA_FrameVisible ]
bool isFrameVisible() const;
/// @brief [ @b MUIA_Height ]
long getHeight() const;
/// @brief [ @b MUIA_HorizDisappear ]
long getHorizDisappear() const;
/// @brief [ @b MUIA_HorizWeight ]
short getHorizWeight() const;
/// @brief [ @b MUIA_InnerBottom ]
long getInnerBottom() const;
/// @brief [ @b MUIA_InnerLeft ]
long getInnerLeft() const;
/// @brief [ @b MUIA_InnerRight ]
long getInnerRight() const;
/// @brief [ @b MUIA_InnerTop ]
long getInnerTop() const;
#ifdef MUIA_KnowsDisabled
/// @brief [ @b MUIA_KnowsDisabled ]
bool isKnowsDisabled() const;
#endif
/// @brief [ @b MUIA_LeftEdge ]
long getLeftEdge() const;
#ifdef MUIA_PointerType
/// @brief [ @b MUIA_PointerType ]
enum PointerType getPointerType() const;
#endif
/// @brief [ @b MUIA_Pressed ]
bool isPressed() const;
/// @brief [ @b MUIA_RightEdge ]
long getRightEdge() const;
/// @brief [ @b MUIA_Selected ]
bool isSelected() const;
/// @brief [ @b MUIA_ShortHelp ]
std::string getShortHelp() const;
/// @brief [ @b MUIA_ShowMe ]
bool isShowMe() const;
/// @brief [ @b MUIA_TextColor ]
unsigned long getTextColor() const;
/// @brief [ @b MUIA_Timer ]
long getTimer() const;
/// @brief [ @b MUIA_TopEdge ]
long getTopEdge() const;
/// @brief [ @b MUIA_VertDisappear ]
long getVertDisappear() const;
/// @brief [ @b MUIA_VertWeight ]
short getVertWeight() const;
/// @brief [ @b MUIA_Width ]
long getWidth() const;
/// @brief [ @b MUIA_Window ]
Window *getWindow() const;
/// @brief [ @b MUIA_WindowObject ]
Object *getWindowObject() const;
/// @brief [ @b MUIA_Background ]
Area &setBackground(const enum ImageOrBackground background);
/// @brief [ @b MUIA_Background ]
/// The string is copied and stored internally by this C++ wrapper!
Area &setBackground(const std::string &background);
/// @brief [ @b MUIA_CycleChain ]
/// Keyboard cycle chain system. Set MUIA_CycleChain to 1 for every object that you want to have in your chain, MUI does the rest
/// automatically.
Area &setCycleChain(const long cycleChain = 1);
/// @brief [ @b MUIA_Disabled ]
Area &setDisabled(const bool disabled);
/// @brief [ @b MUIA_FillArea ]
Area &setFillArea(const bool fillArea);
/// @brief [ @b MUIA_Floating ]
Area &setFloating(const bool floating);
/// @brief [ @b MUIA_Font ] - seems that setting font doesn't work (at least for MUI::Floattext)
Area &setFont(const enum Font font);
/// @brief [ @b MUIA_HorizWeight ]
Area &setHorizWeight(const short horizWeight);
#ifdef MUIA_PointerType
/// @brief [ @b MUIA_PointerType ]
Area &setPointerType(const enum PointerType pointerType);
#endif
/// @brief [ @b MUIA_Selected ]
Area &setSelected(const bool selected);
/// @brief [ @b MUIA_ShortHelp ]
Area &setShortHelp(const std::string &shortHelp);
/// @brief [ @b MUIA_ShowMe ]
Area &setShowMe(const bool showMe);
/// @brief [ @b MUIA_VertWeight ]
Area &setVertWeight(const short vertWeight);
/// @brief [ @b MUIA_Weight ]
/// An object with a weight of 0 will always stay at its minimum size. By default, all objects have a weight of 100.
/// @param weight short weight of object, for negative value is ignored
Area &setWeight(const short weight);
// methods, some returns object reference
/// @brief setDisabled(false)
Area &Enable();
/// @brief setDisabled(true)
Area &Disable();
/// @brief [ @b MUIM_Cleanup /* Custom Class */ ]
Area &Cleanup();
/// @brief [ @b MUIM_Hide /* Custom Class */ ]
Area &Hide();
/// @brief [ @b MUIM_Show /* Custom Class */ ]
Area &Show(struct LongRect *clip);
/// @brief [ @b MUIM_Relayout, flags = 0 ] Perform a full relayout of the object in case it is visible. Actually the object will be
/// completely hidden and shown again to trigger a full redraw as well.
Area &Relayout();
#ifdef MUIM_Text
/// @brief [ @b MUIM_Text ] This function is a preferred way to render text inside the object. It uses the object's font and it's
/// color (if not specified in the string itself).
/// @param left rectangle to render the text into
/// @param top rectangle to render the text into
/// @param width rectangle to render the text into
/// @param height rectangle to render the text into
/// @param text the text to be rendered
/// @param len the number of characters to be respected, pass -1 to render the full string
/// @param preparse an optional preparse string, may be empty
/// @param ulchar character to be underlined (i.e. as shortcut), pass 0 for no underlining
Area &Text(const long left, const long top, const long width, const long height, const std::string &text, const long len,
const std::string &preparse, const char ulchar = 0);
#endif
#ifndef __MORPHOS__
/// @brief [ @b MUIM_TextDim ] Use this function to measure the area which will be required to render a text of the given length.
/// All facilities of MUI's text engine are allowed for both the text and the preparse string. Refer to MUIA_Text_Contents for all
/// possible sequences.
/// @param text the text to be measured
/// @param len the number of characters to be respected, pass -1 to measure the full string
/// @param preparse an optional preparse string, may be empty
/// @param flags currently unused, by default 0
/// @return the calculated width and height of the text string
Dim TextDim(const std::string &text, const long len, const std::string &preparse, const long flags = 0);
#endif
};
template <typename T, typename U> class AreaBuilderTemplate : public NotifyBuilderTemplate<T, U>
{
public:
AreaBuilderTemplate(const std::string &uniqueId = MUI::EmptyUniqueId, const std::string &muiClassName = MUIC_Area)
: NotifyBuilderTemplate<T, U>(uniqueId, muiClassName)
{
}
/// @brief [ @b MUIA_Background ]
T &tagBackground(const enum ImageOrBackground background);
/// @brief [ @b MUIA_Background ]
/// The string is copied and stored internally by this C++ wrapper!
T &tagBackground(const std::string &background);
/// @brief [ @b MUIA_Background ]
/// The string is copied and stored internally by this C++ wrapper!
T &tagBackground(const char *background);
/// @brief [ @b MUIA_CycleChain ]
/// Keyboard cycle chain system. Set MUIA_CycleChain to 1 for every object that you want to have in your chain, MUI does the rest
/// automatically.
T &tagCycleChain(const long cycleChain = 1);
/// @brief [ @b MUIA_Disabled ]
T &tagDisabled(const bool disabled = true);
/// @brief [ @b MUIA_FillArea ]
T &tagFillArea(const bool fillArea);
/// @brief [ @b MUIA_FixHeight ]
T &tagFixHeight(const long fixHeight);
/// @brief [ @b MUIA_FixHeightTxt ]
T &tagFixHeightTxt(const std::string &fixHeightTxt);
/// @brief [ @b MUIA_FixWidth ]
T &tagFixWidth(const long fixWidth);
/// @brief [ @b MUIA_FixWidthTxt ]
T &tagFixWidthTxt(const std::string &fixWidthTxt);
/// @brief [ @b MUIA_Floating ]
T &tagFloating(const bool floating);
/// @brief [ @b MUIA_Font] (for "struct TextFont *" should be separate method)
/// @param font enum Font
T &tagFont(const enum Font font);
/// @brief [ @b MUIA_Frame ]
/// @param frame enum Frame
T &tagFrame(const enum Frame frame);
/// @brief [ @b MUIA_FrameDynamic ]
T &tagDynamic(const bool dynamic);
/// @brief [ @b MUIA_FramePhantomHoriz ]
T &tagPhantomHoriz(const bool phantomHoriz);
/// @brief [ @b MUIA_FrameTitle ]
T &tagFrameTitle(const std::string &frameTitle);
/// @brief [ @b MUIA_HorizWeight ]
T &tagHorizWeight(const short horizWeight);
/// @brief [ @b MUIA_InputMode ]
/// @param inputMode enum InputMode
T &tagInputMode(const enum InputMode inputMode);
#ifdef MUIA_PointerType
/// @brief [ @b MUIA_PointerType ]
/// @param font enum PointerType
T &tagPointerType(const enum PointerType pointerType);
#endif
/// @brief [ @b MUIA_Selected ]
T &tagSelected(const bool selected);
/// @brief [ @b MUIA_ShowMe ]
T &tagShowMe(const bool showMe);
/// @brief [ @b MUIA_ShortHelp ] Specify a string that is to be used as bubble help for this object.
/// @param shortHelp help text, if empty then is ignored, not added to tag list
T &tagShortHelp(const std::string &shortHelp);
/// @brief [ @b MUIA_ShowSelState ]
T &tagShowSelState(const bool showSelState);
/// @brief [ @b MUIA_VertWeight ]
T &tagVertWeight(const short vertWeight);
/// @brief [ @b MUIA_Weight ]
/// An object with a weight of 0 will always stay at its minimum size. By default, all objects have a weight of 100.
/// @param weight short weight of object, for negative value is ignored
T &tagWeight(const short weight);
};
class AreaBuilder : public AreaBuilderTemplate<AreaBuilder, Area>
{
public:
AreaBuilder();
};
template <typename T, typename U> T &AreaBuilderTemplate<T, U>::tagBackground(const enum ImageOrBackground background)
{
this->PushTag(MUIA_Background, (long)background);
return (T &)*this;
}
template <typename T, typename U> T &AreaBuilderTemplate<T, U>::tagBackground(const std::string &background)
{
this->PushTag(MUIA_Background, this->StoreString(MUIA_Background, background));
return (T &)*this;
}
template <typename T, typename U> inline T &AreaBuilderTemplate<T, U>::tagBackground(const char *background)
{
this->PushTag(MUIA_Background, this->StoreString(MUIA_Background, background));
return (T &)*this;
}
template <typename T, typename U> inline T &AreaBuilderTemplate<T, U>::tagCycleChain(const long cycleChain)
{
this->PushTag(MUIA_CycleChain, cycleChain);
return (T &)*this;
}
template <typename T, typename U> inline T &AreaBuilderTemplate<T, U>::tagDisabled(const bool disabled)
{
this->PushTag(MUIA_Disabled, disabled);
return (T &)*this;
}
template <typename T, typename U> inline T &AreaBuilderTemplate<T, U>::tagFillArea(const bool fillArea)
{
this->PushTag(MUIA_FillArea, fillArea);
return (T &)*this;
}
template <typename T, typename U> inline T &AreaBuilderTemplate<T, U>::tagFixHeight(const long fixHeight)
{
this->PushTag(MUIA_FixHeight, fixHeight);
return (T &)*this;
}
template <typename T, typename U> inline T &AreaBuilderTemplate<T, U>::tagFixHeightTxt(const std::string &fixHeightTxt)
{
if (!fixHeightTxt.empty()) // no fixed height when empty string
this->PushTag(MUIA_FixHeightTxt, fixHeightTxt);
return (T &)*this;
}
template <typename T, typename U> inline T &AreaBuilderTemplate<T, U>::tagFixWidth(const long fixWidth)
{
this->PushTag(MUIA_FixWidth, fixWidth);
return (T &)*this;
}
template <typename T, typename U> inline T &AreaBuilderTemplate<T, U>::tagFixWidthTxt(const std::string &fixWidthTxt)
{
if (!fixWidthTxt.empty()) // no fixed width when empty string
this->PushTag(MUIA_FixWidthTxt, fixWidthTxt);
return (T &)*this;
}
template <typename T, typename U> inline T &AreaBuilderTemplate<T, U>::tagFloating(const bool floating)
{
this->PushTag(MUIA_Floating, floating);
return (T &)*this;
}
template <typename T, typename U> inline T &AreaBuilderTemplate<T, U>::tagFont(const enum Font font)
{
this->PushTag(MUIA_Font, (long)font);
return (T &)*this;
}
template <typename T, typename U> inline T &AreaBuilderTemplate<T, U>::tagFrame(const enum Frame frame)
{
this->PushTag(MUIA_Frame, (long)frame);
return (T &)*this;
}
template <typename T, typename U> inline T &AreaBuilderTemplate<T, U>::tagDynamic(const bool dynamic)
{
this->PushTag(MUIA_FrameDynamic, dynamic);
return (T &)*this;
}
template <typename T, typename U> inline T &AreaBuilderTemplate<T, U>::tagPhantomHoriz(const bool phantomHoriz)
{
this->PushTag(MUIA_FramePhantomHoriz, phantomHoriz);
return (T &)*this;
}
template <typename T, typename U> T &AreaBuilderTemplate<T, U>::tagFrameTitle(const std::string &frameTitle)
{
this->PushTag(MUIA_FrameTitle, frameTitle);
return (T &)*this;
}
template <typename T, typename U> inline T &AreaBuilderTemplate<T, U>::tagHorizWeight(const short horizWeight)
{
if (horizWeight >= 0)
this->PushTag(MUIA_HorizWeight, (long)horizWeight);
return (T &)*this;
}
template <typename T, typename U> inline T &AreaBuilderTemplate<T, U>::tagInputMode(const enum InputMode inputMode)
{
this->PushTag(MUIA_InputMode, (long)inputMode);
return (T &)*this;
}
#ifdef MUIA_PointerType
template <typename T, typename U> inline T &AreaBuilderTemplate<T, U>::tagPointerType(const enum PointerType pointerType)
{
this->PushTag(MUIA_PointerType, (long)pointerType);
return (T &)*this;
}
#endif
template <typename T, typename U> inline T &AreaBuilderTemplate<T, U>::tagSelected(const bool selected)
{
this->PushTag(MUIA_Selected, selected);
return (T &)*this;
}
template <typename T, typename U> inline T &AreaBuilderTemplate<T, U>::tagShowMe(const bool showMe)
{
this->PushTag(MUIA_ShowMe, showMe);
return (T &)*this;
}
template <typename T, typename U> inline T &AreaBuilderTemplate<T, U>::tagShortHelp(const std::string &shortHelp)
{
if (!shortHelp.empty())
{
auto copy = this->StoreString(MUIA_ShortHelp, shortHelp);
this->PushTag(MUIA_ShortHelp, copy);
}
return (T &)*this;
}
template <typename T, typename U> inline T &AreaBuilderTemplate<T, U>::tagShowSelState(const bool showSelState)
{
this->PushTag(MUIA_ShowSelState, showSelState);
return (T &)*this;
}
template <typename T, typename U> inline T &AreaBuilderTemplate<T, U>::tagVertWeight(const short vertWeight)
{
if (vertWeight >= 0)
this->PushTag(MUIA_VertWeight, (long)vertWeight);
return (T &)*this;
}
template <typename T, typename U> inline T &AreaBuilderTemplate<T, U>::tagWeight(const short weight)
{
if (weight >= 0)
this->PushTag(MUIA_Weight, (long)weight);
return (T &)*this;
}
}