GUI_Paint.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  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. #include "OLED_Driver.h"
  90. PAINT Paint;
  91. /******************************************************************************
  92. function: Create Image
  93. parameter:
  94. image : Pointer to the image cache
  95. width : The width of the picture
  96. Height : The height of the picture
  97. Color : Whether the picture is inverted
  98. ******************************************************************************/
  99. void Paint_NewImage(UBYTE *image, UWORD Width, UWORD Height, UWORD Rotate, UWORD Color)
  100. {
  101. Paint.Image = NULL;
  102. Paint.Image = image;
  103. Paint.WidthMemory = Width;
  104. Paint.HeightMemory = Height;
  105. Paint.Color = Color;
  106. Paint.Scale = 2;
  107. Paint.WidthByte = (Width % 8 == 0)? (Width / 8 ): (Width / 8 + 1);
  108. Paint.HeightByte = Height;
  109. // printf("WidthByte = %d, HeightByte = %d\r\n", Paint.WidthByte, Paint.HeightByte);
  110. // printf(" EPD_WIDTH / 8 = %d\r\n", 122 / 8);
  111. Paint.Rotate = Rotate;
  112. Paint.Mirror = MIRROR_NONE;
  113. if(Rotate == ROTATE_0 || Rotate == ROTATE_180) {
  114. Paint.Width = Width;
  115. Paint.Height = Height;
  116. } else {
  117. Paint.Width = Height;
  118. Paint.Height = Width;
  119. }
  120. }
  121. /******************************************************************************
  122. function: Select Image
  123. parameter:
  124. image : Pointer to the image cache
  125. ******************************************************************************/
  126. void Paint_SelectImage(UBYTE *image)
  127. {
  128. Paint.Image = image;
  129. }
  130. /******************************************************************************
  131. function: Select Image Rotate
  132. parameter:
  133. Rotate : 0,90,180,270
  134. ******************************************************************************/
  135. void Paint_SetRotate(UWORD Rotate)
  136. {
  137. if(Rotate == ROTATE_0 || Rotate == ROTATE_90 || Rotate == ROTATE_180 || Rotate == ROTATE_270) {
  138. Debug("Set image Rotate %d\r\n", Rotate);
  139. Paint.Rotate = Rotate;
  140. } else {
  141. Debug("rotate = 0, 90, 180, 270\r\n");
  142. }
  143. }
  144. void Paint_SetScale(UBYTE scale)
  145. {
  146. if(scale == 2){
  147. Paint.Scale = scale;
  148. Paint.WidthByte = (Paint.WidthMemory % 8 == 0)? (Paint.WidthMemory / 8 ): (Paint.WidthMemory / 8 + 1);
  149. }else if(scale == 4){
  150. Paint.Scale = scale;
  151. Paint.WidthByte = (Paint.WidthMemory % 4 == 0)? (Paint.WidthMemory / 4 ): (Paint.WidthMemory / 4 + 1);
  152. }else if(scale ==16) {
  153. Paint.Scale = scale;
  154. Paint.WidthByte = (Paint.WidthMemory%2==0) ? (Paint.WidthMemory/2) : (Paint.WidthMemory/2+1);
  155. }else if(scale ==65) {
  156. Paint.Scale = scale;
  157. Paint.WidthByte = Paint.WidthMemory*2;
  158. }else{
  159. Debug("Set Scale Input parameter error\r\n");
  160. Debug("Scale Only support: 2 4 16 65\r\n");
  161. }
  162. }
  163. /******************************************************************************
  164. function: Select Image mirror
  165. parameter:
  166. mirror :Not mirror,Horizontal mirror,Vertical mirror,Origin mirror
  167. ******************************************************************************/
  168. void Paint_SetMirroring(UBYTE mirror)
  169. {
  170. if(mirror == MIRROR_NONE || mirror == MIRROR_HORIZONTAL ||
  171. mirror == MIRROR_VERTICAL || mirror == MIRROR_ORIGIN) {
  172. Debug("mirror image x:%s, y:%s\r\n",(mirror & 0x01)? "mirror":"none", ((mirror >> 1) & 0x01)? "mirror":"none");
  173. Paint.Mirror = mirror;
  174. } else {
  175. Debug("mirror should be MIRROR_NONE, MIRROR_HORIZONTAL, \
  176. MIRROR_VERTICAL or MIRROR_ORIGIN\r\n");
  177. }
  178. }
  179. /******************************************************************************
  180. function: Draw Pixels
  181. parameter:
  182. Xpoint : At point X
  183. Ypoint : At point Y
  184. Color : Painted colors
  185. ******************************************************************************/
  186. void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color)
  187. {
  188. if(Xpoint > Paint.Width || Ypoint > Paint.Height){
  189. Debug("Exceeding display boundaries\r\n");
  190. return;
  191. }
  192. UWORD X, Y;
  193. switch(Paint.Rotate) {
  194. case 0:
  195. X = Xpoint;
  196. Y = Ypoint;
  197. break;
  198. case 90:
  199. X = Paint.WidthMemory - Ypoint - 1;
  200. Y = Xpoint;
  201. break;
  202. case 180:
  203. X = Paint.WidthMemory - Xpoint - 1;
  204. Y = Paint.HeightMemory - Ypoint - 1;
  205. break;
  206. case 270:
  207. X = Ypoint;
  208. Y = Paint.HeightMemory - Xpoint - 1;
  209. break;
  210. default:
  211. return;
  212. }
  213. switch(Paint.Mirror) {
  214. case MIRROR_NONE:
  215. break;
  216. case MIRROR_HORIZONTAL:
  217. X = Paint.WidthMemory - X - 1;
  218. break;
  219. case MIRROR_VERTICAL:
  220. Y = Paint.HeightMemory - Y - 1;
  221. break;
  222. case MIRROR_ORIGIN:
  223. X = Paint.WidthMemory - X - 1;
  224. Y = Paint.HeightMemory - Y - 1;
  225. break;
  226. default:
  227. return;
  228. }
  229. if(X > Paint.WidthMemory || Y > Paint.HeightMemory){
  230. Debug("Exceeding display boundaries\r\n");
  231. return;
  232. }
  233. if(Paint.Scale == 2){
  234. UDOUBLE Addr = X / 8 + Y * Paint.WidthByte;
  235. UBYTE Rdata = Paint.Image[Addr];
  236. if(Color == BLACK)
  237. Paint.Image[Addr] = Rdata & ~(0x80 >> (X % 8));
  238. else
  239. Paint.Image[Addr] = Rdata | (0x80 >> (X % 8));
  240. }else if(Paint.Scale == 4){
  241. UDOUBLE Addr = X / 4 + Y * Paint.WidthByte;
  242. Color = Color % 4;//Guaranteed color scale is 4 --- 0~3
  243. UBYTE Rdata = Paint.Image[Addr];
  244. Rdata = Rdata & (~(0xC0 >> ((X % 4)*2)));
  245. Paint.Image[Addr] = Rdata | ((Color << 6) >> ((X % 4)*2));
  246. }else if(Paint.Scale == 16) {
  247. UDOUBLE Addr = X / 2 + Y * Paint.WidthByte;
  248. UBYTE Rdata = Paint.Image[Addr];
  249. Color = Color % 16;
  250. Rdata = Rdata & (~(0xf0 >> ((X % 2)*4)));
  251. Paint.Image[Addr] = Rdata | ((Color << 4) >> ((X % 2)*4));
  252. }else if(Paint.Scale == 65) {
  253. OLED_1in27_rgb_Set_Point(X, Y, Color);
  254. }
  255. }
  256. /******************************************************************************
  257. function: Clear the color of the picture
  258. parameter:
  259. Color : Painted colors
  260. ******************************************************************************/
  261. void Paint_Clear(UWORD Color)
  262. {
  263. if(Paint.Scale == 2 || Paint.Scale == 4) {
  264. for (UWORD Y = 0; Y < Paint.HeightByte; Y++) {
  265. for (UWORD X = 0; X < Paint.WidthByte; X++ ) {//8 pixel = 1 byte
  266. UDOUBLE Addr = X + Y*Paint.WidthByte;
  267. Paint.Image[Addr] = Color;
  268. }
  269. }
  270. }else if(Paint.Scale == 16) {
  271. for (UWORD Y = 0; Y < Paint.HeightByte; Y++) {
  272. for (UWORD X = 0; X < Paint.WidthByte; X++ ) {//8 pixel = 1 byte
  273. UDOUBLE Addr = X + Y*Paint.WidthByte;
  274. Color = Color & 0x0f;
  275. Paint.Image[Addr] = (Color<<4) | Color;
  276. }
  277. }
  278. }else if(Paint.Scale == 65) {
  279. for (UWORD Y = 0; Y < Paint.HeightByte; Y++) {
  280. for (UWORD X = 0; X < Paint.WidthByte; X++ ) {//8 pixel = 1 byte
  281. OLED_1in27_rgb_Set_Point(X, Y, Color);
  282. }
  283. }
  284. }
  285. }
  286. /******************************************************************************
  287. function: Clear the color of a window
  288. parameter:
  289. Xstart : x starting point
  290. Ystart : Y starting point
  291. Xend : x end point
  292. Yend : y end point
  293. Color : Painted colors
  294. ******************************************************************************/
  295. void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color)
  296. {
  297. UWORD X, Y;
  298. for (Y = Ystart; Y < Yend; Y++) {
  299. for (X = Xstart; X < Xend; X++) {//8 pixel = 1 byte
  300. Paint_SetPixel(X, Y, Color);
  301. }
  302. }
  303. }
  304. /******************************************************************************
  305. function: Draw Point(Xpoint, Ypoint) Fill the color
  306. parameter:
  307. Xpoint : The Xpoint coordinate of the point
  308. Ypoint : The Ypoint coordinate of the point
  309. Color : Painted color
  310. Dot_Pixel : point size
  311. Dot_Style : point Style
  312. ******************************************************************************/
  313. void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color,
  314. DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style)
  315. {
  316. if (Xpoint > Paint.Width || Ypoint > Paint.Height) {
  317. Debug("Paint_DrawPoint Input exceeds the normal display range\r\n");
  318. printf("Xpoint = %d , Paint.Width = %d \r\n ",Xpoint,Paint.Width);
  319. printf("Ypoint = %d , Paint.Height = %d \r\n ",Ypoint,Paint.Height);
  320. return;
  321. }
  322. int16_t XDir_Num , YDir_Num;
  323. if (Dot_Style == DOT_FILL_AROUND) {
  324. for (XDir_Num = 0; XDir_Num < 2 * Dot_Pixel - 1; XDir_Num++) {
  325. for (YDir_Num = 0; YDir_Num < 2 * Dot_Pixel - 1; YDir_Num++) {
  326. if(Xpoint + XDir_Num - Dot_Pixel < 0 || Ypoint + YDir_Num - Dot_Pixel < 0)
  327. break;
  328. // printf("x = %d, y = %d\r\n", Xpoint + XDir_Num - Dot_Pixel, Ypoint + YDir_Num - Dot_Pixel);
  329. Paint_SetPixel(Xpoint + XDir_Num - Dot_Pixel, Ypoint + YDir_Num - Dot_Pixel, Color);
  330. }
  331. }
  332. } else {
  333. for (XDir_Num = 0; XDir_Num < Dot_Pixel; XDir_Num++) {
  334. for (YDir_Num = 0; YDir_Num < Dot_Pixel; YDir_Num++) {
  335. Paint_SetPixel(Xpoint + XDir_Num - 1, Ypoint + YDir_Num - 1, Color);
  336. }
  337. }
  338. }
  339. }
  340. /******************************************************************************
  341. function: Draw a line of arbitrary slope
  342. parameter:
  343. Xstart :Starting Xpoint point coordinates
  344. Ystart :Starting Xpoint point coordinates
  345. Xend :End point Xpoint coordinate
  346. Yend :End point Ypoint coordinate
  347. Color :The color of the line segment
  348. Line_width : Line width
  349. Line_Style: Solid and dotted lines
  350. ******************************************************************************/
  351. void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend,
  352. UWORD Color, DOT_PIXEL Line_width, LINE_STYLE Line_Style)
  353. {
  354. if (Xstart > Paint.Width || Ystart > Paint.Height ||
  355. Xend > Paint.Width || Yend > Paint.Height) {
  356. Debug("Paint_DrawLine Input exceeds the normal display range\r\n");
  357. return;
  358. }
  359. UWORD Xpoint = Xstart;
  360. UWORD Ypoint = Ystart;
  361. int dx = (int)Xend - (int)Xstart >= 0 ? Xend - Xstart : Xstart - Xend;
  362. int dy = (int)Yend - (int)Ystart <= 0 ? Yend - Ystart : Ystart - Yend;
  363. // Increment direction, 1 is positive, -1 is counter;
  364. int XAddway = Xstart < Xend ? 1 : -1;
  365. int YAddway = Ystart < Yend ? 1 : -1;
  366. //Cumulative error
  367. int Esp = dx + dy;
  368. char Dotted_Len = 0;
  369. for (;;) {
  370. Dotted_Len++;
  371. //Painted dotted line, 2 point is really virtual
  372. if (Line_Style == LINE_STYLE_DOTTED && Dotted_Len % 3 == 0) {
  373. //Debug("LINE_DOTTED\r\n");
  374. if(Color)
  375. Paint_DrawPoint(Xpoint, Ypoint, BLACK, Line_width, DOT_STYLE_DFT);
  376. else
  377. Paint_DrawPoint(Xpoint, Ypoint, WHITE, Line_width, DOT_STYLE_DFT);
  378. Dotted_Len = 0;
  379. } else {
  380. Paint_DrawPoint(Xpoint, Ypoint, Color, Line_width, DOT_STYLE_DFT);
  381. }
  382. if (2 * Esp >= dy) {
  383. if (Xpoint == Xend)
  384. break;
  385. Esp += dy;
  386. Xpoint += XAddway;
  387. }
  388. if (2 * Esp <= dx) {
  389. if (Ypoint == Yend)
  390. break;
  391. Esp += dx;
  392. Ypoint += YAddway;
  393. }
  394. }
  395. }
  396. /******************************************************************************
  397. function: Draw a rectangle
  398. parameter:
  399. Xstart :Rectangular Starting Xpoint point coordinates
  400. Ystart :Rectangular Starting Xpoint point coordinates
  401. Xend :Rectangular End point Xpoint coordinate
  402. Yend :Rectangular End point Ypoint coordinate
  403. Color :The color of the Rectangular segment
  404. Line_width: Line width
  405. Draw_Fill : Whether to fill the inside of the rectangle
  406. ******************************************************************************/
  407. void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend,
  408. UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
  409. {
  410. if (Xstart > Paint.Width || Ystart > Paint.Height ||
  411. Xend > Paint.Width || Yend > Paint.Height) {
  412. Debug("Input exceeds the normal display range\r\n");
  413. return;
  414. }
  415. if (Draw_Fill) {
  416. UWORD Ypoint;
  417. for(Ypoint = Ystart; Ypoint < Yend; Ypoint++) {
  418. Paint_DrawLine(Xstart, Ypoint, Xend, Ypoint, Color , Line_width, LINE_STYLE_SOLID);
  419. }
  420. } else {
  421. Paint_DrawLine(Xstart, Ystart, Xend, Ystart, Color, Line_width, LINE_STYLE_SOLID);
  422. Paint_DrawLine(Xstart, Ystart, Xstart, Yend, Color, Line_width, LINE_STYLE_SOLID);
  423. Paint_DrawLine(Xend, Yend, Xend, Ystart, Color, Line_width, LINE_STYLE_SOLID);
  424. Paint_DrawLine(Xend, Yend, Xstart, Yend, Color, Line_width, LINE_STYLE_SOLID);
  425. }
  426. }
  427. /******************************************************************************
  428. function: Use the 8-point method to draw a circle of the
  429. specified size at the specified position->
  430. parameter:
  431. X_Center :Center X coordinate
  432. Y_Center :Center Y coordinate
  433. Radius :circle Radius
  434. Color :The color of the :circle segment
  435. Line_width: Line width
  436. Draw_Fill : Whether to fill the inside of the Circle
  437. ******************************************************************************/
  438. void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius,
  439. UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
  440. {
  441. if (X_Center > Paint.Width || Y_Center >= Paint.Height) {
  442. Debug("Paint_DrawCircle Input exceeds the normal display range\r\n");
  443. return;
  444. }
  445. //Draw a circle from(0, R) as a starting point
  446. int16_t XCurrent, YCurrent;
  447. XCurrent = 0;
  448. YCurrent = Radius;
  449. //Cumulative error,judge the next point of the logo
  450. int16_t Esp = 3 - (Radius << 1 );
  451. int16_t sCountY;
  452. if (Draw_Fill == DRAW_FILL_FULL) {
  453. while (XCurrent <= YCurrent ) { //Realistic circles
  454. for (sCountY = XCurrent; sCountY <= YCurrent; sCountY ++ ) {
  455. Paint_DrawPoint(X_Center + XCurrent, Y_Center + sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//1
  456. Paint_DrawPoint(X_Center - XCurrent, Y_Center + sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//2
  457. Paint_DrawPoint(X_Center - sCountY, Y_Center + XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//3
  458. Paint_DrawPoint(X_Center - sCountY, Y_Center - XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//4
  459. Paint_DrawPoint(X_Center - XCurrent, Y_Center - sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//5
  460. Paint_DrawPoint(X_Center + XCurrent, Y_Center - sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//6
  461. Paint_DrawPoint(X_Center + sCountY, Y_Center - XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//7
  462. Paint_DrawPoint(X_Center + sCountY, Y_Center + XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);
  463. }
  464. if (Esp < 0 )
  465. Esp += 4 * XCurrent + 6;
  466. else {
  467. Esp += 10 + 4 * (XCurrent - YCurrent );
  468. YCurrent --;
  469. }
  470. XCurrent ++;
  471. }
  472. } else { //Draw a hollow circle
  473. while (XCurrent <= YCurrent ) {
  474. Paint_DrawPoint(X_Center + XCurrent, Y_Center + YCurrent, Color, Line_width, DOT_STYLE_DFT);//1
  475. Paint_DrawPoint(X_Center - XCurrent, Y_Center + YCurrent, Color, Line_width, DOT_STYLE_DFT);//2
  476. Paint_DrawPoint(X_Center - YCurrent, Y_Center + XCurrent, Color, Line_width, DOT_STYLE_DFT);//3
  477. Paint_DrawPoint(X_Center - YCurrent, Y_Center - XCurrent, Color, Line_width, DOT_STYLE_DFT);//4
  478. Paint_DrawPoint(X_Center - XCurrent, Y_Center - YCurrent, Color, Line_width, DOT_STYLE_DFT);//5
  479. Paint_DrawPoint(X_Center + XCurrent, Y_Center - YCurrent, Color, Line_width, DOT_STYLE_DFT);//6
  480. Paint_DrawPoint(X_Center + YCurrent, Y_Center - XCurrent, Color, Line_width, DOT_STYLE_DFT);//7
  481. Paint_DrawPoint(X_Center + YCurrent, Y_Center + XCurrent, Color, Line_width, DOT_STYLE_DFT);//0
  482. if (Esp < 0 )
  483. Esp += 4 * XCurrent + 6;
  484. else {
  485. Esp += 10 + 4 * (XCurrent - YCurrent );
  486. YCurrent --;
  487. }
  488. XCurrent ++;
  489. }
  490. }
  491. }
  492. /******************************************************************************
  493. function: Show English characters
  494. parameter:
  495. Xpoint :X coordinate
  496. Ypoint :Y coordinate
  497. Acsii_Char :To display the English characters
  498. Font :A structure pointer that displays a character size
  499. Color_Foreground : Select the foreground color
  500. Color_Background : Select the background color
  501. ******************************************************************************/
  502. void Paint_DrawChar(UWORD Xpoint, UWORD Ypoint, const char Acsii_Char,
  503. sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)
  504. {
  505. UWORD Page, Column;
  506. if (Xpoint > Paint.Width || Ypoint > Paint.Height) {
  507. //Debug("Paint_DrawChar Input exceeds the normal display range\r\n");
  508. return;
  509. }
  510. uint32_t Char_Offset = (Acsii_Char - ' ') * Font->Height * (Font->Width / 8 + (Font->Width % 8 ? 1 : 0));
  511. const unsigned char *ptr = &Font->table[Char_Offset];
  512. for ( Page = 0; Page < Font->Height; Page ++ ) {
  513. for ( Column = 0; Column < Font->Width; Column ++ ) {
  514. //To determine whether the font background color and screen background color is consistent
  515. if (FONT_BACKGROUND == Color_Background) { //this process is to speed up the scan
  516. if (pgm_read_byte(ptr) & (0x80 >> (Column % 8)))
  517. Paint_SetPixel (Xpoint + Column, Ypoint + Page, Color_Foreground );
  518. } else {
  519. if (pgm_read_byte(ptr) & (0x80 >> (Column % 8))) {
  520. Paint_SetPixel (Xpoint + Column, Ypoint + Page, Color_Foreground );
  521. } else {
  522. Paint_SetPixel (Xpoint + Column, Ypoint + Page, Color_Background );
  523. }
  524. }
  525. //One pixel is 8 bits
  526. if (Column % 8 == 7) {
  527. ptr++;
  528. }
  529. }/* Write a line */
  530. if (Font->Width % 8 != 0) {
  531. ptr++;
  532. }
  533. }/* Write all */
  534. }
  535. /******************************************************************************
  536. function: Display the string
  537. parameter:
  538. Xstart :X coordinate
  539. Ystart :Y coordinate
  540. pString :The first address of the English string to be displayed
  541. Font :A structure pointer that displays a character size
  542. Color_Foreground : Select the foreground color
  543. Color_Background : Select the background color
  544. ******************************************************************************/
  545. void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString,
  546. sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)
  547. {
  548. UWORD Xpoint = Xstart;
  549. UWORD Ypoint = Ystart;
  550. if (Xstart > Paint.Width || Ystart > Paint.Height) {
  551. Debug("Paint_DrawString_EN Input exceeds the normal display range\r\n");
  552. return;
  553. }
  554. while (* pString != '\0') {
  555. //if X direction filled , reposition to(Xstart,Ypoint),Ypoint is Y direction plus the Height of the character
  556. if ((Xpoint + Font->Width ) > Paint.Width ) {
  557. Xpoint = Xstart;
  558. Ypoint += Font->Height;
  559. }
  560. // If the Y direction is full, reposition to(Xstart, Ystart)
  561. if ((Ypoint + Font->Height ) > Paint.Height ) {
  562. Xpoint = Xstart;
  563. Ypoint = Ystart;
  564. }
  565. Paint_DrawChar(Xpoint, Ypoint, * pString, Font, Color_Background, Color_Foreground);
  566. //The next character of the address
  567. pString ++;
  568. //The next word of the abscissa increases the font of the broadband
  569. Xpoint += Font->Width;
  570. }
  571. }
  572. /******************************************************************************
  573. function: Display the string
  574. parameter:
  575. Xstart :X coordinate
  576. Ystart :Y coordinate
  577. pString :The first address of the Chinese string and English
  578. string to be displayed
  579. Font :A structure pointer that displays a character size
  580. Color_Foreground : Select the foreground color
  581. Color_Background : Select the background color
  582. ******************************************************************************/
  583. void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font, UWORD Color_Background, UWORD Color_Foreground)
  584. {
  585. const unsigned char* p_text = pString;
  586. int refcolumn = Xstart;
  587. int i, j, Num;
  588. /* Send the string character by character on EPD */
  589. while (*p_text != 0) {
  590. if (*p_text < 0x7F) { //ASCII
  591. for (Num = 0; Num < font->size ; Num++) {
  592. if (*p_text == pgm_read_byte(&font->table[Num].index[0])) {
  593. const char* ptr = &font->table[Num].matrix[0];
  594. for (j = 0; j < font->Height; j++) {
  595. for (i = 0; i < font->Width; i++) {
  596. if (pgm_read_byte(ptr) & (0x80 >> (i % 8))) {
  597. Paint_SetPixel(refcolumn + i,Ystart + j, Color_Foreground);
  598. }
  599. if (i % 8 == 7) {
  600. ptr++;
  601. }
  602. }
  603. if (font->Width % 8 != 0) {
  604. ptr++;
  605. }
  606. }
  607. break;
  608. }
  609. }
  610. /* Point on the next character */
  611. p_text += 1;
  612. /* Decrement the column position by 16 */
  613. refcolumn += font->ASCII_Width;
  614. } else { //中文
  615. for (Num = 0; Num < font->size ; Num++) {
  616. 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]))) {
  617. const char* ptr = &font->table[Num].matrix[0];
  618. for (j = 0; j < font->Height; j++) {
  619. for (i = 0; i < font->Width; i++) {
  620. if (pgm_read_byte(ptr) & (0x80 >> (i % 8))) {
  621. Paint_SetPixel(refcolumn + i,Ystart + j, Color_Foreground);
  622. }
  623. if (i % 8 == 7) {
  624. ptr++;
  625. }
  626. }
  627. if (font->Width % 8 != 0) {
  628. ptr++;
  629. }
  630. }
  631. break;
  632. }
  633. }
  634. /* Point on the next character */
  635. p_text += 3;
  636. /* Decrement the column position by 16 */
  637. refcolumn += font->Width;
  638. }
  639. }
  640. }
  641. /******************************************************************************
  642. function: Display nummber
  643. parameter:
  644. Xstart :X coordinate
  645. Ystart : Y coordinate
  646. Number : The number displayed
  647. Font :A structure pointer that displays a character size
  648. Digit : Fractional width
  649. Color_Foreground : Select the foreground color
  650. Color_Background : Select the background color
  651. ******************************************************************************/
  652. #define ARRAY_LEN 255
  653. void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint,const char * Number,
  654. sFONT* Font, UWORD Digit,UWORD Color_Foreground, UWORD Color_Background)
  655. {
  656. uint8_t Str_Array[ARRAY_LEN] = {0};
  657. uint8_t *pStr = Str_Array;
  658. uint8_t i, len = 0;
  659. int16_t arr[2] = {0, -1};
  660. int16_t *p = arr;
  661. if (Xpoint > Paint.Width || Ypoint > Paint.Height) {
  662. Debug("Paint_DisNum Input exceeds the normal display range\r\n");
  663. return;
  664. }
  665. while(Number[len] != '\0') {
  666. len++; //get total length
  667. (*p)++; //get the integer part length
  668. if(Number[len] == '.') p++; //get fractional part length
  669. }
  670. if(Digit > 0) {
  671. if(Digit <= arr[1]) {
  672. for(i=0; i<len-(arr[1]-Digit); i++) //cut some Number
  673. Str_Array[i] = Number[i];
  674. }
  675. else {
  676. for(i=0; i<len+(Digit-arr[1]); i++) {
  677. if(i >= len) //add '0'
  678. Str_Array[i] = '0';
  679. else
  680. Str_Array[i] = Number[i];
  681. }
  682. }
  683. }
  684. else
  685. for(i=0; i<len; i++) {
  686. Str_Array[i] = Number[i];
  687. }
  688. //show
  689. Paint_DrawString_EN(Xpoint, Ypoint, (const char*)pStr, Font, Color_Background, Color_Foreground);
  690. }
  691. /******************************************************************************
  692. function: Display time
  693. parameter:
  694. Xstart :X coordinate
  695. Ystart : Y coordinate
  696. pTime : Time-related structures
  697. Font :A structure pointer that displays a character size
  698. Color_Foreground : Select the foreground color
  699. Color_Background : Select the background color
  700. ******************************************************************************/
  701. void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font,
  702. UWORD Color_Foreground, UWORD Color_Background)
  703. {
  704. uint8_t value[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
  705. UWORD Dx = Font->Width;
  706. //Write data into the cache
  707. Paint_DrawChar(Xstart , Ystart, value[pTime->Hour / 10], Font, Color_Background, Color_Foreground);
  708. Paint_DrawChar(Xstart + Dx , Ystart, value[pTime->Hour % 10], Font, Color_Background, Color_Foreground);
  709. Paint_DrawChar(Xstart + Dx + Dx / 4 + Dx / 2 , Ystart, ':' , Font, Color_Background, Color_Foreground);
  710. Paint_DrawChar(Xstart + Dx * 2 + Dx / 2 , Ystart, value[pTime->Min / 10] , Font, Color_Background, Color_Foreground);
  711. Paint_DrawChar(Xstart + Dx * 3 + Dx / 2 , Ystart, value[pTime->Min % 10] , Font, Color_Background, Color_Foreground);
  712. Paint_DrawChar(Xstart + Dx * 4 + Dx / 2 - Dx / 4, Ystart, ':' , Font, Color_Background, Color_Foreground);
  713. Paint_DrawChar(Xstart + Dx * 5 , Ystart, value[pTime->Sec / 10] , Font, Color_Background, Color_Foreground);
  714. Paint_DrawChar(Xstart + Dx * 6 , Ystart, value[pTime->Sec % 10] , Font, Color_Background, Color_Foreground);
  715. }
  716. /******************************************************************************
  717. function: Display monochrome bitmap
  718. parameter:
  719. image_buffer :A picture data converted to a bitmap
  720. info:
  721. Use a computer to convert the image into a corresponding array,
  722. and then embed the array directly into Imagedata.cpp as a .c file.
  723. ******************************************************************************/
  724. void Paint_DrawBitMap(const unsigned char* image_buffer)
  725. {
  726. UWORD x, y;
  727. UDOUBLE Addr = 0;
  728. for (y = 0; y < Paint.HeightByte; y++) {
  729. for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  730. Addr = x + y * Paint.WidthByte;
  731. Paint.Image[Addr] = (unsigned char)image_buffer[Addr];
  732. }
  733. }
  734. }
  735. ///******************************************************************************
  736. //function: SDisplay half of monochrome bitmap
  737. //parameter:
  738. // Region : 1 Upper half
  739. // 2 Lower half
  740. //info:
  741. //******************************************************************************/
  742. //void Paint_DrawBitMap_Half(const unsigned char* image_buffer, UBYTE Region)
  743. //{
  744. // UWORD x, y;
  745. // UDOUBLE Addr = 0;
  746. //
  747. // if(Region == 1){
  748. // for (y = 0; y < Paint.HeightByte; y++) {
  749. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  750. // Addr = x + y * Paint.WidthByte;
  751. // Paint.Image[Addr] = (unsigned char)image_buffer[Addr];
  752. // }
  753. // }
  754. // }else{
  755. // for (y = 0; y < Paint.HeightByte; y++) {
  756. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  757. // Addr = x + y * Paint.WidthByte ;
  758. // Paint.Image[Addr] = \
  759. // (unsigned char)image_buffer[Addr+ (Paint.HeightByte)*Paint.WidthByte];
  760. // }
  761. // }
  762. // }
  763. //}
  764. ///******************************************************************************
  765. //function: SDisplay half of monochrome bitmap
  766. //parameter:
  767. // Region : 1 Upper half
  768. // 2 Lower half
  769. //info:
  770. //******************************************************************************/
  771. //void Paint_DrawBitMap_OneQuarter(const unsigned char* image_buffer, UBYTE Region)
  772. //{
  773. // UWORD x, y;
  774. // UDOUBLE Addr = 0;
  775. //
  776. // if(Region == 1){
  777. // for (y = 0; y < Paint.HeightByte; y++) {
  778. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  779. // Addr = x + y * Paint.WidthByte;
  780. // Paint.Image[Addr] = (unsigned char)image_buffer[Addr];
  781. // }
  782. // }
  783. // }else if(Region == 2){
  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] = \
  788. // (unsigned char)image_buffer[Addr+ (Paint.HeightByte)*Paint.WidthByte];
  789. // }
  790. // }
  791. // }else if(Region == 3){
  792. // for (y = 0; y < Paint.HeightByte; y++) {
  793. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  794. // Addr = x + y * Paint.WidthByte ;
  795. // Paint.Image[Addr] = \
  796. // (unsigned char)image_buffer[Addr+ (Paint.HeightByte)*Paint.WidthByte*2];
  797. // }
  798. // }
  799. // }else if(Region == 4){
  800. // for (y = 0; y < Paint.HeightByte; y++) {
  801. // for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  802. // Addr = x + y * Paint.WidthByte ;
  803. // Paint.Image[Addr] = \
  804. // (unsigned char)image_buffer[Addr+ (Paint.HeightByte)*Paint.WidthByte*3];
  805. // }
  806. // }
  807. // }
  808. //}
  809. void Paint_DrawBitMap_Block(const unsigned char* image_buffer, UBYTE Region)
  810. {
  811. UWORD x, y;
  812. UDOUBLE Addr = 0;
  813. for (y = 0; y < Paint.HeightByte; y++) {
  814. for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
  815. Addr = x + y * Paint.WidthByte ;
  816. Paint.Image[Addr] = \
  817. (unsigned char)image_buffer[Addr+ (Paint.HeightByte)*Paint.WidthByte*(Region - 1)];
  818. }
  819. }
  820. }