?? painter.c
字號:
/*** $Id: painter.c,v 1.14.6.1 2006/06/16 01:15:49 xwyan Exp $**** A MiniGUI Painter.**** Copyright (C) 2001 ~ 2002 Wei Yongming** Copyright (C) 2003 ~ 2006 Feynman Software.**** Create date: 2001/11/01*//*** 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>#ifndef _USE_NEWGAL#error "***********************************************************************"#error "** This program needs New GAL of MiniGUI! **"#error "** Please run `./configure --enable-newgal' when configure MiniGUI, **"#error "** then build and reinstall MiniGUI. **"#error "***********************************************************************"#else#include "painter.h"#ifndef M_PI#define M_PI 3.14159265358979323846#endif#define DEFAULT_WIDTH 800#define DEFAULT_HEIGHT 600static HMENU createpmenuabout (void){ HMENU hmnu; MENUITEMINFO mii; memset (&mii, 0, sizeof(MENUITEMINFO)); mii.type = MFT_STRING; mii.id = 0; mii.typedata = (DWORD)"About..."; hmnu = CreatePopupMenu (&mii); memset (&mii, 0, sizeof(MENUITEMINFO)); mii.type = MFT_STRING ; mii.state = 0; mii.id = IDM_ABOUT_THIS; mii.typedata = (DWORD)"About MiniGUI Painter..."; InsertMenuItem(hmnu, 0, TRUE, &mii); memset (&mii, 0, sizeof(MENUITEMINFO)); mii.type = MFT_STRING ; mii.state = 0; mii.id = IDM_ABOUT; mii.typedata = (DWORD)"About MiniGUI..."; InsertMenuItem(hmnu, 1, TRUE, &mii); return hmnu;}static HMENU createpmenufile (void){ HMENU hmnu; MENUITEMINFO mii; memset (&mii, 0, sizeof(MENUITEMINFO)); mii.type = MFT_STRING; mii.id = 0; mii.typedata = (DWORD)"File"; hmnu = CreatePopupMenu (&mii); memset (&mii, 0, sizeof(MENUITEMINFO)); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_NEW; mii.typedata = (DWORD)"New"; InsertMenuItem(hmnu, 0, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_OPEN; mii.typedata = (DWORD)"Open..."; InsertMenuItem(hmnu, 1, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_SAVE; mii.typedata = (DWORD)"Save"; InsertMenuItem(hmnu, 2, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_SAVEAS; mii.typedata = (DWORD)"Save As..."; InsertMenuItem(hmnu, 3, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_CLOSE; mii.typedata = (DWORD)"Close"; InsertMenuItem(hmnu, 4, TRUE, &mii); mii.type = MFT_SEPARATOR; mii.state = 0; mii.id = 0; mii.typedata = 0; InsertMenuItem(hmnu, 5, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_EXIT; mii.typedata = (DWORD)"Exit"; InsertMenuItem(hmnu, 6, TRUE, &mii); return hmnu;}static HMENU createpmenuedit (void){ HMENU hmnu; MENUITEMINFO mii; memset (&mii, 0, sizeof(MENUITEMINFO)); mii.type = MFT_STRING; mii.id = 0; mii.typedata = (DWORD)"Edit"; hmnu = CreatePopupMenu (&mii); mii.type = MFT_STRING ; mii.state = 0; mii.id = IDM_COPY; mii.typedata = (DWORD)"Copy Screen"; InsertMenuItem(hmnu, 0, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_PASTE; mii.typedata = (DWORD)"Paste"; InsertMenuItem(hmnu, 1, TRUE, &mii); return hmnu;}static HMENU createpmenuobject (void){ HMENU hmnu; MENUITEMINFO mii; memset (&mii, 0, sizeof(MENUITEMINFO)); mii.type = MFT_STRING; mii.id = 0; mii.typedata = (DWORD)"Drawing Object"; hmnu = CreatePopupMenu (&mii); mii.type = MFT_STRING; mii.state = MF_CHECKED; mii.id = IDM_LINE; mii.typedata = (DWORD)"Line"; InsertMenuItem(hmnu, 0, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_ELLIPSE; mii.typedata = (DWORD)"Circle/Ellipse"; InsertMenuItem(hmnu, 1, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_RECT; mii.typedata = (DWORD)"Rectangle"; InsertMenuItem(hmnu, 2, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_ARC; mii.typedata = (DWORD)"CircleArc"; InsertMenuItem(hmnu, 3, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_SPLINE; mii.typedata = (DWORD)"Spline"; InsertMenuItem(hmnu, 4, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_FILLED_RECT; mii.typedata = (DWORD)"Filled Rectangle"; InsertMenuItem(hmnu, 5, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_FILLED_ELLIPSE; mii.typedata = (DWORD)"Filled Circle/Ellipse"; InsertMenuItem(hmnu, 6, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_FILLED_POLYGON; mii.typedata = (DWORD)"Filled Polygon"; InsertMenuItem(hmnu, 7, TRUE, &mii); mii.type = MFT_STRING; mii.state = 0; mii.id = IDM_FLOOD_FILL; mii.typedata = (DWORD)"Flood Fill"; InsertMenuItem(hmnu, 8, TRUE, &mii); return hmnu;}static HMENU createmenu (void){ HMENU hmnu; MENUITEMINFO mii; hmnu = CreateMenu(); memset (&mii, 0, sizeof(MENUITEMINFO)); mii.type = MFT_STRING; mii.id = 100; mii.typedata = (DWORD)"File"; mii.hsubmenu = createpmenufile (); InsertMenuItem(hmnu, 0, TRUE, &mii); mii.type = MFT_STRING; mii.id = 110; mii.typedata = (DWORD)"Edit"; mii.hsubmenu = createpmenuedit (); InsertMenuItem(hmnu, 1, TRUE, &mii); mii.type = MFT_STRING; mii.id = 120; mii.typedata = (DWORD)"Object"; mii.hsubmenu = createpmenuobject (); InsertMenuItem(hmnu, 2, TRUE, &mii); mii.type = MFT_STRING; mii.id = 130; mii.typedata = (DWORD)"About"; mii.hsubmenu = createpmenuabout (); InsertMenuItem(hmnu, 3, TRUE, &mii); return hmnu;}#define MAX_POINTS 40static int obj_type = IDM_LINE;static POINT pts [MAX_POINTS];static int cur_pt = 0;static int oldx = -1, oldy;static void DrawObject (HDC hdc){ switch (obj_type) { case IDM_LINE: if (cur_pt == 2) { MoveTo (hdc, pts[0].x, pts[0].y); LineTo (hdc, pts[1].x, pts[1].y); cur_pt = 0; oldx = -1; } break; case IDM_ELLIPSE: if (cur_pt == 2) { int rx = ABS (pts[1].x - pts[0].x); int ry = ABS (pts[1].y - pts[0].y); if (rx == ry) Circle (hdc, pts[0].x, pts[0].y, rx); else Ellipse (hdc, pts[0].x, pts[0].y, rx, ry); cur_pt = 0; oldx = -1; } break; case IDM_RECT: if (cur_pt == 2) { Rectangle (hdc, pts[0].x, pts[0].y, pts[1].x, pts[1].y); cur_pt = 0; oldx = -1; } break; case IDM_ARC: if (cur_pt == 3) { int sx = pts [0].x, sy = pts [0].y; int dx = pts [1].x - sx, dy = pts [1].y - sy; double r = sqrt (dx * dx + dy * dy); double cos_d = dx * 1.0 / r; double ang1 = acos (cos_d); int r2; double ang2; int a1, a2; if (dy > 0) { ang1 = -ang1; } dx = pts [2].x - sx; dy = pts [2].y - sy; r2 = sqrt (dx * dx * 1.0 + dy * dy * 1.0); cos_d = dx * 1.0 / r2;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -