[BACK]Return to ChildView.cpp CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / windows / engine2000

Annotation of OpenXM_contrib2/windows/engine2000/ChildView.cpp, Revision 1.5

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>