📄 gridsub.c
字号:
/*
IGRID - Interactive Gridding Program.
Copyright (c) 1995 Thng Cheok Hoey
This program 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 or License, or (at your option) any
later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY of FIT-
NESS 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 program; if not, write to the Free Software Foundation, Inc., 675 Mass
Ave, Cambridge, MA 02139, USA.
Author's email address: thng@mimicad.colorado.edu
*/
#include <windows.h>
#include <stdio.h>
#include <math.h>
#include "emgrid.h"
#include "geometry.h"
#include "mousemod.h"
long FAR PASCAL _export PaperWndProc (HWND, UINT, UINT, LONG) ;
void setdrawingcoord(HDC);
void lptodrawing(POINT point, dPOINT *);
extern void drawdottedrect(HDC, RECT);
extern mousemode *mouse, *internalmode, *usermode;
extern pointermode pointer;
extern moveobjectmode mover;
extern rotateobjectmode rotater;
extern resizeobjectmode resizer;
extern modifymode modifier;
extern addmode adder;
extern char *buffer;
extern int redrawflag;
extern long deskpixelwidth, deskpixelheight;
extern int cxViewport, cyViewport;
extern int cxmaxViewport, cymaxViewport;
extern int zoomfactor;
extern HWND hwndMain, hwndPaper;
extern HPEN hPenDotBlack, hPenSolidBlack, hPenSolidYellow;
extern HPEN hPenArray[];
extern HCURSOR hwait, harrow;
extern double viewwidth, viewheight;
extern double deskwidth, deskheight;
extern double xOffsetView, yOffsetView;
extern double paperxcenter, paperycenter;
extern blocklist unselected, selected, addon, copied, swaped;
static RECT enclosure;
static double psin, pcos;
long FAR PASCAL _export PaperWndProc(HWND hwnd, UINT message,
UINT wParam, LONG lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
dRECT drect;
HMENU hMenu;
switch (message){
case WM_CREATE:
return 0;
case WM_SIZE:
cxViewport = LOWORD(lParam);
cyViewport = HIWORD(lParam);
viewwidth = deskwidth * ((double)zoomfactor / 32.0) *
((double)cxViewport / cxmaxViewport);
viewheight = deskheight * ((double)zoomfactor / 32.0) *
((double)cyViewport / cymaxViewport);
if((xOffsetView + viewwidth) > deskwidth){
xOffsetView = deskwidth - viewwidth;
}
if((yOffsetView + viewheight) > deskheight){
yOffsetView = deskheight - viewheight;
}
return 0;
case WM_LBUTTONDOWN:
SetFocus(hwnd);
mouse->lbuttondown(hwnd, lParam);
if(mouse == &adder){
internalmode = mouse = usermode;
mouse->presstoolbar();
}
return 0 ;
case WM_LBUTTONDBLCLK:
mouse->ldblclk(hwnd, lParam);
return 0 ;
case WM_RBUTTONDOWN:
mouse->rbuttondown();
if(mouse == &adder){
internalmode = mouse = usermode;
mouse->presstoolbar();
}
return 0;
case WM_MOUSEMOVE:
if(wParam & MK_LBUTTON) mouse->ldownmove(hwnd, lParam);
else mouse->move(hwnd, lParam);
return 0;
case WM_LBUTTONUP:
mouse->lbuttonup(hwnd);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
setdrawingcoord(hdc);
if(redrawflag == DETAILS){
unselected.draw(hdc);
selected.highlight(hdc);
}
else{
unselected.outline(hdc);
selected.outline(hdc);
}
EndPaint(hwnd, &ps) ;
mouse->setflag(NO);
return 0;
case WM_DESTROY :
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
void setdrawingcoord(HDC hdc){
DWORD dw;
int xWinExt, xViewExt, nwidth;
SetMapMode (hdc, MM_ISOTROPIC) ;
SetWindowExt (hdc, (int)(deskpixelwidth / 2 * viewwidth / deskwidth),
(int)(deskpixelheight / 2 * viewheight / deskheight)) ;
SetViewportExt (hdc, cxViewport / 2, -cyViewport / 2) ;
SetWindowOrg (hdc,(int)(xOffsetView/deskwidth * deskpixelwidth),
(int)((yOffsetView+viewheight)/deskheight * deskpixelheight)) ;
dw = GetWindowExt(hdc);
xWinExt = LOWORD(dw);
dw = GetViewportExt(hdc);
xViewExt = LOWORD(dw);
nwidth = (int)(2.5 * xWinExt / xViewExt);
DeleteObject(hPenArray[1]);
DeleteObject(hPenArray[3]);
DeleteObject(hPenArray[5]);
DeleteObject(hPenArray[7]);
DeleteObject(hPenArray[9]);
DeleteObject(hPenArray[11]);
DeleteObject(hPenArray[13]);
DeleteObject(hPenArray[15]);
hPenArray[1] = CreatePen(PS_SOLID, nwidth, RGB(0, 0, 0));
hPenArray[3] = CreatePen(PS_SOLID, nwidth, RGB(0, 0, 255));
hPenArray[5] = CreatePen(PS_SOLID, nwidth, RGB(0, 255, 0));
hPenArray[7] = CreatePen(PS_SOLID, nwidth, RGB(0, 192, 192));
hPenArray[9] = CreatePen(PS_SOLID, nwidth, RGB(192, 0, 0));
hPenArray[11] = CreatePen(PS_SOLID, nwidth, RGB(192, 0, 192));
hPenArray[13] = CreatePen(PS_SOLID, nwidth, RGB(192, 192, 0));
hPenArray[15] = CreatePen(PS_SOLID, nwidth, RGB(192, 192, 192));
}
void lptodrawing(POINT point, dPOINT *loc){
loc->x = paperxcenter + (point.x * deskwidth) / deskpixelwidth;
loc->y = paperycenter + (point.y * deskheight) / deskpixelheight;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -