GUI_Paint.cpp 34 KB

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