main.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include "u8g2.h"
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. u8g2_t u8g2;
  6. int screenshot_n = 0;
  7. void do_screenshot(void)
  8. {
  9. char s[4096];
  10. u8x8_SaveBitmapTGA(u8g2_GetU8x8(&u8g2), "screenshot.tga");
  11. sprintf( s,
  12. "convert -border 4 -bordercolor 'rgb(255,190,40)'"
  13. " -fill 'rgb(255,170,0)' -opaque white"
  14. " -filter point -resize 200%%"
  15. " screenshot.tga pic%04d.png", screenshot_n);
  16. system(s);
  17. screenshot_n++;
  18. /*
  19. gif animation:
  20. convert -delay 40 -loop 0 pic*.png animation.gif
  21. */
  22. }
  23. static const unsigned char teststr[] U8X8_PROGMEM = {
  24. 0x09, 0x28, 0x00, 0x00, // u8g2_DrawGlyph(&u8g2, 0, 0, 2344);
  25. 0x09, 0x2e, 0x10, 0x00, // u8g2_DrawGlyph(&u8g2, 16, 0, 2350);
  26. 0x09, 0x38, 0x10, 0x00, // u8g2_DrawGlyph(&u8g2, 32, 0, 2360);
  27. 0x09, 0x4d, 0x00, 0x00, // u8g2_DrawGlyph(&u8g2, 32, 0, 2381);
  28. 0x09, 0x24, 0x10, 0x00, // u8g2_DrawGlyph(&u8g2, 48, 0, 2340);
  29. 0x09, 0x47, 0x00, 0x00, // u8g2_DrawGlyph(&u8g2, 48, 0, 2375);
  30. 0x00, 0x00 // end of binary
  31. };
  32. static const unsigned char testarabic[] U8X8_PROGMEM = {
  33. 0x06, 0x27, 0x00, 0x00, // u8g2_DrawGlyph(&u8g2, 0, 0, 1575);
  34. 0x06, 0x28, 0x08, 0x00, // u8g2_DrawGlyph(&u8g2, 8, 0, 1576);
  35. 0x06, 0x4b, 0x00, 0x00, // u8g2_DrawGlyph(&u8g2, 8, 0, 1611);
  36. 0x06, 0x2d, 0x08, 0x00, // u8g2_DrawGlyph(&u8g2, 16, 0, 1581);
  37. 0x06, 0x31, 0x08, 0x00, // u8g2_DrawGlyph(&u8g2, 24, 0, 1585);
  38. 0x06, 0x45, 0x08, 0x00, // u8g2_DrawGlyph(&u8g2, 32, 0, 1605);
  39. 0x00, 0x00 // end of binary
  40. };
  41. int main(void)
  42. {
  43. int x, y;
  44. int k;
  45. int offset = 100;
  46. u8g2_SetupBuffer_SDL_128x64_4(&u8g2, &u8g2_cb_r0);
  47. u8x8_InitDisplay(u8g2_GetU8x8(&u8g2));
  48. u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0);
  49. u8x8_ConnectBitmapToU8x8(u8g2_GetU8x8(&u8g2)); /* connect to bitmap */
  50. x = 4; // use as height for the box
  51. y = 20;
  52. for(;;)
  53. {
  54. u8g2_FirstPage(&u8g2);
  55. do
  56. {
  57. u8g2_SetFont(&u8g2, u8g2_font_unifont_t_devanagari);
  58. u8g2_SetFontDirection(&u8g2, 0);
  59. u8g2_SetFontMode(&u8g2, 1);
  60. u8g2_DrawHB(&u8g2, x, y, teststr);
  61. u8g2_SetFont(&u8g2, u8g2_font_unifont_t_arabic);
  62. u8g2_DrawHB(&u8g2, x, y+16, testarabic);
  63. } while( u8g2_NextPage(&u8g2) );
  64. do
  65. {
  66. k = u8g_sdl_get_key();
  67. } while( k < 0 );
  68. if ( k == 273 ) y -= 1;
  69. if ( k == 274 ) y += 1;
  70. if ( k == 276 ) x -= 1;
  71. if ( k == 275 ) x += 1;
  72. if ( k == 'e' ) y -= 1;
  73. if ( k == 'x' ) y += 1;
  74. if ( k == 's' ) x -= 1;
  75. if ( k == 'd' ) x += 1;
  76. if ( k == 'q' ) break;
  77. if ( k == 32 )
  78. offset -= 1;
  79. if ( k == 't' )
  80. {
  81. puts("screenshot");
  82. do_screenshot();
  83. }
  84. if ( x < 0 )
  85. x = 0;
  86. }
  87. return 0;
  88. }