Remove tests for color and palette.
[gfxprim.git] / old_tests / widelinetest.c
blob395885d2d4511b6e66a0d5dca0e021a0210d8c16
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-2010 Cyril Hrubis <metan@ucw.cz> *
23 * *
24 *****************************************************************************/
26 #include <math.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <SDL/SDL.h>
31 #include "GP.h"
33 /* The surface used as a display (in fact it is a software surface). */
34 SDL_Surface *display = NULL;
36 /* Timer used for refreshing the display */
37 SDL_TimerID timer;
39 /* An event used for signaling that the timer was triggered. */
40 SDL_UserEvent timer_event;
42 /* Values for color pixels in display format. */
43 static long colors[GP_BASIC_COLOR_COUNT];
45 Uint32 timer_callback(__attribute__((unused)) Uint32 interval,
46 __attribute__((unused)) void *param)
48 timer_event.type = SDL_USEREVENT;
49 SDL_PushEvent((SDL_Event *) &timer_event);
50 return 30;
53 double start_angle = 0.0;
55 void redraw_screen(void)
57 int i;
59 for (i = 1; i < 10; i++) {
60 GP_HLineWide(display, colors[GP_WHITE], GP_LINE_CENTER, i, 10, 100, 20*i);
61 GP_HLine(display, colors[GP_RED], 10, 100, 20*i);
64 for (i = 1; i < 10; i++) {
65 GP_VLineWide(display, colors[GP_WHITE], GP_LINE_CENTER, i, 100 + 20*i, 100, 190);
66 GP_VLine(display, colors[GP_RED], 100 + 20*i, 100, 190);
70 void event_loop(void)
72 SDL_Event event;
74 while (SDL_WaitEvent(&event) > 0) {
75 switch (event.type) {
76 case SDL_USEREVENT:
77 redraw_screen();
78 SDL_Flip(display);
79 start_angle += 0.01;
80 if (start_angle > 2*M_PI) {
81 start_angle = 0.0;
83 break;
84 case SDL_KEYDOWN:
85 case SDL_QUIT:
86 return;
91 int main(void)
93 /* Initialize SDL */
94 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
95 fprintf(stderr, "Could not initialize SDL: %s\n", SDL_GetError());
96 return 1;
99 /* Create a window with a software back surface */
100 display = SDL_SetVideoMode(640, 480, 0, SDL_SWSURFACE);
101 if (display == NULL) {
102 fprintf(stderr, "Could not open display: %s\n", SDL_GetError());
103 goto fail;
106 /* Print basic information about the surface */
107 printf("Display surface properties:\n");
108 printf(" width: %4d, height: %4d, pitch: %4d\n",
109 display->w, display->h, display->pitch);
110 printf(" bits per pixel: %2d, bytes per pixel: %2d\n",
111 display->format->BitsPerPixel, display->format->BytesPerPixel);
113 /* Get colors */
114 GP_LoadBasicColors(display, colors);
116 /* Set up a clipping rectangle to test proper clipping of pixels */
117 SDL_Rect clip_rect = { 10, 10, 620, 460 };
118 SDL_SetClipRect(display, &clip_rect);
120 /* Set up the refresh timer */
121 timer = SDL_AddTimer(30, timer_callback, NULL);
122 if (timer == 0) {
123 fprintf(stderr, "Could not set up timer: %s\n", SDL_GetError());
124 goto fail;
127 /* Enter the event loop */
128 event_loop();
130 /* We're done */
131 SDL_Quit();
132 return 0;
134 fail:
135 SDL_Quit();
136 return 1;