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

📄 gdiopt.c

📁 飞漫公司的minigui的1.6.8收费增值版本的demon等示例程序
💻 C
📖 第 1 页 / 共 3 页
字号:
/*** $Id: gdiopt.c,v 1.12 2005/02/06 03:18:47 zxh 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>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>#ifdef _USE_NEWGAL#include <minigui/fixedmath.h>#endif#include "global.h"#ifndef M_PI#define M_PI  3.1415926#endif#define DEFAULT_WIDTH   DESKTOP_W#define DEFAULT_HEIGHT  DESKTOP_H#define DEFAULT_X       100#define DEFAULT_Y       60/*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);}*/#ifndef _USE_NEWGALstatic 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);}#endifextern BOOL scene_cmd_stop;#if 1/*#define CHECK_MSG                           \        {                                   \            MSG msg;                        \            if (HavePendingMessage (hwnd)) {\                GetMessage (&msg, hwnd);    \                TranslateMessage (&msg);    \                DispatchMessage (&msg);     \            }                               \        }static int CHECK_MSG(HWND hwnd){    MSG msg;    if (HavePendingMessage(hwnd)) {        GetMessage (&msg, hwnd);        TranslateMessage (&msg);        DispatchMessage (&msg);    }    if (scene_cmd_stop) {        scene_cmd_stop = FALSE;        return TRUE;    }    return FALSE;}*/#else#define CHECK_MSG#endifvoid GDIDemo_NormalLines (HWND hwnd, HDC hdc){#if 0    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 = 10000;    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;        if (CHECK_MSG(hwnd))            return;    }    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);        if (CHECK_MSG(hwnd))            return;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Circle", 10000);#ifdef _USE_NEWGAL    /* Ellipse */    start_tick = GetTickCount ();    count = 10000;    while (count--) {        tox = rand() % DEFAULT_WIDTH;        toy = rand() % DEFAULT_WIDTH;        SetPenColor (hdc, rand() % nr_colors);        Ellipse (hdc, tox, toy, rand() % DEFAULT_X, rand() % DEFAULT_Y);        if (CHECK_MSG(hwnd))            return;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Ellipse", 10000);    /* Arc */    start_tick = GetTickCount ();    count = 10000;    while (count--) {        tox = rand() % DEFAULT_WIDTH;        toy = rand() % DEFAULT_WIDTH;        SetPenColor (hdc, rand() % nr_colors);        CircleArc (hdc, tox, toy, rand() % DEFAULT_X, rand() % 360, rand() % 360);        if (CHECK_MSG(hwnd))            return;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "CircleArc", 10000);#endif#endif}void GDIDemo_XoredLines (HWND hwnd, HDC hdc){#if 0    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);#ifdef _USE_NEWGAL    /* XORed Line */    start_tick = GetTickCount ();    count = 10000;//    SetPenColor (hdc, PIXEL_lightwhite);    SetRasterOperation (hdc, ROP_XOR);    while (count--) {        SetPenColor (hdc, rand() % nr_colors);        MoveTo (hdc, x, y);        LineTo (hdc, tox, toy);        tox = rand() % DEFAULT_WIDTH;        toy = rand() % DEFAULT_WIDTH;        if (CHECK_MSG(hwnd))            return;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "XORed Line", 10000);    /* XORed 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);        if (CHECK_MSG(hwnd))            return;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "XORed Circle", 10000);    /* XORed Ellipse */    start_tick = GetTickCount ();    count = 10000;    while (count--) {        tox = rand() % DEFAULT_WIDTH;        toy = rand() % DEFAULT_WIDTH;        SetPenColor (hdc, rand() % nr_colors);        Ellipse (hdc, tox, toy, rand() % DEFAULT_X, rand() % DEFAULT_Y);        if (CHECK_MSG(hwnd))            return;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "XORed Ellipse", 10000);#else    TellNotImplemented (hwnd, "Xored Line");#endif#endif}void GDIDemo_Filling (HWND hwnd, HDC hdc){#if 0    int tox = DEFAULT_WIDTH, toy = DEFAULT_WIDTH;    int count;    unsigned int start_tick, end_tick;    unsigned int nr_colors = GetGDCapability (hdc, GDCAP_COLORNUM);#ifdef _USE_NEWGAL    /* Filled Box */    start_tick = GetTickCount ();    count = 1000;    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);        if (CHECK_MSG(hwnd))            return;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Filled Box", 1000);    /* Filled Rect with ROP */    SetRasterOperation (hdc, ROP_XOR);    start_tick = GetTickCount ();    count = 1000;    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);        if (CHECK_MSG(hwnd))            return;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Filled ROP Rect", 1000);    /* Filled Circle */    SetRasterOperation (hdc, ROP_SET);    start_tick = GetTickCount ();    count = 500;    while (count--) {        tox = rand() % DEFAULT_WIDTH;        toy = rand() % DEFAULT_WIDTH;        SetBrushColor (hdc, rand() % nr_colors);        FillCircle (hdc, tox, toy, rand() % DEFAULT_X);        if (CHECK_MSG(hwnd))            return;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Filled Circle", 500);    /* Filled Ellipse */    SetRasterOperation (hdc, ROP_SET);    start_tick = GetTickCount ();    count = 500;    while (count--) {        tox = rand() % DEFAULT_WIDTH;        toy = rand() % DEFAULT_WIDTH;        SetBrushColor (hdc, rand() % nr_colors);        FillEllipse (hdc, tox, toy, rand() % DEFAULT_X, rand() % DEFAULT_Y);        if (CHECK_MSG(hwnd))            return;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Filled Ellipse", 500);#else    /* 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);        if (CHECK_MSG(hwnd))            return;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Filled Box", 500);    TellNotImplemented (hwnd, "Filled Circle");#endif#endif}void GDIDemo_NormalBitmaps (HWND hwnd, HDC hdc){  ///*  int tox = DEFAULT_WIDTH, toy = DEFAULT_WIDTH;  //    int count;  //    BITMAP *bitmap = bmp_sample;  //    unsigned int start_tick, end_tick;  //    /* normal bitmap */  //    bitmap->bmColorKey = GetPixelInBitmap (bitmap, 0, 0);  //    start_tick = GetTickCount ();  //    count = 2;  //	tox = 0;  //	toy = 0;  //    while (count--) {  //		tox = tox + 10;  //        toy =  toy + 10;       //        FillBoxWithBitmap (hdc, tox, toy, 0, 0, bitmap);  //        if (CHECK_MSG(hwnd))  //            return;  //    }  //    end_tick = GetTickCount ();  //    TellSpeed (hwnd, start_tick, end_tick, "Normal Bitmap", 2000);  //#ifdef _USE_NEWGAL  //    return;  //    /* 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);  //        if (CHECK_MSG(hwnd))  //            return;  //    }  //    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);  //        if (CHECK_MSG(hwnd))  //            return;  //    }  //    end_tick = GetTickCount ();  //    TellSpeed (hwnd, start_tick, end_tick, "Ored Transparent Bitmap", 300);  //#endif  }void GDIDemo_TransparentBitmaps (HWND hwnd, HDC hdc){#if 0	int tox = DEFAULT_WIDTH, toy = DEFAULT_WIDTH;    int count;    BITMAP *bitmap = bmp_sail;    unsigned int start_tick, end_tick;#ifdef _USE_NEWGAL    /* Transparent bitmap */        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);        if (CHECK_MSG(hwnd))            return;    }    end_tick = GetTickCount ();    TellSpeed (hwnd, start_tick, end_tick, "Transparent Bitmap", 1000);#else    TellNotImplemented (hwnd, "Transparent Bitmap");#endif#endif}

⌨️ 快捷键说明

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