Gui_dispstring () function source code
1 void gui_dispstring (const char gui_uni_ptr * s) {2 int xadjust, yadjust, Xorg; 3 int fontsizey; 4 If (! S) 5 return; 6 gui_lock (); 7 fontsizey = gui_getfontdisty (); // obtain the font height 8 Xorg = gui_context.dispposx; // obtain the currently displayed X coordinate 9/* adjust vertical position */10 yadjust = gui_getyadjust (); 11 gui_context.dispposy-= yadjust; // adjust y 12 for (; * s; s ++) {13 gui_rect R; 14 int linenumchars = GUI _ getlinenumchars (S, 0x7fff); // The number of characters to display in the current line: 15 int xlinesize = GUI _ getlinedistx (S, linenumchars); // The current row is in the X direction The number of records 16/* Check if X-position needs to be changed due to H-alignment */17 switch (gui_context.textalign & tags) {18 case gui_ta_center: xadjust = xlinesize/2; break; 19 case gui_ta_right: xadjust = xlinesize; break; 20 default: xadjust = 0; 21} 22/* calculate the rectangular area of the content displayed in each row */23 R. x0 = gui_context.dispposx-= xadjust; // adjust x coordinates by horizontal alignment. x1 = R. x0 + xlinesize-1; 25 R. y0 = gui_context.d Ispposy; 26 R. y1 = R. y0 + fontsizey-1; 27 28 GUI _ displine (S, linenumchars, & R); // display the current line character 29 gui_context.dispposy = R in the calculated rectangle. y0; 30 s + = gui_uc _ numchars2numbytes (S, linenumchars); // starting from the first character, add 1 to the address, 31 if (* s = '\ n') | (* s =' \ R') {32 switch (gui_context.textalign & gui_ta_horizontal) {33 case gui_ta_center: 34 case gui_ta_right: 35 gui_context.dispposx = Xorg; 36 break; 37 default: 38 Gu I _context.dispposx = gui_context.lborder; 39 break; 40} 41 if (* s = '\ n') 42 gui_context.dispposy + = fontsizey; 43} else {44 records = R. x0 + xlinesize; 45} 46 If (* s = 0)/* end of string (last line) reached? */47 break; 48} 49 gui_context.dispposy + = yadjust; // 50 gui_context.textalign & = ~ Gui_ta_horizontal; // 51 gui_unlock (); 52}
String display Process Overview
<1> obtain the height and width of the selected font.
<2> read the number of characters in one row from the passed string parameters, and finally obtain the rectangular area of the corresponding line.
<3> pass the detailed information of a row to the row display function. The row display function displays the characters of a row in sequence based on the matching words in the font.
<4> if there are not only one row, re-calculate the coordinates displayed in the next row and repeat the <1, 2, 3> operation until the string is fully displayed.
========================================================== ========================================================== ================
Important detail analysis
========================================================== ========================================================== ================
1. Global variables for GUI running
Gui_context is the global variable used by the GUI to save the runtime environment. Its Type gui_context is defined in GUI. h.
Struct gui_context {/* variables in LCD module */LCD _colorindex_union LCD; LCD _rect cliprect; u8 drawmode; u8 sellayer; u8 textstyle;/* variables in GL module */gui_rect * numeric; /* High Level clip rectangle... speed Optimization So drawing routines can optimize */u8 pensize; u8 penshape; u8 linestyle; u8 fillstyle;/* variables in guichar module */const gui_font gui_uni_ptr * pafont; // point to the selected font # If your const character * puc_api;/* unicode encoding API */# endif i16p lborder; i16p dispposx, dispposy; i16p drawposx, drawposy; i16p textmode, textalign; // alignment mode gui_color, bkcolor;/* required only when changing devices and for speed OPT (caching) * // * variables in WM module */# If gui_winsupport const gui_rect * WM _ pusercliprect; gui_hwin hawin; int xoff, yoff; # endif/* variables in memdev module (with memory devices ONLY) */# If your const tlcddev_apilist * pdeviceapi;/* function pointers only */gui_hmem hdevdata; gui_rect cliprectprev; # endif/* variables in anitaliasing module */# If gui_support_aa const limit * plcd_hl;/* required to reroute drawing (hline & pixel) to the AA module */u8 aa_factor; u8 aa_hiresenable; # endif };
2. gui_font Definition
To call a font library by ucgui, You need to define it as a constant of the gui_gont type. This is required when you need to make your own font. The gui_font type is defined in the guitype. h file.
Struct gui_font {gui_dispchar * pfdispchar; // display a function gui_getchardistx * pfgetchardistx that belongs to the current font; // obtain the width of a character in the font gui_getfontinfo * pfgetfontin; // obtain the font information gui_isinfont * pfisinfont; // query whether the character const tgui_enc_apilist * pafencode exists in the font; // u8 ysize; // The height of u8 ydist; // The corresponding pixel u8 xmag; // The amplification coefficient u8 ymag in the X direction; // The amplification coefficient in the Y directionUnion {// This sharing body mainly provides the address for accessing the font data. // for different Font types, it searches for the font model from the font, yes. // there are three types of conditions: const void gui_uni_ptr * pfontdata; const gui_font_mono gui_uni_ptr * pmono; const gui_font_prop gui_uni_ptr *Pprop;} P;U8 baseline; // u8 lheight;/* height of a small lower case character (A, x) * // lower case height u8 cheight; /* height of a small upper case character (A, x) * // uppercase height };
(1)
Analysis of ucgui string display process