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