-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCS580HWView.cpp
157 lines (121 loc) · 3.76 KB
/
CS580HWView.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
// CS580HWView.cpp : implementation of the CCS580HWView class
//
#include "stdafx.h"
#include "CS580HW.h"
#include "CS580HWDoc.h"
#include "CS580HWView.h"
#include "Gz.h"
#include "disp.h"
#include "Application1.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCS580HWView
IMPLEMENT_DYNCREATE(CCS580HWView, CView)
BEGIN_MESSAGE_MAP(CCS580HWView, CView)
//{{AFX_MSG_MAP(CCS580HWView)
ON_COMMAND(IDM_RENDER, OnRender)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCS580HWView construction/destruction
CCS580HWView::CCS580HWView()
{
// TODO: add construction code here
m_pApplication = NULL;
}
CCS580HWView::~CCS580HWView()
{
}
BOOL CCS580HWView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCS580HWView drawing
void CCS580HWView::OnDraw(CDC* pDC)
{
CCS580HWDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
if(m_pApplication != NULL)
DrawFrameBuffer(pDC);
}
/////////////////////////////////////////////////////////////////////////////
// CCS580HWView diagnostics
#ifdef _DEBUG
void CCS580HWView::AssertValid() const
{
CView::AssertValid();
}
void CCS580HWView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCS580HWDoc* CCS580HWView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCS580HWDoc)));
return (CCS580HWDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCS580HWView message handlers
void CCS580HWView::OnRender()
{
// TODO: Add your command handler code here
// Call renderer
// Application 1
m_pApplication = new Application1;
m_pApplication->Render();
// Set window size
CRect clientRect, windowRect;
int x_offset, y_offset;
GetClientRect(&clientRect);
AfxGetMainWnd()->GetWindowRect(&windowRect);
x_offset = windowRect.Width() - clientRect.Width();
y_offset = windowRect.Height() - clientRect.Height();
AfxGetMainWnd()->SetWindowPos(NULL, 0, 0, x_offset+m_pApplication->m_nWidth, y_offset+m_pApplication->m_nHeight, NULL/*,SWP_SHOWWINDOW*/);
Invalidate(true);
}
void CCS580HWView::DrawFrameBuffer(CDC *pDC)
{
if(m_pApplication->m_pFrameBuffer == NULL)
{
return;
}
HDC hdc;
hdc = ::CreateCompatibleDC(pDC->m_hDC);
HBITMAP m_bitmap;
// Display the current image
char buffer[sizeof(BITMAPINFO)];
BITMAPINFO* binfo = (BITMAPINFO*)buffer;
memset(binfo, 0, sizeof(BITMAPINFOHEADER));
binfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
// Create the bitmap
BITMAPINFOHEADER* bih = &binfo->bmiHeader;
bih->biBitCount = 3*8;
bih->biWidth = m_pApplication->m_nWidth;
bih->biHeight = m_pApplication->m_nHeight;
bih->biPlanes = 1;
bih->biCompression = BI_RGB;
bih->biSizeImage = 0;
m_bitmap = CreateDIBSection(hdc, binfo, 0, 0, 0, DIB_RGB_COLORS);
int colors = DIB_RGB_COLORS;
::SelectObject(hdc, m_bitmap);
binfo->bmiHeader.biBitCount = 0;
GetDIBits(hdc, m_bitmap, 0, 0, 0, binfo, colors);
binfo->bmiHeader.biBitCount = 24;
binfo->bmiHeader.biHeight = -abs(binfo->bmiHeader.biHeight);
SetDIBits(hdc, m_bitmap, 0, m_pApplication->m_nHeight, m_pApplication->m_pFrameBuffer, binfo, colors);
::SetStretchBltMode(pDC->m_hDC, COLORONCOLOR);
CRect client;
GetClientRect(&client);
::BitBlt(pDC->m_hDC, 0, 0, m_pApplication->m_nWidth, m_pApplication->m_nHeight,
hdc, 0, 0, SRCCOPY);
::DeleteDC(hdc);
}