Debian Codegraph @

phoenix/core/core.hpp

raw
1 #include <nall/platform.hpp>
2 #include <nall/config.hpp>
3 #include <nall/directory.hpp>
4 #include <nall/function.hpp>
5 #include <nall/group.hpp>
6 #include <nall/image.hpp>
7 #include <nall/map.hpp>
8 #include <nall/stdint.hpp>
9 #include <nall/string.hpp>
10 #include <nall/utility.hpp>
11 #include <nall/vector.hpp>
12
13 namespace phoenix {
14
15 struct Application;
16 struct Font;
17 struct Window;
18 struct Menu;
19 struct Sizable;
20 struct Layout;
21 struct Widget;
22
23 struct pApplication;
24 struct pFont;
25 struct pObject;
26 struct pTimer;
27 struct pWindow;
28 struct pAction;
29 struct pMenu;
30 struct pSeparator;
31 struct pItem;
32 struct pCheckItem;
33 struct pRadioItem;
34 struct pSizable;
35 struct pLayout;
36 struct pWidget;
37 struct pButton;
38 struct pCanvas;
39 struct pCheckButton;
40 struct pCheckLabel;
41 struct pComboButton;
42 struct pConsole;
43 struct pFrame;
44 struct pHexEdit;
45 struct pHorizontalScroller;
46 struct pHorizontalSlider;
47 struct pLabel;
48 struct pLineEdit;
49 struct pListView;
50 struct pProgressBar;
51 struct pRadioButton;
52 struct pRadioLabel;
53 struct pTabFrame;
54 struct pTextEdit;
55 struct pVerticalScroller;
56 struct pVerticalSlider;
57 struct pViewport;
58
59 struct Application {
60 static nall::function<void ()> main;
61
62 static void run();
63 static bool pendingEvents();
64 static void processEvents();
65 static void quit();
66 static void setName(const nall::string& name);
67
68 Application() = delete;
69 struct State;
70 static void initialize();
71
72 struct Windows {
73 static nall::function<void ()> onModalBegin;
74 static nall::function<void ()> onModalEnd;
75 };
76
77 struct Cocoa {
78 static nall::function<void ()> onAbout;
79 static nall::function<void ()> onActivate;
80 static nall::function<void ()> onPreferences;
81 static nall::function<void ()> onQuit;
82 };
83 };
84
85 struct Color {
86 uint8_t red, green, blue, alpha;
87 uint32_t rgb() const;
88 uint32_t argb() const;
89 inline Color() : alpha(255), red(0), green(0), blue(0) {}
90 inline Color(uint8_t red, uint8_t green, uint8_t blue) : alpha(255), red(red), green(green), blue(blue) {}
91 inline Color(uint8_t alpha, uint8_t red, uint8_t green, uint8_t blue) : alpha(alpha), red(red), green(green), blue(blue) {}
92 };
93
94 struct Position {
95 signed x, y;
96 inline Position() : x(0), y(0) {}
97 template<typename X, typename Y> inline Position(X x, Y y) : x(x), y(y) {}
98 };
99
100 struct Size {
101 static const unsigned Maximum = ~0u;
102 static const unsigned Minimum = 0u;
103
104 unsigned width, height;
105 inline Size() : width(0), height(0) {}
106 template<typename W, typename H> inline Size(W width, H height) : width(width), height(height) {}
107 };
108
109 struct Geometry {
110 signed x, y;
111 unsigned width, height;
112 Position position() const;
113 Size size() const;
114 nall::string text() const;
115 inline Geometry() : x(0), y(0), width(0), height(0) {}
116 inline Geometry(Position position, Size size) : x(position.x), y(position.y), width(size.width), height(size.height) {}
117 template<typename X, typename Y, typename W, typename H> inline Geometry(X x, Y y, W width, H height) : x(x), y(y), width(width), height(height) {}
118 Geometry(const nall::string& text);
119 };
120
121 enum class Orientation : unsigned { Horizontal, Vertical };
122
123 struct Font {
124 static nall::string serif(unsigned size = 0, const nall::string& style = "");
125 static nall::string sans(unsigned size = 0, const nall::string& style = "");
126 static nall::string monospace(unsigned size = 0, const nall::string& style = "");
127 static Size size(const nall::string& font, const nall::string& text);
128 Font() = delete;
129 };
130
131 struct Desktop {
132 static Size size();
133 static Geometry workspace();
134 Desktop() = delete;
135 };
136
137 struct Monitor {
138 static unsigned count();
139 static Geometry geometry(unsigned monitor);
140 static unsigned primary();
141 };
142
143 struct Keyboard {
144 #include "keyboard.hpp"
145 static bool pressed(Scancode scancode);
146 static bool released(Scancode scancode);
147 static nall::vector<bool> state();
148 Keyboard() = delete;
149 };
150
151 struct Mouse {
152 enum class Button : unsigned { Left, Middle, Right };
153 static Position position();
154 static bool pressed(Button);
155 static bool released(Button);
156 Mouse() = delete;
157 };
158
159 struct BrowserWindow {
160 nall::string directory();
161 nall::string open();
162 nall::string save();
163 BrowserWindow& setFilters(const nall::lstring& filters);
164 BrowserWindow& setParent(Window& parent);
165 BrowserWindow& setPath(const nall::string& path);
166 BrowserWindow& setTitle(const nall::string& title);
167
168 BrowserWindow();
169 ~BrowserWindow();
170 struct State;
171 State& state;
172 };
173
174 struct MessageWindow {
175 enum class Buttons : unsigned {
176 Ok,
177 OkCancel,
178 YesNo,
179 YesNoCancel,
180 };
181
182 enum class Response : unsigned {
183 Ok,
184 Cancel,
185 Yes,
186 No,
187 };
188
189 Response error(Buttons = Buttons::Ok);
190 Response information(Buttons = Buttons::Ok);
191 Response question(Buttons = Buttons::YesNo);
192 MessageWindow& setParent(Window& parent);
193 MessageWindow& setText(const nall::string& text);
194 MessageWindow& setTitle(const nall::string& title);
195 Response warning(Buttons = Buttons::Ok);
196
197 MessageWindow(const nall::string& text = "");
198 ~MessageWindow();
199 struct State;
200 State& state;
201 };
202
203 struct Object {
204 Object(pObject& p);
205 Object& operator=(const Object&) = delete;
206 Object(const Object&) = delete;
207 virtual ~Object();
208 pObject& p;
209 };
210
211 struct Timer : private nall::base_from_member<pTimer&>, Object {
212 nall::function<void ()> onActivate;
213
214 bool enabled() const;
215 unsigned interval() const;
216 void setEnabled(bool enabled = true);
217 void setInterval(unsigned interval); //in milliseconds
218
219 Timer();
220 ~Timer();
221 struct State;
222 State& state;
223 pTimer& p;
224 };
225
226 struct Window : private nall::base_from_member<pWindow&>, Object {
227 nall::function<void ()> onClose;
228 nall::function<void (nall::lstring)> onDrop;
229 nall::function<void (Keyboard::Keycode)> onKeyPress;
230 nall::function<void (Keyboard::Keycode)> onKeyRelease;
231 nall::function<void ()> onMove;
232 nall::function<void ()> onSize;
233
234 void append(Layout& layout);
235 void append(Menu& menu);
236 void append(Widget& widget);
237 Color backgroundColor() const;
238 bool droppable() const;
239 Geometry frameGeometry();
240 Geometry frameMargin();
241 bool focused();
242 bool fullScreen() const;
243 Geometry geometry();
244 nall::string menuFont() const;
245 bool menuVisible() const;
246 bool modal() const;
247 void remove(Layout& layout);
248 void remove(Menu& menu);
249 void remove(Widget& widget);
250 bool resizable() const;
251 void setBackgroundColor(Color color);
252 void setDroppable(bool droppable = true);
253 void setFrameGeometry(Geometry geometry);
254 void setFocused();
255 void setFullScreen(bool fullScreen = true);
256 void setGeometry(Geometry geometry);
257 void setMenuFont(const nall::string& font);
258 void setMenuVisible(bool visible = true);
259 void setModal(bool modal = true);
260 void setResizable(bool resizable = true);
261 void setStatusFont(const nall::string& font);
262 void setStatusText(const nall::string& text);
263 void setStatusVisible(bool visible = true);
264 void setTitle(const nall::string& text);
265 void setVisible(bool visible = true);
266 void setWidgetFont(const nall::string& font);
267 void setWindowGeometry(Geometry geometry);
268 nall::string statusFont() const;
269 nall::string statusText() const;
270 bool statusVisible() const;
271 void synchronizeLayout();
272 nall::string title() const;
273 bool visible() const;
274 nall::string widgetFont() const;
275
276 Window();
277 ~Window();
278 struct State;
279 State& state;
280 pWindow& p;
281 };
282
283 struct Action : Object {
284 bool enabled() const;
285 void setEnabled(bool enabled = true);
286 void setVisible(bool visible = true);
287 bool visible() const;
288
289 Action(pAction& p);
290 ~Action();
291 struct State;
292 State& state;
293 pAction& p;
294 };
295
296 struct Menu : private nall::base_from_member<pMenu&>, Action {
297 void append(const nall::group<Action>& list);
298 nall::image image() const;
299 void remove(const nall::group<Action>& list);
300 void setImage(const nall::image& image = nall::image{});
301 void setText(const nall::string& text);
302 nall::string text() const;
303
304 Menu();
305 ~Menu();
306 struct State;
307 State& state;
308 pMenu& p;
309 };
310
311 struct Separator : private nall::base_from_member<pSeparator&>, Action {
312 Separator();
313 ~Separator();
314 pSeparator& p;
315 };
316
317 struct Item : private nall::base_from_member<pItem&>, Action {
318 nall::function<void ()> onActivate;
319
320 nall::image image() const;
321 void setImage(const nall::image& image = nall::image{});
322 void setText(const nall::string& text);
323 nall::string text() const;
324
325 Item();
326 ~Item();
327 struct State;
328 State& state;
329 pItem& p;
330 };
331
332 struct CheckItem : private nall::base_from_member<pCheckItem&>, Action {
333 nall::function<void ()> onToggle;
334
335 bool checked() const;
336 void setChecked(bool checked = true);
337 void setText(const nall::string& text);
338 nall::string text() const;
339
340 CheckItem();
341 ~CheckItem();
342 struct State;
343 State& state;
344 pCheckItem& p;
345 };
346
347 struct RadioItem : private nall::base_from_member<pRadioItem&>, Action {
348 template<typename... Args> static void group(Args&&... args) { group({std::forward<Args>(args)...}); }
349 static void group(const nall::group<RadioItem>& list);
350
351 nall::function<void ()> onActivate;
352
353 bool checked() const;
354 void setChecked();
355 void setText(const nall::string& text);
356 nall::string text() const;
357
358 RadioItem();
359 ~RadioItem();
360 struct State;
361 State& state;
362 pRadioItem& p;
363 };
364
365 struct Sizable : Object {
366 bool enabled() const;
367 bool enabledToAll() const;
368 Layout* layout() const;
369 virtual Size minimumSize() = 0;
370 Sizable* parent() const;
371 virtual void setEnabled(bool enabled = true) = 0;
372 virtual void setGeometry(Geometry geometry) = 0;
373 virtual void setVisible(bool visible = true) = 0;
374 virtual void synchronizeLayout() = 0;
375 bool visible() const;
376 bool visibleToAll() const;
377 Window* window() const;
378
379 Sizable(pSizable& p);
380 ~Sizable();
381 struct State;
382 State& state;
383 pSizable& p;
384 };
385
386 struct Layout : private nall::base_from_member<pLayout&>, Sizable {
387 virtual void append(Sizable& sizable);
388 virtual void remove(Sizable& sizable);
389 virtual void reset();
390
391 Layout();
392 Layout(pLayout& p);
393 ~Layout();
394 struct State;
395 State& state;
396 pLayout& p;
397 };
398
399 struct Widget : private nall::base_from_member<pWidget&>, Sizable {
400 nall::function<void ()> onSize;
401
402 bool focused();
403 nall::string font() const;
404 Geometry geometry() const;
405 Size minimumSize();
406 void setEnabled(bool enabled = true);
407 void setFocused();
408 void setFont(const nall::string& font);
409 void setGeometry(Geometry geometry);
410 void setVisible(bool visible = true);
411 void synchronizeLayout();
412
413 Widget();
414 Widget(pWidget& p);
415 ~Widget();
416 struct State;
417 State& state;
418 pWidget& p;
419 };
420
421 struct Button : private nall::base_from_member<pButton&>, Widget {
422 nall::function<void ()> onActivate;
423
424 nall::image image() const;
425 Orientation orientation() const;
426 void setImage(const nall::image& image = nall::image{}, Orientation orientation = Orientation::Horizontal);
427 void setText(const nall::string& text);
428 nall::string text() const;
429
430 Button();
431 ~Button();
432 struct State;
433 State& state;
434 pButton& p;
435 };
436
437 struct Canvas : private nall::base_from_member<pCanvas&>, Widget {
438 enum class Mode : unsigned { Color, Gradient, Image, Data };
439
440 nall::function<void (nall::lstring)> onDrop;
441 nall::function<void ()> onMouseLeave;
442 nall::function<void (Position)> onMouseMove;
443 nall::function<void (Mouse::Button)> onMousePress;
444 nall::function<void (Mouse::Button)> onMouseRelease;
445
446 Color color() const;
447 uint32_t* data() const;
448 bool droppable() const;
449 nall::vector<Color> gradient() const;
450 nall::image image() const;
451 Mode mode() const;
452 void setColor(Color color);
453 void setData();
454 void setDroppable(bool droppable = true);
455 void setHorizontalGradient(Color left, Color right);
456 void setGradient(Color topLeft, Color topRight, Color bottomLeft, Color bottomRight);
457 void setImage(const nall::image& image);
458 void setMode(Mode mode);
459 void setSize(Size size);
460 void setVerticalGradient(Color top, Color bottom);
461 Size size() const;
462
463 Canvas();
464 ~Canvas();
465 struct State;
466 State& state;
467 pCanvas& p;
468 };
469
470 struct CheckButton : private nall::base_from_member<pCheckButton&>, Widget {
471 nall::function<void ()> onToggle;
472
473 bool checked() const;
474 nall::image image() const;
475 void setChecked(bool checked = true);
476 void setImage(const nall::image& image = nall::image{}, Orientation orientation = Orientation::Horizontal);
477 void setText(const nall::string& text);
478 nall::string text() const;
479
480 CheckButton();
481 ~CheckButton();
482 struct State;
483 State& state;
484 pCheckButton& p;
485 };
486
487 struct CheckLabel : private nall::base_from_member<pCheckLabel&>, Widget {
488 nall::function<void ()> onToggle;
489
490 bool checked() const;
491 void setChecked(bool checked = true);
492 void setText(const nall::string& text);
493 nall::string text() const;
494
495 CheckLabel();
496 ~CheckLabel();
497 struct State;
498 State& state;
499 pCheckLabel& p;
500 };
501
502 struct ComboButton : private nall::base_from_member<pComboButton&>, Widget {
503 nall::function<void ()> onChange;
504
505 void append(const nall::string& text = "");
506 void remove(unsigned selection);
507 void reset();
508 unsigned rows() const;
509 unsigned selection() const;
510 void setSelection(unsigned selection);
511 void setText(unsigned selection, const nall::string& text);
512 nall::string text() const;
513 nall::string text(unsigned selection) const;
514
515 ComboButton();
516 ~ComboButton();
517 struct State;
518 State& state;
519 pComboButton& p;
520 };
521
522 struct Console : private nall::base_from_member<pConsole&>, Widget {
523 nall::function<void (nall::string)> onActivate;
524
525 template<typename... Args> void print(Args&&... args) { print({args...}); }
526
527 void print(const nall::string& text);
528 void reset();
529
530 Console();
531 ~Console();
532 struct State;
533 State& state;
534 pConsole& p;
535 };
536
537 struct Frame : private nall::base_from_member<pFrame&>, Widget {
538 void setLayout(Layout& layout);
539 void setText(const nall::string& text);
540 void synchronizeLayout();
541 nall::string text() const;
542
543 Frame();
544 ~Frame();
545 struct State;
546 State& state;
547 pFrame& p;
548 };
549
550 struct HexEdit : private nall::base_from_member<pHexEdit&>, Widget {
551 nall::function<uint8_t (unsigned)> onRead;
552 nall::function<void (unsigned, uint8_t)> onWrite;
553
554 unsigned columns() const;
555 unsigned length() const;
556 unsigned offset() const;
557 unsigned rows() const;
558 void setColumns(unsigned columns);
559 void setLength(unsigned length);
560 void setOffset(unsigned offset);
561 void setRows(unsigned rows);
562 void update();
563
564 HexEdit();
565 ~HexEdit();
566 struct State;
567 State& state;
568 pHexEdit& p;
569 };
570
571 struct HorizontalScroller : private nall::base_from_member<pHorizontalScroller&>, Widget {
572 nall::function<void ()> onChange;
573
574 unsigned length() const;
575 unsigned position() const;
576 void setLength(unsigned length);
577 void setPosition(unsigned position);
578
579 HorizontalScroller();
580 ~HorizontalScroller();
581 struct State;
582 State& state;
583 pHorizontalScroller& p;
584 };
585
586 struct HorizontalSlider : private nall::base_from_member<pHorizontalSlider&>, Widget {
587 nall::function<void ()> onChange;
588
589 unsigned length() const;
590 unsigned position() const;
591 void setLength(unsigned length);
592 void setPosition(unsigned position);
593
594 HorizontalSlider();
595 ~HorizontalSlider();
596 struct State;
597 State& state;
598 pHorizontalSlider& p;
599 };
600
601 struct Label : private nall::base_from_member<pLabel&>, Widget {
602 void setText(const nall::string& text);
603 nall::string text() const;
604
605 Label();
606 ~Label();
607 struct State;
608 State& state;
609 pLabel& p;
610 };
611
612 struct LineEdit : private nall::base_from_member<pLineEdit&>, Widget {
613 nall::function<void ()> onActivate;
614 nall::function<void ()> onChange;
615
616 bool editable() const;
617 void setEditable(bool editable = true);
618 void setText(const nall::string& text);
619 nall::string text();
620
621 LineEdit();
622 ~LineEdit();
623 struct State;
624 State& state;
625 pLineEdit& p;
626 };
627
628 struct ListView : private nall::base_from_member<pListView&>, Widget {
629 nall::function<void ()> onActivate;
630 nall::function<void ()> onChange;
631 nall::function<void (unsigned)> onToggle;
632
633 void append(const nall::lstring& text);
634 void autoSizeColumns();
635 bool checkable() const;
636 bool checked(unsigned selection) const;
637 unsigned columns() const;
638 bool headerVisible() const;
639 nall::image image(unsigned selection, unsigned position) const;
640 void remove(unsigned selection);
641 void reset();
642 unsigned rows() const;
643 bool selected() const;
644 unsigned selection() const;
645 void setCheckable(bool checkable = true);
646 void setChecked(unsigned selection, bool checked = true);
647 void setHeaderText(const nall::lstring& text);
648 void setHeaderVisible(bool visible = true);
649 void setImage(unsigned selection, unsigned position, const nall::image& image = nall::image{});
650 void setSelected(bool selected = true);
651 void setSelection(unsigned selection);
652 void setText(unsigned selection, const nall::lstring& text);
653 void setText(unsigned selection, unsigned position, const nall::string& text);
654 nall::string text(unsigned selection, unsigned position) const;
655
656 ListView();
657 ~ListView();
658 struct State;
659 State& state;
660 pListView& p;
661 };
662
663 struct ProgressBar : private nall::base_from_member<pProgressBar&>, Widget {
664 unsigned position() const;
665 void setPosition(unsigned position);
666
667 ProgressBar();
668 ~ProgressBar();
669 struct State;
670 State& state;
671 pProgressBar& p;
672 };
673
674 struct RadioButton : private nall::base_from_member<pRadioButton&>, Widget {
675 template<typename... Args> static void group(Args&&... args) { group({std::forward<Args>(args)...}); }
676 static void group(const nall::group<RadioButton>& list);
677
678 nall::function<void ()> onActivate;
679
680 bool checked() const;
681 nall::image image() const;
682 void setChecked();
683 void setImage(const nall::image& image = nall::image{}, Orientation orientation = Orientation::Horizontal);
684 void setText(const nall::string& text);
685 nall::string text() const;
686
687 RadioButton();
688 ~RadioButton();
689 struct State;
690 State& state;
691 pRadioButton& p;
692 };
693
694 struct RadioLabel : private nall::base_from_member<pRadioLabel&>, Widget {
695 template<typename... Args> static void group(Args&&... args) { group({std::forward<Args>(args)...}); }
696 static void group(const nall::group<RadioLabel>& list);
697
698 nall::function<void ()> onActivate;
699
700 bool checked() const;
701 void setChecked();
702 void setText(const nall::string& text);
703 nall::string text() const;
704
705 RadioLabel();
706 ~RadioLabel();
707 struct State;
708 State& state;
709 pRadioLabel& p;
710 };
711
712 struct TabFrame : private nall::base_from_member<pTabFrame&>, Widget {
713 nall::function<void ()> onChange;
714
715 void append(const nall::string& text = "", const nall::image& image = nall::image{});
716 nall::image image(unsigned selection) const;
717 void remove(unsigned selection);
718 unsigned selection() const;
719 void setImage(unsigned selection, const nall::image& image = nall::image{});
720 void setLayout(unsigned selection, Layout& layout);
721 void setSelection(unsigned selection);
722 void setText(unsigned selection, const nall::string& text);
723 void synchronizeLayout();
724 unsigned tabs() const;
725 nall::string text(unsigned selection) const;
726
727 TabFrame();
728 ~TabFrame();
729 struct State;
730 State& state;
731 pTabFrame& p;
732 };
733
734 struct TextEdit : private nall::base_from_member<pTextEdit&>, Widget {
735 nall::function<void ()> onChange;
736
737 bool editable() const;
738 void setCursorPosition(unsigned position);
739 void setEditable(bool editable = true);
740 void setText(const nall::string& text);
741 void setWordWrap(bool wordWrap = true);
742 nall::string text();
743 bool wordWrap() const;
744
745 TextEdit();
746 ~TextEdit();
747 struct State;
748 State& state;
749 pTextEdit& p;
750 };
751
752 struct VerticalScroller : private nall::base_from_member<pVerticalScroller&>, Widget {
753 nall::function<void ()> onChange;
754
755 unsigned length() const;
756 unsigned position() const;
757 void setLength(unsigned length);
758 void setPosition(unsigned position);
759
760 VerticalScroller();
761 ~VerticalScroller();
762 struct State;
763 State& state;
764 pVerticalScroller& p;
765 };
766
767 struct VerticalSlider : private nall::base_from_member<pVerticalSlider&>, Widget {
768 nall::function<void ()> onChange;
769
770 unsigned length() const;
771 unsigned position() const;
772 void setLength(unsigned length);
773 void setPosition(unsigned position);
774
775 VerticalSlider();
776 ~VerticalSlider();
777 struct State;
778 State& state;
779 pVerticalSlider& p;
780 };
781
782 struct Viewport : private nall::base_from_member<pViewport&>, Widget {
783 nall::function<void (nall::lstring)> onDrop;
784 nall::function<void ()> onMouseLeave;
785 nall::function<void (Position)> onMouseMove;
786 nall::function<void (Mouse::Button)> onMousePress;
787 nall::function<void (Mouse::Button)> onMouseRelease;
788
789 bool droppable() const;
790 uintptr_t handle();
791 void setDroppable(bool droppable = true);
792
793 Viewport();
794 ~Viewport();
795 struct State;
796 State& state;
797 pViewport& p;
798 };
799
800 #include "layout/fixed-layout.hpp"
801 #include "layout/horizontal-layout.hpp"
802 #include "layout/vertical-layout.hpp"
803
804 }