GUI_Paint.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. /******************************************************************************
  2. * | File : GUI_Paint.c
  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. #include "GUI_Paint.h"
  66. #include "DEV_Config.h"
  67. #include "Debug.h"
  68. #include <stdint.h>
  69. #include <stdlib.h>
  70. #include <string.h> //memset()
  71. #include <math.h>
  72. PAINT Paint;
  73. /******************************************************************************
  74. function: Create Image
  75. parameter:
  76. image : Pointer to the image cache
  77. width : The width of the picture
  78. Height : The height of the picture
  79. Color : Whether the picture is inverted
  80. ******************************************************************************/
  81. void Paint_NewImage(UBYTE *image, UWORD Width, UWORD Height, UWORD Rotate, UWORD Color)
  82. {
  83. Paint.Image = NULL;
  84. Paint.Image = image;
  85. Paint.WidthMemory = Width;
  86. Paint.HeightMemory = Height;
  87. Paint.Color = Color;
  88. Paint.WidthByte = (Width % 8 == 0)? (Width / 8 ): (Width / 8 + 1);
  89. Paint.HeightByte = Height;
  90. // printf("WidthByte = %d, HeightByte = %d\r\n", Paint.WidthByte, Paint.HeightByte);
  91. // printf(" EPD_WIDTH / 8 = %d\r\n", 122 / 8);
  92. Paint.Rotate = Rotate;
  93. Paint.Mirror = MIRROR_NONE;
  94. if(Rotate == ROTATE_0 || Rotate == ROTATE_180) {
  95. Paint.Width = Width;
  96. Paint.Height = Height;
  97. } else {
  98. Paint.Width = Height;
  99. Paint.Height = Width;
  100. }
  101. }
  102. /******************************************************************************
  103. function: Select Image
  104. parameter:
  105. image : Pointer to the image cache
  106. ******************************************************************************/
  107. void Paint_SelectImage(UBYTE *image)
  108. {
  109. Paint.Image = image;
  110. }
  111. /******************************************************************************
  112. function: Select Image Rotate
  113. parameter:
  114. Rotate : 0,90,180,270
  115. ******************************************************************************/
  116. void Paint_SetRotate(UWORD Rotate)
  117. {
  118. if(Rotate == ROTATE_0 || Rotate == ROTATE_90 || Rotate == ROTATE_180 || Rotate == ROTATE_270) {
  119. Debug("Set image Rotate %d\r\n", Rotate);
  120. Paint.Rotate = Rotate;
  121. } else {
  122. Debug("rotate = 0, 90, 180, 270\r\n");
  123. }
  124. }
  125. /******************************************************************************
  126. function: Select Image mirror
  127. parameter:
  128. mirror :Not mirror,Horizontal mirror,Vertical mirror,Origin mirror
  129. ******************************************************************************/
  130. void Paint_SetMirroring(UBYTE mirror)
  131. {
  132. if(mirror == MIRROR_NONE || mirror == MIRROR_HORIZONTAL ||
  133. mirror == MIRROR_VERTICAL || mirror == MIRROR_ORIGIN) {
  134. Debug("mirror image x:%s, y:%s\r\n",(mirror & 0x01)? "mirror":"none", ((mirror >> 1) & 0x01)? "mirror":"none");
  135. Paint.Mirror = mirror;
  136. } else {
  137. Debug("mirror should be MIRROR_NONE, MIRROR_HORIZONTAL, \
  138. MIRROR_VERTICAL or MIRROR_ORIGIN\r\n");
  139. }
  140. }
  141. /******************************************************************************
  142. function: Draw Pixels
  143. parameter:
  144. Xpoint : At point X
  145. Ypoint : At point Y
  146. Color : Painted colors
  147. ******************************************************************************/
  148. void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color)
  149. {
  150. if(Xpoint > Paint.Width || Ypoint > Paint.Height){
  151. Debug("Exceeding display boundaries\r\n");
  152. return;
  153. }
  154. UWORD X, Y;
  155. switch(Paint.Rotate) {
  156. case 0:
  157. X = Xpoint;
  158. Y = Ypoint;
  159. break;
  160. case 90:
  161. X = Paint.WidthMemory - Ypoint - 1;
  162. Y = Xpoint;
  163. break;
  164. case 180:
  165. X = Paint.WidthMemory - Xpoint - 1;
  166. Y = Paint.HeightMemory - Ypoint - 1;
  167. break;
  168. case 270:
  169. X = Ypoint;
  170. Y = Paint.HeightMemory - Xpoint - 1;
  171. break;
  172. default:
  173. return;
  174. }
  175. switch(Paint.Mirror) {
  176. case MIRROR_NONE:
  177. break;
  178. case MIRROR_HORIZONTAL:
  179. X = Paint.WidthMemory - X - 1;
  180. break;
  181. case MIRROR_VERTICAL:
  182. Y = Paint.HeightMemory - Y - 1;
  183. break;
  184. case MIRROR_ORIGIN:
  185. X = Paint.WidthMemory - X - 1;
  186. Y = Paint.HeightMemory - Y - 1;
  187. break;
  188. default:
  189. return;
  190. }
  191. if(X > Paint.WidthMemory || Y > Paint.HeightMemory){
  192. Debug("Exceeding display boundaries\r\n");
  193. return;
  194. }
  195. UDOUBLE Addr = X / 8 + Y * Paint.WidthByte;
  196. UBYTE Rdata = Paint.Image[Addr];
  197. if(Color == BLACK)
  198. Paint.Image[Addr] = Rdata & ~(0x80 >> (X % 8));
  199. else
  200. Paint.Image[Addr] = Rdata | (0x80 >> (X % 8));
  201. }
  202. /******************************************************************************
  203. function: Clear the color of the picture
  204. parameter:
  205. Color : Painted colors
  206. ******************************************************************************/
  207. void Paint_Clear(UWORD Color)
  208. {
  209. for (UWORD Y = 0; Y < Paint.HeightByte; Y++) {
  210. for (UWORD X = 0; X < Paint.WidthByte; X++ ) {//8 pixel = 1 byte
  211. UDOUBLE Addr = X + Y*Paint.WidthByte;
  212. Paint.Image[Addr] = Color;
  213. }
  214. }
  215. }
  216. /******************************************************************************
  217. function: Clear the color of a window
  218. parameter:
  219. Xstart : x starting point
  220. Ystart : Y starting point
  221. Xend : x end point
  222. Yend : y end point
  223. Color : Painted colors
  224. ******************************************************************************/
  225. void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color)
  226. {
  227. UWORD X, Y;
  228. for (Y = Ystart; Y < Yend; Y++) {
  229. for (X = Xstart; X < Xend; X++) {//8 pixel = 1 byte
  230. Paint_SetPixel(X, Y, Color);
  231. }
  232. }
  233. }
  234. /******************************************************************************
  235. function: Draw Point(Xpoint, Ypoint) Fill the color
  236. parameter:
  237. Xpoint : The Xpoint coordinate of the point
  238. Ypoint : The Ypoint coordinate of the point
  239. Color : Painted color
  240. Dot_Pixel : point size
  241. Dot_Style : point Style
  242. ******************************************************************************/
  243. void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color,
  244. DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style)
  245. {
  246. if (Xpoint > Paint.Width || Ypoint > Paint.Height) {
  247. Debug("Paint_DrawPoint Input exceeds the normal display range\r\n");
  248. return;
  249. }
  250. int16_t XDir_Num , YDir_Num;
  251. if (Dot_Style == DOT_FILL_AROUND) {
  252. for (XDir_Num = 0; XDir_Num < 2 * Dot_Pixel - 1; XDir_Num++) {
  253. for (YDir_Num = 0; YDir_Num < 2 * Dot_Pixel - 1; YDir_Num++) {
  254. if(Xpoint + XDir_Num - Dot_Pixel < 0 || Ypoint + YDir_Num - Dot_Pixel < 0)
  255. break;
  256. // printf("x = %d, y = %d\r\n", Xpoint + XDir_Num - Dot_Pixel, Ypoint + YDir_Num - Dot_Pixel);
  257. Paint_SetPixel(Xpoint + XDir_Num - Dot_Pixel, Ypoint + YDir_Num - Dot_Pixel, Color);
  258. }
  259. }
  260. } else {
  261. for (XDir_Num = 0; XDir_Num < Dot_Pixel; XDir_Num++) {
  262. for (YDir_Num = 0; YDir_Num < Dot_Pixel; YDir_Num++) {
  263. Paint_SetPixel(Xpoint + XDir_Num - 1, Ypoint + YDir_Num - 1, Color);
  264. }
  265. }
  266. }
  267. }
  268. /******************************************************************************
  269. function: Draw a line of arbitrary slope
  270. parameter:
  271. Xstart :Starting Xpoint point coordinates
  272. Ystart :Starting Xpoint point coordinates
  273. Xend :End point Xpoint coordinate
  274. Yend :End point Ypoint coordinate
  275. Color :The color of the line segment
  276. Line_width : Line width
  277. Line_Style: Solid and dotted lines
  278. ******************************************************************************/
  279. void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend,
  280. UWORD Color, DOT_PIXEL Line_width, LINE_STYLE Line_Style)
  281. {
  282. if (Xstart > Paint.Width || Ystart > Paint.Height ||
  283. Xend > Paint.Width || Yend > Paint.Height) {
  284. Debug("Paint_DrawLine Input exceeds the normal display range\r\n");
  285. return;
  286. }
  287. UWORD Xpoint = Xstart;
  288. UWORD Ypoint = Ystart;
  289. int dx = (int)Xend - (int)Xstart >= 0 ? Xend - Xstart : Xstart - Xend;
  290. int dy = (int)Yend - (int)Ystart <= 0 ? Yend - Ystart : Ystart - Yend;
  291. // Increment direction, 1 is positive, -1 is counter;
  292. int XAddway = Xstart < Xend ? 1 : -1;
  293. int YAddway = Ystart < Yend ? 1 : -1;
  294. //Cumulative error
  295. int Esp = dx + dy;
  296. char Dotted_Len = 0;
  297. for (;;) {
  298. Dotted_Len++;
  299. //Painted dotted line, 2 point is really virtual
  300. if (Line_Style == LINE_STYLE_DOTTED && Dotted_Len % 3 == 0) {
  301. //Debug("LINE_DOTTED\r\n");
  302. Paint_DrawPoint(Xpoint, Ypoint, IMAGE_BACKGROUND, Line_width, DOT_STYLE_DFT);
  303. Dotted_Len = 0;
  304. } else {
  305. Paint_DrawPoint(Xpoint, Ypoint, Color, Line_width, DOT_STYLE_DFT);
  306. }
  307. if (2 * Esp >= dy) {
  308. if (Xpoint == Xend)
  309. break;
  310. Esp += dy;
  311. Xpoint += XAddway;
  312. }
  313. if (2 * Esp <= dx) {
  314. if (Ypoint == Yend)
  315. break;
  316. Esp += dx;
  317. Ypoint += YAddway;
  318. }
  319. }
  320. }
  321. /******************************************************************************
  322. function: Draw a rectangle
  323. parameter:
  324. Xstart :Rectangular Starting Xpoint point coordinates
  325. Ystart :Rectangular Starting Xpoint point coordinates
  326. Xend :Rectangular End point Xpoint coordinate
  327. Yend :Rectangular End point Ypoint coordinate
  328. Color :The color of the Rectangular segment
  329. Line_width: Line width
  330. Draw_Fill : Whether to fill the inside of the rectangle
  331. ******************************************************************************/
  332. void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend,
  333. UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
  334. {
  335. if (Xstart > Paint.Width || Ystart > Paint.Height ||
  336. Xend > Paint.Width || Yend > Paint.Height) {
  337. Debug("Input exceeds the normal display range\r\n");
  338. return;
  339. }
  340. if (Draw_Fill) {
  341. UWORD Ypoint;
  342. for(Ypoint = Ystart; Ypoint < Yend; Ypoint++) {
  343. Paint_DrawLine(Xstart, Ypoint, Xend, Ypoint, Color , Line_width, LINE_STYLE_SOLID);
  344. }
  345. } else {
  346. Paint_DrawLine(Xstart, Ystart, Xend, Ystart, Color, Line_width, LINE_STYLE_SOLID);
  347. Paint_DrawLine(Xstart, Ystart, Xstart, Yend, Color, Line_width, LINE_STYLE_SOLID);
  348. Paint_DrawLine(Xend, Yend, Xend, Ystart, Color, Line_width, LINE_STYLE_SOLID);
  349. Paint_DrawLine(Xend, Yend, Xstart, Yend, Color, Line_width, LINE_STYLE_SOLID);
  350. }
  351. }
  352. /******************************************************************************
  353. function: Use the 8-point method to draw a circle of the
  354. specified size at the specified position->
  355. parameter:
  356. X_Center :Center X coordinate
  357. Y_Center :Center Y coordinate
  358. Radius :circle Radius
  359. Color :The color of the :circle segment
  360. Line_width: Line width
  361. Draw_Fill : Whether to fill the inside of the Circle
  362. ******************************************************************************/
  363. void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius,
  364. UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
  365. {
  366. if (X_Center > Paint.Width || Y_Center >= Paint.Height) {
  367. Debug("Paint_DrawCircle Input exceeds the normal display range\r\n");
  368. return;
  369. }
  370. //Draw a circle from(0, R) as a starting point
  371. int16_t XCurrent, YCurrent;
  372. XCurrent = 0;
  373. YCurrent = Radius;
  374. //Cumulative error,judge the next point of the logo
  375. int16_t Esp = 3 - (Radius << 1 );
  376. int16_t sCountY;
  377. if (Draw_Fill == DRAW_FILL_FULL) {
  378. while (XCurrent <= YCurrent ) { //Realistic circles
  379. for (sCountY = XCurrent; sCountY <= YCurrent; sCountY ++ ) {
  380. Paint_DrawPoint(X_Center + XCurrent, Y_Center + sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//1
  381. Paint_DrawPoint(X_Center - XCurrent, Y_Center + sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//2
  382. Paint_DrawPoint(X_Center - sCountY, Y_Center + XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//3
  383. Paint_DrawPoint(X_Center - sCountY, Y_Center - XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//4
  384. Paint_DrawPoint(X_Center - XCurrent, Y_Center - sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//5
  385. Paint_DrawPoint(X_Center + XCurrent, Y_Center - sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//6
  386. Paint_DrawPoint(X_Center + sCountY, Y_Center - XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//7
  387. Paint_DrawPoint(X_Center + sCountY, Y_Center + XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  388. }
  389. if (Esp < 0 )
  390. Esp += 4 * XCurrent + 6;
  391. else {
  392. Esp += 10 + 4 * (XCurrent - YCurrent );
  393. YCurrent --;
  394. }
  395. XCurrent ++;
  396. }
  397. } else { //Draw a hollow circle
  398. while (XCurrent <= YCurrent ) {
  399. Paint_DrawPoint(X_Center + XCurrent, Y_Center + YCurrent, Color, Line_width, DOT_STYLE_DFT);//1
  400. Paint_DrawPoint(X_Center - XCurrent, Y_Center + YCurrent, Color, Line_width, DOT_STYLE_DFT);//2
  401. Paint_DrawPoint(X_Center - YCurrent, Y_Center + XCurrent, Color, Line_width, DOT_STYLE_DFT);//3
  402. Paint_DrawPoint(X_Center - YCurrent, Y_Center - XCurrent, Color, Line_width, DOT_STYLE_DFT);//4
  403. Paint_DrawPoint(X_Center - XCurrent, Y_Center - YCurrent, Color, Line_width, DOT_STYLE_DFT);//5
  404. Paint_DrawPoint(X_Center + XCurrent, Y_Center - YCurrent, Color, Line_width, DOT_STYLE_DFT);//6
  405. Paint_DrawPoint(X_Center + YCurrent, Y_Center - XCurrent, Color, Line_width, DOT_STYLE_DFT);//7
  406. Paint_DrawPoint(X_Center + YCurrent, Y_Center + XCurrent, Color, Line_width, DOT_STYLE_DFT);//0
  407. if (Esp < 0 )
  408. Esp += 4 * XCurrent + 6;
  409. else {
  410. Esp += 10 + 4 * (XCurrent - YCurrent );
  411. YCurrent --;
  412. }
  413. XCurrent ++;
  414. }
  415. }
  416. }
  417. /******************************************************************************
  418. function: Show English characters
  419. parameter:
  420. Xpoint :X coordinate
  421. Ypoint :Y coordinate
  422. Acsii_Char :To display the English characters
  423. Font :A structure pointer that displays a character size
  424. Color_Foreground : Select the foreground color
  425. Color_Background : Select the background color
  426. ******************************************************************************/
  427. void Paint_DrawChar(UWORD Xpoint, UWORD Ypoint, const char Acsii_Char,
  428. sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)
  429. {
  430. UWORD Page, Column;
  431. if (Xpoint > Paint.Width || Ypoint > Paint.Height) {
  432. Debug("Paint_DrawChar Input exceeds the normal display range\r\n");
  433. return;
  434. }
  435. uint32_t Char_Offset = (Acsii_Char - ' ') * Font->Height * (Font->Width / 8 + (Font->Width % 8 ? 1 : 0));
  436. const unsigned char *ptr = &Font->table[Char_Offset];
  437. for (Page = 0; Page < Font->Height; Page ++ ) {
  438. for (Column = 0; Column < Font->Width; Column ++ ) {
  439. //To determine whether the font background color and screen background color is consistent
  440. if (FONT_BACKGROUND == Color_Background) { //this process is to speed up the scan
  441. if (*ptr & (0x80 >> (Column % 8)))
  442. Paint_SetPixel(Xpoint + Column, Ypoint + Page, Color_Foreground);
  443. // Paint_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  444. } else {
  445. if (*ptr & (0x80 >> (Column % 8))) {
  446. Paint_SetPixel(Xpoint + Column, Ypoint + Page, Color_Foreground);
  447. // Paint_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  448. } else {
  449. Paint_SetPixel(Xpoint + Column, Ypoint + Page, Color_Background);
  450. // Paint_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  451. }
  452. }
  453. //One pixel is 8 bits
  454. if (Column % 8 == 7)
  455. ptr++;
  456. }// Write a line
  457. if (Font->Width % 8 != 0)
  458. ptr++;
  459. }// Write all
  460. }
  461. /******************************************************************************
  462. function: Display the string
  463. parameter:
  464. Xstart :X coordinate
  465. Ystart :Y coordinate
  466. pString :The first address of the English string to be displayed
  467. Font :A structure pointer that displays a character size
  468. Color_Foreground : Select the foreground color
  469. Color_Background : Select the background color
  470. ******************************************************************************/
  471. void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString,
  472. sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)
  473. {
  474. UWORD Xpoint = Xstart;
  475. UWORD Ypoint = Ystart;
  476. if (Xstart > Paint.Width || Ystart > Paint.Height) {
  477. Debug("Paint_DrawString_EN Input exceeds the normal display range\r\n");
  478. return;
  479. }
  480. while (* pString != '\0') {
  481. //if X direction filled , reposition to(Xstart,Ypoint),Ypoint is Y direction plus the Height of the character
  482. if ((Xpoint + Font->Width ) > Paint.Width ) {
  483. Xpoint = Xstart;
  484. Ypoint += Font->Height;
  485. }
  486. // If the Y direction is full, reposition to(Xstart, Ystart)
  487. if ((Ypoint + Font->Height ) > Paint.Height ) {
  488. Xpoint = Xstart;
  489. Ypoint = Ystart;
  490. }
  491. Paint_DrawChar(Xpoint, Ypoint, * pString, Font, Color_Background, Color_Foreground);
  492. //The next character of the address
  493. pString ++;
  494. //The next word of the abscissa increases the font of the broadband
  495. Xpoint += Font->Width;
  496. }
  497. }
  498. /******************************************************************************
  499. function: Display the string
  500. parameter:
  501. Xstart :X coordinate
  502. Ystart :Y coordinate
  503. pString :The first address of the Chinese string and English
  504. string to be displayed
  505. Font :A structure pointer that displays a character size
  506. Color_Foreground : Select the foreground color
  507. Color_Background : Select the background color
  508. ******************************************************************************/
  509. void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font,
  510. UWORD Color_Foreground, UWORD Color_Background)
  511. {
  512. const char* p_text = pString;
  513. int x = Xstart, y = Ystart;
  514. int i, j,Num;
  515. /* Send the string character by character on EPD */
  516. while (*p_text != 0) {
  517. if(*p_text <= 0x7F) { //ASCII < 126
  518. for(Num = 0; Num < font->size; Num++) {
  519. if(*p_text== font->table[Num].index[0]) {
  520. const char* ptr = &font->table[Num].matrix[0];
  521. for (j = 0; j < font->Height; j++) {
  522. for (i = 0; i < font->Width; i++) {
  523. if (FONT_BACKGROUND == Color_Background) { //this process is to speed up the scan
  524. if (*ptr & (0x80 >> (i % 8))) {
  525. Paint_SetPixel(x + i, y + j, Color_Foreground);
  526. // Paint_DrawPoint(x + i, y + j, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  527. }
  528. } else {
  529. if (*ptr & (0x80 >> (i % 8))) {
  530. Paint_SetPixel(x + i, y + j, Color_Foreground);
  531. // Paint_DrawPoint(x + i, y + j, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  532. } else {
  533. Paint_SetPixel(x + i, y + j, Color_Background);
  534. // Paint_DrawPoint(x + i, y + j, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  535. }
  536. }
  537. if (i % 8 == 7) {
  538. ptr++;
  539. }
  540. }
  541. if (font->Width % 8 != 0) {
  542. ptr++;
  543. }
  544. }
  545. break;
  546. }
  547. }
  548. /* Point on the next character */
  549. p_text += 1;
  550. /* Decrement the column position by 16 */
  551. x += font->ASCII_Width;
  552. } else { //Chinese
  553. for(Num = 0; Num < font->size; Num++) {
  554. if((*p_text== font->table[Num].index[0]) && (*(p_text+1) == font->table[Num].index[1])) {
  555. const char* ptr = &font->table[Num].matrix[0];
  556. for (j = 0; j < font->Height; j++) {
  557. for (i = 0; i < font->Width; i++) {
  558. if (FONT_BACKGROUND == Color_Background) { //this process is to speed up the scan
  559. if (*ptr & (0x80 >> (i % 8))) {
  560. Paint_SetPixel(x + i, y + j, Color_Foreground);
  561. // Paint_DrawPoint(x + i, y + j, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  562. }
  563. } else {
  564. if (*ptr & (0x80 >> (i % 8))) {
  565. Paint_SetPixel(x + i, y + j, Color_Foreground);
  566. // Paint_DrawPoint(x + i, y + j, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  567. } else {
  568. Paint_SetPixel(x + i, y + j, Color_Background);
  569. // Paint_DrawPoint(x + i, y + j, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  570. }
  571. }
  572. if (i % 8 == 7) {
  573. ptr++;
  574. }
  575. }
  576. if (font->Width % 8 != 0) {
  577. ptr++;
  578. }
  579. }
  580. break;
  581. }
  582. }
  583. /* Point on the next character */
  584. p_text += 2;
  585. /* Decrement the column position by 16 */
  586. x += font->Width;
  587. }
  588. }
  589. }
  590. /******************************************************************************
  591. function: Display nummber
  592. parameter:
  593. Xstart :X coordinate
  594. Ystart : Y coordinate
  595. Nummber : The number displayed
  596. Font :A structure pointer that displays a character size
  597. Color_Foreground : Select the foreground color
  598. Color_Background : Select the background color
  599. ******************************************************************************/
  600. #define ARRAY_LEN 255
  601. void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, int32_t Nummber,
  602. sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)
  603. {
  604. int16_t Num_Bit = 0, Str_Bit = 0;
  605. uint8_t Str_Array[ARRAY_LEN] = {0}, Num_Array[ARRAY_LEN] = {0};
  606. uint8_t *pStr = Str_Array;
  607. if (Xpoint > Paint.Width || Ypoint > Paint.Height) {
  608. Debug("Paint_DisNum Input exceeds the normal display range\r\n");
  609. return;
  610. }
  611. //Converts a number to a string
  612. while (Nummber) {
  613. Num_Array[Num_Bit] = Nummber % 10 + '0';
  614. Num_Bit++;
  615. Nummber /= 10;
  616. }
  617. //The string is inverted
  618. while (Num_Bit > 0) {
  619. Str_Array[Str_Bit] = Num_Array[Num_Bit - 1];
  620. Str_Bit ++;
  621. Num_Bit --;
  622. }
  623. //show
  624. Paint_DrawString_EN(Xpoint, Ypoint, (const char*)pStr, Font, Color_Background, Color_Foreground);
  625. }
  626. /******************************************************************************
  627. function: Display time
  628. parameter:
  629. Xstart :X coordinate
  630. Ystart : Y coordinate
  631. pTime : Time-related structures
  632. Font :A structure pointer that displays a character size
  633. Color_Foreground : Select the foreground color
  634. Color_Background : Select the background color
  635. ******************************************************************************/
  636. void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font,
  637. UWORD Color_Foreground, UWORD Color_Background)
  638. {
  639. uint8_t value[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
  640. UWORD Dx = Font->Width;
  641. //Write data into the cache
  642. Paint_DrawChar(Xstart , Ystart, value[pTime->Hour / 10], Font, Color_Background, Color_Foreground);
  643. Paint_DrawChar(Xstart + Dx , Ystart, value[pTime->Hour % 10], Font, Color_Background, Color_Foreground);
  644. Paint_DrawChar(Xstart + Dx + Dx / 4 + Dx / 2 , Ystart, ':' , Font, Color_Background, Color_Foreground);
  645. Paint_DrawChar(Xstart + Dx * 2 + Dx / 2 , Ystart, value[pTime->Min / 10] , Font, Color_Background, Color_Foreground);
  646. Paint_DrawChar(Xstart + Dx * 3 + Dx / 2 , Ystart, value[pTime->Min % 10] , Font, Color_Background, Color_Foreground);
  647. Paint_DrawChar(Xstart + Dx * 4 + Dx / 2 - Dx / 4, Ystart, ':' , Font, Color_Background, Color_Foreground);
  648. Paint_DrawChar(Xstart + Dx * 5 , Ystart, value[pTime->Sec / 10] , Font, Color_Background, Color_Foreground);
  649. Paint_DrawChar(Xstart + Dx * 6 , Ystart, value[pTime->Sec % 10] , Font, Color_Background, Color_Foreground);
  650. }
  651. /******************************************************************************
  652. function: Display monochrome bitmap
  653. parameter:
  654. image_buffer :A picture data converted to a bitmap
  655. info:
  656. Use a computer to convert the image into a corresponding array,
  657. and then embed the array directly into Imagedata.cpp as a .c file.
  658. ******************************************************************************/
  659. void Paint_DrawBitMap(const unsigned char* image_buffer)
  660. {
  661. UWORD x, y;
  662. UDOUBLE Addr = 0;
  663. for (y = 0; y < Paint.HeightByte; y++) {
  664. for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  665. Addr = x + y * Paint.WidthByte;
  666. Paint.Image[Addr] = (unsigned char)image_buffer[Addr];
  667. }
  668. }
  669. }