/* Line clipper */ BOOL GUIAPI LineClipper (const RECT* cliprc, int *_x0, int *_y0, int *_x1, int *_y1);
/* Line generators */ typedef void (* CB_LINE) (void* context, int stepx, int stepy); void GUIAPI LineGenerator (void* context, int x1, int y1, int x2, int y2, CB_LINE cb);
LineGenerator 是采用 Breshenham 算法的生成器。該生成器從給定直線的起始端點開始,每生成一個點調用一次 cb 回調函數,并傳遞上下文 context、以及新的點相對于上一個點的步進值或者差量。比如,傳遞 stepx =1,stepy = 0 表示新的點比上一個點在 X 軸上前進一步,而在 Y 軸上保持不變。回調函數可以在步進值基礎上實現某種程度上的優化。
2.2 圓生成器
MiniGUI 定義的圓生成器原型如下:
/* Circle generator */ typedef void (* CB_CIRCLE) (void* context, int x1, int x2, int y); void GUIAPI CircleGenerator (void* context, int sx, int sy, int r, CB_CIRCLE cb);
/* Ellipse generator */ typedef void (* CB_ELLIPSE) (void* context, int x1, int x2, int y); void GUIAPI EllipseGenerator (void* context, int sx, int sy, int rx, int ry, CB_ELLIPSE cb);
首先要指定橢圓心坐標以及 X 軸和 Y 軸半徑,并傳遞上下文信息以及回調函數,每生成一個點,生成器將調用一次 cb 回調函數,并傳遞三個值:x1、x2 和 y。這三個值實際表示了橢圓上的兩個點:(x1, y) 和 (x2, y)。因為橢圓的對稱性,生成器只要計算橢圓上的二分之一圓弧點即可得出橢圓上所有的點。
2.4 圓弧生成器
MiniGUI 定義的圓弧生成器如下所示:
/* Arc generator */ typedef void (* CB_ARC) (void* context, int x, int y); void GUIAPI ArcGenerator (void* context, int sx, int sy, int r, fixed ang1, fixed ang2, CB_ARC cb);
/* General Flood Filling generator */ typedef BOOL (* CB_EQUAL_PIXEL) (void* context, int x, int y); typedef void (* CB_FLOOD_FILL) (void* context, int x1, int x2, int y); BOOL GUIAPI FloodFillGenerator (void* context, const RECT* src_rc, int x, int y, CB_EQUAL_PIXEL cb_equal_pixel, CB_FLOOD_FILL cb_flood_fill);
static void _flood_fill_draw_hline (void* context, int x1, int x2, int y) { PDC pdc = (PDC)context; RECT rcOutput = {MIN (x1, x2), y, MAX (x1, x2) + 1, y + 1};