📄 txx4_10view.cpp
字号:
// txx4_10View.cpp : implementation of the CTxx4_10View class
//
#include "stdafx.h"
#include "txx4_10.h"
#include "txx4_10Doc.h"
#include "txx4_10View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTxx4_10View
IMPLEMENT_DYNCREATE(CTxx4_10View, CView)
BEGIN_MESSAGE_MAP(CTxx4_10View, CView)
//{{AFX_MSG_MAP(CTxx4_10View)
ON_WM_LBUTTONDOWN()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CTxx4_10View construction/destruction
CTxx4_10View::CTxx4_10View()
{
// TODO: add construction code here
BkColor = RGB(255, 255, 255);
}
CTxx4_10View::~CTxx4_10View()
{
}
BOOL CTxx4_10View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CTxx4_10View drawing
void CTxx4_10View::OnDraw(CDC* pDC)
{
CTxx4_10Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pDC->TextOut(0,0,"单击左键选择种子点");
DrawEdge(pDC, pDoc->plg, RGB(0,0,0));
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CTxx4_10View printing
BOOL CTxx4_10View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CTxx4_10View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTxx4_10View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CTxx4_10View diagnostics
#ifdef _DEBUG
void CTxx4_10View::AssertValid() const
{
CView::AssertValid();
}
void CTxx4_10View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CTxx4_10Doc* CTxx4_10View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTxx4_10Doc)));
return (CTxx4_10Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTxx4_10View message handlers
void CTxx4_10View::DrawEdge(CDC *pDC, list<CPoint> &polygon, int color)
{
list<CPoint>::iterator p_ite;
p_ite= polygon.begin();
pDC->MoveTo(p_ite->x, p_ite->y);
for (++p_ite; p_ite != polygon.end(); ++p_ite)
pDC->LineTo(p_ite->x, p_ite->y);
p_ite = polygon.begin();
pDC->LineTo(p_ite->x, p_ite->y);
}
bool CTxx4_10View::IsInside(CPoint point)
{
CRect rect;
CClientDC dc(this);
int i, judge = 0;
GetClientRect(&rect);
for (i = point.x+1; i < rect.right; ++i)
if (dc.GetPixel(i, point.y) != BkColor)
{
++judge;
break;
}
for (i = point.x-1; i > rect.left; --i)
if (dc.GetPixel(i, point.y) != BkColor)
{
++judge;
break;
}
for (i = point.y+1; i < rect.bottom; ++i)
if (dc.GetPixel(point.x, i) != BkColor)
{
++judge;
break;
}
for (i = point.y-1; i > rect.top; ++i)
if (dc.GetPixel(point.x, i) != BkColor)
{
++judge;
break;
}
if (judge == 4) return true;
else return false;
}
void CTxx4_10View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
CRect rect;
CPoint cur;
int x, xl, xr;
if(IsInside(point))
{
GetClientRect(&rect);
stk.push(CPoint(point.x, point.y));
while (!stk.empty())
{
cur = stk.top();
stk.pop();
for (x = cur.x; x > rect.left; --x)
{
if (dc.GetPixel(x, cur.y) != BkColor) break;
dc.SetPixel(x, cur.y, RGB(0,0,255));
}
xl = x + 1;
for (x = cur.x+1; x < rect.right; ++x)
{
if (dc.GetPixel(x, cur.y) != BkColor) break;
dc.SetPixel(x, cur.y, RGB(0,0,255));
}
xr = x - 1;
for (x = xr; x >= xl; --x) // downward
{
while (x >= xl && dc.GetPixel(x, cur.y+1) != BkColor) --x;
if (x < xl) break;
if (dc.GetPixel(x, cur.y+1) != RGB(0,0,255))
{
stk.push(CPoint(x, cur.y+1));
while (x >= xl && dc.GetPixel(x, cur.y+1) == BkColor) --x;
}
}
for (x = xr; x >= xl; --x) // upward
{
while (x >= xl && dc.GetPixel(x, cur.y-1) != BkColor) --x;
if (x < xl) break;
if (dc.GetPixel(x, cur.y-1) != RGB(0,0,255))
{
stk.push(CPoint(x, cur.y-1));
while (x >= xl && dc.GetPixel(x, cur.y-1) == BkColor) --x;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -