ScummVM API documentation
graphics.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 TSAGE_GRAPHICS_H
23#define TSAGE_GRAPHICS_H
24
25#include "tsage/events.h"
26#include "tsage/saveload.h"
27#include "common/list.h"
28#include "common/rect.h"
29#include "common/system.h"
30#include "graphics/screen.h"
31
32namespace TsAGE {
33
34class GfxSurface;
35class Region;
36
40class Rect : public Common::Rect, public Serialisable {
41public:
42 Rect() : Common::Rect() {}
43 Rect(int16 x1, int16 y1, int16 x2, int16 y2) : Common::Rect(x1, y1, x2, y2) {}
44
45 void set(int16 x1, int16 y1, int16 x2, int16 y2);
46 void collapse(int dx, int dy);
47 void center(int dx, int dy);
48 void center(const Rect &r);
49 void center(const Common::Point &pt) { center(pt.x, pt.y); }
50 void contain(const Rect &r);
51 void resize(const GfxSurface &surface, int xp, int yp, int percent);
52 void expandPanes();
53
54 void synchronize(Serializer &s) override;
55};
56
57class GfxColors {
58public:
59 uint8 foreground;
60 uint8 background;
61
62 GfxColors() : foreground(0), background(0) {}
63};
64
65class LineSlice {
66public:
67 int xs, xe;
68
69 LineSlice() { xs = 0; xe = 0; }
70 LineSlice(int xStart, int xEnd) { xs = xStart; xe = xEnd; }
71};
72
73enum FrameFlag { FRAME_FLIP_CENTROID_X = 4, FRAME_FLIP_CENTROID_Y = 8 };
74
80private:
81 int _lockSurfaceCtr;
82 Graphics::ManagedSurface _rawSurface;
83
84 bool _disableUpdates;
85 Rect _bounds;
86 protected:
91 void addDirtyRect(const Common::Rect &r) override {}
92public:
93 Common::Point _centroid;
94 int _transColor;
95 Rect _clipRect;
96 byte _flags;
97public:
98 GfxSurface();
99 GfxSurface(const GfxSurface &s);
100 ~GfxSurface() override;
101
102 Graphics::ManagedSurface &lockSurface();
103 void unlockSurface();
104 void synchronize(Serializer &s);
105 void create(int16 width, int16 height) override;
106 void setBounds(const Rect &bounds);
107 const Rect &getBounds() const { return _bounds; }
108
109 void copyFrom(GfxSurface &src, Rect srcBounds, Rect destBounds,
110 Region *priorityRegion = NULL, const byte *shadowMap = NULL);
111 void copyFrom(GfxSurface &src, Rect destBounds, Region *priorityRegion = NULL) {
112 copyFrom(src, src.getBounds(), destBounds, priorityRegion);
113 }
114 void copyFrom(GfxSurface &src, int destX = 0, int destY = 0, Region *priorityRegion = NULL) {
115 Rect tempRect = src.getBounds();
116 tempRect.moveTo(destX, destY);
117 copyFrom(src, tempRect, priorityRegion);
118 }
119 void draw(const Common::Point &pt, Rect *rect = NULL);
120 GfxSurface &operator=(const GfxSurface &s);
121
122 static void loadScreenSection(Graphics::ManagedSurface &dest, int xHalf, int yHalf, int xSection, int ySection);
123 static bool displayText(const Common::String &msg, const Common::Point &pt = Common::Point(160, 100));
124};
125
126enum TextAlign {ALIGN_LEFT = 0, ALIGN_CENTER = 1, ALIGN_RIGHT = 2, ALIGN_JUSTIFIED = 3};
127
128class GfxFont {
129 friend class GfxFontBackup;
130private:
131 GfxManager *_gfxManager;
132 // Raw font details
133 const byte *_fontData;
134 int _numChars;
135 Common::Point _fontSize;
136 int _bpp;
137public:
138 // Font fields
139 Common::Point _edgeSize;
140 Common::Point _position;
141 bool _fillFlag;
142 GfxColors _colors;
143 GfxColors _colors2;
144 uint32 _fontNumber;
145 Common::Point _topLeft;
146public:
147 GfxFont();
148 virtual ~GfxFont();
149
150 void setFontNumber(uint32 fontNumber);
151 int32 getHeight() const { return _fontSize.y; }
152 int getCharWidth(char ch);
153 int getStringWidth(const char *s, int numChars);
154 int getStringWidth(const char *s);
155 int getStringFit(const char *&s, int maxWidth);
156 void getStringBounds(const char *s, Rect &bounds, int maxWidth);
157
158 void setOwner(GfxManager *owner) { _gfxManager = owner; }
159 void setPosition(int xp, int yp) { _position.x = xp; _position.y = yp; }
160 int writeChar(const char ch);
161 void writeString(const char *s);
162 void writeString(const char *s, int numChars);
163 void writeLines(const char *s, const Rect &bounds, TextAlign align);
164};
165
167private:
168 Common::Point _edgeSize;
169 Common::Point _position;
170 GfxColors _colors;
171 uint32 _fontNumber;
172public:
175};
176
177enum GFX_FLAGS {GFXFLAG_THICK_FRAME = 8};
178
179class GfxManager;
180
182public:
183 GfxElement *_owner;
184 Rect _bounds;
185 uint16 _flags;
186 uint16 _fontNumber;
187 GfxColors _colors;
188 GfxColors _fontColors;
189 byte _color1, _color2, _color3;
190 uint16 _keycode;
191public:
192 GfxElement();
193 virtual ~GfxElement() {}
194
195 void drawFrame();
196
197 // Virtual table method
198 virtual void setDefaults();
199 virtual void remove() { _owner = NULL; }
200 virtual void highlight();
201 virtual void draw() {}
202 virtual bool process(Event &event) { return false; }
203 virtual bool focusedEvent(Event &event);
204};
205
206class GfxImage : public GfxElement {
207public:
208 GfxSurface _surface;
209 int _resNum;
210 int _rlbNum;
211 int _cursorNum;
212public:
213 GfxImage();
214
215 void setDetails(int resNum, int rlbNum, int cursorNum);
216
217 void setDefaults() override;
218 void draw() override;
219 bool process(Event &event) override { return false; }
220};
221
222class GfxMessage : public GfxElement {
223public:
224 Common::String _message;
225 TextAlign _textAlign;
226 int _width;
227public:
228 GfxMessage();
229 ~GfxMessage() override {}
230
231 void set(const Common::String &s, int width, TextAlign textAlign);
232
233 void setDefaults() override;
234 void draw() override;
235};
236
237class GfxButton : public GfxElement {
238private:
239 void setFocus();
240public:
241 Common::String _message;
242public:
243 GfxButton() : GfxElement() {}
244 ~GfxButton() override {}
245
246 void setText(const Common::String &s) {
247 _message = s;
248 setDefaults();
249 }
250
251 // Virtual table method
252 void setDefaults() override;
253 void draw() override;
254 bool process(Event &event) override;
255};
256
258private:
259 GfxSurface &_surface;
260public:
261 GfxManager *_oldManager;
262 Common::Point _topLeft;
263 Rect _bounds;
264 Rect _pane0Rect4;
265 GfxFont _font;
266public:
267 GfxManager();
269 virtual ~GfxManager() {}
270
271 void setDefaults();
272 void activate();
273 void deactivate();
274
275 // Accessor methods
276 int getStringWidth(const char *s, int numChars);
277 int getStringWidth(const char *s);
278 void getStringBounds(const char *s, Rect &bounds, int maxWidth);
279
280 void setDialogPalette();
281 Graphics::ManagedSurface &lockSurface() {
282 _surface.setBounds(_bounds);
283 return _surface.lockSurface();
284 }
285 void unlockSurface() { _surface.unlockSurface(); }
286 void fillArea(int xp, int yp, int color);
287 void fillRect(const Rect &bounds, int color);
288 void fillRect2(int xs, int ys, int width, int height, int color);
289 void setFillFlag(bool v) { _font._fillFlag = v; }
290
291 static int getAngle(const Common::Point &p1, const Common::Point &p2);
292
293 // Virtual method table
294 virtual void xorArea(const Common::Rect &r, int color, int fillMode) {
295 //_surface->xorArea(r, color, fillMode);
296 }
297 virtual void draw(const Common::Rect &r, void *gfxData, int v1, GfxColors *colors) {
298 //_surface->draw(r, gfxData, v1, colors);
299 }
300 virtual void copy(const byte *src, byte *dest, int size) {
301 Common::copy(src, src + size, dest);
302 }
303 virtual void set(byte *dest, int size, byte val) {
304 Common::fill(dest, dest + size, val);
305 }
306 void copyFrom(GfxSurface &src, Rect destBounds, Region *priorityRegion = NULL);
307 void copyFrom(GfxSurface &src, int destX, int destY);
308 void copyFrom(GfxSurface &src, const Rect &srcBounds, const Rect &destBounds);
309
310 GfxSurface &getSurface() {
311 _surface.setBounds(_bounds);
312 return _surface;
313 }
314};
315
317
318class GfxDialog : public GfxElement {
319public:
320 GfxManager _gfxManager;
321 GfxElementList _elements;
322 GfxButton *_defaultButton;
323 GfxSurface *_savedArea;
324public:
325 GfxDialog();
326 ~GfxDialog() override;
327
328 void add(GfxElement *element);
329 void addElements(GfxElement *ge, ...);
330 void setTopLeft(int xp, int yp);
331 void setCenter(int xp, int yp);
332 void frame() {
333 setDefaults();
334 _bounds.collapse(6, 6);
335 }
336 GfxButton *execute(GfxButton *defaultButton = NULL);
337
338 void setDefaults() override;
339 void remove() override;
340 void draw() override;
341
342 static void setPalette();
343
344 virtual bool handleKeypress(Event &evt, GfxButton *&btn) { return false; }
345};
346
347GfxSurface *surfaceGetArea(GfxSurface &src, const Rect &bounds);
348
349GfxSurface surfaceFromRes(const byte *imgData);
350GfxSurface surfaceFromRes(int resNum, int rlbNum, int subNum);
351
352} // End of namespace TsAGE
353
354#endif
Definition: str.h:59
Definition: managed_surface.h:51
Definition: screen.h:47
Definition: events.h:47
Definition: graphics.h:237
Definition: graphics.h:57
Definition: graphics.h:318
Definition: graphics.h:181
Definition: graphics.h:166
Definition: graphics.h:128
Definition: graphics.h:206
Definition: graphics.h:257
Definition: graphics.h:222
Definition: graphics.h:79
void addDirtyRect(const Common::Rect &r) override
Definition: graphics.h:91
void create(int16 width, int16 height) override
Definition: graphics.h:65
Definition: graphics.h:40
Definition: core.h:703
Definition: saveload.h:84
Definition: saveload.h:63
Out copy(In first, In last, Out dst)
Definition: algorithm.h:52
signed char * fill(signed char *first, signed char *last, Value val)
Definition: algorithm.h:168
TextAlign
Definition: font.h:48
T y
Definition: rect.h:49
T x
Definition: rect.h:48
Definition: rect.h:144
void moveTo(T x, T y)
Definition: rect.h:399
Point center() const
Definition: rect.h:488
Definition: rect.h:536