2
0

GUI_Paint.c 31 KB

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