| 
									
										
										
										
											2017-02-08 22:15:43 -05:00
										 |  |  | // Copyright 2017 Dolphin Emulator Project
 | 
					
						
							|  |  |  | // Licensed under GPLv2+
 | 
					
						
							|  |  |  | // Refer to the license.txt file included.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "InputCommon/ControllerEmu/ControlGroup/Slider.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <cmath>
 | 
					
						
							|  |  |  | #include <memory>
 | 
					
						
							|  |  |  | #include <string>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "Common/Common.h"
 | 
					
						
							|  |  |  | #include "InputCommon/ControlReference/ControlReference.h"
 | 
					
						
							|  |  |  | #include "InputCommon/ControllerEmu/Control/Control.h"
 | 
					
						
							|  |  |  | #include "InputCommon/ControllerEmu/Control/Input.h"
 | 
					
						
							|  |  |  | #include "InputCommon/ControllerEmu/ControllerEmu.h"
 | 
					
						
							| 
									
										
										
										
											2017-02-26 12:00:24 -08:00
										 |  |  | #include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
 | 
					
						
							| 
									
										
										
										
											2017-02-08 22:15:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace ControllerEmu | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-12-19 11:21:27 +01:00
										 |  |  | Slider::Slider(const std::string& name_, const std::string& ui_name_) | 
					
						
							|  |  |  |     : ControlGroup(name_, ui_name_, GroupType::Slider) | 
					
						
							| 
									
										
										
										
											2017-02-08 22:15:43 -05:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2018-04-10 17:22:30 +02:00
										 |  |  |   controls.emplace_back(std::make_unique<Input>(Translate, _trans("Left"))); | 
					
						
							|  |  |  |   controls.emplace_back(std::make_unique<Input>(Translate, _trans("Right"))); | 
					
						
							| 
									
										
										
										
											2017-02-08 22:15:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 50)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-19 11:21:27 +01:00
										 |  |  | Slider::Slider(const std::string& name_) : Slider(name_, name_) | 
					
						
							| 
									
										
										
										
											2017-07-23 13:11:06 +02:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-13 11:49:05 -04:00
										 |  |  | Slider::StateData Slider::GetState() | 
					
						
							| 
									
										
										
										
											2017-02-08 22:15:43 -05:00
										 |  |  | { | 
					
						
							|  |  |  |   const ControlState deadzone = numeric_settings[0]->GetValue(); | 
					
						
							|  |  |  |   const ControlState state = controls[1]->control_ref->State() - controls[0]->control_ref->State(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (fabs(state) > deadzone) | 
					
						
							| 
									
										
										
										
											2018-07-13 11:49:05 -04:00
										 |  |  |     return {(state - (deadzone * sign(state))) / (1 - deadzone)}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return {0.0}; | 
					
						
							| 
									
										
										
										
											2017-02-08 22:15:43 -05:00
										 |  |  | } | 
					
						
							|  |  |  | }  // namespace ControllerEmu
 |