📄 dolview.cpp
字号:
// DOLView.cpp : implementation of the CDOLView class
//
#include "stdafx.h"
#include "DOL.h"
#include <math.h>
#include"SetDlg.h"
#include "DOLDoc.h"
#include "DOLView.h"
#define MAXN 100
#define TSMAX 8
#define pi 3.1415926
#include <iostream.h>
#include<string.h>
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDOLView
IMPLEMENT_DYNCREATE(CDOLView, CView)
BEGIN_MESSAGE_MAP(CDOLView, CView)
ON_WM_CONTEXTMENU()
//{{AFX_MSG_MAP(CDOLView)
ON_COMMAND(ID_draw, Ondraw)
ON_COMMAND(ID_selectcolor, Onselectcolor)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDOLView construction/destruction
CDOLView::CDOLView()
{
// TODO: add construction code here
/* Rule[0]='F';Rule[1]='F';Rule[2]='-'; //Tree that=30 ;w=F;
Rule[3]='[';Rule[4]='-';Rule[5]='F';
Rule[6]='+';Rule[7]='F';Rule[8]='+';
Rule[9]='F';Rule[10]=']'; Rule[11]='+';
Rule[12]='['; Rule[13]='+';Rule[14]='F';
Rule[15]='-';Rule[16]='F';Rule[17]='-';
Rule[18]='F';Rule[19]=']'; */
/* Rule[0][0]='F';Rule[0][1]='-';Rule[0][2]='F';
Rule[0][3]='+';Rule[0][4]='F'; Rule[0][5]='-';
Rule[0][6]='F';Rule[0][7]='-';Rule[0][8]='F'; */
/* Rule[0]='F';Rule[1]='-';Rule[2]='F';Rule[3]='+';
Rule[4]='F';Rule[5]='-';Rule[6]='F';Rule[7]='-';
Rule[8]='F'; */
/* Rule[0]='F';Rule[1]='F';Rule[2]='-';Rule[3]='F';
Rule[4]='-';Rule[5]='F';Rule[6]='-';Rule[7]='F';
Rule[8]='-';Rule[9]='F';Rule[10]='F';*/
//vonkoch-1
/* Rule[0]='F';Rule[1]='+'; //that=85;w=F
Rule[2]='F';Rule[3]='-';Rule[4]='-';Rule[5]='F';
Rule[6]='+';Rule[7]='F'; */
m_pColor=RGB(150,0,0);
}
CDOLView::~CDOLView()
{
}
BOOL CDOLView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CDOLView drawing
void CDOLView::OnDraw(CDC* pDC)
{
CDOLDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
TurDir=0;
TSSize=0;
/* drawtrue=pDoc->drawtrue;
str=pDoc->str;
Rule=pDoc->Rule;
Klevel=pDoc->Klevel;
Turx=pDoc->Turx;
Tury=pDoc->Tury;
v1=pDoc->v1;
v2=pDoc->v2;
that=pDoc->that;
stan=pDoc->stan;*/
if(drawtrue==1)
{ int i;
float s;
s=5.0;
for(i=0;i<Klevel;i++)stan=stan/s;
Draw( str,1);
}
}
/////////////////////////////////////////////////////////////////////////////
// CDOLView printing
BOOL CDOLView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CDOLView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CDOLView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CDOLView diagnostics
#ifdef _DEBUG
void CDOLView::AssertValid() const
{
CView::AssertValid();
}
void CDOLView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CDOLDoc* CDOLView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDOLDoc)));
return (CDOLDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDOLView message handlers
void CDOLView::TurState(char Command)
{
int x0,y0;
CClientDC dc(this);
CPen newpen;
newpen.CreatePen(PS_SOLID,1,m_pColor);
CPen *pOriginpen;
pOriginpen=dc.SelectObject(&newpen);
if(Command=='F')
{ x0=int(Turx);
y0=int(Tury);
Turx=float(Turx+1.5*stan*sin(TurDir*that*pi/180 ));
Tury=float(Tury-stan*cos(TurDir*that*pi/180 ));
// if(Command=='F')
{ dc.MoveTo(x0 ,y0 );
dc.LineTo(int(Turx),int(Tury)); }
//// else {//dc.MoveTo(Turx,Tury);
// y0=int(Tury);
// }
}
else if (Command=='+'){TurDir=TurDir-1;}
else if (Command=='-'){TurDir=TurDir+1;}
else if(Command=='[')
{if(TSSize==TSMAX)
{
cout<<"ERRor\n";
exit(0);
}
TSX[TSSize]=Turx;
TSY[TSSize]=Tury;
TSDir[TSSize]=TurDir;
TSSize+=1;
}
else if(Command==']')
{if(TSSize==0)
{
cout<<"ERROr\n";
exit(0);}
TSSize-=1;
Turx=TSX[TSSize];
Tury=TSY[TSSize];
TurDir=TSDir[TSSize];
// dc.MoveTo(Turx,Tury);
x0=int(Turx);
y0=int(Tury);
}
dc.SelectObject(pOriginpen);
}
//void CDOLView::Draw(char str[20],int level)
void CDOLView::Draw(CString str ,int level)
{
int istr,j,k;
k=0;
//while(str[k]!='\0')
while(k<str.GetLength())
{
// i=0;
// for(i=0;i<MAXN;i++)
//TurState(Command=str[k]);
// if(str[k]==Kar[i])
if(str[k]=='F')
{
level+=1;
if(level>Klevel)
{
level-=1;
istr=strlen(Rule);
for(j=0;j<istr; j++)
{TurState(Command=Rule[j]);}
goto loop;
}
else
Draw(Rule,level);
}
else
{
TurState(Command=str[k]);goto loop;
}
level =level-1 ;
loop: k=k+1;
}
}
void CDOLView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
CDOLDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TurDir=0;
// TSSize=0;
}
void CDOLView::Ondraw()
{
// TODO: Add your command handler code here
drawtrue=1;
Rule= "F[+F]F[-F][F]" ;
str= "F" ;
Turx=300;
Tury=500;
stan=60000;
Klevel=6;
that=20;
CSetDlg setdlg;
setdlg.rule=Rule;
setdlg.w=str;
setdlg.that=that;
setdlg.stan=stan;
setdlg.turx=Turx;
setdlg.tury=Tury;
setdlg.klevel=Klevel;
if(setdlg.DoModal()==IDOK)
{
that=setdlg.that;
stan=setdlg.stan;
Turx=setdlg.turx;
Tury=setdlg.tury;
Klevel=setdlg.klevel;
Rule=setdlg.rule;
str=setdlg.w;
}
Invalidate();
}
void CDOLView::Onselectcolor()
{
// TODO: Add your command handler code here
CColorDialog colordlg;
if (colordlg.DoModal()==IDOK)
{
m_pColor=colordlg.GetColor();
}
}
void CDOLView::OnContextMenu(CWnd*, CPoint point)
{
// CG: This block was added by the Pop-up Menu component { if (point.x == -1 && point.y == -1){ //keystroke invocation CRect rect; GetClientRect(rect); ClientToScreen(rect); point = rect.TopLeft(); point.Offset(5, 5); } CMenu menu; VERIFY(menu.LoadMenu(CG_IDR_POPUP_DOLVIEW)); CMenu* pPopup = menu.GetSubMenu(0); ASSERT(pPopup != NULL); CWnd* pWndPopupOwner = this; while (pWndPopupOwner->GetStyle() & WS_CHILD) pWndPopupOwner = pWndPopupOwner->GetParent(); pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, pWndPopupOwner); }
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -