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

📄 gdidemo.c

📁 minigui 1.6.10 高级例程 比game的例子多
💻 C
📖 第 1 页 / 共 3 页
字号:
        MoveTo (mem_dc, tox, toy);        SetPenColor (mem_dc, rand() % nr_colors);        tox = rand() % DEFAULT_WIDTH; toy = rand() % DEFAULT_WIDTH;        LineTo (mem_dc, tox, toy);        Circle (mem_dc, tox, toy, rand() % DEFAULT_X);        BitBlt (mem_dc, 0, 0, rand () % DEFAULT_WIDTH, rand () % DEFAULT_WIDTH, hdc,                         rand () % DEFAULT_WIDTH, rand () % DEFAULT_WIDTH, 0);        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Blit", 200);#ifdef _USE_NEWGAL    SetBrushColor (mem_dc, 0);    FillBox (mem_dc, 0, 0, 65535, 65535);    SetMemDCColorKey (mem_dc, MEMDC_FLAG_SRCCOLORKEY, 0);    start_tick = GetTickCount ();    count = 200;    while (count--) {        tox = rand() % DEFAULT_WIDTH; toy = rand() % DEFAULT_WIDTH;        MoveTo (mem_dc, tox, toy);        SetPenColor (mem_dc, rand() % nr_colors);        tox = rand() % DEFAULT_WIDTH; toy = rand() % DEFAULT_WIDTH;        LineTo (mem_dc, tox, toy);        Circle (mem_dc, tox, toy, rand() % DEFAULT_X);        BitBlt (mem_dc, 0, 0, rand () % DEFAULT_WIDTH, rand () % DEFAULT_WIDTH, hdc,                         rand () % DEFAULT_WIDTH, rand () % DEFAULT_WIDTH, 0);        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Transparent Blit", 200);#endif    DeleteCompatibleDC (mem_dc);#ifdef _USE_NEWGAL    /* Memory DC with alpha */    mem_dc = CreateMemDC (400, 100, 16, MEMDC_FLAG_HWSURFACE | MEMDC_FLAG_SRCALPHA,                    0x0000F000, 0x00000F00, 0x000000F0, 0x0000000F);    SetBrushColor (mem_dc, RGBA2Pixel (mem_dc, 0xFF, 0xFF, 0x00, 0x80));    FillBox (mem_dc, 0, 0, 200, 50);    SetBrushColor (mem_dc, RGBA2Pixel (mem_dc, 0xFF, 0x00, 0xFF, 0x80));    FillBox (mem_dc, 200, 0, 200, 50);    SetBrushColor (mem_dc, RGBA2Pixel (mem_dc, 0x00, 0xFF, 0xFF, 0x80));    FillBox (mem_dc, 0, 50, 200, 50);    SetBrushColor (mem_dc, RGBA2Pixel (mem_dc, 0xFF, 0xFF, 0xFF, 0x80));    FillBox (mem_dc, 200, 50, 200, 50);    SetTextColor (mem_dc, RGBA2Pixel (mem_dc, 0x00, 0x00, 0x00, 0x80));    SetBkColor (mem_dc, RGBA2Pixel (mem_dc, 0xFF, 0xFF, 0xFF, 0x80));    SetBkMode (mem_dc, BM_TRANSPARENT);    TabbedTextOut (mem_dc, 0, 0, "Memory DC with alpha.\n"                                 "The source DC have alpha per-pixel.");    start_tick = GetTickCount ();    count = 200;    while (count--) {        BitBlt (mem_dc, 0, 0, 400, 100, hdc, rand () % DEFAULT_WIDTH, rand () % DEFAULT_WIDTH, 0);        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Per-Pixel Alpha Blit", 200);    DeleteMemDC (mem_dc);    /* Memory DC with alpha*/    mem_dc = CreateMemDC (400, 100, 32, MEMDC_FLAG_HWSURFACE | MEMDC_FLAG_SRCALPHA | MEMDC_FLAG_SRCCOLORKEY,                    0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000);    SetBrushColor (mem_dc, RGB2Pixel (mem_dc, 0xFF, 0xFF, 0x00));    FillBox (mem_dc, 0, 0, 400, 100);    SetTextColor (mem_dc, RGB2Pixel (mem_dc, 0x00, 0x00, 0xFF));    SetBkColor (mem_dc, RGB2Pixel (mem_dc, 0x00, 0x00, 0x00));    SetBkMode (mem_dc, BM_TRANSPARENT);    TabbedTextOut (mem_dc, 0, 0, "Memory DC with alpha.\n"                                 "The source DC have alpha per-surface.");    start_tick = GetTickCount ();    count = 200;    while (count--) {        SetMemDCAlpha (mem_dc, MEMDC_FLAG_SRCALPHA | MEMDC_FLAG_RLEACCEL, rand () % 256);        BitBlt (mem_dc, 0, 0, 400, 100, hdc, rand () % DEFAULT_WIDTH, rand () % DEFAULT_WIDTH, 0);        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Per-Surface Alpha Blit", 200);    FillBox (mem_dc, 0, 0, 400, 100);    SetBrushColor (mem_dc, RGB2Pixel (mem_dc, 0xFF, 0x00, 0xFF));    FillBox (mem_dc, 200, 0, 400, 100);    TabbedTextOut (mem_dc, 0, 0, "Memory DC with alpha and colorkey.\n"                                 "The source DC have alpha per-surface.\n"                                 "And the source DC have a colorkey, \n"                                 "and RLE accelerated.");    SetMemDCColorKey (mem_dc, MEMDC_FLAG_SRCCOLORKEY | MEMDC_FLAG_RLEACCEL,                     RGB2Pixel (mem_dc, 0xFF, 0xFF, 0x00));    start_tick = GetTickCount ();    count = 200;    while (count--) {        SetMemDCAlpha (mem_dc, MEMDC_FLAG_SRCALPHA | MEMDC_FLAG_RLEACCEL, rand () % 256);        BitBlt (mem_dc, 0, 0, 400, 100, hdc, rand () % DEFAULT_WIDTH, rand () % DEFAULT_WIDTH, 0);        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Alpha and colorkey Blit", 200);    DeleteMemDC (mem_dc);#else    TellNotImplemented (hwnd, "Alpha Blit");#endif}#ifdef _USE_NEWGALstatic BLOCKHEAP my_cliprc_heap;static BOOL ch_inited = FALSE;static void GDIDemo_Region (HWND hWnd, HDC hdc){    CLIPRGN my_cliprgn1;    CLIPRGN my_cliprgn2;    CLIPRGN my_cliprgn3;    if (!ch_inited) {        InitFreeClipRectList (&my_cliprc_heap, 100);        ch_inited = TRUE;    }    InitClipRgn (&my_cliprgn1, &my_cliprc_heap);    InitClipRgn (&my_cliprgn2, &my_cliprc_heap);    InitClipRgn (&my_cliprgn3, &my_cliprc_heap);    InitCircleRegion (&my_cliprgn1, 100, 100, 60);    InitEllipseRegion (&my_cliprgn2, 100, 100, 50, 70);    SetBrushColor (hdc, PIXEL_blue);    FillBox (hdc, 0, 0, DEFAULT_WIDTH, 200);    SubtractRegion (&my_cliprgn1, &my_cliprgn1, &my_cliprgn2);    SelectClipRegion (hdc, &my_cliprgn1);    SetBrushColor (hdc, PIXEL_red);    FillBox (hdc, 0, 0, 180, 200);    InitCircleRegion (&my_cliprgn1, 300, 100, 60);    OffsetRegion (&my_cliprgn2, 200, 0);    XorRegion (&my_cliprgn1, &my_cliprgn1, &my_cliprgn2);    SelectClipRegion (hdc, &my_cliprgn1);    FillBox (hdc, 200, 0, 180, 200);    InitCircleRegion (&my_cliprgn1, 500, 100, 60);    OffsetRegion (&my_cliprgn2, 200, 0);    IntersectRegion (&my_cliprgn1, &my_cliprgn1, &my_cliprgn2);    SelectClipRegion (hdc, &my_cliprgn1);    FillBox (hdc, 400, 0, 180, 200);#if 0    {    static POINT pts [] = {        {400, 500},        {200, 200},        {500, 100},        {100, 50},    };    InitPolygonRegion (&my_cliprgn3, pts, 4);    SelectClipRegion (hdc, &my_cliprgn3);    SetBrushColor (hdc, PIXEL_green);    FillBox (hdc, 0, 0, DEFAULT_WIDTH, 200);        EmptyClipRgn (&my_cliprgn1);    EmptyClipRgn (&my_cliprgn2);    EmptyClipRgn (&my_cliprgn3);    }#endif    /* You should not forget to destroy the FreeClipRectList in your applications */}#ifdef _ADV_2DAPIconst unsigned char stipple_bits [] = "\x81\x42\x24\x18\x18\x24\x42\x81";static STIPPLE my_stipple ={    8, 8, 1, 8,    stipple_bits};#if 1void GetPentagram (POINT * pts, int cx, int cy, int r){    /** size of pts must have more than 11 */    const double PI = 3.1514926;    /** r0: radius of inscribed circle*/    /** r : radius of circumcircle */    int r0 = (int) (r * cos (72 * PI / 180));    int i;    pts [0].x = 0;    pts [1].x = (int)(r0*cos (54*PI / 180));    pts [2].x = (int)(r*sin (72*PI/180));    pts [3].x = (int)(r0*cos(18*PI/180));    pts [4].x = (int)(r*cos(54*PI/180));    pts [5].x = (int)0;    pts [6].x = (int)((-r)*cos(54*PI/180));    pts [7].x = (int)((-r0)*cos(18*PI/180));    pts [8].x = (int)((-r)*sin(72*PI/180));    pts [9].x = (int)((-r0)*cos(54*PI/180));    pts [10].x = pts [0].x;    pts [0].y = r;    pts [1].y = (int)(r0*sin(54*PI/180));    pts [2].y = (int)(r*cos(72*PI/180));    pts [3].y = (int)((-r0)*sin(18*PI/180));    pts [4].y = (int)((-r)*(sin(54*PI/180)));    pts [5].y = (int)(-r0);    pts [6].y = (int)((-r)*(sin(54*PI/180)));    pts [7].y = (int)((-r0)*sin(18*PI/180));    pts [8].y = (int)(r*cos(72*PI/180));    pts [9].y = (int)(r0*sin(54*PI/180));    pts [10].y = pts [0].y;    /** parallel move */    for (i = 0; i < 11; ++i)    {        pts [i].x = pts [i].x + r + cx;        pts [i].y = pts [i].y + r + cy;    }}void GDIDemo_Adv2DAPI (HWND hWnd, HDC hdc){    POINT pt [11];    BITMAP bitmap;    int scr_center_x = g_rcScr.right / 2;    int scr_center_y = g_rcScr.bottom / 2;    int head_width = 160;    int head_height = 260;    int head_center_x = scr_center_x - head_width / 2;    int head_center_y = scr_center_y - head_height / 2;    int i = 0;    ARC arc_hat[1];    ARC arc_mouth [2];    int eye_width = 16;    if (LoadBitmap (hdc, &bitmap, "res/icon.bmp"))        return;    /** set pen and brush style */    SetPenType (hdc, PT_SOLID);    SetPenDashes (hdc, 0, (const unsigned char*)"\1\1", 2);    SetPenJoinStyle (hdc, PT_JOIN_BEVEL);    SetPenCapStyle (hdc, PT_CAP_ROUND);    SetBrushType (hdc, BT_SOLID);    /** head */    SetPenWidth (hdc, 3);    SetPenColor (hdc, PIXEL_darkgray);    ArcEx (hdc, head_center_x, head_center_y,         head_width, head_height, 130 * 64, 280 * 64);    SetBrushColor (hdc, PIXEL_lightgray);    FillArcEx (hdc, scr_center_x - head_width / 2,             scr_center_y - head_height / 2,             head_width, head_height, 0, 360 * 64);    /** hat shape*/    arc_hat [0].width = 240;    arc_hat [0].height = 240;    arc_hat [0].x = scr_center_x - arc_hat [0].width / 2;    arc_hat [0].y = scr_center_y - 180 - arc_hat [0].height / 2;    arc_hat [0].angle1 = 236 * 64;    arc_hat [0].angle2 = 68 * 64;    SetBrushType (hdc, BT_TILED);    SetBrushInfo (hdc, &bitmap, &my_stipple);    SetBrushColor (hdc, PIXEL_darkred);    SetBrushOrigin (hdc, arc_hat [0].x, arc_hat [0].y);    PolyFillArcEx (hdc, arc_hat, 1);         SetBrushType (hdc, BT_SOLID);    SetPenWidth (hdc, 1);    SetPenJoinStyle (hdc, PT_JOIN_ROUND);    SetPenColor (hdc, PIXEL_darkred);    LineEx (hdc, scr_center_x, scr_center_y - 178, scr_center_x - 65, scr_center_y - 80);    LineEx (hdc, scr_center_x, scr_center_y - 178, scr_center_x + 65, scr_center_y - 80);    LineEx (hdc, scr_center_x, scr_center_y - 178, scr_center_x, scr_center_y - 60);    LineEx (hdc, scr_center_x, scr_center_y - 178, scr_center_x - 30, scr_center_y - 65);    LineEx (hdc, scr_center_x, scr_center_y - 178, scr_center_x + 30, scr_center_y - 65);    LineEx (hdc, scr_center_x, scr_center_y - 178, scr_center_x - 50, scr_center_y - 72);    LineEx (hdc, scr_center_x, scr_center_y - 178, scr_center_x + 50, scr_center_y - 72);    /** eye */    SetPenWidth (hdc, 2);    SetPenColor (hdc, PIXEL_black);    SetBrushColor (hdc, PIXEL_black);    FillArcEx (hdc, scr_center_x - 30 - 20, scr_center_y - 60, 40, 60, 0, 360 * 64);    FillArcEx (hdc, scr_center_x + 30 - 20, scr_center_y - 60, 40, 60, 0, 360 * 64);    /** eye ball */    SetPenColor (hdc, PIXEL_lightwhite);    SetBrushColor (hdc, PIXEL_lightwhite);    FillArcEx (hdc, scr_center_x - 38 - eye_width / 2, scr_center_y - 20, eye_width, eye_width, 0, 360 * 64 );    FillArcEx (hdc, scr_center_x + 38 - eye_width / 2, scr_center_y - 20, eye_width, eye_width, 0, 360 * 64 );    /** draw quadrangle at face */    pt [0].x = scr_center_x + 60;    pt [0].y = scr_center_y + 60;    pt [1].x = pt [0].x;    pt [1].y = pt [0].y + 10;    pt [2].x = pt [0].x - 10;    pt [2].y = pt [0].y + 5;    pt [3].x = pt [0].x - 10;    pt [3].y = pt [0].y - 10;    pt [4].x = pt [0].x;    pt [4].y = pt [0].y;    SetBrushColor (hdc, PIXEL_darkgreen);    SetPenWidth (hdc, 1);    SetPenColor (hdc, PIXEL_black);    FillPolygon (hdc, pt, 5);    PolyLineEx (hdc, pt, 5);    for (i= 0; i < 5; ++i)    {        pt [i].x -= 30;        pt [i].y -= 30;    }    FillPolygon (hdc, pt, 5);    PolyLineEx (hdc, pt, 5);    for (i= 0; i < 5; ++i)    {        pt [i].x -= 90;        pt [i].y -= 80;    }    FillPolygon (hdc, pt, 5);    PolyLineEx (hdc, pt, 5);    /** draw GetPentagram at face*/    SetBrushColor (hdc, PIXEL_blue);    SetPenColor (hdc, PIXEL_darkblue);    GetPentagram (pt, scr_center_x - 60 - 10, scr_center_y - 40 , 10);    FillPolygon (hdc, pt, 11);    PolyLineEx (hdc, pt, 11);    GetPentagram (pt, scr_center_x + 60 - 10, scr_center_y - 40 , 10);    FillPolygon (hdc, pt, 11);    PolyLineEx (hdc, pt, 11);    SetBrushColor (hdc, PIXEL_red);    SetPenColor (hdc, PIXEL_darkred);    GetPentagram (pt, scr_center_x - 10, scr_center_y + 110, 10);    FillPolygon (hdc, pt, 11);    PolyLineEx (hdc, pt, 11);    /** line to fix nose */    SetPenWidth (hdc, 1);    SetPenColor (hdc, PIXEL_black);    ArcEx (hdc, scr_center_x - 100, scr_center_y - 125 , 200, 180, 216 * 64, 108 * 64);    /** nose */    SetBrushColor (hdc, PIXEL_red);     FillArcEx (hdc, scr_center_x - 20, scr_center_y + 20, 40, 40, 0, 360 * 64);    SetPenWidth (hdc, 2);    SetPenColor (hdc, PIXEL_darkred);    ArcEx (hdc, scr_center_x - 20, scr_center_y + 20, 40, 40, 0, 360 * 64);    /** mouth */    arc_mouth [0].width = 160;    arc_mouth [0].height = 140;    arc_mouth [0].x = scr_center_x - arc_mouth [0].width / 2;    arc_mouth [0].y = scr_center_y + 30 - arc_mouth [0].height / 2;    arc_mouth [0].angle1 = 220 * 64;    arc_mouth [0].angle2 = 100 * 64;    arc_mouth [1].width = 160;    arc_mouth [1].height = 170;    arc_mouth [1].x = scr_center_x - arc_mouth [1].width / 2;    arc_mouth [1].y = scr_center_y + 25 - arc_mouth [1].height / 2;    arc_mouth [1].angle1 = 220 * 64;    arc_mouth [1].angle2 = 100 * 64;        SetPenWidth (hdc, 6);    SetPenColor (hdc, PIXEL_darkred);    SetPenJoinStyle (hdc, PT_JOIN_BEVEL);    SetPenCapStyle (hdc, PT_CAP_ROUND);    PolyArcEx (hdc, arc_mouth, 2);    /** ear */    SetBrushColor (hdc, PIXEL_darkred);    FillArcEx (hdc, scr_center_x - 90 - 20, scr_center_y + 10 - 20,             40, 40, 60 * 64, 240 * 64);    FillArcEx (hdc, scr_center_x + 90 - 20, scr_center_y + 10 - 20,             40, 40, -120 * 64, 240 * 64);        UnloadBitmap (&bitmap);}#elsevoid GDIDemo_Adv2DAPI (HWND hWnd, HDC hdc){    POINT pt [10];    BITMAP bitmap;    pt[0].x = 80;    pt[0].y = 80;    pt[1].x = 70;    pt[1].y = 90;    pt[2].x = 90;    pt[2].y = 90;    pt[3].x = 80;    pt[3].y = 80;    SetPenType (hdc, PT_SOLID);    PolyLineEx (hdc, pt, 4);    return;    if (LoadBitmap (hdc, &bitmap, "res/sample.bmp"))        return;    SetPenType (hdc, PT_SOLID);    SetPenWidth (hdc, 5);    LineEx (hdc, 10, 10, 210, 10);    SetPenDashes (hdc, 0, "\5\5", 2);    SetPenType (hdc, PT_ON_OFF_DASH);    LineEx (hdc, 10, 20, 210, 20);    SetPenDashes (hdc, 0, "\x8\x8", 2);    SetPenType (hdc, PT_DOUBLE_DASH);    SetBrushType (hdc, BT_SOLID);    SetBrushColor (hdc, PIXEL_green);    SetBkColor (hdc, PIXEL_lightwhite);    LineEx (hdc, 10, 30, 210, 30);    SetPenDashes (hdc, 0, "\x10\x10", 2);    SetBrushType (hdc, BT_STIPPLED);    SetBrushInfo (hdc, &bitmap, &my_stipple);    SetPenWidth (hdc, 10);    LineEx (hdc, 10, 50, 210, 50);    MoveTo (hdc, 10, 60);    LineTo (hdc, 10, 120);

⌨️ 快捷键说明

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