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 *****************************************************************************/
30 /* Values for color pixels in display format. */
31 static GP_Pixel black
, white
;
33 static double start_angle
= 0.0;
35 static int aa_flag
= 0;
36 static int pause_flag
= 0;
38 static GP_Backend
*win
;
40 void redraw_screen(void)
44 int w
= win
->context
->w
;
45 int h
= win
->context
->h
;
49 GP_Fill(win
->context
, black
);
51 for (angle
= 0.0; angle
< 2*M_PI
; angle
+= 0.1) {
52 x
= (int) (w
/2 * cos(start_angle
+ angle
));
53 y
= (int) (h
/2 * sin(start_angle
+ angle
));
55 int r
= 127.0 + 127.0 * cos(start_angle
+ angle
);
56 int b
= 127.0 + 127.0 * sin(start_angle
+ angle
);
59 pixel
= GP_RGBToPixel(r
, 0, b
, win
->context
->pixel_type
);
62 GP_LineAA_Raw(win
->context
, GP_FP_FROM_INT(xcenter
), GP_FP_FROM_INT(ycenter
),
63 GP_FP_FROM_INT(xcenter
+ x
), GP_FP_FROM_INT(ycenter
+ y
), pixel
);
65 GP_Line(win
->context
, xcenter
+ x
, ycenter
+ y
, xcenter
, ycenter
, pixel
);
66 GP_Line(win
->context
, xcenter
, ycenter
, xcenter
+ x
, ycenter
+ y
, pixel
);
73 // GP_HLineXYW(&context, 0, ycenter, display->w, white);
74 // GP_VLineXYH(&context, xcenter, 0, display->h, white);
81 while (GP_BackendGetEvent(win
, &ev
)) {
84 if (ev
.code
!= GP_EV_KEY_DOWN
)
87 switch (ev
.val
.key
.key
) {
96 pause_flag
= !pause_flag
;
106 case GP_EV_SYS_RESIZE
:
107 GP_BackendResizeAck(win
);
115 int main(int argc
, char *argv
[])
117 const char *backend_opts
= "X11";
120 while ((opt
= getopt(argc
, argv
, "b:")) != -1) {
123 backend_opts
= optarg
;
126 fprintf(stderr
, "Invalid paramter '%c'\n", opt
);
130 win
= GP_BackendInit(backend_opts
, "Line Test");
133 fprintf(stderr
, "Failed to initalize backend '%s'\n",
138 white
= GP_ColorToContextPixel(GP_COL_WHITE
, win
->context
);
139 black
= GP_ColorToContextPixel(GP_COL_BLACK
, win
->context
);
156 if (start_angle
> 2*M_PI
) {