diff options
Diffstat (limited to 'engines/mohawk/graphics.h')
-rw-r--r-- | engines/mohawk/graphics.h | 115 |
1 files changed, 62 insertions, 53 deletions
diff --git a/engines/mohawk/graphics.h b/engines/mohawk/graphics.h index 9419aad277..38d174b481 100644 --- a/engines/mohawk/graphics.h +++ b/engines/mohawk/graphics.h @@ -30,6 +30,7 @@ #include "mohawk/livingbooks.h" #include "common/file.h" +#include "common/hashmap.h" #include "graphics/pict.h" #include "graphics/video/codecs/mjpeg.h" @@ -40,57 +41,56 @@ class MohawkEngine_Riven; class MohawkBitmap; class MystBitmap; -enum { - kRivenOpenHandCursor = 2003, - kRivenClosedHandCursor = 2004, - kRivenMainCursor = 3000, - kRivenPelletCursor = 5000, - kRivenHideCursor = 9000 -}; +class MohawkSurface { +public: + MohawkSurface(); + MohawkSurface(Graphics::Surface *surface, byte *palette = NULL, int offsetX = 0, int offsetY = 0); + ~MohawkSurface(); + + // getSurface() returns the surface in the current format + // This will be the initial format unless convertToTrueColor() is called + Graphics::Surface *getSurface() const { return _surface; } + byte *getPalette() const { return _palette; } + + // Convert the 8bpp image to the current screen format + // Does nothing if _surface is already >8bpp + void convertToTrueColor(); + + // Functions for OldMohawkBitmap offsets + // They both default to 0 + int getOffsetX() const { return _offsetX; } + int getOffsetY() const { return _offsetY; } + void setOffsetX(int x) { _offsetX = x; } + void setOffsetY(int y) { _offsetY = y; } -// 803-805 are animated, one large bmp which is in chunks -// Other cursors (200, 300, 400, 500, 600, 700) are not the same in each stack -enum { - kDefaultMystCursor = 100, // The default hand - kWhitePageCursor = 800, // Holding a white page - kRedPageCursor = 801, // Holding a red page - kBluePageCursor = 802, // Holding a blue page - // kDroppingWhitePageAnimCursor = 803, - // kDroppingRedPageAnimCursor = 804, - // kDroppingBluePageAnimCursor = 805, - kNewMatchCursor = 900, // Match that has not yet been lit - kLitMatchCursor = 901, // Match that's burning - kDeadMatchCursor = 902, // Match that's been extinguished - kKeyCursor = 903, // Key in Lighthouse in Stoneship - kRotateClockwiseCursor = 904, // Rotate gear clockwise (boiler on Myst) - kRotateCounterClockwiseCursor = 905, // Rotate gear counter clockwise (boiler on Myst) - kMystZipModeCursor = 999 // Zip Mode cursor +private: + Graphics::Surface *_surface; + byte *_palette; + int _offsetX, _offsetY; }; -// A simple struct to hold necessary image info -class ImageData { +class GraphicsManager { public: - ImageData() : _surface(0), _palette(0) {} - ImageData(Graphics::Surface *surface, byte *palette = NULL) : _surface(surface), _palette(palette) {} - ~ImageData() { - if (_palette) - free(_palette); - if (_surface) { - _surface->free(); - delete _surface; - } - } - - // getSurface() will convert to the current screen format, if it's not already - // in that format. Makes it easy to support both 8bpp and 24bpp images. - Graphics::Surface *getSurface(); - - // These are still public in case the 8bpp surface needs to be accessed - Graphics::Surface *_surface; - byte *_palette; + GraphicsManager(); + virtual ~GraphicsManager(); + + // Free all surfaces in the cache + void clearCache(); + +protected: + // findImage will search the cache to find the image. + // If not found, it will call decodeImage to get a new one. + MohawkSurface *findImage(uint16 id); + + // decodeImage will always return a new image. + virtual MohawkSurface *decodeImage(uint16 id) = 0; + +private: + // An image cache that stores images until clearCache() is called + Common::HashMap<uint16, MohawkSurface*> _cache; }; -class MystGraphics { +class MystGraphics : public GraphicsManager { public: MystGraphics(MohawkEngine_Myst*); ~MystGraphics(); @@ -98,17 +98,18 @@ public: void loadExternalPictureFile(uint16 stack); void copyImageSectionToScreen(uint16 image, Common::Rect src, Common::Rect dest); void copyImageToScreen(uint16 image, Common::Rect dest); - void showCursor(); - void hideCursor(); - void changeCursor(uint16); + void updateScreen(); void drawRect(Common::Rect rect, bool active); + +protected: + MohawkSurface *decodeImage(uint16 id); + private: MohawkEngine_Myst *_vm; MystBitmap *_bmpDecoder; Graphics::PictDecoder *_pictDecoder; Graphics::JPEGDecoder *_jpegDecoder; - Graphics::PixelFormat _pixelFormat; struct PictureFile { uint32 pictureCount; @@ -123,6 +124,10 @@ private: Common::File picFile; } _pictureFile; + + Graphics::Surface *_mainScreen; + bool _dirtyScreen; + Graphics::PixelFormat _pixelFormat; }; struct SFXERecord { @@ -137,7 +142,7 @@ struct SFXERecord { uint32 lastFrameTime; }; -class RivenGraphics { +class RivenGraphics : public GraphicsManager { public: RivenGraphics(MohawkEngine_Riven *vm); ~RivenGraphics(); @@ -145,7 +150,6 @@ public: void copyImageToScreen(uint16, uint32, uint32, uint32, uint32); void updateScreen(); bool _updatesEnabled; - void changeCursor(uint16); Common::Array<uint16> _activatedPLSTs; void drawPLST(uint16 x); void drawRect(Common::Rect rect, bool active); @@ -165,6 +169,9 @@ public: void showInventory(); void hideInventory(); +protected: + MohawkSurface *decodeImage(uint16 id); + private: MohawkEngine_Riven *_vm; MohawkBitmap *_bitmapDecoder; @@ -187,7 +194,7 @@ private: Graphics::PixelFormat _pixelFormat; }; -class LBGraphics { +class LBGraphics : public GraphicsManager { public: LBGraphics(MohawkEngine_LivingBooks *vm); ~LBGraphics(); @@ -195,10 +202,12 @@ public: void copyImageToScreen(uint16 image, uint16 left = 0, uint16 top = 0); void setPalette(uint16 id); +protected: + MohawkSurface *decodeImage(uint16 id); + private: MohawkBitmap *_bmpDecoder; MohawkEngine_LivingBooks *_vm; - byte *_palette; }; } // End of namespace Mohawk |