Annotation of OpenXM_contrib2/windows/engine2000/ChildView.cpp, Revision 1.2
1.1 noro 1: // ChildView.cpp : CChildView クラスの動作の定義を行います。
2: //
3:
4: #include "stdafx.h"
5: #include "ox_plot.h"
6: #include "ChildView.h"
7:
8: #ifdef _DEBUG
9: #define new DEBUG_NEW
10: #undef THIS_FILE
11: static char THIS_FILE[] = __FILE__;
12: #endif
13:
14: #include <math.h>
15:
16: extern "C" {
17: #include "ca.h"
18: #include "ifplot.h"
19:
20: #if defined(sun) && !defined(__svr4__)
21: #define EXP10(a) exp10(a)
22: #else
23: #define EXP10(a) pow(10.0,a)
24: #endif
25:
26: HANDLE hResizeNotify,hResizeNotify_Ack;
27: void destroy_canvas(struct canvas *);
28: void pline(int *,struct canvas *, HDC);
29: void draw_wideframe(struct canvas *, HDC);
30: double adjust_scale(double,double);
31: }
32: /////////////////////////////////////////////////////////////////////////////
33: // CChildView
34:
35: CChildView::CChildView()
36: {
37: can = 0;
38: }
39:
40: CChildView::~CChildView()
41: {
42: }
43:
44:
45: BEGIN_MESSAGE_MAP(CChildView,CWnd )
46: //{{AFX_MSG_MAP(CChildView)
47: ON_WM_PAINT()
48: ON_WM_LBUTTONDOWN()
49: ON_WM_MOUSEMOVE()
50: ON_WM_LBUTTONUP()
51: ON_COMMAND(ID_OPT_NOAXIS, OnOptNoaxis)
52: ON_UPDATE_COMMAND_UI(ID_OPT_NOAXIS, OnUpdateOptNoaxis)
53: ON_COMMAND(ID_OPT_PRECISE, OnOptPrecise)
54: ON_UPDATE_COMMAND_UI(ID_OPT_PRECISE, OnUpdateOptPrecise)
55: ON_COMMAND(ID_OPT_WIDE, OnOptWide)
56: ON_UPDATE_COMMAND_UI(ID_OPT_WIDE, OnUpdateOptWide)
57: //}}AFX_MSG_MAP
58: END_MESSAGE_MAP()
59:
60:
61: /////////////////////////////////////////////////////////////////////////////
62: // CChildView メッセージ ハンドラ
63:
64: BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs)
65: {
66: if (!CWnd::PreCreateWindow(cs))
67: return FALSE;
68:
69: cs.dwExStyle |= WS_EX_CLIENTEDGE;
70: cs.style &= ~WS_BORDER;
71: cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,
72: ::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL);
73: return TRUE;
74: }
75:
76: void CChildView::OnPaint()
77: {
78: CPaintDC dc(this); // 描画用のデバイス コンテキスト
79:
80: // TODO: メッセージ ハンドラのコードをここに追加してください。
81:
82: // 描画のために CWnd::OnPaint を呼び出してはいけません。
83: if ( can->mode == MODE_INTERACTIVE ) {
84: ::BitBlt(dc.m_hDC,0,0,can->width,can->height,can->pix,0,0,SRCCOPY);
85: } else {
86: if ( !can->wide ) {
87: ::BitBlt(dc.m_hDC,0,0,can->width,can->height,can->pix,0,0,SRCCOPY);
88: pline(0,can,dc.m_hDC);
89: } else
90: draw_wideframe(can,dc.m_hDC);
91: }
92: BringWindowToTop();
93: }
94:
95: void CChildView::OnPrint(CDC &dc)
96: {
97: DOCINFO docinfo;
98: NODE n;
99: int width,height,ratio,x,y;
100:
101: memset(&docinfo,0,sizeof(DOCINFO));
102: docinfo.cbSize = sizeof(DOCINFO);
103: docinfo.lpszDocName = "test";
104: docinfo.lpszOutput = 0;
105:
106: // black pen
107: CPen pen(PS_SOLID,0,(COLORREF)0);
108: dc.SelectObject(&pen);
109:
110: // black brush
111: CBrush brush((COLORREF)0);
112: dc.SelectObject(&brush);
113:
114: // setup
115: // isotropic mode
116: dc.SetMapMode(MM_ISOTROPIC);
117:
118: // the page size in device pixel
119: width = dc.GetDeviceCaps(HORZRES)*9/10;
120: height = dc.GetDeviceCaps(VERTRES)*9/10;
121:
122: dc.StartDoc(&docinfo);
123: dc.StartPage();
124:
125: if ( can->mode == MODE_INTERACTIVE ) {
126: // We want to associate precisely one printer pixel to
127: // one bitmap pixel
128: // if can->width/can->height > width/height
129: // then match the widths, else match the height
130: if ( can->width*height > can->height*width )
131: ratio = width/can->width;
132: else
133: ratio = height/can->height;
134:
135: // set the logical src bitmap size
136: dc.SetWindowExt(can->width*ratio,can->height*ratio);
137:
138: // set the viewport size and the origine in printer pixel
139: dc.SetViewportOrg(width/18,height/18);
140: dc.SetViewportExt(width,height);
141:
142: for ( n = can->history; n; n = NEXT(n) ) {
143: RealVect *rv = (RealVect *)n->body;
144: if ( rv->len == 2 ) {
145: // dc.SetPixel(rv->body[0],rv->body[1],0);
146: x = rv->body[0]*ratio;
147: y = rv->body[1]*ratio;
148: // dc.FillRect(CRect(x,y,x+1,y+1),&brush);
149: dc.FillRect(CRect(x-1,y-1,x+1,y+1),&brush);
150: } else if ( rv->len == 4 ) {
151: dc.MoveTo(rv->body[0]*ratio,rv->body[1]*ratio);
152: dc.LineTo(rv->body[2]*ratio,rv->body[3]*ratio);
153: }
154: }
155: } else {
156: // set the logical src bitmap size
157: dc.SetWindowExt(can->width,can->height);
158:
159: // set the viewport size and the origine in printer pixel
160: dc.SetViewportOrg(width/18,height/18);
161: dc.SetViewportExt(width,height);
162:
163: if ( can->mode == MODE_PLOT )
164: dc.Polyline(can->pa[0].pos,can->pa[0].length);
165: else
166: ::StretchBlt(dc.m_hDC,0,0,can->width,can->height,can->pix,
167: 0,0,can->width,can->height,SRCCOPY);
168: PrintAxis(dc);
169: }
170: dc.EndPage();
171: dc.EndDoc();
172: }
173:
174: void CChildView::PrintAxis(CDC &dc)
175: {
176: #define D 5
177:
1.2 ! noro 178: double w,w1,e,n;
1.1 noro 179: int x0,y0,x,y,xadj,yadj;
180: char buf[BUFSIZ];
181:
182: /* XXX : should be cleaned up */
183: if ( can->noaxis || (can->mode == MODE_PLOT && !can->pa) )
184: return;
185: if ( can->mode == MODE_INTERACTIVE )
186: return;
187:
188: xadj = yadj = 0;
189: if ( (can->xmin < 0) && (can->xmax > 0) ) {
190: x0 = (int)((can->width)*(-can->xmin/(can->xmax-can->xmin)));
191: dc.MoveTo(x0,0); dc.LineTo(x0,can->height);
192: } else if ( can->xmin >= 0 )
193: x0 = 0;
194: else
195: x0 = can->width-D;
196: if ( (can->ymin < 0) && (can->ymax > 0) ) {
197: y0 = (int)((can->height)*(can->ymax/(can->ymax-can->ymin)));
198: dc.MoveTo(0,y0); dc.LineTo(can->width,y0);
199: } else if ( can->ymin >= 0 )
200: y0 = can->height;
201: else
202: y0 = D;
203: w = can->xmax-can->xmin;
204: w1 = w * DEFAULTWIDTH/can->width;
205: e = adjust_scale(EXP10(floor(log10(w1))),w1);
206: for ( n = ceil(can->xmin/e); n*e<= can->xmax; n++ ) {
1.2 ! noro 207: x = (int)(can->width*(n*e-can->xmin)/w);
1.1 noro 208: dc.MoveTo(x,y0); dc.LineTo(x,y0-D);
209: sprintf(buf,"%g",n*e);
210: dc.TextOut(x+2,y0+2,buf,strlen(buf));
211: }
212: w = can->ymax-can->ymin;
213: w1 = w * DEFAULTHEIGHT/can->height;
214: e = adjust_scale(EXP10(floor(log10(w1))),w1);
215: for ( n = ceil(can->ymin/e); n*e<= can->ymax; n++ ) {
1.2 ! noro 216: y = (int)(can->height*(1-(n*e-can->ymin)/w));
1.1 noro 217: dc.MoveTo(x0,y); dc.LineTo(x0+D,y);
218: sprintf(buf,"%g",n*e);
219: if ( can->xmax <= 0 ) {
220: xadj = dc.GetOutputTextExtent(buf,strlen(buf)).cx;
221: }
222: dc.TextOut(x0+2-xadj,y+2,buf,strlen(buf));
223: }
224: }
225:
226: static CPoint start,prev;
227:
228: void CChildView::OnLButtonDown(UINT nFlags, CPoint point) {
229: start = point;
230: prev = point;
231: SetCapture();
232: CWnd::OnLButtonDown(nFlags,point);
233: }
234:
235: void CChildView::OnMouseMove(UINT nFlags, CPoint point) {
236: if ( nFlags & MK_LBUTTON ) {
237: CDC *pDC = GetDC();
238: CRect prevrect(start,prev),rect(start,point);
239: CSize size(1,1);
240:
241: pDC->DrawDragRect(&rect,size,&prevrect,size);
242: ReleaseDC(pDC);
243: prev = point;
244: }
245: CWnd::OnMouseMove(nFlags,point);
246: }
247:
248: void CChildView::OnLButtonUp(UINT nFlags, CPoint point) {
249: CDC *pDC = GetDC();
250: CRect rect(start,point);
251: CSize size(1,1);
252:
253: pDC->DrawDragRect(&rect,size,0,size);
254: ReleaseDC(pDC);
255: ReleaseCapture();
256: start_point = start; end_point = point;
257: current_can = can;
258: SetEvent(hResizeNotify);
259: WaitForSingleObject(hResizeNotify_Ack,(DWORD)-1);
260:
261: CWnd::OnLButtonUp(nFlags,point);
262: }
263:
264: void CChildView::DestroyCanvas() {
265: destroy_canvas(can);
266: }
267:
268: void CChildView::OnOptNoaxis()
269: {
270: // TODO: この位置にコマンド ハンドラ用のコードを追加してください
271: can->noaxis = !can->noaxis;
272: RedrawWindow();
273: }
274:
275: void CChildView::OnUpdateOptNoaxis(CCmdUI* pCmdUI)
276: {
277: // TODO: この位置に command update UI ハンドラ用のコードを追加してください
278: pCmdUI->SetCheck(can->noaxis);
279: }
280:
281: void CChildView::OnOptPrecise()
282: {
283: // TODO: この位置にコマンド ハンドラ用のコードを追加してください
284: can->precise = !can->precise;
285: }
286:
287: void CChildView::OnUpdateOptPrecise(CCmdUI* pCmdUI)
288: {
289: // TODO: この位置に command update UI ハンドラ用のコードを追加してください
290: pCmdUI->SetCheck(can->precise);
291: }
292:
293: void CChildView::OnOptWide()
294: {
295: // TODO: この位置にコマンド ハンドラ用のコードを追加してください
296: can->wide = !can->wide;
297: RedrawWindow();
298: }
299:
300: void CChildView::OnUpdateOptWide(CCmdUI* pCmdUI)
301: {
302: // TODO: この位置に command update UI ハンドラ用のコードを追加してください
303: pCmdUI->SetCheck(can->wide);
304: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>