2014-02-18 20:08:58 -05: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.
|
2015-05-09 15:56:27 +02:00
|
|
|
*
|
2014-02-18 20:08:58 -05: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.
|
2015-05-09 15:56:27 +02:00
|
|
|
*
|
2014-02-18 20:08:58 -05: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 MADS_MSURFACE_H
|
|
|
|
#define MADS_MSURFACE_H
|
|
|
|
|
|
|
|
#include "common/scummsys.h"
|
|
|
|
#include "common/rect.h"
|
2016-05-26 21:37:52 -04:00
|
|
|
#include "graphics/screen.h"
|
2014-02-18 20:08:58 -05:00
|
|
|
#include "mads/palette.h"
|
|
|
|
|
|
|
|
namespace MADS {
|
|
|
|
|
|
|
|
class MADSEngine;
|
|
|
|
class MSprite;
|
2014-05-25 13:23:05 -04:00
|
|
|
class DepthSurface;
|
2014-02-18 20:08:58 -05:00
|
|
|
|
2014-02-19 20:22:06 -05:00
|
|
|
/**
|
|
|
|
* Basic sprite information
|
|
|
|
*/
|
2014-02-18 20:08:58 -05:00
|
|
|
struct SpriteInfo {
|
|
|
|
MSprite *sprite;
|
|
|
|
int hotX, hotY;
|
|
|
|
int width, height;
|
|
|
|
int scaleX, scaleY;
|
|
|
|
uint8 encoding;
|
|
|
|
byte *inverseColorTable;
|
2014-02-19 21:28:54 -05:00
|
|
|
byte *palette;
|
2014-02-18 20:08:58 -05:00
|
|
|
};
|
|
|
|
|
2014-02-19 20:22:06 -05:00
|
|
|
/*
|
2016-05-26 21:37:52 -04:00
|
|
|
* Base MADS surface class. This derivces from Graphics::Screen
|
|
|
|
* because it has logic we'll need for our own Screen class that
|
|
|
|
* derives from this one
|
2014-02-19 20:22:06 -05:00
|
|
|
*/
|
2016-05-26 21:37:52 -04:00
|
|
|
class BaseSurface : public Graphics::Screen {
|
2016-03-10 21:51:23 -05:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Helper method for calculating new dimensions when scaling a sprite
|
|
|
|
*/
|
|
|
|
int scaleValue(int value, int scale, int err);
|
2014-03-10 00:00:39 -04:00
|
|
|
protected:
|
2014-02-18 20:08:58 -05:00
|
|
|
static MADSEngine *_vm;
|
2014-02-25 23:10:51 -05:00
|
|
|
public:
|
2014-02-18 20:08:58 -05:00
|
|
|
/**
|
2016-02-14 10:27:44 +01:00
|
|
|
* Sets the engine reference used all surfaces
|
2014-02-18 20:08:58 -05:00
|
|
|
*/
|
|
|
|
static void setVm(MADSEngine *vm) { _vm = vm; }
|
|
|
|
|
2014-09-20 11:29:00 -04:00
|
|
|
/**
|
|
|
|
* Base method for descendents to load their contents
|
|
|
|
*/
|
|
|
|
virtual void load(const Common::String &resName) {}
|
2014-02-25 23:10:51 -05:00
|
|
|
public:
|
2014-02-19 20:22:06 -05:00
|
|
|
/**
|
|
|
|
* Basic constructor
|
|
|
|
*/
|
2016-05-27 06:00:58 -04:00
|
|
|
BaseSurface() : Graphics::Screen(0, 0) {
|
|
|
|
free(); // Free the 0x0 surface allocated by Graphics::Screen
|
|
|
|
}
|
2014-02-19 20:22:06 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor for a surface with fixed dimensions
|
|
|
|
*/
|
2016-05-26 21:37:52 -04:00
|
|
|
BaseSurface(int width, int height) : Graphics::Screen(width, height) {}
|
2014-02-25 23:10:51 -05:00
|
|
|
|
2014-02-19 21:56:38 -05:00
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
2016-05-26 21:37:52 -04:00
|
|
|
virtual ~BaseSurface() {}
|
2014-02-19 20:22:06 -05:00
|
|
|
|
2014-02-22 17:25:30 -05:00
|
|
|
/**
|
2016-03-10 21:51:23 -05:00
|
|
|
* Return a rect containing the bounds of the surface
|
2014-02-22 17:25:30 -05:00
|
|
|
*/
|
2016-03-10 21:51:23 -05:00
|
|
|
Common::Rect getBounds() { return Common::Rect(0, 0, this->w, this->h); }
|
2014-02-22 17:25:30 -05:00
|
|
|
|
2014-02-19 20:22:06 -05:00
|
|
|
/**
|
2016-03-10 21:51:23 -05:00
|
|
|
* Return the pixels for the surface
|
2014-02-19 20:22:06 -05:00
|
|
|
*/
|
2016-03-10 21:51:23 -05:00
|
|
|
inline byte *getPixels() { return (byte *)Graphics::ManagedSurface::getPixels(); }
|
2014-05-08 11:43:23 +03:00
|
|
|
|
2014-02-19 20:22:06 -05:00
|
|
|
/**
|
2016-03-10 21:51:23 -05:00
|
|
|
* Return the pixels for the surface
|
2014-02-19 20:22:06 -05:00
|
|
|
*/
|
2016-03-10 21:51:23 -05:00
|
|
|
inline const void *getPixels() const { return (const byte *)Graphics::ManagedSurface::getPixels(); }
|
2014-02-19 20:22:06 -05:00
|
|
|
|
2014-03-05 09:04:53 -05:00
|
|
|
/**
|
2016-03-10 21:51:23 -05:00
|
|
|
* Return a pointer to a given position on the surface
|
2014-02-19 20:22:06 -05:00
|
|
|
*/
|
2016-03-10 21:51:23 -05:00
|
|
|
byte *getBasePtr(int x, int y) { return (byte *)Graphics::ManagedSurface::getBasePtr(x, y); }
|
2014-02-19 20:22:06 -05:00
|
|
|
|
|
|
|
/**
|
2016-03-10 21:51:23 -05:00
|
|
|
* Return a pointer to a given position on the surface
|
2014-02-19 20:22:06 -05:00
|
|
|
*/
|
2016-03-10 21:51:23 -05:00
|
|
|
inline const byte *getBasePtr(int x, int y) const { return (const byte *)Graphics::ManagedSurface::getBasePtr(x, y); }
|
2014-02-19 20:22:06 -05:00
|
|
|
|
|
|
|
/**
|
2016-03-10 21:51:23 -05: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
|
2014-02-19 20:22:06 -05:00
|
|
|
*/
|
2016-03-10 21:51:23 -05:00
|
|
|
void drawSprite(const Common::Point &pt, SpriteInfo &info, const Common::Rect &clipRect);
|
2014-02-18 20:08:58 -05:00
|
|
|
|
2014-03-05 20:45:02 -05:00
|
|
|
/**
|
|
|
|
* Scroll the screen horizontally by a given amount
|
|
|
|
* @param xAmount Horizontal amount
|
|
|
|
*/
|
|
|
|
void scrollX(int xAmount);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scroll the screen vertically by a given amount
|
|
|
|
* @param yAmount Vertical amount
|
|
|
|
*/
|
|
|
|
void scrollY(int yAmount);
|
|
|
|
|
2014-02-19 20:22:06 -05:00
|
|
|
/**
|
2014-02-28 20:37:42 -05:00
|
|
|
* Translates the pixels of an image used the passed palette with RGB mapping
|
2014-02-19 20:22:06 -05:00
|
|
|
*/
|
2014-02-28 20:37:42 -05:00
|
|
|
void translate(Common::Array<RGB6> &palette);
|
2014-03-05 09:04:53 -05:00
|
|
|
|
2014-05-11 18:08:31 -04:00
|
|
|
/**
|
|
|
|
* Translates the pixels of an image used the passed palette with RGB mapping
|
|
|
|
*/
|
|
|
|
void translate(byte map[PALETTE_COUNT]);
|
|
|
|
|
2014-03-05 09:04:53 -05:00
|
|
|
/**
|
|
|
|
* Create a new surface which is a flipped horizontal copy of the current one
|
|
|
|
*/
|
2016-05-26 21:37:52 -04:00
|
|
|
BaseSurface *flipHorizontal() const;
|
2015-02-08 22:07:42 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy an area from one surface to another, translating it using a palette
|
|
|
|
* map as it's done
|
|
|
|
*/
|
2016-05-26 21:37:52 -04:00
|
|
|
void copyRectTranslate(BaseSurface &srcSurface, const byte *paletteMap,
|
2015-02-08 22:07:42 -05:00
|
|
|
const Common::Point &destPos, const Common::Rect &srcRect);
|
2016-03-10 21:51:23 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copys a sub-section of another surface into the current one.
|
|
|
|
* @param src Source surface
|
|
|
|
* @param destPos Destination position to draw in current surface
|
|
|
|
* @param depth Depth of sprite
|
|
|
|
* @param depthSurface Depth surface to use with sprite depth
|
|
|
|
* @param scale Scale for image
|
|
|
|
* @param flipped Flag for whether image is to be flipped
|
|
|
|
* @param transparentColor Transparency palette index
|
|
|
|
*/
|
2016-05-26 21:37:52 -04:00
|
|
|
void copyFrom(BaseSurface &src, const Common::Point &destPos, int depth, DepthSurface *depthSurface,
|
2016-03-10 21:51:23 -05:00
|
|
|
int scale, bool flipped, int transparentColor = -1);
|
2014-02-18 20:08:58 -05:00
|
|
|
};
|
|
|
|
|
2016-05-26 21:37:52 -04:00
|
|
|
class MSurface : public BaseSurface {
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Override the addDirtyRect from Graphics::Screen, since for standard
|
|
|
|
* surfaces we don't need dirty rects to be tracked
|
|
|
|
*/
|
|
|
|
virtual void addDirtyRect(const Common::Rect &r) {}
|
|
|
|
public:
|
|
|
|
MSurface() : BaseSurface() {}
|
|
|
|
MSurface(int width, int height) : BaseSurface(width, height) {}
|
|
|
|
};
|
|
|
|
|
2014-03-06 22:31:41 -05:00
|
|
|
class DepthSurface : public MSurface {
|
|
|
|
public:
|
2014-07-24 21:09:34 -04:00
|
|
|
/**
|
|
|
|
* Depth style
|
|
|
|
*/
|
|
|
|
int _depthStyle;
|
|
|
|
|
2014-03-06 22:31:41 -05:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
2016-03-10 21:51:23 -05:00
|
|
|
DepthSurface() : MSurface(), _depthStyle(0) {}
|
2014-03-06 22:31:41 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the depth at a given position
|
|
|
|
*/
|
|
|
|
int getDepth(const Common::Point &pt);
|
2014-03-16 14:53:10 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
int getDepthHighBit(const Common::Point &pt);
|
2014-03-06 22:31:41 -05:00
|
|
|
};
|
|
|
|
|
2014-02-18 20:08:58 -05:00
|
|
|
} // End of namespace MADS
|
|
|
|
|
|
|
|
#endif /* MADS_MSURFACE_H */
|