GUI_Paint.c 35 KB

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