ScummVM API documentation
ui_scroll_box.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef BLADERUNNER_UI_SCROLLBOX_H
23 #define BLADERUNNER_UI_SCROLLBOX_H
24 
25 #include "bladerunner/color.h"
26 #include "bladerunner/ui/ui_component.h"
27 
28 #include "common/array.h"
29 #include "common/rect.h"
30 #include "common/str.h"
31 
32 namespace BladeRunner {
33 
34 typedef void UIScrollBoxClickedCallback(void *callbackData, void *source, int lineData, int mouseButton);
35 
36 class UIScrollBox : public UIComponent {
37  static const int kLineHeight = 10;
38  static const Color256 k3DFrameColors[];
39  static const Color256 kTextBackgroundColors[];
40  static const Color256 kTextColors1[];
41  static const Color256 kTextColors2[];
42  static const Color256 kTextColors3[];
43  static const Color256 kTextColors4[];
44 
45  struct Line {
46  Common::String text;
47  int lineData;
48  int flags;
49  uint32 checkboxFrame;
50  };
51 
52  int _selectedLineState;
53  int _scrollUpButtonState;
54  int _scrollDownButtonState;
55  int _scrollAreaUpState;
56  int _scrollAreaDownState;
57  int _scrollBarState;
58 
59  int _hoveredLine;
60  int _selectedLineIndex;
61 
62  bool _scrollUpButtonHover;
63  bool _scrollDownButtonHover;
64  bool _scrollAreaUpHover;
65  bool _scrollAreaDownHover;
66  bool _scrollBarHover;
67 
68  bool _mouseButton;
69 
70  UIScrollBoxClickedCallback *_lineSelectedCallback;
71  void *_callbackData;
72 
73  bool _isVisible;
74  int _style;
75  bool _center;
76 
77  uint32 _timeLastScroll;
78  uint32 _timeLastCheckbox;
79  uint32 _timeLastHighlight;
80 
81  int _highlightFrame;
82 
83  Common::Rect _rect;
84  Common::Rect _scrollBarRect;
85 
86  int _lineCount;
87  int _maxLineCount;
88  Common::Array<Line *> _lines;
89  int _maxLinesVisible;
90  int _firstLineVisible;
91 
92  bool _mouseOver;
93 
94 public:
96  UIScrollBoxClickedCallback *lineSelectedCallback,
97  void *callbackData,
98  int maxLineCount,
99  int style,
100  bool center,
101  Common::Rect rect,
102  Common::Rect scrollBarRect);
103 
104  ~UIScrollBox() override;
105 
106  void draw(Graphics::Surface &surface) override;
107 
108  void handleMouseMove(int mouseX, int mouseY) override;
109  void handleMouseDown(bool alternateButton) override;
110  void handleMouseUp(bool alternateButton) override;
111  void handleMouseScroll(int direction) override;
112 
113  void show();
114  void hide();
115  bool isVisible();
116  bool hasFocus();
117 
118  void setBoxTop(int top);
119  void setBoxLeft(int left);
120  void setBoxWidth(uint16 width);
121  void setScrollbarTop(int top);
122  void setScrollbarLeft(int left);
123  void setScrollbarWidth(uint16 width);
124 
125  int getBoxLeft();
126  uint16 getBoxWidth();
127 
128 
129  void clearLines();
130  void addLine(const Common::String &text, int lineData, int flags);
131  void addLine(const char *text, int lineData, int flags);
132  void sortLines();
133 
134  int getSelectedLineData();
135  Common::String getLineText(int lineData);
136  int getMaxLinesVisible();
137  int getLineCount();
138 
139  void checkAll();
140  void uncheckAll();
141  void toggleCheckBox(int lineData);
142 
143  bool hasLine(int lineData);
144 
145  void resetHighlight(int lineData);
146  void setFlags(int lineData, int flags);
147  void resetFlags(int lineData, int flags);
148 
149 private:
150  static int sortFunction(const void *line1, const void *line2);
151 
152  void draw3DFrame(Graphics::Surface &surface, Common::Rect rect, bool pressed, int style);
153 
154  void scrollUp();
155  void scrollDown();
156 
157  int findLine(int lineData);
158 };
159 
160 } // End of namespace BladeRunner
161 
162 #endif
Definition: str.h:59
Definition: surface.h:67
Definition: array.h:52
Definition: actor.h:31
Definition: rect.h:144
Definition: ui_component.h:40
Definition: bladerunner.h:113
Definition: color.h:47
Definition: ui_scroll_box.h:36