GUI_Paint.c 33 KB

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