2011-06-24 23:25:01 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2014-02-18 01:34:22 +00:00
|
|
|
*
|
2011-06-24 23:25:01 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2014-02-18 01:34:22 +00:00
|
|
|
*
|
2011-06-24 23:25:01 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NEVERHOOD_GRAPHICS_H
|
|
|
|
#define NEVERHOOD_GRAPHICS_H
|
|
|
|
|
|
|
|
#include "common/array.h"
|
|
|
|
#include "common/file.h"
|
2011-06-26 18:08:18 +00:00
|
|
|
#include "graphics/surface.h"
|
2011-06-24 23:25:01 +00:00
|
|
|
#include "neverhood/neverhood.h"
|
|
|
|
|
|
|
|
namespace Neverhood {
|
|
|
|
|
2011-06-30 09:55:59 +00:00
|
|
|
struct NPoint {
|
|
|
|
int16 x, y;
|
2011-06-24 23:25:01 +00:00
|
|
|
};
|
|
|
|
|
2011-07-16 11:01:08 +00:00
|
|
|
typedef Common::Array<NPoint> NPointArray;
|
|
|
|
|
2011-06-30 09:55:59 +00:00
|
|
|
struct NDimensions {
|
|
|
|
int16 width, height;
|
2011-06-24 23:25:01 +00:00
|
|
|
};
|
|
|
|
|
2011-06-26 18:08:18 +00:00
|
|
|
struct NRect {
|
|
|
|
int16 x1, y1, x2, y2;
|
2012-05-11 11:03:40 +00:00
|
|
|
|
2013-08-05 09:47:11 +00:00
|
|
|
static NRect make(int16 x01, int16 y01, int16 x02, int16 y02) {
|
|
|
|
NRect r;
|
|
|
|
r.set(x01, y01, x02, y02);
|
|
|
|
return r;
|
|
|
|
}
|
2012-05-11 11:03:40 +00:00
|
|
|
|
2011-09-20 07:48:17 +00:00
|
|
|
void set(int16 x01, int16 y01, int16 x02, int16 y02) {
|
|
|
|
x1 = x01;
|
|
|
|
y1 = y01;
|
|
|
|
x2 = x02;
|
|
|
|
y2 = y02;
|
|
|
|
}
|
2012-05-11 11:03:40 +00:00
|
|
|
|
|
|
|
bool contains(int16 x, int16 y) const {
|
|
|
|
return x >= x1 && x <= x2 && y >= y1 && y <= y2;
|
|
|
|
}
|
|
|
|
|
2011-06-26 18:08:18 +00:00
|
|
|
};
|
|
|
|
|
2011-07-16 11:01:08 +00:00
|
|
|
typedef Common::Array<NRect> NRectArray;
|
|
|
|
|
2013-07-14 17:01:47 +00:00
|
|
|
// TODO: Use Common::Rect
|
2011-06-26 18:08:18 +00:00
|
|
|
struct NDrawRect {
|
|
|
|
int16 x, y, width, height;
|
|
|
|
NDrawRect() : x(0), y(0), width(0), height(0) {}
|
2011-07-05 18:19:46 +00:00
|
|
|
NDrawRect(int16 x0, int16 y0, int16 width0, int16 height0) : x(x0), y(y0), width(width0), height(height0) {}
|
2013-07-14 17:01:47 +00:00
|
|
|
int16 x2() { return x + width; }
|
2011-09-20 07:48:17 +00:00
|
|
|
int16 y2() { return y + height; }
|
|
|
|
void set(int16 x0, int16 y0, int16 width0, int16 height0) {
|
|
|
|
x = x0;
|
|
|
|
y = y0;
|
|
|
|
width = width0;
|
|
|
|
height = height0;
|
|
|
|
}
|
2011-06-26 18:08:18 +00:00
|
|
|
};
|
|
|
|
|
2011-07-06 09:15:37 +00:00
|
|
|
class AnimResource;
|
2011-06-27 11:06:40 +00:00
|
|
|
class SpriteResource;
|
2011-07-11 12:21:56 +00:00
|
|
|
class MouseCursorResource;
|
2011-06-27 11:06:40 +00:00
|
|
|
|
2011-06-26 18:08:18 +00:00
|
|
|
class BaseSurface {
|
|
|
|
public:
|
2013-06-09 14:13:23 +00:00
|
|
|
BaseSurface(NeverhoodEngine *vm, int priority, int16 width, int16 height, Common::String name);
|
2011-06-26 18:08:18 +00:00
|
|
|
virtual ~BaseSurface();
|
|
|
|
virtual void draw();
|
2011-06-27 11:06:40 +00:00
|
|
|
void clear();
|
|
|
|
void drawSpriteResource(SpriteResource &spriteResource);
|
2011-07-05 18:19:46 +00:00
|
|
|
void drawSpriteResourceEx(SpriteResource &spriteResource, bool flipX, bool flipY, int16 width, int16 height);
|
2011-07-06 09:15:37 +00:00
|
|
|
void drawAnimResource(AnimResource &animResource, uint frameIndex, bool flipX, bool flipY, int16 width, int16 height);
|
2011-07-11 12:21:56 +00:00
|
|
|
void drawMouseCursorResource(MouseCursorResource &mouseCursorResource, int frameNum);
|
2013-01-17 08:27:38 +00:00
|
|
|
void copyFrom(Graphics::Surface *sourceSurface, int16 x, int16 y, NDrawRect &sourceRect);
|
2011-06-30 09:55:59 +00:00
|
|
|
int getPriority() const { return _priority; }
|
|
|
|
void setPriority(int priority) { _priority = priority; }
|
2011-07-01 10:25:55 +00:00
|
|
|
NDrawRect& getDrawRect() { return _drawRect; }
|
|
|
|
NDrawRect& getSysRect() { return _sysRect; }
|
|
|
|
NRect& getClipRect() { return _clipRect; }
|
2011-07-05 18:19:46 +00:00
|
|
|
void setClipRect(NRect clipRect) { _clipRect = clipRect; }
|
2012-10-06 21:15:18 +00:00
|
|
|
void setClipRects(NRect *clipRects, uint clipRectsCount) { _clipRects = clipRects; _clipRectsCount = clipRectsCount; }
|
|
|
|
void clearClipRects() { _clipRects = NULL; _clipRectsCount = 0; }
|
2011-07-06 09:15:37 +00:00
|
|
|
bool getVisible() const { return _visible; }
|
|
|
|
void setVisible(bool value) { _visible = value; }
|
2011-07-06 11:01:21 +00:00
|
|
|
void setTransparent(bool value) { _transparent = value; }
|
2011-07-16 17:27:21 +00:00
|
|
|
Graphics::Surface *getSurface() { return _surface; }
|
2013-06-09 14:13:23 +00:00
|
|
|
const Common::String getName() const { return _name; }
|
2011-06-26 18:08:18 +00:00
|
|
|
protected:
|
|
|
|
NeverhoodEngine *_vm;
|
|
|
|
int _priority;
|
|
|
|
bool _visible;
|
2013-06-09 14:13:23 +00:00
|
|
|
Common::String _name;
|
2011-06-26 18:08:18 +00:00
|
|
|
Graphics::Surface *_surface;
|
|
|
|
NDrawRect _drawRect;
|
|
|
|
NDrawRect _sysRect;
|
|
|
|
NRect _clipRect;
|
2012-10-06 21:15:18 +00:00
|
|
|
NRect *_clipRects;
|
|
|
|
uint _clipRectsCount;
|
2011-07-06 11:01:21 +00:00
|
|
|
bool _transparent;
|
2012-10-18 12:44:00 +00:00
|
|
|
// Version changes each time the pixels are touched in any way
|
2012-10-17 20:49:43 +00:00
|
|
|
byte _version;
|
2011-06-26 18:08:18 +00:00
|
|
|
};
|
|
|
|
|
2012-09-14 22:38:31 +00:00
|
|
|
class ShadowSurface : public BaseSurface {
|
|
|
|
public:
|
|
|
|
ShadowSurface(NeverhoodEngine *vm, int priority, int16 width, int16 height, BaseSurface *shadowSurface);
|
|
|
|
virtual void draw();
|
|
|
|
protected:
|
|
|
|
BaseSurface *_shadowSurface;
|
|
|
|
};
|
|
|
|
|
2011-07-16 11:01:08 +00:00
|
|
|
class FontSurface : public BaseSurface {
|
|
|
|
public:
|
2013-01-12 00:19:20 +00:00
|
|
|
FontSurface(NeverhoodEngine *vm, NPointArray *tracking, uint charsPerRow, uint16 numRows, byte firstChar, uint16 charWidth, uint16 charHeight);
|
|
|
|
FontSurface(NeverhoodEngine *vm, uint32 fileHash, uint charsPerRow, uint16 numRows, byte firstChar, uint16 charWidth, uint16 charHeight);
|
|
|
|
virtual ~FontSurface();
|
2012-09-19 11:03:28 +00:00
|
|
|
void drawChar(BaseSurface *destSurface, int16 x, int16 y, byte chr);
|
2013-01-12 00:19:20 +00:00
|
|
|
void drawString(BaseSurface *destSurface, int16 x, int16 y, const byte *string, int stringLen = -1);
|
2012-09-19 11:03:28 +00:00
|
|
|
int16 getStringWidth(const byte *string, int stringLen);
|
2012-10-26 11:01:10 +00:00
|
|
|
uint16 getCharWidth() const { return _charWidth; }
|
2012-10-25 13:14:26 +00:00
|
|
|
uint16 getCharHeight() const { return _charHeight; }
|
2013-01-12 00:19:20 +00:00
|
|
|
static FontSurface *createFontSurface(NeverhoodEngine *vm, uint32 fileHash);
|
2012-09-19 11:03:28 +00:00
|
|
|
protected:
|
2013-01-12 00:19:20 +00:00
|
|
|
uint _charsPerRow;
|
2012-09-19 11:03:28 +00:00
|
|
|
uint16 _numRows;
|
|
|
|
byte _firstChar;
|
|
|
|
uint16 _charWidth;
|
|
|
|
uint16 _charHeight;
|
2013-01-12 00:19:20 +00:00
|
|
|
NPointArray *_tracking;
|
2012-09-19 11:03:28 +00:00
|
|
|
};
|
|
|
|
|
2011-06-26 18:08:18 +00:00
|
|
|
// Misc
|
|
|
|
|
2012-11-16 21:26:15 +00:00
|
|
|
void parseBitmapResource(const byte *sprite, bool *rle, NDimensions *dimensions, NPoint *position, const byte **palette, const byte **pixels);
|
|
|
|
void unpackSpriteRle(const byte *source, int width, int height, byte *dest, int destPitch, bool flipX, bool flipY, byte oldColor = 0, byte newColor = 0);
|
|
|
|
void unpackSpriteNormal(const byte *source, int width, int height, byte *dest, int destPitch, bool flipX, bool flipY);
|
2011-10-14 08:11:10 +00:00
|
|
|
int calcDistance(int16 x1, int16 y1, int16 x2, int16 y2);
|
2011-06-24 23:25:01 +00:00
|
|
|
|
|
|
|
} // End of namespace Neverhood
|
|
|
|
|
|
|
|
#endif /* NEVERHOOD_GRAPHICS_H */
|