-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageSegView.cpp
170 lines (131 loc) · 3.86 KB
/
ImageSegView.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// ImageSegView.cpp : implementation of the CImageSegView class
//
#include "stdafx.h"
#include "ImageSeg.h"
#include "ImageSegDoc.h"
#include "ImageSegView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CImageSegView
IMPLEMENT_DYNCREATE(CImageSegView, CScrollView)
BEGIN_MESSAGE_MAP(CImageSegView, CScrollView)
//{{AFX_MSG_MAP(CImageSegView)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CImageSegView construction/destruction
CImageSegView::CImageSegView()
{
// TODO: add construction code here
}
CImageSegView::~CImageSegView()
{
}
BOOL CImageSegView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CImageSegView drawing
void CImageSegView::OnDraw(CDC* pDC)
{
CImageSegDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
if (pDoc->m_showBmp.IsValid())
{
pDoc->m_showBmp.Draw(pDC->m_hDC,CRect(0,0,pDoc->m_originBmp.GetWidth(),pDoc->m_originBmp.GetHeight()));
//确定滚动条范围
CSize cs;
if( pDoc->m_showBmp.GetWidth()<800) cs.cx=0;
else cs.cx= pDoc->m_showBmp.GetWidth();
if( pDoc->m_showBmp.GetHeight()<550) cs.cy=0;
else cs.cy= pDoc->m_showBmp.GetHeight();
SetScrollSizes(MM_TEXT,cs);
}
}
void CImageSegView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
//
CImageSegDoc* pDoc = GetDocument();
pDoc->pView=this;
}
/////////////////////////////////////////////////////////////////////////////
// CImageSegView printing
BOOL CImageSegView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CImageSegView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CImageSegView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CImageSegView diagnostics
#ifdef _DEBUG
void CImageSegView::AssertValid() const
{
CScrollView::AssertValid();
}
void CImageSegView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CImageSegDoc* CImageSegView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CImageSegDoc)));
return (CImageSegDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CImageSegView message handlers
void CImageSegView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CImageSegDoc* pDoc = GetDocument();
if(pDoc->m_regionGrow)
{
//获得焦点
SetCapture();
//改变鼠标形态
::SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR_SUCK));
}
CScrollView::OnMouseMove(nFlags, point);
}
void CImageSegView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CImageSegDoc* pDoc = GetDocument();
if(pDoc->m_regionGrow)//可以分割
{
int x=point.x;
int y=pDoc->m_originBmp.GetHeight()-point.y;//由于坐标是相反方向的。
pDoc->RegionGrow(CPoint(x,y));
pDoc->m_regionGrow=FALSE;
//释放焦点
ReleaseCapture();
}
CScrollView::OnLButtonUp(nFlags, point);
}