gui.c (1073B)
1 /* gui.c - la calculadora en una ventana SDL (misma pantalla que la PicoCalc). */ 2 #include <stdio.h> 3 #include <stdlib.h> 4 #include <string.h> 5 #include "guikit.h" 6 #include "paths.h" 7 #include "calc_gfx.h" 8 #include "store.h" 9 10 int gui_run(Calc *c, int scale) 11 { 12 Surface *s = gk_open("Calculadora", 320, 320, scale); 13 if (!s) { fprintf(stderr, "no se pudo abrir la ventana\n"); return 1; } 14 bool dirty = true; 15 for (;;) { 16 if (dirty) { 17 calc_prepare(c, -1); 18 gfx_noclip(s); 19 calc_paint(s, c); 20 gk_present(); 21 dirty = false; 22 } 23 InEvent ev; 24 if (!gk_wait(1000, 0, &ev)) continue; 25 if (ev.type == EV_QUIT) break; 26 if (ev.type == EV_RESIZE) { dirty = true; continue; } 27 if (ev.type != EV_KEY) continue; 28 int k = ev.key; 29 if ((k == K_UP || k == K_DOWN) && calc_vert_px(c, k == K_UP ? -1 : 1)) dirty = true; 30 else if (calc_key(c, k)) dirty = true; 31 if (c->dirty_save) store_save(c); 32 } 33 store_save(c); 34 gk_close(); 35 return 0; 36 }