1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef AGI_GRAPHICS_H 24 #define AGI_GRAPHICS_H 25 26 #include "agi/font.h" 27 28 namespace Agi { 29 30 #define SCRIPT_WIDTH 160 31 #define SCRIPT_HEIGHT 168 32 #define VISUAL_WIDTH 160 33 #define VISUAL_HEIGHT 200 34 #define DISPLAY_DEFAULT_WIDTH 320 35 #define DISPLAY_DEFAULT_HEIGHT 200 36 37 enum GfxScreenUpscaledMode { 38 DISPLAY_UPSCALED_DISABLED = 0, 39 DISPLAY_UPSCALED_640x400 = 1 40 }; 41 42 class AgiEngine; 43 44 enum GfxScreenMasks { 45 GFX_SCREEN_MASK_VISUAL = 1, 46 GFX_SCREEN_MASK_PRIORITY = 2, 47 GFX_SCREEN_MASK_ALL = GFX_SCREEN_MASK_VISUAL | GFX_SCREEN_MASK_PRIORITY 48 }; 49 50 struct MouseCursorData { 51 const byte *bitmapData; 52 byte *bitmapDataAllocated; 53 uint16 width; 54 uint16 height; 55 int hotspotX; 56 int hotspotY; 57 }; 58 59 class GfxMgr { 60 private: 61 AgiBase *_vm; 62 GfxFont *_font; 63 64 uint8 _paletteGfxMode[256 * 3]; 65 uint8 _paletteTextMode[256 * 3]; 66 67 uint8 _agipalPalette[16 * 3]; 68 int _agipalFileNum; 69 70 public: 71 GfxMgr(AgiBase *vm, GfxFont *font); 72 73 int initVideo(); 74 int deinitVideo(); 75 void initPalette(uint8 *destPalette, const uint8 *paletteData, uint colorCount = 16, uint fromBits = 6, uint toBits = 8); 76 void initPaletteCLUT(uint8 *destPalette, const uint16 *paletteCLUTData, uint colorCount = 16); 77 void setAGIPal(int); 78 int getAGIPalFileNum(); 79 void setPalette(bool GfxModePalette); 80 81 void initMouseCursor(MouseCursorData *mouseCursor, const byte *bitmapData, uint16 width, uint16 height, int hotspotX, int hotspotY); 82 void setMouseCursor(bool busy = false); 83 84 void setRenderStartOffset(uint16 offsetY); 85 uint16 getRenderStartDisplayOffsetY(); 86 87 void translateGamePosToDisplayScreen(int16 &x, int16 &y); 88 void translateVisualPosToDisplayScreen(int16 &x, int16 &y); 89 void translateDisplayPosToGameScreen(int16 &x, int16 &y); 90 91 void translateVisualDimensionToDisplayScreen(int16 &width, int16 &height); 92 void translateDisplayDimensionToVisualScreen(int16 &width, int16 &height); 93 94 void translateGameRectToDisplayScreen(int16 &x, int16 &y, int16 &width, int16 &height); 95 void translateVisualRectToDisplayScreen(int16 &x, int16 &y, int16 &width, int16 &height); 96 void translateDisplayRectToVisualScreen(int16 &x, int16 &y, int16 &width, int16 &height); 97 98 uint32 getDisplayOffsetToGameScreenPos(int16 x, int16 y); 99 uint32 getDisplayOffsetToVisualScreenPos(int16 x, int16 y); 100 101 void copyDisplayRectToScreen(int16 x, int16 y, int16 width, int16 height); 102 void copyDisplayRectToScreen(int16 x, int16 adjX, int16 y, int16 adjY, int16 width, int16 adjWidth, int16 height, int16 adjHeight); 103 void copyDisplayRectToScreenUsingGamePos(int16 x, int16 y, int16 width, int16 height); 104 void copyDisplayRectToScreenUsingVisualPos(int16 x, int16 y, int16 width, int16 height); 105 void copyDisplayToScreen(); 106 107 void translateFontPosToDisplayScreen(int16 &x, int16 &y); 108 void translateDisplayPosToFontScreen(int16 &x, int16 &y); 109 void translateFontDimensionToDisplayScreen(int16 &width, int16 &height); 110 void translateFontRectToDisplayScreen(int16 &x, int16 &y, int16 &width, int16 &height); 111 Common::Rect getFontRectForDisplayScreen(int16 column, int16 row, int16 width, int16 height); 112 113 private: 114 uint _pixels; 115 uint _displayPixels; 116 117 byte *_activeScreen; 118 byte *_gameScreen; // 160x168 - screen, where the actual game content is drawn to (actual graphics, not including status line, prompt, etc.) 119 byte *_priorityScreen; // 160x168 - screen contains priority information of the game screen 120 // the term "visual screen" is effectively the display screen, but at 160x200 resolution. Used for coordinate translation 121 byte *_displayScreen; // 320x200 or 640x400 - screen, that the game is rendered to and which is then copied to framebuffer 122 123 uint16 _displayScreenWidth; 124 uint16 _displayScreenHeight; 125 126 uint16 _displayFontWidth; 127 uint16 _displayFontHeight; 128 129 uint16 _displayWidthMulAdjust; 130 uint16 _displayHeightMulAdjust; 131 132 /** 133 * This variable defines, if upscaled hires is active and what upscaled mode 134 * is used. 135 */ 136 GfxScreenUpscaledMode _upscaledHires; 137 138 bool _priorityTableSet; 139 uint8 _priorityTable[SCRIPT_HEIGHT]; /**< priority table */ 140 141 MouseCursorData _mouseCursor; 142 MouseCursorData _mouseCursorBusy; 143 144 uint16 _renderStartVisualOffsetY; 145 uint16 _renderStartDisplayOffsetY; 146 147 public: getDisplayScreenWidth()148 uint16 getDisplayScreenWidth() { 149 return _displayScreenWidth; 150 } getDisplayFontWidth()151 uint16 getDisplayFontWidth() { 152 return _displayFontWidth; 153 } getDisplayFontHeight()154 uint16 getDisplayFontHeight() { 155 return _displayFontHeight; 156 } 157 getUpscaledHires()158 GfxScreenUpscaledMode getUpscaledHires() { 159 return _upscaledHires; 160 } 161 162 void debugShowMap(int mapNr); 163 164 void clear(byte color, byte priority); 165 void clearDisplay(byte color, bool copyToScreen = true); 166 void putPixel(int16 x, int16 y, byte drawMask, byte color, byte priority); 167 void putPixelOnDisplay(int16 x, int16 y, byte color); 168 void putPixelOnDisplay(int16 x, int16 adjX, int16 y, int16 adjY, byte color); 169 void putFontPixelOnDisplay(int16 baseX, int16 baseY, int16 addX, int16 addY, byte color, bool isHires); 170 171 byte getColor(int16 x, int16 y); 172 byte getPriority(int16 x, int16 y); 173 bool checkControlPixel(int16 x, int16 y, byte newPriority); 174 175 byte getCGAMixtureColor(byte color); 176 177 void render_Block(int16 x, int16 y, int16 width, int16 height, bool copyToScreen = true); 178 bool render_Clip(int16 &x, int16 &y, int16 &width, int16 &height, int16 clipAgainstWidth = SCRIPT_WIDTH, int16 clipAgainstHeight = SCRIPT_HEIGHT); 179 180 private: 181 void render_BlockEGA(int16 x, int16 y, int16 width, int16 height, bool copyToScreen); 182 void render_BlockCGA(int16 x, int16 y, int16 width, int16 height, bool copyToScreen); 183 void render_BlockHercules(int16 x, int16 y, int16 width, int16 height, bool copyToScreen); 184 185 public: 186 void transition_Amiga(); 187 void transition_AtariSt(); 188 189 void block_save(int16 x, int16 y, int16 width, int16 height, byte *bufferPtr); 190 void block_restore(int16 x, int16 y, int16 width, int16 height, byte *bufferPtr); 191 192 void drawBox(int16 x, int16 y, int16 width, int16 height, byte backgroundColor, byte lineColor); 193 void drawDisplayRect(int16 x, int16 y, int16 width, int16 height, byte color, bool copyToScreen = true); 194 void drawDisplayRect(int16 x, int16 adjX, int16 y, int16 adjY, int16 width, int16 adjWidth, int16 height, int16 adjHeight, byte color, bool copyToScreen = true); 195 private: 196 void drawDisplayRectEGA(int16 x, int16 y, int16 width, int16 height, byte color); 197 void drawDisplayRectCGA(int16 x, int16 y, int16 width, int16 height, byte color); 198 199 public: 200 void drawCharacter(int16 row, int16 column, byte character, byte foreground, byte background, bool disabledLook); 201 void drawStringOnDisplay(int16 x, int16 y, const char *text, byte foreground, byte background); 202 void drawStringOnDisplay(int16 x, int16 adjX, int16 y, int16 adjY, const char *text, byte foregroundColor, byte backgroundColor); 203 void drawCharacterOnDisplay(int16 x, int16 y, byte character, byte foreground, byte background, byte transformXOR = 0, byte transformOR = 0); 204 205 void shakeScreen(int16 repeatCount); 206 void updateScreen(); 207 208 void initPriorityTable(); 209 void createDefaultPriorityTable(uint8 *priorityTable); 210 void setPriorityTable(int16 priorityBase); 211 bool saveLoadWasPriorityTableModified(); 212 int16 saveLoadGetPriority(int16 yPos); 213 void saveLoadSetPriorityTableModifiedBool(bool wasModified); 214 void saveLoadSetPriority(int16 yPos, int16 priority); 215 void saveLoadFigureOutPriorityTableModifiedBool(); 216 217 int16 priorityToY(int16 priority); 218 int16 priorityFromY(int16 yPos); 219 }; 220 221 } // End of namespace Agi 222 223 #endif /* AGI_GRAPHICS_H */ 224