// DDA画线View.cpp : implementation of the CDDAView class
//
#include "stdafx.h"
#include "DDA画线.h"
#include "蠢橘DDA画线Doc.h"
#include "DDA画线View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__
#endif
/////////////////////////////////////////////////////////////////////////////
// CDDAView
IMPLEMENT_DYNCREATE(CDDAView, CView)
BEGIN_MESSAGE_MAP(CDDAView, CView)
//{{AFX_MSG_MAP(CDDAView)
// NOTE - the ClassWizard will add and remove mapping macros here.
//DO NOT EDIT what you see in these blocks of generated code!
//}}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()
/////////////////////////////////////////////////////////岁册////////////////////
// CDDAView construction/destruction
CDDAView::CDDAView()
{
// TODO: add construction code here
}
CDDAView::~CDDAView()
{
}
BOOL CDDAView::PreCreateWindow(CREATESTRUCT&cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs)
}
/////////////////////////////////////////////////////////////////////////////
// CDDAView drawing
void CDDAView::OnDraw(CDC* pDC)
{
CDDADoc* pDoc = GetDocument()
ASSERT_VALID(pDoc)
int xx,yy,x2,y2,m,n
float dx,dy,k,x,y
int x0=50,y0=500,x1=50,y1=50
if(x0>x1)
{
m=x0x0=x1x1=m
m=y0y0=y1y1=m
}
dx=x1-x0
dy=y1-y0
k=dy/dx
if(x0==x1)
{
if(y0>y1)
{
n=y0
y0=y1
y1=n
}
for(y2=y0y2<=y1)
{
for(n=-10n<11)
{
pDC->SetPixel(x0+n,y2,255)
n++
}
y2=y2+3
}
}
if(k>=-1&&k<=1.0)
{
y=y0
for(x2=x0x2<=x1)
{
yy=(int)(y+0.5)
for(n=-10n<11)
{
pDC->SetPixel(x2,yy+n,255)
n++
}
y=y+k
x2++
}
}
else if(k>1)
{
x=x0
k=dx/dy
for(y2=y0y2<=y1)
{
xx=(int)(x+0.5)
for(n=-10n<11)
{
pDC->SetPixel(xx+n,y2,255)
n++
}
x=x+k
y2++
}
}
else if(k<-1)
{
x=x1
k=dx/dy
for(y2=y1y2<=y0)
{
xx=(int)(x+0.5)
for(n=-10n<11)
{
pDC->SetPixel(xx+n,y2,255)
n++
}
x=x+k
y2++
}
}
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CDDAView printing
BOOL CDDAView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo)
}
void CDDAView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CDDAView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CDDAView diagnostics
#ifdef _DEBUG
void CDDAView::AssertValid() const
{
CView::AssertValid()
}
void CDDAView::Dump(CDumpContext&dc) const
{
CView::Dump(dc)
}
CDDADoc* CDDAView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDDADoc)))
return (CDDADoc*)m_pDocument
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDDAView message handlers
DDAline(100,200,300,400,466)这个函数中的五个数字分别表示x0,y0,x1,y1和颜色。斜率是由x0,y0,x1,y1决定迟型的码启猜。你想改变旁历斜率,只需改变这四个数字即可。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)