-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathGDIView.cpp
202 lines (176 loc) · 4.27 KB
/
GDIView.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include "stdafx.h"
#include "nv_SvcMFCUI.h"
#include "GDIView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/**
** Instanciation of an object.
**/
const void * GDIView::NewObjectFunc(unsigned long lparam1, unsigned long lparam2)
{
return NULL;
/*
AFX_MANAGE_STATE(AfxGetStaticModuleState());
RECT rc = {0,0,50,50};
CWnd *pwnd;
{
pwnd = new CEmptytMDIChildWnd;
if (!((CEmptytMDIChildWnd*)pwnd)->Create(NULL, "gdiviewmdiwin",WS_CHILD|WS_VISIBLE|WS_OVERLAPPEDWINDOW))
{
delete pwnd;
return FALSE;
}
pwnd->GetClientRect(&rc);
}
GDIView *pwndgdi = new GDIView(pwnd);
if (!pwndgdi->Create(NULL, "gdiview", WS_CHILD|WS_VISIBLE,rc,pwnd,10))
{
pwnd->DestroyWindow();
//delete pwnd;
delete pwndgdi;
return FALSE;
}
((CEmptytMDIChildWnd*)pwnd)->m_childwnd = pwndgdi;
//pwnd->PeekMyself();
return (void*)(static_cast<IGDIView*>(pwndgdi));*/
}
/////////////////////////////////////////////////////////////////////////////
// GDIView
IMPLEMENT_DYNCREATE(GDIView, CScrollView)
GDIView::GDIView(CWnd *parent) :
m_gdiwidth(200),
m_gdiheight(200),
m_pwnd(parent),
m_zoom(1)
{
IMPLSMARTREFINIT
}
GDIView::~GDIView()
{
}
BEGIN_MESSAGE_MAP(GDIView, CScrollView)
//{{AFX_MSG_MAP(GDIView)
ON_WM_CREATE()
ON_WM_MOUSEWHEEL()
ON_WM_SIZE()
ON_WM_CLOSE()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// GDIView drawing
void GDIView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
}
void GDIView::OnDraw(CDC* pDC)
{
RECT rc={0,0,50,50};
pDC->Ellipse(&rc);
RECT rc2={0,0,200,200};
pDC->Ellipse(&rc2);
CBrush br(HS_BDIAGONAL,0x802020);
FillOutsideRect(pDC, &br);
}
void GDIView::FillOutsideRect(CDC* pDC, CBrush* pBrush)
{
/// ASSERT_VALID(pDC);
// ASSERT_VALID(pBrush);
// fill rect outside the image
CRect rect;
GetClientRect(rect);
rect.right = (int)((float)rect.right * m_zoom);
rect.bottom = (int)((float)rect.bottom * m_zoom);
ASSERT(rect.left == 0 && rect.top == 0);
rect.left = m_gdiwidth;
if (!rect.IsRectEmpty())
pDC->FillRect(rect, pBrush); // vertical strip along the side
rect.left = 0;
rect.right = m_gdiwidth;
rect.top = m_gdiheight;
if (!rect.IsRectEmpty())
pDC->FillRect(rect, pBrush); // horizontal strip along the bottom
}
/////////////////////////////////////////////////////////////////////////////
// GDIView diagnostics
#ifdef _DEBUG
void GDIView::AssertValid() const
{
CScrollView::AssertValid();
}
void GDIView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// GDIView message handlers
int GDIView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CScrollView::OnCreate(lpCreateStruct) == -1)
return -1;
SetScrollSizes(MM_TEXT, CSize(m_gdiwidth,m_gdiheight));
return 0;
}
void GDIView::ShowSliders(bool bYes)
{
}
void GDIView::SetZoom(float zoom)
{
}
void GDIView::SetOffset(float x, float y)
{
}
void GDIView::SetViewFrame(float x1, float y1, float x2, float y2)
{
}
BOOL GDIView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
RECT rc;
float step = m_zoom * (float)zDelta * 0.001f;
m_zoom += step;
GetClientRect(&rc);
SetScrollSizes(MM_TEXT, CSize((int)((float)m_gdiwidth/m_zoom), (int)((float)m_gdiheight/m_zoom)));
RedrawWindow();
return TRUE;
}
void GDIView::OnSize(UINT nType, int cx, int cy)
{
CScrollView::OnSize(nType, cx, cy);
}
void GDIView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
CScrollView::OnPrepareDC(pDC, pInfo);
if(m_zoom != 1)
{
pDC->SetMapMode(MM_ANISOTROPIC);
RECT rc;
GetClientRect(&rc);
pDC->SetViewportExt(rc.right, rc.bottom);
pDC->SetWindowExt((int)(m_zoom*(float)rc.right), (int)(m_zoom*(float)rc.bottom)); // window is in logical coordinates
}
}
void GDIView::OnClose()
{
//
// Send the event
//
for(int ic = 0; ic < m_pclients.size(); ic++)
{
// HACK : This forces this object to not be deleted inside an event.
AddRef();
m_pclients[ic]->rtWindowClosed(static_cast<IWindow*>(this));
Release();
}
//CScrollView::OnClose();
}
void GDIView::OnDestroy()
{
CScrollView::OnDestroy();
if(m_pwnd) m_pwnd->DestroyWindow();
for(int ic = 0; ic < m_pclients.size(); ic++)
m_pclients[ic]->rtWindowDestroyed(static_cast<IWindow*>(this));
}