ScummVM API documentation
text32.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 SCI_GRAPHICS_TEXT32_H
23 #define SCI_GRAPHICS_TEXT32_H
24 
25 #include "sci/engine/state.h"
26 #include "sci/graphics/celobj32.h"
27 #include "sci/graphics/frameout.h"
28 #include "sci/graphics/helpers.h"
29 
30 namespace Sci {
31 
32 enum TextAlign {
33  kTextAlignDefault = -1,
34  kTextAlignLeft = 0,
35  kTextAlignCenter = 1,
36  kTextAlignRight = 2
37 };
38 
39 enum ScrollDirection {
40  kScrollUp,
41  kScrollDown
42 };
43 
44 class GfxFont;
45 
53 class GfxText32 {
54 private:
55  SegManager *_segMan;
56  GfxCache *_cache;
57 
64  int16 _width, _height;
65 
69  uint8 _foreColor;
70 
74  uint8 _backColor;
75 
80  uint8 _skipColor;
81 
86  Common::Rect _textRect;
87 
91  Common::String _text;
92 
96  GuiResourceId _fontId;
97 
101  int16 _borderColor;
102 
107  bool _dimmed;
108 
112  TextAlign _alignment;
113 
117  Common::Point _drawPosition;
118 
119  void drawFrame(const Common::Rect &rect, const int16 size, const uint8 color, const bool doScaling);
120 
121  void drawChar(const uint16 charIndex);
122  void drawText(const uint index, uint length);
123 
129  void drawTextRTL(const char *text, uint length);
130 
138  uint getLongest(uint *charIndex, const int16 maxWidth);
139 
144  int16 getTextWidth(const uint index, uint length) const;
145 
150  void getTextDimensions(const uint index, uint length, int16 &width, int16& height) const;
151 
152  inline Common::Rect scaleRect(const Common::Rect &rect) {
153  Common::Rect scaledRect(rect);
154  const int16 scriptWidth = g_sci->_gfxFrameout->getScriptWidth();
155  const int16 scriptHeight = g_sci->_gfxFrameout->getScriptHeight();
156  const Ratio scaleX(_xResolution, scriptWidth);
157  const Ratio scaleY(_yResolution, scriptHeight);
158  mulinc(scaledRect, scaleX, scaleY);
159  return scaledRect;
160  }
161 
162 public:
163  GfxText32(SegManager *segMan, GfxCache *fonts);
164 
168  static void init();
169 
174 
179  static int16 _xResolution;
180 
185  static int16 _yResolution;
186 
194 
198  reg_t createFontBitmap(int16 width, int16 height, const Common::Rect &rect, const Common::String &text, const uint8 foreColor, const uint8 backColor, const uint8 skipColor, const GuiResourceId fontId, TextAlign alignment, const int16 borderColor, bool dimmed, const bool doScaling, const bool gc);
199 
203  reg_t createFontBitmap(const CelInfo32 &celInfo, const Common::Rect &rect, const Common::String &text, const int16 foreColor, const int16 backColor, const GuiResourceId fontId, const int16 skipColor, const int16 borderColor, const bool dimmed, const bool gc);
204 
208  reg_t createTitledFontBitmap(int16 width, int16 height, const Common::Rect &textRect, const Common::String &text, const uint8 foreColor, const uint8 backColor, const uint8 skipColor, const GuiResourceId fontId, const TextAlign alignment, const int16 borderColor, const Common::String &title, const uint8 titleForeColor, const uint8 titleBackColor, const GuiResourceId titleFontId, const bool doScaling, const bool gc);
209 
210  inline int scaleUpWidth(int value) const {
211  const int scriptWidth = g_sci->_gfxFrameout->getScriptWidth();
212  return (value * scriptWidth + _xResolution - 1) / _xResolution;
213  }
214 
215  inline int scaleUpHeight(int value) const {
216  const int scriptHeight = g_sci->_gfxFrameout->getScriptHeight();
217  return (value * scriptHeight + _yResolution - 1) / _yResolution;
218  }
219 
223  void drawTextBox();
224 
232  void drawTextBox(const Common::String &text);
233 
237  void erase(const Common::Rect &rect, const bool doScaling);
238 
239  void invertRect(const reg_t bitmap, const int16 bitmapStride, const Common::Rect &rect, const uint8 foreColor, const uint8 backColor, const bool doScaling);
240 
245  void setFont(const GuiResourceId fontId);
246 
250  int16 getScaledFontHeight() const;
251 
255  uint16 getCharWidth(const uint16 charIndex, const bool doScaling) const;
256 
260  Common::Rect getTextSize(const Common::String &text, const int16 maxWidth, bool doScaling);
261 
266  int16 getTextWidth(const Common::String &text, const uint index, const uint length);
267 
271  int16 getStringWidth(const Common::String &text);
272 
277  int16 getTextCount(const Common::String &text, const uint index, const Common::Rect &textRect, const bool doScaling);
278 
283  int16 getTextCount(const Common::String &text, const uint index, const GuiResourceId fontId, const Common::Rect &textRect, const bool doScaling);
284 
290  void scrollLine(const Common::String &textLine, int numLines, uint8 color, TextAlign align, GuiResourceId fontId, ScrollDirection dir);
291 
292  bool SwitchToFont1001OnKorean(const char *text);
293 
294 };
295 
296 } // End of namespace Sci
297 
298 #endif // SCI_GRAPHICS_TEXT32_H
reg_t createTitledFontBitmap(int16 width, int16 height, const Common::Rect &textRect, const Common::String &text, const uint8 foreColor, const uint8 backColor, const uint8 skipColor, const GuiResourceId fontId, const TextAlign alignment, const int16 borderColor, const Common::String &title, const uint8 titleForeColor, const uint8 titleBackColor, const GuiResourceId titleFontId, const bool doScaling, const bool gc)
Definition: str.h:59
static int16 _yResolution
Definition: text32.h:185
int16 getTextCount(const Common::String &text, const uint index, const Common::Rect &textRect, const bool doScaling)
Definition: text32.h:53
SciEngine * g_sci
void drawTextBox()
Definition: rect.h:536
Common::Rect getTextSize(const Common::String &text, const int16 maxWidth, bool doScaling)
static void init()
Definition: rational.h:40
reg_t _bitmap
Definition: text32.h:173
void scrollLine(const Common::String &textLine, int numLines, uint8 color, TextAlign align, GuiResourceId fontId, ScrollDirection dir)
Definition: celobj32.h:64
int16 getStringWidth(const Common::String &text)
Definition: scifont.h:37
Definition: cache.h:38
Definition: rect.h:144
int16 getScaledFontHeight() const
Definition: console.h:28
void erase(const Common::Rect &rect, const bool doScaling)
static int16 _xResolution
Definition: text32.h:179
Definition: seg_manager.h:48
GfxFont * _font
Definition: text32.h:193
void setFont(const GuiResourceId fontId)
Definition: vm_types.h:39
uint16 getCharWidth(const uint16 charIndex, const bool doScaling) const
reg_t createFontBitmap(int16 width, int16 height, const Common::Rect &rect, const Common::String &text, const uint8 foreColor, const uint8 backColor, const uint8 skipColor, const GuiResourceId fontId, TextAlign alignment, const int16 borderColor, bool dimmed, const bool doScaling, const bool gc)