gui_paint.c 37 KB

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