GUI_Paint.cpp 35 KB

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