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 *****************************************************************************/
32 static GP_Context
*win
;
33 static GP_Backend
*backend
;
35 static GP_Pixel red
, green
, white
, black
;
37 static void draw_event(GP_Event
*ev
)
39 static GP_Size size
= 0;
41 if (ev
->type
!= GP_EV_KEY
)
44 int align
= GP_ALIGN_RIGHT
|GP_VALIGN_BOTTOM
;
46 GP_TextClear(win
, NULL
, 20, 20, align
, black
, size
);
47 size
= GP_Print(win
, NULL
, 20, 20, align
,
48 white
, black
, "Key=%s",
49 GP_EventKeyName(ev
->val
.key
.key
));
51 GP_BackendFlip(backend
);
54 static void event_loop(void)
57 GP_BackendWait(backend
);
59 while (GP_BackendEventsQueued(backend
)) {
62 GP_BackendGetEvent(backend
, &ev
);
69 switch (ev
.val
.key
.key
) {
71 GP_BackendExit(backend
);
75 GP_HLineXXY(win
, ev
.cursor_x
- 3,
78 GP_VLineXYY(win
, ev
.cursor_x
,
80 ev
.cursor_y
+ 3, red
);
81 GP_BackendFlip(backend
);
91 if (GP_EventGetKey(&ev
, GP_BTN_LEFT
)) {
92 GP_PutPixel(win
, ev
.cursor_x
,
95 int align
= GP_ALIGN_RIGHT
|GP_VALIGN_BOTTOM
;
97 GP_TextClear(win
, NULL
, 20, 40, align
,
99 size
= GP_Print(win
, NULL
, 20, 40, align
,
100 white
, black
, "X=%3u Y=%3u dX=%3i dY=%3i",
101 ev
.cursor_x
, ev
.cursor_y
,
102 ev
.val
.rel
.rx
, ev
.val
.rel
.ry
);
103 GP_BackendFlip(backend
);
109 case GP_EV_SYS_RESIZE
:
110 GP_BackendResizeAck(backend
);
113 GP_BackendExit(backend
);
123 int main(int argc
, char *argv
[])
125 const char *backend_opts
= "X11";
128 while ((opt
= getopt(argc
, argv
, "b:h")) != -1) {
131 backend_opts
= optarg
;
134 GP_BackendInit("help", NULL
);
138 fprintf(stderr
, "Invalid paramter '%c'\n", opt
);
143 backend
= GP_BackendInit(backend_opts
, "Input Test");
145 if (backend
== NULL
) {
146 fprintf(stderr
, "Failed to initalize backend '%s'\n",
151 win
= backend
->context
;
153 red
= GP_ColorToContextPixel(GP_COL_RED
, win
);
154 green
= GP_ColorToContextPixel(GP_COL_GREEN
, win
);
155 white
= GP_ColorToContextPixel(GP_COL_WHITE
, win
);
156 black
= GP_ColorToContextPixel(GP_COL_BLACK
, win
);
159 GP_BackendFlip(backend
);
162 GP_BackendWait(backend
);