ScummVM API documentation
ui_dropdown.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_DROPDOWN_H
23 #define BLADERUNNER_UI_DROPDOWN_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 class BladeRunnerEngine;
35 class UIImagePicker;
36 class UIScrollBox;
37 
38 typedef void UIDropDownLineSelectedCallback(void *callbackData, void *source, int data, int mouseButton);
39 typedef void UIDropDownGenericCallback(void *callbackData, void *source);
40 
41 class UIDropDown : public UIComponent {
42 
43  static const int kDropDownButtonShapeWidth = 15;
44  static const int kDropDownButtonShapeHeight = 10;
45  static const uint8 kFrameRectPaddingPx = 2;
46  static const int kFurthestLeftForScrollBar = 495;
47 
48  static const Color256 kColors[];
49 
50  int _controlLeftX;
51  Common::String _labelStr;
52 
53  bool _isVisible;
54 
55  int _lineSelectedId;
56  Common::String _lineSelectedStr;
57  UIScrollBox *_lineSelectorScrollBox;
58  UIImagePicker *_lineDropdownBtn;
59  //int _lineDropdownBtnTopY;
60  //int _lineDropdownBtnHeight;
61 
62  Common::Rect _lineSelectorFrameRect;
63  int _lineSelectorFrameRectColor;
64  bool _lineSelectorFrameRectHasFocus;
65  int _lineSelectorScrollBoxMaxLineWidth;
66 
67  UIDropDownLineSelectedCallback *_ddlLineSelectedCallback;
68  UIDropDownGenericCallback *_ddlCancelledCallback;
69  UIDropDownGenericCallback *_ddlTopFrameClickCallback;
70  void *_callbackData;
71 
72  int _mouseX;
73  int _mouseY;
74 
75 public:
76  UIDropDown(BladeRunnerEngine *vm, UIDropDownLineSelectedCallback *ddlLineSelectedCallback,
77  UIDropDownGenericCallback *ddlCancelledCallback,
78  UIDropDownGenericCallback *ddlTopFrameClickCallback,
79  void *callbackData,
80  Common::String labelStr,
81  int controlLeftX,
82  int controlTopY,
83  int scrollBoxMaxLineCount);
84  ~UIDropDown() override;
85 
86  void draw(Graphics::Surface &surface) override;
87 
88  void handleMouseMove(int mouseX, int mouseY) override;
89  void handleMouseDown(bool alternateButton) override;
90  void handleMouseUp(bool alternateButton) override;
91  void handleMouseScroll(int direction) override;
92 
93  void show();
94  void hide();
95  bool isVisible();
96  bool isDropDownMenuExpanded();
97 
98  void activate();
99  void deactivate();
100 
101  void clearLines();
102  void addLine(const Common::String &text, int lineData);
103  void addLine(const char *text, int lineData);
104 
105  void sortLines();
106 
107  void setLabelStr(Common::String newLabel);
108  void setControlLeft(int controlLeftX);
109 
110  Common::String getLineSelectedStr();
111 
112 private:
113  static void mouseDownLDBCallback(int buttonId, void *callbackData);
114  static void scrollBoxLineSelectCallback(void *callbackData, void *source, int lineData, int mouseButton);
115 
116  void onButtonPressed(int buttonId);
117 
118  void showSelectionDropdown(bool showToggle);
119 };
120 
121 } // End of namespace BladeRunner
122 
123 #endif
Definition: str.h:59
Definition: surface.h:67
Definition: actor.h:31
Definition: rect.h:144
Definition: ui_dropdown.h:41
Definition: ui_image_picker.h:40
Definition: ui_component.h:40
Definition: bladerunner.h:113
Definition: color.h:47
Definition: ui_scroll_box.h:36