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 
131  uint getLongest(uint *charIndex, const int16 maxWidth);
132 
137  int16 getTextWidth(const uint index, uint length) const;
138 
143  void getTextDimensions(const uint index, uint length, int16 &width, int16& height) const;
144 
145  inline Common::Rect scaleRect(const Common::Rect &rect) {
146  Common::Rect scaledRect(rect);
147  const int16 scriptWidth = g_sci->_gfxFrameout->getScriptWidth();
148  const int16 scriptHeight = g_sci->_gfxFrameout->getScriptHeight();
149  const Ratio scaleX(_xResolution, scriptWidth);
150  const Ratio scaleY(_yResolution, scriptHeight);
151  mulinc(scaledRect, scaleX, scaleY);
152  return scaledRect;
153  }
154 
155 public:
156  GfxText32(SegManager *segMan, GfxCache *fonts);
157 
161  static void init();
162 
167 
172  static int16 _xResolution;
173 
178  static int16 _yResolution;
179 
187 
191  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);
192 
196  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);
197 
201  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);
202 
203  inline int scaleUpWidth(int value) const {
204  const int scriptWidth = g_sci->_gfxFrameout->getScriptWidth();
205  return (value * scriptWidth + _xResolution - 1) / _xResolution;
206  }
207 
208  inline int scaleUpHeight(int value) const {
209  const int scriptHeight = g_sci->_gfxFrameout->getScriptHeight();
210  return (value * scriptHeight + _yResolution - 1) / _yResolution;
211  }
212 
216  void drawTextBox();
217 
225  void drawTextBox(const Common::String &text);
226 
230  void erase(const Common::Rect &rect, const bool doScaling);
231 
232  void invertRect(const reg_t bitmap, const int16 bitmapStride, const Common::Rect &rect, const uint8 foreColor, const uint8 backColor, const bool doScaling);
233 
238  void setFont(const GuiResourceId fontId);
239 
243  int16 getScaledFontHeight() const;
244 
248  uint16 getCharWidth(const uint16 charIndex, const bool doScaling) const;
249 
253  Common::Rect getTextSize(const Common::String &text, const int16 maxWidth, bool doScaling);
254 
259  int16 getTextWidth(const Common::String &text, const uint index, const uint length);
260 
264  int16 getStringWidth(const Common::String &text);
265 
270  int16 getTextCount(const Common::String &text, const uint index, const Common::Rect &textRect, const bool doScaling);
271 
276  int16 getTextCount(const Common::String &text, const uint index, const GuiResourceId fontId, const Common::Rect &textRect, const bool doScaling);
277 
283  void scrollLine(const Common::String &textLine, int numLines, uint8 color, TextAlign align, GuiResourceId fontId, ScrollDirection dir);
284 
285  bool SwitchToFont1001OnKorean(const char *text);
286 
287 };
288 
289 } // End of namespace Sci
290 
291 #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:178
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:144
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:166
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:45
int16 getScaledFontHeight() const
Definition: console.h:28
void erase(const Common::Rect &rect, const bool doScaling)
static int16 _xResolution
Definition: text32.h:172
Definition: seg_manager.h:48
GfxFont * _font
Definition: text32.h:186
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)