rnd-20001122-1-src
[rocksndiamonds.git] / src / sdl.c
1 /***********************************************************
2 *  Rocks'n'Diamonds -- McDuffin Strikes Back!              *
3 *----------------------------------------------------------*
4 *  ©1995 Artsoft Development                               *
5 *        Holger Schemel                                    *
6 *        33659 Bielefeld-Senne                             *
7 *        Telefon: (0521) 493245                            *
8 *        eMail: aeglos@valinor.owl.de                      *
9 *               aeglos@uni-paderborn.de                    *
10 *               q99492@pbhrzx.uni-paderborn.de             *
11 *----------------------------------------------------------*
12 *  sdl.c                                                   *
13 ***********************************************************/
14
15 #ifdef USE_SDL_LIBRARY
16
17 #include "main.h"
18 #include "misc.h"
19
20 inline void SDLCopyArea(SDL_Surface *src_surface, SDL_Surface *dst_surface,
21                         int src_x, int src_y,
22                         int width, int height,
23                         int dst_x, int dst_y)
24 {
25   SDL_Surface *surface = (dst_surface == window ? backbuffer : dst_surface);
26   SDL_Rect src_rect, dst_rect;
27
28   src_rect.x = src_x;
29   src_rect.y = src_y;
30   src_rect.w = width;
31   src_rect.h = height;
32
33   dst_rect.x = dst_x;
34   dst_rect.y = dst_y;
35   dst_rect.w = width;
36   dst_rect.h = height;
37
38   if (src_surface != backbuffer || dst_surface != window)
39     SDL_BlitSurface(src_surface, &src_rect, surface, &dst_rect);
40
41   if (dst_surface == window)
42     SDL_UpdateRect(backbuffer, dst_x, dst_y, width, height);
43 }
44
45 inline void SDLFillRectangle(SDL_Surface *dst_surface, int x, int y,
46                              int width, int height, unsigned int color)
47 {
48   SDL_Surface *surface = (dst_surface == window ? backbuffer : dst_surface);
49   SDL_Rect rect;
50   unsigned int color_r = (color >> 16) && 0xff;
51   unsigned int color_g = (color >>  8) && 0xff;
52   unsigned int color_b = (color >>  0) && 0xff;
53
54   rect.x = x;
55   rect.y = y;
56   rect.w = width;
57   rect.h = height;
58
59   SDL_FillRect(surface, &rect,
60                SDL_MapRGB(surface->format, color_r, color_g, color_b));
61
62   if (dst_surface == window)
63     SDL_UpdateRect(backbuffer, x, y, width, height);
64 }
65
66 inline void SDLDrawSimpleLine(SDL_Surface *surface, int from_x, int from_y,
67                               int to_x, int to_y, unsigned int color)
68 {
69   SDL_Rect rect;
70   unsigned int color_r = (color >> 16) & 0xff;
71   unsigned int color_g = (color >>  8) & 0xff;
72   unsigned int color_b = (color >>  0) & 0xff;
73
74   if (from_x > to_x)
75     swap_numbers(&from_x, &to_x);
76
77   if (from_y > to_y)
78     swap_numbers(&from_y, &to_y);
79
80   rect.x = from_x;
81   rect.y = from_y;
82   rect.w = (to_x - from_x + 1);
83   rect.h = (to_y - from_y + 1);
84
85   SDL_FillRect(surface, &rect,
86                SDL_MapRGB(surface->format, color_r, color_g, color_b));
87 }
88
89 #endif /* USE_SDL_LIBRARY */