OpenXcom  1.0
Open-source clone of the original X-Com
ComboBox.h
1 #pragma once
2 /*
3  * Copyright 2010-2016 OpenXcom Developers.
4  *
5  * This file is part of OpenXcom.
6  *
7  * OpenXcom 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  * OpenXcom 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 OpenXcom. If not, see <http://www.gnu.org/licenses/>.
19  */
20 #include "../Engine/InteractiveSurface.h"
21 #include <vector>
22 #include <string>
23 
24 namespace OpenXcom
25 {
26 
27 class TextButton;
28 class TextList;
29 class Window;
30 class Language;
31 
37 {
38 private:
39  static const int HORIZONTAL_MARGIN;
40  static const int VERTICAL_MARGIN;
41  static const int MAX_ITEMS;
42  static const int BUTTON_WIDTH;
43  static const int TEXT_HEIGHT;
44 
45  TextButton *_button;
46  Surface *_arrow;
47  Window *_window;
48  TextList *_list;
49 
50  ActionHandler _change;
51  size_t _sel;
52  State *_state;
53  Language *_lang;
54  Uint8 _color;
55  bool _toggled;
56  bool _popupAboveButton;
57 
58  void drawArrow();
59  void setDropdown(int options);
60 public:
62  ComboBox(State *state, int width, int height, int x = 0, int y = 0, bool popupAboveButton = false);
64  ~ComboBox();
66  void setX(int x);
68  void setY(int y);
70  void setPalette(SDL_Color *colors, int firstcolor = 0, int ncolors = 256);
72  void initText(Font *big, Font *small, Language *lang);
74  void setBackground(Surface *bg);
76  void setColor(Uint8 color);
78  Uint8 getColor() const;
80  void setHighContrast(bool contrast);
82  void setArrowColor(Uint8 color);
84  size_t getSelected() const;
87  size_t getHoveredListIdx() const;
89  void setText(const std::wstring &text);
91  void setSelected(size_t sel);
93  void setOptions(const std::vector<std::string> &options);
95  void setOptions(const std::vector<std::wstring> &options);
97  void blit(Surface *surface);
99  void think();
101  void handle(Action *action, State *state);
103  void toggle(bool first = false);
105  void onChange(ActionHandler handler);
107  void onListMouseIn(ActionHandler handler);
109  void onListMouseOut(ActionHandler handler);
111  void onListMouseOver(ActionHandler handler);
112 };
113 
114 }
void initText(Font *big, Font *small, Language *lang)
Initializes the resources for the text list.
Definition: ComboBox.cpp:148
void onListMouseOver(ActionHandler handler)
Hooks an action handler to moving the mouse over the listbox when it is visible.
Definition: ComboBox.cpp:460
void setY(int y)
Sets the Y position of the surface.
Definition: ComboBox.cpp:114
Container for all the information associated with a given user action, like mouse clicks...
Definition: Action.h:32
void setOptions(const std::vector< std::string > &options)
Sets the list of options.
Definition: ComboBox.cpp:320
void setX(int x)
Sets the X position of the surface.
Definition: ComboBox.cpp:101
A game state that receives user input and reacts accordingly.
Definition: State.h:43
Box with a coloured border and custom background.
Definition: Window.h:40
void think()
Thinks arrow buttons.
Definition: ComboBox.cpp:394
ComboBox(State *state, int width, int height, int x=0, int y=0, bool popupAboveButton=false)
Creates a combo box with the specified size and position.
Definition: ComboBox.cpp:60
Surface that the user can interact with.
Definition: InteractiveSurface.h:37
void setSelected(size_t sel)
Sets the selected option in the list.
Definition: ComboBox.cpp:284
List of Text&#39;s split into columns.
Definition: TextList.h:40
size_t getHoveredListIdx() const
Gets the item that is currently hovered over in the popup list, or the current selected item if no it...
Definition: ComboBox.cpp:257
void toggle(bool first=false)
Toggles the combo box state.
Definition: ComboBox.cpp:407
void setPalette(SDL_Color *colors, int firstcolor=0, int ncolors=256)
Sets the palette of the text list.
Definition: ComboBox.cpp:133
void setArrowColor(Uint8 color)
Sets the arrow color of the text list.
Definition: ComboBox.cpp:243
Contains strings used throughout the game for localization.
Definition: Language.h:39
void setText(const std::wstring &text)
Sets the button text without changing the selected option.
Definition: ComboBox.cpp:275
Text button with a list dropdown when pressed.
Definition: ComboBox.h:36
Takes care of loading and storing each character in a sprite font.
Definition: Font.h:45
Coloured button with a text label.
Definition: TextButton.h:38
Element that is blit (rendered) onto the screen.
Definition: Surface.h:36
size_t getSelected() const
Gets the selected option in the list.
Definition: ComboBox.cpp:252
void onChange(ActionHandler handler)
Hooks an action handler to when the slider changes.
Definition: ComboBox.cpp:433
Uint8 getColor() const
Gets the border color.
Definition: ComboBox.cpp:181
void onListMouseIn(ActionHandler handler)
Hooks an action handler to moving the mouse in to the listbox when it is visible. ...
Definition: ComboBox.cpp:442
void setHighContrast(bool contrast)
Sets the high contrast color setting.
Definition: ComboBox.cpp:232
void handle(Action *action, State *state)
Handle arrow buttons.
Definition: ComboBox.cpp:369
void onListMouseOut(ActionHandler handler)
Hooks an action handler to moving the mouse out of the listbox when it is visible.
Definition: ComboBox.cpp:451
void setColor(Uint8 color)
Sets the border color.
Definition: ComboBox.cpp:168
void setBackground(Surface *bg)
Sets the background surface.
Definition: ComboBox.cpp:159
Definition: BaseInfoState.cpp:40
~ComboBox()
Cleans up the combo box.
Definition: ComboBox.cpp:89
void blit(Surface *surface)
Blits the combo box onto another surface.
Definition: ComboBox.cpp:351