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 QUEEN_DISPLAY_H
24 #define QUEEN_DISPLAY_H
25 
26 #include "common/str.h"
27 #include "common/util.h"
28 #include "common/random.h"
29 #include "queen/defs.h"
30 
31 class OSystem;
32 
33 namespace Common {
34 struct Rect;
35 }
36 
37 namespace Queen {
38 
39 class QueenEngine;
40 
41 class Display {
42 public:
43 
44 	Display(QueenEngine *vm, OSystem *system);
45 	~Display();
46 
47 	//! initialize dynalum for the specified room
48 	void dynalumInit(const char *roomName, uint16 roomNum);
49 
50 	//! update dynalum for the current room
51 	void dynalumUpdate(int16 x, int16 y);
52 
53 	//! update the palette
54 	void palSet(const uint8 *pal, int start, int end, bool updateScreen = false);
55 
56 	//! setup palette for Joe's dress
57 	void palSetJoeDress();
58 
59 	//! setup palette for Joe's normal clothes
60 	void palSetJoeNormal();
61 
62 	//! setup palette for panel and inventory objects
63 	void palSetPanel();
64 
65 	//! fade the current palette in
66 	void palFadeIn(uint16 roomNum, bool dynalum = false, int16 dynaX = 0, int16 dynaY = 0);
67 
68 	//! fade the current palette out
69 	void palFadeOut(uint16 roomNum);
70 
71 	//! grey the panel area (used when panel is disabled)
72 	void palGreyPanel();
73 
74 	//! scroll some palette colors
75 	void palScroll(int start, int end);
76 
77 	void palSetAmigaColor(uint8 color, uint16 rgb);
78 
79 	//! custom palette effect for the specified room
80 	void palCustomColors(uint16 roomNum);
81 
82 	//! custom palette scroll for the specified room
83 	void palCustomScroll(uint16 roomNum);
84 
85 	//! process a 'palette flash' effect
86 	void palCustomFlash();
87 
88 	void palCustomLightsOff(uint16 roomNum);
89 	void palCustomLightsOn(uint16 roomNum);
90 
91 	//! mark all palette entries as dirty
palSetAllDirty()92 	void palSetAllDirty() { _pal.dirtyMin = 0; _pal.dirtyMax = 255; }
93 
94 	//! returns the number of colors used by the room
95 	int getNumColorsForRoom(uint16 room) const;
96 
97 	//! returns true if we shouldn't fade the palette in the specified room
98 	bool isPalFadingDisabled(uint16 room) const;
99 
100 	//! change fullscreen/panel mode
101 	void screenMode(int comPanel, bool inCutaway);
102 
103 	void prepareUpdate();
104 	void update(bool dynalum = false, int16 dynaX = 0, int16 dynaY = 0);
105 
106 	void setupPanel();
107 	void setupNewRoom(const char *name, uint16 room);
108 
109 	void drawBobSprite(const uint8 *data, uint16 x, uint16 y, uint16 w, uint16 h, uint16 pitch, bool xflip);
110 	void drawBobPasteDown(const uint8 *data, uint16 x, uint16 y, uint16 w, uint16 h);
111 	void drawInventoryItem(const uint8 *data, uint16 x, uint16 y, uint16 w, uint16 h);
112 
113 	void blit(uint8 *dstBuf, uint16 dstPitch, uint16 x, uint16 y, const uint8 *srcBuf, uint16 srcPitch, uint16 w, uint16 h, bool xflip, bool masked);
114 	void fill(uint8 *dstBuf, uint16 dstPitch, uint16 x, uint16 y, uint16 w, uint16 h, uint8 color);
115 
116 	//! decode PCX picture data
117 	void decodePCX(const uint8 *src, uint32 srcSize, uint8 *dst, uint16 dstPitch, uint16 *w, uint16 *h, uint8 *pal, uint16 palStart, uint16 palEnd);
118 
119 	//! decode IFF picture data
120 	void decodeIFF(const uint8 *src, uint32 srcSize, uint8 *dst, uint16 dstPitch, uint16 *w, uint16 *h, uint8 *pal, uint16 palStart, uint16 palEnd, uint8 colorBase = 0);
121 
122 	void horizontalScrollUpdate(int16 xCamera);
123 	void horizontalScroll(int16 scroll);
horizontalScroll()124 	int16 horizontalScroll() const { return _horizontalScroll; }
125 
fullscreen(bool fs)126 	void fullscreen(bool fs) { _fullRefresh = 2; _fullscreen = fs; }
fullscreen()127 	bool fullscreen() const { return _fullscreen; }
128 
129 	//! mark the specified block as dirty
130 	void setDirtyBlock(uint16 x, uint16 y, uint16 w, uint16 h);
131 
132 	//! force a full refresh (bypassing the dirtyblocks rendering), on next screen update
forceFullRefresh()133 	void forceFullRefresh() { _fullRefresh = 2; }
134 
135 	//! change mouse cursor bitmap
136 	void setMouseCursor(uint8 *buf, uint16 w, uint16 h);
137 
138 	//! show/hide mouse cursor
139 	void showMouseCursor(bool show);
140 
141 	//! initialize font, compute justification sizes
142 	void initFont();
143 
144 	//! add the specified text to the texts list
145 	void setText(uint16 x, uint16 y, const char *text, bool outlined = true);
146 
147 	//! add the specified text to the texts list
148 	void setTextCentered(uint16 y, const char *text, bool outlined = true);
149 
150 	//! draw the text lists
151 	void drawTexts();
152 
153 	//! remove entries from the texts list
154 	void clearTexts(uint16 y1, uint16 y2);
155 
156 	void setupInkColors();
157 
getInkColor(InkColor color)158 	uint8 getInkColor(InkColor color) const { return _inkColors[color]; }
159 
160 	//! change the current text color
textCurrentColor(uint8 color)161 	void textCurrentColor(uint8 color) { _curTextColor = color; }
162 
163 	//! change the text color for the specified texts list entry
textColor(uint16 y,uint8 color)164 	void textColor(uint16 y, uint8 color) { _texts[y].color = color; }
165 
166 	//! Set the focus rectangle to the speaking character
167 	void setFocusRect(const Common::Rect& rect);
168 
169 	int textCenterX(const char *text) const;
170 	uint16 textWidth(const char *text) const;
171 	uint16 textWidth(const char *text, uint16 len) const;
172 	void drawChar(uint16 x, uint16 y, uint8 color, const uint8 *chr);
173 	void drawText(uint16 x, uint16 y, uint8 color, const char *text, bool outlined = true);
174 	void drawBox(int16 x1, int16 y1, int16 x2, int16 y2, uint8 col);
175 
176 	void shake(bool reset);
177 
178 	void blankScreen();
179 	void blankScreenEffect1();
180 	void blankScreenEffect2();
181 	void blankScreenEffect3();
182 
183 private:
184 
185 	enum {
186 		FADE_SPEED = 16,
187 		D_BLOCK_W  =  8,
188 		D_BLOCK_H  =  8
189 	};
190 
191 	enum BufferDimension {
192 		BACKDROP_W = 640,
193 		BACKDROP_H = 200,
194 		SCREEN_W   = 320,
195 		SCREEN_H   = 200,
196 		PANEL_W    = 320,
197 		PANEL_H    =  50
198 	};
199 
200 	struct {
201 		uint8 *room;
202 		uint8 *screen;
203 		uint8 *panel;
204 		int dirtyMin, dirtyMax;
205 		bool scrollable;
206 	} _pal;
207 
208 	struct Dynalum {
209 		bool valid;
210 		uint8 *mskBuf;
211 		uint32 mskSize;
212 		int8 *lumBuf;
213 		uint32 lumSize;
214 		uint8 prevColMask;
215 	};
216 
217 	struct TextSlot {
218 		uint16 x;
219 		uint8 color;
220 		Common::String text;
221 		bool outlined;
222 	};
223 
224 	uint8 *_screenBuf;
225 	uint8 *_panelBuf;
226 	uint8 *_backdropBuf;
227 
228 	uint8 _fullRefresh;
229 	uint8 *_dirtyBlocks;
230 	uint16 _dirtyBlocksWidth, _dirtyBlocksHeight;
231 
232 	bool _fullscreen;
233 
234 	uint16 _horizontalScroll;
235 	uint16 _bdWidth, _bdHeight;
236 
237 	const char *_imageExt;
238 
239 	//! texts list
240 	TextSlot _texts[GAME_SCREEN_HEIGHT];
241 
242 	//! current text color to use for display
243 	uint8 _curTextColor;
244 
245 	//! font justification sizes
246 	uint8 _charWidth[256];
247 
248 	uint8 _inkColors[INK_COUNT];
249 
250 	Common::RandomSource _rnd;
251 	Dynalum _dynalum;
252 	OSystem *_system;
253 	QueenEngine *_vm;
254 
255 	const uint8 *_font;
256 
257 	static const uint8 _fontRegular[];
258 	static const uint8 _fontHebrew[];
259 	static const uint8 _fontRussian[];
260 	static const uint8 _fontGreek[];
261 	static const uint8 _palJoeClothes[];
262 	static const uint8 _palJoeDress[];
263 };
264 
265 
266 } // End of namespace Queen
267 
268 #endif
269