1 /* -*- Mode: C++; c-basic-offset: 2; tab-width: 2; indent-tabs-mode: nil -*-
2  *
3  * Quadra, an action puzzle game
4  * Copyright (C) 1998-2000  Ludus Design
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 
21 #ifndef _HEADER_PALETTE
22 #define _HEADER_PALETTE
23 
24 #include "config.h"
25 
26 #include <stdio.h>
27 #include "types.h"
28 #include "error.h"
29 #include "image.h"
30 
31 class Palette {
32 private:
33   friend class Fade;
34   friend class Remap;
35   friend class Video;
36   SDL_Color pal[256];
37   int size;
38 public:
Palette()39   Palette() {
40     memset(pal, 0, sizeof(pal));
41     size=256;
42   }
Palette(const Image & raw)43   Palette(const Image& raw) {
44     memset(pal, 0, sizeof(pal));
45     load(raw);
46   }
set_size(int s)47   void set_size(int s) {
48     size=s;
49   }
50   void load(const Image& raw);
r(Byte c)51   Byte r(Byte c) {
52     return pal[c].r;
53   }
g(Byte c)54   Byte g(Byte c) {
55     return pal[c].g;
56   }
b(Byte c)57   Byte b(Byte c) {
58     return pal[c].b;
59   }
setcolor(Byte c,Byte r,Byte g,Byte b)60   void setcolor(Byte c, Byte r, Byte g, Byte b) {
61     pal[c].r=r;
62     pal[c].g=g;
63     pal[c].b=b;
64   }
65 };
66 
67 extern Palette noir;
68 
69 class Remap {
70   const Palette& dst;
71 public:
72   Byte map[256];
73   Remap(const Palette& d, Palette* src=NULL);
74   void findrgb(const Byte m, const Byte r, const Byte g, const Byte b);
75 };
76 
77 class Fade {
78   Palette dest;
79   short delta[768];
80   short current[768];
81   int currentframe;
82   int destframe;
83 public:
84   Fade(const Palette& dst=Palette(), const Palette& src=Palette(), int frame=70);
85   void newdest(const Palette& dst, int frame=70);
86   void setdest(const Palette& dst);
done()87   bool done() const {
88     return currentframe==destframe;
89   }
90   int step();
91   void set();
92 };
93 
94 #endif
95