main.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #include "u8g2.h"
  2. #include <stdio.h>
  3. #include <string.h>
  4. char str1[100];
  5. char str2[100];
  6. u8g2_t u8g2;
  7. int screenshot_n = 0;
  8. void do_screenshot(void)
  9. {
  10. char s[4096];
  11. u8x8_SaveBitmapTGA(u8g2_GetU8x8(&u8g2), "screenshot.tga");
  12. sprintf( s,
  13. "convert -border 4 -bordercolor 'rgb(255,190,40)'"
  14. " -fill 'rgb(255,170,0)' -opaque white"
  15. " -filter point -resize 200%%"
  16. " screenshot.tga pic%04d.png", screenshot_n);
  17. system(s);
  18. screenshot_n++;
  19. /*
  20. gif animation:
  21. convert -delay 40 -loop 0 pic*.png animation.gif
  22. */
  23. }
  24. int main(void)
  25. {
  26. int x, y;
  27. int k;
  28. int offset = 100;
  29. u8g2_SetupBuffer_SDL_128x64_4(&u8g2, &u8g2_cb_r0);
  30. u8x8_InitDisplay(u8g2_GetU8x8(&u8g2));
  31. u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0);
  32. u8x8_ConnectBitmapToU8x8(u8g2_GetU8x8(&u8g2)); /* connect to bitmap */
  33. x = 4; // use as height for the box
  34. y = 0;
  35. for(;;)
  36. {
  37. //printf("offset=%d\n", offset);
  38. u8g2_FirstPage(&u8g2);
  39. do
  40. {
  41. u8g2_SetDrawColor(&u8g2, 1);
  42. u8g2_SetFont(&u8g2, u8g2_font_helvB08_tf);
  43. u8g2_DrawUTF8(&u8g2, x,10+y,"ABC helvB08");
  44. u8g2_DrawButtonUTF8(&u8g2, x+76, 10+y, U8G2_BTN_BW1, 0, /* padding_h*/ 0, /* padding_v */0, "AB");
  45. u8g2_DrawButtonUTF8(&u8g2, x+95, 10+y, U8G2_BTN_BW1, 0, /* padding_h*/ 1, /* padding_v */0, "AB");
  46. u8g2_SetFont(&u8g2, u8g2_font_ncenB08_te);
  47. u8g2_DrawUTF8(&u8g2, x,25+y,"ABC ncenB08");
  48. u8g2_DrawButtonUTF8(&u8g2, x+76, 25+y, U8G2_BTN_BW1, 0, /* padding_h*/ 0, /* padding_v */0, "AB");
  49. u8g2_DrawButtonUTF8(&u8g2, x+95, 25+y, U8G2_BTN_BW1, 0, /* padding_h*/ 1, /* padding_v */0, "AB");
  50. printf("ncenB08 A xoffset=%d\n", (int8_t)u8g2_GetXOffsetGlyph(&u8g2, 'A'));
  51. u8g2_SetFont(&u8g2, u8g2_font_helvR08_te);
  52. u8g2_DrawUTF8(&u8g2, x,40+y,"ĈD helvR08");
  53. u8g2_DrawButtonUTF8(&u8g2, x+76, 40+y, U8G2_BTN_BW1, 0, /* padding_h*/ 0, /* padding_v */0, "ĈD");
  54. u8g2_DrawButtonUTF8(&u8g2, x+95, 40+y, U8G2_BTN_BW1, 0, /* padding_h*/ 1, /* padding_v */0, "ĈD");
  55. printf("helvR08 C xoffset=%d\n", (int8_t)u8g2_GetXOffsetGlyph(&u8g2, 'C'));
  56. printf("helvR08 Ĉ xoffset=%d\n", (int8_t)u8g2_GetXOffsetUTF8(&u8g2, "Ĉ"));
  57. printf("helvR08 Ĉ xoffset=%d\n", (int8_t)u8g2_GetStrX(&u8g2, "Ĉ"));
  58. u8g2_SetFont(&u8g2, u8g2_font_ncenR08_tf);
  59. u8g2_DrawUTF8(&u8g2, x,55+y,"CD ncenR08");
  60. u8g2_DrawButtonUTF8(&u8g2, x+76, 55+y, U8G2_BTN_BW1, 0, /* padding_h*/ 0, /* padding_v */0, "CD");
  61. u8g2_DrawButtonUTF8(&u8g2, x+95, 55+y, U8G2_BTN_BW1, 0, /* padding_h*/ 1, /* padding_v */0, "CD");
  62. /*
  63. u8g2_SetFont(&u8g2, u8g2_font_helvR08_tf);
  64. u8g2_DrawUTF8(&u8g2, x,30+y,"ABC helvR08");
  65. u8g2_SetFont(&u8g2, u8g2_font_ncenR08_tf);
  66. u8g2_DrawUTF8(&u8g2, x,40+y,"ABC ncenR08");
  67. u8g2_SetFont(&u8g2, u8g2_font_5x8_tf);
  68. u8g2_DrawUTF8(&u8g2, x,50+y,"ABC 5x8");
  69. u8g2_SetFont(&u8g2, u8g2_font_6x10_tf);
  70. u8g2_DrawUTF8(&u8g2, x,60+y,"ABC 6x10");
  71. u8g2_SetFont(&u8g2, u8g2_font_mozart_nbp_tf);
  72. u8g2_DrawUTF8(&u8g2, x,70+y,"ABC mozart_nbp");
  73. u8g2_SetFont(&u8g2, u8g2_font_profont12_tf);
  74. u8g2_DrawUTF8(&u8g2, x,80+y,"ABC profont12");
  75. u8g2_SetFont(&u8g2, u8g2_font_simple1_tf);
  76. u8g2_DrawUTF8(&u8g2, x,90+y,"ABC simple1");
  77. u8g2_SetFont(&u8g2, u8g2_font_princess_te);
  78. u8g2_DrawUTF8(&u8g2, x,100+y,"ABC princess");
  79. */
  80. u8g2_SetDrawColor(&u8g2, 2);
  81. u8g2_DrawVLine(&u8g2, x, 0, 64);
  82. //u8g2_DrawLine(&u8g2, 30, 10, 30, 100);
  83. } while( u8g2_NextPage(&u8g2) );
  84. do
  85. {
  86. k = u8g_sdl_get_key();
  87. } while( k < 0 );
  88. if ( k == 273 ) y -= 1;
  89. if ( k == 274 ) y += 1;
  90. if ( k == 276 ) x -= 1;
  91. if ( k == 275 ) x += 1;
  92. if ( k == 'e' ) y -= 1;
  93. if ( k == 'x' ) y += 1;
  94. if ( k == 's' ) x -= 1;
  95. if ( k == 'd' ) x += 1;
  96. if ( k == 'q' ) break;
  97. if ( k == 32 )
  98. offset -= 1;
  99. if ( k == 't' )
  100. {
  101. puts("screenshot");
  102. do_screenshot();
  103. }
  104. if ( x < 0 )
  105. x = 0;
  106. }
  107. return 0;
  108. }