123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- /*
- * src/multiwin.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 multiple window demo program
- */
- /* GLFW uses a hidden global state. So to support multiple windows, we have to initialize and terminate outself once
- * SMGUI itself doesn't care how many contexts there are */
- #define UI_BACKEND_INITIALIZED
- #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[] = { "Multiple windows demo" };
- /* variables to store game states */
- int win_closed = 0;
- /* form referencing those variables */
- ui_event_t *evt;
- ui_t ctx1, ctx2, ctx3;
- ui_form_t form[1] = { { .type = UI_END } };
- /* GLFW uses a hidden global state. So to support multiple windows, we have to initialize and terminate outself once */
- glfwInit();
- /* open multiple windows */
- ui_init(&ctx1, 1, lang, 640, 480, NULL);
- ui_init(&ctx2, 1, lang, 640, 480, NULL);
- ui_init(&ctx3, 1, lang, 640, 480, NULL);
- while(win_closed < 7) {
- /* if first window isn't closed yet, get events, and if user clicked X or Escape pressed, close it */
- if(!(win_closed & 1) && (!(evt = ui_event(&ctx1, form)) || (evt->type == UI_EVT_KEY && evt->key[0] == 0x1b))) {
- ui_free(&ctx1);
- win_closed |= 1;
- }
- /* if second window isn't closed yet, get events, and if user clicked X or Escape pressed, close it */
- if(!(win_closed & 2) && (!(evt = ui_event(&ctx2, form)) || (evt->type == UI_EVT_KEY && evt->key[0] == 0x1b))) {
- ui_free(&ctx2);
- win_closed |= 2;
- }
- /* if third window isn't closed yet, get events, and if user clicked X or Escape pressed, close it */
- if(!(win_closed & 4) && (!(evt = ui_event(&ctx3, form)) || (evt->type == UI_EVT_KEY && evt->key[0] == 0x1b))) {
- ui_free(&ctx3);
- win_closed |= 4;
- }
- }
- /* GLFW uses a hidden global state. So to support multiple windows, we have to initialize and terminate outself once */
- glfwTerminate();
- (void)argc; (void)argv;
- return 0;
- }
|