OSDN Git Service

作業部屋#50802 画面キャプチャができなくなっていた問題を暫定対応(F12キー固定で対応中)
[dtxmaniaxg-verk/dtxmaniaxg-verk-git.git] / SlimDXc_Jun2010(VC++2008) / source / directinput / EffectParameters.cpp
1 /*
2 * Copyright (c) 2007-2010 SlimDX Group
3
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22 #include "stdafx.h"
23 #include <dinput.h>
24
25 #include "EffectParameters.h"
26
27 using namespace System;
28 using namespace System::Runtime::InteropServices;
29
30 namespace SlimDX
31 {
32 namespace DirectInput
33 {
34         EffectParameters::EffectParameters( const DIEFFECT &effect )
35         {
36                 Flags = static_cast<EffectFlags>( effect.dwFlags );
37                 Duration = effect.dwDuration;
38                 SamplePeriod = effect.dwSamplePeriod;
39                 Gain = effect.dwGain;
40                 TriggerButton = effect.dwTriggerButton;
41                 TriggerRepeatInterval = effect.dwTriggerRepeatInterval;
42                 StartDelay = effect.dwStartDelay;
43
44                 if( effect.rgdwAxes != NULL && effect.cAxes > 0 )
45                 {
46                         axes = gcnew array<int>( effect.cAxes );
47                         for( UINT i = 0; i < effect.cAxes; i++ )
48                                 axes[i] = effect.rgdwAxes[i];
49                 }
50
51                 if( effect.rglDirection != NULL && effect.cAxes > 0 )
52                 {
53                         directions = gcnew array<int>( effect.cAxes );
54                         for( UINT i = 0; i < effect.cAxes; i++ )
55                                 directions[i] = effect.rglDirection[i];
56                 }
57
58                 if( effect.lpEnvelope != NULL )
59                 {
60                         DirectInput::Envelope env;
61                         env.AttackLevel = effect.lpEnvelope->dwAttackLevel;
62                         env.AttackTime = effect.lpEnvelope->dwAttackTime;
63                         env.FadeLevel = effect.lpEnvelope->dwFadeLevel;
64                         env.FadeTime = effect.lpEnvelope->dwFadeTime;
65
66                         Envelope = env;
67                 }
68
69                 if( effect.cbTypeSpecificParams > 0 && effect.lpvTypeSpecificParams != NULL )
70                         Parameters = gcnew TypeSpecificParameters( effect.lpvTypeSpecificParams, effect.cbTypeSpecificParams );
71         }
72
73         DIEFFECT EffectParameters::ToUnmanaged()
74         {
75                 DIEFFECT result;
76                 memset( &result, 0, sizeof( DIEFFECT ) );
77
78                 result.dwSize = sizeof( DIEFFECT );
79                 result.dwFlags = static_cast<DWORD>( Flags );
80                 result.dwDuration = Duration;
81                 result.dwSamplePeriod = SamplePeriod;
82                 result.dwGain = Gain;
83                 result.dwTriggerButton = TriggerButton;
84                 result.dwTriggerRepeatInterval = TriggerRepeatInterval;
85                 result.dwStartDelay = StartDelay;
86
87                 if( axes != nullptr )
88                 {
89                         result.cAxes = axes->Length;
90
91                         // Manual Allocation: cleaned up in Cleanup() method
92                         result.rgdwAxes = new DWORD[axes->Length];
93
94                         pin_ptr<int> pinnedAxes = &axes[0];
95                         memcpy( result.rgdwAxes, pinnedAxes, sizeof( DWORD ) * axes->Length );
96                 }
97
98                 if( directions != nullptr )
99                 {
100                         // Manual Allocation: cleaned up in Cleanup() method
101                         result.rglDirection = new LONG[axes->Length];
102
103                         pin_ptr<int> pinnedDirections = &directions[0];
104                         memcpy( result.rglDirection, pinnedDirections, sizeof( LONG ) * axes->Length );
105                 }
106
107                 if( Envelope.HasValue )
108                 {
109                         // Manual Allocation: cleaned up in Cleanup() method
110                         DIENVELOPE *env = new DIENVELOPE();
111                         env->dwSize = sizeof( DIENVELOPE );
112                         env->dwAttackLevel = Envelope.Value.AttackLevel;
113                         env->dwAttackTime = Envelope.Value.AttackTime;
114                         env->dwFadeLevel = Envelope.Value.FadeLevel;
115                         env->dwFadeTime = Envelope.Value.FadeTime;
116
117                         result.lpEnvelope = env;
118                 }
119
120                 if( Parameters != nullptr )
121                 {
122                         result.cbTypeSpecificParams = Parameters->Size;
123                         result.lpvTypeSpecificParams = Parameters->ToUnmanaged();
124                 }
125
126                 return result;
127         }
128
129         void EffectParameters::Cleanup( const DIEFFECT &effect )
130         {
131                 if( effect.rgdwAxes != NULL )
132                         delete[] effect.rgdwAxes;
133
134                 if( effect.rglDirection != NULL )
135                         delete[] effect.rglDirection;
136
137                 if( effect.lpEnvelope != NULL )
138                         delete effect.lpEnvelope;
139
140                 if( effect.lpvTypeSpecificParams != NULL && Parameters != nullptr )
141                         Parameters->Release( effect.lpvTypeSpecificParams );
142         }
143
144         void EffectParameters::GetAxes( [Out] array<int>^ %axes, [Out] array<int>^ %directions )
145         {
146                 axes = this->axes;
147                 directions = this->directions;
148         }
149
150         void EffectParameters::SetAxes( array<int>^ axes, array<int>^ directions )
151         {
152                 this->axes = axes;
153                 this->directions = directions;
154         }
155 }
156 }