29 SDL_Rect surface::srcrect;
30 SDL_Rect surface::dstrect;
34 if (l == length () && h == height ())
return;
36 if (vis) SDL_FreeSurface (vis);
41 vis = SDL_CreateRGBSurface (SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_ASYNCBLIT,
51 void surface::double_size(
const surface & src)
58 dbl_mode = src.is_dbl_mode ();
60 for (
u_int16 j = 0; j < height(); j++)
61 for (
u_int16 i = 0; i < length(); i++)
63 src.get_pix_aux(i, j, col);
71 void surface::half_size(
const surface & src)
78 dbl_mode = src.is_dbl_mode ();
84 put_pix_aux(i, j, col);
93 u_int8 * offset = ((Uint8 *) vis->pixels) + y * vis->pitch
94 + x * vis->format->BytesPerPixel;
96 switch (vis->format->BytesPerPixel)
99 col = *((Uint8 *)(offset));
102 col = *((Uint16 *)(offset));
110 r = *((offset) + (vis->format->Rshift >> 3));
111 g = *((offset) + (vis->format->Gshift >> 3));
112 b = *((offset) + (vis->format->Bshift >> 3));
114 t = r << vis->format->Rshift;
116 t = g << vis->format->Gshift;
118 t = b << vis->format->Bshift;
124 col = *((Uint32 *)(offset));
131 u_int8 * offset = ((Uint8 *) vis->pixels) + y * vis->pitch
132 + x*vis->format->BytesPerPixel;
134 switch (vis->format->BytesPerPixel)
137 *((Uint16 *) (offset)) = (Uint16) col;
140 *((Uint16 *) (offset+vis->format->BytesPerPixel)) = (Uint16) col;
141 *((Uint16 *) (offset+vis->pitch)) = (Uint16) col;
142 *((Uint16 *) (offset+vis->pitch+vis->format->BytesPerPixel)) = (Uint16) col;
149 r = (col >> vis->format->Rshift);
150 g = (col >> vis->format->Gshift);
151 b = (col >> vis->format->Bshift);
152 *((offset) + (vis->format->Rshift >> 3)) = r;
153 *((offset) + (vis->format->Gshift >> 3)) = g;
154 *((offset) + (vis->format->Bshift >> 3)) = b;
157 *((offset+vis->format->BytesPerPixel) + (vis->format->Rshift >> 3)) = r;
158 *((offset+vis->format->BytesPerPixel) + (vis->format->Gshift >> 3)) = g;
159 *((offset+vis->format->BytesPerPixel) + (vis->format->Bshift >> 3)) = b;
160 *((offset+vis->pitch) + (vis->format->Rshift >> 3)) = r;
161 *((offset+vis->pitch) + (vis->format->Gshift >> 3)) = g;
162 *((offset+vis->pitch) + (vis->format->Bshift >> 3)) = b;
163 *((offset+vis->pitch+vis->format->BytesPerPixel) + (vis->format->Rshift >> 3)) = r;
164 *((offset+vis->pitch+vis->format->BytesPerPixel) + (vis->format->Gshift >> 3)) = g;
165 *((offset+vis->pitch+vis->format->BytesPerPixel) + (vis->format->Bshift >> 3)) = b;
170 *((Uint32 *)(offset)) = (Uint32) col;
173 *((Uint32 *) (offset+vis->format->BytesPerPixel)) = (Uint32) col;
174 *((Uint32 *) (offset+vis->pitch)) = (Uint32) col;
175 *((Uint32 *) (offset+vis->pitch+vis->format->BytesPerPixel)) = (Uint32) col;
190 dbl_mode = mode ? screen::dbl_mode () :
false;
195 if (
vis && not_screen) SDL_FreeSurface (
vis);
210 if ((t == 255) && (alpha_ != 255) &&
vis)
211 SDL_SetAlpha (
vis, 0, 0);
221 setup_rects (x, y, sx, sy, sl, sh, da_opt);
223 if (screen::dbl_mode())
241 if (!dstrect.w || !dstrect.h)
250 SDL_SetColorKey (
vis, 0, 0);
254 SDL_SetAlpha (
vis, SDL_SRCALPHA, alpha_);
256 SDL_BlitSurface (
vis, &srcrect, target->
vis, &dstrect);
275 if (screen::dbl_mode ())
283 SDL_FillRect (
vis, &dstrect, col);
290 if (SDL_MUSTLOCK(
vis))
291 SDL_LockSurface (
vis);
297 if (SDL_MUSTLOCK(
vis))
298 SDL_UnlockSurface (
vis);
309 u_int8 * offset = ((Uint8 *)
vis->pixels) + y *
vis->pitch
310 + x*
vis->format->BytesPerPixel;
312 switch (
vis->format->BytesPerPixel)
315 *((Uint16 *) (offset)) = (Uint16) col;
318 *((Uint16 *) (offset+
vis->format->BytesPerPixel)) = (Uint16) col;
319 *((Uint16 *) (offset+
vis->pitch)) = (Uint16) col;
320 *((Uint16 *) (offset+
vis->pitch+
vis->format->BytesPerPixel)) = (Uint16) col;
327 r = (col >>
vis->format->Rshift);
328 g = (col >>
vis->format->Gshift);
329 b = (col >>
vis->format->Bshift);
330 *((offset) + (
vis->format->Rshift >> 3)) = r;
331 *((offset) + (
vis->format->Gshift >> 3)) = g;
332 *((offset) + (
vis->format->Bshift >> 3)) = b;
335 *((offset+
vis->format->BytesPerPixel) + (
vis->format->Rshift >> 3)) = r;
336 *((offset+
vis->format->BytesPerPixel) + (
vis->format->Gshift >> 3)) = g;
337 *((offset+
vis->format->BytesPerPixel) + (
vis->format->Bshift >> 3)) = b;
338 *((offset+
vis->pitch) + (
vis->format->Rshift >> 3)) = r;
339 *((offset+
vis->pitch) + (
vis->format->Gshift >> 3)) = g;
340 *((offset+
vis->pitch) + (
vis->format->Bshift >> 3)) = b;
341 *((offset+
vis->pitch+
vis->format->BytesPerPixel) + (
vis->format->Rshift >> 3)) = r;
342 *((offset+
vis->pitch+
vis->format->BytesPerPixel) + (
vis->format->Gshift >> 3)) = g;
343 *((offset+
vis->pitch+
vis->format->BytesPerPixel) + (
vis->format->Bshift >> 3)) = b;
348 *((Uint32 *)(offset)) = (Uint32) col;
351 *((Uint32 *) (offset+
vis->format->BytesPerPixel)) = (Uint32) col;
352 *((Uint32 *) (offset+
vis->pitch)) = (Uint32) col;
353 *((Uint32 *) (offset+
vis->pitch+
vis->format->BytesPerPixel)) = (Uint32) col;
367 u_int8 * offset = ((Uint8 *)
vis->pixels) + y *
vis->pitch
368 + x *
vis->format->BytesPerPixel;
370 switch (
vis->format->BytesPerPixel)
373 col = *((Uint16 *)(offset));
381 r = *((offset) + (
vis->format->Rshift >> 3));
382 g = *((offset) + (
vis->format->Gshift >> 3));
383 b = *((offset) + (
vis->format->Bshift >> 3));
385 t = r <<
vis->format->Rshift;
387 t = g <<
vis->format->Gshift;
389 t = b <<
vis->format->Bshift;
395 col = *((Uint32 *)(offset));
403 mask_on = src.mask_on;
405 not_screen = src.not_screen;
407 if (
vis) SDL_FreeSurface (
vis);
411 vis = SDL_DisplayFormat (src.
vis);
426 if (
vis) SDL_FreeSurface (
vis);
431 if (screen::dbl_mode ())
437 vis = SDL_CreateRGBSurface (SDL_SRCCOLORKEY | SDL_SRCALPHA | SDL_ASYNCBLIT,
451 SDL_FreeSurface (
vis);
483 srcrect.x = x < dstrect.x ? sx + dstrect.x - x : sx;
484 srcrect.y = y < dstrect.y ? sy + dstrect.y - y : sy;
void set_length(u_int16 l)
Sets the length of the drawable.
u_int16 length() const
Returns the length of the drawable.
bool is_masked() const
Returns whether a surface is masked or not.
#define u_int16
16 bits long unsigned integer
void set_height(u_int16 h)
Sets the height of the drawable.
surface & operator=(surface &src)
Surface copy (similar to copy ()).
surface(bool mode=true)
Default constructor.
Class where drawables can actually be drawn to.
Declares the screen class.
void fillrect(s_int16 x, s_int16 y, u_int16 l, u_int16 h, u_int32 col, drawing_area *da_opt=NULL)
Fills an area of the surface with a given color.
#define u_int32
32 bits long unsigned integer
#define u_int8
8 bits long unsigned integer
void assign_drawing_area(const drawing_area *da)
Assign a drawing_area to this drawing_area.
void resize(u_int16 l, u_int16 h)
Resize this surface.
SDL_Rect setup_rects() const
Gets the real parameters of this drawing_area.
void unlock() const
Unlock the surface after you've worked on it's pixels with the get_pix () and put_pix () methods...
u_int8 alpha() const
Returns the alpha value of the surface.
void clear()
Resets the surface to it's initial state, that is totally empty.
void draw(s_int16 x, s_int16 y, const drawing_area *da_opt=NULL, surface *target=NULL) const
Draw the surface.
Implements "drawing zones" for drawing operations.
void set_alpha(u_int8 a)
Sets the alpha value of the surface.
u_int16 height() const
Returns the height of the drawable.
static u_int8 bytes_per_pixel()
Returns the screen depth, in bytes per pixel.
#define s_int16
16 bits long signed integer
SDL_Surface * vis
The actual surface.
Declares the surface class.
static surface display
The actual screen surface.
Abstract class for drawable objects manipulation.
void get_pix(u_int16 x, u_int16 y, u_int32 &col) const
Gets a pixel from the surface.
bool changed
Must be set to true when you change the surface by something else than class surface operations...
static u_int32 trans_col()
Returns the translucent color in screen's depth format.
void set_mask(bool m)
Sets the mask parameter of the surface.
virtual ~surface()
Destructor.
void lock() const
Locks the surface.
void put_pix(u_int16 x, u_int16 y, u_int32 col)
Puts a pixel of a given color.