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 static GP_Pixel white_pixel
, black_pixel
, red_pixel
, blue_pixel
, green_pixel
;
36 static void redraw(GP_Backend
*backend
)
38 GP_Pixmap
*pixmap
= backend
->pixmap
;
40 /* Now draw some testing patters */
41 black_pixel
= GP_RGBToPixmapPixel(0x00, 0x00, 0x00, pixmap
);
42 white_pixel
= GP_RGBToPixmapPixel(0xff, 0xff, 0xff, pixmap
);
43 red_pixel
= GP_RGBToPixmapPixel(0xff, 0x00, 0x00, pixmap
);
44 blue_pixel
= GP_RGBToPixmapPixel(0x00, 0x00, 0xff, pixmap
);
45 green_pixel
= GP_RGBToPixmapPixel(0x00, 0xff, 0x00, pixmap
);
47 GP_Fill(pixmap
, white_pixel
);
50 for (i
= 0; i
< 40; i
++) {
51 GP_HLineXYW(pixmap
, 0, i
, i
, black_pixel
);
52 GP_HLineXYW(pixmap
, 1, i
+ 40, i
, black_pixel
);
53 GP_HLineXYW(pixmap
, 2, i
+ 80, i
, black_pixel
);
54 GP_HLineXYW(pixmap
, 3, i
+ 120, i
, black_pixel
);
55 GP_HLineXYW(pixmap
, 4, i
+ 160, i
, black_pixel
);
56 GP_HLineXYW(pixmap
, 5, i
+ 200, i
, black_pixel
);
57 GP_HLineXYW(pixmap
, 6, i
+ 240, i
, black_pixel
);
58 GP_HLineXYW(pixmap
, 7, i
+ 280, i
, black_pixel
);
61 for (i
= 0; i
< 256; i
++) {
62 for (j
= 0; j
< 256; j
++) {
63 uint8_t val
= 1.00 * sqrt(i
*i
+ j
*j
)/sqrt(2) + 0.5;
65 GP_Pixel pix
= GP_RGBToPixmapPixel(i
, j
, val
, pixmap
);
66 GP_PutPixel(pixmap
, i
+ 60, j
+ 10, pix
);
70 GP_Text(pixmap
, NULL
, 60, 270, GP_VALIGN_BELOW
|GP_ALIGN_RIGHT
,
71 black_pixel
, white_pixel
, "Lorem Ipsum dolor sit...");
73 GP_Text(pixmap
, NULL
, 60, 290, GP_VALIGN_BELOW
|GP_ALIGN_RIGHT
,
74 red_pixel
, white_pixel
, "Lorem Ipsum dolor sit...");
76 GP_Text(pixmap
, NULL
, 60, 310, GP_VALIGN_BELOW
|GP_ALIGN_RIGHT
,
77 green_pixel
, white_pixel
, "Lorem Ipsum dolor sit...");
79 GP_Text(pixmap
, NULL
, 60, 330, GP_VALIGN_BELOW
|GP_ALIGN_RIGHT
,
80 blue_pixel
, white_pixel
, "Lorem Ipsum dolor sit...");
82 /* Update the backend screen */
83 GP_BackendFlip(backend
);
86 int main(int argc
, char *argv
[])
89 const char *backend_opts
= "X11:350x350";
91 GP_PixelType emul_type
= GP_PIXEL_UNKNOWN
;
93 while ((opt
= getopt(argc
, argv
, "b:h:p:")) != -1) {
96 backend_opts
= optarg
;
99 emul_type
= GP_PixelTypeByName(optarg
);
101 if (emul_type
== GP_PIXEL_UNKNOWN
) {
102 fprintf(stderr
, "Invalid pixel type '%s'\n", optarg
);
107 GP_BackendInit("help", NULL
);
111 fprintf(stderr
, "Invalid paramter '%c'\n", opt
);
116 /* Turn on debug messages */
117 GP_SetDebugLevel(10);
119 backend
= GP_BackendInit(backend_opts
, "Virtual Backend Example");
121 if (emul_type
!= GP_PIXEL_UNKNOWN
) {
125 * Create an emulated backend on the top of real backend.
127 * The GP_BACKEND_CALL_EXIT says that when calling exit on
128 * emulated backend, the real backend exit will be called as
131 emul
= GP_BackendVirtualInit(backend
, emul_type
, GP_BACKEND_CALL_EXIT
);
134 fprintf(stderr
, "Failed to create Virtual Backend\n");
135 GP_BackendExit(backend
);
139 /* Once created virtual backend behaves exactly like a real one */
147 GP_BackendPoll(backend
);
151 /* Read and parse events */
154 while (GP_BackendGetEvent(backend
, &ev
)) {
160 switch (ev
.val
.key
.key
) {
163 GP_BackendExit(backend
);
170 case GP_EV_SYS_RESIZE
:
171 GP_BackendResizeAck(backend
);
180 GP_BackendExit(backend
);