OpenXcom  1.0
Open-source clone of the original X-Com
TextList.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 <vector>
21 #include <map>
22 #include "../Engine/InteractiveSurface.h"
23 #include "Text.h"
24 
25 namespace OpenXcom
26 {
27 
28 enum ArrowOrientation { ARROW_VERTICAL, ARROW_HORIZONTAL };
29 
30 class ArrowButton;
31 class ComboBox;
32 class ScrollBar;
33 
41 {
42 private:
43  std::vector< std::vector<Text*> > _texts;
44  std::vector<size_t> _columns, _rows;
45  Font *_big, *_small, *_font;
46  Language *_lang;
47  size_t _scroll, _visibleRows, _selRow;
48  Uint8 _color, _color2;
49  std::map<int, TextHAlign> _align;
50  bool _dot, _selectable, _condensed, _contrast, _wrap, _flooding;
51  Surface *_bg, *_selector;
52  ArrowButton *_up, *_down;
53  ScrollBar *_scrollbar;
54  int _margin;
55  bool _scrolling;
56  std::vector<ArrowButton*> _arrowLeft, _arrowRight;
57  int _arrowPos, _scrollPos;
58  ArrowOrientation _arrowType;
59  ActionHandler _leftClick, _leftPress, _leftRelease, _rightClick, _rightPress, _rightRelease;
60  int _arrowsLeftEdge, _arrowsRightEdge;
61  ComboBox *_comboBox;
62 
64  void updateArrows();
66  void updateVisible();
67 public:
69  TextList(int width, int height, int x = 0, int y = 0);
71  ~TextList();
73  void setX(int x);
75  void setY(int y);
77  int getArrowsLeftEdge();
79  int getArrowsRightEdge();
81  void unpress(State *state);
83  void setCellColor(size_t row, size_t column, Uint8 color);
85  void setRowColor(size_t row, Uint8 color);
87  std::wstring getCellText(size_t row, size_t column) const;
89  void setCellText(size_t row, size_t column, const std::wstring &text);
91  int getColumnX(size_t column) const;
93  int getRowY(size_t row) const;
95  int getTextHeight(size_t row) const;
97  int getNumTextLines(size_t row) const;
99  size_t getTexts() const;
101  size_t getRows() const;
103  size_t getVisibleRows() const;
105  void addRow(int cols, ...);
107  void setColumns(int cols, ...);
109  void setPalette(SDL_Color *colors, int firstcolor = 0, int ncolors = 256);
111  void initText(Font *big, Font *small, Language *lang);
113  void setHeight(int height);
115  void setColor(Uint8 color);
117  Uint8 getColor() const;
119  void setSecondaryColor(Uint8 color);
121  Uint8 getSecondaryColor() const;
123  void setWordWrap(bool wrap);
125  void setHighContrast(bool contrast);
127  void setAlign(TextHAlign align, int col = -1);
129  void setDot(bool dot);
131  void setSelectable(bool selectable);
133  void setBig();
135  void setSmall();
137  void setCondensed(bool condensed);
139  void setBackground(Surface *bg);
141  unsigned int getSelectedRow() const;
143  void setMargin(int margin);
145  int getMargin() const;
147  void setArrowColor(Uint8 color);
149  void setArrowColumn(int pos, ArrowOrientation type);
151  void onLeftArrowClick(ActionHandler handler);
153  void onLeftArrowPress(ActionHandler handler);
155  void onLeftArrowRelease(ActionHandler handler);
157  void onRightArrowClick(ActionHandler handler);
159  void onRightArrowPress(ActionHandler handler);
161  void onRightArrowRelease(ActionHandler handler);
163  void clearList();
165  void scrollUp(bool toMax, bool scrollByWheel = false);
167  void scrollDown(bool toMax, bool scrollByWheel = false);
169  void setScrolling(bool scrolling, int scrollPos = 4);
171  void draw();
173  void blit(Surface *surface);
175  void think();
177  void handle(Action *action, State *state);
179  void mousePress(Action *action, State *state);
181  void mouseRelease(Action *action, State *state);
183  void mouseClick(Action *action, State *state);
185  void mouseOver(Action *action, State *state);
187  void mouseOut(Action *action, State *state);
189  size_t getScroll();
191  void scrollTo(size_t scroll);
193  void setComboBox(ComboBox *comboBox);
195  ComboBox *getComboBox() const;
196  void setBorderColor(Uint8 color);
197  int getScrollbarColor();
199  void setFlooding(bool flooding);
200 };
201 
202 }
void setCondensed(bool condensed)
Sets whether to condense columns instead of a table like layout.
Definition: TextList.cpp:657
Container for all the information associated with a given user action, like mouse clicks...
Definition: Action.h:32
void setMargin(int margin)
Sets the margin of the text list.
Definition: TextList.cpp:693
int getNumTextLines(size_t row) const
Gets the number of lines in the wrapped text for the specified row.
Definition: TextList.cpp:230
void setBorderColor(Uint8 color)
Sets the border colour of the surface.
Definition: TextList.cpp:1256
A game state that receives user input and reacts accordingly.
Definition: State.h:43
void setHeight(int height)
Sets the height of the surface.
Definition: TextList.cpp:496
Surface that the user can interact with.
Definition: InteractiveSurface.h:37
Horizontal scrollbar control to select from a range of values.
Definition: ScrollBar.h:30
List of Text&#39;s split into columns.
Definition: TextList.h:40
ComboBox * getComboBox() const
Check for a combobox.
Definition: TextList.cpp:1251
void setColor(Uint8 color)
Sets the text color of the text list.
Definition: TextList.cpp:510
void think()
Thinks arrow buttons.
Definition: TextList.cpp:1053
size_t getVisibleRows() const
Gets the amount of visible rows in the list.
Definition: TextList.cpp:257
void setColumns(int cols,...)
Sets the columns in the text list.
Definition: TextList.cpp:422
int getColumnX(size_t column) const
Gets the X position of a certain column.
Definition: TextList.cpp:200
void setBackground(Surface *bg)
Sets the background for the selector.
Definition: TextList.cpp:683
void draw()
Draws the text onto the text list.
Definition: TextList.cpp:934
void onRightArrowPress(ActionHandler handler)
Hooks an action handler to a mouse press over the right arrows.
Definition: TextList.cpp:788
void setDot(bool dot)
Sets whether to separate columns with dots.
Definition: TextList.cpp:607
void blit(Surface *surface)
Blits the text list onto another surface.
Definition: TextList.cpp:969
Uint8 getSecondaryColor() const
Gets the secondary color of the text list.
Definition: TextList.cpp:547
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:724
std::wstring getCellText(size_t row, size_t column) const
Gets the text of a certain cell.
Definition: TextList.cpp:178
void setWordWrap(bool wrap)
Sets the text list&#39;s wordwrap setting.
Definition: TextList.cpp:558
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:863
Contains strings used throughout the game for localization.
Definition: Language.h:39
int getArrowsLeftEdge()
Gets the arrowsLeftEdge.
Definition: TextList.cpp:115
void mouseOver(Action *action, State *state)
Special handling for mouse hovering.
Definition: TextList.cpp:1149
void setBig()
Sets the text size to big.
Definition: TextList.cpp:625
Text button with a list dropdown when pressed.
Definition: ComboBox.h:36
void setX(int x)
Sets the X position of the surface.
Definition: TextList.cpp:87
int getRowY(size_t row) const
Gets the Y position of a certain row.
Definition: TextList.cpp:210
Takes care of loading and storing each character in a sprite font.
Definition: Font.h:45
size_t getRows() const
Gets the amount of rows in the list.
Definition: TextList.cpp:248
void handle(Action *action, State *state)
Handles arrow buttons.
Definition: TextList.cpp:1019
void setSmall()
Sets the text size to small.
Definition: TextList.cpp:640
~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:1205
void onRightArrowClick(ActionHandler handler)
Hooks an action handler to a mouse click on the right arrows.
Definition: TextList.cpp:775
void onLeftArrowClick(ActionHandler handler)
Hooks an action handler to a mouse click on the left arrows.
Definition: TextList.cpp:736
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:538
void mouseClick(Action *action, State *state)
Special handling for mouse clicks.
Definition: TextList.cpp:1124
void onLeftArrowRelease(ActionHandler handler)
Hooks an action handler to a mouse release over the left arrows.
Definition: TextList.cpp:762
size_t getScroll()
get the scroll depth
Definition: TextList.cpp:1219
Element that is blit (rendered) onto the screen.
Definition: Surface.h:36
unsigned int getSelectedRow() const
Gets the selected row in the list.
Definition: TextList.cpp:667
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:35
void unpress(State *state)
Unpresses the surface.
Definition: TextList.cpp:133
void clearList()
Clears the list.
Definition: TextList.cpp:813
void initText(Font *big, Font *small, Language *lang)
Initializes the resources for the text list.
Definition: TextList.cpp:476
void scrollTo(size_t scroll)
set the scroll depth
Definition: TextList.cpp:1228
void setScrolling(bool scrolling, int scrollPos=4)
Sets the list scrolling.
Definition: TextList.cpp:919
void setComboBox(ComboBox *comboBox)
Attaches this button to a combobox.
Definition: TextList.cpp:1242
void onRightArrowRelease(ActionHandler handler)
Hooks an action handler to a mouse release over the right arrows.
Definition: TextList.cpp:801
void scrollUp(bool toMax, bool scrollByWheel=false)
Scrolls the list up.
Definition: TextList.cpp:834
size_t getTexts() const
Gets the amount of text in the list.
Definition: TextList.cpp:239
void onLeftArrowPress(ActionHandler handler)
Hooks an action handler to a mouse press over the left arrows.
Definition: TextList.cpp:749
int getTextHeight(size_t row) const
Gets the height of the row text in pixels.
Definition: TextList.cpp:220
Uint8 getColor() const
Gets the text color of the text list.
Definition: TextList.cpp:529
void setPalette(SDL_Color *colors, int firstcolor=0, int ncolors=256)
Sets the palette of the text list.
Definition: TextList.cpp:442
void mouseRelease(Action *action, State *state)
Special handling for mouse releases.
Definition: TextList.cpp:1104
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:1074
void setFlooding(bool flooding)
Allows the cell to flood into other columns.
Definition: TextList.cpp:1268
void addRow(int cols,...)
Adds a new row to the text list.
Definition: TextList.cpp:268
void setAlign(TextHAlign align, int col=-1)
Sets the text horizontal alignment of the text list.
Definition: TextList.cpp:587
void setArrowColor(Uint8 color)
Sets the arrow color of the text list.
Definition: TextList.cpp:711
void setHighContrast(bool contrast)
Sets the text list&#39;s high contrast color setting.
Definition: TextList.cpp:568
int getMargin() const
Gets the margin of the text list.
Definition: TextList.cpp:702
void setSelectable(bool selectable)
Sets whether the list is selectable.
Definition: TextList.cpp:617
Definition: BaseInfoState.cpp:40
void setCellText(size_t row, size_t column, const std::wstring &text)
Sets the text of a certain cell.
Definition: TextList.cpp:189