FifeGUI 0.2.0
A C++ GUI library designed for games.
widget.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause
2// SPDX-FileCopyrightText: 2004 - 2008 Olof Naessén and Per Larsson
3// SPDX-FileCopyrightText: 2013 - 2026 Fifengine contributors
4
5#include "fifechan/widget.hpp"
6
7#include <algorithm>
8#include <iostream>
9#include <list>
10#include <ranges>
11#include <string>
12
13#include "fifechan/actionevent.hpp"
14#include "fifechan/actionlistener.hpp"
15#include "fifechan/deathlistener.hpp"
16#include "fifechan/defaultfont.hpp"
17#include "fifechan/event.hpp"
18#include "fifechan/exception.hpp"
19#include "fifechan/focushandler.hpp"
20#include "fifechan/graphics.hpp"
21#include "fifechan/keylistener.hpp"
22#include "fifechan/mouselistener.hpp"
23#include "fifechan/rectangle.hpp"
24#include "fifechan/size.hpp"
25#include "fifechan/visibilityeventhandler.hpp"
26#include "fifechan/widgetlistener.hpp"
27
28namespace fcn
29{
30 Font* Widget::mGlobalFont = nullptr;
32 std::list<Widget*> Widget::mWidgetInstances;
35
37 {
38 mWidgetInstances.push_back(this);
39 }
40
41 Widget::~Widget()
42 {
43 // We're in a destructor, we can't throw.
44 // We can only catch and print the error message.
45 try {
46
47 if (mParent != nullptr) {
48 mParent->remove(this);
49 }
50
51 std::list<Widget*>::const_iterator childrenIter;
52 for (childrenIter = mChildren.begin(); childrenIter != mChildren.end(); ++childrenIter) {
53 (*childrenIter)->_setParent(nullptr);
54 }
55
56 std::list<DeathListener*>::const_iterator deathIter;
57 for (deathIter = mDeathListeners.begin(); deathIter != mDeathListeners.end(); ++deathIter) {
58 Event const event(this);
59 (*deathIter)->death(event);
60 }
61
62 if (mGuiDeathListener != nullptr) {
63 Event const event(this);
64 mGuiDeathListener->death(event);
65 }
66
67 // Directly handle focus handler cleanup without virtual call
68 if (mFocusHandler != nullptr) {
70 if (mFocusHandler->getModalMouseInputFocused() == this) {
72 }
73 mFocusHandler->remove(this);
74 mFocusHandler = nullptr;
75 }
76
77 mWidgetInstances.remove(this);
78
79 } catch (fcn::Exception const & e) {
80 std::cerr << "Exception caught in Widget destructor: " << e.what() << '\n';
81 } catch (std::exception const & e) {
82 std::cerr << "Exception caught in Widget destructor: " << e.what() << '\n';
83 } catch (...) {
84 std::cerr << "Unknown exception caught in Widget destructor" << '\n';
85 }
86 }
87
89 {
90 Color const outlineColor = getOutlineColor();
91 Color highlightColor;
92 Color shadowColor;
93 int const alpha = getBaseColor().a;
94 int const width = getWidth() + (getOutlineSize() * 2) - 1;
95 int const height = getHeight() + (getOutlineSize() * 2) - 1;
96 highlightColor = outlineColor + 0x303030;
97 highlightColor.a = alpha;
98 shadowColor = outlineColor - 0x303030;
99 shadowColor.a = alpha;
100
101 for (unsigned int i = 0; i < getOutlineSize(); ++i) {
102 graphics->setColor(shadowColor);
103 graphics->drawLine(i, i, width - i, i);
104 graphics->drawLine(i, i + 1, i, height - i - 1);
105 graphics->setColor(highlightColor);
106 graphics->drawLine(width - i, i + 1, width - i, height - i);
107 graphics->drawLine(i, height - i, width - i - 1, height - i);
108 }
109 }
110
112 {
113 Color const borderColor = getBorderColor();
114 Color highlightColor;
115 Color shadowColor;
116 int const alpha = getBaseColor().a;
117 int const width = getWidth() - 1;
118 int const height = getHeight() - 1;
119
120 highlightColor = borderColor + 0x303030;
121 highlightColor.a = alpha;
122 shadowColor = borderColor - 0x303030;
123 shadowColor.a = alpha;
124
125 for (int i = 0; i < getBorderSize(); ++i) {
126 graphics->setColor(shadowColor);
127 graphics->drawLine(i, i, width - i, i);
128 graphics->drawLine(i, i + 1, i, height - i - 1);
129 graphics->setColor(highlightColor);
130 graphics->drawLine(width - i, i + 1, width - i, height - i);
131 graphics->drawLine(i, height - i, width - i - 1, height - i);
132 }
133 }
134
136 {
137 int const width = getWidth() - 1;
138 int const height = getHeight() - 1;
139 graphics->setColor(getSelectionColor());
140
141 // currently border size is used here too, not sure an extra frame size is really needed.
142 for (unsigned int i = 0; i < getBorderSize(); ++i) {
143 // would be better but causes problems with OpenGL
144 // graphics->drawRectangle(i, i, width - 2 * i, height - 2 * i);
145 graphics->drawLine(i, i, width - i, i);
146 graphics->drawLine(i, i + 1, i, height - i - 1);
147 graphics->drawLine(width - i, i + 1, width - i, height - i);
148 graphics->drawLine(i, height - i, width - i - 1, height - i);
149 }
150 }
151
153 {
154 mParent = parent;
155 }
156
158 {
159 return mParent;
160 }
161
162 void Widget::setWidth(int width)
163 {
164 Rectangle newDimension = mDimension;
165 newDimension.width = width;
166
167 setDimension(newDimension);
168 }
169
171 {
172 return mDimension.width;
173 }
174
175 void Widget::setHeight(int height)
176 {
177 Rectangle newDimension = mDimension;
178 newDimension.height = height;
179
180 setDimension(newDimension);
181 }
182
184 {
185 return mDimension.height;
186 }
187
188 void Widget::setX(int x)
189 {
190 Rectangle newDimension = mDimension;
191 newDimension.x = x;
192
193 setDimension(newDimension);
194 }
195
196 int Widget::getX() const
197 {
198 return mDimension.x;
199 }
200
201 void Widget::setY(int y)
202 {
203 Rectangle newDimension = mDimension;
204 newDimension.y = y;
205
206 setDimension(newDimension);
207 }
208
209 int Widget::getY() const
210 {
211 return mDimension.y;
212 }
213
214 void Widget::setPosition(int x, int y)
215 {
216 Rectangle newDimension = mDimension;
217 newDimension.x = x;
218 newDimension.y = y;
219
220 setDimension(newDimension);
221 }
222
223 void Widget::setDimension(Rectangle const & dimension)
224 {
225 Rectangle const oldDimension = mDimension;
226 mDimension = dimension;
227
228 if (mDimension.width != oldDimension.width || mDimension.height != oldDimension.height) {
230 if (mDimension.width != oldDimension.width || mDimension.height != oldDimension.height) {
232 }
233 }
234
235 if (mDimension.x != oldDimension.x || mDimension.y != oldDimension.y) {
237
238 auto currChild(mChildren.begin());
239 auto const endChildren(mChildren.end());
240
241 for (; currChild != endChildren; ++currChild) {
242 (*currChild)->distributeAncestorMovedEvent(this);
243 }
244 }
245 }
246
247 unsigned int Widget::getChildrenCount() const
248 {
249 unsigned int childs = 0;
250 auto currChild(mChildren.begin());
251 auto const endChildren(mChildren.end());
252 for (; currChild != endChildren; ++currChild) {
253 ++childs;
254 }
255 return childs;
256 }
257
259 {
260 unsigned int childs = 0;
261 auto currChild(mChildren.begin());
262 auto const endChildren(mChildren.end());
263 for (; currChild != endChildren; ++currChild) {
264 if (isVisible()) {
265 ++childs;
266 }
267 }
268 return childs;
269 }
270
271 void Widget::setMinSize(Size const & size)
272 {
273 mMinSize = size;
275 }
276
277 Size const & Widget::getMinSize() const
278 {
279 return mMinSize;
280 }
281
282 void Widget::setMaxSize(Size const & size)
283 {
284 mMaxSize = size;
286 }
287
288 Size const & Widget::getMaxSize() const
289 {
290 return mMaxSize;
291 }
292
293 void Widget::setFixedSize(Size const & size)
294 {
295 mFixedSize = size;
296 if (mFixedSize.getWidth() < 0 || mFixedSize.getHeight() < 0) {
297 mFixedSizeUsed = false;
298 } else {
299 mFixedSizeUsed = true;
301 }
302 }
303
305 {
306 return mFixedSize;
307 }
308
310 {
311 return mFixedSizeUsed;
312 }
313
315 {
316 if (mFixedSizeUsed) {
317 mDimension.width = mFixedSize.getWidth();
318 mDimension.height = mFixedSize.getHeight();
319 return;
320 }
321 int const minWidth = mMinSize.getWidth();
322 int const minHeight = mMinSize.getHeight();
323 int const maxWidth = mMaxSize.getWidth();
324 int const maxHeight = mMaxSize.getHeight();
325 int const currWidth = mDimension.width;
326 int const currHeight = mDimension.height;
327
328 mDimension.width = std::max(std::min(currWidth, maxWidth), minWidth);
329 mDimension.height = std::max(std::min(currHeight, maxHeight), minHeight);
330 }
331
333 {
334 mVExpand = expand;
335 }
336
338 {
339 return mVExpand;
340 }
341
343 {
344 mHExpand = expand;
345 }
346
348 {
349 return mHExpand;
350 }
351
352 void Widget::adaptLayout(bool top)
353 {
354 Widget* widget = this;
355 while ((widget->getParent() != nullptr) && top) {
356 Widget* parent = widget->getParent();
357 if (!parent->isLayouted()) {
358 break;
359 }
360 widget = parent;
361 }
362 widget->resizeToContent();
363 widget->expandContent();
364 }
365
366 void Widget::setOutlineSize(unsigned int size)
367 {
368 mOutlineSize = size;
369 }
370
371 unsigned int Widget::getOutlineSize() const
372 {
373 return mOutlineSize;
374 }
375
376 void Widget::setBorderSize(unsigned int size)
377 {
378 mBorderSize = size;
379 }
380
381 unsigned int Widget::getBorderSize() const
382 {
383 return mBorderSize;
384 }
385
386 void Widget::setMargin(int margin)
387 {
388 mMarginTop = margin;
389 mMarginRight = margin;
390 mMarginBottom = margin;
391 mMarginLeft = margin;
392 }
393
394 void Widget::setMarginTop(int margin)
395 {
396 mMarginTop = margin;
397 }
398
400 {
401 return mMarginTop;
402 }
403
404 void Widget::setMarginRight(int margin)
405 {
406 mMarginRight = margin;
407 }
408
410 {
411 return mMarginRight;
412 }
413
414 void Widget::setMarginBottom(int margin)
415 {
416 mMarginBottom = margin;
417 }
418
420 {
421 return mMarginBottom;
422 }
423
424 void Widget::setMarginLeft(int margin)
425 {
426 mMarginLeft = margin;
427 }
428
430 {
431 return mMarginLeft;
432 }
433
434 void Widget::setPadding(unsigned int padding)
435 {
436 mPaddingTop = padding;
437 mPaddingRight = padding;
438 mPaddingBottom = padding;
439 mPaddingLeft = padding;
440 }
441
442 void Widget::setPaddingTop(unsigned int padding)
443 {
444 mPaddingTop = padding;
445 }
446
447 unsigned int Widget::getPaddingTop() const
448 {
449 return mPaddingTop;
450 }
451
452 void Widget::setPaddingRight(unsigned int padding)
453 {
454 mPaddingRight = padding;
455 }
456
457 unsigned int Widget::getPaddingRight() const
458 {
459 return mPaddingRight;
460 }
461
462 void Widget::setPaddingBottom(unsigned int padding)
463 {
464 mPaddingBottom = padding;
465 }
466
467 unsigned int Widget::getPaddingBottom() const
468 {
469 return mPaddingBottom;
470 }
471
472 void Widget::setPaddingLeft(unsigned int padding)
473 {
474 mPaddingLeft = padding;
475 }
476
477 unsigned int Widget::getPaddingLeft() const
478 {
479 return mPaddingLeft;
480 }
481
483 {
484 return mDimension;
485 }
486
487 std::string const & Widget::getActionEventId() const
488 {
489 return mActionEventId;
490 }
491
492 void Widget::setActionEventId(std::string const & actionEventId)
493 {
494 mActionEventId = actionEventId;
495 }
496
497 bool Widget::isFocused() const
498 {
499 if (mFocusHandler == nullptr) {
500 return false;
501 }
502
503 return (mFocusHandler->isFocused(this));
504 }
505
506 void Widget::setFocusable(bool focusable)
507 {
508 if (!focusable && isFocused()) {
509 mFocusHandler->focusNone();
510 }
511
512 mFocusable = focusable;
513 }
514
516 {
517 return mFocusable && isVisible() && isEnabled();
518 }
519
521 {
522 if (mFocusHandler == nullptr) {
523 throwException("No focus handler is set (did you add the widget to the GUI?)");
524 }
525
526 if (isFocusable()) {
527 mFocusHandler->requestFocus(this);
528 }
529 }
530
532 {
533 if (mParent != nullptr) {
534 mParent->moveToTop(this);
535 }
536 }
537
539 {
540 if (mParent != nullptr) {
541 mParent->moveToBottom(this);
542 }
543 }
544
545 void Widget::setVisible(bool visible)
546 {
547 VisibilityEventHandler* visibilityEventHandler = _getVisibilityEventHandler();
548
549 if (!visible && isFocused()) {
550 mFocusHandler->focusNone();
551 }
552
553 if (visible) {
554 visibilityEventHandler->widgetShown(Event(this));
556
557 auto currChild(mChildren.begin());
558 auto const endChildren(mChildren.end());
559
560 for (; currChild != endChildren; ++currChild) {
561 (*currChild)->distributeAncestorShownEvent(this);
562 }
563 } else {
564 visibilityEventHandler->widgetHidden(Event(this));
566
567 auto currChild(mChildren.begin());
568 auto const endChildren(mChildren.end());
569
570 for (; currChild != endChildren; ++currChild) {
571 (*currChild)->distributeAncestorHiddenEvent(this);
572 }
573 }
574
575 mVisible = visible;
576 }
577
578 bool Widget::isVisible() const
579 {
580 if (getParent() == nullptr) {
581 return mVisible;
582 }
583 return mVisible && getParent()->isVisible();
584 }
585
587 {
588 return mVisible;
589 }
590
591 void Widget::setBaseColor(Color const & color)
592 {
593 mBaseColor = color;
594 }
595
597 {
598 return mBaseColor;
599 }
600
602 {
603 mForegroundColor = color;
604 }
605
607 {
608 return mForegroundColor;
609 }
610
612 {
613 mBackgroundColor = color;
614 }
615
617 {
618 return mBackgroundColor;
619 }
620
622 {
623 mSelectionColor = color;
624 }
625
627 {
628 return mSelectionColor;
629 }
630
631 void Widget::setOutlineColor(Color const & color)
632 {
633 mOutlineColor = color;
634 }
635
637 {
638 return mOutlineColor;
639 }
640
641 void Widget::setBorderColor(Color const & color)
642 {
643 mBorderColor = color;
644 }
645
647 {
648 return mBorderColor;
649 }
650
652 {
653 mSelectionMode = mode;
654 }
655
660
662 {
663 if (mFocusHandler != nullptr) {
665 if (mFocusHandler->getModalMouseInputFocused() == this) {
667 }
668 mFocusHandler->remove(this);
669 }
670
671 if (focusHandler != nullptr) {
672 focusHandler->add(this);
673 }
674
675 mFocusHandler = focusHandler;
676
677 if (mInternalFocusHandler != nullptr) {
678 return;
679 }
680
681 std::list<Widget*>::const_iterator iter;
682 for (iter = mChildren.begin(); iter != mChildren.end(); ++iter) {
683 if (widgetExists(*iter)) {
684 (*iter)->_setFocusHandler(focusHandler);
685 }
686 }
687 }
688
693
695 {
696 mVisibilityEventHandler = visibilityEventHandler;
697 }
698
703
705 {
706 mGuiDeathListener = deathListener;
707 }
708
713
715 {
716 mActionListeners.push_back(actionListener);
717 }
718
720 {
721 mActionListeners.remove(actionListener);
722 }
723
725 {
726 mDeathListeners.push_back(deathListener);
727 }
728
730 {
731 mDeathListeners.remove(deathListener);
732 }
733
735 {
736 mKeyListeners.push_back(keyListener);
737 }
738
740 {
741 mKeyListeners.remove(keyListener);
742 }
743
745 {
746 mFocusListeners.push_back(focusListener);
747 }
748
750 {
751 mFocusListeners.remove(focusListener);
752 }
753
755 {
756 mMouseListeners.push_back(mouseListener);
757 }
758
760 {
761 mMouseListeners.remove(mouseListener);
762 }
763
765 {
766 mWidgetListeners.push_back(widgetListener);
767 }
768
770 {
771 mWidgetListeners.remove(widgetListener);
772 }
773
774 void Widget::getAbsolutePosition(int& x, int& y) const
775 {
776 if (getParent() == nullptr) {
777 if (isLastPositionSet()) {
778 x = mLastX;
779 y = mLastY;
780 } else {
781 x = mDimension.x;
782 y = mDimension.y;
783 }
784 return;
785 }
786
787 int parentX = 0;
788 int parentY = 0;
789
790 getParent()->getAbsolutePosition(parentX, parentY);
791
792 x = parentX + mDimension.x + getParent()->getChildrenArea().x;
793 y = parentY + mDimension.y + getParent()->getChildrenArea().y;
794 }
795
797 {
798 if (mCurrentFont == nullptr) {
799 if (mGlobalFont == nullptr) {
800 return &mDefaultFont;
801 }
802
803 return mGlobalFont;
804 }
805
806 return mCurrentFont;
807 }
808
810 {
811 mGlobalFont = font;
812
813 std::list<Widget*>::iterator iter;
814 for (iter = mWidgetInstances.begin(); iter != mWidgetInstances.end(); ++iter) {
815 if ((*iter)->mCurrentFont == nullptr) {
816 (*iter)->fontChanged();
817 }
818 }
819 }
820
822 {
823 mCurrentFont = font;
824 fontChanged();
825 }
826
827 bool Widget::widgetExists(Widget const * widget)
828 {
829 auto iter = std::ranges::find_if(mWidgetInstances, [widget](Widget* w) {
830 return w == widget;
831 });
832 return iter != mWidgetInstances.end();
833 }
834
836 {
837 return mTabIn;
838 }
839
840 void Widget::setTabInEnabled(bool enabled)
841 {
842 mTabIn = enabled;
843 }
844
846 {
847 return mTabOut;
848 }
849
850 void Widget::setTabOutEnabled(bool enabled)
851 {
852 mTabOut = enabled;
853 }
854
855 void Widget::setSize(int width, int height)
856 {
857 Rectangle newDimension = mDimension;
858 newDimension.width = width;
859 newDimension.height = height;
860
861 setDimension(newDimension);
862 }
863
864 void Widget::setEnabled(bool enabled)
865 {
866 mEnabled = enabled;
867 }
868
869 bool Widget::isEnabled() const
870 {
871 return mEnabled && isVisible();
872 }
873
875 {
876 if (mFocusHandler == nullptr) {
877 throwException("No focus handler is set (did you add the widget to the GUI?)");
878 return false;
879 }
880 return mFocusHandler->getModalFocused() == nullptr;
881 }
882
884 {
885 if (mFocusHandler == nullptr) {
886 throwException("No focus handler is set (did you add the widget to the GUI?)");
887 return false;
888 }
889 return mFocusHandler->getModalMouseInputFocused() == nullptr;
890 }
891
893 {
894 if (mFocusHandler == nullptr) {
895 throwException("No focus handler is set (did you add the widget to the GUI?)");
896 }
897
898 mFocusHandler->requestModalFocus(this);
899 }
900
902 {
903 if (mFocusHandler == nullptr) {
904 throwException("No focus handler is set (did you add the widget to the GUI?)");
905 }
906
907 mFocusHandler->requestModalMouseInputFocus(this);
908 }
909
911 {
912 if (mFocusHandler == nullptr) {
913 return;
914 }
915
916 mFocusHandler->releaseModalFocus(this);
917 }
918
920 {
921 if (mFocusHandler == nullptr) {
922 return;
923 }
924
925 mFocusHandler->releaseModalMouseInputFocus(this);
926 }
927
929 {
930 if (mFocusHandler == nullptr) {
931 throwException("No focus handler is set (did you add the widget to the GUI?)");
932 }
933
934 if (getParent() != nullptr) {
935 return (mFocusHandler->getModalFocused() == this) || getParent()->isModalFocused();
936 }
937
938 return mFocusHandler->getModalFocused() == this;
939 }
940
942 {
943 if (mFocusHandler == nullptr) {
944 throwException("No focus handler is set (did you add the widget to the GUI?)");
945 }
946
947 if (getParent() != nullptr) {
948 return (mFocusHandler->getModalMouseInputFocused() == this) || getParent()->isModalMouseInputFocused();
949 }
950
951 return mFocusHandler->getModalMouseInputFocused() == this;
952 }
953
954 Widget* Widget::getWidgetAt(int x, int y, Widget* exclude)
955 {
956 Rectangle const r = getChildrenArea();
957
958 if (!r.isContaining(x, y)) {
959 return nullptr;
960 }
961
962 x -= r.x;
963 y -= r.y;
964
965 std::list<Widget*>::reverse_iterator iter;
966 for (iter = mChildren.rbegin(); iter != mChildren.rend(); ++iter) {
967 Widget* widget = (*iter);
968
969 if (widget != exclude && widget->isVisible() && widget->getDimension().isContaining(x, y)) {
970 return widget;
971 }
972 }
973
974 return nullptr;
975 }
976
977 std::list<MouseListener*> const & Widget::_getMouseListeners()
978 {
979 return mMouseListeners;
980 }
981
982 std::list<KeyListener*> const & Widget::_getKeyListeners()
983 {
984 return mKeyListeners;
985 }
986
987 std::list<FocusListener*> const & Widget::_getFocusListeners()
988 {
989 return mFocusListeners;
990 }
991
993 {
994 return {0, 0, 0, 0};
995 }
996
1001
1003 {
1004 mInternalFocusHandler = focusHandler;
1005
1006 std::list<Widget*>::const_iterator iter;
1007 for (iter = mChildren.begin(); iter != mChildren.end(); ++iter) {
1008 if (mInternalFocusHandler == nullptr) {
1009 (*iter)->_setFocusHandler(_getFocusHandler());
1010 } else {
1011 (*iter)->_setFocusHandler(mInternalFocusHandler);
1012 }
1013 }
1014 }
1015
1016 void Widget::setId(std::string const & id)
1017 {
1018 mId = id;
1019 }
1020
1021 std::string const & Widget::getId() const
1022 {
1023 return mId;
1024 }
1025
1027 {
1028 std::list<WidgetListener*>::const_iterator iter;
1029 for (iter = mWidgetListeners.begin(); iter != mWidgetListeners.end(); ++iter) {
1030 Event const event(this);
1031 (*iter)->widgetResized(event);
1032 }
1033 }
1034
1036 {
1037 std::list<WidgetListener*>::const_iterator iter;
1038 for (iter = mWidgetListeners.begin(); iter != mWidgetListeners.end(); ++iter) {
1039 Event const event(this);
1040 (*iter)->widgetMoved(event);
1041 }
1042 }
1043
1045 {
1046 std::list<WidgetListener*>::const_iterator iter;
1047 for (iter = mWidgetListeners.begin(); iter != mWidgetListeners.end(); ++iter) {
1048 Event const event(this);
1049 (*iter)->widgetHidden(event);
1050 }
1051 }
1052
1054 {
1055 auto currWidgetListener(mWidgetListeners.begin());
1056 auto const endWidgetListeners(mWidgetListeners.end());
1057 Event const event(ancestor);
1058
1059 for (; currWidgetListener != endWidgetListeners; ++currWidgetListener) {
1060 (*currWidgetListener)->ancestorMoved(event);
1061 }
1062
1063 auto currChild(mChildren.begin());
1064 auto const endChildren(mChildren.end());
1065
1066 for (; currChild != endChildren; ++currChild) {
1067 (*currChild)->distributeAncestorMovedEvent(ancestor);
1068 }
1069 }
1070
1072 {
1073 // additional call VisibilityEventHandler, needed to get new focus / MouseEvent::Entered or Exited
1075
1076 auto currWidgetListener(mWidgetListeners.begin());
1077 auto const endWidgetListeners(mWidgetListeners.end());
1078 Event const event(ancestor);
1079
1080 for (; currWidgetListener != endWidgetListeners; ++currWidgetListener) {
1081 (*currWidgetListener)->ancestorHidden(event);
1082 }
1083
1084 auto currChild(mChildren.begin());
1085 auto const endChildren(mChildren.end());
1086
1087 for (; currChild != endChildren; ++currChild) {
1088 (*currChild)->distributeAncestorHiddenEvent(ancestor);
1089 }
1090 }
1091
1093 {
1094 // additional call VisibilityEventHandler, needed to get new focus / MouseEvent::Entered or Exited
1096
1097 auto currWidgetListener(mWidgetListeners.begin());
1098 auto const endWidgetListeners(mWidgetListeners.end());
1099 Event const event(ancestor);
1100
1101 for (; currWidgetListener != endWidgetListeners; ++currWidgetListener) {
1102 (*currWidgetListener)->ancestorShown(event);
1103 }
1104
1105 auto currChild(mChildren.begin());
1106 auto const endChildren(mChildren.end());
1107
1108 for (; currChild != endChildren; ++currChild) {
1109 (*currChild)->distributeAncestorShownEvent(ancestor);
1110 }
1111 }
1112
1114 {
1115 std::list<ActionListener*>::const_iterator iter;
1116 for (iter = mActionListeners.begin(); iter != mActionListeners.end(); ++iter) {
1117 ActionEvent const actionEvent(this, mActionEventId);
1118 (*iter)->action(actionEvent);
1119 }
1120 }
1121
1123 {
1124 std::list<WidgetListener*>::const_iterator iter;
1125 for (iter = mWidgetListeners.begin(); iter != mWidgetListeners.end(); ++iter) {
1126 Event const event(this);
1127 (*iter)->widgetShown(event);
1128 }
1129 }
1130
1132 {
1133 if (mParent != nullptr) {
1134 mParent->showWidgetPart(this, rectangle);
1135 }
1136 }
1137
1139 {
1140 if (getParent() == nullptr) {
1141 return nullptr;
1142 }
1143
1144 Widget* widget = getParent();
1145 Widget* parent = getParent()->getParent();
1146
1147 while (parent != nullptr) {
1148 widget = parent;
1149 parent = parent->getParent();
1150 }
1151
1152 return widget;
1153 }
1154
1155 std::list<Widget*> Widget::getWidgetsIn(Rectangle const & area, Widget* ignore)
1156 {
1157 std::list<Widget*> result;
1158
1159 std::list<Widget*>::const_iterator iter;
1160 for (iter = mChildren.begin(); iter != mChildren.end(); ++iter) {
1161 Widget* widget = (*iter);
1162 if (ignore != widget && widget->getDimension().isIntersecting(area)) {
1163 result.push_back(widget);
1164 }
1165 }
1166
1167 return result;
1168 }
1169
1171 {
1172 int w = 0;
1173 int h = 0;
1174 std::list<Widget*>::const_iterator iter;
1175 for (iter = mChildren.begin(); iter != mChildren.end(); ++iter) {
1176 Widget* widget = (*iter);
1177 w = std::max(widget->getX() + widget->getWidth(), w);
1178 h = std::max(widget->getY() + widget->getHeight(), h);
1179 }
1180
1181 setSize(w, h);
1182 }
1183
1184 Widget* Widget::findWidgetById(std::string const & id)
1185 {
1186 std::list<Widget*>::const_iterator iter;
1187 for (iter = mChildren.begin(); iter != mChildren.end(); ++iter) {
1188 Widget* widget = (*iter);
1189
1190 if (widget->getId() == id) {
1191 return widget;
1192 }
1193
1194 Widget* child = widget->findWidgetById(id);
1195
1196 if (child != nullptr) {
1197 return child;
1198 }
1199 }
1200
1201 return nullptr;
1202 }
1203
1205 {
1206 Rectangle const widgetArea = getChildrenArea();
1207
1208 area.x += widget->getX();
1209 area.y += widget->getY();
1210
1211 if (area.x + area.width > widgetArea.width) {
1212 widget->setX(widget->getX() - area.x - area.width + widgetArea.width);
1213 }
1214
1215 if (area.y + area.height > widgetArea.height) {
1216 widget->setY(widget->getY() - area.y - area.height + widgetArea.height);
1217 }
1218
1219 if (area.x < 0) {
1220 widget->setX(widget->getX() - area.x);
1221 }
1222
1223 if (area.y < 0) {
1224 widget->setY(widget->getY() - area.y);
1225 }
1226 }
1227
1229 {
1230 std::list<Widget*>::const_iterator iter;
1231 for (iter = mChildren.begin(); iter != mChildren.end(); ++iter) {
1232 Widget* widget = (*iter);
1233 int x = 0;
1234 int y = 0;
1235 widget->getAbsolutePosition(x, y);
1236 widget->setLastPosition(x, y);
1237 widget->_setFocusHandler(nullptr);
1238 widget->_setParent(nullptr);
1239 // thats more a hack but needed
1240 if (_getVisibilityEventHandler() != nullptr) {
1242 }
1243 }
1244
1245 mChildren.clear();
1246 }
1247
1249 {
1250 auto it = std::ranges::find(mChildren, widget);
1251
1252 if (it == std::ranges::end(mChildren)) {
1253 throwException("There is no such widget in this container.");
1254 } else {
1255 int x = 0;
1256 int y = 0;
1257 widget->getAbsolutePosition(x, y);
1258 widget->setLastPosition(x, y);
1259
1260 mChildren.erase(it);
1261
1262 widget->_setFocusHandler(nullptr);
1263 widget->_setParent(nullptr);
1264
1265 // TODO thats more a hack but needed
1266 if (_getVisibilityEventHandler() != nullptr) {
1268 }
1269 }
1270 }
1271
1272 void Widget::add(Widget* widget)
1273 {
1274 mChildren.push_back(widget);
1275
1276 if (mInternalFocusHandler == nullptr) {
1278 } else {
1280 }
1281
1282 widget->_setParent(this);
1283 setLastPosition(0, 0);
1284 // thats more a hack but needed
1285 if (_getVisibilityEventHandler() != nullptr) {
1287 }
1288 }
1289
1291 {
1292 std::list<Widget*>::iterator iter;
1293 iter = std::ranges::find(mChildren, widget);
1294
1295 if (iter == mChildren.end()) {
1296 throwException("There is no such widget in this widget.");
1297 }
1298
1299 mChildren.remove(widget);
1300 mChildren.push_back(widget);
1301 }
1302
1304 {
1305 std::list<Widget*>::iterator iter;
1306 iter = std::ranges::find(mChildren, widget);
1307
1308 if (iter == mChildren.end()) {
1309 throwException("There is no such widget in this widget.");
1310 }
1311
1312 mChildren.remove(widget);
1313 mChildren.push_front(widget);
1314 }
1315
1317 {
1318 if (mChildren.empty()) {
1319 return;
1320 }
1321
1322 auto focused = std::ranges::find_if(mChildren, [](auto* w) {
1323 return w->isFocused();
1324 });
1325
1326 auto next = (focused == std::ranges::end(mChildren)) ? std::ranges::begin(mChildren) : std::next(focused);
1327
1328 auto it = std::ranges::find_if(next, std::ranges::end(mChildren), [](auto* w) {
1329 return w->isFocusable();
1330 });
1331
1332 if (it == std::ranges::end(mChildren)) {
1333 it = std::ranges::find_if(std::ranges::begin(mChildren), next, [](auto* w) {
1334 return w->isFocusable();
1335 });
1336 }
1337
1338 if (it != next) {
1339 (*it)->requestFocus();
1340 }
1341 }
1342
1344 {
1345 if (mChildren.empty()) {
1346 return;
1347 }
1348
1349 auto rev = std::ranges::reverse_view(mChildren);
1350
1351 auto focused = std::ranges::find_if(rev, [](auto* w) {
1352 return w->isFocused();
1353 });
1354
1355 auto next = (focused == std::ranges::end(rev)) ? std::ranges::begin(rev) : std::next(focused);
1356
1357 auto rit = std::ranges::find_if(next, std::ranges::end(rev), [](auto* w) {
1358 return w->isFocusable();
1359 });
1360
1361 if (rit == std::ranges::end(rev)) {
1362 rit = std::ranges::find_if(std::ranges::begin(rev), next, [](auto* w) {
1363 return w->isFocusable();
1364 });
1365 }
1366
1367 if (rit != next) {
1368 (*rit)->requestFocus();
1369 }
1370 }
1371
1372 void Widget::_draw(Graphics* graphics)
1373 {
1374 if (mOutlineSize > 0) {
1375 Rectangle rec = mDimension;
1376 rec.x -= mOutlineSize;
1377 rec.y -= mOutlineSize;
1378 rec.width += 2 * mOutlineSize;
1379 rec.height += 2 * mOutlineSize;
1380 graphics->pushClipArea(rec);
1381 drawOutline(graphics);
1382 graphics->popClipArea();
1383 }
1384
1385 graphics->pushClipArea(mDimension);
1386 draw(graphics);
1387
1388 if (!mChildren.empty()) {
1389 Rectangle const & childrenArea = getChildrenArea();
1390 graphics->pushClipArea(childrenArea);
1391
1392 for (auto* widget : mChildren) {
1393 // Only draw a widget:
1394 // if it's visible
1395 // and inside the children area.
1396 if (widget->isVisible() && childrenArea.isIntersecting(widget->getDimension())) {
1397 widget->_draw(graphics);
1398 }
1399 }
1400 graphics->popClipArea();
1401 }
1402 graphics->popClipArea();
1403 }
1404
1406 {
1407 logic();
1408
1409 std::list<Widget*>::const_iterator iter;
1410 for (iter = mChildren.begin(); iter != mChildren.end(); ++iter) {
1411 (*iter)->_logic();
1412 }
1413 }
1414
1415 std::list<Widget*> const & Widget::getChildren() const
1416 {
1417 return mChildren;
1418 }
1419
1420 void Widget::getLastPosition(int& x, int& y) const
1421 {
1422 x = mLastX;
1423 y = mLastY;
1424 }
1425
1426 void Widget::setLastPosition(int x, int y)
1427 {
1428 mLastX = x;
1429 mLastY = y;
1430 }
1431
1433 {
1434 return mLastX != 0 || mLastY != 0;
1435 }
1436} // namespace fcn
Represents an action trigger (e.g., button click).
Interface for listening to action events from widgets.
Color.
Definition color.hpp:56
uint8_t a
Alpha color component (0-255).
Definition color.hpp:322
Interface for listening to widget destruction events.
A basic font implementation capable only of drawing rectangles (placeholder).
Base class for all GUI event objects.
Definition event.hpp:24
char const * what() const noexcept override
Returns a pointer to a null-terminated string with a description of the exception.
Definition exception.hpp:58
Manages focus navigation and assignment among widgets within a Gui instance.
virtual void add(Widget *widget)
Adds a widget to by handles by the focus handler.
Interface for listening to focus gain/loss events.
Abstract interface for font rendering.
Definition font.hpp:24
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:57
virtual void popClipArea()
Removes the top most clip area from the stack.
Definition graphics.cpp:55
virtual bool pushClipArea(Rectangle area)
Pushes a clip area onto the stack.
Definition graphics.cpp:18
virtual void drawLine(int x1, int y1, int x2, int y2)=0
Draws a line.
virtual void setColor(Color const &color)=0
Sets the color to use when drawing.
Interface for listening to keyboard events.
Interface for listening to mouse events.
Represents a rectangular area (X, Y, Width, Height).
Definition rectangle.hpp:20
bool isContaining(int x, int y) const
Checks the rectangle contains a point.
Definition rectangle.cpp:52
int width
Holds the width of the rectangle.
int y
Holds the x coordinate of the rectangle.
int x
Holds the x coordinate of the rectangle.
int height
Holds the height of the rectangle.
bool isIntersecting(Rectangle const &rectangle) const
Checks if another rectangle intersects with the rectangle.
Definition rectangle.cpp:23
Represents dimensions defined by width and height.
Definition size.hpp:18
Handles changes in widget visibility states.
void widgetHidden(Event const &e) override
Informs gui that a widget was hidden.
void widgetShown(Event const &e) override
Informs gui that a widget was shown.
Interface for receiving generic events from widgets.
std::list< FocusListener * > mFocusListeners
Holds the focus listeners of the widget.
Definition widget.hpp:1618
void setActionEventId(std::string const &actionEventId)
Sets the action event identifier of the widget.
Definition widget.cpp:492
bool mHExpand
True if the widget can be horizontal expanded.
Definition widget.hpp:1803
void addFocusListener(FocusListener *focusListener)
Adds a focus listener to the widget.
Definition widget.cpp:744
void setMaxSize(Size const &size)
Sets the maximal dimension of the widget.
Definition widget.cpp:282
void setLastPosition(int x, int y)
Stores the last known position for this widget.
Definition widget.cpp:1426
Color const & getBaseColor() const
Gets the base color.
Definition widget.cpp:596
virtual bool isModalMouseInputFocused() const
Checks if the widget or it's parent has modal mouse input focus.
Definition widget.cpp:941
void setVisible(bool visible)
Sets the widget to be visible, or not.
Definition widget.cpp:545
void setMargin(int margin)
Sets all 4 margins to one value.
Definition widget.cpp:386
void distributeShownEvent()
Distributes shown events to all of the widget's listeners.
Definition widget.cpp:1122
Widget * mParent
Holds the parent of the widget.
Definition widget.hpp:1670
std::list< Widget * > const & getChildren() const
Gets the children of the widget.
Definition widget.cpp:1415
bool isHorizontalExpand() const
Gets if widget is horizontal expandable.
Definition widget.cpp:347
int getY() const
Gets the y coordinate of the widget.
Definition widget.cpp:209
std::list< DeathListener * > mDeathListeners
Holds the death listeners of the widget.
Definition widget.hpp:1613
void setFocusable(bool focusable)
Sets the widget to be focusable, or not.
Definition widget.cpp:506
virtual FocusHandler * _getFocusHandler()
Gets the focus handler used.
Definition widget.cpp:689
virtual void fontChanged()
Called when the font has changed.
Definition widget.hpp:999
static DefaultFont mDefaultFont
Holds the default font used by the widget.
Definition widget.hpp:1813
unsigned int getChildrenCount() const
Gets how many childs the widget have.
Definition widget.cpp:247
virtual bool isModalFocused() const
Checks if the widget or it's parent has modal focus.
Definition widget.cpp:928
FocusHandler * mFocusHandler
Holds the focus handler used by the widget.
Definition widget.hpp:1658
void setEnabled(bool enabled)
Sets the widget to enabled, or not.
Definition widget.cpp:864
Size mMinSize
Holds the min size.
Definition widget.hpp:1775
int mMarginTop
Holds the top margin of the widget.
Definition widget.hpp:1700
int getWidth() const
Gets the width of the widget.
Definition widget.cpp:170
virtual void drawOutline(Graphics *graphics)
Called when a widget is given a chance to draw a outline around itself.
Definition widget.cpp:88
virtual Widget * getParent() const
Gets the widget's parent container.
Definition widget.cpp:157
void setMinSize(Size const &size)
Sets the minimal dimension of the widget.
Definition widget.cpp:271
virtual bool isLayouted()
Helper function to decide if we need to layout.
Definition widget.hpp:1455
void setBorderSize(unsigned int size)
Sets the size of the widget's border.
Definition widget.cpp:376
void add(Widget *widget)
Adds a child to the widget.
Definition widget.cpp:1272
Size const & getFixedSize() const
Gets the fixed size of the widget.
Definition widget.cpp:304
int mLastY
Last stored Y coordinate used for layout and event calculations.
Definition widget.hpp:1848
void removeWidgetListener(WidgetListener *widgetListener)
Removes an added widget listener from the widget.
Definition widget.cpp:769
std::list< KeyListener * > mKeyListeners
Holds the key listeners of the widget.
Definition widget.hpp:1603
std::list< ActionListener * > mActionListeners
Holds the action listeners of the widget.
Definition widget.hpp:1608
void resizeToChildren()
Resizes the widget to fit it's children exactly.
Definition widget.cpp:1170
void setTabInEnabled(bool enabled)
Sets tab in enabled, or not.
Definition widget.cpp:840
virtual Widget * findWidgetById(std::string const &id)
Finds a widget by id.
Definition widget.cpp:1184
void setOutlineSize(unsigned int size)
Sets the size of the widget's outline.
Definition widget.cpp:366
Size const & getMaxSize() const
Gets the maximal dimension of the widget.
Definition widget.cpp:288
virtual void releaseModalMouseInputFocus()
Releases modal mouse input focus.
Definition widget.cpp:919
void distributeHiddenEvent()
Distributes hidden events to all of the widget's listeners.
Definition widget.cpp:1044
virtual void requestMoveToBottom()
Requests a move to the bottom in the parent widget.
Definition widget.cpp:538
SelectionMode
Selection mode.
Definition widget.hpp:51
void setMarginTop(int margin)
Sets the top margin.
Definition widget.cpp:394
unsigned int getOutlineSize() const
Gets the size of the widget's outline.
Definition widget.cpp:371
virtual std::list< KeyListener * > const & _getKeyListeners()
Gets the key listeners of the widget.
Definition widget.cpp:982
void removeKeyListener(KeyListener *keyListener)
Removes an added key listener from the widget.
Definition widget.cpp:739
static std::list< Widget * > mWidgetInstances
Holds a list of all instances of widgets.
Definition widget.hpp:1823
virtual Rectangle getChildrenArea()
Gets the area of the widget occupied by the widget's children.
Definition widget.cpp:992
virtual void moveToTop(Widget *widget)
Moves a widget to the top of this widget.
Definition widget.cpp:1290
virtual void logic()
Called for all widgets in the gui each time Gui::logic is called.
Definition widget.hpp:378
virtual void setOutlineColor(Color const &color)
Sets the outline color.
Definition widget.cpp:631
virtual void remove(Widget *widget)
Removes a specific child from the widget.
Definition widget.cpp:1248
virtual void releaseModalFocus()
Releases modal focus.
Definition widget.cpp:910
int getX() const
Gets the x coordinate of the widget.
Definition widget.cpp:196
void removeMouseListener(MouseListener *mouseListener)
Removes an added mouse listener from the widget.
Definition widget.cpp:759
unsigned int mPaddingTop
Holds the top padding of the widget.
Definition widget.hpp:1720
virtual bool isFocused() const
Checks if the widget is focused.
Definition widget.cpp:497
bool isTabOutEnabled() const
Checks if tab out is enabled.
Definition widget.cpp:845
void setDimension(Rectangle const &dimension)
Sets the dimension of the widget.
Definition widget.cpp:223
virtual void showPart(Rectangle rectangle)
Shows a certain part of a widget in the widget's parent.
Definition widget.cpp:1131
Rectangle mDimension
Holds the dimension of the widget.
Definition widget.hpp:1675
void setMarginRight(int margin)
Sets the right margin.
Definition widget.cpp:404
bool mTabOut
True if the widget has tab in enabled, false otherwise.
Definition widget.hpp:1760
void removeActionListener(ActionListener *actionListener)
Removes an added action listener from the widget.
Definition widget.cpp:719
bool isEnabled() const
Checks if the widget is enabled.
Definition widget.cpp:869
virtual void removeAllChildren()
Remvoes all children from the widget.
Definition widget.cpp:1228
unsigned int getPaddingLeft() const
Gets the left padding.
Definition widget.cpp:477
Color mForegroundColor
Holds the foreground color of the widget.
Definition widget.hpp:1628
std::string mActionEventId
Holds the action event of the widget.
Definition widget.hpp:1740
int getMarginBottom() const
Gets the bottom margin.
Definition widget.cpp:419
Widget()
Constructor.
Definition widget.cpp:36
void expandContent()
Expands the child widgets to the size of this widget, calls recursively all childs.
Definition widget.hpp:1440
void setSize(int width, int height)
Sets the size of the widget.
Definition widget.cpp:855
void setPaddingTop(unsigned int padding)
Sets the top padding.
Definition widget.cpp:442
virtual void _setParent(Widget *parent)
Sets the parent of the widget.
Definition widget.cpp:152
Color mOutlineColor
Holds the outline color of the widget.
Definition widget.hpp:1648
virtual void requestFocus()
Requests focus for the widget.
Definition widget.cpp:520
virtual void showWidgetPart(Widget *widget, Rectangle area)
Tries to show a specific part of a widget by moving it.
Definition widget.cpp:1204
Color mBorderColor
Holds the border color of the widget.
Definition widget.hpp:1653
virtual FocusHandler * _getInternalFocusHandler()
Gets the internal focus handler used.
Definition widget.cpp:997
void setPaddingRight(unsigned int padding)
Sets the right padding.
Definition widget.cpp:452
virtual void _logic()
Called whenever a widget should perform logic.
Definition widget.cpp:1405
bool isLastPositionSet() const
Returns whether a last position has been stored for this widget.
Definition widget.cpp:1432
std::string const & getActionEventId() const
Gets the action event identifier of the widget.
Definition widget.cpp:487
Color const & getOutlineColor() const
Gets the outline color.
Definition widget.cpp:636
std::list< WidgetListener * > mWidgetListeners
Holds the widget listeners of the widget.
Definition widget.hpp:1623
Color const & getBorderColor() const
Gets the border color.
Definition widget.cpp:646
void distributeAncestorHiddenEvent(Widget *ancestor)
Distributes ancestor hidden events to all of the widget's listeners.
Definition widget.cpp:1071
bool isVisible() const
Checks if the widget is visible.
Definition widget.cpp:578
Color const & getBackgroundColor() const
Gets the background color.
Definition widget.cpp:616
bool isSetVisible() const
Checks if the widget setting is visible.
Definition widget.cpp:586
void distributeResizedEvent()
Distributes resized events to all of the widget's listeners.
Definition widget.cpp:1026
virtual void setForegroundColor(Color const &color)
Sets the foreground color.
Definition widget.cpp:601
Size mFixedSize
Holds the fixed size.
Definition widget.hpp:1788
void addMouseListener(MouseListener *mouseListener)
Adds a mouse listener to the widget.
Definition widget.cpp:754
virtual void requestMoveToTop()
Requests a move to the top in the parent widget.
Definition widget.cpp:531
FocusHandler * mInternalFocusHandler
Holds the focus handler used by the widget.
Definition widget.hpp:1664
void setHorizontalExpand(bool expand)
Sets the widget to horizontal expandable.
Definition widget.cpp:342
Widget * getWidgetAt(int x, int y)
Gets a widget at a certain position in the widget.
Definition widget.hpp:1135
void setPosition(int x, int y)
Sets position of the widget.
Definition widget.cpp:214
void addDeathListener(DeathListener *deathListener)
Adds a death listener to the widget.
Definition widget.cpp:724
void setY(int y)
Sets the y coordinate of the widget.
Definition widget.cpp:201
SelectionMode mSelectionMode
Holds the selection mode.
Definition widget.hpp:1695
void calculateSize()
Checks the size against the size constraints.
Definition widget.cpp:314
void resizeToContent()
Resizes the widget's size to fit the content exactly, calls recursively all childs.
Definition widget.hpp:1417
void setX(int x)
Sets the x coordinate of the widget.
Definition widget.cpp:188
int getMarginLeft() const
Gets the left margin.
Definition widget.cpp:429
void addWidgetListener(WidgetListener *widgetListener)
Adds a widget listener to the widget.
Definition widget.cpp:764
void distributeAncestorShownEvent(Widget *ancestor)
Distributes ancestor shown events to all of the widget's listeners.
Definition widget.cpp:1092
void addActionListener(ActionListener *actionListener)
Adds an action listener to the widget.
Definition widget.cpp:714
virtual void setBorderColor(Color const &color)
Sets the border color.
Definition widget.cpp:641
std::list< MouseListener * > mMouseListeners
Holds the mouse listeners of the widget.
Definition widget.hpp:1598
static bool widgetExists(Widget const *widget)
Checks if a widget exists or not, that is if it still exists an instance of the object.
Definition widget.cpp:827
static void _setGuiDeathListener(DeathListener *deathListener)
Set the global GUI death listener used to observe widget deletions.
Definition widget.cpp:704
virtual std::list< MouseListener * > const & _getMouseListeners()
Gets the mouse listeners of the widget.
Definition widget.cpp:977
void adaptLayout()
Execute the layouting.
Definition widget.hpp:1399
unsigned int mBorderSize
Holds the border size of the widget.
Definition widget.hpp:1690
unsigned int mPaddingRight
Holds the right padding of the widget.
Definition widget.hpp:1725
void setWidth(int width)
Sets the width of the widget.
Definition widget.cpp:162
int getMarginRight() const
Gets the right margin.
Definition widget.cpp:409
virtual void requestModalMouseInputFocus()
Requests modal mouse input focus.
Definition widget.cpp:901
void addKeyListener(KeyListener *keyListener)
Adds a key listener to the widget.
Definition widget.cpp:734
virtual std::list< FocusListener * > const & _getFocusListeners()
Gets the focus listeners of the widget.
Definition widget.cpp:987
void setPaddingLeft(unsigned int padding)
Sets the left padding.
Definition widget.cpp:472
void distributeAncestorMovedEvent(Widget *ancestor)
Distributes ancestor moved events to all of the widget's listeners.
Definition widget.cpp:1053
std::string const & getId() const
Gets the id of a widget.
Definition widget.cpp:1021
static void _setVisibilityEventHandler(VisibilityEventHandler *visibilityEventHandler)
Sets the visibility event handler to be used.
Definition widget.cpp:694
unsigned int mPaddingBottom
Holds the bottom padding of the widget.
Definition widget.hpp:1730
int mLastX
Last stored X coordinate used for layout and event calculations.
Definition widget.hpp:1845
int mMarginRight
Holds the top right of the widget.
Definition widget.hpp:1705
void setInternalFocusHandler(FocusHandler *internalFocusHandler)
Sets the internal focus handler.
Definition widget.cpp:1002
Rectangle const & getDimension() const
Gets the dimension of the widget.
Definition widget.cpp:482
bool isTabInEnabled() const
Checks if tab in is enabled.
Definition widget.cpp:835
void setTabOutEnabled(bool enabled)
Sets tab out enabled.
Definition widget.cpp:850
static DeathListener * _getGuiDeathListener()
Get the global GUI death listener.
Definition widget.cpp:709
virtual void drawBorder(Graphics *graphics)
Called when a widget have a border.
Definition widget.cpp:111
static DeathListener * mGuiDeathListener
Holds the death listener used by the widgets.
Definition widget.hpp:1837
static Font * mGlobalFont
Holds the global font used by the widget.
Definition widget.hpp:1818
static void setGlobalFont(Font *font)
Sets the global font to be used by default for all widgets.
Definition widget.cpp:809
virtual bool isModalFocusable() const
Checks if a widget is modal focusable.
Definition widget.cpp:874
virtual void requestModalFocus()
Requests modal focus.
Definition widget.cpp:892
unsigned int getPaddingTop() const
Gets the top padding.
Definition widget.cpp:447
virtual void _draw(Graphics *graphics)
Called whenever a widget should draw itself.
Definition widget.cpp:1372
unsigned int getBorderSize() const
Gets the size of the widget's border.
Definition widget.cpp:381
Size const & getMinSize() const
Gets the minimal dimension of the widget.
Definition widget.cpp:277
virtual void drawSelectionFrame(Graphics *graphics)
Called when a widget is "active" and the selection mode is Frame or FrameWithBackground.
Definition widget.cpp:135
virtual bool isModalMouseInputFocusable() const
Checks if a widget is modal mouse input focusable.
Definition widget.cpp:883
std::list< Widget * > mChildren
Holds all children of the widget.
Definition widget.hpp:1842
std::list< Widget * > getWidgetsIn(Rectangle const &area)
Gets all widgets inside a certain area of the widget.
Definition widget.hpp:1160
bool mEnabled
True if the widget is enabled, false otherwise.
Definition widget.hpp:1765
unsigned int mOutlineSize
Holds the outline size of the widget.
Definition widget.hpp:1685
unsigned int getVisibleChildrenCount() const
Gets how many visible childs the widget have.
Definition widget.cpp:258
void removeFocusListener(FocusListener *focusListener)
Removes an added focus listener from the widget.
Definition widget.cpp:749
Color mBaseColor
Holds the base color of the widget.
Definition widget.hpp:1638
bool mVisible
True if the widget visible, false otherwise.
Definition widget.hpp:1750
virtual void focusPrevious()
Focuses the previous widget in the widget.
Definition widget.cpp:1343
void getLastPosition(int &x, int &y) const
Retrieves the last stored position used by layout or event logic.
Definition widget.cpp:1420
virtual void focusNext()
Focuses the next widget in the widget.
Definition widget.cpp:1316
virtual Widget * getTop() const
Gets the top widget, or top parent, of this widget.
Definition widget.cpp:1138
int getMarginTop() const
Gets the top margin.
Definition widget.cpp:399
unsigned int getPaddingBottom() const
Gets the bottom padding.
Definition widget.cpp:467
Color mSelectionColor
Holds the selection color of the widget.
Definition widget.hpp:1643
bool mVExpand
True if the widget can be vertical expanded.
Definition widget.hpp:1798
virtual void setBaseColor(Color const &color)
Sets the base color of the widget.
Definition widget.cpp:591
unsigned int mPaddingLeft
Holds the left padding of the widget.
Definition widget.hpp:1735
void setId(std::string const &id)
Sets an id of a widget.
Definition widget.cpp:1016
Font * mCurrentFont
Holds the font used by the widget.
Definition widget.hpp:1808
Color const & getForegroundColor() const
Gets the foreground color.
Definition widget.cpp:606
virtual void setFont(Font *font)
Sets the font for the widget.
Definition widget.cpp:821
SelectionMode getSelectionMode() const
Gets the selection mode.
Definition widget.cpp:656
bool mFocusable
True if the widget focusable, false otherwise.
Definition widget.hpp:1745
bool isFocusable() const
Checks if a widget is focusable.
Definition widget.cpp:515
Color mBackgroundColor
Holds the background color of the widget.
Definition widget.hpp:1633
Font * getFont() const
Gets the font set for the widget.
Definition widget.cpp:796
virtual void getAbsolutePosition(int &x, int &y) const
Gets the absolute position on the screen for the widget.
Definition widget.cpp:774
static VisibilityEventHandler * _getVisibilityEventHandler()
Gets the visibility event handler of this widget.
Definition widget.cpp:699
void setVerticalExpand(bool expand)
Sets the widget to vertical expandable.
Definition widget.cpp:332
void setFixedSize(Size const &size)
Sets the dimension of the widget to a fixed size.
Definition widget.cpp:293
int mMarginLeft
Holds the left margin of the widget.
Definition widget.hpp:1715
int mMarginBottom
Holds the bottom margin of the widget.
Definition widget.hpp:1710
void distributeActionEvent()
Distributes an action event to all action listeners of the widget.
Definition widget.cpp:1113
virtual void draw(Graphics *graphics)=0
Draws the widget.
void removeDeathListener(DeathListener *deathListener)
Removes an added death listener from the widget.
Definition widget.cpp:729
bool mFixedSizeUsed
True if the widget used a fixed size.
Definition widget.hpp:1793
int getHeight() const
Gets the height of the widget.
Definition widget.cpp:183
void setMarginLeft(int margin)
Sets the left margin.
Definition widget.cpp:424
void setPaddingBottom(unsigned int padding)
Sets the bottom padding.
Definition widget.cpp:462
bool mTabIn
True if the widget has tab in enabled, false otherwise.
Definition widget.hpp:1755
std::string mId
Holds the id of the widget.
Definition widget.hpp:1770
void setMarginBottom(int margin)
Sets the bottom margin.
Definition widget.cpp:414
virtual void _setFocusHandler(FocusHandler *focusHandler)
Sets the focus handler to be used.
Definition widget.cpp:661
virtual void setSelectionColor(Color const &color)
Sets the selection color.
Definition widget.cpp:621
void setHeight(int height)
Sets the height of the widget.
Definition widget.cpp:175
unsigned int getPaddingRight() const
Gets the right padding.
Definition widget.cpp:457
Color const & getSelectionColor() const
Gets the selection color.
Definition widget.cpp:626
virtual void setBackgroundColor(Color const &color)
Sets the background color.
Definition widget.cpp:611
void setPadding(unsigned int padding)
Sets all 4 paddings to one value.
Definition widget.cpp:434
bool isFixedSize() const
Gets if the widget use a fixed size.
Definition widget.cpp:309
virtual void setSelectionMode(SelectionMode mode)
Sets the selection mode.
Definition widget.cpp:651
virtual void moveToBottom(Widget *widget)
Moves a widget in this widget to the bottom of this widget.
Definition widget.cpp:1303
void distributeMovedEvent()
Distributes moved events to all of the widget's listeners.
Definition widget.cpp:1035
Size mMaxSize
Holds the max size.
Definition widget.hpp:1783
bool isVerticalExpand() const
Gets if widget is vertical expandable.
Definition widget.cpp:337
static VisibilityEventHandler * mVisibilityEventHandler
Holds the visibility event handler used by the widgets.
Definition widget.hpp:1832