OpenXcom  1.0
Open-source clone of the original X-Com
TextEdit.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 "Text.h"
22 
23 namespace OpenXcom
24 {
25 
26 class Timer;
27 enum TextEditConstraint { TEC_NONE, TEC_NUMERIC_POSITIVE, TEC_NUMERIC };
28 
35 {
36 private:
37  Text *_text, *_caret;
38  std::wstring _value;
39  bool _blink, _modal;
40  Timer *_timer;
41  wchar_t _ascii;
42  size_t _caretPos;
43  TextEditConstraint _textEditConstraint;
44  ActionHandler _change;
45  State *_state;
47  bool exceedsMaxWidth(wchar_t c);
49  bool isValidChar(Uint16 key);
50 public:
52  TextEdit(State *state, int width, int height, int x = 0, int y = 0);
54  ~TextEdit();
56  void handle(Action *action, State *state);
58  void setFocus(bool focus, bool modal = true);
60  void setBig();
62  void setSmall();
64  void initText(Font *big, Font *small, Language *lang);
66  void setText(const std::wstring &text);
68  std::wstring getText() const;
70  void setWordWrap(bool wrap);
72  void setInvert(bool invert);
74  void setHighContrast(bool contrast);
76  void setAlign(TextHAlign align);
78  void setVerticalAlign(TextVAlign valign);
80  void setConstraint(TextEditConstraint constraint);
82  void setColor(Uint8 color);
84  Uint8 getColor() const;
86  void setSecondaryColor(Uint8 color);
88  Uint8 getSecondaryColor() const;
90  void setPalette(SDL_Color *colors, int firstcolor = 0, int ncolors = 256);
92  void think();
94  void blink();
96  void draw();
98  void mousePress(Action *action, State *state);
100  void keyboardPress(Action *action, State *state);
102  void onChange(ActionHandler handler);
103 };
104 
105 }
Container for all the information associated with a given user action, like mouse clicks...
Definition: Action.h:32
void setSmall()
Sets the text size to small.
Definition: TextEdit.cpp:121
void setPalette(SDL_Color *colors, int firstcolor=0, int ncolors=256)
Sets the text edit&#39;s palette.
Definition: TextEdit.cpp:270
void setSecondaryColor(Uint8 color)
Sets the text edit&#39;s secondary color.
Definition: TextEdit.cpp:250
void setWordWrap(bool wrap)
Sets the text edit&#39;s wordwrap setting.
Definition: TextEdit.cpp:167
A game state that receives user input and reacts accordingly.
Definition: State.h:43
void setConstraint(TextEditConstraint constraint)
Sets the text edit constraint.
Definition: TextEdit.cpp:218
TextEdit(State *state, int width, int height, int x=0, int y=0)
Creates a new text edit with the specified size and position.
Definition: TextEdit.cpp:37
void think()
Handles the timers.
Definition: TextEdit.cpp:280
Timer used to run code in fixed intervals.
Definition: Timer.h:35
Surface that the user can interact with.
Definition: InteractiveSurface.h:37
void setFocus(bool focus, bool modal=true)
Sets focus on this text edit.
Definition: TextEdit.cpp:82
void initText(Font *big, Font *small, Language *lang)
Initializes the text edit&#39;s resources.
Definition: TextEdit.cpp:135
Text string displayed on screen.
Definition: Text.h:40
void setBig()
Sets the text size to big.
Definition: TextEdit.cpp:112
std::wstring getText() const
Gets the text edit&#39;s string.
Definition: TextEdit.cpp:156
void setVerticalAlign(TextVAlign valign)
Sets the text edit&#39;s vertical alignment.
Definition: TextEdit.cpp:209
void setText(const std::wstring &text)
Sets the text&#39;s string.
Definition: TextEdit.cpp:145
void setHighContrast(bool contrast)
Sets the text edit&#39;s high contrast color setting.
Definition: TextEdit.cpp:188
void setInvert(bool invert)
Sets the text edit&#39;s color invert setting.
Definition: TextEdit.cpp:177
void keyboardPress(Action *action, State *state)
Special handling for keyboard presses.
Definition: TextEdit.cpp:457
Contains strings used throughout the game for localization.
Definition: Language.h:39
Takes care of loading and storing each character in a sprite font.
Definition: Font.h:45
void blink()
Plays the blinking animation.
Definition: TextEdit.cpp:289
void draw()
Draws the text edit.
Definition: TextEdit.cpp:299
~TextEdit()
Cleans up the text edit.
Definition: TextEdit.cpp:50
Uint8 getColor() const
Gets the text edit&#39;s color.
Definition: TextEdit.cpp:239
void setColor(Uint8 color)
Sets the text edit&#39;s color.
Definition: TextEdit.cpp:229
void mousePress(Action *action, State *state)
Special handling for mouse presses.
Definition: TextEdit.cpp:417
void invert(Uint8 mid)
Inverts the surface&#39;s colors.
Definition: Surface.cpp:552
void onChange(ActionHandler handler)
Hooks an action handler to when the slider changes.
Definition: TextEdit.cpp:556
void handle(Action *action, State *state)
Handle focus.
Definition: TextEdit.cpp:65
Uint8 getSecondaryColor() const
Gets the text edit&#39;s secondary color.
Definition: TextEdit.cpp:259
Editable version of Text.
Definition: TextEdit.h:34
void setAlign(TextHAlign align)
Sets the text edit&#39;s horizontal alignment.
Definition: TextEdit.cpp:199
Definition: BaseInfoState.cpp:40