1 /*
2  * GNUjump
3  * =======
4  *
5  * Copyright (C) 2005-2008, Juan Pedro Bolivar Puente
6  *
7  * GNUjump is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * GNUjump is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef SURFACE_H
22 #define SURFACE_H
23 
24 #include "SDL_2dgl.h"
25 
26 #define LARGE_GL -1
27 #define TRUE 1
28 #define FALSE 0
29 
30 /* MY SURFACE TYPE */
31 typedef struct surface
32 {
33   SDL_Surface *surf;
34   GL2D_SurfaceGL *surfGL;
35   GL2D_LargeSurfaceGL *LsurfGL;
36   Uint8 alpha;
37   Uint16 w, h;
38   Sint8 gl;
39 }
40 JPB_surface;
41 
42 /* MY ROTABLE SURFACE TYPE */
43 /* NOTE: If using OpenGL, you can't use it for surfaces larger than the maximun
44  * texture size of you graphics card. */
45 typedef struct rot_surface
46 {
47   SDL_Surface *surf;
48   SDL_Surface *rSurf;		//this is a rotated copy of the picture.
49   GL2D_SurfaceGL *surfGL;
50   Uint8 alpha;
51   Uint16 w, h;
52   Uint8 gl;			//is this an openGL surface?
53   float angle;
54 }
55 JPB_surfaceRot;
56 
57 void JPB_drawSquare (Uint32 color, Uint8 alpha, int x, int y, int w, int h);
58 
59 void drawLine (SDL_Surface * dest, Uint8 dr, Uint8 dg, Uint8 db, Uint8 alpha,
60 	       int x0, int y0, int x1, int y1);
61 
62 void JPB_drawLine (Uint8 r, Uint8 g, Uint8 b, Uint8 a, int x0, int y0, int x1,
63 		   int y1);
64 
65 
66 /********************
67  *	ROTABLE SURFACE *
68  ********************/
69 
70 /*
71  * JPB_LoadImgRot ()
72  * Loads a rotable surface
73  */
74 JPB_surfaceRot *JPB_LoadImgRot (char *file,
75 				Uint8 gl, Uint8 alpha, Uint8 trans,
76 				Uint8 rev);
77 
78 /*
79  * JPB_FreeSurfaceRot()
80  * Frees a rotable surface.
81  */
82 void JPB_FreeSurfaceRot (JPB_surfaceRot * surface);
83 
84 /*
85  * JPB_PrintSurfaceRot()
86  * Prints a rotable surface on the screen. The x and y values of the destiny rectangle
87  * define the where the centre of the pic will be. The picture is blitted rotated around its
88  * centre "angle" degrees.
89  */
90 void JPB_PrintSurfaceRot (JPB_surfaceRot * src, SDL_Rect * src_r,
91 			  SDL_Rect * dest_r, float angle);
92 
93 /*
94  * JPB_CreateSurfaceRot()
95  * Creates a rotable surface from an SDL_Surface.
96  */
97 JPB_surfaceRot *JPB_CreateSurfaceRot (SDL_Surface * src, Uint8 gl);
98 
99 /*******************
100  * SURFACE         *
101  *******************/
102 JPB_surface *JPB_CreateSurface (SDL_Surface * src, Uint8 gl);
103 
104 void JPB_FreeSurface (JPB_surface * surface);
105 
106 JPB_surface *JPB_LoadImg (char *file,
107 			  Uint8 gl, Uint8 alpha, Uint8 trans, Uint8 rev);
108 
109 void JPB_PrintSurface (JPB_surface * src, SDL_Rect * src_r,
110 		       SDL_Rect * dest_r);
111 
112 /*
113 ** BlitSurface()
114 ** Blits a surface with alpha blending options...
115 */
116 int BlitSurface (SDL_Surface * src, SDL_Rect * src_r,
117 		 SDL_Surface * dest, SDL_Rect * dest_r, Uint8 alpha);
118 
119 /*
120  * This blits a SDL_Surface with an angle of rotation...
121  */
122 int BlitRot (SDL_Surface * src, SDL_Surface * dest, SDL_Rect * dest_r,
123 	     Sint16 angle, Uint8 alpha);
124 
125 
126 //tools.........................................................................
127 
128 void drawSquareAlpha (SDL_Surface * dest, Uint32 color, Uint8 alpha,
129 		      int x, int y, int w, int h);
130 
131 /*
132 ** flipscreen()
133 ** Swaps buffers.
134 */
135 void FlipScreen ();
136 
137 /*
138 ** getpixel()
139 ** Function from the SDL tutorial. Gets a pixel form a given surface.
140 */
141 Uint32 getpixel (SDL_Surface * surface, int x, int y);
142 
143 /*
144 ** putpixel()
145 ** Function from the SDL tutorial. Draws a pixel in a given surface.
146 */
147 void putpixel (SDL_Surface * surface, int x, int y, Uint32 pixel);
148 
149 /*
150 ** Slock()
151 ** Locks a surface.
152 */
153 void Slock (SDL_Surface * door);
154 
155 /*
156 ** Sulock()
157 ** Unlocks a surface.
158 */
159 void Sulock (SDL_Surface * door);
160 
161 /*
162 ** LoadIMG()
163 ** Loads a picture form a BMP image and converts it to the screen bps.
164 */
165 SDL_Surface *LoadImg (char *file, Uint8 Use_Alpha, Uint8 trans);
166 
167 /*
168 ** SetTrans()
169 ** Sets a color picked from a pixel in a surface as transparent in that surface.
170 */
171 void SetTrans (SDL_Surface * src, int x, int y);
172 
173 /*
174 ** ReversePic()
175 ** Horizontal mirror effect.
176 */
177 SDL_Surface *ReversePic (SDL_Surface * source);
178 
179 #endif
180