gfx: Implement GP_FillCircleSeg()
[gfxprim.git] / demos / c_simple / SDL_glue.c
blobef360e0b0e84d69f9f4e4c0c2530ad46ae963c5b
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
18 * *
19 * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
20 * <jiri.bluebear.dluhos@gmail.com> *
21 * *
22 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
23 * *
24 *****************************************************************************/
28 This example shows how to mix SDL with GFXprim.
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <SDL/SDL.h>
35 #include <GP.h>
36 #include <backends/GP_SDL_Pixmap.h>
38 #define W 320
39 #define H 240
41 static SDL_Surface *display = NULL;
42 static GP_Pixmap pixmap;
44 static GP_Pixel black_pixel, darkgray_pixel;
46 void redraw_screen(void)
48 SDL_LockSurface(display);
50 GP_Fill(&pixmap, black_pixel);
52 GP_Text(&pixmap, NULL, W/2, 20, GP_ALIGN_CENTER | GP_VALIGN_BELOW,
53 darkgray_pixel, black_pixel, "GFXprim SDL Demo");
55 GP_Line(&pixmap, 0, 0, W-1, H-1, darkgray_pixel);
56 GP_Line(&pixmap, 0, H-1, W-1, 0, darkgray_pixel);
58 SDL_UnlockSurface(display);
61 void event_loop(void)
63 SDL_Event event;
65 while (SDL_WaitEvent(&event) > 0) {
66 switch (event.type) {
68 case SDL_VIDEOEXPOSE:
69 redraw_screen();
70 SDL_Flip(display);
71 break;
73 case SDL_KEYDOWN:
74 switch (event.key.keysym.sym) {
75 case SDLK_ESCAPE:
76 return;
77 default:
78 break;
80 break;
82 case SDL_QUIT:
83 return;
88 int main(void)
90 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
91 fprintf(stderr, "Could not initialize SDL: %s\n", SDL_GetError());
92 return 1;
95 display = SDL_SetVideoMode(W, H, 0, SDL_SWSURFACE);
97 if (display == NULL) {
98 fprintf(stderr, "Could not open display: %s\n", SDL_GetError());
99 SDL_Quit();
100 return 1;
103 GP_PixmapFromSDLSurface(&pixmap, display);
105 black_pixel = GP_RGBToPixmapPixel(0x00, 0x00, 0x00, &pixmap);
106 darkgray_pixel = GP_RGBToPixmapPixel(0x7f, 0x7f, 0x7f, &pixmap);
108 redraw_screen();
109 SDL_Flip(display);
111 event_loop();
113 SDL_Quit();
114 return 0;