This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via 8701e8765185f90507ff6a02c03fcf0c22ae1e8f (commit) from 3f35d87f9ab132a5e60d3c6d7d8324af2da43653 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/8701e8765185f90507ff6a02c03fcf0c22ae1...
commit 8701e8765185f90507ff6a02c03fcf0c22ae1e8f Author: Cyril Hrubis metan@ucw.cz Date: Tue Oct 30 22:22:16 2012 +0100
tests, demos: Port randomshapetest to backends.
diff --git a/demos/c_simple/Makefile b/demos/c_simple/Makefile index f703dd1..042c208 100644 --- a/demos/c_simple/Makefile +++ b/demos/c_simple/Makefile @@ -9,7 +9,7 @@ LDLIBS+=-lrt `$(TOPDIR)/gfxprim-config --libs --libs-backends` APPS=backend_example loaders_example loaders filters_symmetry gfx_koch virtual_backend_example meta_data meta_data_dump tmp_file showimage v4l2_show v4l2_grab convolution weighted_median shapetest koch input- fileview linetest + fileview linetest randomshapetest
v4l2_show: LDLIBS+=-lGP_grabbers v4l2_grab: LDLIBS+=-lGP_grabbers diff --git a/tests/SDL/randomshapetest.c b/demos/c_simple/randomshapetest.c similarity index 50% rename from tests/SDL/randomshapetest.c rename to demos/c_simple/randomshapetest.c index f7c8939..b699348 100644 --- a/tests/SDL/randomshapetest.c +++ b/demos/c_simple/randomshapetest.c @@ -19,40 +19,23 @@ * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos * * jiri.bluebear.dluhos@gmail.com * * * - * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
#include <stdio.h> #include <stdlib.h> -#include <SDL/SDL.h>
-#include "GP_SDL.h" +#include <GP.h>
-/* The surface used as a display (in fact it is a software surface). */ -SDL_Surface *display = NULL; -GP_Context context; - -/* Timer used for refreshing the display */ -SDL_TimerID timer; - -/* An event used for signaling that the timer was triggered. */ -SDL_UserEvent timer_event; +static GP_Backend *win;
/* Globally used colors. */ -GP_Pixel white, black; +static GP_Pixel white, black;
/* Holding flag (pauses drawing). */ static int pause_flag = 0;
-Uint32 timer_callback(__attribute__((unused)) Uint32 interval, - __attribute__((unused)) void *param) -{ - timer_event.type = SDL_USEREVENT; - SDL_PushEvent((SDL_Event *) &timer_event); - return 60; -} - /* Shape to draw */ #define SHAPE_FIRST 1 #define SHAPE_CIRCLE 1 @@ -73,111 +56,110 @@ static int fill_flag = 1; /* Do a clipping test? */ static int cliptest_flag = 0;
-void random_point(SDL_Surface *surf, int *x, int *y) +void random_point(const GP_Context *c, int *x, int *y) { if (cliptest_flag) { - *x = random() % (3*surf->w) - surf->w; - *y = random() % (3*surf->h) - surf->h; + *x = random() % (3*c->w) - c->w; + *y = random() % (3*c->h) - c->h; } else { - *x = random() % surf->w; - *y = random() % surf->h; + *x = random() % c->w; + *y = random() % c->h; } }
-void random_point_AA(SDL_Surface *surf, int *x, int *y) +void random_point_AA(const GP_Context *c, int *x, int *y) { - *x = random() % (surf->w<<8); - *y = random() % (surf->h<<8); + *x = random() % (c->w<<8); + *y = random() % (c->h<<8); }
void draw_random_circle(GP_Pixel pixel) { int x, y; - random_point(display, &x, &y); + random_point(win->context, &x, &y); int r = random() % 50;
if (fill_flag) - GP_FillCircle(&context, x, y, r, pixel); + GP_FillCircle(win->context, x, y, r, pixel);
if (outline_flag) - GP_Circle(&context, x, y, r, white); + GP_Circle(win->context, x, y, r, white); }
void draw_random_ellipse(GP_Pixel pixel) { int x, y; - random_point(display, &x, &y); + random_point(win->context, &x, &y); int rx = random() % 50; int ry = random() % 50;
if (fill_flag) - GP_FillEllipse(&context, x, y, rx, ry, pixel); + GP_FillEllipse(win->context, x, y, rx, ry, pixel);
if (outline_flag) - GP_Ellipse(&context, x, y, rx, ry, white); + GP_Ellipse(win->context, x, y, rx, ry, white); }
void draw_random_triangle(GP_Pixel pixel) { int x0, y0, x1, y1, x2, y2; - random_point(display, &x0, &y0); - random_point(display, &x1, &y1); - random_point(display, &x2, &y2); + random_point(win->context, &x0, &y0); + random_point(win->context, &x1, &y1); + random_point(win->context, &x2, &y2);
if (fill_flag) - GP_FillTriangle(&context, x0, y0, x1, y1, x2, y2, pixel); + GP_FillTriangle(win->context, x0, y0, x1, y1, x2, y2, pixel);
if (outline_flag) - GP_Triangle(&context, x0, y0, x1, y1, x2, y2, white); + GP_Triangle(win->context, x0, y0, x1, y1, x2, y2, white); }
void draw_random_rectangle(GP_Pixel pixel) { int x0, y0, x1, y1; - random_point(display, &x0, &y0); - random_point(display, &x1, &y1); + random_point(win->context, &x0, &y0); + random_point(win->context, &x1, &y1);
if (fill_flag) - GP_FillRect(&context, x0, y0, x1, y1, pixel); + GP_FillRect(win->context, x0, y0, x1, y1, pixel);
if (outline_flag) - GP_Rect(&context, x0, y0, x1, y1, white); + GP_Rect(win->context, x0, y0, x1, y1, white); }
void draw_random_tetragon(GP_Pixel pixel) { int x0, y0, x1, y1, x2, y2, x3, y3; - random_point(display, &x0, &y0); - random_point(display, &x1, &y1); - random_point(display, &x2, &y2); - random_point(display, &x3, &y3); + random_point(win->context, &x0, &y0); + random_point(win->context, &x1, &y1); + random_point(win->context, &x2, &y2); + random_point(win->context, &x3, &y3);
if (fill_flag) - GP_FillTetragon(&context, x0, y0, x1, y1, x2, y2, x3, y3, pixel); + GP_FillTetragon(win->context, x0, y0, x1, y1, x2, y2, x3, y3, pixel);
if (outline_flag) - GP_Tetragon(&context, x0, y0, x1, y1, x2, y2, x3, y3, pixel); + GP_Tetragon(win->context, x0, y0, x1, y1, x2, y2, x3, y3, pixel); }
void draw_random_rectangle_AA(GP_Pixel pixel) { int x0, y0, x1, y1; - random_point_AA(display, &x0, &y0); - random_point_AA(display, &x1, &y1); + random_point_AA(win->context, &x0, &y0); + random_point_AA(win->context, &x1, &y1);
// if (fill_flag) - GP_FillRect_AA(&context, x0, y0, x1, y1, pixel); + GP_FillRect_AA(win->context, x0, y0, x1, y1, pixel);
// if (outline_flag) -// GP_Rect(&context, x0, y0, x1, y1, white); +// GP_Rect(win->context, x0, y0, x1, y1, white); }
void clear_screen(void) { - SDL_LockSurface(display); - GP_Fill(&context, black); - SDL_UnlockSurface(display); + GP_Fill(win->context, black); + GP_BackendFlip(win); }
void redraw_screen(void) @@ -185,12 +167,10 @@ void redraw_screen(void) if (pause_flag) return;
- SDL_LockSurface(display); - /* Pick a random color for drawing. */ GP_Pixel pixel; pixel = GP_RGBToPixel(random() % 256, random() % 256, - random() % 256, context.pixel_type); + random() % 256, win->context->pixel_type);
switch (shape) { case SHAPE_CIRCLE: @@ -212,133 +192,80 @@ void redraw_screen(void) draw_random_rectangle_AA(pixel); break; } - - SDL_UnlockSurface(display); }
void event_loop(void) { - SDL_Event event; - - while (SDL_WaitEvent(&event) > 0) { - - switch (event.type) { - - case SDL_USEREVENT: - redraw_screen(); - SDL_Flip(display); - break; - - case SDL_KEYDOWN: - switch (event.key.keysym.sym) { - - case SDLK_SPACE: + GP_Event ev; + + while (GP_EventGet(&ev)) { + switch (ev.type) { + case GP_EV_KEY: + if (ev.code != GP_EV_KEY_DOWN) + continue; + + switch (ev.val.key.key) { + case GP_KEY_SPACE: shape++; if (shape > SHAPE_LAST) shape = SHAPE_FIRST; clear_screen(); - SDL_Flip(display); pause_flag = 0; - break; - - case SDLK_p: + break; + case GP_KEY_P: pause_flag = !pause_flag; - break; - - case SDLK_f: + break; + case GP_KEY_F: fill_flag = !fill_flag; - if (!fill_flag && !outline_flag) { + if (!fill_flag && !outline_flag) outline_flag = 1; - } - break; - - case SDLK_o: + break; + case GP_KEY_O: outline_flag = !outline_flag; - if (!fill_flag && !outline_flag) { + if (!fill_flag && !outline_flag) fill_flag = 1; - } - break; - - case SDLK_c: + break; + case GP_KEY_C: cliptest_flag = !cliptest_flag; - break; - - case SDLK_x: + break; + case GP_KEY_X: clear_screen(); - SDL_Flip(display); - break; - - case SDLK_ESCAPE: - return; - - default: - break; - } break; - case SDL_QUIT: - return; - default: + case GP_KEY_ESC: + GP_BackendExit(win); + exit(0); break; + } } } }
-int main(int argc, char *argv[]) +int main(void) { - /* Bits per pixel to be set for the display surface. */ - int display_bpp = 0; - - int i; - for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-16") == 0) { - display_bpp = 16; - } - else if (strcmp(argv[i], "-24") == 0) { - display_bpp = 24; - } - else if (strcmp(argv[i], "-32") == 0) { - display_bpp = 32; - } - } + const char *backend_opts = "X11"; + + win = GP_BackendInit(backend_opts, "Random Shape Test", stderr);
- /* Initialize SDL */ - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) { - fprintf(stderr, "Could not initialize SDL: %sn", SDL_GetError()); + if (win == NULL) { + fprintf(stderr, "Failed to initalize backend '%s'n", + backend_opts); return 1; } - - /* Create a window with a software back surface */ - display = SDL_SetVideoMode(640, 480, display_bpp, SDL_SWSURFACE); - if (display == NULL) { - fprintf(stderr, "Could not open display: %sn", SDL_GetError()); - goto fail; - } - - /* Set up a clipping rectangle to test proper clipping of pixels */ - SDL_Rect clip_rect = {10, 10, 620, 460}; - SDL_SetClipRect(display, &clip_rect); - - GP_SDL_ContextFromSurface(&context, display); - - white = GP_ColorToContextPixel(GP_COL_WHITE, &context); - black = GP_ColorToContextPixel(GP_COL_BLACK, &context); - - /* Set up the refresh timer */ - timer = SDL_AddTimer(60, timer_callback, NULL); - if (timer == 0) { - fprintf(stderr, "Could not set up timer: %sn", SDL_GetError()); - goto fail; + + white = GP_ColorToContextPixel(GP_COL_WHITE, win->context); + black = GP_ColorToContextPixel(GP_COL_BLACK, win->context); + + for (;;) { + GP_BackendPoll(win); + event_loop(); + + usleep(20000); + + if (pause_flag) + continue; + + redraw_screen(); + GP_BackendFlip(win); } - - /* Enter the event loop */ - event_loop(); - - /* We're done */ - SDL_Quit(); - return 0; - -fail: - SDL_Quit(); - return 1; }
diff --git a/tests/SDL/Makefile b/tests/SDL/Makefile index 1002fcb..6985861 100644 --- a/tests/SDL/Makefile +++ b/tests/SDL/Makefile @@ -7,7 +7,7 @@ LDLIBS+=-lGP -L$(TOPDIR)/build/ -lGP_SDL -lSDL ifeq ($(HAVE_LIBSDL),yes) CSOURCES=$(shell echo *.c)
-APPS=pixeltest fonttest randomshapetest+APPS=pixeltest fonttest symbolstest textaligntest blittest subcontext aatest mixpixeltest endif
-----------------------------------------------------------------------
Summary of changes: demos/c_simple/Makefile | 2 +- {tests/SDL => demos/c_simple}/randomshapetest.c | 249 ++++++++--------------- tests/SDL/Makefile | 2 +- 3 files changed, 90 insertions(+), 163 deletions(-) rename {tests/SDL => demos/c_simple}/randomshapetest.c (50%)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.