juegos

Juegos de terminal de Pancho: Catan (TUI, GUI, web, servidor, PicoCalc), ajedrez, calculadora y minijuegos
git clone https://git.lu3dhn.xyz/juegos.git
Log | Files | Refs

gui_sdl.c (1777B)


      1 /* gui_sdl.c - interfaz grafica con SDL3 (ventana de comun/linux/guikit). */
      2 #include <stdlib.h>
      3 #include <string.h>
      4 #ifdef __EMSCRIPTEN__
      5 #include <emscripten.h>
      6 #endif
      7 #include "frontend.h"
      8 #include "guikit.h"
      9 
     10 static Surface *surf;
     11 
     12 static void gui_draw_game(Frontend *f, const Game *gm, const Ctrl *c, const UiInfo *ui)
     13 {
     14     gfx_screen(surf, gm, c, ui, &f->hits, &f->geom);
     15     f->board_ox = 0;
     16     f->board_oy = 0;
     17     f->board_sy = 1;
     18     gk_present();
     19 }
     20 
     21 static void gui_draw_form(Frontend *f, const Form *form)
     22 {
     23     gfx_form(surf, form, &f->hits);
     24     gk_present();
     25 }
     26 
     27 static int gui_wait(Frontend *f, int timeout_ms, const int *fds, int nfds, InEvent *ev)
     28 {
     29     (void)f;
     30     (void)fds;
     31     return gk_wait(timeout_ms, nfds, ev);
     32 }
     33 
     34 static void gui_close(Frontend *f)
     35 {
     36     (void)f;
     37     gk_close();
     38 }
     39 
     40 static int gui_text_input(Frontend *f, const char *title, char *buf, int n)
     41 {
     42     (void)f;
     43     return gk_text_input(title, buf, n);
     44 }
     45 
     46 Frontend *gui_open(int layout, int scale)
     47 {
     48     static Frontend fe;
     49     /* el ancho sigue a la ventana (sin bordes); el compacto imita la PicoCalc tal cual */
     50     surf = layout == LAYOUT_COMPACT ? gk_open("Catan", 320, 320, scale) : gk_open_fluid("Catan", 640, 360);
     51     if (!surf) return NULL;
     52     gfx_form_backdrop = catan_form_backdrop;
     53     memset(&fe, 0, sizeof fe);
     54     fe.draw_game = gui_draw_game;
     55     fe.draw_form = gui_draw_form;
     56     fe.wait = gui_wait;
     57     fe.close = gui_close;
     58     fe.text_input = gui_text_input;
     59     fe.is_gui = true;
     60 #ifdef __EMSCRIPTEN__
     61     fe.touch = EM_ASM_INT({ return navigator.maxTouchPoints > 0 ? 1 : 0; });   /* telefono/tablet si, PC no */
     62 #else
     63     fe.touch = getenv("APP_TOUCH") != NULL;   /* para probar los botones tactiles en la PC */
     64 #endif
     65     gfx_touch = fe.touch;
     66     return &fe;
     67 }