GUI_Paint.h 5.8 KB

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