⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 minigui 体系结构之四 图形抽象层和输入抽象层及 native engine 的实现(一).htm

📁 minigui--面向实时嵌入式系统的图形用户界面。此文档介绍了miniguide体系结构。
💻 HTM
📖 第 1 页 / 共 4 页
字号:
  57     char*   id;
  58
  59     // Initialization and termination
  60     BOOL    (*initgfx) (struct tagGFX* gfx);
  61     void    (*termgfx) (struct tagGFX* gfx);
  62
  63     // Phisical graphics context
  64     GAL_GC  phygc;
  65     int     bytes_per_phypixel;
  66     int     bits_per_phypixel;
  67     int     width_phygc;
  68     int     height_phygc;
  69     int     colors_phygc;
  70     BOOL    grayscale_screen;
  71
  72     // GC properties
  73     int     (*bytesperpixel) (GAL_GC gc);
  74     int     (*bitsperpixel) (GAL_GC gc);
  75     int     (*width) (GAL_GC gc);
  76     int     (*height) (GAL_GC gc);
  77     int     (*colors) (GAL_GC gc);
  78
  79     // Allocation and release of graphics context
  80     int     (*allocategc) (GAL_GC gc, int width, int height, int depth,
  81                 GAL_GC* newgc);
  82     void    (*freegc) (GAL_GC gc);
  83     void    (*setgc) (GAL_GC gc);
  84
  85     // Clipping of graphics context
  86     void    (*enableclipping) (GAL_GC gc);
  87     void    (*disableclipping) (GAL_GC gc);
  88     int     (*setclipping) (GAL_GC gc, int x1, int y1, int x2, int y2);
  89     int     (*getclipping) (GAL_GC gc, int* x1, int* y1, int* x2, int* y2);
  90
  91     // Background and foreground colors
  92     int     (*getbgcolor) (GAL_GC gc, gal_pixel* color);
  93     int     (*setbgcolor) (GAL_GC gc, gal_pixel color);
  94     int     (*getfgcolor) (GAL_GC gc, gal_pixel* color);
  95     int     (*setfgcolor) (GAL_GC gc, gal_pixel color);
  96
  97     // Convertion between gal_color and gal_pixel
  98     gal_pixel (*mapcolor) (GAL_GC gc, gal_color *color);
  99     int     (*unmappixel) (GAL_GC gc, gal_pixel pixel, gal_color* color);
 100     int     (*packcolors) (GAL_GC gc, void* buf, gal_color* colors, int len);
 101     int     (*unpackpixels) (GAL_GC gc, void* buf, gal_color* colors, int len);
 102
 103     // Palette operations
 104     int     (*getpalette) (GAL_GC gc, int s, int len, gal_color* cmap);
 105     int     (*setpalette) (GAL_GC gc, int s, int len, gal_color* cmap);
 106     int     (*setcolorfulpalette) (GAL_GC gc);
 107
 108     // Box operations
 109     size_t  (*boxsize) (GAL_GC gc, int w, int h);
 110     int     (*fillbox) (GAL_GC gc, int x, int y, int w, int h,
 111                 gal_pixel pixel);
 112     int     (*putbox) (GAL_GC gc, int x, int y, int w, int h, void* buf);
 113     int     (*getbox) (GAL_GC gc, int x, int y, int w, int h, void* buf);
 114     int     (*putboxmask) (GAL_GC gc, int x, int y, int w, int h, void* buf, gal_pixel cxx);
 115     int     (*putboxpart) (GAL_GC gc, int x, int y, int w, int h, int bw,
 116                 int bh, void* buf, int xo, int yo);
 117     int     (*putboxwithop) (GAL_GC gc, int x, int y, int w, int h,
 118                 void* buf, int raster_op);
 119     int     (*scalebox) (GAL_GC gc, int sw, int sh, void* srcbuf,
 120                 int dw, int dh, void* dstbuf);
 121
 122     int     (*copybox) (GAL_GC gc, int x, int y, int w, int h, int nx, int ny);
 123     int     (*crossblit) (GAL_GC src, int sx, int sy, int sw, int sh,
 124                 GAL_GC dst, int dx, int dy);
 125
 126     // Horizontal line operaions
 127     int     (*drawhline) (GAL_GC gc, int x, int y, int w, gal_pixel pixel);
 128     int     (*puthline)  (GAL_GC gc, int x, int y, int w, void* buf);
 129     int     (*gethline)  (GAL_GC gc, int x, int y, int w, void* buf);
 130
 131     // Vertical line operations
 132     int     (*drawvline) (GAL_GC gc, int x, int y, int h, gal_pixel pixel);
 133     int     (*putvline)  (GAL_GC gc, int x, int y, int h, void* buf);
 134     int     (*getvline)  (GAL_GC gc, int x, int y, int h, void* buf);
 135
 136     // Pixel operations
 137     int     (*drawpixel) (GAL_GC gc, int x, int y, gal_pixel pixel);
 138     int     (*putpixel) (GAL_GC gc, int x, int y, gal_pixel color);
 139     int     (*getpixel) (GAL_GC gc, int x, int y, gal_pixel* color);
 140
 141     // Other drawing
 142     int     (*circle) (GAL_GC gc, int x, int y, int r, gal_pixel pixel);
 143     int     (*line) (GAL_GC gc, int x1, int y1, int x2, int y2,
 144                 gal_pixel pixel);
 145     int     (*rectangle) (GAL_GC gc, int l, int t, int r, int b,
 146                 gal_pixel pixel);
 147
 148     // Simple Character output
 149     int     (*putchar) (GAL_GC gc, int x, int y, char c);
 150     int     (*putstr) (GAL_GC gc, int x, int y, const char* str);
 151     int     (*getcharsize) (GAL_GC gc, int* width, int* height);
 152     int     (*setputcharmode) (GAL_GC gc, int bkmode);
 153     int     (*setfontcolors) (GAL_GC gc,
 154                 gal_pixel fg, gal_pixel bg);
 155
 156     // Asynchronous mode support
 157     void (*flush) (GAL_GC gc);
 158     void (*flushregion) (GAL_GC gc, int x, int y, int w, int h);
 159
 160     // Panic
 161     void (*panic) (int exitcode);
 162
 163 } GFX;
 164
 165 extern GFX* cur_gfx;
