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 #include "../Engine/Unicode.h"
23 
24 namespace OpenXcom
25 {
26 
27 class Timer;
28 enum TextEditConstraint { TEC_NONE, TEC_NUMERIC_POSITIVE, TEC_NUMERIC };
29 
36 {
37 private:
38  Text *_text, *_caret;
39  UString _value;
40  bool _blink, _modal;
41  Timer *_timer;
42  UCode _char;
43  size_t _caretPos;
44  TextEditConstraint _textEditConstraint;
45  ActionHandler _change;
46  State *_state;
48  bool exceedsMaxWidth(UCode c) const;
50  bool isValidChar(UCode c) const;
51 public:
53  TextEdit(State *state, int width, int height, int x = 0, int y = 0);
55  ~TextEdit();
57  void handle(Action *action, State *state);
59  void setFocus(bool focus, bool modal = true);
61  void setBig();
63  void setSmall();
65  void initText(Font *big, Font *small, Language *lang);
67  void setText(const std::string &text);
69  std::string getText() const;
71  void setWordWrap(bool wrap);
73  void setInvert(bool invert);
75  void setHighContrast(bool contrast);
77  void setAlign(TextHAlign align);
79  void setVerticalAlign(TextVAlign valign);
81  void setConstraint(TextEditConstraint constraint);
83  void setColor(Uint8 color);
85  Uint8 getColor() const;
87  void setSecondaryColor(Uint8 color);
89  Uint8 getSecondaryColor() const;
91  void setPalette(SDL_Color *colors, int firstcolor = 0, int ncolors = 256);
93  void think();
95  void blink();
97  void draw();
99  void mousePress(Action *action, State *state);
101  void keyboardPress(Action *action, State *state);
103  void onChange(ActionHandler handler);
104 };
105 
106 }
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 setText(const std::string &text)
Sets the text&#39;s string.
Definition: TextEdit.cpp:145
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:44
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
std::string getText() const
Gets the text edit&#39;s string.
Definition: TextEdit.cpp:156
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
void setVerticalAlign(TextVAlign valign)
Sets the text edit&#39;s vertical alignment.
Definition: TextEdit.cpp:209
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:456
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:46
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:416
void invert(Uint8 mid)
Inverts the surface&#39;s colors.
Definition: Surface.cpp:592
void onChange(ActionHandler handler)
Hooks an action handler to when the slider changes.
Definition: TextEdit.cpp:555
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:35
void setAlign(TextHAlign align)
Sets the text edit&#39;s horizontal alignment.
Definition: TextEdit.cpp:199
Definition: BaseInfoState.cpp:40