FifeGUI 0.3.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// Corresponding header include
6#include "fifechan/widgets/scrollarea.hpp"
7
8// Standard library includes
9#include <algorithm>
10#include <cassert>
11#include <iostream>
12
13// Project headers (subdirs before local)
14#include "fifechan/exception.hpp"
15#include "fifechan/graphics.hpp"
16
17namespace fcn
18{
19 ScrollArea::ScrollArea()
20 {
21 addMouseListener(this);
22 }
23
24 ScrollArea::ScrollArea(Widget* content)
25 {
26 // cppcheck-suppress virtualCallInConstructor
27 setContent(content);
28 addMouseListener(this);
29 }
30
31 ScrollArea::ScrollArea(Widget* content, ScrollPolicy /*hPolicy*/, ScrollPolicy /*vPolicy*/)
32 {
33 // cppcheck-suppress virtualCallInConstructor
34 setContent(content);
35 addMouseListener(this);
36 }
37
38 ScrollArea::~ScrollArea()
39 {
40 try {
41 // cppcheck-suppress virtualCallInConstructor
42 setContent(nullptr);
43 } catch (std::exception const & e) {
44 std::cerr << "[ScrollArea] Exception in destructor: " << e.what() << "\n";
45 }
46 }
47
49 {
51
52 if (widget != nullptr) {
53 add(widget);
54 widget->setPosition(0, 0);
55 }
56
58 }
59
61 {
62 if (!mChildren.empty()) {
63 return *mChildren.begin();
64 }
65
66 return nullptr;
67 }
68
70 {
71 mHPolicy = hPolicy;
73 }
74
79
81 {
82 mVPolicy = vPolicy;
84 }
85
90
92 {
93 mHPolicy = hPolicy;
94 mVPolicy = vPolicy;
96 }
97
99 {
100 int const max = getVerticalMaxScroll();
101
102 mVScroll = vScroll;
103
104 if (vScroll > max) {
105 mVScroll = max;
106 }
107
108 if (vScroll < 0) {
109 mVScroll = 0;
110 }
111 }
112
114 {
115 return mVScroll;
116 }
117
119 {
120 int const max = getHorizontalMaxScroll();
121
122 mHScroll = hScroll;
123
124 if (hScroll > max) {
125 mHScroll = max;
126 } else if (hScroll < 0) {
127 mHScroll = 0;
128 }
129 }
130
132 {
133 return mHScroll;
134 }
135
136 void ScrollArea::setScrollAmount(int hScroll, int vScroll)
137 {
140 }
141
143 {
145
146 if (getContent() == nullptr) {
147 return 0;
148 }
149
150 int const value = getContent()->getWidth() - getChildrenArea().width + (2 * getContent()->getBorderSize());
151
152 if (value < 0) {
153 return 0;
154 }
155
156 return value;
157 }
158
160 {
162
163 if (getContent() == nullptr) {
164 return 0;
165 }
166
167 int value = 0;
168
170
171 if (value < 0) {
172 return 0;
173 }
174
175 return value;
176 }
177
179 {
180 if (width <= 0) {
181 throwException("Width should be greater then 0.");
182 }
183
184 mScrollbarWidth = width;
185 }
186
188 {
189 return mScrollbarWidth;
190 }
191
193 {
194 int const x = mouseEvent.getX();
195 int const y = mouseEvent.getY();
196
197 if (getUpButtonDimension().isContaining(x, y)) {
199 mUpButtonPressed = true;
200 } else if (getDownButtonDimension().isContaining(x, y)) {
202 mDownButtonPressed = true;
203 } else if (getLeftButtonDimension().isContaining(x, y)) {
205 mLeftButtonPressed = true;
206 } else if (getRightButtonDimension().isContaining(x, y)) {
208 mRightButtonPressed = true;
209 } else if (getVerticalMarkerDimension().isContaining(x, y)) {
212
214 } else if (getVerticalBarDimension().isContaining(x, y)) {
215 if (y < getVerticalMarkerDimension().y) {
217 getVerticalScrollAmount() - static_cast<int>((getChildrenArea().height * 0.95)));
218 } else {
220 getVerticalScrollAmount() + static_cast<int>((getChildrenArea().height * 0.95)));
221 }
222 } else if (getHorizontalMarkerDimension().isContaining(x, y)) {
225
227 } else if (getHorizontalBarDimension().isContaining(x, y)) {
228 if (x < getHorizontalMarkerDimension().x) {
230 getHorizontalScrollAmount() - static_cast<int>((getChildrenArea().width * 0.95)));
231 } else {
233 getHorizontalScrollAmount() + static_cast<int>((getChildrenArea().width * 0.95)));
234 }
235 }
236 }
237
239 {
240 mUpButtonPressed = false;
241 mDownButtonPressed = false;
242 mLeftButtonPressed = false;
243 mRightButtonPressed = false;
246
247 mouseEvent.consume();
248 }
249
251 {
253 int const pos = mouseEvent.getY() - getVerticalBarDimension().y - mVerticalMarkerDragOffset;
254 int const length = getVerticalMarkerDimension().height;
255
256 Rectangle const barDim = getVerticalBarDimension();
257
258 if ((barDim.height - length) > 0) {
259 setVerticalScrollAmount((getVerticalMaxScroll() * pos) / (barDim.height - length));
260 } else {
262 }
263 }
264
266 int const pos = mouseEvent.getX() - getHorizontalBarDimension().x - mHorizontalMarkerDragOffset;
267 int const length = getHorizontalMarkerDimension().width;
268
269 Rectangle const barDim = getHorizontalBarDimension();
270
271 if ((barDim.width - length) > 0) {
272 setHorizontalScrollAmount((getHorizontalMaxScroll() * pos) / (barDim.width - length));
273 } else {
275 }
276 }
277
278 mouseEvent.consume();
279 }
280
282 {
283 drawBackground(graphics);
284
285 if (mVBarVisible) {
286 drawUpButton(graphics);
287 drawDownButton(graphics);
288 drawVBar(graphics);
289 drawVMarker(graphics);
290 }
291
292 if (mHBarVisible) {
293 drawLeftButton(graphics);
294 drawRightButton(graphics);
295 drawHBar(graphics);
296 drawHMarker(graphics);
297 }
298
299 if (mHBarVisible && mVBarVisible) {
300 graphics->setColor(getBaseColor());
301 graphics->fillRectangle(
303 }
304 }
305
307 {
309
310 graphics->pushClipArea(dim);
311
312 int const alpha = getBackgroundColor().a;
313 Color trackColor = getBackgroundColor() - Color(0x101010);
314 trackColor.a = alpha;
315 Color shadowColor = getBackgroundColor() - Color(0x303030);
316 shadowColor.a = alpha;
317
318 graphics->setColor(trackColor);
319 graphics->fillRectangle(0, 0, dim.width, dim.height);
320
321 graphics->setColor(shadowColor);
322 graphics->drawLine(0, 0, dim.width, 0);
323
324 graphics->popClipArea();
325 }
326
328 {
330
331 graphics->pushClipArea(dim);
332
333 int const alpha = getBackgroundColor().a;
334 Color trackColor = getBackgroundColor() - Color(0x101010);
335 trackColor.a = alpha;
336 Color shadowColor = getBackgroundColor() - Color(0x303030);
337 shadowColor.a = alpha;
338
339 graphics->setColor(trackColor);
340 graphics->fillRectangle(0, 0, dim.width, dim.height);
341
342 graphics->setColor(shadowColor);
343 graphics->drawLine(0, 0, 0, dim.height);
344
345 graphics->popClipArea();
346 }
347
349 {
350 if (isOpaque()) {
351 graphics->setColor(getBackgroundColor());
352 graphics->fillRectangle(getChildrenArea());
353 }
354 }
355
357 {
358 Rectangle const dim = getUpButtonDimension();
359
360 graphics->pushClipArea(dim);
361
362 Color highlightColor;
363 Color shadowColor;
364 Color faceColor;
365 int offset = 0;
366 int const alpha = getBaseColor().a;
367
368 if (mUpButtonPressed) {
369 faceColor = getBaseColor() - Color(0x303030);
370 faceColor.a = alpha;
371 highlightColor = faceColor - Color(0x303030);
372 highlightColor.a = alpha;
373 shadowColor = getBaseColor();
374 shadowColor.a = alpha;
375
376 offset = 1;
377 } else {
378 faceColor = getBaseColor();
379 faceColor.a = alpha;
380 highlightColor = faceColor + Color(0x303030);
381 highlightColor.a = alpha;
382 shadowColor = faceColor - Color(0x303030);
383 shadowColor.a = alpha;
384
385 offset = 0;
386 }
387
388 graphics->setColor(faceColor);
389 graphics->fillRectangle(0, 0, dim.width, dim.height);
390
391 graphics->setColor(highlightColor);
392 graphics->drawLine(0, 0, dim.width - 1, 0);
393 graphics->drawLine(0, 1, 0, dim.height - 1);
394
395 graphics->setColor(shadowColor);
396 graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1);
397 graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1);
398
399 graphics->setColor(getForegroundColor());
400
401 int i = 0;
402 int const w = dim.height / 2;
403 int const h = (w / 2) + 2;
404 for (i = 0; i < w / 2; ++i) {
405 graphics->drawLine(w - i + offset, i + h + offset, w + i + offset, i + h + offset);
406 }
407
408 graphics->popClipArea();
409 }
410
412 {
413 Rectangle const dim = getDownButtonDimension();
414
415 graphics->pushClipArea(dim);
416
417 Color highlightColor;
418 Color shadowColor;
419 Color faceColor;
420 int offset = 0;
421 int const alpha = getBaseColor().a;
422
423 if (mDownButtonPressed) {
424 faceColor = getBaseColor() - Color(0x303030);
425 faceColor.a = alpha;
426 highlightColor = faceColor - Color(0x303030);
427 highlightColor.a = alpha;
428 shadowColor = getBaseColor();
429 shadowColor.a = alpha;
430
431 offset = 1;
432 } else {
433 faceColor = getBaseColor();
434 faceColor.a = alpha;
435 highlightColor = faceColor + Color(0x303030);
436 highlightColor.a = alpha;
437 shadowColor = faceColor - Color(0x303030);
438 shadowColor.a = alpha;
439
440 offset = 0;
441 }
442
443 graphics->setColor(faceColor);
444 graphics->fillRectangle(0, 0, dim.width, dim.height);
445
446 graphics->setColor(highlightColor);
447 graphics->drawLine(0, 0, dim.width - 1, 0);
448 graphics->drawLine(0, 1, 0, dim.height - 1);
449
450 graphics->setColor(shadowColor);
451 graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1);
452 graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1);
453
454 graphics->setColor(getForegroundColor());
455
456 int i = 0;
457 int const w = dim.height / 2;
458 int const h = w + 1;
459 for (i = 0; i < w / 2; ++i) {
460 graphics->drawLine(w - i + offset, -i + h + offset, w + i + offset, -i + h + offset);
461 }
462
463 graphics->popClipArea();
464 }
465
467 {
468 Rectangle const dim = getLeftButtonDimension();
469 graphics->pushClipArea(dim);
470
471 Color highlightColor;
472 Color shadowColor;
473 Color faceColor;
474 int offset = 0;
475 int const alpha = getBaseColor().a;
476
477 if (mLeftButtonPressed) {
478 faceColor = getBaseColor() - Color(0x303030);
479 faceColor.a = alpha;
480 highlightColor = faceColor - Color(0x303030);
481 highlightColor.a = alpha;
482 shadowColor = getBaseColor();
483 shadowColor.a = alpha;
484
485 offset = 1;
486 } else {
487 faceColor = getBaseColor();
488 faceColor.a = alpha;
489 highlightColor = faceColor + Color(0x303030);
490 highlightColor.a = alpha;
491 shadowColor = faceColor - Color(0x303030);
492 shadowColor.a = alpha;
493
494 offset = 0;
495 }
496
497 graphics->setColor(faceColor);
498 graphics->fillRectangle(0, 0, dim.width, dim.height);
499
500 graphics->setColor(highlightColor);
501 graphics->drawLine(0, 0, dim.width - 1, 0);
502 graphics->drawLine(0, 1, 0, dim.height - 1);
503
504 graphics->setColor(shadowColor);
505 graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1);
506 graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1);
507
508 graphics->setColor(getForegroundColor());
509
510 int i = 0;
511 int const w = dim.width / 2;
512 int const h = w - 2;
513 for (i = 0; i < w / 2; ++i) {
514 graphics->drawLine(i + h + offset, w - i + offset, i + h + offset, w + i + offset);
515 }
516
517 graphics->popClipArea();
518 }
519
521 {
523
524 graphics->pushClipArea(dim);
525
526 Color highlightColor;
527 Color shadowColor;
528 Color faceColor;
529 int offset = 0;
530 int const alpha = getBaseColor().a;
531
533 faceColor = getBaseColor() - Color(0x303030);
534 faceColor.a = alpha;
535 highlightColor = faceColor - Color(0x303030);
536 highlightColor.a = alpha;
537 shadowColor = getBaseColor();
538 shadowColor.a = alpha;
539
540 offset = 1;
541 } else {
542 faceColor = getBaseColor();
543 faceColor.a = alpha;
544 highlightColor = faceColor + Color(0x303030);
545 highlightColor.a = alpha;
546 shadowColor = faceColor - Color(0x303030);
547 shadowColor.a = alpha;
548
549 offset = 0;
550 }
551
552 graphics->setColor(faceColor);
553 graphics->fillRectangle(0, 0, dim.width, dim.height);
554
555 graphics->setColor(highlightColor);
556 graphics->drawLine(0, 0, dim.width - 1, 0);
557 graphics->drawLine(0, 1, 0, dim.height - 1);
558
559 graphics->setColor(shadowColor);
560 graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1);
561 graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1);
562
563 graphics->setColor(getForegroundColor());
564
565 int i = 0;
566 int const w = dim.width / 2;
567 int const h = w + 1;
568 for (i = 0; i < w / 2; ++i) {
569 graphics->drawLine(-i + h + offset, w - i + offset, -i + h + offset, w + i + offset);
570 }
571
572 graphics->popClipArea();
573 }
574
576 {
578 graphics->pushClipArea(dim);
579
580 int const alpha = getBaseColor().a;
581 Color faceColor = getBaseColor();
582 faceColor.a = alpha;
583 Color highlightColor = faceColor + Color(0x303030);
584 highlightColor.a = alpha;
585 Color shadowColor = faceColor - Color(0x303030);
586 shadowColor.a = alpha;
587
588 graphics->setColor(faceColor);
589 graphics->fillRectangle(1, 1, dim.width - 1, dim.height - 1);
590
591 graphics->setColor(highlightColor);
592 graphics->drawLine(0, 0, dim.width - 1, 0);
593 graphics->drawLine(0, 1, 0, dim.height - 1);
594
595 graphics->setColor(shadowColor);
596 graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1);
597 graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1);
598
599 graphics->popClipArea();
600 }
601
603 {
605 graphics->pushClipArea(dim);
606
607 int const alpha = getBaseColor().a;
608 Color faceColor = getBaseColor();
609 faceColor.a = alpha;
610 Color highlightColor = faceColor + Color(0x303030);
611 highlightColor.a = alpha;
612 Color shadowColor = faceColor - Color(0x303030);
613 shadowColor.a = alpha;
614
615 graphics->setColor(faceColor);
616 graphics->fillRectangle(1, 1, dim.width - 1, dim.height - 1);
617
618 graphics->setColor(highlightColor);
619 graphics->drawLine(0, 0, dim.width - 1, 0);
620 graphics->drawLine(0, 1, 0, dim.height - 1);
621
622 graphics->setColor(shadowColor);
623 graphics->drawLine(1, dim.height - 1, dim.width - 1, dim.height - 1);
624 graphics->drawLine(dim.width - 1, 0, dim.width - 1, dim.height - 1);
625
626 graphics->popClipArea();
627 }
628
642
644 {
645 int const w = getWidth();
646 int const h = getHeight();
647
648 mHBarVisible = false;
649 mVBarVisible = false;
650
651 if (getContent() == nullptr) {
652 mHBarVisible = (mHPolicy == ScrollPolicy::ShowAlways);
653 mVBarVisible = (mVPolicy == ScrollPolicy::ShowAlways);
654 return;
655 }
656
657 if (mHPolicy == ScrollPolicy::ShowAuto && mVPolicy == ScrollPolicy::ShowAuto) {
658 if (getContent()->getWidth() <= w && getContent()->getHeight() <= h) {
659 mHBarVisible = false;
660 mVBarVisible = false;
661 }
662
663 if (getContent()->getWidth() > w) {
664 mHBarVisible = true;
665 }
666
667 if ((getContent()->getHeight() > h) || (mHBarVisible && getContent()->getHeight() > h - mScrollbarWidth)) {
668 mVBarVisible = true;
669 }
670
672 mHBarVisible = true;
673 }
674
675 return;
676 }
677
678 switch (mHPolicy) {
679 case ScrollPolicy::ShowNever:
680 mHBarVisible = false;
681 break;
682
683 case ScrollPolicy::ShowAlways:
684 mHBarVisible = true;
685 break;
686
687 case ScrollPolicy::ShowAuto:
688 if (mVPolicy == ScrollPolicy::ShowNever) {
690 } else {
691 // (mVPolicy == ScrollPolicy::ShowAlways)
693 }
694 break;
695
696 default:
697 throwException("Horizontal scroll policy invalid.");
698 }
699
700 switch (mVPolicy) {
701 case ScrollPolicy::ShowNever:
702 mVBarVisible = false;
703 break;
704
705 case ScrollPolicy::ShowAlways:
706 mVBarVisible = true;
707 break;
708
709 case ScrollPolicy::ShowAuto:
710 if (mHPolicy == ScrollPolicy::ShowNever) {
712 } else {
713 // (mHPolicy == ScrollPolicy::ShowAlways)
715 }
716 break;
717 default:
718 throwException("Vertical scroll policy invalid.");
719 }
720 }
721
723 {
724 if (!mVBarVisible) {
725 return {0, 0, 0, 0};
726 }
727
729 }
730
732 {
733 if (!mVBarVisible) {
734 return {0, 0, 0, 0};
735 }
736
737 assert("mVBarVisible must be true here" && mVBarVisible);
738 if (mHBarVisible) {
739 return {
741 }
742
744 }
745
747 {
748 if (!mHBarVisible) {
749 return {0, 0, 0, 0};
750 }
751
753 }
754
756 {
757 if (!mHBarVisible) {
758 return {0, 0, 0, 0};
759 }
760
761 assert("mHBarVisible must be true here" && mHBarVisible);
762 if (mVBarVisible) {
763 return {
765 }
766
768 }
769
771 {
772 int const childrenWidth = std::max(0, mVBarVisible ? getWidth() - mScrollbarWidth : getWidth());
773 int const childrenHeight = std::max(0, mHBarVisible ? getHeight() - mScrollbarWidth : getHeight());
774
775 Rectangle area = Rectangle(0, 0, childrenWidth, childrenHeight);
776
777 if (area.isEmpty()) {
778 return {};
779 }
780
781 return area;
782 }
783
804
825
827 {
828 if (!mVBarVisible) {
829 return {0, 0, 0, 0};
830 }
831
832 int length = 0;
833 int pos = 0;
834
835 Rectangle const barDim = getVerticalBarDimension();
836
837 if ((getContent() != nullptr) && getContent()->getHeight() != 0) {
838 length = (barDim.height * getChildrenArea().height) / getContent()->getHeight();
839 } else {
840 length = barDim.height;
841 }
842
843 length = std::max(length, mScrollbarWidth);
844
845 length = std::min(length, barDim.height);
846
847 if (getVerticalMaxScroll() != 0) {
848 pos = ((barDim.height - length) * getVerticalScrollAmount()) / getVerticalMaxScroll();
849 } else {
850 pos = 0;
851 }
852
853 return {barDim.x, barDim.y + pos, mScrollbarWidth, length};
854 }
855
857 {
858 if (!mHBarVisible) {
859 return {0, 0, 0, 0};
860 }
861
862 int length = 0;
863 int pos = 0;
864
865 Rectangle const barDim = getHorizontalBarDimension();
866
867 if ((getContent() != nullptr) && getContent()->getWidth() != 0) {
868 length = (barDim.width * getChildrenArea().width) / getContent()->getWidth();
869 } else {
870 length = barDim.width;
871 }
872
873 length = std::max(length, mScrollbarWidth);
874
875 length = std::min(length, barDim.width);
876
877 if (getHorizontalMaxScroll() != 0) {
878 pos = ((barDim.width - length) * getHorizontalScrollAmount()) / getHorizontalMaxScroll();
879 } else {
880 pos = 0;
881 }
882
883 return {barDim.x + pos, barDim.y, length, mScrollbarWidth};
884 }
885
887 {
888 if (widget != getContent()) {
889 throwException("Widget not content widget");
890 }
891
892 Widget::showWidgetPart(widget, area);
893
896 }
897
899 {
900 if (getChildrenArea().isContaining(x, y)) {
901 return getContent();
902 }
903
904 return nullptr;
905 }
906
908 {
909 if (mouseEvent.isConsumed()) {
910 return;
911 }
912
913 if (!mVBarVisible) {
914 mouseEvent.consume();
915 return;
916 }
917
919
920 mouseEvent.consume();
921 }
922
924 {
925 if (mouseEvent.isConsumed()) {
926 return;
927 }
928
929 if (!mVBarVisible) {
930 mouseEvent.consume();
931 return;
932 }
933
935
936 mouseEvent.consume();
937 }
938
940 {
941 if (mouseEvent.isConsumed()) {
942 return;
943 }
944
945 if (!mHBarVisible) {
946 mouseEvent.consume();
947 return;
948 }
949
951
952 mouseEvent.consume();
953 }
954
956 {
957 if (mouseEvent.isConsumed()) {
958 return;
959 }
960
961 if (!mHBarVisible) {
962 mouseEvent.consume();
963 return;
964 }
965
967
968 mouseEvent.consume();
969 }
970
971 void ScrollArea::setWidth(int width)
972 {
973 Widget::setWidth(width);
974 Widget* content = getContent();
975 if (content != nullptr) {
976 int const contW = std::max(getWidth(), content->getWidth());
977 content->setWidth(contW);
978 }
980 }
981
982 void ScrollArea::setHeight(int height)
983 {
984 Widget::setHeight(height);
985 Widget* content = getContent();
986 if (content != nullptr) {
987 int const contH = std::max(getHeight(), content->getHeight());
988 content->setHeight(contH);
989 }
991 }
992
993 void ScrollArea::setDimension(Rectangle const & dimension)
994 {
995 Widget::setDimension(dimension);
996 Widget* content = getContent();
997 if (content != nullptr) {
998 int const contW = std::max(getWidth(), content->getWidth());
999 content->setWidth(contW);
1000 int const contH = std::max(getHeight(), content->getHeight());
1001 content->setHeight(contH);
1002 }
1003 checkPolicies();
1004 }
1005
1006 void ScrollArea::resizeToContent(bool recursion)
1007 {
1008 static_cast<void>(recursion);
1009 Widget* content = getContent();
1010 if (content != nullptr) {
1011 content->resizeToContent();
1012 }
1013 Size const & min = getMinSize();
1014 setWidth(min.getWidth());
1015 setHeight(min.getHeight());
1016 }
1017
1019 {
1020 Widget* content = getContent();
1021 if (content != nullptr) {
1022 content->adjustSize();
1023 }
1024 Size const & min = getMinSize();
1025 setWidth(min.getWidth());
1026 setHeight(min.getHeight());
1027 }
1028
1029 void ScrollArea::expandContent(bool recursion)
1030 {
1031 static_cast<void>(recursion);
1032 // remove that hack
1033 setWidth(getWidth());
1035
1036 Widget* content = getContent();
1037 if (content != nullptr) {
1038 content->expandContent();
1039 }
1040 checkPolicies();
1041 }
1042
1044 {
1045 mLeftButtonScrollAmount = amount;
1046 }
1047
1049 {
1050 mRightButtonScrollAmount = amount;
1051 }
1052
1054 {
1055 mUpButtonScrollAmount = amount;
1056 }
1057
1059 {
1060 mDownButtonScrollAmount = amount;
1061 }
1062
1067
1072
1074 {
1075 return mUpButtonScrollAmount;
1076 }
1077
1082
1083 void ScrollArea::setOpaque(bool opaque)
1084 {
1085 mOpaque = opaque;
1086 }
1087
1089 {
1090 return mOpaque;
1091 }
1092} // namespace fcn
Color.
Definition color.hpp:58
uint8_t a
Alpha color component (0-255).
Definition color.hpp:350
Abstract interface providing primitive drawing functions (lines, rectangles, etc.).
Definition graphics.hpp:58
virtual void popClipArea()
Removes the top most clip area from the stack.
Definition graphics.cpp:65
virtual bool pushClipArea(Rectangle area)
Pushes a clip area onto the stack.
Definition graphics.cpp:25
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 this 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:22
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:82
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.
void resizeToContent(bool recursion=true) override
Resizes the widget's size to fit the content exactly, calls recursively all childs.
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.
void setHeight(int height) override
Set the height of the scroll area.
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:1597
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 down on the widget 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.
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.
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.
void setDimension(Rectangle const &dimension) override
Set the bounds/dimension of the scroll area.
void setWidth(int width) override
Set the width of the scroll area.
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.
virtual void drawVBar(Graphics *graphics)
Draws the vertical scroll bar.
Represents dimensions defined by width and height.
Definition size.hpp:21
int getHeight() const
Definition size.cpp:19
int getWidth() const
Definition size.cpp:14
Color const & getBaseColor() const
Gets the base color.
Definition widget.cpp:742
int getY() const
Gets the y coordinate of the widget.
Definition widget.cpp:301
virtual void adjustSize()
Resizes the widget's size to fit the content exactly.
Definition widget.hpp:1587
int getWidth() const
Gets the width of the widget.
Definition widget.cpp:252
void add(Widget *widget)
Adds a child to the widget.
Definition widget.cpp:1446
virtual void logic()
Called for all widgets in the GUI each time Gui::logic is called.
Definition widget.hpp:467
int getX() const
Gets the x coordinate of the widget.
Definition widget.cpp:288
virtual void setDimension(Rectangle const &dimension)
Sets the dimension of the widget.
Definition widget.cpp:315
virtual void removeAllChildren()
Remvoes all children from the widget.
Definition widget.cpp:1402
Widget()
Constructor.
Definition widget.cpp:52
void expandContent()
Expands the child widgets to the size of this widget, calls recursively all childs.
Definition widget.hpp:1597
virtual void showWidgetPart(Widget *widget, Rectangle area)
Tries to show a specific part of a widget by moving it.
Definition widget.cpp:1378
Color const & getBackgroundColor() const
Gets the background color.
Definition widget.cpp:762
void addMouseListener(MouseListener *mouseListener)
Adds a mouse listener to the widget.
Definition widget.cpp:907
void setPosition(int x, int y)
Sets position of the widget.
Definition widget.cpp:306
virtual void setWidth(int width)
Sets the width of the widget.
Definition widget.cpp:244
unsigned int getBorderSize() const
Gets the size of the widget's border.
Definition widget.cpp:474
Size const & getMinSize() const
Gets the minimal dimension of the widget.
Definition widget.cpp:369
std::list< Widget * > mChildren
Holds all children of the widget.
Definition widget.hpp:2099
Color const & getForegroundColor() const
Gets the foreground color.
Definition widget.cpp:752
virtual void resizeToContent(bool recursion=true)
Resizes the widget's size to fit the content exactly, calls recursively all childs.
Definition widget.hpp:1580
int getHeight() const
Gets the height of the widget.
Definition widget.cpp:265
virtual void setHeight(int height)
Sets the height of the widget.
Definition widget.cpp:257
Used replacement tokens by configure_file():
void throwException(std::string const &message, std::source_location location=std::source_location::current())
Throw an Exception capturing the current source location.