📄 gdidemo.c
字号:
/*** $Id: gdidemo.c,v 1.20 2005/02/18 08:30:35 lihong Exp $**** The gdi demo of minigui**** Copyright (C) 2004 Feynman Software.**** Create date: 2004/07/20*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <locale.h>#include <minigui/common.h>#include <minigui/minigui.h>#include <minigui/gdi.h>#include <minigui/window.h>#include <minigui/control.h>#include <minigui/mgext.h>#include "global.h"#include "meter.h"static const char* filename = "160.gif";static ANIMATION* anim = NULL;#define PI 3.1415926static int dmetrealfa = 0;static int metreflag = 0;static int sinalfa = 0;static HDC FontDc = 0;static int FontDCPosition = 0;static int DC_Position = 0;PLOGFONT font[16];#define FONT_MEMDC_WIDTH 300#define FONT_MEMDC_HIGHT 325#define DEMO_WINDOW_WIDTH 320#define DEMO_WINDOW_HIGHT 175int gdi_scene_init (HWND hWnd, MDSCENE *pScene);/*-------------------------------求指针坐标的函数--------------------------------*/void GetPinPoint(POINT x1, POINT x2, double alfa, int width, int height, POINT *x3, POINT *x4, POINT *x5){ double dRadPerDeg = 4.0*atan(1.0)/180.0; x3->x = x1.x - width * sin(alfa * dRadPerDeg); x3->y = x1.y - width * cos(alfa * dRadPerDeg); x4->x = x1.x - height* cos(alfa * dRadPerDeg); x4->y = x1.y + height * sin(alfa * dRadPerDeg); x5->x = x1.x + width * sin(alfa * dRadPerDeg); x5->y = x1.y + width * cos(alfa * dRadPerDeg);}/* ------------------------------- clock ---------------------------------- */const char *gdi_clock_tips[] = { "Clock Demo", NULL};static int clock_scene_init (HWND hWnd, MDSCENE *pScene){ gdi_scene_init (hWnd, pScene); return 0;}static int ClockProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam){ //printf("message = %d\n", message); switch (message) { case MSG_CHANGESIZE: { time_t seconds; SetTimer(hDlg, 110, 10); seconds = time((time_t *) NULL); SetWindowAdditionalData(hDlg,(DWORD)seconds); break; } case MSG_TIMER: { RECT rc; time_t seconds; seconds = time((time_t *) NULL); rc.left = 50; rc.top = 10; rc.right = 170; rc.bottom = 130; SetWindowAdditionalData(hDlg,(DWORD)seconds); InvalidateRect(hDlg, &rc, FALSE); break; } case MSG_PAINT: { HDC hdc; int i = 0; /* center of the clock */ int rx = 110; int ry = 80; POINT pt[5]; double alfa, alfa1; int x, y; time_t time_int; struct tm *ptime; hdc = BeginPaint(hDlg); SetBrushColor(hdc, PIXEL_lightwhite); FillBox(hdc, 0, 0, 240, 165); SetBrushColor(hdc, PIXEL_black); Circle(hdc, rx, ry, 1); FillCircle(hdc, rx, ry, 1); for(i = 0; i <= 360; i = i + 6) { x =(int)( rx + 60 * cos((float)i/180 * PI)); y =(int)( ry - 60 * sin((float)i/180 * PI)); if(i % 30 == 0) { SetPenColor(hdc, PIXEL_darkblue); Circle(hdc, x, y, 2); SetBrushColor(hdc, PIXEL_green); FillCircle(hdc, x, y, 2); } else { SetPixel(hdc, x, y, PIXEL_blue); } } /* gettime and paint */ time_int = GetWindowAdditionalData(hDlg); ptime = localtime(&time_int); /* paint the hour pin */ alfa1 = 90.0 - (ptime->tm_hour * 30.0 + ptime->tm_min * 0.5 + ptime->tm_sec * 0.5 / 60.0 ); alfa = alfa1 /180.0 * PI; x = rx + 30 * cos(alfa); y = ry - 30 * sin(alfa); //SetPenColor(hdc, PIXEL_black); //SetPenWidth(hdc, 1); pt[0].x = rx; pt[0].y = ry; pt[1].x = x; pt[1].y = y; GetPinPoint(pt[0], pt[1], alfa1, 3, 8, &pt[2], &pt[3], &pt[4]); SetBrushColor(hdc, PIXEL_darkgreen); FillPolygon(hdc, &pt[1], 4); //LineEx(hdc, rx, ry, x, y); if(ptime->tm_sec == 0) { /* paint the minute pin */ alfa1 = (90 - (ptime->tm_min) * 6 ); alfa = alfa1/180.0 * PI; x = rx + 40 * cos(alfa); y = ry - 40 * sin(alfa); } else { alfa1 = 90 - (ptime->tm_min * 6 ); alfa = alfa1/180.0 * PI; x = rx + 40 * cos(alfa); y = ry - 40 * sin(alfa); } alfa = alfa1/180.0 * PI; pt[0].x = rx; pt[0].y = ry; pt[1].x = x; pt[1].y = y; GetPinPoint(pt[0], pt[1], alfa1, 2, 8, &pt[2], &pt[3], &pt[4]); SetBrushColor(hdc, PIXEL_blue); FillPolygon(hdc, &pt[1], 4); /* paint the second pin */ x = rx + 50 * cos(((90 - ptime->tm_sec * 6 ))/180.0 * PI); y = ry - 50 * sin(((90 - ptime->tm_sec * 6 ))/180.0 * PI); SetPenWidth(hdc, 1); LineEx(hdc, rx, ry, x, y);#ifdef MGDEMO_ENGLISH FillBoxWithBitmap(hdc, DEMO_WINDOW_WIDTH - bmp_bk->bmWidth - 15, 5, bmp_bk->bmWidth, bmp_bk->bmHeight, bmp_bk_en); #else
FillBoxWithBitmap(hdc, DEMO_WINDOW_WIDTH - bmp_bk->bmWidth - 15, 5, bmp_bk->bmWidth, bmp_bk->bmHeight, bmp_bk);
#endif
EndPaint(hDlg, hdc); break; } case MSG_FIRSTCONTROLMSG: KillTimer(hDlg, 110); break; } return default_desktop_win_proc (hDlg, message, wParam, lParam);;}/* ------------------------------- meter ---------------------------------- */const char *gdi_meter_tips[] = { "Meter Demo", NULL};static int meter_scene_init (HWND hWnd, MDSCENE *pScene){ gdi_scene_init (hWnd, pScene); return 0;}void gdi_meter_deinit(HWND hWnd, MDSCENE *pScene){ release_meter(); ReleaseDC ( ((GDISCENE *)pScene)->hdc );}int MerterProc(HWND hDlg, int message, WPARAM wParam, LPARAM lParam){ switch (message) { case MSG_CHANGESIZE: { SetTimer(hDlg, 120, 10); dmetrealfa = 0; break; } case MSG_TIMER: { RECT rc; rc.left = 10; rc.top = 0; rc.right = DEMO_WINDOW_WIDTH; rc.bottom = DEMO_WINDOW_HIGHT; InvalidateRect(hDlg, &rc, FALSE); if(dmetrealfa == 180) { metreflag = 1; } else if(dmetrealfa == 0) { metreflag = 0; } if(metreflag == 1) { dmetrealfa --; } else { dmetrealfa ++; } break; } case MSG_PAINT: { HDC hdc; hdc = BeginPaint(hDlg); meter_paint(hdc, dmetrealfa); EndPaint(hDlg, hdc); break; } case MSG_FIRSTCONTROLMSG: KillTimer(hDlg, 120); break; } return default_desktop_win_proc (hDlg, message, wParam, lParam);}/* ------------------------------- wave ---------------------------------- */const char *gdi_wave_tips[] = { "Wave Demo", NULL};static int Wav_scene_init (HWND hWnd, MDSCENE *pScene){ gdi_scene_init (hWnd, pScene); return 0;}void gdi_wave_deinit(HWND hWnd, MDSCENE *pScene){ release_sin(); ReleaseDC ( ((GDISCENE *)pScene)->hdc );}int WaveProc(HWND hDlg, int message, WPARAM wParam, LPARAM lParam){ switch (message) { case MSG_CHANGESIZE: { SetTimer(hDlg, 130, 20); sinalfa = 0; break; } case MSG_TIMER: { RECT rc; rc.left = 10; rc.top = 2; rc.right = 310; rc.bottom = 172; InvalidateRect(hDlg, &rc, FALSE); if(sinalfa == 360) { sinalfa = 0; } else { sinalfa +=10; } break; } case MSG_PAINT: { HDC hdc; hdc = BeginPaint(hDlg); draw_sin(hdc, sinalfa); EndPaint(hDlg, hdc); break; } case MSG_FIRSTCONTROLMSG: KillTimer(hDlg, 130); break; } return default_desktop_win_proc (hDlg, message, wParam, lParam);}/* ------------------------------- animation ---------------------------------- */const char *gdi_animation_tips[] = { "Animation Demo", NULL};static int Animation_scene_init (HWND hWnd, MDSCENE *pScene){ gdi_scene_init (hWnd, pScene); if(anim == NULL) { anim = CreateAnimationFromGIF89aFile (HDC_SCREEN, filename); if (anim == NULL) return 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -