?? gdidemo.c
字號:
/*** $Id: gdidemo.c,v 1.47.2.1 2006/06/16 01:15:49 xwyan Exp $**** The demo for GDI.**** Copyright (C) 2001 ~ 2002 Wei Yongming.** Copyright (C) 2003 ~ 2006 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#define DEFAULT_WIDTH 640#define DEFAULT_HEIGHT 400#define DEFAULT_X 320#define DEFAULT_Y 200/* 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);}#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);}#endif#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);#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); CHECK_MSG; } end_tick = GetTickCount (); TellSpeed (hwnd, start_tick, end_tick, "Ellipse", 10000); /* CircleArc */ 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 * 64, (rand() % 360 - 180) * 64); CHECK_MSG; } end_tick = GetTickCount (); TellSpeed (hwnd, start_tick, end_tick, "CircleArc", 10000);#endif}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);#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; CHECK_MSG; } 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); CHECK_MSG; } 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); CHECK_MSG; } end_tick = GetTickCount (); TellSpeed (hwnd, start_tick, end_tick, "XORed Ellipse", 10000);#else TellNotImplemented (hwnd, "Xored Line");#endif}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);#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); CHECK_MSG; } 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); CHECK_MSG; } 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); CHECK_MSG; } 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); CHECK_MSG; } 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); CHECK_MSG; } end_tick = GetTickCount (); TellSpeed (hwnd, start_tick, end_tick, "Filled Box", 500); TellNotImplemented (hwnd, "Filled Circle");#endif}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);#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;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -