1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- /*
- * src/ssfn.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 Scalable Screen Font demo program
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <ui_ssfn.h>
- #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 */
- enum { WINDOW_TITLE, HELLO_WORLD };
- char *english[] = { "Window title", "Hello World!" };
- ui_t ctx; /* the main context */
- ui_form_t form[2] = { /* your layout */
- { .type = UI_LABEL, .align = UI_CENTER, .x = UI_PERCENT(50), .y = 100, .label = HELLO_WORLD },
- { .type = UI_END }
- };
- /* load font */
- ssfn_t fnt = { 0 };
- FILE *f;
- uint8_t *fntbuf;
- int fntsize = 0;
- if(argc < 2) { fprintf(stderr, "ssfn <font.sfn>\n"); return 1; }
- if((f = fopen(argv[1], "rb"))) {
- fseek(f, 0, SEEK_END); fntsize = (int)ftell(f); fseek(f, 0, SEEK_SET);
- if(!(fntbuf = malloc(fntsize))) { fclose(f); fprintf(stderr, "unable to allocate memory\n"); return 1; }
- fread(fntbuf, 1, fntsize, f); fclose(f);
- } else { fprintf(stderr, "unable to load font\n"); return 1; }
- /* set up SSFN context */
- ssfn_load(&fnt, fntbuf);
- ssfn_select(&fnt, SSFN_FAMILY_ANY, NULL, SSFN_STYLE_REGULAR, 16);
- /* initialize the UI context, pass it the string array, the window size and icon */
- ui_init(&ctx, 2, english, 640, 480, NULL);
- /* set SSFN font context in SMGUI */
- ui_font(&ctx, &fnt);
- /* wait until user closes the window */
- while(ui_event(&ctx, form)) { }
- /* destroy window, free resources */
- ui_free(&ctx);
- ssfn_free(&fnt);
- free(fntbuf);
- return 0;
- }
|