rnd-20000908-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_Rect src_rect, dst_rect;
26
27   src_rect.x = src_x;
28   src_rect.y = src_y;
29   src_rect.w = width;
30   src_rect.h = height;
31
32   dst_rect.x = dst_x;
33   dst_rect.y = dst_y;
34   dst_rect.w = width;
35   dst_rect.h = height;
36
37   SDL_BlitSurface(src_surface, &src_rect, dst_surface, &dst_rect);
38
39   if (dst_surface == window)
40     SDL_UpdateRect(dst_surface, dst_x, dst_y, width, height);
41 }
42
43 inline void SDLFillRectangle(SDL_Surface *surface, int x, int y,
44                              int width, int height, unsigned int color)
45 {
46   SDL_Rect rect;
47   unsigned int color_r = (color >> 2) && 0xff;
48   unsigned int color_g = (color >> 1) && 0xff;
49   unsigned int color_b = (color >> 0) && 0xff;
50
51   rect.x = x;
52   rect.y = y;
53   rect.w = width;
54   rect.h = height;
55
56   SDL_FillRect(surface, &rect,
57                SDL_MapRGB(surface->format, color_r, color_g, color_b));
58   SDL_UpdateRect(surface, x, y, width, height);
59 }
60
61 inline void SDLDrawSimpleLine(SDL_Surface *surface, int from_x, int from_y,
62                               int to_x, int to_y, unsigned int color)
63 {
64   SDL_Rect rect;
65   unsigned int color_r = (color >> 2) & 0xff;
66   unsigned int color_g = (color >> 1) & 0xff;
67   unsigned int color_b = (color >> 0) & 0xff;
68
69   if (from_x > to_x)
70     swap_numbers(&from_x, &to_x);
71
72   if (from_y > to_y)
73     swap_numbers(&from_y, &to_y);
74
75   rect.x = from_x;
76   rect.y = from_y;
77   rect.w = (to_x - from_x + 1);
78   rect.h = (to_y - from_y + 1);
79
80   SDL_FillRect(surface, &rect,
81                SDL_MapRGB(surface->format, color_r, color_g, color_b));
82 }
83
84 #endif /* USE_SDL_LIBRARY */