2014-02-19 01:08:58 +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.
|
|
|
|
|
|
|
|
* 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.
|
|
|
|
|
|
|
|
* 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 MADS_MSURFACE_H
|
|
|
|
#define MADS_MSURFACE_H
|
|
|
|
|
|
|
|
#include "common/scummsys.h"
|
|
|
|
#include "common/rect.h"
|
|
|
|
#include "graphics/surface.h"
|
|
|
|
#include "mads/palette.h"
|
|
|
|
|
|
|
|
namespace MADS {
|
|
|
|
|
|
|
|
class MADSEngine;
|
|
|
|
class MSprite;
|
|
|
|
|
2014-02-20 01:22:06 +00:00
|
|
|
/**
|
|
|
|
* Basic sprite information
|
|
|
|
*/
|
2014-02-19 01:08:58 +00:00
|
|
|
struct SpriteInfo {
|
|
|
|
MSprite *sprite;
|
|
|
|
int hotX, hotY;
|
|
|
|
int width, height;
|
|
|
|
int scaleX, scaleY;
|
|
|
|
uint8 encoding;
|
|
|
|
byte *inverseColorTable;
|
2014-02-20 02:28:54 +00:00
|
|
|
byte *palette;
|
2014-02-19 01:08:58 +00:00
|
|
|
};
|
|
|
|
|
2014-02-20 01:22:06 +00:00
|
|
|
/*
|
|
|
|
* MADS graphics surface
|
|
|
|
*/
|
2014-02-19 01:08:58 +00:00
|
|
|
class MSurface : public Graphics::Surface {
|
|
|
|
public:
|
|
|
|
static MADSEngine *_vm;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the engine reference
|
|
|
|
*/
|
|
|
|
static void setVm(MADSEngine *vm) { _vm = vm; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new surface the same size as the screen.
|
|
|
|
* @param isScreen Set to true for the screen surface
|
|
|
|
*/
|
|
|
|
static MSurface *init(bool isScreen = false);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a surface
|
|
|
|
*/
|
2014-02-20 01:22:06 +00:00
|
|
|
static MSurface *init(int width, int height);
|
2014-02-19 01:08:58 +00:00
|
|
|
private:
|
|
|
|
byte _color;
|
|
|
|
bool _isScreen;
|
|
|
|
protected:
|
2014-02-20 01:22:06 +00:00
|
|
|
/**
|
|
|
|
* Basic constructor
|
|
|
|
*/
|
2014-02-19 01:08:58 +00:00
|
|
|
MSurface(bool isScreen = false);
|
2014-02-20 01:22:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor for a surface with fixed dimensions
|
|
|
|
*/
|
|
|
|
MSurface(int width, int height);
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Helper method for calculating new dimensions when scaling a sprite
|
|
|
|
*/
|
|
|
|
static int scaleValue(int value, int scale, int err);
|
2014-02-19 01:08:58 +00:00
|
|
|
public:
|
2014-02-19 04:56:41 +00:00
|
|
|
virtual ~MSurface() {}
|
|
|
|
|
2014-02-20 01:22:06 +00:00
|
|
|
/**
|
|
|
|
* Reinitialises a surface to have a given set of dimensions
|
|
|
|
*/
|
|
|
|
void setSize(int width, int height) {
|
|
|
|
Graphics::Surface::create(width, height, Graphics::PixelFormat::createFormatCLUT8());
|
2014-02-19 01:08:58 +00:00
|
|
|
}
|
|
|
|
|
2014-02-20 01:22:06 +00:00
|
|
|
/**
|
|
|
|
* Sets the color used for drawing on the surface
|
|
|
|
*/
|
2014-02-19 01:08:58 +00:00
|
|
|
void setColor(byte value) { _color = value; }
|
2014-02-20 01:22:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the currently active color
|
|
|
|
*/
|
|
|
|
byte getColor() const { return _color; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws a vertical line using the currently set color
|
|
|
|
*/
|
2014-02-19 01:08:58 +00:00
|
|
|
void vLine(int x, int y1, int y2);
|
2014-02-20 01:22:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws a horizontal line using the currently set color
|
|
|
|
*/
|
2014-02-19 01:08:58 +00:00
|
|
|
void hLine(int x1, int x2, int y);
|
2014-02-20 01:22:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws a vertical line using an Xor on each pixel
|
|
|
|
*/
|
2014-02-19 01:08:58 +00:00
|
|
|
void vLineXor(int x, int y1, int y2);
|
2014-02-20 01:22:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws a horizontal line using an Xor on each pixel
|
|
|
|
*/
|
2014-02-19 01:08:58 +00:00
|
|
|
void hLineXor(int x1, int x2, int y);
|
2014-02-20 01:22:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws an arbitrary line on the screen using a specified color
|
|
|
|
*/
|
2014-02-19 01:08:58 +00:00
|
|
|
void line(int x1, int y1, int x2, int y2, byte color);
|
2014-02-20 01:22:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws a rectangular frame using the currently set color
|
|
|
|
*/
|
2014-02-19 01:08:58 +00:00
|
|
|
void frameRect(int x1, int y1, int x2, int y2);
|
|
|
|
|
2014-02-20 01:22:06 +00:00
|
|
|
/**
|
|
|
|
* Draws a rectangular frame using a specified color
|
|
|
|
*/
|
2014-02-19 01:08:58 +00:00
|
|
|
void frameRect(const Common::Rect &r, uint8 color);
|
2014-02-20 01:22:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws a filled in box using the currently set color
|
|
|
|
*/
|
|
|
|
void fillRect(int x1, int y1, int x2, int y2);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draws a filled in box using a specified color
|
|
|
|
*/
|
2014-02-19 01:08:58 +00:00
|
|
|
void fillRect(const Common::Rect &r, uint8 color);
|
|
|
|
|
2014-02-20 01:22:06 +00:00
|
|
|
/**
|
|
|
|
* Draws a sprite
|
|
|
|
* @param pt Position to draw sprite at
|
|
|
|
* @param info General sprite details
|
|
|
|
* @param clipRect Clipping rectangle to constrain sprite drawing within
|
|
|
|
*/
|
|
|
|
void drawSprite(const Common::Point &pt, SpriteInfo &info, const Common::Rect &clipRect);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the width of the surface
|
|
|
|
*/
|
|
|
|
int getWidth() const { return w; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the height of the surface
|
|
|
|
*/
|
|
|
|
int getHeight() const { return h; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a pointer to the surface data
|
|
|
|
*/
|
|
|
|
byte *getData() { return (byte *)Graphics::Surface::getPixels(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a pointer to a given position within the surface
|
|
|
|
*/
|
|
|
|
byte *getBasePtr(int x, int y) { return (byte *)Graphics::Surface::getBasePtr(x, y); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears the surface
|
|
|
|
*/
|
|
|
|
void empty();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the surface. If it's the screen surface, copies it to the physical screen.
|
|
|
|
*/
|
2014-02-19 01:08:58 +00:00
|
|
|
void update() {
|
|
|
|
if (_isScreen) {
|
|
|
|
g_system->copyRectToScreen((const byte *)pixels, pitch, 0, 0, w, h);
|
|
|
|
g_system->updateScreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-20 01:22:06 +00:00
|
|
|
/**
|
|
|
|
* Copys a sub-section of another surface into the current one.
|
|
|
|
* @param src Source surface
|
|
|
|
* @param srcBounds Area of source surface to copy
|
|
|
|
* @param destPos Destination position to draw in current surface
|
|
|
|
* @param transparentColor Transparency palette index
|
|
|
|
*/
|
|
|
|
void copyFrom(MSurface *src, const Common::Rect &srcBounds, const Common::Point &destPos,
|
|
|
|
int transparentColor = -1);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies the surface to a given destination surface
|
|
|
|
*/
|
2014-02-19 01:08:58 +00:00
|
|
|
void copyTo(MSurface *dest, int transparentColor = -1) {
|
2014-02-20 01:22:06 +00:00
|
|
|
dest->copyFrom(this, Common::Rect(w, h), Common::Point(), transparentColor);
|
2014-02-19 01:08:58 +00:00
|
|
|
}
|
2014-02-20 01:22:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies the surface to a given destination surface
|
|
|
|
*/
|
|
|
|
void copyTo(MSurface *dest, const Common::Point &pt, int transparentColor = -1) {
|
|
|
|
dest->copyFrom(this, Common::Rect(w, h), pt, transparentColor);
|
2014-02-19 01:08:58 +00:00
|
|
|
}
|
2014-02-20 01:22:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copies the surface to a given destination surface
|
|
|
|
*/
|
|
|
|
void copyTo(MSurface *dest, const Common::Rect &srcBounds, const Common::Point &destPos,
|
2014-02-19 01:08:58 +00:00
|
|
|
int transparentColor = -1) {
|
2014-02-20 01:22:06 +00:00
|
|
|
dest->copyFrom(this, srcBounds, destPos, transparentColor);
|
2014-02-19 01:08:58 +00:00
|
|
|
}
|
|
|
|
|
2014-02-20 01:22:06 +00:00
|
|
|
/**
|
|
|
|
* Translates the data of a surface using a specified RGBList translation matrix.
|
|
|
|
*/
|
2014-02-19 01:08:58 +00:00
|
|
|
void translate(RGBList *list, bool isTransparent = false);
|
|
|
|
|
|
|
|
// Base virtual methods
|
2014-02-20 01:22:06 +00:00
|
|
|
/**
|
|
|
|
* Loads a background by scene name
|
|
|
|
*/
|
2014-02-19 01:08:58 +00:00
|
|
|
virtual void loadBackground(const Common::String &sceneName) {}
|
2014-02-20 01:22:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load background by room number
|
|
|
|
*/
|
2014-02-19 01:08:58 +00:00
|
|
|
virtual void loadBackground(int roomNumber, RGBList **palData) = 0;
|
2014-02-20 01:22:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load background from a passed stream
|
|
|
|
*/
|
2014-02-19 01:08:58 +00:00
|
|
|
virtual void loadBackground(Common::SeekableReadStream *source, RGBList **palData) {}
|
2014-02-20 01:22:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load scene codes from a passed stream
|
|
|
|
*/
|
2014-02-19 01:08:58 +00:00
|
|
|
virtual void loadCodes(Common::SeekableReadStream *source) = 0;
|
2014-02-20 01:22:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a given user interface by index
|
|
|
|
*/
|
2014-02-19 01:08:58 +00:00
|
|
|
virtual void loadInterface(int index, RGBList **palData) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class MSurfaceMADS: public MSurface {
|
|
|
|
friend class MSurface;
|
|
|
|
protected:
|
|
|
|
MSurfaceMADS(bool isScreen = false): MSurface(isScreen) {}
|
2014-02-20 01:22:06 +00:00
|
|
|
MSurfaceMADS(int width, int height): MSurface(width, height) {}
|
2014-02-19 01:08:58 +00:00
|
|
|
public:
|
|
|
|
virtual void loadCodes(Common::SeekableReadStream *source);
|
|
|
|
virtual void loadBackground(const Common::String &sceneName) {}
|
|
|
|
virtual void loadBackground(int roomNumber, RGBList **palData);
|
|
|
|
virtual void loadInterface(int index, RGBList **palData);
|
|
|
|
};
|
|
|
|
|
|
|
|
class MSurfaceNebular: public MSurfaceMADS {
|
|
|
|
friend class MSurface;
|
|
|
|
protected:
|
|
|
|
MSurfaceNebular(bool isScreen = false): MSurfaceMADS(isScreen) {}
|
2014-02-20 01:22:06 +00:00
|
|
|
MSurfaceNebular(int width, int height): MSurfaceMADS(width, height) {}
|
2014-02-19 01:08:58 +00:00
|
|
|
private:
|
|
|
|
void loadBackgroundStream(Common::SeekableReadStream *source, RGBList **palData);
|
|
|
|
public:
|
|
|
|
virtual void loadBackground(int roomNumber, RGBList **palData);
|
|
|
|
};
|
|
|
|
|
|
|
|
class MSurfaceM4: public MSurface {
|
|
|
|
friend class MSurface;
|
|
|
|
protected:
|
|
|
|
MSurfaceM4(bool isScreen = false): MSurface(isScreen) {}
|
2014-02-20 01:22:06 +00:00
|
|
|
MSurfaceM4(int width, int height): MSurface(width, height) {}
|
2014-02-19 01:08:58 +00:00
|
|
|
|
|
|
|
void loadBackgroundStream(Common::SeekableReadStream *source);
|
|
|
|
public:
|
|
|
|
virtual void loadCodes(Common::SeekableReadStream *source);
|
|
|
|
virtual void loadBackground(int roomNumber, RGBList **palData);
|
|
|
|
};
|
|
|
|
|
|
|
|
class MSurfaceRiddle: public MSurfaceM4 {
|
|
|
|
friend class MSurface;
|
|
|
|
protected:
|
|
|
|
MSurfaceRiddle(bool isScreen = false): MSurfaceM4(isScreen) {}
|
2014-02-20 01:22:06 +00:00
|
|
|
MSurfaceRiddle(int width, int height): MSurfaceM4(width, height) {}
|
2014-02-19 01:08:58 +00:00
|
|
|
public:
|
|
|
|
virtual void loadBackground(const Common::String &sceneName);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // End of namespace MADS
|
|
|
|
|
|
|
|
#endif /* MADS_MSURFACE_H */
|