3 * Copyright (c) 2007-2010 SlimDX Group
\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
12 * The above copyright notice and this permission notice shall be included in
\r
13 * all copies or substantial portions of the Software.
\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
26 #include "../ComObject.h"
\r
27 #include "../InternalHelpers.h"
\r
28 #include "../Result.h"
\r
30 #include "Direct3D9Exception.h"
\r
31 #include "Direct3DEx.h"
\r
32 #include "DisplayModeEx.h"
\r
34 using namespace System;
\r
35 using namespace System::Collections::Generic;
\r
41 DisplayModeEx DisplayModeEx::FromUnmanaged( const D3DDISPLAYMODEEX& nativeMode )
\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
54 D3DDISPLAYMODEEX DisplayModeEx::ToUnmanaged()
\r
56 D3DDISPLAYMODEEX mode;
\r
58 mode.Size = sizeof(D3DDISPLAYMODEEX);
\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
68 bool DisplayModeEx::operator == ( DisplayModeEx left, DisplayModeEx right )
\r
70 return DisplayModeEx::Equals( left, right );
\r
73 bool DisplayModeEx::operator != ( DisplayModeEx left, DisplayModeEx right )
\r
75 return !DisplayModeEx::Equals( left, right );
\r
78 int DisplayModeEx::GetHashCode()
\r
80 return Width.GetHashCode() + Height.GetHashCode() + RefreshRate.GetHashCode()
\r
81 + Format.GetHashCode() + ScanlineOrdering.GetHashCode();
\r
84 bool DisplayModeEx::Equals( Object^ value )
\r
86 if( value == nullptr )
\r
89 if( value->GetType() != GetType() )
\r
92 return Equals( safe_cast<DisplayModeEx>( value ) );
\r
95 bool DisplayModeEx::Equals( DisplayModeEx value )
\r
97 return ( Width == value.Width && Height == value.Height && RefreshRate == value.RefreshRate
\r
98 && Format == value.Format && ScanlineOrdering == value.ScanlineOrdering );
\r
101 bool DisplayModeEx::Equals( DisplayModeEx% value1, DisplayModeEx% value2 )
\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
107 DisplayModeExCollection::DisplayModeExCollection( IDirect3D9Ex *direct3D, unsigned int adapter, DisplayModeFilter filter )
\r
108 : ReadOnlyCollection( gcnew List<DisplayModeEx>() )
\r
110 D3DDISPLAYMODEFILTER nativeFilter;
\r
111 filter.ToUnmanaged( nativeFilter );
\r
113 int count = direct3D->GetAdapterModeCountEx( adapter, &nativeFilter );
\r
115 for( int i = 0; i < count; ++i )
\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
123 DisplayModeEx displayMode = DisplayModeEx::FromUnmanaged( nativeDisplayMode );
\r
124 Items->Add( displayMode );
\r