FifeGUI 0.2.0
A C++ GUI library designed for games.
scrollarea.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/widgets/scrollarea.hpp"
6
7#include <algorithm>
8
9#include "fifechan/exception.hpp"
10#include "fifechan/graphics.hpp"
11
12namespace fcn
13{
14 ScrollArea::ScrollArea()
15 {
16 addMouseListener(this);
17 }
18
19 ScrollArea::ScrollArea(Widget* content)
20 {
21 setContent(content);
22 addMouseListener(this);
23 }
24
25 ScrollArea::ScrollArea(Widget* content, ScrollPolicy /*hPolicy*/, ScrollPolicy /*vPolicy*/)
26 {
27 setContent(content);
28 addMouseListener(this);
29 }
30
31 ScrollArea::~ScrollArea()
32 {
33 try {
34 setContent(nullptr);
35 } catch (std::exception&) {
36 // logError("Exception in ScrollArea destructor: " + std::string(e.what()));
37 }
38 }
39
41 {
43
44 if (widget != nullptr) {
45 add(widget);
46 widget->setPosition(0, 0);
47 }
48
50 }
51
53 {
54 if (!mChildren.empty()) {
55 return *mChildren.begin();
56 }
57
58 return nullptr;
59 }
60
62 {
63 mHPolicy = hPolicy;
65 }
66
71
73 {
74 mVPolicy = vPolicy;
76 }
77
82
84 {
85 mHPolicy = hPolicy;
86 mVPolicy = vPolicy;
88 }
89
91 {
92 int const max = getVerticalMaxScroll();
93
94 mVScroll = vScroll;
95
96 if (vScroll > max) {
97 mVScroll = max;
98 }
99
100 if (vScroll < 0) {
101 mVScroll = 0;
102 }
103 }
104
106 {
107 return mVScroll;
108 }
109
111 {
112 int const max = getHorizontalMaxScroll();
113
114 mHScroll = hScroll;
115
116 if (hScroll > max) {
117 mHScroll = max;
118 } else if (hScroll < 0) {
119 mHScroll = 0;
120 }
121 }
122
124 {
125 return mHScroll;
126 }
127
128 void ScrollArea::setScrollAmount(int hScroll, int vScroll)
129 {
132 }
133
135 {
137
138 if (getContent() == nullptr) {
139 return 0;
140 }
141
142 int const value = getContent()->getWidth() - getChildrenArea().width + (2 * getContent()->getBorderSize());
143
144 if (value < 0) {
145 return 0;
146 }
147
148 return value;
149 }
150
152 {
154
155 if (getContent() == nullptr) {
156 return 0;
157 }
158
159 int value = 0;
160
162
163 if (value < 0) {
164 return 0;
165 }
166
167 return value;
168 }
169
171 {
172 if (width <= 0) {
173 throwException("Width should be greater then 0.");
174 }
175
176 mScrollbarWidth = width;
177 }
178
180 {
181 return mScrollbarWidth;
182 }
183
185 {
186 int const x = mouseEvent.getX();
187 int const y = mouseEvent.getY();
188
189 if (getUpButtonDimension().isContaining(x, y)) {
191 mUpButtonPressed = true;
192 } else if (getDownButtonDimension().isContaining(x, y)) {
194 mDownButtonPressed = true;
195 } else if (getLeftButtonDimension().isContaining(x, y)) {
197 mLeftButtonPressed = true;
198 } else if (getRightButtonDimension().isContaining(x, y)) {
200 mRightButtonPressed = true;
201 } else if (getVerticalMarkerDimension().isContaining(x, y)) {
204
206 } else if (getVerticalBarDimension().isContaining(x, y)) {
207 if (y < getVerticalMarkerDimension().y) {
209 getVerticalScrollAmount() - static_cast<int>((getChildrenArea().height * 0.95)));
210 } else {
212 getVerticalScrollAmount() + static_cast<int>((getChildrenArea().height * 0.95)));
213 }
214 } else if (getHorizontalMarkerDimension().isContaining(x, y)) {
217
219 } else if (getHorizontalBarDimension().isContaining(x, y)) {
220 if (x < getHorizontalMarkerDimension().x) {
222 getHorizontalScrollAmount() - static_cast<int>((getChildrenArea().width * 0.95)));
223 } else {
225 getHorizontalScrollAmount() + static_cast<int>((getChildrenArea().width * 0.95)));
226 }
227 }
228 }
229
231 {
232 mUpButtonPressed = false;
233 mDownButtonPressed = false;
234 mLeftButtonPressed = false;
235 mRightButtonPressed = false;
238
239 mouseEvent.consume();
240 }
241
243 {
245 int const pos = mouseEvent.getY() - getVerticalBarDimension().y - mVerticalMarkerDragOffset;
246 int const length = getVerticalMarkerDimension().height;
247
248 Rectangle const barDim = getVerticalBarDimension();
249
250 if ((barDim.height - length) > 0) {
251 setVerticalScrollAmount((getVerticalMaxScroll() * pos) / (barDim.height - length));
252 } else {
254 }
255 }
256
258 int const pos = mouseEvent.getX() - getHorizontalBarDimension().x - mHorizontalMarkerDragOffset;
259 int const length = getHorizontalMarkerDimension().width;
260
261 Rectangle const barDim = getHorizontalBarDimension();
262
263 if ((barDim.width - length) > 0) {
264 setHorizontalScrollAmount((getHorizontalMaxScroll() * pos) / (barDim.width - length));
265 } else {
267 }
268 }
269
270 mouseEvent.consume();
271 }
272
274 {
275 drawBackground(graphics);
276
277 if (mVBarVisible) {
278 drawUpButton(graphics);
279 drawDownButton(graphics);
280 drawVBar(graphics);
281 drawVMarker(graphics);
282 }
283
284 if (mHBarVisible) {
285 drawLeftButton(graphics);
286 drawRightButton(graphics);
287 drawHBar(graphics);
288 drawHMarker(graphics);
289 }
290
291 if (mHBarVisible && mVBarVisible) {
292 graphics->setColor(getBaseColor());
293 graphics->fillRectangle(
295 }
296 }
297
299 {
301
302 graphics->pushClipArea(dim);
303
304 int const alpha = getBaseColor().a;
305 Color trackColor = getBaseColor() - 0x101010;
306 trackColor.a = alpha;
307 Color shadowColor = getBaseColor() - 0x303030;
308 shadowColor.a = alpha;
309
310 graphics->setColor(trackColor);
311 graphics->fillRectangle(0, 0, dim.width, dim.height);
312
313 graphics->setColor(shadowColor);
314 graphics->drawLine(0, 0, dim.width, 0);
315
316 graphics->popClipArea();
317 }
318
320 {
322
323 graphics->pushClipArea(dim);
324
325 int const alpha = getBaseColor().a;
326 Color trackColor = getBaseColor() - 0x101010;
327 trackColor.a = alpha;
328 Color shadowColor = getBaseColor() - 0x303030;
329 shadowColor.a = alpha;
330
331 graphics->setColor(trackColor);
332 graphics->fillRectangle(0, 0, dim.width, dim.height);
333
334 graphics->setColor(shadowColor);
335 graphics->drawLine(0, 0, 0, dim.height);
336
337 graphics->popClipArea();
338 }
339
341 {
342 if (isOpaque()) {
343 graphics->setColor(getBackgroundColor());
344 graphics->fillRectangle(getChildrenArea());
345 }
346 }
347
349 {
350 Rectangle const dim = getUpButtonDimension();
351
352 graphics->pushClipArea(dim);
353
354 Color highlightColor;
355 Color shadowColor;
356 Color faceColor;
357 int offset = 0;
358 int const alpha = getBaseColor().a;
359
360 if (mUpButtonPressed) {
361 faceColor = getBaseColor() - 0x303030;
362 faceColor.a = alpha;
363 highlightColor = faceColor - 0x303030;
364 highlightColor.a = alpha;
365 shadowColor = getBaseColor();
366 shadowColor.a = alpha;
367
368 offset = 1;
369 } else {
370 faceColor = getBaseColor();
371 faceColor.a = alpha;
372 highlightColor = faceColor + 0x303030;
373 highlightColor.a = alpha;
374 shadowColor = faceColor - 0x303030;
375 shadowColor.a = alpha;
376
377 offset = 0;
378 }
379
380 graphics->setColor(faceColor);
381 graphics->fillRectangle(0, 0, dim.width, dim.height);
382
383 graphics->setColor(highlightColor);
384 graphics->drawLine(0, 0, dim.width - 1, 0);
385 graphics->drawLine(0, 1, 0, dim.height - 1);
386
387 graphics->setColor(shadowColor);
388 graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1);
389 graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1);
390
391 graphics->setColor(getForegroundColor());
392
393 int i = 0;
394 int const w = dim.height / 2;
395 int const h = (w / 2) + 2;
396 for (i = 0; i < w / 2; ++i) {
397 graphics->drawLine(w - i + offset, i + h + offset, w + i + offset, i + h + offset);
398 }
399
400 graphics->popClipArea();
401 }
402
404 {
405 Rectangle const dim = getDownButtonDimension();
406
407 graphics->pushClipArea(dim);
408
409 Color highlightColor;
410 Color shadowColor;
411 Color faceColor;
412 int offset = 0;
413 int const alpha = getBaseColor().a;
414
415 if (mDownButtonPressed) {
416 faceColor = getBaseColor() - 0x303030;
417 faceColor.a = alpha;
418 highlightColor = faceColor - 0x303030;
419 highlightColor.a = alpha;
420 shadowColor = getBaseColor();
421 shadowColor.a = alpha;
422
423 offset = 1;
424 } else {
425 faceColor = getBaseColor();
426 faceColor.a = alpha;
427 highlightColor = faceColor + 0x303030;
428 highlightColor.a = alpha;
429 shadowColor = faceColor - 0x303030;
430 shadowColor.a = alpha;
431
432 offset = 0;
433 }
434
435 graphics->setColor(faceColor);
436 graphics->fillRectangle(0, 0, dim.width, dim.height);
437
438 graphics->setColor(highlightColor);
439 graphics->drawLine(0, 0, dim.width - 1, 0);
440 graphics->drawLine(0, 1, 0, dim.height - 1);
441
442 graphics->setColor(shadowColor);
443 graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1);
444 graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1);
445
446 graphics->setColor(getForegroundColor());
447
448 int i = 0;
449 int const w = dim.height / 2;
450 int const h = w + 1;
451 for (i = 0; i < w / 2; ++i) {
452 graphics->drawLine(w - i + offset, -i + h + offset, w + i + offset, -i + h + offset);
453 }
454
455 graphics->popClipArea();
456 }
457
459 {
460 Rectangle const dim = getLeftButtonDimension();
461 graphics->pushClipArea(dim);
462
463 Color highlightColor;
464 Color shadowColor;
465 Color faceColor;
466 int offset = 0;
467 int const alpha = getBaseColor().a;
468
469 if (mLeftButtonPressed) {
470 faceColor = getBaseColor() - 0x303030;
471 faceColor.a = alpha;
472 highlightColor = faceColor - 0x303030;
473 highlightColor.a = alpha;
474 shadowColor = getBaseColor();
475 shadowColor.a = alpha;
476
477 offset = 1;
478 } else {
479 faceColor = getBaseColor();
480 faceColor.a = alpha;
481 highlightColor = faceColor + 0x303030;
482 highlightColor.a = alpha;
483 shadowColor = faceColor - 0x303030;
484 shadowColor.a = alpha;
485
486 offset = 0;
487 }
488
489 graphics->setColor(faceColor);
490 graphics->fillRectangle(0, 0, dim.width, dim.height);
491
492 graphics->setColor(highlightColor);
493 graphics->drawLine(0, 0, dim.width - 1, 0);
494 graphics->drawLine(0, 1, 0, dim.height - 1);
495
496 graphics->setColor(shadowColor);
497 graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1);
498 graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1);
499
500 graphics->setColor(getForegroundColor());
501
502 int i = 0;
503 int const w = dim.width / 2;
504 int const h = w - 2;
505 for (i = 0; i < w / 2; ++i) {
506 graphics->drawLine(i + h + offset, w - i + offset, i + h + offset, w + i + offset);
507 }
508
509 graphics->popClipArea();
510 }
511
513 {
515
516 graphics->pushClipArea(dim);
517
518 Color highlightColor;
519 Color shadowColor;
520 Color faceColor;
521 int offset = 0;
522 int const alpha = getBaseColor().a;
523
525 faceColor = getBaseColor() - 0x303030;
526 faceColor.a = alpha;
527 highlightColor = faceColor - 0x303030;
528 highlightColor.a = alpha;
529 shadowColor = getBaseColor();
530 shadowColor.a = alpha;
531
532 offset = 1;
533 } else {
534 faceColor = getBaseColor();
535 faceColor.a = alpha;
536 highlightColor = faceColor + 0x303030;
537 highlightColor.a = alpha;
538 shadowColor = faceColor - 0x303030;
539 shadowColor.a = alpha;
540
541 offset = 0;
542 }
543
544 graphics->setColor(faceColor);
545 graphics->fillRectangle(0, 0, dim.width, dim.height);
546
547 graphics->setColor(highlightColor);
548 graphics->drawLine(0, 0, dim.width - 1, 0);
549 graphics->drawLine(0, 1, 0, dim.height - 1);
550
551 graphics->setColor(shadowColor);
552 graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1);
553 graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1);
554
555 graphics->setColor(getForegroundColor());
556
557 int i = 0;
558 int const w = dim.width / 2;
559 int const h = w + 1;
560 for (i = 0; i < w / 2; ++i) {
561 graphics->drawLine(-i + h + offset, w - i + offset, -i + h + offset, w + i + offset);
562 }
563
564 graphics->popClipArea();
565 }
566
568 {
570 graphics->pushClipArea(dim);
571
572 int const alpha = getBaseColor().a;
573 Color faceColor = getBaseColor();
574 faceColor.a = alpha;
575 Color highlightColor = faceColor + 0x303030;
576 highlightColor.a = alpha;
577 Color shadowColor = faceColor - 0x303030;
578 shadowColor.a = alpha;
579
580 graphics->setColor(faceColor);
581 graphics->fillRectangle(1, 1, dim.width - 1, dim.height - 1);
582
583 graphics->setColor(highlightColor);
584 graphics->drawLine(0, 0, dim.width - 1, 0);
585 graphics->drawLine(0, 1, 0, dim.height - 1);
586
587 graphics->setColor(shadowColor);
588 graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1);
589 graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1);
590
591 graphics->popClipArea();
592 }
593
595 {
597 graphics->pushClipArea(dim);
598
599 int const alpha = getBaseColor().a;
600 Color faceColor = getBaseColor();
601 faceColor.a = alpha;
602 Color highlightColor = faceColor + 0x303030;
603 highlightColor.a = alpha;
604 Color shadowColor = faceColor - 0x303030;
605 shadowColor.a = alpha;
606
607 graphics->setColor(faceColor);
608 graphics->fillRectangle(1, 1, dim.width - 1, dim.height - 1);
609
610 graphics->setColor(highlightColor);
611 graphics->drawLine(0, 0, dim.width - 1, 0);
612 graphics->drawLine(0, 1, 0, dim.height - 1);
613
614 graphics->setColor(shadowColor);
615 graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1);
616 graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1);
617
618 graphics->popClipArea();
619 }
620
634
636 {
637 int const w = getWidth();
638 int const h = getHeight();
639
640 mHBarVisible = false;
641 mVBarVisible = false;
642
643 if (getContent() == nullptr) {
644 mHBarVisible = (mHPolicy == ScrollPolicy::ShowAlways);
645 mVBarVisible = (mVPolicy == ScrollPolicy::ShowAlways);
646 return;
647 }
648
649 if (mHPolicy == ScrollPolicy::ShowAuto && mVPolicy == ScrollPolicy::ShowAuto) {
650 if (getContent()->getWidth() <= w && getContent()->getHeight() <= h) {
651 mHBarVisible = false;
652 mVBarVisible = false;
653 }
654
655 if (getContent()->getWidth() > w) {
656 mHBarVisible = true;
657 }
658
659 if ((getContent()->getHeight() > h) || (mHBarVisible && getContent()->getHeight() > h - mScrollbarWidth)) {
660 mVBarVisible = true;
661 }
662
664 mHBarVisible = true;
665 }
666
667 return;
668 }
669
670 switch (mHPolicy) {
671 case ScrollPolicy::ShowNever:
672 mHBarVisible = false;
673 break;
674
675 case ScrollPolicy::ShowAlways:
676 mHBarVisible = true;
677 break;
678
679 case ScrollPolicy::ShowAuto:
680 if (mVPolicy == ScrollPolicy::ShowNever) {
682 } else {
683 // (mVPolicy == ScrollPolicy::ShowAlways)
685 }
686 break;
687
688 default:
689 throwException("Horizontal scroll policy invalid.");
690 }
691
692 switch (mVPolicy) {
693 case ScrollPolicy::ShowNever:
694 mVBarVisible = false;
695 break;
696
697 case ScrollPolicy::ShowAlways:
698 mVBarVisible = true;
699 break;
700
701 case ScrollPolicy::ShowAuto:
702 if (mHPolicy == ScrollPolicy::ShowNever) {
704 } else {
705 // (mHPolicy == ScrollPolicy::ShowAlways)
707 }
708 break;
709 default:
710 throwException("Vertical scroll policy invalid.");
711 }
712 }
713
715 {
716 if (!mVBarVisible) {
717 return {0, 0, 0, 0};
718 }
719
721 }
722
724 {
725 if (!mVBarVisible) {
726 return {0, 0, 0, 0};
727 }
728
729 if (mVBarVisible && mHBarVisible) {
730 return {
732 }
733
735 }
736
738 {
739 if (!mHBarVisible) {
740 return {0, 0, 0, 0};
741 }
742
744 }
745
747 {
748 if (!mHBarVisible) {
749 return {0, 0, 0, 0};
750 }
751
752 if (mVBarVisible && mHBarVisible) {
753 return {
755 }
756
758 }
759
761 {
762 Rectangle area = Rectangle(
763 0,
764 0,
767
768 if (area.isEmpty()) {
769 return {};
770 }
771
772 return area;
773 }
774
795
816
818 {
819 if (!mVBarVisible) {
820 return {0, 0, 0, 0};
821 }
822
823 int length = 0;
824 int pos = 0;
825
826 Rectangle const barDim = getVerticalBarDimension();
827
828 if ((getContent() != nullptr) && getContent()->getHeight() != 0) {
829 length = (barDim.height * getChildrenArea().height) / getContent()->getHeight();
830 } else {
831 length = barDim.height;
832 }
833
834 length = std::max(length, mScrollbarWidth);
835
836 length = std::min(length, barDim.height);
837
838 if (getVerticalMaxScroll() != 0) {
839 pos = ((barDim.height - length) * getVerticalScrollAmount()) / getVerticalMaxScroll();
840 } else {
841 pos = 0;
842 }
843
844 return {barDim.x, barDim.y + pos, mScrollbarWidth, length};
845 }
846
848 {
849 if (!mHBarVisible) {
850 return {0, 0, 0, 0};
851 }
852
853 int length = 0;
854 int pos = 0;
855
856 Rectangle const barDim = getHorizontalBarDimension();
857
858 if ((getContent() != nullptr) && getContent()->getWidth() != 0) {
859 length = (barDim.width * getChildrenArea().width) / getContent()->getWidth();
860 } else {
861 length = barDim.width;
862 }
863
864 length = std::max(length, mScrollbarWidth);
865
866 length = std::min(length, barDim.width);
867
868 if (getHorizontalMaxScroll() != 0) {
869 pos = ((barDim.width - length) * getHorizontalScrollAmount()) / getHorizontalMaxScroll();
870 } else {
871 pos = 0;
872 }
873
874 return {barDim.x + pos, barDim.y, length, mScrollbarWidth};
875 }
876
878 {
879 if (widget != getContent()) {
880 throwException("Widget not content widget");
881 }
882
883 Widget::showWidgetPart(widget, area);
884
887 }
888
890 {
891 if (getChildrenArea().isContaining(x, y)) {
892 return getContent();
893 }
894
895 return nullptr;
896 }
897
899 {
900 if (mouseEvent.isConsumed()) {
901 return;
902 }
903
904 if (!mVBarVisible) {
905 mouseEvent.consume();
906 return;
907 }
908
910
911 mouseEvent.consume();
912 }
913
915 {
916 if (mouseEvent.isConsumed()) {
917 return;
918 }
919
920 if (!mVBarVisible) {
921 mouseEvent.consume();
922 return;
923 }
924
926
927 mouseEvent.consume();
928 }
929
931 {
932 if (mouseEvent.isConsumed()) {
933 return;
934 }
935
936 if (!mHBarVisible) {
937 mouseEvent.consume();
938 return;
939 }
940
942
943 mouseEvent.consume();
944 }
945
947 {
948 if (mouseEvent.isConsumed()) {
949 return;
950 }
951
952 if (!mHBarVisible) {
953 mouseEvent.consume();
954 return;
955 }
956
958
959 mouseEvent.consume();
960 }
961
962 void ScrollArea::setWidth(int width)
963 {
964 Widget::setWidth(width);
965 Widget* content = getContent();
966 if (content != nullptr) {
967 int const contW = std::max(getWidth(), content->getWidth());
968 content->setWidth(contW);
969 }
971 }
972
973 void ScrollArea::setHeight(int height)
974 {
975 Widget::setHeight(height);
976 Widget* content = getContent();
977 if (content != nullptr) {
978 int const contH = std::max(getHeight(), content->getHeight());
979 content->setHeight(contH);
980 }
982 }
983
984 void ScrollArea::setDimension(Rectangle const & dimension)
985 {
986 Widget::setDimension(dimension);
987 Widget* content = getContent();
988 if (content != nullptr) {
989 int const contW = std::max(getWidth(), content->getWidth());
990 content->setWidth(contW);
991 int const contH = std::max(getHeight(), content->getHeight());
992 content->setHeight(contH);
993 }
995 }
996
997 void ScrollArea::resizeToContent(bool recursion)
998 {
999 static_cast<void>(recursion);
1000 Widget* content = getContent();
1001 if (content != nullptr) {
1002 content->resizeToContent();
1003 }
1004 Size const & min = getMinSize();
1005 setWidth(min.getWidth());
1006 setHeight(min.getHeight());
1007 }
1008
1010 {
1011 Widget* content = getContent();
1012 if (content != nullptr) {
1013 content->adjustSize();
1014 }
1015 Size const & min = getMinSize();
1016 setWidth(min.getWidth());
1017 setHeight(min.getHeight());
1018 }
1019
1020 void ScrollArea::expandContent(bool recursion)
1021 {
1022 static_cast<void>(recursion);
1023 // remove that hack
1024 setWidth(getWidth());
1026
1027 Widget* content = getContent();
1028 if (content != nullptr) {
1029 content->expandContent();
1030 }
1031 checkPolicies();
1032 }
1033
1035 {
1036 mLeftButtonScrollAmount = amount;
1037 }
1038
1040 {
1041 mRightButtonScrollAmount = amount;
1042 }
1043
1045 {
1046 mUpButtonScrollAmount = amount;
1047 }
1048
1050 {
1051 mDownButtonScrollAmount = amount;
1052 }
1053
1058
1063
1065 {
1066 return mUpButtonScrollAmount;
1067 }
1068
1073
1074 void ScrollArea::setOpaque(bool opaque)
1075 {
1076 mOpaque = opaque;
1077 }
1078
1080 {
1081 return mOpaque;
1082 }
1083} // namespace fcn
Color.
Definition color.hpp:56
uint8_t a
Alpha color component (0-255).
Definition color.hpp:322
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.
virtual void fillRectangle(Rectangle const &rectangle)=0
Draws a filled rectangle.
bool isConsumed() const
Checks if the input event is consumed.
void consume()
Marks the event as consumed.
Represents a mouse event.
int getX() const
Gets the x coordinate of the mouse event.
int getY() const
Gets the y coordinate of the mouse event.
Represents a rectangular area (X, Y, Width, Height).
Definition rectangle.hpp:20
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 isEmpty() const
Checks whether the rectangle is empty or not.
Definition rectangle.cpp:71
virtual void drawHMarker(Graphics *graphics)
Draws the horizontal marker.
void mouseWheelMovedRight(MouseEvent &mouseEvent) override
Called when the mouse wheel has moved right on the widget area.
int mVerticalMarkerDragOffset
Holds the vertical markers drag offset.
int mRightButtonScrollAmount
Holds the right button scroll amount.
void setVerticalScrollAmount(int vScroll)
Sets the amount to scroll vertically.
ScrollPolicy getVerticalScrollPolicy() const
Gets the vertical scrollbar policy.
Widget * getContent() const
Gets the content.
void draw(Graphics *graphics) override
Draws the widget.
virtual void checkPolicies()
Checks the policies for the scroll bars.
Rectangle getDownButtonDimension()
Gets the down button dimension.
int mLeftButtonScrollAmount
Holds the left button scroll amount.
int getVerticalScrollAmount() const
Gets the amount that is scrolled vertically.
bool mRightButtonPressed
True if the right button is pressed, false otherwise.
void logic() override
Called for all widgets in the gui each time Gui::logic is called.
void setOpaque(bool opaque)
Sets the scroll area to be opaque, that is sets the scroll area to display its background.
Rectangle getRightButtonDimension()
Gets the right button dimension.
int getHorizontalScrollAmount() const
Gets the amount that is scrolled horizontally.
int mDownButtonScrollAmount
Holds the down button scroll amount.
ScrollPolicy mHPolicy
Holds the horizontal scroll bar policy.
bool mIsVerticalMarkerDragged
True if the vertical marked is dragged.
bool mOpaque
True if the scroll area should be opaque (that is display its background), false otherwise.
void mouseWheelMovedUp(MouseEvent &mouseEvent) override
Called when the mouse wheel has moved up on the widget area.
virtual void drawDownButton(Graphics *graphics)
Draws the down button.
void setVerticalScrollPolicy(ScrollPolicy vPolicy)
Sets the vertical scrollbar policy.
ScrollPolicy getHorizontalScrollPolicy() const
Gets the horizontal scrollbar policy.
void setHorizontalScrollAmount(int hScroll)
Sets the amount to scroll horizontally.
int getVerticalMaxScroll()
Gets the maximum amount of vertical scroll.
virtual void drawHBar(Graphics *graphics)
Draws the horizontal scroll bar.
void mouseWheelMovedDown(MouseEvent &mouseEvent) override
Called when the mouse wheel has moved down on the widget area.
bool mDownButtonPressed
True if the down button is pressed, false otherwise.
Rectangle getChildrenArea() override
Gets the area of the widget occupied by the widget's children.
void expandContent()
Expands the child widgets to the size of this widget, calls recursively all childs.
Definition widget.hpp:1440
Rectangle getUpButtonDimension()
Gets the up button dimension.
void mouseReleased(MouseEvent &mouseEvent) override
Called when a mouse button has been released on the widget area.
void setHorizontalScrollPolicy(ScrollPolicy hPolicy)
Sets the horizontal scrollbar policy.
int getDownButtonScrollAmount() const
Gets the amount to scroll in pixels when the down scroll button is pushed.
Rectangle getHorizontalMarkerDimension()
Gets the horizontal marker dimension.
void mousePressed(MouseEvent &mouseEvent) override
Called when a mouse button has been pressed on the widget area.
void setWidth(int width)
Set the width of the scroll area.
void mouseDragged(MouseEvent &mouseEvent) override
Called when the mouse has moved and the mouse has previously been pressed on the widget.
ScrollPolicy mVPolicy
Holds the vertical scroll bar policy.
Rectangle getLeftButtonDimension()
Gets the left button dimension.
void setContent(Widget *widget)
Sets the content.
void setScrollPolicy(ScrollPolicy hPolicy, ScrollPolicy vPolicy)
Sets the horizontal and vertical scrollbar policy.
void showWidgetPart(Widget *widget, Rectangle area) override
Tries to show a specific part of a widget by moving it.
virtual void drawVMarker(Graphics *graphics)
Draws the vertical marker.
void resizeToContent()
Resizes the widget's size to fit the content exactly, calls recursively all childs.
Definition widget.hpp:1417
Rectangle getHorizontalBarDimension()
Gets the horizontal scrollbar dimension.
bool mVBarVisible
True if the vertical scroll bar is visible, false otherwise.
void setScrollbarWidth(int width)
Sets the width of the scroll bars.
bool mHBarVisible
True if the horizontal scroll bar is visible, false otherwise.
virtual void drawLeftButton(Graphics *graphics)
Draws the left button.
int getUpButtonScrollAmount() const
Gets the amount to scroll in pixels when the up scroll button is pushed.
void setDimension(Rectangle const &dimension)
Set the bounds/dimension of the scroll area.
Rectangle getVerticalMarkerDimension()
Gets the vertical marker dimension.
virtual void drawBackground(Graphics *graphics)
Draws the background of the scroll area, that is the area behind the content.
int mScrollbarWidth
Holds the width of the scroll bars.
int getScrollbarWidth() const
Gets the width of the scroll bars.
Rectangle getVerticalBarDimension()
Gets the vertical scrollbar dimension.
bool mIsHorizontalMarkerDragged
True if the horizontal marked is dragged.
void setScrollAmount(int hScroll, int vScroll)
Sets the amount to scroll horizontally and vertically.
void setUpButtonScrollAmount(int amount)
Sets the amount to scroll in pixels when the up scroll button is pushed.
int mVScroll
Holds the vertical scroll amount.
void setLeftButtonScrollAmount(int amount)
Sets the amount to scroll in pixels when the left scroll button is pushed.
ScrollPolicy
Scroll policies for the horizontal and vertical scrollbar.
void setRightButtonScrollAmount(int amount)
Sets the amount to scroll in pixels when the right scroll button is pushed.
virtual void drawRightButton(Graphics *graphics)
Draws the right button.
bool mUpButtonPressed
True if the up button is pressed, false otherwise.
bool mLeftButtonPressed
True if the left button is pressed, false otherwise.
int getHorizontalMaxScroll()
Gets the maximum amount of horizontal scroll.
int mUpButtonScrollAmount
Holds the up button scroll amount.
virtual Widget * getWidgetAt(int x, int y)
Hit-test for widgets inside the scroll area.
int mHorizontalMarkerDragOffset
Holds the horizontal markers drag offset.
int getRightButtonScrollAmount() const
Gets the amount to scroll in pixels when the right scroll button is pushed.
bool isOpaque() const
Checks if the scroll area is opaque, that is if the scroll area displays its background.
int mHScroll
Holds the horizontal scroll amount.
void adjustSize() override
Resizes the widget's size to fit the content exactly.
int getLeftButtonScrollAmount() const
Gets the amount to scroll in pixels when the left scroll button is pushed.
void setDownButtonScrollAmount(int amount)
Sets the amount to scroll in pixels when the down scroll button is pushed.
virtual void drawUpButton(Graphics *graphics)
Draws the up button.
void mouseWheelMovedLeft(MouseEvent &mouseEvent) override
Called when the mouse wheel has moved left on the widget area.
void setHeight(int height)
Set the height of the scroll area.
virtual void drawVBar(Graphics *graphics)
Draws the vertical scroll bar.
Represents dimensions defined by width and height.
Definition size.hpp:18
int getHeight() const
Definition size.cpp:16
int getWidth() const
Definition size.cpp:11
Color const & getBaseColor() const
Gets the base color.
Definition widget.cpp:596
int getY() const
Gets the y coordinate of the widget.
Definition widget.cpp:209
virtual void adjustSize()
Resizes the widget's size to fit the content exactly.
Definition widget.hpp:1432
int getWidth() const
Gets the width of the widget.
Definition widget.cpp:170
void add(Widget *widget)
Adds a child to the widget.
Definition widget.cpp:1272
virtual void logic()
Called for all widgets in the gui each time Gui::logic is called.
Definition widget.hpp:378
int getX() const
Gets the x coordinate of the widget.
Definition widget.cpp:196
void setDimension(Rectangle const &dimension)
Sets the dimension of the widget.
Definition widget.cpp:223
virtual void removeAllChildren()
Remvoes all children from the widget.
Definition widget.cpp:1228
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
virtual void showWidgetPart(Widget *widget, Rectangle area)
Tries to show a specific part of a widget by moving it.
Definition widget.cpp:1204
Color const & getBackgroundColor() const
Gets the background color.
Definition widget.cpp:616
void addMouseListener(MouseListener *mouseListener)
Adds a mouse listener to the widget.
Definition widget.cpp:754
void setPosition(int x, int y)
Sets position of the widget.
Definition widget.cpp:214
void resizeToContent()
Resizes the widget's size to fit the content exactly, calls recursively all childs.
Definition widget.hpp:1417
void setWidth(int width)
Sets the width of the widget.
Definition widget.cpp:162
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
std::list< Widget * > mChildren
Holds all children of the widget.
Definition widget.hpp:1842
Color const & getForegroundColor() const
Gets the foreground color.
Definition widget.cpp:606
int getHeight() const
Gets the height of the widget.
Definition widget.cpp:183
void setHeight(int height)
Sets the height of the widget.
Definition widget.cpp:175