1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
|
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef CINE_GFX_H
#define CINE_GFX_H
#include "common/noncopyable.h"
#include "common/rect.h"
#include "common/stack.h"
#include "cine/object.h"
#include "cine/bg_list.h"
namespace Cine {
extern byte *collisionPage;
static const int kCollisionPageBgIdxAlias = 8;
enum BackBufferSource {
BEFORE_OPENING_MENU = 0,
BEFORE_TAKING_THUMBNAIL,
MAX_BACK_BUFFER_SOURCES
};
/**
* Background with palette
*/
struct palBg {
byte *bg; ///< Background data
Cine::Palette pal; ///< Background color palette
char name[15]; ///< Background filename
/** @brief Default constructor. */
palBg() : bg(NULL), pal(), name() {
// Make sure the name is empty (Maybe this is not needed?)
memset(this->name, 0, sizeof(this->name));
}
/** @brief Clears the struct (Releases allocated memory etc). */
void clear() {
// In Operation Stealth the 9th background is sometimes aliased to
// the collision page so we should take care not to double delete it
// (The collision page is deleted elsewhere).
if (this->bg != collisionPage) {
delete[] this->bg;
}
this->bg = NULL;
this->pal.clear();
memset(this->name, 0, sizeof(this->name));
}
};
class FWRenderer;
class Menu {
public:
enum Type {
kSelectionMenu,
kTextInputMenu
};
Menu(Type t) : _type(t) {}
virtual ~Menu() {}
Type getType() const { return _type; }
virtual void drawMenu(FWRenderer &r, bool top) = 0;
private:
const Type _type;
};
class SelectionMenu : public Menu {
public:
SelectionMenu(Common::Point p, int width, Common::StringArray elements);
int getElementCount() const { return _elements.size(); }
void setSelection(int selection);
void drawMenu(FWRenderer &r, bool top) override;
private:
const Common::Point _pos;
const int _width;
const Common::StringArray _elements;
int _selection;
};
class TextInputMenu : public Menu {
public:
TextInputMenu(Common::Point p, int width, const char *info);
void setInput(const char *input, int cursor);
void drawMenu(FWRenderer &r, bool top) override;
private:
const Common::Point _pos;
const int _width;
const Common::String _info;
Common::String _input;
int _cursor;
};
/**
* Future Wars renderer
*
* Screen backbuffer is not cleared between frames.
*/
class FWRenderer : public Common::NonCopyable {
// TODO: Consider getting rid of this
friend class SelectionMenu;
friend class TextInputMenu;
private:
byte * _savedBackBuffers[MAX_BACK_BUFFER_SOURCES];
byte *_background; ///< Current background
char _bgName[13]; ///< Background filename
Common::String _cmd; ///< Player command string
protected:
static const int _screenSize = 320 * 200; ///< Screen size
static const int _screenWidth = 320; ///< Screen width
static const int _screenHeight = 200; ///< Screen height
byte *_backBuffer; ///< Screen backbuffer
Cine::Palette _backupPal; ///< The backup color palette
Cine::Palette _activePal; ///< The active color palette
Common::Stack<Menu *> _menuStack; ///< All displayed menus
int _changePal; ///< Load active palette to video backend on next frame
bool _showCollisionPage; ///< Should we show the collision page instead of the back buffer? Used for debugging.
uint32 _fadeToBlackLastCalledMs;
virtual const Cine::Palette& getFadeInSourcePalette();
void fillSprite(const ObjectStruct &obj, uint8 color = 0);
void drawMaskedSprite(const ObjectStruct &obj, const byte *mask);
virtual void drawSprite(const ObjectStruct &obj);
int drawMessage(const char *str, int x, int y, int width, int color, bool draw = true);
void drawPlainBox(int x, int y, int width, int height, byte color);
byte transparentDialogBoxStartColor();
void drawTransparentBox(int x, int y, int width, int height);
void drawBorder(int x, int y, int width, int height, byte color);
void drawDoubleBorder(int x, int y, int width, int height, byte color);
virtual int drawChar(char character, int x, int y, bool draw = true);
virtual int undrawChar(char character, int x, int y);
void drawLine(int x, int y, int width, int height, byte color);
void remaskSprite(byte *mask, Common::List<overlay>::iterator it);
virtual void drawBackground();
virtual void clearBackBuffer();
virtual void removeSavedBackBuffers();
virtual void renderOverlay(const Common::List<overlay>::iterator &it);
void drawOverlays();
virtual void blit(bool useCollisionPage);
public:
uint16 _messageBg; ///< Message box background color
uint16 _cmdY; ///< Player command string position on screen
FWRenderer();
virtual ~FWRenderer();
virtual bool initialize();
/** Test if renderer is ready to draw */
virtual bool ready() { return _background != NULL; }
virtual unsigned int currentBg() { return 0; };
virtual unsigned int scrollBg() { return 0; }
virtual bool useTransparentDialogBoxes();
virtual void clear();
void drawFrame(bool wait = false);
void drawCommand();
void setCommand(Common::String cmd);
Common::String getCommand();
virtual void blit();
virtual void blitBackBuffer();
virtual void incrustMask(const BGIncrust &incrust, uint8 color = 0);
virtual void incrustSprite(const BGIncrust &incrust);
virtual bool hasSavedBackBuffer(BackBufferSource source);
/** Saves back buffer content without palette. */
virtual void saveBackBuffer(BackBufferSource source);
virtual void popSavedBackBuffer(BackBufferSource source);
/** Restores back buffer content without palette. */
virtual void restoreSavedBackBuffer(BackBufferSource source);
virtual void removeSavedBackBuffer(BackBufferSource source);
virtual int16 addBackground(const char *bgName, uint16 bgIdx);
virtual void loadBg16(const byte *bg, const char *name, unsigned int idx = 0);
virtual void loadCt16(const byte *ct, const char *name);
virtual void loadBg256(const byte *bg, const char *name, unsigned int idx = 0);
virtual void loadCt256(const byte *ct, const char *name);
virtual void selectBg(unsigned int idx);
virtual void selectScrollBg(unsigned int idx);
virtual void setScroll(unsigned int shift);
virtual uint getScroll() const;
virtual void removeBg(unsigned int idx);
virtual void saveBgNames(Common::OutSaveFile &fHandle);
virtual const char *getBgName(uint idx = 0) const;
virtual void setBlackPalette(bool updateChangePal);
virtual void setPalette();
virtual void restorePalette(Common::SeekableReadStream &fHandle, int version);
virtual void savePalette(Common::OutSaveFile &fHandle);
virtual void rotatePalette(int firstIndex, int lastIndex, int mode);
virtual void transformPalette(int first, int last, int r, int g, int b);
void pushMenu(Menu *menu);
Menu *popMenu();
void clearMenuStack();
virtual uint fadeDelayMs();
virtual uint fadeToBlackMinMs();
virtual void fadeToBlack();
virtual void fadeFromBlack();
void showCollisionPage(bool state);
void drawString(const char *string, byte param);
int getStringWidth(const char *str);
};
/**
* Operation Stealth renderer
*/
class OSRenderer : public FWRenderer {
private:
Common::Array<palBg> _bgTable; ///< Table of backgrounds loaded into renderer (Maximum is 9)
unsigned int _currentBg; ///< Current background
unsigned int _scrollBg; ///< Current scroll background
unsigned int _bgShift; ///< Background shift
protected:
void setBackground8ToCollisionPage();
const Cine::Palette& getFadeInSourcePalette() override;
void drawSprite(const ObjectStruct &obj) override;
void drawSprite(overlay *overlayPtr, const byte *spritePtr, int16 width, int16 height, byte *page, int16 x, int16 y, byte transparentColor, byte bpp);
int drawChar(char character, int x, int y, bool draw = true) override;
void drawBackground() override;
void renderOverlay(const Common::List<overlay>::iterator &it) override;
public:
OSRenderer();
~OSRenderer() override;
bool initialize() override;
/** Test if renderer is ready to draw */
bool ready() override { return _bgTable[_currentBg].bg != NULL; }
unsigned int currentBg() override { return _currentBg; };
unsigned int scrollBg() override { return _scrollBg; }
void clear() override;
void incrustMask(const BGIncrust &incrust, uint8 color = 0) override;
void incrustSprite(const BGIncrust &incrust) override;
int16 addBackground(const char *bgName, uint16 bgIdx) override;
void loadBg16(const byte *bg, const char *name, unsigned int idx = 0) override;
void loadCt16(const byte *ct, const char *name) override;
void loadBg256(const byte *bg, const char *name, unsigned int idx = 0) override;
void loadCt256(const byte *ct, const char *name) override;
void selectBg(unsigned int idx) override;
void selectScrollBg(unsigned int idx) override;
void setScroll(unsigned int shift) override;
uint getScroll() const override;
void removeBg(unsigned int idx) override;
void saveBgNames(Common::OutSaveFile &fHandle) override;
const char *getBgName(uint idx = 0) const override;
void restorePalette(Common::SeekableReadStream &fHandle, int version) override;
void savePalette(Common::OutSaveFile &fHandle) override;
void rotatePalette(int firstIndex, int lastIndex, int mode) override;
void transformPalette(int first, int last, int r, int g, int b) override;
};
void gfxDrawSprite(byte *src4, uint16 sw, uint16 sh, byte *dst4, int16 sx, int16 sy);
extern FWRenderer *renderer;
void setMouseCursor(int cursor);
void gfxCopyPage(byte *source, byte *dest);
void transformPaletteRange(byte startColor, byte numColor, int8 r, int8 g, int8 b);
void gfxFlipPage();
void gfxDrawMaskedSprite(const byte *ptr, const byte *msk, uint16 width, uint16 height, byte *page, int16 x, int16 y);
void gfxFillSprite(const byte *src4, uint16 sw, uint16 sh, byte *dst4, int16 sx, int16 sy, uint8 fillColor = 0);
void gfxUpdateSpriteMask(byte *destMask, int16 x, int16 y, int16 width, int16 height, const byte *maskPtr, int16 xm, int16 ym, int16 maskWidth, int16 maskHeight);
void gfxDrawLine(int16 x1, int16 y1, int16 x2, int16 y2, byte color, byte *page);
void gfxDrawPlainBox(int16 x1, int16 y1, int16 x2, int16 y2, byte color);
void gfxResetPage(byte *pagePtr);
int16 gfxGetBit(int16 x, int16 y, const byte *ptr, int16 width);
byte gfxGetColor(int16 x, int16 y, const byte *ptr, int16 width);
void gfxResetRawPage(byte *pageRaw);
void gfxConvertSpriteToRaw(byte *dst, const byte *src, uint16 w, uint16 h);
void gfxCopyRawPage(byte *source, byte *dest);
void gfxFlipRawPage(byte *frontBuffer);
void drawSpriteRaw(const byte *spritePtr, const byte *maskPtr, int16 width, int16 height, byte *page, int16 x, int16 y);
void gfxDrawPlainBoxRaw(int16 x1, int16 y1, int16 x2, int16 y2, byte color, byte *page);
void drawSpriteRaw2(const byte *spritePtr, byte transColor, int16 width, int16 height, byte *page, int16 x, int16 y);
void maskBgOverlay(int targetBgIdx, const byte *spritePtr, const byte *maskPtr, int16 width, int16 height, byte *page, int16 x, int16 y);
void fadeFromBlack();
void fadeToBlack();
//void gfxDrawMaskedSprite(byte *param1, byte *param2, byte *param3, byte *param4, int16 param5);
void gfxWaitVBL();
void gfxRedrawMouseCursor();
void blitScreen(byte *frontBuffer, byte *backbuffer);
void blitRawScreen(byte *frontBuffer);
void flip();
} // End of namespace Cine
#endif
|