OSDN Git Service

DTXMania089リリースに際してのtag付け。
[dtxmania/dtxmania.git] / 110401(DTXMania089) / SlimDXc_Jun2010(VC++2008) / source / direct3d9 / DisplayModeEx.cpp
1 #include "stdafx.h"\r
2 /*\r
3 * Copyright (c) 2007-2010 SlimDX Group\r
4\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy\r
6 * of this software and associated documentation files (the "Software"), to deal\r
7 * in the Software without restriction, including without limitation the rights\r
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
9 * copies of the Software, and to permit persons to whom the Software is\r
10 * furnished to do so, subject to the following conditions:\r
11\r
12 * The above copyright notice and this permission notice shall be included in\r
13 * all copies or substantial portions of the Software.\r
14\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
21 * THE SOFTWARE.\r
22 */\r
23 #include <d3d9.h>\r
24 #include <d3dx9.h>\r
25 \r
26 #include "../ComObject.h"\r
27 #include "../InternalHelpers.h"\r
28 #include "../Result.h"\r
29 \r
30 #include "Direct3D9Exception.h"\r
31 #include "Direct3DEx.h"\r
32 #include "DisplayModeEx.h"\r
33 \r
34 using namespace System;\r
35 using namespace System::Collections::Generic;\r
36 \r
37 namespace SlimDX\r
38 {\r
39 namespace Direct3D9\r
40 {\r
41         DisplayModeEx DisplayModeEx::FromUnmanaged( const D3DDISPLAYMODEEX& nativeMode )\r
42         {\r
43                 DisplayModeEx mode;\r
44 \r
45                 mode.Width = nativeMode.Width;\r
46                 mode.Height = nativeMode.Height;\r
47                 mode.RefreshRate = nativeMode.RefreshRate;\r
48                 mode.Format = static_cast<SlimDX::Direct3D9::Format>( nativeMode.Format );\r
49                 mode.ScanlineOrdering = static_cast<SlimDX::Direct3D9::ScanlineOrdering>( nativeMode.ScanLineOrdering );\r
50 \r
51                 return mode;\r
52         }\r
53 \r
54         D3DDISPLAYMODEEX DisplayModeEx::ToUnmanaged()\r
55         {\r
56                 D3DDISPLAYMODEEX mode;\r
57 \r
58                 mode.Size = sizeof(D3DDISPLAYMODEEX);\r
59                 mode.Width = Width;\r
60                 mode.Height = Height;\r
61                 mode.RefreshRate = RefreshRate;\r
62                 mode.Format = static_cast<D3DFORMAT>( Format );\r
63                 mode.ScanLineOrdering = static_cast<D3DSCANLINEORDERING>( ScanlineOrdering );\r
64 \r
65                 return mode;\r
66         }\r
67 \r
68         bool DisplayModeEx::operator == ( DisplayModeEx left, DisplayModeEx right )\r
69         {\r
70                 return DisplayModeEx::Equals( left, right );\r
71         }\r
72 \r
73         bool DisplayModeEx::operator != ( DisplayModeEx left, DisplayModeEx right )\r
74         {\r
75                 return !DisplayModeEx::Equals( left, right );\r
76         }\r
77 \r
78         int DisplayModeEx::GetHashCode()\r
79         {\r
80                 return Width.GetHashCode() + Height.GetHashCode() + RefreshRate.GetHashCode()\r
81                          + Format.GetHashCode() + ScanlineOrdering.GetHashCode();\r
82         }\r
83 \r
84         bool DisplayModeEx::Equals( Object^ value )\r
85         {\r
86                 if( value == nullptr )\r
87                         return false;\r
88 \r
89                 if( value->GetType() != GetType() )\r
90                         return false;\r
91 \r
92                 return Equals( safe_cast<DisplayModeEx>( value ) );\r
93         }\r
94 \r
95         bool DisplayModeEx::Equals( DisplayModeEx value )\r
96         {\r
97                 return ( Width == value.Width && Height == value.Height && RefreshRate == value.RefreshRate\r
98                          && Format == value.Format && ScanlineOrdering == value.ScanlineOrdering );\r
99         }\r
100 \r
101         bool DisplayModeEx::Equals( DisplayModeEx% value1, DisplayModeEx% value2 )\r
102         {\r
103                 return ( value1.Width == value2.Width && value1.Height == value2.Height && value1.RefreshRate == value2.RefreshRate\r
104                          && value1.Format == value2.Format && value1.ScanlineOrdering == value2.ScanlineOrdering );\r
105         }\r
106 \r
107         DisplayModeExCollection::DisplayModeExCollection( IDirect3D9Ex *direct3D, unsigned int adapter, DisplayModeFilter filter )\r
108                 : ReadOnlyCollection( gcnew List<DisplayModeEx>() )\r
109         {\r
110                 D3DDISPLAYMODEFILTER nativeFilter;\r
111                 filter.ToUnmanaged( nativeFilter );\r
112 \r
113                 int count = direct3D->GetAdapterModeCountEx( adapter, &nativeFilter );\r
114 \r
115                 for( int i = 0; i < count; ++i )\r
116                 {\r
117                         D3DDISPLAYMODEEX nativeDisplayMode = {0};\r
118                         nativeDisplayMode.Size = sizeof(D3DDISPLAYMODEEX);\r
119                         HRESULT hr = direct3D->EnumAdapterModesEx( adapter, &nativeFilter, i, &nativeDisplayMode );\r
120                         if( RECORD_D3D9( hr ).IsFailure )\r
121                                 continue;\r
122 \r
123                         DisplayModeEx displayMode = DisplayModeEx::FromUnmanaged( nativeDisplayMode );\r
124                         Items->Add( displayMode );\r
125                 }\r
126         }\r
127 }\r
128 }