1 /* 2 * Copyright (C) 2000-2013 The Exult Team 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 */ 18 19 #ifndef PALETTE_H 20 #define PALETTE_H 21 22 class Image_window8; 23 struct File_spec; 24 class U7multiobject; 25 26 #include <memory> 27 28 /* 29 * Palette #'s in 'palettes.flx': 30 */ 31 const int PALETTE_DAY = 0; 32 const int PALETTE_DUSK = 1; 33 const int PALETTE_DAWN = 1; // Think this is it. 34 const int PALETTE_NIGHT = 2; 35 const int PALETTE_INVISIBLE = 3; // When Avatar is invisible. 36 const int PALETTE_OVERCAST = 4; // When raining or overcast during daytime 37 const int PALETTE_FOG = 5; 38 const int PALETTE_SPELL = 6; // light spell. 39 const int PALETTE_CANDLE = 7; // is somewhat warmer, candles. 40 const int PALETTE_RED = 8; // Used when hit in combat. 41 // 9 has lots of black. 42 const int PALETTE_LIGHTNING = 10; 43 const int PALETTE_SINGLE_LIGHT = 11; 44 const int PALETTE_MANY_LIGHTS = 12; 45 46 class Palette { 47 Image_window8 *win; 48 unsigned char pal1[768]; 49 unsigned char pal2[768]; 50 int palette; // Palette #. 51 int brightness; 52 int max_val; 53 bool border255; 54 bool faded_out; // true if faded palette to black. 55 bool fades_enabled; 56 void set_loaded(const U7multiobject &pal, const char *xfname, int xindex); 57 void loadxform(const unsigned char *buf, const char *xfname, int &xindex); 58 59 static unsigned char border[3]; 60 public: 61 Palette(); 62 Palette(Palette *pal); // "Copy" constructor. 63 void take(Palette *pal); // Copies a palette into another. 64 // Fade palette in/out. 65 void fade(int cycles, int inout, int pal_num = -1); is_faded_out()66 bool is_faded_out() const { 67 return faded_out; 68 } 69 void flash_red(); // Flash red for a moment. 70 // Set desired palette. 71 void set(int pal_num, int new_brightness = -1, 72 bool repaint = true); 73 void set(unsigned char palnew[768], int new_brightness = -1, 74 bool repaint = true, bool border255 = false); get_brightness()75 int get_brightness() const { // Percentage: 100 = normal. 76 return brightness; 77 } 78 // the user. set_fades_enabled(bool f)79 void set_fades_enabled(bool f) { 80 fades_enabled = f; 81 } get_fades_enabled()82 bool get_fades_enabled() const { 83 return fades_enabled; 84 } 85 86 void apply(bool repaint = true); 87 void load(const File_spec &fname0, int index, 88 const char *xfname = nullptr, int xindex = -1); 89 void load(const File_spec &fname0, const File_spec &fname1, 90 int index, const char *xfname = nullptr, int xindex = -1); 91 void load(const File_spec &fname0, const File_spec &fname1, 92 const File_spec &fname2, int index, 93 const char *xfname = nullptr, int xindex = -1); 94 void set_brightness(int bright); set_max_val(int max)95 void set_max_val(int max) { 96 max_val = max; 97 } get_max_val()98 int get_max_val() const { 99 return max_val; 100 } 101 void fade_in(int cycles); 102 void fade_out(int cycles); 103 int find_color(int r, int g, int b, int last = 0xe0) const; 104 void create_palette_map(const Palette *to, unsigned char *&buf) const; 105 std::unique_ptr<Palette> create_intermediate(const Palette &to, int nsteps, int pos) const; 106 void create_trans_table(unsigned char br, unsigned bg, 107 unsigned bb, int alpha, unsigned char *table) const; 108 void show(); 109 110 void set_color(int nr, int r, int g, int b); get_red(int nr)111 unsigned char get_red(int nr) const { 112 return pal1[3 * nr]; 113 } get_green(int nr)114 unsigned char get_green(int nr) const { 115 return pal1[3 * nr + 1]; 116 } get_blue(int nr)117 unsigned char get_blue(int nr) const { 118 return pal1[3 * nr + 2]; 119 } 120 void set_palette(unsigned char palnew[768]); set_border(int r,int g,int b)121 static void set_border(int r, int g, int b) { 122 border[0] = r; 123 border[1] = g; 124 border[2] = b; 125 } 126 get_border_index()127 unsigned char get_border_index() const { 128 129 return border255 ? 255 : 0; 130 } 131 }; 132 133 /* 134 * Smooth palette transition. 135 */ 136 137 class Palette_transition { 138 Palette start, end; 139 std::unique_ptr<Palette> current; 140 int step, max_steps; 141 int start_hour, start_minute, start_ticks; 142 int rate; 143 public: 144 Palette_transition(int from, int to, int ch, int cm, int ct, int, 145 int nsteps, int sh, int smin, int stick); 146 Palette_transition(Palette *from, Palette *to, int ch, int cm, int ct, 147 int r, int nsteps, int sh, int smin, int stick); 148 Palette_transition(Palette *from, int to, int ch, int cm, int ct, 149 int r, int nsteps, int sh, int smin, int stick); get_step()150 int get_step() const { 151 return step; 152 } 153 bool set_step(int hour, int min, int tick); get_current_palette()154 Palette *get_current_palette() const { 155 return current.get(); 156 } 157 }; 158 159 #endif 160