2
* Copyright (C) 2001 by Holger Rapp
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
20
#ifndef __S__GRAPHIC_H
21
#define __S__GRAPHIC_H
23
#define DEF_CLRKEY Graph::pack_rgb(0,0,255)
28
#include "singleton.h"
32
/** inline unsigned short Graph::pack_rgb(const unsigned char r, const unsigned char g, const unsigned char b);
34
* This functions packs a RGB tribble into a short
38
* b blue value (SUPRISE!)
39
* Returns: packed value
41
inline unsigned short Graph::pack_rgb(const unsigned char r, const unsigned char g, const unsigned char b) {
42
return ((b>>3) + ((g>>2)<<5)+ ((r>>3)<<11) );
45
/** inline void Graph::unpack_rgb(const unsigned short clr, unsigned char* r, unsigned char* g, unsigned char* b) ;
47
* this unpacks a clr and returns the RGB tribble
49
* Args: clr clr to unpack
50
* r ptr to var to hold red value
51
* g ptr to var to hold green value
52
* b ptr to var to hold blue value
55
inline void Graph::unpack_rgb(const unsigned short clr, unsigned char* r, unsigned char* g, unsigned char* b) {
64
* This class represents a picture
68
Pic(void) { pixels=NULL; w=h=lpix=clrkey=sh_clrkey=bhas_clrkey=0; }
69
~Pic(void) { if(pixels) free(pixels); }
71
void set_size(const unsigned short, const unsigned short);
72
void set_clrkey(const unsigned short);
73
void set_clrkey(const unsigned char, const unsigned char, const unsigned char);
74
int load(const char*);
76
Pic& operator=(const Pic&);
79
/** inline int Pic::get_w(void) const
81
* This function returns the width
85
inline int get_w(void) const { return w; }
87
/** inline int Pic::get_h(void) const
89
* This function returns the height
93
inline int get_h(void) const { return h; }
95
/** inline unsigned short get_clrkey(void) const
97
* this returns the current colorkey
102
inline unsigned short get_clrkey(void) const {
103
if(bhas_clrkey) return sh_clrkey;
107
/** inline bool has_clrkey(void) const
109
* this indicates if the pixel has a valid clrkey
112
* Returns: if the pixel has a clrkey or not
114
inline bool has_clrkey(void) { return bhas_clrkey; }
116
// optimized pixel get functions
117
// They are rather simple,
118
// THEY DON'T CHECK FOR OVERFLOWS!!
119
inline unsigned short get_pixel(const unsigned int x, const unsigned int y) {
123
inline unsigned short get_npixel(void) {
124
return pixels[++lpix];
126
inline unsigned short get_ppixel(void) {
127
return pixels[--lpix];
129
inline unsigned short get_fpixel(void) {
134
// rewinding or forwarding without change
135
inline void npixel(void) { ++lpix; }
136
inline void ppixel(void) { --lpix; }
137
inline void fpixel(void) { lpix=0; }
138
inline void set_cpixel(const unsigned int x, const unsigned int y) { lpix=y*w + x; }
140
// optimized pixel set functions declared inline
141
// All those functions take either a rgb tribble or 3 chars
142
// And they are rather simple,
143
// THEY DON'T CHECK FOR OVERFLOWS!!
144
inline void set_pixel(const unsigned int x, const unsigned int y, const unsigned char r, const unsigned char g, const unsigned char b) {
146
pixels[lpix] = pack_rgb(r, g, b);
148
inline void set_pixel(const unsigned int x, const unsigned int y, const unsigned short clr) {
152
inline void set_npixel(const unsigned short clr) {
153
pixels[++lpix] = clr;
155
inline void set_npixel(const unsigned char r, const unsigned char g, const unsigned char b) {
156
pixels[++lpix]= pack_rgb(r, g, b);
158
inline void set_ppixel(const unsigned short clr) {
161
inline void set_ppixel(const unsigned char r, const unsigned char g, const unsigned char b) {
162
pixels[--lpix]= pack_rgb(r, g, b);
164
inline void set_fpixel(const unsigned short clr) {
168
inline void set_fpixel(const unsigned char r, const unsigned char g, const unsigned char b) {
170
pixels[0] = pack_rgb(r, g, b);
173
// this function really needs faaast blitting
174
friend void copy_pic(Pic*, Pic*, const unsigned short, const unsigned short, const unsigned short, const unsigned short,
175
const unsigned short, const unsigned short);
176
friend void draw_pic(Pic*, const unsigned short, const unsigned short, const unsigned short, const unsigned short,
177
const unsigned short, const unsigned short);
181
unsigned long clrkey;
182
unsigned short sh_clrkey;
183
unsigned short* pixels;
190
* This class is responsible for all graphics stuff. It's
191
* modified/optimized to work only for 16bit colordepth and nothing else
195
class Graphic : public Singleton<Graphic> {
196
// forbidden functions
197
Graphic(const Graphic&);
198
Graphic& operator=(const Graphic&);
215
void set_mode(const unsigned short, const unsigned short, const Mode);
216
void update_screen(void);
217
void update_rect(const unsigned short, const unsigned short, const unsigned short, const unsigned short);
218
void update_quarter(void);
220
/** Graphic::State Graphic::get_state(void)
222
* returns the current state of the graphics class
227
State get_state(void) const { return st; }
229
/** inline bool Graphic::is_fs(void)
231
* graphic mode is fullscreen?
234
* Returns: true if fs, false if window
236
inline bool is_fs(void) { return bis_fs; st=OK; }
238
/** inline int Graphic::get_xres(void) const
240
* This function returns the X Resoultion of the current screen
244
inline int get_xres(void) const { return xres; }
246
/** inline void Graphic::get_yres(void) const
248
* This function returns the Y Resoultion of the current screen
252
inline int get_yres(void) const { return yres; }
255
// optimized pixel get functions
256
// They are rather simple,
257
// THEY DON'T CHECK FOR OVERFLOWS!!
258
inline unsigned short get_pixel(const unsigned int x, const unsigned int y) {
259
lpix=(y)*(xres>>1) + (x);
260
return *((Uint16*) sc->pixels + lpix);
262
inline unsigned short get_npixel(void) {
263
return *((Uint16*) sc->pixels + ++lpix);
265
inline unsigned short get_ppixel(void) {
266
return *((Uint16*) sc->pixels + --lpix);
268
inline unsigned short get_fpixel(void) {
270
return *((Uint16*) sc->pixels);
273
// rewinding or forwarding without change
274
inline void npixel(void) { ++lpix; }
275
inline void ppixel(void) { --lpix; }
276
inline void fpixel(void) { lpix=0; }
277
inline void set_cpixel(const unsigned int x, const unsigned int y) { lpix=y*xres + x; }
279
// optimized pixel set functions declared inline
280
// All those functions take either a rgb tribble or 3 chars
281
// And they are rather simple,
282
// THEY DON'T CHECK FOR OVERFLOWS!!
283
inline void set_pixel(const unsigned int x, const unsigned int y, const unsigned char r, const unsigned char g, const unsigned char b) {
284
lpix=(y)*(xres) + (x);
285
pixels[lpix] = pack_rgb(r, g, b);
287
inline void set_pixel(const unsigned int x, const unsigned int y, const unsigned short clr) {
288
lpix=(y)*(xres) + (x);
291
inline void set_npixel(const unsigned short clr) {
292
pixels[++lpix] = clr;
294
inline void set_npixel(const unsigned char r, const unsigned char g, const unsigned char b) {
295
pixels[++lpix]= pack_rgb(r, g, b);
297
inline void set_ppixel(const unsigned short clr) {
300
inline void set_ppixel(const unsigned char r, const unsigned char g, const unsigned char b) {
301
pixels[--lpix]= pack_rgb(r, g, b);
303
inline void set_fpixel(const unsigned short clr) {
307
inline void set_fpixel(const unsigned char r, const unsigned char g, const unsigned char b) {
309
pixels[0] = pack_rgb(r, g, b);
313
// this function really needs faaast blitting
314
friend void draw_pic(Pic*, const unsigned short, const unsigned short, const unsigned short, const unsigned short,
315
const unsigned short, const unsigned short);
318
unsigned short* pixels;
319
unsigned short xres, yres;
326
void draw_pic(Pic*, const unsigned short, const unsigned short, const unsigned short, const unsigned short,
327
const unsigned short, const unsigned short);
328
void copy_pic(Pic*, Pic*, const unsigned short, const unsigned short, const unsigned short, const unsigned short,
329
const unsigned short, const unsigned short);
332
using Graph::Graphic;
334
#define g_gr Graph::Graphic::get_singleton()
336
#endif /* __S__GRAPHIC_H */