1 //
2 // Copyright (C) 2001-2013 Graeme Walker <graeme_walker@users.sourceforge.net>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 //
18 // gdc.cpp
19 //
20 
21 #include "gdef.h"
22 #include "gdc.h"
23 
DeviceContext(HWND hwnd)24 GGui::DeviceContext::DeviceContext( HWND hwnd ) :
25 	m_hwnd(hwnd) ,
26 	m_do_release(true)
27 {
28 	m_hdc = ::GetDC( m_hwnd ) ;
29 }
30 
DeviceContext(HDC hdc)31 GGui::DeviceContext::DeviceContext( HDC hdc ) :
32 	m_hdc(hdc) ,
33 	m_hwnd(0) ,
34 	m_do_release(false) // ignored
35 {
36 }
37 
~DeviceContext()38 GGui::DeviceContext::~DeviceContext()
39 {
40 	if( m_hwnd != 0 && m_do_release )
41 		::ReleaseDC( m_hwnd , m_hdc ) ;
42 }
43 
handle() const44 HDC GGui::DeviceContext::handle() const
45 {
46 	return m_hdc ;
47 }
48 
extractHandle()49 HDC GGui::DeviceContext::extractHandle()
50 {
51 	m_do_release = false ;
52 	return m_hdc ;
53 }
54 
operator ()() const55 HDC GGui::DeviceContext::operator()() const
56 {
57 	return m_hdc ;
58 }
59 
swapBuffers()60 void GGui::DeviceContext::swapBuffers()
61 {
62 	BOOL ok = ::SwapBuffers( m_hdc ) ;
63 }
64 
65 // ===
66 
ScreenDeviceContext()67 GGui::ScreenDeviceContext::ScreenDeviceContext()
68 {
69 	m_dc = ::CreateDCA( "DISPLAY" , 0 , 0 , 0 ) ;
70 }
71 
~ScreenDeviceContext()72 GGui::ScreenDeviceContext::~ScreenDeviceContext()
73 {
74 	::DeleteDC( m_dc ) ;
75 }
76 
handle()77 HDC GGui::ScreenDeviceContext::handle()
78 {
79 	return m_dc ;
80 }
81 
operator ()()82 HDC GGui::ScreenDeviceContext::operator()()
83 {
84 	return handle() ;
85 }
86 
colours() const87 int GGui::ScreenDeviceContext::colours() const
88 {
89 	return ::GetDeviceCaps( m_dc , NUMCOLORS ) ;
90 }
91 
dx() const92 int GGui::ScreenDeviceContext::dx() const
93 {
94 	return ::GetDeviceCaps( m_dc , HORZRES ) ;
95 }
96 
dy() const97 int GGui::ScreenDeviceContext::dy() const
98 {
99 	return ::GetDeviceCaps( m_dc , VERTRES ) ;
100 }
101 
aspectx() const102 int GGui::ScreenDeviceContext::aspectx() const
103 {
104 	return ::GetDeviceCaps( m_dc , ASPECTX ) ;
105 }
106 
aspecty() const107 int GGui::ScreenDeviceContext::aspecty() const
108 {
109 	return ::GetDeviceCaps( m_dc , ASPECTY ) ;
110 }
111 
112 /// \file gdc.cpp
113