-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorldView.cpp
More file actions
106 lines (75 loc) · 2.09 KB
/
WorldView.cpp
File metadata and controls
106 lines (75 loc) · 2.09 KB
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
/* WorldView.cpp
Robert Kirk DeLisle
19 August 2006
Purpose: Defines a View on the World Model that is Win32 platform specific and
expects graphical objects to be resources (bitmaps are not DIBs, but rather
resources within the project).
Modificaton History:
*/
#include <string>
#include "WorldView.h"
void WorldView::Clear()
{
BitBlt( m_hBackBuffer,
0,0,
m_PixelWidth, m_PixelHeight,
m_hBackBuffer,
0,0,
BLACKNESS);
}
void WorldView::Draw(HDC TargetDC) const
{
/* Purpose: Draw the backbuffer to the target
Parameters: TargetDC - where the drawing will occur
Return: none
Exceptions:
*/
//convert the score to a string
string score;
char cscore[10];
score = itoa(m_Model->GetScore(),cscore,10);
//write out the score
SetTextColor(m_hBackBuffer, RGB(255,0,0));
SetBkColor(m_hBackBuffer, RGB(0,0,0));
TextOut(m_hBackBuffer, 0, 0, score.c_str(), score.length());
//draw the backbuffer to the target
BitBlt( TargetDC,
0,0,
m_PixelWidth, m_PixelHeight,
m_hBackBuffer,
0,0,
SRCCOPY);
return;
}
void WorldView::SetViewDimensions(const long Height, const long Width)
{
/* Purpose: Set the dimensions of the view and create the backbuffer
Parameters: Height and Width in pixels
Return: none
Exceptions:
*/
//store the dimensions
m_PixelHeight = Height;
m_PixelWidth = Width;
//create the DC compatible with the screen and get a bitmap inside for drawing
HDC screen = GetDC(NULL);
m_hBackBuffer = CreateCompatibleDC(screen);
m_hBitmap = CreateCompatibleBitmap(screen, m_PixelWidth, m_PixelHeight);
ReleaseDC(NULL, screen);
m_hOldBitmap = (HBITMAP) SelectObject(m_hBackBuffer, m_hBitmap);
return;
}
WorldView::~WorldView()
{
/* Purpose: Free the GDI references
Parameters: none
Return: none
Exceptions:
*/
//put the old bitmap back in, delete the new
SelectObject(m_hBackBuffer, m_hOldBitmap);
DeleteObject(m_hBitmap);
//get rid of the backbuffer
DeleteDC(m_hBackBuffer);
return;
}