OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
TextList.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_TEXTLIST_H
20 #define OPENXCOM_TEXTLIST_H
21 
22 #include <vector>
23 #include <map>
24 #include "../Engine/InteractiveSurface.h"
25 #include "Text.h"
26 
27 namespace OpenXcom
28 {
29 
30 enum ArrowOrientation { ARROW_VERTICAL, ARROW_HORIZONTAL };
31 
32 class ArrowButton;
33 class ComboBox;
34 class ScrollBar;
35 
43 {
44 private:
45  std::vector< std::vector<Text*> > _texts;
46  std::vector<size_t> _columns, _rows;
47  Font *_big, *_small, *_font;
48  Language *_lang;
49  size_t _scroll, _visibleRows, _selRow;
50  Uint8 _color, _color2;
51  std::map<int, TextHAlign> _align;
52  bool _dot, _selectable, _condensed, _contrast, _wrap;
53  Surface *_bg, *_selector;
54  ArrowButton *_up, *_down;
55  ScrollBar *_scrollbar;
56  int _margin;
57  bool _scrolling;
58  std::vector<ArrowButton*> _arrowLeft, _arrowRight;
59  int _arrowPos, _scrollPos;
60  ArrowOrientation _arrowType;
61  ActionHandler _leftClick, _leftPress, _leftRelease, _rightClick, _rightPress, _rightRelease;
62  int _arrowsLeftEdge, _arrowsRightEdge;
63  ComboBox *_comboBox;
64 
66  void updateArrows();
68  void updateVisible();
69 public:
71  TextList(int width, int height, int x = 0, int y = 0);
73  ~TextList();
75  void setX(int x);
77  void setY(int y);
79  int getArrowsLeftEdge();
81  int getArrowsRightEdge();
83  void unpress(State *state);
85  void setCellColor(size_t row, size_t column, Uint8 color);
87  void setRowColor(size_t row, Uint8 color);
89  std::wstring getCellText(size_t row, size_t column) const;
91  void setCellText(size_t row, size_t column, const std::wstring &text);
93  int getColumnX(size_t column) const;
95  int getRowY(size_t row) const;
97  size_t getTexts() const;
99  size_t getRows() const;
101  size_t getVisibleRows() const;
103  void addRow(int cols, ...);
105  void setColumns(int cols, ...);
107  void setPalette(SDL_Color *colors, int firstcolor = 0, int ncolors = 256);
109  void initText(Font *big, Font *small, Language *lang);
111  void setHeight(int height);
113  void setColor(Uint8 color);
115  Uint8 getColor() const;
117  void setSecondaryColor(Uint8 color);
119  Uint8 getSecondaryColor() const;
121  void setWordWrap(bool wrap);
123  void setHighContrast(bool contrast);
125  void setAlign(TextHAlign align, int col = -1);
127  void setDot(bool dot);
129  void setSelectable(bool selectable);
131  void setBig();
133  void setSmall();
135  void setCondensed(bool condensed);
137  void setBackground(Surface *bg);
139  int getSelectedRow() const;
141  void setMargin(int margin);
143  int getMargin() const;
145  void setArrowColor(Uint8 color);
147  void setArrowColumn(int pos, ArrowOrientation type);
149  void onLeftArrowClick(ActionHandler handler);
151  void onLeftArrowPress(ActionHandler handler);
153  void onLeftArrowRelease(ActionHandler handler);
155  void onRightArrowClick(ActionHandler handler);
157  void onRightArrowPress(ActionHandler handler);
159  void onRightArrowRelease(ActionHandler handler);
161  void clearList();
163  void scrollUp(bool toMax, bool scrollByWheel = false);
165  void scrollDown(bool toMax, bool scrollByWheel = false);
167  void setScrolling(bool scrolling, int scrollPos = 4);
169  void draw();
171  void blit(Surface *surface);
173  void think();
175  void handle(Action *action, State *state);
177  void mousePress(Action *action, State *state);
179  void mouseRelease(Action *action, State *state);
181  void mouseClick(Action *action, State *state);
183  void mouseOver(Action *action, State *state);
185  void mouseOut(Action *action, State *state);
187  size_t getScroll();
189  void scrollTo(size_t scroll);
191  void setComboBox(ComboBox *comboBox);
193  ComboBox *getComboBox() const;
194 };
195 
196 }
197 
198 #endif
void setCondensed(bool condensed)
Sets whether to condense columns instead of a table like layout.
Definition: TextList.cpp:596
Uint8 getColor() const
Gets the text color of the text list.
Definition: TextList.cpp:465
Container for all the information associated with a given user action, like mouse clicks...
Definition: Action.h:34
void setMargin(int margin)
Sets the margin of the text list.
Definition: TextList.cpp:632
A game state that receives user input and reacts accordingly.
Definition: State.h:44
void setHeight(int height)
Sets the height of the surface.
Definition: TextList.cpp:432
Surface that the user can interact with.
Definition: InteractiveSurface.h:39
Horizontal scrollbar control to select from a range of values.
Definition: ScrollBar.h:32
List of Text's split into columns.
Definition: TextList.h:42
void setColor(Uint8 color)
Sets the text color of the text list.
Definition: TextList.cpp:446
void think()
Thinks arrow buttons.
Definition: TextList.cpp:955
void setColumns(int cols,...)
Sets the columns in the text list.
Definition: TextList.cpp:358
void setBackground(Surface *bg)
Sets the background for the selector.
Definition: TextList.cpp:622
void draw()
Draws the text onto the text list.
Definition: TextList.cpp:872
void onRightArrowPress(ActionHandler handler)
Hooks an action handler to a mouse press over the right arrows.
Definition: TextList.cpp:727
void setDot(bool dot)
Sets whether to separate columns with dots.
Definition: TextList.cpp:546
size_t getTexts() const
Gets the amount of text in the list.
Definition: TextList.cpp:219
int getColumnX(size_t column) const
Gets the X position of a certain column.
Definition: TextList.cpp:200
void blit(Surface *surface)
Blits the text list onto another surface.
Definition: TextList.cpp:903
size_t getRows() const
Gets the amount of rows in the list.
Definition: TextList.cpp:228
int getArrowsRightEdge()
Gets the arrowsRightEdge.
Definition: TextList.cpp:124
void setArrowColumn(int pos, ArrowOrientation type)
Sets the arrow column of the text list.
Definition: TextList.cpp:663
void setWordWrap(bool wrap)
Sets the text list's wordwrap setting.
Definition: TextList.cpp:494
void setRowColor(size_t row, Uint8 color)
Sets the text color of a certain row.
Definition: TextList.cpp:163
void scrollDown(bool toMax, bool scrollByWheel=false)
Scrolls the list down.
Definition: TextList.cpp:801
Contains strings used throughout the game for localization.
Definition: Language.h:42
int getArrowsLeftEdge()
Gets the arrowsLeftEdge.
Definition: TextList.cpp:115
void mouseOver(Action *action, State *state)
Special handling for mouse hovering.
Definition: TextList.cpp:1051
void setBig()
Sets the text size to big.
Definition: TextList.cpp:564
Text button with a list dropdown when pressed.
Definition: ComboBox.h:38
void setX(int x)
Sets the X position of the surface.
Definition: TextList.cpp:87
Takes care of loading and storing each character in a sprite font.
Definition: Font.h:40
void handle(Action *action, State *state)
Handles arrow buttons.
Definition: TextList.cpp:933
void setSmall()
Sets the text size to small.
Definition: TextList.cpp:579
int getSelectedRow() const
Gets the selected row in the list.
Definition: TextList.cpp:606
~TextList()
Cleans up the text list.
Definition: TextList.cpp:60
void mouseOut(Action *action, State *state)
Special handling for mouse hovering out.
Definition: TextList.cpp:1107
void onRightArrowClick(ActionHandler handler)
Hooks an action handler to a mouse click on the right arrows.
Definition: TextList.cpp:714
int getRowY(size_t row) const
Gets the Y position of a certain row.
Definition: TextList.cpp:210
void onLeftArrowClick(ActionHandler handler)
Hooks an action handler to a mouse click on the left arrows.
Definition: TextList.cpp:675
void setCellColor(size_t row, size_t column, Uint8 color)
Sets the text color of a certain cell.
Definition: TextList.cpp:152
void setSecondaryColor(Uint8 color)
Sets the secondary color of the text list.
Definition: TextList.cpp:474
void mouseClick(Action *action, State *state)
Special handling for mouse clicks.
Definition: TextList.cpp:1026
void onLeftArrowRelease(ActionHandler handler)
Hooks an action handler to a mouse release over the left arrows.
Definition: TextList.cpp:701
size_t getScroll()
get the scroll depth
Definition: TextList.cpp:1121
Element that is blit (rendered) onto the screen.
Definition: Surface.h:39
int getMargin() const
Gets the margin of the text list.
Definition: TextList.cpp:641
TextList(int width, int height, int x=0, int y=0)
Creates a text list with the specified size and position.
Definition: TextList.cpp:41
Button with an arrow on it.
Definition: ArrowButton.h:37
void unpress(State *state)
Unpresses the surface.
Definition: TextList.cpp:133
Uint8 getSecondaryColor() const
Gets the secondary color of the text list.
Definition: TextList.cpp:483
void clearList()
Clears the list.
Definition: TextList.cpp:752
void initText(Font *big, Font *small, Language *lang)
Initializes the resources for the text list.
Definition: TextList.cpp:412
size_t getVisibleRows() const
Gets the amount of visible rows in the list.
Definition: TextList.cpp:237
void scrollTo(size_t scroll)
set the scroll depth
Definition: TextList.cpp:1130
void setScrolling(bool scrolling, int scrollPos=4)
Sets the list scrolling.
Definition: TextList.cpp:857
void setComboBox(ComboBox *comboBox)
Attaches this button to a combobox.
Definition: TextList.cpp:1144
void onRightArrowRelease(ActionHandler handler)
Hooks an action handler to a mouse release over the right arrows.
Definition: TextList.cpp:740
void scrollUp(bool toMax, bool scrollByWheel=false)
Scrolls the list up.
Definition: TextList.cpp:772
void onLeftArrowPress(ActionHandler handler)
Hooks an action handler to a mouse press over the left arrows.
Definition: TextList.cpp:688
std::wstring getCellText(size_t row, size_t column) const
Gets the text of a certain cell.
Definition: TextList.cpp:178
ComboBox * getComboBox() const
Check for a combobox.
Definition: TextList.cpp:1153
void setPalette(SDL_Color *colors, int firstcolor=0, int ncolors=256)
Sets the palette of the text list.
Definition: TextList.cpp:378
void mouseRelease(Action *action, State *state)
Special handling for mouse releases.
Definition: TextList.cpp:1006
void setY(int y)
Sets the Y position of the surface.
Definition: TextList.cpp:101
void mousePress(Action *action, State *state)
Special handling for mouse presses.
Definition: TextList.cpp:976
void addRow(int cols,...)
Adds a new row to the text list.
Definition: TextList.cpp:248
void setAlign(TextHAlign align, int col=-1)
Sets the text horizontal alignment of the text list.
Definition: TextList.cpp:526
void setArrowColor(Uint8 color)
Sets the arrow color of the text list.
Definition: TextList.cpp:650
void setHighContrast(bool contrast)
Sets the text list's high contrast color setting.
Definition: TextList.cpp:507
void setSelectable(bool selectable)
Sets whether the list is selectable.
Definition: TextList.cpp:556
void setCellText(size_t row, size_t column, const std::wstring &text)
Sets the text of a certain cell.
Definition: TextList.cpp:189