123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- /*
- * src/events.c
- * https://gitlab.com/bztsrc/smgui
- *
- * Copyright (C) 2024 bzt (bztsrc@gitlab), MIT license
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY
- * DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
- * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * @brief State-Mode GUI events demo program
- */
- #define UI_IMPLEMENTATION
- #include <ui.h>
- int main(int argc, char **argv)
- {
- /* strings are gathered into an array so that you can change the language on-the-fly */
- char *lang[] = { "Events demo", "Events will be printed to stdout" };
- ui_event_t *evt;
- ui_t ctx;
- ui_form_t form[] = {
- { .type = UI_LABEL, .x = 5, .y = 5, .label = 1 },
- { .type = UI_END }
- };
- /* initialize the UI context, pass it the string array, the window size and icon */
- ui_init(&ctx, 2, lang, 640, 480, NULL);
- /* wait until user closes the window */
- while((evt = ui_event(&ctx, form))) {
- /* if Esc is pressed, exit (should be '\e', but not all C compiler likes that) */
- if(evt->type == UI_EVT_KEY && evt->key[0] == 0x1b) break;
- /* print event to stdout */
- switch(evt->type) {
- case UI_EVT_MOUSE:
- printf("mouse btn=%06x x=%d y=%d\n", evt->btn, evt->x, evt->y);
- break;
- case UI_EVT_GAMEPAD:
- printf("gamepad btn=%06x x=%d y=%d rx=%d ry=%d key=%d\n", evt->btn, evt->x, evt->y, evt->rx, evt->ry, evt->key[0]);
- break;
- case UI_EVT_KEY:
- printf("key btn=%06x key='%s'\n", evt->btn, evt->key);
- break;
- case UI_EVT_DROP:
- printf("drop btn=%06x x=%d y=%d fn='%s'\n", evt->btn, evt->x, evt->y, evt->fn);
- break;
- case UI_EVT_RESIZE:
- printf("resize x=%d y=%d\n", evt->x, evt->y);
- break;
- }
- }
- /* destroy window, free resources */
- ui_free(&ctx);
- (void)argc; (void)argv;
- return 0;
- }
|