4
(c) Richard Thrippleton
5
Licensing terms are in the 'LICENSE' file
6
If that file is not included with this source then permission is not given to use this source in any way whatsoever.
11
#include "SDL_rotozoom.h"
12
#include "SDL_gfxPrimitives.h"
15
#include "interface.h"
21
for(int i=0;i<ISIZE;i++)
26
void graphic::setup(bool big,bool full)
28
Uint32 flags; //Flags for setting video;
29
SDL_Surface* tmp; //Temporary holding place while sprites are converted
30
char* path; //Path to load bmp from
32
if(SDL_InitSubSystem(SDL_INIT_VIDEO)==-1)
33
throw error(SDL_GetError());
34
flags=SDL_DOUBLEBUF|SDL_HWSURFACE;
36
flags=flags|SDL_FULLSCREEN;
38
screen=SDL_SetVideoMode(800,600,0,flags);
40
screen=SDL_SetVideoMode(600,400,0,flags);
42
throw error(SDL_GetError());
47
SDL_WM_SetCaption("Star Voyager","Star Voyager");
50
cols[BLACK]=SDL_MapRGB(screen->format,0,0,0);
51
cols[RED]=SDL_MapRGB(screen->format,255,0,0);
52
cols[LIGHTRED]=SDL_MapRGB(screen->format,255,100,100);
53
cols[GREEN]=SDL_MapRGB(screen->format,0,255,0);
54
cols[LIGHTGREEN]=SDL_MapRGB(screen->format,100,255,100);
55
cols[BLUE]=SDL_MapRGB(screen->format,0,0,255);
56
cols[LIGHTBLUE]=SDL_MapRGB(screen->format,100,100,255);
57
cols[YELLOW]=SDL_MapRGB(screen->format,255,255,0);
58
cols[ORANGE]=SDL_MapRGB(screen->format,255,100,100);
59
cols[PURPLE]=SDL_MapRGB(screen->format,255,0,255);
60
cols[GREY]=SDL_MapRGB(screen->format,180,180,180);
61
cols[DARKGREY]=SDL_MapRGB(screen->format,64,64,64);
62
cols[WHITE]=SDL_MapRGB(screen->format,255,255,255);
64
path=new char[strlen(DATADIR)+32];
65
sprintf(path,"%s/gfx/font.bmp",DATADIR);
66
font=SDL_LoadBMP(path);
69
throw error(SDL_GetError());
70
tmp=SDL_ConvertSurface(font,screen->format,SDL_SWSURFACE);
71
SDL_FreeSurface(font);
73
SDL_SetColorKey(font,SDL_SRCCOLORKEY|SDL_RLEACCEL,cols[BLACK]);
75
path=new char[strlen(DATADIR)+32];
76
sprintf(path,"%s/gfx/haze.bmp",DATADIR);
77
cloak=SDL_LoadBMP(path);
80
throw error(SDL_GetError());
81
tmp=SDL_ConvertSurface(cloak,screen->format,SDL_SWSURFACE);
82
SDL_FreeSurface(cloak);
84
SDL_SetColorKey(cloak,SDL_SRCCOLORKEY|SDL_RLEACCEL,cols[WHITE]);
92
graphic* graphic::get(int indx)
94
if(!(indx>=0 && indx<ISIZE))
98
graphics[indx]=new graphic(indx);
100
return graphics[indx];
103
void graphic::string(char* str,int x,short y,bool opq)
105
SDL_Rect srct,drct; //Source rect and destination rect
106
int i; //Position in text
107
char c; //Character in use
108
char l; //Letter to print
115
drct.w=6*strlen(str);
117
SDL_FillRect(screen,&drct,cols[BLACK]);
137
SDL_BlitSurface(font,&srct,screen,&drct);
156
void graphic::box(sbox* box,int col)
158
SDL_Rect rect; //Rectangle to draw
164
SDL_FillRect(screen,&rect,cols[col]);
173
void graphic::clip(sbox* box)
175
SDL_Rect rect; //Rectangle to clip with
182
SDL_SetClipRect(screen,&rect);
191
void graphic::pix(int x,short y,short col)
193
fastPixelColor(screen,x,y,cols[col]);
203
sbox graphic::dimension()
205
sbox out; //Value to output
214
void graphic::line(int x1,short y1,short x2,short y2,short col)
218
lineColor(screen,x1,y1,x2,y2,cols[col]);
231
void graphic::draw(int x,short y,short rot,short zout,short haze,bool trg)
233
graphic* tspr; //Targetting sprite
234
SDL_Rect dst; //Destination rect
235
int hw,hh; //Half-width and half-height, for centering
239
string("Graphic missing",x,y,true);
243
if(!(rot>=0 && rot<36 && zout>=0 && zout<4))
245
if(!rots[rot][zout-1])
247
hw=(rots[rot][zout-1]->w)/2;
248
hh=(rots[rot][zout-1]->h)/2;
253
SDL_BlitSurface(rots[rot][zout-1],NULL,screen,&dst);
259
tspr->draw(x,y-hh,0,1,0,false);
260
tspr->draw(x,y+hh,18,1,0,false);
261
tspr->draw(x-hw,y,27,1,0,false);
262
tspr->draw(x+hw,y,9,1,0,false);
271
if(haze>0 && hw*2>cloak->w && hh*2>cloak->h)
275
for(int i=0;i<haze;i++)
277
dst.x=x-hw+calc::rnd(hw*2-cloak->w);
278
dst.y=y-hh+calc::rnd(hh*2-cloak->h);
279
SDL_BlitSurface(cloak,NULL,screen,&dst);
286
void graphic::embed()
291
void graphic::clean()
293
int j; //Loop limiter
296
SDL_SetClipRect(screen,NULL);
297
for(int i=0;i<nd;i++)
302
SDL_SetClipRect(screen,&dpos[i]);
306
fastPixelColor(screen,dpos[i].x,dpos[i].y,cols[BLACK]);
310
lineColor(screen,dpos[i].x,dpos[i].y,dpos[i].w,dpos[i].h,cols[BLACK]);
314
SDL_FillRect(screen,&dpos[i],cols[BLACK]);
321
graphic::graphic(int indx)
325
for(int i=0;i<36;i++)
340
SDL_Surface* tmp; //Temporary holding place while sprites are converted
341
char* path; //Path to load sprite from
343
path=new char[strlen(DATADIR)+32];
344
sprintf(path,"%s/gfx/%i.bmp",DATADIR,self);
345
orig=SDL_LoadBMP(path);
348
throw error(SDL_GetError());
349
tmp=SDL_ConvertSurface(orig,screen->format,SDL_SWSURFACE);
350
SDL_FreeSurface(orig);
352
SDL_SetColorKey(orig,SDL_SRCCOLORKEY|SDL_RLEACCEL,cols[BLACK]);
356
void graphic::calculate(int rot,short zout)
358
int ang; //Angle to rotate by
362
rots[rot][zout-1]=rotozoomSurface(orig,ang,1.0/zout,1);
364
rots[rot][zout-1]=rotozoomSurface(orig,ang,1.0/zout,0);
365
SDL_SetColorKey(rots[rot][zout-1],SDL_SRCCOLORKEY|SDL_RLEACCEL,cols[BLACK]);
366
if(!rots[rot][zout-1])
367
throw error(SDL_GetError());
370
graphic* graphic::graphics[ISIZE];
371
SDL_Surface* graphic::screen;
372
SDL_Surface* graphic::font;
373
SDL_Surface* graphic::cloak;
374
unsigned long graphic::cols[16];
376
int graphic::dtyp[1024];
377
SDL_Rect graphic::dpos[1024];
378
SDL_Rect graphic::crct;