1 /*****************************************************************************
2 * This file is part of gfxprim library. *
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. *
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. *
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 *
19 * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos *
20 * <jiri.bluebear.dluhos@gmail.com> *
22 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
24 *****************************************************************************/
29 static GP_Pixel black
;
30 static GP_Pixel white
;
32 static GP_Backend
*win
;
34 static GP_Pixmap
*bitmap
, *bitmap_raw
, *bitmap_conv
;
35 static int bitmap_x
, bitmap_y
, bitmap_vx
= -3, bitmap_vy
= -3;
36 static int pause_flag
= 0;
38 static char text_buf
[255];
40 void redraw_screen(void)
42 bitmap_x
+= bitmap_vx
;
43 bitmap_y
+= bitmap_vy
;
45 if (bitmap_x
+ GP_PixmapW(bitmap
) > win
->pixmap
->w
) {
46 bitmap_vx
= -bitmap_vx
;
47 bitmap_x
+= bitmap_vx
;
51 bitmap_vx
= -bitmap_vx
;
52 bitmap_x
+= bitmap_vx
;
55 if (bitmap_y
+ GP_PixmapH(bitmap
) > win
->pixmap
->h
) {
56 bitmap_vy
= -bitmap_vy
;
57 bitmap_y
+= bitmap_vy
;
61 bitmap_vy
= -bitmap_vy
;
62 bitmap_y
+= bitmap_vy
;
65 GP_FillRectXYWH(win
->pixmap
, 20, 20, 300, 50, black
);
67 GP_Text(win
->pixmap
, NULL
, 20, 20, GP_ALIGN_RIGHT
|GP_VALIGN_BOTTOM
,
68 white
, black
, text_buf
);
70 GP_Print(win
->pixmap
, NULL
, 250, 20, GP_ALIGN_RIGHT
|GP_VALIGN_BOTTOM
,
71 white
, black
, "%c|%c|%c", bitmap
->x_swap
? 'x' : ' ',
72 bitmap
->y_swap
? 'y' : ' ', bitmap
->axes_swap
? 'a' : ' ');
74 GP_Blit(bitmap
, 0, 0, GP_PixmapW(bitmap
), GP_PixmapH(bitmap
),
75 win
->pixmap
, bitmap_x
, bitmap_y
);
77 GP_BackendUpdateRectXYWH(win
, bitmap_x
, bitmap_y
,
78 GP_PixmapW(bitmap
), GP_PixmapH(bitmap
));
79 GP_BackendUpdateRectXYWH(win
, 20, 20, 400, 50);
82 static void change_bitmap(void)
84 if (bitmap
== bitmap_raw
)
89 snprintf(text_buf
, sizeof(text_buf
), "'%s' -> '%s'",
90 GP_PixelTypeName(bitmap
->pixel_type
),
91 GP_PixelTypeName(win
->pixmap
->pixel_type
));
98 while (GP_BackendGetEvent(win
, &ev
)) {
103 if (ev
.code
!= GP_EV_KEY_DOWN
)
106 switch (ev
.val
.key
.key
) {
108 bitmap
->x_swap
= !bitmap
->x_swap
;
111 bitmap
->y_swap
= !bitmap
->y_swap
;
114 bitmap
->axes_swap
= !bitmap
->axes_swap
;
117 pause_flag
= !pause_flag
;
134 case GP_EV_SYS_RESIZE
:
135 GP_BackendResizeAck(win
);
136 GP_Fill(win
->pixmap
, black
);
145 void print_instructions(void)
147 printf("Use the following keys to control the test:\n");
148 printf(" Esc ............. exit\n");
149 printf(" Space ........... converts bitmap to screen pixel format\n");
150 printf(" R ............... swap sprite axes\n");
151 printf(" X ............... mirror sprite X\n");
152 printf(" Y ............... mirror sprite Y\n");
153 printf(" P ............... pause\n");
158 const char *sprite
= "ball.ppm";
159 const char *backend_opts
= "X11";
161 print_instructions();
163 bitmap_raw
= GP_LoadImage(sprite
, NULL
);
166 fprintf(stderr
, "Failed to load '%s'\n", sprite
);
170 win
= GP_BackendInit(backend_opts
, "Blit Test");
173 fprintf(stderr
, "Failed to initalize backend '%s'\n",
178 bitmap_conv
= GP_PixmapConvertAlloc(bitmap_raw
,
179 win
->pixmap
->pixel_type
);
182 black
= GP_RGBToPixmapPixel(0x00, 0x00, 0x00, win
->pixmap
);
183 white
= GP_RGBToPixmapPixel(0xff, 0xff, 0xff, win
->pixmap
);
185 GP_Fill(win
->pixmap
, black
);