main.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #include "u8g2.h"
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include "mui.h"
  6. #include "mui_u8g2.h"
  7. /*=================================================*/
  8. /* global variables */
  9. u8g2_t u8g2;
  10. mui_t ui;
  11. muif_t muif_list[] MUI_PROGMEM = {
  12. MUIF_LABEL(mui_u8g2_draw_text)
  13. };
  14. fds_t fds[] MUI_PROGMEM =
  15. MUI_FORM(1)
  16. MUI_LABEL(5,12, "A label")
  17. ;
  18. int screenshot_n = 0;
  19. void do_screenshot(void)
  20. {
  21. char s[4096];
  22. u8x8_SaveBitmapTGA(u8g2_GetU8x8(&u8g2), "screenshot.tga");
  23. sprintf( s,
  24. "convert -border 4 -bordercolor 'rgb(255,190,40)'"
  25. " -fill 'rgb(255,170,0)' -opaque white"
  26. " -filter point -resize 200%%"
  27. " screenshot.tga pic%04d.png", screenshot_n);
  28. system(s);
  29. screenshot_n++;
  30. /*
  31. gif animation:
  32. convert -delay 40 -loop 0 pic*.png animation.gif
  33. */
  34. }
  35. int main(void)
  36. {
  37. int x, y;
  38. int k;
  39. u8g2_SetupBuffer_SDL_128x64_4(&u8g2, &u8g2_cb_r0);
  40. u8x8_InitDisplay(u8g2_GetU8x8(&u8g2));
  41. u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0);
  42. u8x8_ConnectBitmapToU8x8(u8g2_GetU8x8(&u8g2)); /* connect to bitmap */
  43. u8g2_SetFont(&u8g2, u8g2_font_6x10_tr);
  44. u8g2_SetFontMode(&u8g2, 1);
  45. mui_Init(&ui, &u8g2, fds, muif_list, sizeof(muif_list)/sizeof(muif_t));
  46. mui_GotoForm(&ui, 1, 0);
  47. x = 4; // use as height for the box
  48. y = 0;
  49. for(;;)
  50. {
  51. u8g2_SetFontRefHeightExtendedText(&u8g2);
  52. u8g2_FirstPage(&u8g2);
  53. do
  54. {
  55. mui_Draw(&ui);
  56. } while( u8g2_NextPage(&u8g2) );
  57. do_screenshot();
  58. // printf("mui_GetCurrentCursorFocusPosition=%d\n", mui_GetCurrentCursorFocusPosition(&ui));
  59. do
  60. {
  61. k = u8g_sdl_get_key();
  62. } while( k < 0 );
  63. if ( k == 273 ) y -= 1;
  64. if ( k == 274 ) y += 1;
  65. if ( k == 276 ) x -= 1;
  66. if ( k == 275 ) x += 1;
  67. /*
  68. if ( k == 'e' ) y -= 1;
  69. if ( k == 'x' ) y += 1;
  70. if ( k == 's' ) x -= 1;
  71. if ( k == 'd' ) x += 1;
  72. */
  73. if ( k == 'q' ) break;
  74. if ( k == 'n' )
  75. {
  76. mui_NextField(&ui);
  77. }
  78. if ( k == 'p' )
  79. {
  80. mui_PrevField(&ui);
  81. }
  82. if ( k == 's' )
  83. {
  84. mui_SendSelect(&ui);
  85. }
  86. if ( k == 't' )
  87. {
  88. puts("screenshot");
  89. do_screenshot();
  90. }
  91. if ( x < 0 )
  92. x = 0;
  93. }
  94. return 0;
  95. }