2
0

GUI_Paint.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  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) {
  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 == 4) {
  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<<6)|(Color<<4)|(Color<<2)|Color;
  265. }
  266. }
  267. }else if(Paint.Scale == 7) {
  268. for (UWORD Y = 0; Y < Paint.HeightByte; Y++) {
  269. for (UWORD X = 0; X < Paint.WidthByte; X++ ) {
  270. UDOUBLE Addr = X + Y*Paint.WidthByte;
  271. Paint.Image[Addr] = (Color<<4)|Color;
  272. }
  273. }
  274. }
  275. }
  276. /******************************************************************************
  277. function: Clear the color of a window
  278. parameter:
  279. Xstart : x starting point
  280. Ystart : Y starting point
  281. Xend : x end point
  282. Yend : y end point
  283. Color : Painted colors
  284. ******************************************************************************/
  285. void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color)
  286. {
  287. UWORD X, Y;
  288. for (Y = Ystart; Y < Yend; Y++) {
  289. for (X = Xstart; X < Xend; X++) {//8 pixel = 1 byte
  290. Paint_SetPixel(X, Y, Color);
  291. }
  292. }
  293. }
  294. /******************************************************************************
  295. function: Draw Point(Xpoint, Ypoint) Fill the color
  296. parameter:
  297. Xpoint : The Xpoint coordinate of the point
  298. Ypoint : The Ypoint coordinate of the point
  299. Color : Painted color
  300. Dot_Pixel : point size
  301. Dot_Style : point Style
  302. ******************************************************************************/
  303. void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color,
  304. DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style)
  305. {
  306. if (Xpoint > Paint.Width || Ypoint > Paint.Height) {
  307. Debug("Paint_DrawPoint Input exceeds the normal display range\r\n");
  308. return;
  309. }
  310. int16_t XDir_Num , YDir_Num;
  311. if (Dot_Style == DOT_FILL_AROUND) {
  312. for (XDir_Num = 0; XDir_Num < 2 * Dot_Pixel - 1; XDir_Num++) {
  313. for (YDir_Num = 0; YDir_Num < 2 * Dot_Pixel - 1; YDir_Num++) {
  314. if(Xpoint + XDir_Num - Dot_Pixel < 0 || Ypoint + YDir_Num - Dot_Pixel < 0)
  315. break;
  316. // printf("x = %d, y = %d\r\n", Xpoint + XDir_Num - Dot_Pixel, Ypoint + YDir_Num - Dot_Pixel);
  317. Paint_SetPixel(Xpoint + XDir_Num - Dot_Pixel, Ypoint + YDir_Num - Dot_Pixel, Color);
  318. }
  319. }
  320. } else {
  321. for (XDir_Num = 0; XDir_Num < Dot_Pixel; XDir_Num++) {
  322. for (YDir_Num = 0; YDir_Num < Dot_Pixel; YDir_Num++) {
  323. Paint_SetPixel(Xpoint + XDir_Num - 1, Ypoint + YDir_Num - 1, Color);
  324. }
  325. }
  326. }
  327. }
  328. /******************************************************************************
  329. function: Draw a line of arbitrary slope
  330. parameter:
  331. Xstart :Starting Xpoint point coordinates
  332. Ystart :Starting Xpoint point coordinates
  333. Xend :End point Xpoint coordinate
  334. Yend :End point Ypoint coordinate
  335. Color :The color of the line segment
  336. Line_width : Line width
  337. Line_Style: Solid and dotted lines
  338. ******************************************************************************/
  339. void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend,
  340. UWORD Color, DOT_PIXEL Line_width, LINE_STYLE Line_Style)
  341. {
  342. if (Xstart > Paint.Width || Ystart > Paint.Height ||
  343. Xend > Paint.Width || Yend > Paint.Height) {
  344. Debug("Paint_DrawLine Input exceeds the normal display range\r\n");
  345. return;
  346. }
  347. UWORD Xpoint = Xstart;
  348. UWORD Ypoint = Ystart;
  349. int dx = (int)Xend - (int)Xstart >= 0 ? Xend - Xstart : Xstart - Xend;
  350. int dy = (int)Yend - (int)Ystart <= 0 ? Yend - Ystart : Ystart - Yend;
  351. // Increment direction, 1 is positive, -1 is counter;
  352. int XAddway = Xstart < Xend ? 1 : -1;
  353. int YAddway = Ystart < Yend ? 1 : -1;
  354. //Cumulative error
  355. int Esp = dx + dy;
  356. char Dotted_Len = 0;
  357. for (;;) {
  358. Dotted_Len++;
  359. //Painted dotted line, 2 point is really virtual
  360. if (Line_Style == LINE_STYLE_DOTTED && Dotted_Len % 3 == 0) {
  361. //Debug("LINE_DOTTED\r\n");
  362. Paint_DrawPoint(Xpoint, Ypoint, IMAGE_BACKGROUND, Line_width, DOT_STYLE_DFT);
  363. Dotted_Len = 0;
  364. } else {
  365. Paint_DrawPoint(Xpoint, Ypoint, Color, Line_width, DOT_STYLE_DFT);
  366. }
  367. if (2 * Esp >= dy) {
  368. if (Xpoint == Xend)
  369. break;
  370. Esp += dy;
  371. Xpoint += XAddway;
  372. }
  373. if (2 * Esp <= dx) {
  374. if (Ypoint == Yend)
  375. break;
  376. Esp += dx;
  377. Ypoint += YAddway;
  378. }
  379. }
  380. }
  381. /******************************************************************************
  382. function: Draw a rectangle
  383. parameter:
  384. Xstart :Rectangular Starting Xpoint point coordinates
  385. Ystart :Rectangular Starting Xpoint point coordinates
  386. Xend :Rectangular End point Xpoint coordinate
  387. Yend :Rectangular End point Ypoint coordinate
  388. Color :The color of the Rectangular segment
  389. Line_width: Line width
  390. Draw_Fill : Whether to fill the inside of the rectangle
  391. ******************************************************************************/
  392. void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend,
  393. UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
  394. {
  395. if (Xstart > Paint.Width || Ystart > Paint.Height ||
  396. Xend > Paint.Width || Yend > Paint.Height) {
  397. Debug("Input exceeds the normal display range\r\n");
  398. return;
  399. }
  400. if (Draw_Fill) {
  401. UWORD Ypoint;
  402. for(Ypoint = Ystart; Ypoint < Yend; Ypoint++) {
  403. Paint_DrawLine(Xstart, Ypoint, Xend, Ypoint, Color , Line_width, LINE_STYLE_SOLID);
  404. }
  405. } else {
  406. Paint_DrawLine(Xstart, Ystart, Xend, Ystart, Color, Line_width, LINE_STYLE_SOLID);
  407. Paint_DrawLine(Xstart, Ystart, Xstart, Yend, Color, Line_width, LINE_STYLE_SOLID);
  408. Paint_DrawLine(Xend, Yend, Xend, Ystart, Color, Line_width, LINE_STYLE_SOLID);
  409. Paint_DrawLine(Xend, Yend, Xstart, Yend, Color, Line_width, LINE_STYLE_SOLID);
  410. }
  411. }
  412. /******************************************************************************
  413. function: Use the 8-point method to draw a circle of the
  414. specified size at the specified position->
  415. parameter:
  416. X_Center :Center X coordinate
  417. Y_Center :Center Y coordinate
  418. Radius :circle Radius
  419. Color :The color of the :circle segment
  420. Line_width: Line width
  421. Draw_Fill : Whether to fill the inside of the Circle
  422. ******************************************************************************/
  423. void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius,
  424. UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
  425. {
  426. if (X_Center > Paint.Width || Y_Center >= Paint.Height) {
  427. Debug("Paint_DrawCircle Input exceeds the normal display range\r\n");
  428. return;
  429. }
  430. //Draw a circle from(0, R) as a starting point
  431. int16_t XCurrent, YCurrent;
  432. XCurrent = 0;
  433. YCurrent = Radius;
  434. //Cumulative error,judge the next point of the logo
  435. int16_t Esp = 3 - (Radius << 1 );
  436. int16_t sCountY;
  437. if (Draw_Fill == DRAW_FILL_FULL) {
  438. while (XCurrent <= YCurrent ) { //Realistic circles
  439. for (sCountY = XCurrent; sCountY <= YCurrent; sCountY ++ ) {
  440. Paint_DrawPoint(X_Center + XCurrent, Y_Center + sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//1
  441. Paint_DrawPoint(X_Center - XCurrent, Y_Center + sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//2
  442. Paint_DrawPoint(X_Center - sCountY, Y_Center + XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//3
  443. Paint_DrawPoint(X_Center - sCountY, Y_Center - XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//4
  444. Paint_DrawPoint(X_Center - XCurrent, Y_Center - sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//5
  445. Paint_DrawPoint(X_Center + XCurrent, Y_Center - sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//6
  446. Paint_DrawPoint(X_Center + sCountY, Y_Center - XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//7
  447. Paint_DrawPoint(X_Center + sCountY, Y_Center + XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  448. }
  449. if (Esp < 0 )
  450. Esp += 4 * XCurrent + 6;
  451. else {
  452. Esp += 10 + 4 * (XCurrent - YCurrent );
  453. YCurrent --;
  454. }
  455. XCurrent ++;
  456. }
  457. } else { //Draw a hollow circle
  458. while (XCurrent <= YCurrent ) {
  459. Paint_DrawPoint(X_Center + XCurrent, Y_Center + YCurrent, Color, Line_width, DOT_STYLE_DFT);//1
  460. Paint_DrawPoint(X_Center - XCurrent, Y_Center + YCurrent, Color, Line_width, DOT_STYLE_DFT);//2
  461. Paint_DrawPoint(X_Center - YCurrent, Y_Center + XCurrent, Color, Line_width, DOT_STYLE_DFT);//3
  462. Paint_DrawPoint(X_Center - YCurrent, Y_Center - XCurrent, Color, Line_width, DOT_STYLE_DFT);//4
  463. Paint_DrawPoint(X_Center - XCurrent, Y_Center - YCurrent, Color, Line_width, DOT_STYLE_DFT);//5
  464. Paint_DrawPoint(X_Center + XCurrent, Y_Center - YCurrent, Color, Line_width, DOT_STYLE_DFT);//6
  465. Paint_DrawPoint(X_Center + YCurrent, Y_Center - XCurrent, Color, Line_width, DOT_STYLE_DFT);//7
  466. Paint_DrawPoint(X_Center + YCurrent, Y_Center + XCurrent, Color, Line_width, DOT_STYLE_DFT);//0
  467. if (Esp < 0 )
  468. Esp += 4 * XCurrent + 6;
  469. else {
  470. Esp += 10 + 4 * (XCurrent - YCurrent );
  471. YCurrent --;
  472. }
  473. XCurrent ++;
  474. }
  475. }
  476. }
  477. /******************************************************************************
  478. function: Show English characters
  479. parameter:
  480. Xpoint :X coordinate
  481. Ypoint :Y coordinate
  482. Acsii_Char :To display the English characters
  483. Font :A structure pointer that displays a character size
  484. Color_Foreground : Select the foreground color
  485. Color_Background : Select the background color
  486. ******************************************************************************/
  487. void Paint_DrawChar(UWORD Xpoint, UWORD Ypoint, const char Acsii_Char,
  488. sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)
  489. {
  490. UWORD Page, Column;
  491. if (Xpoint > Paint.Width || Ypoint > Paint.Height) {
  492. Debug("Paint_DrawChar Input exceeds the normal display range\r\n");
  493. return;
  494. }
  495. uint32_t Char_Offset = (Acsii_Char - ' ') * Font->Height * (Font->Width / 8 + (Font->Width % 8 ? 1 : 0));
  496. const unsigned char *ptr = &Font->table[Char_Offset];
  497. for (Page = 0; Page < Font->Height; Page ++ ) {
  498. for (Column = 0; Column < Font->Width; Column ++ ) {
  499. //To determine whether the font background color and screen background color is consistent
  500. if (FONT_BACKGROUND == Color_Background) { //this process is to speed up the scan
  501. if (*ptr & (0x80 >> (Column % 8)))
  502. Paint_SetPixel(Xpoint + Column, Ypoint + Page, Color_Foreground);
  503. // Paint_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  504. } else {
  505. if (*ptr & (0x80 >> (Column % 8))) {
  506. Paint_SetPixel(Xpoint + Column, Ypoint + Page, Color_Foreground);
  507. // Paint_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  508. } else {
  509. Paint_SetPixel(Xpoint + Column, Ypoint + Page, Color_Background);
  510. // Paint_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  511. }
  512. }
  513. //One pixel is 8 bits
  514. if (Column % 8 == 7)
  515. ptr++;
  516. }// Write a line
  517. if (Font->Width % 8 != 0)
  518. ptr++;
  519. }// Write all
  520. }
  521. /******************************************************************************
  522. function: Display the string
  523. parameter:
  524. Xstart :X coordinate
  525. Ystart :Y coordinate
  526. pString :The first address of the English string to be displayed
  527. Font :A structure pointer that displays a character size
  528. Color_Foreground : Select the foreground color
  529. Color_Background : Select the background color
  530. ******************************************************************************/
  531. void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString,
  532. sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)
  533. {
  534. UWORD Xpoint = Xstart;
  535. UWORD Ypoint = Ystart;
  536. if (Xstart > Paint.Width || Ystart > Paint.Height) {
  537. Debug("Paint_DrawString_EN Input exceeds the normal display range\r\n");
  538. return;
  539. }
  540. while (* pString != '\0') {
  541. //if X direction filled , reposition to(Xstart,Ypoint),Ypoint is Y direction plus the Height of the character
  542. if ((Xpoint + Font->Width ) > Paint.Width ) {
  543. Xpoint = Xstart;
  544. Ypoint += Font->Height;
  545. }
  546. // If the Y direction is full, reposition to(Xstart, Ystart)
  547. if ((Ypoint + Font->Height ) > Paint.Height ) {
  548. Xpoint = Xstart;
  549. Ypoint = Ystart;
  550. }
  551. Paint_DrawChar(Xpoint, Ypoint, * pString, Font, Color_Background, Color_Foreground);
  552. //The next character of the address
  553. pString ++;
  554. //The next word of the abscissa increases the font of the broadband
  555. Xpoint += Font->Width;
  556. }
  557. }
  558. /******************************************************************************
  559. function: Display the string
  560. parameter:
  561. Xstart :X coordinate
  562. Ystart :Y coordinate
  563. pString :The first address of the Chinese string and English
  564. string to be displayed
  565. Font :A structure pointer that displays a character size
  566. Color_Foreground : Select the foreground color
  567. Color_Background : Select the background color
  568. ******************************************************************************/
  569. void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font,
  570. UWORD Color_Foreground, UWORD Color_Background)
  571. {
  572. const char* p_text = pString;
  573. int x = Xstart, y = Ystart;
  574. int i, j,Num;
  575. /* Send the string character by character on EPD */
  576. while (*p_text != 0) {
  577. if(*p_text <= 0x7F) { //ASCII < 126
  578. for(Num = 0; Num < font->size; Num++) {
  579. if(*p_text== font->table[Num].index[0]) {
  580. const char* ptr = &font->table[Num].matrix[0];
  581. for (j = 0; j < font->Height; j++) {
  582. for (i = 0; i < font->Width; i++) {
  583. if (FONT_BACKGROUND == Color_Background) { //this process is to speed up the scan
  584. if (*ptr & (0x80 >> (i % 8))) {
  585. Paint_SetPixel(x + i, y + j, Color_Foreground);
  586. // Paint_DrawPoint(x + i, y + j, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  587. }
  588. } else {
  589. if (*ptr & (0x80 >> (i % 8))) {
  590. Paint_SetPixel(x + i, y + j, Color_Foreground);
  591. // Paint_DrawPoint(x + i, y + j, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  592. } else {
  593. Paint_SetPixel(x + i, y + j, Color_Background);
  594. // Paint_DrawPoint(x + i, y + j, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  595. }
  596. }
  597. if (i % 8 == 7) {
  598. ptr++;
  599. }
  600. }
  601. if (font->Width % 8 != 0) {
  602. ptr++;
  603. }
  604. }
  605. break;
  606. }
  607. }
  608. /* Point on the next character */
  609. p_text += 1;
  610. /* Decrement the column position by 16 */
  611. x += font->ASCII_Width;
  612. } else { //Chinese
  613. for(Num = 0; Num < font->size; Num++) {
  614. if((*p_text== font->table[Num].index[0]) && (*(p_text+1) == font->table[Num].index[1])) {
  615. const char* ptr = &font->table[Num].matrix[0];
  616. for (j = 0; j < font->Height; j++) {
  617. for (i = 0; i < font->Width; i++) {
  618. if (FONT_BACKGROUND == Color_Background) { //this process is to speed up the scan
  619. if (*ptr & (0x80 >> (i % 8))) {
  620. Paint_SetPixel(x + i, y + j, Color_Foreground);
  621. // Paint_DrawPoint(x + i, y + j, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  622. }
  623. } else {
  624. if (*ptr & (0x80 >> (i % 8))) {
  625. Paint_SetPixel(x + i, y + j, Color_Foreground);
  626. // Paint_DrawPoint(x + i, y + j, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  627. } else {
  628. Paint_SetPixel(x + i, y + j, Color_Background);
  629. // Paint_DrawPoint(x + i, y + j, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  630. }
  631. }
  632. if (i % 8 == 7) {
  633. ptr++;
  634. }
  635. }
  636. if (font->Width % 8 != 0) {
  637. ptr++;
  638. }
  639. }
  640. break;
  641. }
  642. }
  643. /* Point on the next character */
  644. p_text += 2;
  645. /* Decrement the column position by 16 */
  646. x += font->Width;
  647. }
  648. }
  649. }
  650. /******************************************************************************
  651. function: Display nummber
  652. parameter:
  653. Xstart :X coordinate
  654. Ystart : Y coordinate
  655. Nummber : The number displayed
  656. Font :A structure pointer that displays a character size
  657. Color_Foreground : Select the foreground color
  658. Color_Background : Select the background color
  659. ******************************************************************************/
  660. #define ARRAY_LEN 255
  661. void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, int32_t Nummber,
  662. sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)
  663. {
  664. int16_t Num_Bit = 0, Str_Bit = 0;
  665. uint8_t Str_Array[ARRAY_LEN] = {0}, Num_Array[ARRAY_LEN] = {0};
  666. uint8_t *pStr = Str_Array;
  667. if (Xpoint > Paint.Width || Ypoint > Paint.Height) {
  668. Debug("Paint_DisNum Input exceeds the normal display range\r\n");
  669. return;
  670. }
  671. //Converts a number to a string
  672. do {
  673. Num_Array[Num_Bit] = Nummber % 10 + '0';
  674. Num_Bit++;
  675. Nummber /= 10;
  676. } while(Nummber);
  677. //The string is inverted
  678. while (Num_Bit > 0) {
  679. Str_Array[Str_Bit] = Num_Array[Num_Bit - 1];
  680. Str_Bit ++;
  681. Num_Bit --;
  682. }
  683. //show
  684. Paint_DrawString_EN(Xpoint, Ypoint, (const char*)pStr, Font, Color_Background, Color_Foreground);
  685. }
  686. /******************************************************************************
  687. function: Display nummber (Able to display decimals)
  688. parameter:
  689. Xstart :X coordinate
  690. Ystart : Y coordinate
  691. Nummber : The number displayed
  692. Font :A structure pointer that displays a character size
  693. Digit : Fractional width
  694. Color_Foreground : Select the foreground color
  695. Color_Background : Select the background color
  696. ******************************************************************************/
  697. void Paint_DrawNumDecimals(UWORD Xpoint, UWORD Ypoint, double Nummber,
  698. sFONT* Font, UWORD Digit, UWORD Color_Foreground, UWORD Color_Background)
  699. {
  700. int16_t Num_Bit = 0, Str_Bit = 0;
  701. uint8_t Str_Array[ARRAY_LEN] = {0}, Num_Array[ARRAY_LEN] = {0};
  702. uint8_t *pStr = Str_Array;
  703. int temp = Nummber;
  704. float decimals;
  705. uint8_t i;
  706. if (Xpoint > Paint.Width || Ypoint > Paint.Height) {
  707. Debug("Paint_DisNum Input exceeds the normal display range\r\n");
  708. return;
  709. }
  710. if(Digit > 0) {
  711. decimals = Nummber - temp;
  712. for(i=Digit; i > 0; i--) {
  713. decimals*=10;
  714. }
  715. temp = decimals;
  716. //Converts a number to a string
  717. for(i=Digit; i>0; i--) {
  718. Num_Array[Num_Bit] = temp % 10 + '0';
  719. Num_Bit++;
  720. temp /= 10;
  721. }
  722. Num_Array[Num_Bit] = '.';
  723. Num_Bit++;
  724. }
  725. temp = Nummber;
  726. //Converts a number to a string
  727. do {
  728. Num_Array[Num_Bit] = temp % 10 + '0';
  729. Num_Bit++;
  730. temp /= 10;
  731. } while(temp);
  732. //The string is inverted
  733. while (Num_Bit > 0) {
  734. Str_Array[Str_Bit] = Num_Array[Num_Bit - 1];
  735. Str_Bit ++;
  736. Num_Bit --;
  737. }
  738. //show
  739. Paint_DrawString_EN(Xpoint, Ypoint, (const char*)pStr, Font, Color_Background, Color_Foreground);
  740. }
  741. /******************************************************************************
  742. function: Display time
  743. parameter:
  744. Xstart :X coordinate
  745. Ystart : Y coordinate
  746. pTime : Time-related structures
  747. Font :A structure pointer that displays a character size
  748. Color_Foreground : Select the foreground color
  749. Color_Background : Select the background color
  750. ******************************************************************************/
  751. void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font,
  752. UWORD Color_Foreground, UWORD Color_Background)
  753. {
  754. uint8_t value[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
  755. UWORD Dx = Font->Width;
  756. //Write data into the cache
  757. Paint_DrawChar(Xstart , Ystart, value[pTime->Hour / 10], Font, Color_Background, Color_Foreground);
  758. Paint_DrawChar(Xstart + Dx , Ystart, value[pTime->Hour % 10], Font, Color_Background, Color_Foreground);
  759. Paint_DrawChar(Xstart + Dx + Dx / 4 + Dx / 2 , Ystart, ':' , Font, Color_Background, Color_Foreground);
  760. Paint_DrawChar(Xstart + Dx * 2 + Dx / 2 , Ystart, value[pTime->Min / 10] , Font, Color_Background, Color_Foreground);
  761. Paint_DrawChar(Xstart + Dx * 3 + Dx / 2 , Ystart, value[pTime->Min % 10] , Font, Color_Background, Color_Foreground);
  762. Paint_DrawChar(Xstart + Dx * 4 + Dx / 2 - Dx / 4, Ystart, ':' , Font, Color_Background, Color_Foreground);
  763. Paint_DrawChar(Xstart + Dx * 5 , Ystart, value[pTime->Sec / 10] , Font, Color_Background, Color_Foreground);
  764. Paint_DrawChar(Xstart + Dx * 6 , Ystart, value[pTime->Sec % 10] , Font, Color_Background, Color_Foreground);
  765. }
  766. /******************************************************************************
  767. function: Display monochrome bitmap
  768. parameter:
  769. image_buffer :A picture data converted to a bitmap
  770. info:
  771. Use a computer to convert the image into a corresponding array,
  772. and then embed the array directly into Imagedata.cpp as a .c file.
  773. ******************************************************************************/
  774. void Paint_DrawBitMap(const unsigned char* image_buffer)
  775. {
  776. UWORD x, y;
  777. UDOUBLE Addr = 0;
  778. for (y = 0; y < Paint.HeightByte; y++) {
  779. for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  780. Addr = x + y * Paint.WidthByte;
  781. Paint.Image[Addr] = (unsigned char)image_buffer[Addr];
  782. }
  783. }
  784. }