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

📄 gdidemo.c

📁 minigui的相关资料建立minigui环境必需
💻 C
字号:
/*** $Id: gdidemo.c,v 1.31 2003/08/15 08:45:46 weiym Exp $**** The demo for GDI.**** Copyright (C) 2001 ~ 2002 Wei Yongming.** Copyright (C) 2003 Feynman Software.**** Create date: 2001/10/17*//***  This source is free software; you can redistribute it and/or**  modify it under the terms of the GNU General Public**  License as published by the Free Software Foundation; either**  version 2 of the License, or (at your option) any later version.****  This software is distributed in the hope that it will be useful,**  but WITHOUT ANY WARRANTY; without even the implied warranty of**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU**  General Public License for more details.****  You should have received a copy of the GNU General Public**  License along with this library; if not, write to the Free**  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,**  MA 02111-1307, USA*//*** TODO:*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <signal.h>#include <time.h>#include <sys/types.h>#include <sys/wait.h>#include <math.h>/* This isn't in the headers */#ifndef M_PI#define M_PI        3.14159265358979323846#endif#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>//#define DEFAULT_WIDTH   640//#define DEFAULT_HEIGHT  400#define DEFAULT_WIDTH   320#define DEFAULT_HEIGHT  240#define DEFAULT_X       320#define DEFAULT_Y       240/* defined in tesyuv.c *///void test_yuv(HWND hwnd, HDC hdc);static void TellSpeed (HWND hwnd, unsigned int start_tick, unsigned int end_tick, const char* drawing, unsigned int count){        char buff [1024];        unsigned int seconds = (end_tick - start_tick)/100;        sprintf (buff, "Draw %u %s(s) whthin %u seconds. \n\n"                        "Spend %f second for per-drawing.",                         count, drawing, seconds, (end_tick - start_tick) / (count * 100.0));        MessageBox (hwnd, buff, drawing, MB_OK | MB_ICONINFORMATION);}static void TellNotImplemented (HWND hwnd, const char* drawing){    char buff [1024];    sprintf (buff, "%s: not implemented. \n", drawing);    MessageBox (hwnd, buff, drawing, MB_OK | MB_ICONINFORMATION);}#if 0#define CHECK_MSG                           \        {                                   \            MSG msg;                        \            if (HavePendingMessage (hwnd)) {\                GetMessage (&msg, hwnd);    \                TranslateMessage (&msg);    \                DispatchMessage (&msg);     \            }                               \        }#else#define CHECK_MSG#endifstatic void GDIDemo_NormalLines (HWND hwnd, HDC hdc){    int x = DEFAULT_X, y = DEFAULT_Y;    int tox = DEFAULT_WIDTH, toy = DEFAULT_WIDTH;    int count;    unsigned int start_tick, end_tick;    unsigned int nr_colors = GetGDCapability (hdc, GDCAP_COLORNUM);    /* Line */    start_tick = GetTickCount ();    count = 100000;    SetPenColor (hdc, PIXEL_yellow);    while (count--) {        SetPenColor (hdc, rand() % nr_colors);        MoveTo (hdc, x, y);        LineTo (hdc, tox, toy);        tox = rand() % DEFAULT_WIDTH;        toy = rand() % DEFAULT_WIDTH;        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Line", 100000);    /* Circle */    start_tick = GetTickCount ();    count = 10000;    while (count--) {        tox = rand() % DEFAULT_WIDTH;        toy = rand() % DEFAULT_WIDTH;        SetPenColor (hdc, rand() % nr_colors);        Circle (hdc, tox, toy, rand() % DEFAULT_X);        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Circle", 10000);}static void GDIDemo_XoredLines (HWND hwnd, HDC hdc){    int x = DEFAULT_X, y = DEFAULT_Y;    int tox = DEFAULT_WIDTH, toy = DEFAULT_WIDTH;    int count;    unsigned int start_tick, end_tick;    unsigned int nr_colors = GetGDCapability (hdc, GDCAP_COLORNUM);    TellNotImplemented (hwnd, "Xored Line");}static void GDIDemo_Filling (HWND hwnd, HDC hdc){    int tox = DEFAULT_WIDTH, toy = DEFAULT_WIDTH;    int count;    unsigned int start_tick, end_tick;    unsigned int nr_colors = GetGDCapability (hdc, GDCAP_COLORNUM);    /* Filled Box */    start_tick = GetTickCount ();    count = 500;    while (count--) {        tox = rand() % DEFAULT_WIDTH;        toy = rand() % DEFAULT_WIDTH;        SetBrushColor (hdc, rand() % nr_colors);        FillBox (hdc, tox, toy, rand() % DEFAULT_X, rand() % DEFAULT_Y);        CHECK_MSG;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Filled Box", 500);    TellNotImplemented (hwnd, "Filled Circle");}static void GDIDemo_NormalBitmaps (HWND hwnd, HDC hdc){    int tox = DEFAULT_WIDTH, toy = DEFAULT_WIDTH;    int count;    BITMAP bitmap;    unsigned int start_tick, end_tick;    if (LoadBitmap (hdc, &bitmap, "res/sample.bmp"))        return;        /* normal bitmap */    start_tick = GetTickCount ();    count = 2000;    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, "Normal Bitmap", 2000);    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;    TellNotImplemented (hwnd, "Transparent Bitmap");}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;    TellNotImplemented (hwnd, "Alpha Blended Bitmap");}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);    DeleteCompatibleDC (mem_dc);    TellNotImplemented (hwnd, "Alpha Blit");}int GDIDemoWinProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam){    unsigned int start_tick, end_tick;    HDC hdc;    switch (message) {        case MSG_CHAR:            srand (time (NULL));            hdc = GetClientDC (hWnd);            switch (wParam) {            case '0':                GDIDemo_NormalLines (hWnd, hdc);                break;		/*            case 'b':            case 'B':                GDIDemo_XoredLines (hWnd, hdc);                break;		*/            case '1':                GDIDemo_Filling (hWnd, hdc);                break;		/*            case '2':                GDIDemo_NormalBitmaps (hWnd, hdc);                break;            case 'e':            case 'E':                GDIDemo_TransparentBitmaps (hWnd, hdc);                break;            case 'f':            case 'F':                GDIDemo_AlphaBlendedBitmaps (hWnd, hdc);                break;		*/            case '2':                GDIDemo_MemDC (hWnd, hdc);                break;            case '3':                PostMessage (hWnd, MSG_CLOSE, 0, 0);                break;            }            ReleaseDC (hdc);            InvalidateRect (hWnd, NULL, TRUE);        break;        case MSG_PAINT:            hdc = BeginPaint (hWnd);            SetTextColor (hdc, PIXEL_black);            SetBkColor (hdc, PIXEL_lightwhite);            SetBkMode (hdc, BM_TRANSPARENT);            TabbedTextOut (hdc, 50, 20,                                  "Type '0': Drawing normal lines and curves.\n"                      //           "Type 'B': Drawing xored lines and curves.\n"                                 "Type '1': Drawing filled areas.\n"                      //           "Type '2': Drawing normal bitmaps.\n"                     //            "Type 'E': Drawing transparent bitmaps.\n"                     //            "Type 'F': Drawing alpha blending bitmaps.\n"                                 "Type '2' Memory DC and blitting.\n"                     //            "Type 'H': Animation.\n"                     //            "Type 'I': Complex region.\n"                     //            "Type 'J': YUV overlay display.\n"                                 "\nType '3' to quit.");            EndPaint (hWnd, hdc);            return 0;        case MSG_CLOSE:            DestroyMainWindow (hWnd);            PostQuitMessage (hWnd);        return 0;    }    return DefaultMainWinProc(hWnd, message, wParam, lParam);}static void InitCreateInfo (PMAINWINCREATE pCreateInfo){    pCreateInfo->dwStyle = WS_CAPTION | WS_VISIBLE;    pCreateInfo->dwExStyle = 0;    pCreateInfo->spCaption = "GDI Demo" ;    pCreateInfo->hMenu = 0;    pCreateInfo->hCursor = GetSystemCursor (0);    pCreateInfo->hIcon = 0;    pCreateInfo->MainWindowProc = GDIDemoWinProc;    pCreateInfo->lx = 0;     pCreateInfo->ty = 0;     pCreateInfo->rx = pCreateInfo->lx + DEFAULT_WIDTH;    pCreateInfo->by = pCreateInfo->ty + DEFAULT_HEIGHT;    pCreateInfo->iBkColor = PIXEL_lightwhite;     pCreateInfo->dwAddData = 0;    pCreateInfo->hHosting = HWND_DESKTOP;}int MiniGUIMain (int args, const char* arg[]){    MSG Msg;    MAINWINCREATE CreateInfo;    HWND hMainWnd;#if defined(_LITE_VERSION) && !(_STAND_ALONE)    int i;    const char* layer = NULL;    RECT max_rect = {0, 0, 0, 0};    for (i = 1; i < args; i++) {        if (strcmp (arg[i], "-layer") == 0) {            layer = arg[i + 1];            break;        }    }    GetLayerInfo (layer, &max_rect, NULL, NULL, NULL);    if (JoinLayer (layer, arg[0],                 max_rect.left, max_rect.top,                 max_rect.left + DEFAULT_WIDTH,                 max_rect.top + DEFAULT_HEIGHT) == INV_LAYER_HANDLE) {        printf ("JoinLayer: invalid layer handle.\n");        exit (1);    }#endif    InitCreateInfo (&CreateInfo);    hMainWnd = CreateMainWindow (&CreateInfo);    if (hMainWnd == HWND_INVALID)        return -1;    while (GetMessage (&Msg, hMainWnd)) {        TranslateMessage (&Msg);        DispatchMessage (&Msg);    }    MainWindowThreadCleanup (hMainWnd);    return 0;}#ifndef _LITE_VERSION#include <minigui/dti.c>#endif

⌨️ 快捷键说明

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