GUI_Paint.cpp 37 KB

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