ScummVM API documentation
hypertext.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 NANCY_MISC_HYPERTEXT_H
23 #define NANCY_MISC_HYPERTEXT_H
24 
25 #include "engines/nancy/renderobject.h"
26 #include "engines/nancy/graphics.h"
27 
28 namespace Nancy {
29 
30 class Font;
31 
32 namespace Misc {
33 
34 // Base class for handling the engine's custom hypertext format
35 // Used by the Textbox and by Autotext action records
37 public:
38  HypertextParser() :
39  _backgroundColor(0),
40  _highlightBackgroundColor(0),
41  _numDrawnLines(0),
42  _drawnTextHeight(0),
43  _needsTextRedraw(false),
44  _defaultTextColor(0),
45  _imageVerticalOffset(0) {}
46  virtual ~HypertextParser() {};
47 
48  bool hasBeenDrawn() const { return !_needsTextRedraw; }
49 
50 protected:
51  enum Justification { kJustifyLeft, kJustifyRight, kJustifyCenter };
52 
53  // Image embedded in the text via the <iNAME,left,top,right,bottom> tag
54  struct InlineImage {
55  Common::Path name;
56  Common::Rect src; // empty means the whole image
57  };
58 
59  void initSurfaces(uint width, uint height, const struct Graphics::PixelFormat &format, uint32 backgroundColor, uint32 highlightBackgroundColor);
60 
61  void addTextLine(const Common::String &text);
62  void addImage(uint16 lineID, const Common::Rect &src);
63  void setImageName(const Common::Path &name);
64 
65  void drawAllText(const Common::Rect &textBounds, uint leftOffsetNonNewline, uint fontID, uint highlightFontID);
66  virtual void clear();
67 
68  void drawInlineImage(const InlineImage &inlineImage, const Common::Rect &textBounds, uint horizontalOffset, uint justification, const Font *font);
69 
70  // Nancy16 UI text starts out in a color of its own, until a color tag picks one of
71  // the font colors; that color then gets used in place of _defaultTextColor
72  void setDefaultTextRGB(byte r, byte g, byte b);
73 
74  Graphics::ManagedSurface _fullSurface; // Contains all rendered text (may be cropped)
75  Graphics::ManagedSurface _textHighlightSurface; // Same as above, but drawn with the highlight font
76 
77  uint32 _backgroundColor;
78  uint32 _highlightBackgroundColor;
79  uint _defaultTextColor;
80  uint _defaultJustification = kJustifyLeft;
81  FontColorState _fontColorState = kFontColorNormal; // Nancy16+: picks the color of a color tag
82  int _imageVerticalOffset;
83 
86 
87  // When set, drawAllText records the dest rect of every drawn mark glyph
88  // (in _fullSurface coords, in draw order). The notebook uses this to hit-
89  // test the tasklist's clickable checkboxes.
90  bool _recordMarkHotspots = false;
91  Common::Array<Common::Rect> _markHotspots;
92 
93  // Data for displaying images inside text; used in Hypertext
94  Common::Path _imageName;
95  Common::Array<uint16> _imageLineIDs;
96  Common::Array<Common::Rect> _imageSrcs;
97 
98  uint16 _numDrawnLines;
99  uint16 _drawnTextHeight;
100  bool _needsTextRedraw;
101 
102 private:
103  // Color IDs are font color IDs, or this for the color given to setDefaultTextRGB()
104  static const int kDefaultRGB = -1;
105 
106  void drawTextRun(Graphics::ManagedSurface &surface, const Font *font, const Common::String &text, int x, int y, int width, int colorID) const;
107  uint32 getColorPixel(const Font *font, int colorID) const;
108 
109  bool _hasDefaultTextRGB = false;
110  byte _defaultTextRGB[3] = {};
111 };
112 
113 } // End of namespace Misc
114 } // End of namespace Nancy
115 
116 #endif // NANCY_MISC_HYPERTEXT_H
Definition: managed_surface.h:51
Definition: str.h:59
Definition: pixelformat.h:138
Definition: rect.h:536
Definition: path.h:52
Definition: hypertext.h:36
Definition: font.h:38
Definition: actionmanager.h:32