ScummVM API documentation
text.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program 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  * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef MEDIASTATION_TEXT_H
23 #define MEDIASTATION_TEXT_H
24 
25 #include "common/str.h"
26 
27 #include "mediastation/actor.h"
28 #include "mediastation/actors/font.h"
29 #include "mediastation/graphics.h"
30 #include "mediastation/mediascript/scriptvalue.h"
31 #include "mediastation/mediascript/scriptconstants.h"
32 
33 namespace MediaStation {
34 
35 enum TextJustification {
36  kTextJustificationLeft = 0x25c,
37  kTextJustificationRight = 0x25d,
38  kTextJustificationCenter = 0x25e
39 };
40 
41 enum TextPosition {
42  kTextPositionMiddle = 0x25e,
43  kTextPositionTop = 0x260,
44  kTextPositionBottom = 0x261
45 };
46 
47 class TextActor : public SpatialEntity {
48 public:
49  TextActor() : SpatialEntity(kActorTypeText) {};
50 
51  virtual void loadIsComplete() override;
52  virtual void readParameter(Chunk &chunk, ActorHeaderSectionType paramType) override;
53  virtual ScriptValue callMethod(BuiltInMethod methodId, Common::Array<ScriptValue> &args) override;
54  virtual void draw(DisplayContext &displayContext) override;
55  virtual uint16 findActorToAcceptKeyboardEvents(uint16 charCode, uint16 eventMask, MouseActorState &state) override;
56  virtual void keyboardEvent(const Common::Event &event) override;
57 
58 private:
59  static const uint CURSOR_CHAR_ID = 0x104;
60  bool _isEditable = false;
61  Common::String _text;
62  uint _maxLength = 0;
63  FontActor *_fontActor = nullptr;
64  TextJustification _justification = kTextJustificationLeft;
65  TextPosition _position = kTextPositionTop;
66  Common::HashMap<uint, uint> _acceptedChars;
67  uint _cursorPosition = 0;
68  uint _pressedCharCode = 0;
69  bool _cursorIsVisible = false;
70  bool _constrainToWidth = false;
71  bool _overwriteMode = false;
72 
73  void setText();
74  void addAcceptedChars(uint firstCharCode, uint lastCharCode, uint charCodeOffset = 0);
75  bool hasScriptResponse(EventType eventType, const ScriptValue &arg) const;
76 
77  int16 calcStartingXPosition();
78  int16 calcBaseline();
79  void drawCharacter(FontCharacter *glyph, int16 x, int16 y, DisplayContext &displayContext);
80  void drawCursor(int16 x, int16 y, DisplayContext &displayContext);
81  int16 calcPixelLength(const Common::String &text);
82 };
83 
84 } // End of namespace MediaStation
85 
86 #endif
Definition: str.h:59
Definition: actor.h:144
Definition: actor.h:229
Definition: actor.h:33
Definition: font.h:33
Definition: datafile.h:102
Definition: graphics.h:100
Definition: events.h:210
Definition: text.h:47
Definition: font.h:46
Definition: scriptvalue.h:35