</PRE></TD></TR></TBODY></TABLE>
      <P>系统启动之后,将根据配置寻找特定的图形引擎作为当前的图形引擎,并且对全局变量 cur_gfx 赋值。之后,当 MiniGUI 
      需要在屏幕上进行绘制之后,调用当前图形引擎的相应功能函数。比如,在画水平线时如下调用:</P>
      <TABLE class=code-sample cellPadding=0 width="100%" border=0>
        <TBODY>
        <TR>
          <TD><PRE>(*cur_gfx-&gt;drawhline) (gc, x, y, w, pixel);
</PRE></TD></TR></TBODY></TABLE>
      <P>为方便程序书写,我们还定义了如下 C 语言宏:</P>
      <TABLE class=code-sample cellPadding=0 width="100%" border=0>
        <TBODY>
        <TR>
          <TD><PRE> 167 #define PHYSICALGC              (cur_gfx-&gt;phygc)
 168 #define BYTESPERPHYPIXEL        (cur_gfx-&gt;bytes_per_phypixel)
 169 #define BITSPERPHYPIXEL         (cur_gfx-&gt;bits_per_phypixel)
 170 #define WIDTHOFPHYGC            (cur_gfx-&gt;width_phygc)
 171 #define HEIGHTOFPHYGC           (cur_gfx-&gt;height_phygc)
 172 #define COLORSOFPHYGC           (cur_gfx-&gt;colors_phygc)
 173 #define GRAYSCALESCREEN         (cur_gfx-&gt;grayscale_screen)
 174
 175 #define GAL_BytesPerPixel       (*cur_gfx-&gt;bytesperpixel)
 176 #define GAL_BitsPerPixel        (*cur_gfx-&gt;bitsperpixel)
 177 #define GAL_Width               (*cur_gfx-&gt;width)
 178 #define GAL_Height              (*cur_gfx-&gt;height)
 179 #define GAL_Colors              (*cur_gfx-&gt;colors)
 180
 181 #define GAL_InitGfx             (*cur_gfx-&gt;initgfx)
 182 #define GAL_TermGfx             (*cur_gfx-&gt;termgfx)
 183
 184 #define GAL_AllocateGC          (*cur_gfx-&gt;allocategc)
 185 #define GAL_FreeGC              (*cur_gfx-&gt;freegc)
 186
 ...
