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