GUI_Paint.c 30 KB

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