GUI_Paint.cpp 35 KB

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