123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- /*
- * src/draw.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 line draw demo program
- */
- #define UI_IMPLEMENTATION
- #include <ui.h>
- int16_t lines[1024] = { 0 };
- int main(int argc, char **argv)
- {
- int x, y, lx = -1, ly = -1, btn = 0;
- char *lang[] = { "Line demo" };
- ui_event_t *evt;
- ui_t ctx;
- ui_form_t form[2] = {
- { .type = UI_LINES, .ptr = lines },
- { .type = UI_END }
- };
- (void)argc; (void)argv;
- ui_init(&ctx, 1, lang, 640, 480, NULL);
- /* wait until user closes the window */
- while((evt = ui_event(&ctx, form))) {
- /* exit on Esc */
- if(evt->type == UI_EVT_KEY && evt->key[0] == 0x1b) break;
- /* save left button pressed state */
- if(evt->type == UI_EVT_MOUSE) btn = evt->btn & UI_BTN_L;
- /* save new coordinate */
- ui_getmouse(&ctx, &x, &y);
- if(btn && x != lx && y != ly) {
- memmove(&lines[2], &lines[0], sizeof(lines) - 4 * sizeof(lines[0]));
- lines[0] = lx = x;
- lines[1] = ly = y;
- /* set color to foreground color */
- form[0].value = ctx.theme[UI_FG];
- /* let the UI know that it needs to redraw */
- ui_refresh(&ctx);
- }
- }
- ui_free(&ctx);
- return 0;
- }
|