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 #ifndef DRAGONS_SCREEN_H
23 #define DRAGONS_SCREEN_H
24 
25 #include "graphics/surface.h"
26 #include "graphics/pixelformat.h"
27 #include "common/scummsys.h"
28 #include "common/rect.h"
29 
30 namespace Dragons {
31 #define DRAGONS_NUM_PALETTES 5
32 #define DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE 256
33 
34 #define DRAGONS_SCREEN_WIDTH 320
35 #define DRAGONS_SCREEN_HEIGHT 200
36 
37 #define DRAGONS_NUM_FLAT_QUADS 0xf
38 
39 #ifdef SCUMM_BIG_ENDIAN
40 	#define WRITE_SCREEN WRITE_BE_UINT16
41 	#define READ_SCREEN READ_BE_INT16
42 #else
43 	#define WRITE_SCREEN WRITE_LE_UINT16
44 	#define READ_SCREEN READ_LE_INT16
45 #endif
46 
47 enum AlphaBlendMode {
48 	NONE,
49 	NORMAL,       // 50% x Back + 50% x Sprite
50 	ADDITIVE,     // 100% x Back + 100% x Sprite
51 	ADDITIVE_50,  // 100% x Back + 50% x Sprite
52 	SUBTRACTIVE   // 100% x Back - 100% x Sprite
53 };
54 
55 struct FlatQuad {
56 	uint16 flags;
57 	uint16 priorityLayer;
58 	Common::Point points[4];
59 	uint16 colour;
60 
FlatQuadFlatQuad61 	FlatQuad() {
62 		flags = 0;
63 		priorityLayer = 0;
64 		colour = 0;
65 	}
66 };
67 
68 class Screen {
69 private:
70 	Graphics::PixelFormat _pixelFormat;
71 	Graphics::Surface *_backSurface;
72 	byte _palettes[DRAGONS_NUM_PALETTES][512];
73 	Common::Point _screenShakeOffset;
74 	FlatQuad _flatQuads[DRAGONS_NUM_FLAT_QUADS];
75 public:
76 	virtual ~Screen();
77 
78 	Screen();
79 
getPixelFormat()80 	Graphics::PixelFormat getPixelFormat() { return _pixelFormat; }
81 	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY);
82 	void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, Common::Rect srcRect, bool flipX = false, AlphaBlendMode alpha = NONE);
83 	void copyRectToSurface8bpp(const Graphics::Surface &srcSurface, const byte *palette, int destX, int destY, Common::Rect srcRect, bool flipX = false, AlphaBlendMode alpha = NONE, uint16 scale = DRAGONS_ENGINE_SPRITE_100_PERCENT_SCALE);
84 	void copyRectToSurface8bppWrappedX(const Graphics::Surface &srcSurface, const byte *palette, Common::Rect srcRect, AlphaBlendMode alpha = NONE);
85 	void updateScreen();
86 	void loadPalette(uint16 paletteNum, const byte *palette);
87 	byte *getPalette(uint16 paletteNum);
88 	void setPaletteRecord(uint16 paletteNum, uint16 offset, uint16 newValue);
89 	void updatePaletteTransparency(uint16 paletteNum, uint16 startOffset, uint16 endOffset, bool isTransparent);
90 	void clearScreen();
91 	void drawRect(uint16 colour, Common::Rect rect, int id);
92 	void fillRect(uint16 colour, Common::Rect rect);
93 	Common::Rect clipRectToScreen(int destX, int destY, const Common::Rect rect);
94 	Common::Rect clipRectToRect(int destX, int destY, const Common::Rect rect, const Common::Rect containerRect);
95 
96 	void setScreenShakeOffset(int16 x, int16 y);
97 
98 	void copyRectToSurface8bppWrappedY(const Graphics::Surface &srcSurface, const byte *palette, int yOffset);
99 
100 	int16 addFlatQuad(int16 x0, int16 y0, int16 x1, int16 y1, int16 x3, int16 y3, int16 x2, int16 y2, uint16 colour, int16 priorityLayer, uint16 flags);
101 	void drawFlatQuads(uint16 priorityLayer);
102 	FlatQuad *getFlatQuad(uint16 quadId);
103 	void clearAllFlatQuads();
104 
105 private:
106 	void copyRectToSurface(const void *buffer, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, AlphaBlendMode alpha);
107 	void copyRectToSurface8bpp(const void *buffer, const byte* palette, int srcPitch, int srcWidth, int srcXOffset, int destX, int destY, int width, int height, bool flipX, AlphaBlendMode alpha);
108 	void drawScaledSprite(Graphics::Surface *destSurface, const byte *source, int sourceWidth, int sourceHeight, int destX, int destY, int destWidth, int destHeight, const byte *palette, bool flipX, AlphaBlendMode alpha);
109 };
110 
111 } // End of namespace Dragons
112 
113 #endif //DRAGONS_SCREEN_H
114