2
0

GUI_Paint.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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.2
  12. * | Date : 2020-07-23
  13. * | Info :
  14. * -----------------------------------------------------------------------------
  15. * V3.2(2020-07-23):
  16. * 1. Change: Paint_SetScale(UBYTE scale)
  17. * Add scale 7 for 5.65f e-Parper
  18. * 2. Change: Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color)
  19. * Add the branch for scale 7
  20. * 3. Change: Paint_Clear(UWORD Color)
  21. * Add the branch for scale 7
  22. *
  23. * V3.1(2019-10-10):
  24. * 1. Add gray level
  25. * PAINT Add Scale
  26. * 2. Add void Paint_SetScale(UBYTE scale);
  27. *
  28. * V3.0(2019-04-18):
  29. * 1.Change:
  30. * Paint_DrawPoint(..., DOT_STYLE DOT_STYLE)
  31. * => Paint_DrawPoint(..., DOT_STYLE Dot_Style)
  32. * Paint_DrawLine(..., LINE_STYLE Line_Style, DOT_PIXEL Dot_Pixel)
  33. * => Paint_DrawLine(..., DOT_PIXEL Line_width, LINE_STYLE Line_Style)
  34. * Paint_DrawRectangle(..., DRAW_FILL Filled, DOT_PIXEL Dot_Pixel)
  35. * => Paint_DrawRectangle(..., DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
  36. * Paint_DrawCircle(..., DRAW_FILL Draw_Fill, DOT_PIXEL Dot_Pixel)
  37. * => Paint_DrawCircle(..., DOT_PIXEL Line_width, DRAW_FILL Draw_Filll)
  38. *
  39. * -----------------------------------------------------------------------------
  40. * V2.0(2018-11-15):
  41. * 1.add: Paint_NewImage()
  42. * Create an image's properties
  43. * 2.add: Paint_SelectImage()
  44. * Select the picture to be drawn
  45. * 3.add: Paint_SetRotate()
  46. * Set the direction of the cache
  47. * 4.add: Paint_RotateImage()
  48. * Can flip the picture, Support 0-360 degrees,
  49. * but only 90.180.270 rotation is better
  50. * 4.add: Paint_SetMirroring()
  51. * Can Mirroring the picture, horizontal, vertical, origin
  52. * 5.add: Paint_DrawString_CN()
  53. * Can display Chinese(GB1312)
  54. *
  55. * -----------------------------------------------------------------------------
  56. * V1.0(2018-07-17):
  57. * Create library
  58. *
  59. * Permission is hereby granted, free of charge, to any person obtaining a copy
  60. * of this software and associated documnetation files (the "Software"), to deal
  61. * in the Software without restriction, including without limitation the rights
  62. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  63. * copies of the Software, and to permit persons to whom the Software is
  64. * furished to do so, subject to the following conditions:
  65. *
  66. * The above copyright notice and this permission notice shall be included in
  67. * all copies or substantial portions of the Software.
  68. *
  69. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  70. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  71. * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  72. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  73. * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  74. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  75. * THE SOFTWARE.
  76. *
  77. ******************************************************************************/
  78. #ifndef __GUI_PAINT_H
  79. #define __GUI_PAINT_H
  80. #include "Debug.h"
  81. #include "DEV_Config.h"
  82. #include "fonts.h"
  83. /**
  84. * Image attributes
  85. **/
  86. typedef struct {
  87. UBYTE *Image;
  88. UWORD Width;
  89. UWORD Height;
  90. UWORD WidthMemory;
  91. UWORD HeightMemory;
  92. UWORD Color;
  93. UWORD Rotate;
  94. UWORD Mirror;
  95. UWORD WidthByte;
  96. UWORD HeightByte;
  97. UWORD Scale;
  98. } PAINT;
  99. extern PAINT Paint;
  100. /**
  101. * Display rotate
  102. **/
  103. #define ROTATE_0 0
  104. #define ROTATE_90 90
  105. #define ROTATE_180 180
  106. #define ROTATE_270 270
  107. /**
  108. * Display Flip
  109. **/
  110. typedef enum {
  111. MIRROR_NONE = 0x00,
  112. MIRROR_HORIZONTAL = 0x01,
  113. MIRROR_VERTICAL = 0x02,
  114. MIRROR_ORIGIN = 0x03,
  115. } MIRROR_IMAGE;
  116. #define MIRROR_IMAGE_DFT MIRROR_NONE
  117. /**
  118. * image color
  119. **/
  120. #define WHITE 0xFF
  121. #define BLACK 0x00
  122. #define RED BLACK
  123. #define IMAGE_BACKGROUND WHITE
  124. #define FONT_FOREGROUND BLACK
  125. #define FONT_BACKGROUND WHITE
  126. #define TRUE 1
  127. #define FALSE 0
  128. //4 Gray level
  129. #define GRAY1 0x03 //Blackest
  130. #define GRAY2 0x02
  131. #define GRAY3 0x01 //gray
  132. #define GRAY4 0x00 //white
  133. /**
  134. * The size of the point
  135. **/
  136. typedef enum {
  137. DOT_PIXEL_1X1 = 1, // 1 x 1
  138. DOT_PIXEL_2X2 , // 2 X 2
  139. DOT_PIXEL_3X3 , // 3 X 3
  140. DOT_PIXEL_4X4 , // 4 X 4
  141. DOT_PIXEL_5X5 , // 5 X 5
  142. DOT_PIXEL_6X6 , // 6 X 6
  143. DOT_PIXEL_7X7 , // 7 X 7
  144. DOT_PIXEL_8X8 , // 8 X 8
  145. } DOT_PIXEL;
  146. #define DOT_PIXEL_DFT DOT_PIXEL_1X1 //Default dot pilex
  147. /**
  148. * Point size fill style
  149. **/
  150. typedef enum {
  151. DOT_FILL_AROUND = 1, // dot pixel 1 x 1
  152. DOT_FILL_RIGHTUP , // dot pixel 2 X 2
  153. } DOT_STYLE;
  154. #define DOT_STYLE_DFT DOT_FILL_AROUND //Default dot pilex
  155. /**
  156. * Line style, solid or dashed
  157. **/
  158. typedef enum {
  159. LINE_STYLE_SOLID = 0,
  160. LINE_STYLE_DOTTED,
  161. } LINE_STYLE;
  162. /**
  163. * Whether the graphic is filled
  164. **/
  165. typedef enum {
  166. DRAW_FILL_EMPTY = 0,
  167. DRAW_FILL_FULL,
  168. } DRAW_FILL;
  169. /**
  170. * Custom structure of a time attribute
  171. **/
  172. typedef struct {
  173. UWORD Year; //0000
  174. UBYTE Month; //1 - 12
  175. UBYTE Day; //1 - 30
  176. UBYTE Hour; //0 - 23
  177. UBYTE Min; //0 - 59
  178. UBYTE Sec; //0 - 59
  179. } PAINT_TIME;
  180. extern PAINT_TIME sPaint_time;
  181. //init and Clear
  182. void Paint_NewImage(UBYTE *image, UWORD Width, UWORD Height, UWORD Rotate, UWORD Color);
  183. void Paint_SelectImage(UBYTE *image);
  184. void Paint_SetRotate(UWORD Rotate);
  185. void Paint_SetMirroring(UBYTE mirror);
  186. void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color);
  187. void Paint_SetScale(UBYTE scale);
  188. void Paint_Clear(UWORD Color);
  189. void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color);
  190. //Drawing
  191. void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color, DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_FillWay);
  192. void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, DOT_PIXEL Line_width, LINE_STYLE Line_Style);
  193. void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill);
  194. void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill);
  195. //Display string
  196. void Paint_DrawChar(UWORD Xstart, UWORD Ystart, const char Acsii_Char, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background);
  197. void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background);
  198. void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font, UWORD Color_Foreground, UWORD Color_Background);
  199. void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, int32_t Nummber, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background);
  200. void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background);
  201. //pic
  202. void Paint_DrawBitMap(const unsigned char* image_buffer);
  203. void Paint_DrawBitMap_Paste(const unsigned char* image_buffer, UWORD xStart, UWORD yStart, UWORD imageWidth, UWORD imageHeight, UBYTE flipColor);
  204. void Paint_DrawImage(const unsigned char *image_buffer, UWORD xStart, UWORD yStart, UWORD W_Image, UWORD H_Image);
  205. #endif