OSDN Git Service

#32713 初コミット。SVNrev567時点での、ファイルはbranch/140707(ReBuild XGVersion)から移行したもの。
[dtxmaniaxg-verk/dtxmaniaxg-verk-git.git] / SlimDXc_Jun2010(VC++2008) / source / direct3d9 / Sprite9.cpp
1 #include "stdafx.h"
2 /*
3 * Copyright (c) 2007-2010 SlimDX Group
4
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 */
23 #include <windows.h>
24 #include <d3d9.h>
25 #include <d3dx9.h>
26
27 #include "../ComObject.h"
28
29 #include "../math/Color4.h"
30 #include "../math/Vector3.h"
31
32 #include "Device.h"
33 #include "Sprite9.h"
34 #include "Texture.h"
35
36 #include "Direct3D9Exception.h"
37
38 using namespace System;
39 using namespace System::Drawing;
40
41 namespace SlimDX
42 {
43 namespace Direct3D9
44 {
45         Sprite::Sprite( SlimDX::Direct3D9::Device^ device )
46         {
47                 ID3DXSprite* sprite;
48                 
49                 HRESULT hr = D3DXCreateSprite( device->InternalPointer, &sprite );
50                 
51                 if( RECORD_D3D9( hr ).IsFailure )
52                         throw gcnew Direct3D9Exception( Result::Last );
53
54                 Construct(sprite);
55         }
56
57         Result Sprite::Begin( SpriteFlags flags )
58         {
59                 HRESULT hr = InternalPointer->Begin( static_cast<DWORD>( flags ) );
60                 return RECORD_D3D9( hr );
61         }
62
63         Result Sprite::End()
64         {
65                 HRESULT hr = InternalPointer->End();
66                 return RECORD_D3D9( hr );
67         }
68
69         Result Sprite::Flush()
70         {
71                 HRESULT hr = InternalPointer->Flush();
72                 return RECORD_D3D9( hr );
73         }
74
75         Result Sprite::OnLostDevice()
76         {
77                 HRESULT hr = InternalPointer->OnLostDevice();
78                 return RECORD_D3D9( hr );
79         }
80
81         Result Sprite::OnResetDevice()
82         {
83                 HRESULT hr = InternalPointer->OnResetDevice();
84                 return RECORD_D3D9( hr );
85         }
86
87         SlimDX::Direct3D9::Device^ Sprite::Device::get()
88         {
89                 IDirect3DDevice9* device;
90
91                 HRESULT hr = InternalPointer->GetDevice( &device );
92                 
93                 if( RECORD_D3D9( hr ).IsFailure )
94                         return nullptr;
95
96                 return SlimDX::Direct3D9::Device::FromPointer( device );
97         }
98
99         Matrix Sprite::Transform::get()
100         {
101                 Matrix result;
102
103                 HRESULT hr = InternalPointer->GetTransform( reinterpret_cast<D3DXMATRIX*>( &result ) );
104                 RECORD_D3D9( hr );
105
106                 return result;
107         }
108
109         void Sprite::Transform::set( Matrix value )
110         {
111                 HRESULT hr = InternalPointer->SetTransform( reinterpret_cast<const D3DXMATRIX*>( &value ) );
112                 RECORD_D3D9( hr );
113         }
114
115         Result Sprite::SetWorldViewLH( Matrix world, Matrix view )
116         {
117                 HRESULT hr = InternalPointer->SetWorldViewLH( reinterpret_cast<const D3DXMATRIX*>( &world ), reinterpret_cast<const D3DXMATRIX*>( &view ) );
118                 return RECORD_D3D9( hr );
119         }
120
121         Result Sprite::SetWorldViewRH( Matrix world, Matrix view )
122         {
123                 HRESULT hr = InternalPointer->SetWorldViewRH( reinterpret_cast<const D3DXMATRIX*>( &world ), reinterpret_cast<const D3DXMATRIX*>( &view ) );
124                 return RECORD_D3D9( hr );
125         }
126
127         Result Sprite::Draw( Texture^ texture, Nullable<System::Drawing::Rectangle> sourceRect, Nullable<Vector3> center, Nullable<Vector3> position, Color4 color )
128         {
129                 RECT rect = {0};
130                 RECT* rectPtr = 0;
131                 if(sourceRect.HasValue)
132                 {
133                         System::Drawing::Rectangle rectValue = sourceRect.Value;
134                         Utilities::ConvertRect(rectValue, rect);
135                         rectPtr = &rect;
136                 }
137
138                 const D3DXVECTOR3* centerPtr = 0;
139                 Vector3 centerValue;
140                 if( center.HasValue ) 
141                 {
142                         centerValue = center.Value;
143                         centerPtr = reinterpret_cast<const D3DXVECTOR3*>( &centerValue );
144                 }
145                 
146                 const D3DXVECTOR3* positionPtr = 0;
147                 Vector3 positionValue;
148                 if( position.HasValue ) 
149                 {
150                         positionValue = position.Value;
151                         positionPtr = reinterpret_cast<const D3DXVECTOR3*>( &positionValue );
152                 }
153                 
154                 HRESULT hr = InternalPointer->Draw( texture->InternalPointer, rectPtr, centerPtr, positionPtr, color.ToArgb() );
155                 return RECORD_D3D9( hr );
156         }
157
158         Result Sprite::Draw( Texture^ texture, Nullable<System::Drawing::Rectangle> sourceRect, Color4 color )
159         {
160                 RECT rect = {0};
161                 RECT* rectPtr = 0;
162                 if(sourceRect.HasValue)
163                 {
164                         System::Drawing::Rectangle rectValue = sourceRect.Value;
165                         Utilities::ConvertRect(rectValue, rect);
166                         rectPtr = &rect;
167                 }
168
169                 HRESULT hr = InternalPointer->Draw( texture->InternalPointer, rectPtr, NULL, NULL, color.ToArgb() );
170                 return RECORD_D3D9( hr );
171         }
172
173         Result Sprite::Draw( Texture^ texture, Nullable<Vector3> center, Nullable<Vector3> position, Color4 color )
174         {
175                 const D3DXVECTOR3* centerPtr = 0;
176                 Vector3 centerValue;
177                 if( center.HasValue ) 
178                 {
179                         centerValue = center.Value;
180                         centerPtr = reinterpret_cast<const D3DXVECTOR3*>( &centerValue );
181                 }
182                 
183                 const D3DXVECTOR3* positionPtr = 0;
184                 Vector3 positionValue;
185                 if( position.HasValue ) 
186                 {
187                         positionValue = position.Value;
188                         positionPtr = reinterpret_cast<const D3DXVECTOR3*>( &positionValue );
189                 }
190
191                 HRESULT hr = InternalPointer->Draw( texture->InternalPointer, NULL, centerPtr, positionPtr, color.ToArgb() );
192                 return RECORD_D3D9( hr );
193         }
194
195         Result Sprite::Draw( Texture^ texture, Color4 color )
196         {
197                 HRESULT hr = InternalPointer->Draw( texture->InternalPointer, NULL, NULL, NULL, color.ToArgb() );
198                 return RECORD_D3D9( hr );
199         }
200 }
201 }