OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ComboBox.h
1 /*
2  * Copyright 2010-2014 OpenXcom Developers.
3  *
4  * This file is part of OpenXcom.
5  *
6  * OpenXcom is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * OpenXcom is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 #ifndef OPENXCOM_COMBOBOX_H
20 #define OPENXCOM_COMBOBOX_H
21 
22 #include "../Engine/InteractiveSurface.h"
23 #include <vector>
24 #include <string>
25 
26 namespace OpenXcom
27 {
28 
29 class TextButton;
30 class TextList;
31 class Window;
32 class Language;
33 
39 {
40 private:
41  static const int HORIZONTAL_MARGIN;
42  static const int VERTICAL_MARGIN;
43  static const int MAX_ITEMS;
44  static const int BUTTON_WIDTH;
45  static const int TEXT_HEIGHT;
46 
47  TextButton *_button;
48  Surface *_arrow;
49  Window *_window;
50  TextList *_list;
51 
52  ActionHandler _change;
53  size_t _sel;
54  State *_state;
55  Language *_lang;
56  Uint8 _color;
57  bool _toggled;
58 
59  void drawArrow();
60  void setDropdown(int options);
61 public:
63  ComboBox(State *state, int width, int height, int x = 0, int y = 0);
65  ~ComboBox();
67  void setX(int x);
69  void setY(int y);
71  void setPalette(SDL_Color *colors, int firstcolor = 0, int ncolors = 256);
73  void initText(Font *big, Font *small, Language *lang);
75  void setBackground(Surface *bg);
77  void setColor(Uint8 color);
79  Uint8 getColor() const;
81  void setHighContrast(bool contrast);
83  void setArrowColor(Uint8 color);
85  size_t getSelected() const;
87  void setSelected(size_t sel);
89  void setOptions(const std::vector<std::string> &options);
91  void setOptions(const std::vector<std::wstring> &options);
93  void blit(Surface *surface);
95  void think();
97  void handle(Action *action, State *state);
99  void toggle(bool first = false);
101  void onChange(ActionHandler handler);
102 };
103 
104 }
105 
106 #endif
void initText(Font *big, Font *small, Language *lang)
Initializes the resources for the text list.
Definition: ComboBox.cpp:129
void setY(int y)
Sets the Y position of the surface.
Definition: ComboBox.cpp:98
Container for all the information associated with a given user action, like mouse clicks...
Definition: Action.h:34
void setOptions(const std::vector< std::string > &options)
Sets the list of options.
Definition: ComboBox.cpp:273
void setX(int x)
Sets the X position of the surface.
Definition: ComboBox.cpp:85
A game state that receives user input and reacts accordingly.
Definition: State.h:44
Box with a coloured border and custom background.
Definition: Window.h:42
void think()
Thinks arrow buttons.
Definition: ComboBox.cpp:346
Surface that the user can interact with.
Definition: InteractiveSurface.h:39
void setSelected(size_t sel)
Sets the selected option in the list.
Definition: ComboBox.cpp:242
List of Text's split into columns.
Definition: TextList.h:42
void toggle(bool first=false)
Toggles the combo box state.
Definition: ComboBox.cpp:359
void setPalette(SDL_Color *colors, int firstcolor=0, int ncolors=256)
Sets the palette of the text list.
Definition: ComboBox.cpp:114
size_t getSelected() const
Gets the selected option in the list.
Definition: ComboBox.cpp:233
void setArrowColor(Uint8 color)
Sets the arrow color of the text list.
Definition: ComboBox.cpp:224
ComboBox(State *state, int width, int height, int x=0, int y=0)
Creates a combo box with the specified size and position.
Definition: ComboBox.cpp:46
Contains strings used throughout the game for localization.
Definition: Language.h:42
Text button with a list dropdown when pressed.
Definition: ComboBox.h:38
Takes care of loading and storing each character in a sprite font.
Definition: Font.h:40
Coloured button with a text label.
Definition: TextButton.h:40
Element that is blit (rendered) onto the screen.
Definition: Surface.h:39
void onChange(ActionHandler handler)
Hooks an action handler to when the slider changes.
Definition: ComboBox.cpp:385
void setHighContrast(bool contrast)
Sets the high contrast color setting.
Definition: ComboBox.cpp:213
Uint8 getColor() const
Gets the border color.
Definition: ComboBox.cpp:162
void handle(Action *action, State *state)
Handle arrow buttons.
Definition: ComboBox.cpp:322
void setColor(Uint8 color)
Sets the border color.
Definition: ComboBox.cpp:149
void setBackground(Surface *bg)
Sets the background surface.
Definition: ComboBox.cpp:140
~ComboBox()
Cleans up the combo box.
Definition: ComboBox.cpp:73
void blit(Surface *surface)
Blits the combo box onto another surface.
Definition: ComboBox.cpp:304