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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef BLADERUNNER_UI_DROPDOWN_H
24 #define BLADERUNNER_UI_DROPDOWN_H
25 
26 #include "bladerunner/color.h"
27 #include "bladerunner/ui/ui_component.h"
28 
29 #include "common/array.h"
30 #include "common/rect.h"
31 #include "common/str.h"
32 
33 namespace BladeRunner {
34 
35 class BladeRunnerEngine;
36 class UIImagePicker;
37 class UIScrollBox;
38 
39 typedef void UIDropDownLineSelectedCallback(void *callbackData, void *source, int data, int mouseButton);
40 typedef void UIDropDownGenericCallback(void *callbackData, void *source);
41 
42 class UIDropDown : public UIComponent {
43 
44 	static const int   kDropDownButtonShapeWidth   =  15;
45 	static const int   kDropDownButtonShapeHeight  =  10;
46 	static const uint8 kFrameRectPaddingPx         =   2;
47 	static const int   kFurthestLeftForScrollBar   = 495;
48 
49 	static const Color256 kColors[];
50 
51 	int            _controlLeftX;
52 	Common::String _labelStr;
53 
54 	bool           _isVisible;
55 
56 	int            _lineSelectedId;
57 	Common::String _lineSelectedStr;
58 	UIScrollBox   *_lineSelectorScrollBox;
59 	UIImagePicker *_lineDropdownBtn;
60 	//int            _lineDropdownBtnTopY;
61 	//int            _lineDropdownBtnHeight;
62 
63 	Common::Rect   _lineSelectorFrameRect;
64 	int            _lineSelectorFrameRectColor;
65 	bool           _lineSelectorFrameRectHasFocus;
66 	int            _lineSelectorScrollBoxMaxLineWidth;
67 
68 	UIDropDownLineSelectedCallback   *_ddlLineSelectedCallback;
69 	UIDropDownGenericCallback        *_ddlCancelledCallback;
70 	UIDropDownGenericCallback        *_ddlTopFrameClickCallback;
71 	void                             *_callbackData;
72 
73 	int            _mouseX;
74 	int            _mouseY;
75 
76 public:
77 	UIDropDown(BladeRunnerEngine *vm, UIDropDownLineSelectedCallback *ddlLineSelectedCallback,
78 	                                  UIDropDownGenericCallback *ddlCancelledCallback,
79 	                                  UIDropDownGenericCallback *ddlTopFrameClickCallback,
80 	                                  void *callbackData,
81 		                              Common::String labelStr,
82 	                                  int controlLeftX,
83 	                                  int controlTopY,
84 	                                  int scrollBoxMaxLineCount);
85 	~UIDropDown() override;
86 
87 	void draw(Graphics::Surface &surface) override;
88 
89 	void handleMouseMove(int mouseX, int mouseY) override;
90 	void handleMouseDown(bool alternateButton) override;
91 	void handleMouseUp(bool alternateButton) override;
92 	void handleMouseScroll(int direction) override;
93 
94 	void show();
95 	void hide();
96 	bool isVisible();
97 	bool isDropDownMenuExpanded();
98 
99 	void activate();
100 	void deactivate();
101 
102 	void clearLines();
103 	void addLine(const Common::String &text, int lineData);
104 	void addLine(const char *text, int lineData);
105 
106 	void sortLines();
107 
108 	void setLabelStr(Common::String newLabel);
109 	void setControlLeft(int controlLeftX);
110 
111 	Common::String getLineSelectedStr();
112 
113 private:
114 	static void mouseDownLDBCallback(int buttonId, void *callbackData);
115 	static void scrollBoxLineSelectCallback(void *callbackData, void *source, int lineData, int mouseButton);
116 
117 	void onButtonPressed(int buttonId);
118 
119 	void showSelectionDropdown(bool showToggle);
120 };
121 
122 } // End of namespace BladeRunner
123 
124 #endif
125