ScummVM API documentation
screen.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 TOLTECS_SCREEN_H
23 #define TOLTECS_SCREEN_H
24 
25 #include "graphics/surface.h"
26 #include "toltecs/toltecs.h"
27 
28 namespace Toltecs {
29 
30 struct DrawRequest {
31  int16 x, y;
32  int16 resIndex;
33  uint16 flags;
34  int16 baseColor;
35  int8 scaling;
36 };
37 
39  int16 x, y;
40  int16 width, height;
41  int16 origWidth, origHeight;
42  int16 resIndex, frameNum;
43  uint32 offset;
44  int16 xdelta, ydelta;
45  uint16 flags;
46  int16 skipX, yerror;
47  int16 priority;
48  int16 baseColor;
49 };
50 
52  int16 y, x, h, w;
53  uint32 offset;
55  }
56  SpriteFrameEntry(byte *data) {
57  y = READ_LE_UINT16(data + 0);
58  x = READ_LE_UINT16(data + 2);
59  h = READ_LE_UINT16(data + 4);
60  w = READ_LE_UINT16(data + 6);
61  offset = READ_LE_UINT32(data + 8);
62  }
63 };
64 
65 class Font {
66 public:
67  Font(byte *fontData) : _fontData(fontData) {
68  }
69  ~Font() {
70  }
71  int16 getSpacing() const {
72  return _fontData[1];
73  }
74  int16 getHeight() const {
75  return _fontData[2];
76  }
77  int16 getWidth() const {
78  return _fontData[3];
79  }
80  int16 getCharWidth(byte ch) const {
81  return _fontData[4 + (ch - 0x21)];
82  }
83  byte *getCharData(byte ch) const {
84  return _fontData + 0x298 + READ_LE_UINT16(&_fontData[0xE0 + (ch - 0x21) * 2]);
85  }
86  int16 getTextWidth(const byte *text) {
87  int16 width = 0;
88  while (*text && *text < 0xF0) {
89  byte ch = *text++;
90  if (ch <= 0x20) {
91  width += getWidth();
92  } else {
93  width += getCharWidth(ch) + getSpacing() - 1;
94  }
95  }
96  return width;
97  }
98 
99 protected:
100  byte *_fontData;
101 };
102 
103 struct PixelPacket {
104  byte count;
105  byte pixel;
106 };
107 
108 enum SpriteReaderStatus {
109  kSrsPixelsLeft,
110  kSrsEndOfLine,
111  kSrsEndOfSprite
112 };
113 
115 public:
116  SpriteFilter(const SpriteDrawItem &sprite) : _sprite(&sprite) {
117  }
118  virtual ~SpriteFilter() {}
119  virtual SpriteReaderStatus readPacket(PixelPacket &packet) = 0;
120 protected:
121  const SpriteDrawItem *_sprite;
122 };
123 
124 struct TextRect {
125  int16 x, y;
126  int16 width, length;
127 };
128 
129 struct TalkTextItem {
130  int16 duration;
131  int16 slotIndex;
132  int16 slotOffset;
133  int16 fontNum;
134  byte color;
135  byte lineCount;
136  TextRect lines[15];
137  bool alwaysDisplayed;
138 };
139 
141  int16 len1, len2;
142  byte *sourceString;
143  byte *destString;
144  int16 width;
145  byte textBuffer[100];
146 };
147 
148 class RenderQueue;
149 
150 class Screen {
151 public:
152  Screen(ToltecsEngine *vm);
153  ~Screen();
154 
155  void unpackRle(byte *source, byte *dest, uint16 width, uint16 height);
156 
157  void loadMouseCursor(uint resIndex);
158 
159  void drawGuiImage(int16 x, int16 y, uint resIndex);
160 
161  void startShakeScreen(int16 shakeCounter);
162  void stopShakeScreen();
163  bool updateShakeScreen();
164 
165  // Sprite list
166  void addStaticSprite(byte *spriteItem);
167  void addAnimatedSprite(int16 x, int16 y, int16 fragmentId, byte *data, int16 *spriteArray, bool loop, int mode);
168 
169  // Sprite drawing
170  void drawSprite(const SpriteDrawItem &sprite);
171  void drawSpriteCore(byte *dest, SpriteFilter &reader, const SpriteDrawItem &sprite);
172  void blastSprite(int16 x, int16 y, int16 fragmentId, int16 resIndex, uint16 flags);
173 
174  // Verb line
175  void updateVerbLine(int16 slotIndex, int16 slotOffset);
176 
177  // Talk text
178  void updateTalkText(int16 slotIndex, int16 slotOffset, bool alwaysDisplayed);
179  void addTalkTextRect(Font &font, int16 x, int16 &y, int16 length, int16 width, TalkTextItem *item);
180  void addTalkTextItemsToRenderQueue();
181  int16 getTalkTextDuration();
182  bool isTalkTextActive(int16 slotIndex);
183  void finishTalkTextItem(int16 slotIndex);
184  void finishTalkTextItems();
185  void keepTalkTextItemsAlive();
186 
187  // Font/text
188  void registerFont(uint fontIndex, uint resIndex);
189  void drawGuiTextMulti(byte *textData);
190  int16 wrapGuiText(uint fontResIndex, int maxWidth, GuiTextWrapState &wrapState);
191  void drawGuiText(int16 x, int16 y, byte fontColor1, byte fontColor2, uint fontResIndex, GuiTextWrapState &wrapState);
192 
193  int16 drawString(int16 x, int16 y, byte color, uint fontResIndex, const byte *text, int len = -1, int16 *ywobble = NULL, bool outline = false);
194  void drawChar(const Font &font, byte *dest, int16 x, int16 y, byte ch, byte color, bool outline);
195 
196  void drawSurface(int16 x, int16 y, Graphics::Surface *surface);
197 
198  void saveState(Common::WriteStream *out);
199  void loadState(Common::ReadStream *in);
200 
201  uint getFontResIndex(int fontNum) const { return _fontResIndexArray[fontNum]; }
202 
203 //protected:
204 public:
205 
206  struct VerbLineItem {
207  int16 slotIndex;
208  int16 slotOffset;
209  };
210 
211  struct Rect {
212  int16 x, y, width, height;
213  };
214 
215  ToltecsEngine *_vm;
216 
217  byte *_frontScreen, *_backScreen;
218 
219  uint _fontResIndexArray[10];
220  byte _fontColor1, _fontColor2;
221 
222  // Screen shaking
223  bool _shakeActive;
224  uint32 _shakeTime;
225  int16 _shakeCounterInit, _shakeCounter;
226  int _shakePos;
227 
228  // Verb line
229  int16 _verbLineNum;
230  VerbLineItem _verbLineItems[8];
231  int16 _verbLineX, _verbLineY, _verbLineWidth;
232  int16 _verbLineCount;
233 
234  // Talk text
235  int16 _talkTextX, _talkTextY;
236  int16 _talkTextMaxWidth;
237  byte _talkTextFontColor;
238  int16 _talkTextItemNum;
239  TalkTextItem _talkTextItems[5];
240 
241  RenderQueue *_renderQueue;
242  bool _fullRefresh;
243  bool _guiRefresh;
244 
245  bool createSpriteDrawItem(const DrawRequest &drawRequest, SpriteDrawItem &sprite);
246  void addDrawRequest(const DrawRequest &drawRequest);
247 
248 };
249 
250 } // End of namespace Toltecs
251 
252 #endif /* TOLTECS_SCREEN_H */
Definition: animation.h:28
Definition: surface.h:67
Definition: screen.h:206
Definition: screen.h:103
Definition: stream.h:77
Definition: screen.h:211
Definition: screen.h:114
Definition: screen.h:51
Definition: render.h:66
Definition: screen.h:65
Definition: screen.h:140
Definition: screen.h:129
Definition: toltecs.h:94
Definition: screen.h:38
Definition: screen.h:30
Definition: stream.h:385
Definition: screen.h:150
Definition: screen.h:124