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