No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

text.c 991B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "font.h"
  2. #include "odroid/display.h"
  3. #include "text.h"
  4. static const int MAX_GLYPHS_PER_ROW = LCD_WIDTH / GLYPH_WIDTH;
  5. static const int MAX_GLYPHS_PER_COL = LCD_HEIGHT / GLYPH_HEIGHT;
  6. void DrawText(uint16_t* framebuffer, char* string, int length, int x, int y, uint16_t color)
  7. {
  8. assert(x + length <= MAX_GLYPHS_PER_ROW);
  9. assert(y <= MAX_GLYPHS_PER_COL);
  10. for (int charIndex = 0; charIndex < length; ++charIndex)
  11. {
  12. char c = string[charIndex];
  13. if (c == ' ')
  14. {
  15. continue;
  16. }
  17. int xStart = GLYPH_WIDTH * (x + charIndex);
  18. int yStart = GLYPH_HEIGHT * y;
  19. for (int row = 0; row < GLYPH_HEIGHT; ++row)
  20. {
  21. for (int col = 0; col < GLYPH_WIDTH; ++col)
  22. {
  23. int bitPosition = 1U << (15U - col);
  24. int glyphIndex = GetGlyphIndex(c);
  25. uint16_t pixel = glyphMap[glyphIndex][row] & bitPosition;
  26. if (pixel)
  27. {
  28. int screenX = xStart + col;
  29. int screenY = yStart + row;
  30. framebuffer[screenY * LCD_WIDTH + screenX] = color;
  31. }
  32. }
  33. }
  34. }
  35. }