GUI_Paint.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /******************************************************************************
  2. * | File : GUI_Paint.h
  3. * | Author : Waveshare electronics
  4. * | Function : Achieve drawing: draw points, lines, boxes, circles and
  5. * their size, solid dotted line, solid rectangle hollow
  6. * rectangle, solid circle hollow circle.
  7. * | Info :
  8. * Achieve display characters: Display a single character, string, number
  9. * Achieve time display: adaptive size display time minutes and seconds
  10. *----------------
  11. * | This version: V3.0
  12. * | Date : 2019-04-18
  13. * | Info :
  14. * -----------------------------------------------------------------------------
  15. * V3.0(2019-04-18):
  16. * 1.Change:
  17. * Paint_DrawPoint(..., DOT_STYLE DOT_STYLE)
  18. * => Paint_DrawPoint(..., DOT_STYLE Dot_Style)
  19. * Paint_DrawLine(..., LINE_STYLE Line_Style, DOT_PIXEL Dot_Pixel)
  20. * => Paint_DrawLine(..., DOT_PIXEL Line_width, LINE_STYLE Line_Style)
  21. * Paint_DrawRectangle(..., DRAW_FILL Filled, DOT_PIXEL Dot_Pixel)
  22. * => Paint_DrawRectangle(..., DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
  23. * Paint_DrawCircle(..., DRAW_FILL Draw_Fill, DOT_PIXEL Dot_Pixel)
  24. * => Paint_DrawCircle(..., DOT_PIXEL Line_width, DRAW_FILL Draw_Filll)
  25. *
  26. * -----------------------------------------------------------------------------
  27. * V2.0(2018-11-15):
  28. * 1.add: Paint_NewImage()
  29. * Create an image's properties
  30. * 2.add: Paint_SelectImage()
  31. * Select the picture to be drawn
  32. * 3.add: Paint_SetRotate()
  33. * Set the direction of the cache
  34. * 4.add: Paint_RotateImage()
  35. * Can flip the picture, Support 0-360 degrees,
  36. * but only 90.180.270 rotation is better
  37. * 4.add: Paint_SetMirroring()
  38. * Can Mirroring the picture, horizontal, vertical, origin
  39. * 5.add: Paint_DrawString_CN()
  40. * Can display Chinese(GB1312)
  41. *
  42. * -----------------------------------------------------------------------------
  43. * V1.0(2018-07-17):
  44. * Create library
  45. *
  46. * Permission is hereby granted, free of charge, to any person obtaining a copy
  47. * of this software and associated documnetation files (the "Software"), to deal
  48. * in the Software without restriction, including without limitation the rights
  49. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  50. * copies of the Software, and to permit persons to whom the Software is
  51. * furished to do so, subject to the following conditions:
  52. *
  53. * The above copyright notice and this permission notice shall be included in
  54. * all copies or substantial portions of the Software.
  55. *
  56. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  57. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  58. * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  59. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  60. * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  61. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  62. * THE SOFTWARE.
  63. *
  64. ******************************************************************************/
  65. #ifndef __GUI_PAINT_H
  66. #define __GUI_PAINT_H
  67. #include "esp_log.h"
  68. #define UBYTE uint8_t
  69. #define UWORD uint16_t
  70. #define UDOUBLE uint32_t
  71. //whc set start
  72. // extern const unsigned char gImage_right[38880];
  73. // extern const unsigned char gImage_mid[38880];
  74. // extern const unsigned char gImage_left[38880];
  75. // extern const unsigned char gImage_baoyang[600];
  76. // extern const unsigned char gImage_yunxing[600];
  77. // extern const unsigned char gImage_tingji[600];
  78. // extern const unsigned char gImage_dailiao[600];
  79. // extern const unsigned char gImage_guzhang[600];
  80. // extern const unsigned char gImage_fengcun[600];
  81. //extern const unsigned char gImage_in_battery[16];
  82. extern const unsigned char gImage_none_people[75];
  83. extern const unsigned char gImage_people[75];
  84. extern const unsigned char gImage_no_sound[72];
  85. extern const unsigned char gImage_sound[72];
  86. extern const unsigned char gImage_battery[90];
  87. extern const unsigned char gImage_right_[15360];
  88. extern const unsigned char gImage_mid_[15360];
  89. extern const unsigned char gImage_left_[15360];
  90. extern const unsigned char gImage_button[576];
  91. extern const unsigned char gImage_button_128x64[1024];
  92. extern const unsigned char gImage_nfc[264];
  93. extern const unsigned char gImage_bat_ing[90];
  94. extern const unsigned char gImage_charging[18];
  95. extern const unsigned char gImage_filled[18];
  96. extern const unsigned char gImage_left_instructions[38880];
  97. extern const unsigned char gImage_right_instruction[38880];
  98. extern const unsigned char gImage_low_batt[8162];
  99. extern const unsigned char gImage_online[90];
  100. typedef struct _font_type_t
  101. {
  102. char *font_type_name;
  103. uint16_t Font_lib_type;
  104. uint16_t Font_Width;
  105. uint16_t Font_Height;
  106. }FONT_TYPE_T;
  107. //whc set end
  108. typedef struct _tFont
  109. {
  110. uint8_t *table;
  111. uint16_t Width;
  112. uint16_t Height;
  113. uint8_t font_size;
  114. uint16_t font_num;
  115. } sFONT;
  116. //#define LOG_TAG "GUI_PAINT"
  117. #define Debug(INFO, ... ) ESP_LOGD("GUI_PAINT", INFO, ##__VA_ARGS__)
  118. /**
  119. * Image attributes
  120. **/
  121. typedef struct {
  122. UBYTE *Image;
  123. UWORD Width;
  124. UWORD Height;
  125. UWORD WidthMemory;
  126. UWORD HeightMemory;
  127. UWORD Color;
  128. UWORD Rotate;
  129. UWORD Mirror;
  130. UWORD WidthByte;
  131. UWORD HeightByte;
  132. UWORD Scale;
  133. } PAINT;
  134. extern PAINT Paint_info;
  135. // extern PAINT Paint_left_info;
  136. // extern PAINT Paint_right_info;
  137. /**
  138. * Display rotate
  139. **/
  140. #define ROTATE_0 0
  141. #define ROTATE_90 90
  142. #define ROTATE_180 180
  143. #define ROTATE_270 270
  144. /**
  145. * Display Flip
  146. **/
  147. typedef enum {
  148. MIRROR_NONE = 0x00,
  149. MIRROR_HORIZONTAL = 0x01,
  150. MIRROR_VERTICAL = 0x02,
  151. MIRROR_ORIGIN = 0x03,
  152. } MIRROR_IMAGE;
  153. #define MIRROR_IMAGE_DFT MIRROR_NONE
  154. /**
  155. * image color
  156. **/
  157. #define WHITE 0x00
  158. #define BLACK 0xff
  159. #define RED BLACK
  160. //
  161. #define FONT_FOREGROUND BLACK
  162. #define FONT_BACKGROUND WHITE
  163. #define IMAGE_BACKGROUND WHITE
  164. #define PAINT_FOREGROUND BLACK
  165. #define PAINT_BACKGROUND WHITE
  166. #define TRUE 1
  167. #define FALSE 0
  168. //4 Gray level
  169. #define GRAY1 0x03 //Blackest
  170. #define GRAY2 0x02
  171. #define GRAY3 0x01 //gray
  172. #define GRAY4 0x00 //white
  173. /**
  174. * The size of the point
  175. **/
  176. typedef enum {
  177. DOT_PIXEL_1X1 = 1, // 1 x 1
  178. DOT_PIXEL_2X2 , // 2 X 2
  179. DOT_PIXEL_3X3 , // 3 X 3
  180. DOT_PIXEL_4X4 , // 4 X 4
  181. DOT_PIXEL_5X5 , // 5 X 5
  182. DOT_PIXEL_6X6 , // 6 X 6
  183. DOT_PIXEL_7X7 , // 7 X 7
  184. DOT_PIXEL_8X8 , // 8 X 8
  185. } DOT_PIXEL;
  186. #define DOT_PIXEL_DFT DOT_PIXEL_1X1 //Default dot pilex
  187. /**
  188. * Point size fill style
  189. **/
  190. typedef enum {
  191. DOT_FILL_AROUND = 1, // dot pixel 1 x 1
  192. DOT_FILL_RIGHTUP , // dot pixel 2 X 2
  193. } DOT_STYLE;
  194. #define DOT_STYLE_DFT DOT_FILL_AROUND //Default dot pilex
  195. /**
  196. * Line style, solid or dashed
  197. **/
  198. typedef enum {
  199. LINE_STYLE_SOLID = 0,
  200. LINE_STYLE_DOTTED,
  201. LINE_STYLE_DOTTED_2,
  202. } LINE_STYLE;
  203. /**
  204. * Whether the graphic is filled
  205. **/
  206. typedef enum {
  207. DRAW_FILL_EMPTY = 0,
  208. DRAW_FILL_FULL,
  209. } DRAW_FILL;
  210. /**
  211. * Custom structure of a time attribute
  212. **/
  213. typedef struct {
  214. UWORD Year; //0000
  215. UBYTE Month; //1 - 12
  216. UBYTE Day; //1 - 30
  217. UBYTE Hour; //0 - 23
  218. UBYTE Min; //0 - 59
  219. UBYTE Sec; //0 - 59
  220. } PAINT_TIME;
  221. extern PAINT_TIME Paint_time_info;
  222. //init and Clear
  223. void Paint_NewImage(UBYTE *image, UWORD Width, UWORD Height, UWORD Rotate, UWORD Color );
  224. void Paint_SelectImage(UBYTE *image );
  225. void Paint_SetRotate(UWORD Rotate );
  226. void Paint_SetMirroring(UBYTE mirror );
  227. void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color );
  228. void Paint_SetScale(UBYTE scale );
  229. void Paint_Clear(UWORD Color );
  230. void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color );
  231. //Drawing
  232. void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color, DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_FillWay );
  233. void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color_Background, DOT_PIXEL Line_width, LINE_STYLE Line_Style );
  234. void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color_Background, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill );
  235. void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius, UWORD Color_Background, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill );
  236. // //Display string
  237. void Paint_DrawChar(UWORD Xpoint, UWORD Ypoint, const char Acsii_Char,FONT_TYPE_T* Ascii_type, UWORD Color_Foreground, UWORD Color_Background );
  238. void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString,FONT_TYPE_T* Ascii_type, UWORD Color_Foreground, UWORD Color_Background );
  239. void Paint_DrawChar_CN(UWORD Xstart, UWORD Ystart, const char * pString, FONT_TYPE_T* chinese_type,UWORD Color_Foreground, UWORD Color_Background );
  240. void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, FONT_TYPE_T* chinese_type, UWORD Color_Foreground, UWORD Color_Background );
  241. void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, FONT_TYPE_T* Font_type,UWORD Color_Foreground, UWORD Color_Background );
  242. void Paint_DrawString_CN48(UWORD Xstart, UWORD Ystart, const char * pString , int is_black);
  243. void Paint_DrawChar_CN64(UWORD Xstart, UWORD Ystart, const char * pString );
  244. void Paint_DrawString_CN64(UWORD Xstart, UWORD Ystart, const char * pString );
  245. // void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font, UWORD Color_Foreground, UWORD Color_Background);
  246. // void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, int32_t Nummber, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background);
  247. // void Paint_DrawNumDecimals(UWORD Xpoint, UWORD Ypoint, double Nummber, sFONT* Font, UWORD Digit, UWORD Color_Foreground, UWORD Color_Background); // Able to display decimals
  248. // void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background);
  249. //pic
  250. void Paint_DrawBitMap_Vertical(const unsigned char* image_buffer );
  251. void Paint_DrawBitMap(const unsigned char* image_buffer );
  252. void Paint_DrawBitMap_Paste(const unsigned char* image_buffer, UWORD Xstart, UWORD Ystart, UWORD imageWidth, UWORD imageHeight, UBYTE flipColor );
  253. //void Paint_DrawBitMap_Half(const unsigned char* image_buffer, UBYTE Region);
  254. //void Paint_DrawBitMap_OneQuarter(const unsigned char* image_buffer, UBYTE Region);
  255. //void Paint_DrawBitMap_OneEighth(const unsigned char* image_buffer, UBYTE Region);
  256. void Paint_DrawBitMap_Block(const unsigned char* image_buffer, UBYTE Region );
  257. void Paint_DrawBitMap_Paste_t(const unsigned char* image_buffer, UWORD xStart, UWORD yStart, UWORD imageWidth,
  258. UWORD imageHeight, UBYTE flipColor );
  259. void drawQuadraticBezierCurve(uint8_t* framebuffer, int width, int height,
  260. int x0, int y0, int x1, int y1, int x2, int y2,
  261. uint8_t color, int thickness) ;
  262. void drawQuadraticBezierCurve_do(uint8_t* framebuffer, int width, int height,
  263. int x0, int y0, int x1, int y1, int x2, int y2,
  264. uint8_t color, int thickness);
  265. #endif