wineps: Handle EMR_INVERTRGN record in spool files.
[wine.git] / dlls / windows.gaming.input / ramp_effect.c
blobfadcf151c0486e79eb7fb048c07a0c6f158fc1e5
1 /* WinRT Windows.Gaming.Input implementation
3 * Copyright 2022 RĂ©mi Bernon for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "private.h"
21 #include "provider.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(input);
25 struct ramp_effect
27 IRampForceEffect IRampForceEffect_iface;
28 IWineForceFeedbackEffectImpl *IWineForceFeedbackEffectImpl_inner;
29 LONG ref;
32 static inline struct ramp_effect *impl_from_IRampForceEffect( IRampForceEffect *iface )
34 return CONTAINING_RECORD( iface, struct ramp_effect, IRampForceEffect_iface );
37 static HRESULT WINAPI effect_QueryInterface( IRampForceEffect *iface, REFIID iid, void **out )
39 struct ramp_effect *impl = impl_from_IRampForceEffect( iface );
41 TRACE( "iface %p, iid %s, out %p.\n", iface, debugstr_guid( iid ), out );
43 if (IsEqualGUID( iid, &IID_IUnknown ) ||
44 IsEqualGUID( iid, &IID_IInspectable ) ||
45 IsEqualGUID( iid, &IID_IAgileObject ) ||
46 IsEqualGUID( iid, &IID_IRampForceEffect ))
48 IInspectable_AddRef( (*out = &impl->IRampForceEffect_iface) );
49 return S_OK;
52 return IWineForceFeedbackEffectImpl_QueryInterface( impl->IWineForceFeedbackEffectImpl_inner, iid, out );
55 static ULONG WINAPI effect_AddRef( IRampForceEffect *iface )
57 struct ramp_effect *impl = impl_from_IRampForceEffect( iface );
58 ULONG ref = InterlockedIncrement( &impl->ref );
59 TRACE( "iface %p increasing refcount to %lu.\n", iface, ref );
60 return ref;
63 static ULONG WINAPI effect_Release( IRampForceEffect *iface )
65 struct ramp_effect *impl = impl_from_IRampForceEffect( iface );
66 ULONG ref = InterlockedDecrement( &impl->ref );
68 TRACE( "iface %p decreasing refcount to %lu.\n", iface, ref );
70 if (!ref)
72 /* guard against re-entry if inner releases an outer iface */
73 InterlockedIncrement( &impl->ref );
74 IWineForceFeedbackEffectImpl_Release( impl->IWineForceFeedbackEffectImpl_inner );
75 free( impl );
78 return ref;
81 static HRESULT WINAPI effect_GetIids( IRampForceEffect *iface, ULONG *iid_count, IID **iids )
83 FIXME( "iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids );
84 return E_NOTIMPL;
87 static HRESULT WINAPI effect_GetRuntimeClassName( IRampForceEffect *iface, HSTRING *class_name )
89 return WindowsCreateString( RuntimeClass_Windows_Gaming_Input_ForceFeedback_RampForceEffect,
90 ARRAY_SIZE(RuntimeClass_Windows_Gaming_Input_ForceFeedback_RampForceEffect),
91 class_name );
94 static HRESULT WINAPI effect_GetTrustLevel( IRampForceEffect *iface, TrustLevel *trust_level )
96 FIXME( "iface %p, trust_level %p stub!\n", iface, trust_level );
97 return E_NOTIMPL;
100 static HRESULT WINAPI effect_SetParameters( IRampForceEffect *iface, Vector3 start_vector, Vector3 end_vector, TimeSpan duration )
102 WineForceFeedbackEffectParameters params =
104 .ramp =
106 .type = WineForceFeedbackEffectType_Ramp,
107 .start_vector = start_vector,
108 .end_vector = end_vector,
109 .duration = duration,
110 .repeat_count = 1,
111 .gain = 1.,
114 struct ramp_effect *impl = impl_from_IRampForceEffect( iface );
116 TRACE( "iface %p, start_vector %s, end_vector %s, duration %I64u.\n", iface,
117 debugstr_vector3( &start_vector ), debugstr_vector3( &end_vector ), duration.Duration );
119 return IWineForceFeedbackEffectImpl_put_Parameters( impl->IWineForceFeedbackEffectImpl_inner, params, NULL );
122 static HRESULT WINAPI effect_SetParametersWithEnvelope( IRampForceEffect *iface, Vector3 start_vector, Vector3 end_vector, FLOAT attack_gain,
123 FLOAT sustain_gain, FLOAT release_gain, TimeSpan start_delay,
124 TimeSpan attack_duration, TimeSpan sustain_duration,
125 TimeSpan release_duration, UINT32 repeat_count )
127 WineForceFeedbackEffectParameters params =
129 .ramp =
131 .type = WineForceFeedbackEffectType_Ramp,
132 .start_vector = start_vector,
133 .end_vector = end_vector,
134 .duration = {attack_duration.Duration + sustain_duration.Duration + release_duration.Duration},
135 .start_delay = start_delay,
136 .repeat_count = repeat_count,
137 .gain = sustain_gain,
140 WineForceFeedbackEffectEnvelope envelope =
142 .attack_gain = attack_gain,
143 .release_gain = release_gain,
144 .attack_duration = attack_duration,
145 .release_duration = release_duration,
147 struct ramp_effect *impl = impl_from_IRampForceEffect( iface );
149 TRACE( "iface %p, start_vector %s, end_vector %s, attack_gain %f, sustain_gain %f, release_gain %f, start_delay %I64u, attack_duration %I64u, "
150 "sustain_duration %I64u, release_duration %I64u, repeat_count %u.\n", iface, debugstr_vector3( &start_vector ), debugstr_vector3( &end_vector ),
151 attack_gain, sustain_gain, release_gain, start_delay.Duration, attack_duration.Duration, sustain_duration.Duration,
152 release_duration.Duration, repeat_count );
154 return IWineForceFeedbackEffectImpl_put_Parameters( impl->IWineForceFeedbackEffectImpl_inner, params, &envelope );
157 static const struct IRampForceEffectVtbl effect_vtbl =
159 effect_QueryInterface,
160 effect_AddRef,
161 effect_Release,
162 /* IInspectable methods */
163 effect_GetIids,
164 effect_GetRuntimeClassName,
165 effect_GetTrustLevel,
166 /* IRampForceEffect methods */
167 effect_SetParameters,
168 effect_SetParametersWithEnvelope,
171 struct ramp_factory
173 IActivationFactory IActivationFactory_iface;
174 LONG ref;
177 static inline struct ramp_factory *impl_from_IActivationFactory( IActivationFactory *iface )
179 return CONTAINING_RECORD( iface, struct ramp_factory, IActivationFactory_iface );
182 static HRESULT WINAPI activation_QueryInterface( IActivationFactory *iface, REFIID iid, void **out )
184 struct ramp_factory *impl = impl_from_IActivationFactory( iface );
186 TRACE( "iface %p, iid %s, out %p.\n", iface, debugstr_guid( iid ), out );
188 if (IsEqualGUID( iid, &IID_IUnknown ) ||
189 IsEqualGUID( iid, &IID_IInspectable ) ||
190 IsEqualGUID( iid, &IID_IAgileObject ) ||
191 IsEqualGUID( iid, &IID_IActivationFactory ))
193 IInspectable_AddRef( (*out = &impl->IActivationFactory_iface) );
194 return S_OK;
197 FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) );
198 *out = NULL;
199 return E_NOINTERFACE;
202 static ULONG WINAPI activation_AddRef( IActivationFactory *iface )
204 struct ramp_factory *impl = impl_from_IActivationFactory( iface );
205 ULONG ref = InterlockedIncrement( &impl->ref );
206 TRACE( "iface %p increasing refcount to %lu.\n", iface, ref );
207 return ref;
210 static ULONG WINAPI activation_Release( IActivationFactory *iface )
212 struct ramp_factory *impl = impl_from_IActivationFactory( iface );
213 ULONG ref = InterlockedDecrement( &impl->ref );
214 TRACE( "iface %p decreasing refcount to %lu.\n", iface, ref );
215 return ref;
218 static HRESULT WINAPI activation_GetIids( IActivationFactory *iface, ULONG *iid_count, IID **iids )
220 FIXME( "iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids );
221 return E_NOTIMPL;
224 static HRESULT WINAPI activation_GetRuntimeClassName( IActivationFactory *iface, HSTRING *class_name )
226 FIXME( "iface %p, class_name %p stub!\n", iface, class_name );
227 return E_NOTIMPL;
230 static HRESULT WINAPI activation_GetTrustLevel( IActivationFactory *iface, TrustLevel *trust_level )
232 FIXME( "iface %p, trust_level %p stub!\n", iface, trust_level );
233 return E_NOTIMPL;
236 static HRESULT WINAPI activation_ActivateInstance( IActivationFactory *iface, IInspectable **instance )
238 struct ramp_effect *impl;
239 HRESULT hr;
241 TRACE( "iface %p, instance %p.\n", iface, instance );
243 if (!(impl = calloc( 1, sizeof(struct ramp_effect) ))) return E_OUTOFMEMORY;
244 impl->IRampForceEffect_iface.lpVtbl = &effect_vtbl;
245 impl->ref = 1;
247 if (FAILED(hr = force_feedback_effect_create( WineForceFeedbackEffectType_Ramp, (IInspectable *)&impl->IRampForceEffect_iface,
248 &impl->IWineForceFeedbackEffectImpl_inner )))
250 free( impl );
251 return hr;
254 *instance = (IInspectable *)&impl->IRampForceEffect_iface;
255 TRACE( "created RampForceEffect %p\n", *instance );
256 return S_OK;
259 static const struct IActivationFactoryVtbl activation_vtbl =
261 activation_QueryInterface,
262 activation_AddRef,
263 activation_Release,
264 /* IInspectable methods */
265 activation_GetIids,
266 activation_GetRuntimeClassName,
267 activation_GetTrustLevel,
268 /* IActivationFactory methods */
269 activation_ActivateInstance,
272 static struct ramp_factory ramp_statics =
274 {&activation_vtbl},
278 IInspectable *ramp_effect_factory = (IInspectable *)&ramp_statics.IActivationFactory_iface;