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-2013 Cyril Hrubis <metan@ucw.cz> *
21 *****************************************************************************/
25 Simple virtual backend test.
27 Virtual backned allows you to test interactively pixel types that your
28 hardware/xserver doesn't support.
34 int main(int argc
, char *argv
[])
38 GP_Pixel white_pixel
, black_pixel
, red_pixel
, blue_pixel
, green_pixel
;
39 const char *backend_opts
= "X11:350x350";
41 GP_PixelType emul_type
= GP_PIXEL_UNKNOWN
;
43 while ((opt
= getopt(argc
, argv
, "b:h:p:")) != -1) {
46 backend_opts
= optarg
;
49 emul_type
= GP_PixelTypeByName(optarg
);
51 if (emul_type
== GP_PIXEL_UNKNOWN
) {
52 fprintf(stderr
, "Invalid pixel type '%s'\n", optarg
);
57 GP_BackendInit("help", NULL
);
61 fprintf(stderr
, "Invalid paramter '%c'\n", opt
);
66 /* Turn on debug messages */
69 backend
= GP_BackendInit(backend_opts
, "Virtual Backend Example");
71 if (emul_type
!= GP_PIXEL_UNKNOWN
) {
75 * Create an emulated backend on the top of real backend.
77 * The GP_BACKEND_CALL_EXIT says that when calling exit on
78 * emulated backend, the real backend exit will be called as
81 emul
= GP_BackendVirtualInit(backend
, emul_type
, GP_BACKEND_CALL_EXIT
);
84 fprintf(stderr
, "Failed to create Virtual Backend\n");
85 GP_BackendExit(backend
);
89 /* Once created virtual backend behaves exactly like a real one */
93 context
= backend
->context
;
95 /* Now draw some testing patters */
96 black_pixel
= GP_RGBToContextPixel(0x00, 0x00, 0x00, context
);
97 white_pixel
= GP_RGBToContextPixel(0xff, 0xff, 0xff, context
);
98 red_pixel
= GP_RGBToContextPixel(0xff, 0x00, 0x00, context
);
99 blue_pixel
= GP_RGBToContextPixel(0x00, 0x00, 0xff, context
);
100 green_pixel
= GP_RGBToContextPixel(0x00, 0xff, 0x00, context
);
102 GP_Fill(context
, white_pixel
);
105 for (i
= 0; i
< 40; i
++) {
106 GP_HLineXYW(context
, 0, i
, i
, black_pixel
);
107 GP_HLineXYW(context
, 1, i
+ 40, i
, black_pixel
);
108 GP_HLineXYW(context
, 2, i
+ 80, i
, black_pixel
);
109 GP_HLineXYW(context
, 3, i
+ 120, i
, black_pixel
);
110 GP_HLineXYW(context
, 4, i
+ 160, i
, black_pixel
);
111 GP_HLineXYW(context
, 5, i
+ 200, i
, black_pixel
);
112 GP_HLineXYW(context
, 6, i
+ 240, i
, black_pixel
);
113 GP_HLineXYW(context
, 7, i
+ 280, i
, black_pixel
);
116 for (i
= 0; i
< 256; i
++) {
117 for (j
= 0; j
< 256; j
++) {
118 uint8_t val
= 1.00 * sqrt(i
*i
+ j
*j
)/sqrt(2) + 0.5;
120 GP_Pixel pix
= GP_RGBToContextPixel(i
, j
, val
, context
);
121 GP_PutPixel(context
, i
+ 60, j
+ 10, pix
);
125 GP_Text(context
, NULL
, 60, 270, GP_VALIGN_BELOW
|GP_ALIGN_RIGHT
,
126 black_pixel
, white_pixel
, "Lorem Ipsum dolor sit...");
128 GP_Text(context
, NULL
, 60, 290, GP_VALIGN_BELOW
|GP_ALIGN_RIGHT
,
129 red_pixel
, white_pixel
, "Lorem Ipsum dolor sit...");
131 GP_Text(context
, NULL
, 60, 310, GP_VALIGN_BELOW
|GP_ALIGN_RIGHT
,
132 green_pixel
, white_pixel
, "Lorem Ipsum dolor sit...");
134 GP_Text(context
, NULL
, 60, 330, GP_VALIGN_BELOW
|GP_ALIGN_RIGHT
,
135 blue_pixel
, white_pixel
, "Lorem Ipsum dolor sit...");
137 /* Update the backend screen */
138 GP_BackendFlip(backend
);
142 GP_BackendPoll(backend
);
146 /* Read and parse events */
149 while (GP_BackendGetEvent(backend
, &ev
)) {
155 switch (ev
.val
.key
.key
) {
158 GP_BackendExit(backend
);
166 GP_BackendExit(backend
);