1 
2 /**
3  *
4  * @file paletteeffects.h
5  *
6  * Part of the OpenJazz project
7  *
8  * @par History:
9  * - 23rd August 2005: Created OpenJazz.h
10  * - 4th February 2009: Created palette.h from parts of OpenJazz.h
11  * - 1st August 2009: Renamed palette.h to paletteeffects.h
12  *
13  * @par Licence:
14  * Copyright (c) 2005-2010 Alister Thomson
15  *
16  * OpenJazz is distributed under the terms of
17  * the GNU General Public License, version 2.0
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22  *
23  */
24 
25 
26 #ifndef _PALETTE_H
27 #define _PALETTE_H
28 
29 
30 #include "OpenJazz.h"
31 
32 #include <SDL.h>
33 
34 
35 // Constants
36 
37 // Types of palette effect
38 #define PE_FADE   0 /* Fades to black, then remains black */
39 #define PE_ROTATE 1 /* Cyclical colour animation */
40 
41 // Level background palette effects
42 #define PE_SKY    2 /* Transfers the appropriate section of the background
43                        palette to the main palette */
44 #define PE_2D     8 /* Real parallaxing background */
45 #define PE_1D     9 /* Diagonal lines parallaxing background */
46 #define PE_WATER  11 /* The deeper below water, the darker it gets */
47 
48 
49 // Class
50 
51 /// Palette effect base class
52 class PaletteEffect {
53 
54 	protected:
55 		PaletteEffect* next; ///< Next effect to use
56 
57 	public:
58 		PaletteEffect          (PaletteEffect* nextPE);
59 		virtual ~PaletteEffect ();
60 
61 		virtual void apply (SDL_Color* shownPalette, bool direct, int mspf);
62 
63 };
64 
65 /// Dissolve from white palette effect
66 class WhiteInPaletteEffect : public PaletteEffect {
67 
68 	private:
69 		int   duration;  ///< Number of milliseconds the effect lasts
70 		fixed whiteness;
71 
72 	public:
73 		WhiteInPaletteEffect (int newDuration, PaletteEffect* nextPE);
74 
75 		void apply (SDL_Color* shownPalette, bool direct, int mspf);
76 
77 };
78 
79 /// Fade in palette effect
80 class FadeInPaletteEffect : public PaletteEffect {
81 
82 	private:
83 		int   duration;  ///< Number of milliseconds the effect lasts
84 		fixed blackness;
85 
86 	public:
87 		FadeInPaletteEffect (int newDuration, PaletteEffect* nextPE);
88 
89 		void apply (SDL_Color* shownPalette, bool direct, int mspf);
90 
91 };
92 
93 /// Dissolve to white palette effect
94 class WhiteOutPaletteEffect : public PaletteEffect {
95 
96 	private:
97 		int   duration;  ///< Number of milliseconds the effect lasts
98 		fixed whiteness;
99 
100 	public:
101 		WhiteOutPaletteEffect (int newDuration, PaletteEffect* nextPE);
102 
103 		void apply  (SDL_Color* shownPalette, bool direct, int mspf);
104 
105 };
106 
107 /// Fade out palette effect
108 class FadeOutPaletteEffect : public PaletteEffect {
109 
110 	private:
111 		int   duration;  ///< Number of milliseconds the effect lasts
112 		fixed blackness;
113 
114 	public:
115 		FadeOutPaletteEffect (int newDuration, PaletteEffect* nextPE);
116 
117 		void apply (SDL_Color* shownPalette, bool direct, int mspf);
118 
119 };
120 
121 /// Flash colour (dissolve to it and back again) palette effect
122 class FlashPaletteEffect : public PaletteEffect {
123 
124 	private:
125 		int           duration;  ///< Number of milliseconds the effect lasts
126 		fixed         progress;
127 		unsigned char red, green, blue; ///< Flash colour
128 
129 	public:
130 		FlashPaletteEffect (unsigned char newRed, unsigned char newGreen, unsigned char newBlue, int newDuration, PaletteEffect* nextPE);
131 
132 		void apply (SDL_Color* shownPalette, bool direct, int mspf);
133 
134 };
135 
136 /// Entry rotation palette effect
137 class RotatePaletteEffect : public PaletteEffect {
138 
139 	private:
140 		unsigned char first;    ///< The first palette index affected
141 		int           amount;   ///< The number of (consecutive) palette indices affected
142 		fixed         speed;    ///< Rotations per second
143 		fixed         position;
144 
145 	public:
146 		RotatePaletteEffect (unsigned char newFirst, int newAmount, fixed newSpeed, PaletteEffect* nextPE);
147 
148 		void apply (SDL_Color* shownPalette, bool direct, int mspf);
149 
150 };
151 
152 /// Sky palette palette effect
153 class SkyPaletteEffect : public PaletteEffect {
154 
155 	private:
156 		SDL_Color*    skyPalette;
157 		unsigned char first;      ///< The first palette index affected
158 		int           amount;     ///< The number of (consecutive) palette indices affected
159 		fixed         speed;      ///< Relative Y speed - as in Jazz 2
160 
161 	public:
162 		SkyPaletteEffect (unsigned char newFirst, int newAmount, fixed newSpeed, SDL_Color* newSkyPalette, PaletteEffect* nextPE);
163 
164 		void apply (SDL_Color* shownPalette, bool direct, int mspf);
165 
166 };
167 
168 /// 2D parallaxing background palette effect
169 class P2DPaletteEffect : public PaletteEffect {
170 
171 	private:
172 		unsigned char first;  ///< The first palette index affected
173 		int           amount; ///< The number of (consecutive) palette indices affected
174 		fixed         speed;  ///< Relative X & Y speed - as in Jazz 2
175 
176 	public:
177 		P2DPaletteEffect (unsigned char newFirst, int newAmount, fixed newSpeed, PaletteEffect* nextPE);
178 
179 		void apply (SDL_Color* shownPalette, bool direct, int mspf);
180 
181 };
182 
183 /// 1D parallaxing background palette effect
184 class P1DPaletteEffect : public PaletteEffect {
185 
186 	private:
187 		unsigned char first;    ///< The first palette index affected
188 		int           amount;   ///< The number of (consecutive) palette indices affected
189 		fixed         speed;    ///< Relative X & Y speed - as in Jazz 2
190 
191 	public:
192 		P1DPaletteEffect (unsigned char newFirst, int newAmount, fixed newSpeed, PaletteEffect* nextPE);
193 
194 		void apply (SDL_Color* shownPalette, bool direct, int mspf);
195 
196 };
197 
198 /// Underwater darkening palette effect
199 class WaterPaletteEffect : public PaletteEffect {
200 
201 	private:
202 		fixed depth; ///< Number of pixels between water surface and total darkness
203 
204 	public:
205 		WaterPaletteEffect (fixed newDepth, PaletteEffect* nextPE);
206 
207 		void apply (SDL_Color* shownPalette, bool direct, int mspf);
208 
209 };
210 
211 
212 #endif
213 
214 
215