main.c 2.4 KB

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