GUI_Paint.h 8.0 KB

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