GUI_Paint.h 6.9 KB

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