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 TWINE_TEXT_H
23 #define TWINE_TEXT_H
24 
25 #include "common/scummsys.h"
26 #include "common/str.h"
27 #include "common/rect.h"
28 #include "twine/shared.h"
29 
30 namespace TwinE {
31 
32 class TextEntry;
33 
34 #define TEXT_MAX_FADE_IN_CHR 32
35 
36 enum class ProgressiveTextState {
37  End = 0,
38  ContinueRunning = 1,
39  NextPage = 2
40 };
41 
42 class TwinEEngine;
43 
44 class Text {
45 private:
46  TwinEEngine *_engine;
47  void initVoxBank(TextBankId bankIdx);
54  void drawCharacter(int32 x, int32 y, uint16 character);
62  void drawCharacterShadow(int32 x, int32 y, uint16 character, int32 color, Common::Rect& dirtyRect);
63  void initProgressiveTextBuffer();
64  struct WordSize {
65  int32 inChar = 0;
66  int32 inPixel = 0;
67  };
68  struct LineCharacter {
69  int16 chr = 0;
70  int16 x = 0;
71  };
72  WordSize getWordSize(const char *completeText, char *wordBuf, int32 wordBufSize);
73  uint16 getNextChar(const char *&dialogue);
74  void processTextLine();
75  void appendProgressiveTextBuffer(const char *s, int &x, uint &i);
76  // draw next page arrow polygon
77  void renderContinueReadingTriangle();
81  void fillFadeInBuffer(int16 baseX, int16 y, const LineCharacter &chr);
88  void fadeInCharacters(int32 counter, int32 fontColor);
89 
90  TextBankId _currentBankIdx = TextBankId::None;
91 
92  LineCharacter _progressiveTextBuffer[256];
93  const char *_currentTextPosition = nullptr;
94 
95  int32 _dialTextBaseXPos = 0;
96  int32 _dialTextYPos = 0;
97 
99  const LineCharacter *_progressiveTextBufferPtr = nullptr;
100 
101  int32 _dialTextBoxCurrentLine = 0;
102  struct BlendInCharacter {
103  int16 chr = 0;
104  int16 x = 0;
105  int16 y = 0;
106  };
107  BlendInCharacter _fadeInCharacters[TEXT_MAX_FADE_IN_CHR];
108  int32 _fadeInCharactersPos = 0;
109 
111  const char *_currDialTextPtr = nullptr;
113  int32 _currDialTextSize = 0;
114 
115  char _currMenuTextBuffer[256];
116  TextBankId _currMenuTextBank = TextBankId::None;
117  TextId _currMenuTextIndex = TextId::kNone;
118 
120  int32 _dialSpaceBetween = 0;
122  int32 _dialCharSpace = 0;
124  int32 _dialTextColor = 0;
125 
127  int32 _dialTextStartColor = 0;
129  int32 _dialTextStopColor = 0;
135  int32 _dialTextStepSize = 0;
137  int32 _dialTextBufferSize = 0;
138 
139  Common::Rect _dialTextBox { 0, 0, 0, 0};
140 
141  int32 _dialTextBoxLines = 0; // dialogueBoxParam1
142  int32 _dialTextBoxMaxX = 0; // dialogueBoxParam2
143 
144  bool _isShiftJIS = false;
145  bool _isVisualRTL = false;
146 
147  bool displayText(TextId index, bool showText, bool playVox, bool loop);
148 public:
149  Text(TwinEEngine *engine);
150  ~Text();
151 
152  static const int32 lineHeight = 38;
153 
154  // TODO: refactor all this variables and related functions
155  bool _hasValidTextHandle = false;
156  // renders a triangle if the next side of the text can get activated
157  bool _renderTextTriangle = false;
158  bool _drawTextBoxBackground = false;
159  bool _hasHiddenVox = false; // printTextVar5
160  int32 _voxHiddenIndex = 0;
161  // ---
162 
163  const TextEntry *_currDialTextEntry = nullptr; // ordered entry
164  Common::String _currentVoxBankFile;
165  // used for the android version (dotemu)
166  Common::String _currentOggBaseFile;
167 
168  bool _showDialogueBubble = true;
169 
174  void initDial(TextBankId bankIdx);
175  void initSceneTextBank();
176  inline TextBankId textBank() const {
177  return _currentBankIdx;
178  }
179 
186  void drawText(int32 x, int32 y, const char *dialogue, bool shadow = false);
187 
188  bool drawTextProgressive(TextId index, bool playVox = true, bool loop = true);
189 
194  int32 getTextSize(const char *dialogue);
195  int32 getCharWidth(uint16 chr) const;
196  int32 getCharHeight(uint16 chr) const;
197 
198  void initDialogueBox();
199  void initInventoryDialogueBox();
200 
201  void initText(TextId index);
202  void initLine();
203  void initInventoryText(InventoryItems index);
204  void initItemFoundText(InventoryItems index);
205  void fadeInRemainingChars();
206  ProgressiveTextState updateProgressiveText();
207 
213  void setFontParameters(int32 spaceBetween, int32 charSpace);
214 
219  void setFontCrossColor(int32 color);
220 
225  void setFontColor(int32 color);
226 
233  void setTextCrossColor(int32 stopColor, int32 startColor, int32 stepSize);
234 
240  bool getText(TextId index);
241 
248  bool getMenuText(TextId index, char *text, uint32 textSize);
249 
250  void bigWinDial();
251  void normalWinDial();
252 
253  void drawAskQuestion(TextId index);
254  void drawHolomapLocation(TextId index);
255 
256  bool playVox(const TextEntry *text);
257  bool playVoxSimple(const TextEntry *text);
258  bool stopVox(const TextEntry *text);
259  bool initVoxToPlay(const TextEntry *text);
260  bool initVoxToPlayTextId(TextId index);
261 };
262 
263 } // namespace TwinE
264 
265 #endif
Definition: text.h:33
Definition: str.h:59
Definition: rect.h:144
Definition: twine.h:200
Definition: achievements_tables.h:27
Definition: text.h:44