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