198
 199 #define GAL_MapColor            (*cur_gfx-&gt;mapcolor)
 200 #define GAL_UnmapPixel          (*cur_gfx-&gt;unmappixel)
 201 #define GAL_PackColors          (*cur_gfx-&gt;packcolors)
 202 #define GAL_UnpackPixels        (*cur_gfx-&gt;unpackpixels)
 203
 ...
 208 #define GAL_BoxSize             (*cur_gfx-&gt;boxsize)
 209 #define GAL_FillBox             (*cur_gfx-&gt;fillbox)
 210 #define GAL_PutBox              (*cur_gfx-&gt;putbox)
 211 #define GAL_GetBox              (*cur_gfx-&gt;getbox)
 212 #define GAL_PutBoxMask          (*cur_gfx-&gt;putboxmask)
 213 #define GAL_PutBoxPart          (*cur_gfx-&gt;putboxpart)
 214 #define GAL_PubBoxWithOp        (*cur_gfx-&gt;putboxwithop)
 215 #define GAL_ScaleBox            (*cur_gfx-&gt;scalebox)
 ...
 224 #define GAL_DrawVLine           (*cur_gfx-&gt;drawvline)
 225 #define GAL_PutVLine            (*cur_gfx-&gt;putvline)
 226 #define GAL_GetVLine            (*cur_gfx-&gt;getvline)
</PRE></TD></TR></TBODY></TABLE>
      <P>这样,上述画线函数可以如下书写:</P>
      <TABLE class=code-sample cellPadding=0 width="100%" border=0>
        <TBODY>
        <TR>
          <TD><PRE>GAL_DrawVLine (gc, x, y, w, pixel);
</PRE></TD></TR></TBODY></TABLE>
      <P>显然,只要在系统初始化时能够根据设定对 cur_gfx 进行适当的赋值,MiniGUI 就能够在相应的图形引擎之上进行绘制。</P>
      <P>对底层图形引擎的调用,主要集中在 MiniGUI 的 GDI 函数中。比如,要绘制一条直线,MiniGUI 的 LineTo 函数定义如清单 
      2 所示:</P>
      <TABLE class=code-sample cellPadding=0 width="100%" border=0>
        <TBODY>
        <TR>
          <TD><PRE>                           清单 2   LineTo 函数(src/gdi/draw-lite.c)

 255 void GUIAPI LineTo (HDC hdc, int x, int y)
 256 {
 257     PCLIPRECT pClipRect;
 258     PDC pdc;
 259     RECT rcOutput;
 260     int startx, starty;
 261
 262     pdc = dc_HDC2PDC(hdc);
 263
 264     if (dc_IsGeneralHDC(hdc)) {
 265         if (!dc_GenerateECRgn (pdc, FALSE)) {
 266             return;
 267         }
 268     }
 269
 270     // Transfer logical to device to screen here.
 271     startx = pdc-&gt;CurPenPos.x;
 272     starty = pdc-&gt;CurPenPos.y;
 273
 274     // Move the current pen pos.
 275     pdc-&gt;CurPenPos.x = x;
 276     pdc-&gt;CurPenPos.y = y;
 277
 278     coor_LP2SP(pdc, &amp;x, &amp;y);
 279     coor_LP2SP(pdc, &amp;startx, &amp;starty);
 280     rcOutput.left = startx - 1;
 281     rcOutput.top  = starty - 1;
 282     rcOutput.right = x + 1;
 283     rcOutput.bottom = y + 1;
 284     NormalizeRect(&amp;rcOutput);
 285
 286     IntersectRect (&amp;rcOutput, &amp;rcOutput, &amp;pdc-&gt;ecrgn.rcBound);
 287     if( !dc_IsMemHDC(hdc) ) ShowCursorForGDI(FALSE, &amp;rcOutput);
 288
 289     // set graphics context.
 290     GAL_SetGC (pdc-&gt;gc);
 291     GAL_SetFgColor (pdc-&gt;gc, pdc-&gt;pencolor);
 292
 293     pClipRect = pdc-&gt;ecrgn.head;
 294     while(pClipRect)
 295     {
 296         if (DoesIntersect (&amp;rcOutput, &amp;pClipRect-&gt;rc)) {
 297             GAL_SetClipping (pdc-&gt;gc, pClipRect-&gt;rc.left, pClipRect-&gt;rc.top,
 298                     pClipRect-&gt;rc.right - 1, pClipRect-&gt;rc.bottom - 1);
 299
 300             if(starty == y) {
 301                 if (startx &gt; x)
 302                     GAL_DrawHLine (pdc-&gt;gc, x, y, startx - x, pdc-&gt;pencolor);
 303                 else
 304                     GAL_DrawHLine (pdc-&gt;gc, startx, y, x - startx, pdc-&gt;pencolor);
 305             }
 306             else
 307                 GAL_Line (pdc-&gt;gc, startx, starty, x, y, pdc-&gt;pencolor);
 308         }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -