gdidemo.c

来自「MDE 图形引擎」· C语言 代码 · 共 966 行 · 第 1/3 页

C
966
字号
        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Normal Bitmap", 2000);#ifdef _USE_NEWGAL    /* xored bitmap */    SetRasterOperation (hdc, ROP_XOR);    start_tick = GetTickCount ();    count = 200;    while (count--) {        tox = rand() % DEFAULT_WIDTH;        toy = rand() % DEFAULT_WIDTH;        FillBoxWithBitmap (hdc, tox - 100, toy - 100, 0, 0, &bitmap);        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Xored Normal Bitmap", 200);    /* xored transparent bitmap */    SetRasterOperation (hdc, ROP_OR);    bitmap.bmColorKey = GetPixelInBitmap (&bitmap, 0, 0);    start_tick = GetTickCount ();    count = 300;    while (count--) {        tox = rand() % DEFAULT_WIDTH;        toy = rand() % DEFAULT_WIDTH;        FillBoxWithBitmap (hdc, tox - 100, toy - 100, 0, 0, &bitmap);        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Ored Transparent Bitmap", 300);#endif    UnloadBitmap (&bitmap);}static void GDIDemo_TransparentBitmaps (HWND hwnd, HDC hdc){    int tox = DEFAULT_WIDTH, toy = DEFAULT_WIDTH;    int count;    BITMAP bitmap;    unsigned int start_tick, end_tick;#ifdef _USE_NEWGAL    /* Transparent bitmap */    if (LoadBitmap (hdc, &bitmap, "res/sail.bmp"))        return;        bitmap.bmType = BMP_TYPE_COLORKEY;    bitmap.bmColorKey = GetPixelInBitmap (&bitmap, 0, 0);    /* color key */    start_tick = GetTickCount ();    count = 1000;    while (count--) {        tox = rand() % DEFAULT_WIDTH;        toy = rand() % DEFAULT_WIDTH;        FillBoxWithBitmap (hdc, tox, toy, 0, 0, &bitmap);        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Transparent Bitmap", 1000);    UnloadBitmap (&bitmap);#else    TellNotImplemented (hwnd, "Transparent Bitmap");#endif}static void GDIDemo_AlphaBlendedBitmaps (HWND hwnd, HDC hdc){    int tox = DEFAULT_WIDTH, toy = DEFAULT_WIDTH;    int count;    BITMAP bitmap;    unsigned int start_tick, end_tick;#ifdef _USE_NEWGAL    if (LoadBitmap (hdc, &bitmap, "res/icon.bmp"))        return;    bitmap.bmType = BMP_TYPE_ALPHACHANNEL;    /* alpha blending */    start_tick = GetTickCount ();    count = 1000;    while (count--) {        tox = rand() % DEFAULT_WIDTH;        toy = rand() % DEFAULT_WIDTH;        bitmap.bmAlpha = rand() % 256;        FillBoxWithBitmap (hdc, tox, toy, 0, 0, &bitmap);        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Alpha Blended Bitmap", 1000);    bitmap.bmType = BMP_TYPE_ALPHACHANNEL | BMP_TYPE_COLORKEY;    bitmap.bmColorKey = GetPixelInBitmap (&bitmap, 0, 0);    /* alpha blending and transparent */    start_tick = GetTickCount ();    count = 1000;    while (count--) {        tox = rand() % DEFAULT_WIDTH;        toy = rand() % DEFAULT_WIDTH;        bitmap.bmAlpha = rand() % 256;        FillBoxWithBitmap (hdc, tox, toy, 0, 0, &bitmap);        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Alpha Blended Transparent Bitmap", 1000);    UnloadBitmap (&bitmap);#else    TellNotImplemented (hwnd, "Alpha Blended Bitmap");#endif}static void GDIDemo_MemDC (HWND hwnd, HDC hdc){    HDC mem_dc;    int tox = DEFAULT_WIDTH, toy = DEFAULT_WIDTH;    int count;    unsigned int start_tick, end_tick;    unsigned int nr_colors = GetGDCapability (hdc, GDCAP_COLORNUM);        /* Compatible DC */    mem_dc = CreateCompatibleDC (hdc);    SetBrushColor (mem_dc, 0);    FillBox (mem_dc, 0, 0, 65535, 65535);    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, "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;    if (!ch_inited) {        InitFreeClipRectList (&my_cliprc_heap, 100);        ch_inited = TRUE;    }    InitClipRgn (&my_cliprgn1, &my_cliprc_heap);    InitClipRgn (&my_cliprgn2, &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);    EmptyClipRgn (&my_cliprgn1);    EmptyClipRgn (&my_cliprgn2);    /* You should not forget to destroy the FreeClipRectList in your applications */}#define TEXT_WIDTH      630#define TEXT_HEIGHT     120#define LOGO_WIDTH      220#define LOGO_HEIGHT     68#define IDT_ANIMATION   100#define FRAME_SPEED     10      /* 10 frames per second */static BOOL anim_inited = FALSE;static HDC shadow;static HDC logo_layer;static HDC text_layer;static int text_line;static const char* text[] = {    "MiniGUI Version 1.2.3.",    "Copyright (C) 1998 ~ 2002 Feynman Software and others.",    "MiniGUI is free software, covered by the GNU Lesser General Public License, ",    "and you are welcome to change it and/or distribute copies of it under certain conditions. ",

⌨️ 快捷键说明

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