display_ch.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef __DISPLAY_CH_H_
  2. #define __DISPLAY_CH_H_
  3. #include <M5Stack.h>
  4. #include "Fonts/HZK16.h"
  5. #include "Fonts/ASC16.h"
  6. typedef enum
  7. {
  8. DontUsedHzk16,
  9. InternalHzk16,
  10. ExternalHzk16
  11. }Hzk16Types;
  12. class DisplayCh {
  13. public:
  14. DisplayCh();
  15. /**************************************************************************
  16. **
  17. ** GBK character support
  18. **
  19. **************************************************************************/
  20. void loadHzk16(Hzk16Types hzkTypes = InternalHzk16,const char* HZK16Path = "/HZK16", const char* ASC16Path = "/ASC16");
  21. void disableHzk16();
  22. void setTextColor(uint16_t c);
  23. void setTextColor(uint16_t c, uint16_t b);
  24. void setCursor(int16_t x, int16_t y);
  25. void setCursor(int16_t x, int16_t y, uint8_t font);
  26. void setTextSize(uint8_t size);
  27. void fillScreen(uint32_t color);
  28. // Highlight the text (Once set to be true, the text background will not be transparent any more)
  29. inline void highlight(bool isHighlight) { highlighted = isHighlight; }
  30. // Set highlight color
  31. inline void setHighlightColor(uint16_t color) { highlightcolor = color; istransparent = false; }
  32. void writeHzk(char* c);
  33. private:
  34. inline void setTransparentBgColor(bool isTransparent) { istransparent = isTransparent; }
  35. inline bool isTransparentBg(){return istransparent;}
  36. bool initHzk16(boolean use, const char* HZK16Path = nullptr, const char* ASC16Path = nullptr);
  37. inline bool isHzk16Used(){return hzk16Used;}
  38. void setTextWrap(boolean wrap);
  39. void writeHzkAsc(const char c);
  40. void writeHzkGbk(const char* c);
  41. private:
  42. uint8_t hzkBufCount,hzkBuf[2];
  43. boolean hzk16Used,istransparent,
  44. highlighted;
  45. Hzk16Types hzk16Type; // Use of HZK16 and ASC16 font.
  46. File
  47. Asc16File, Hzk16File, // Font file
  48. *pAsc16File, *pHzk16File; // Font file pointer
  49. uint8_t *pAscCharMatrix, *pGbkCharMatrix;
  50. uint16_t
  51. highlightcolor,
  52. ascCharWidth,
  53. ascCharHeigth,
  54. gbkCharWidth,
  55. gbkCharHeight;
  56. uint32_t textcolor,textbgcolor;
  57. int32_t cursor_x, cursor_y;
  58. uint8_t textfont,textsize;
  59. uint32_t _width, _height; // Display w/h as modified by current rotation
  60. boolean textwrap; // If set, 'wrap' text at right edge of display
  61. };
  62. #endif