GUI_Paint.c 29 KB

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