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 NEVERHOOD_GRAPHICS_H
23 #define NEVERHOOD_GRAPHICS_H
24 
25 #include "common/array.h"
26 #include "common/file.h"
27 #include "graphics/surface.h"
28 #include "neverhood/neverhood.h"
29 
30 namespace Neverhood {
31 
32 struct NPoint {
33  int16 x, y;
34 };
35 
37 
38 struct NDimensions {
39  int16 width, height;
40 };
41 
42 struct NRect {
43  int16 x1, y1, x2, y2;
44 
45  static NRect make(int16 x01, int16 y01, int16 x02, int16 y02) {
46  NRect r;
47  r.set(x01, y01, x02, y02);
48  return r;
49  }
50 
51  void set(int16 x01, int16 y01, int16 x02, int16 y02) {
52  x1 = x01;
53  y1 = y01;
54  x2 = x02;
55  y2 = y02;
56  }
57 
58  bool contains(int16 x, int16 y) const {
59  return x >= x1 && x <= x2 && y >= y1 && y <= y2;
60  }
61 
62 };
63 
65 
66 // TODO: Use Common::Rect
67 struct NDrawRect {
68  int16 x, y, width, height;
69  NDrawRect() : x(0), y(0), width(0), height(0) {}
70  NDrawRect(int16 x0, int16 y0, int16 width0, int16 height0) : x(x0), y(y0), width(width0), height(height0) {}
71  int16 x2() { return x + width; }
72  int16 y2() { return y + height; }
73  void set(int16 x0, int16 y0, int16 width0, int16 height0) {
74  x = x0;
75  y = y0;
76  width = width0;
77  height = height0;
78  }
79 };
80 
81 class AnimResource;
82 class SpriteResource;
84 
85 class BaseSurface {
86 public:
87  BaseSurface(NeverhoodEngine *vm, int priority, int16 width, int16 height, Common::String name);
88  virtual ~BaseSurface();
89  virtual void draw();
90  void clear();
91  void drawSpriteResource(SpriteResource &spriteResource);
92  void drawSpriteResourceEx(SpriteResource &spriteResource, bool flipX, bool flipY, int16 width, int16 height);
93  void drawAnimResource(AnimResource &animResource, uint frameIndex, bool flipX, bool flipY, int16 width, int16 height);
94  void drawMouseCursorResource(MouseCursorResource &mouseCursorResource, int frameNum);
95  void copyFrom(Graphics::Surface *sourceSurface, int16 x, int16 y, NDrawRect &sourceRect);
96  int getPriority() const { return _priority; }
97  void setPriority(int priority) { _priority = priority; }
98  NDrawRect& getDrawRect() { return _drawRect; }
99  NDrawRect& getSysRect() { return _sysRect; }
100  NRect& getClipRect() { return _clipRect; }
101  void setClipRect(NRect clipRect) { _clipRect = clipRect; }
102  void setClipRects(NRect *clipRects, uint clipRectsCount) { _clipRects = clipRects; _clipRectsCount = clipRectsCount; }
103  void clearClipRects() { _clipRects = NULL; _clipRectsCount = 0; }
104  bool getVisible() const { return _visible; }
105  void setVisible(bool value) { _visible = value; }
106  void setTransparent(bool value) { _transparent = value; }
107  Graphics::Surface *getSurface() { return _surface; }
108  const Common::String getName() const { return _name; }
109 protected:
110  NeverhoodEngine *_vm;
111  int _priority;
112  bool _visible;
113  Common::String _name;
114  Graphics::Surface *_surface;
115  NDrawRect _drawRect;
116  NDrawRect _sysRect;
117  NRect _clipRect;
118  NRect *_clipRects;
119  uint _clipRectsCount;
120  bool _transparent;
121  // Version changes each time the pixels are touched in any way
122  byte _version;
123 };
124 
125 class ShadowSurface : public BaseSurface {
126 public:
127  ShadowSurface(NeverhoodEngine *vm, int priority, int16 width, int16 height, const Common::SharedPtr<BaseSurface> &shadowSurface);
128  void draw() override;
129 protected:
130  Common::SharedPtr<BaseSurface> _shadowSurface;
131 };
132 
133 class FontSurface : public BaseSurface {
134 public:
135  FontSurface(NeverhoodEngine *vm, NPointArray *tracking, uint charsPerRow, uint16 numRows, byte firstChar, uint16 charWidth, uint16 charHeight);
136  FontSurface(NeverhoodEngine *vm, uint32 fileHash, uint charsPerRow, uint16 numRows, byte firstChar, uint16 charWidth, uint16 charHeight);
137  ~FontSurface() override;
138  void drawChar(BaseSurface *destSurface, int16 x, int16 y, byte chr);
139  void drawString(const Common::SharedPtr<BaseSurface> &destSurface, int16 x, int16 y, const byte *string, int stringLen = -1);
140  int16 getStringWidth(const byte *string, int stringLen);
141  uint16 getCharWidth() const { return _charWidth; }
142  uint16 getCharHeight() const { return _charHeight; }
143  static FontSurface *createFontSurface(NeverhoodEngine *vm, uint32 fileHash);
144 protected:
145  uint _charsPerRow;
146  uint16 _numRows;
147  byte _firstChar;
148  uint16 _charWidth;
149  uint16 _charHeight;
150  NPointArray *_tracking;
151 };
152 
153 // Misc
154 
155 void parseBitmapResource(const byte *sprite, bool *rle, NDimensions *dimensions, NPoint *position, const byte **palette, const byte **pixels);
156 void unpackSpriteRle(const byte *source, int width, int height, byte *dest, int destPitch, bool flipX, bool flipY, byte oldColor = 0, byte newColor = 0);
157 void unpackSpriteNormal(const byte *source, int width, int height, byte *dest, int destPitch, bool flipX, bool flipY);
158 int calcDistance(int16 x1, int16 y1, int16 x2, int16 y2);
159 
160 } // End of namespace Neverhood
161 
162 #endif /* NEVERHOOD_GRAPHICS_H */
Definition: background.h:30
Definition: str.h:59
Definition: surface.h:66
Definition: neverhood.h:60
Definition: array.h:52
Definition: resource.h:51
Definition: resource.h:94
Definition: graphics.h:42
Definition: graphics.h:67
Definition: graphics.h:38
Definition: resource.h:122
Definition: graphics.h:133
Definition: graphics.h:125
Definition: ptr.h:159
Definition: graphics.h:85
Definition: graphics.h:32