GUI_Paint.c 34 KB

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