GUI_Paint.c 31 KB

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