Browse Source

Resolved virtual joystick support

- Added function to set virtual joystick visibility.
- Updated samples.iml to reflect changess.
thebluefish 11 years ago
parent
commit
1ba75f5222
3 changed files with 17 additions and 4 deletions
  1. 11 0
      Source/Engine/Input/Input.cpp
  2. 2 0
      Source/Engine/Input/Input.h
  3. 4 4
      Source/Samples/Sample.inl

+ 11 - 0
Source/Engine/Input/Input.cpp

@@ -231,6 +231,17 @@ void Input::SetMouseVisible(bool enable)
     #endif
 }
 
+void Input::SetScreenJoystickVisible(SDL_JoystickID index, bool enable)
+{
+	if(joysticks_.Contains(index))
+	{
+		JoystickState& state = joysticks_[index];
+
+		if (state.screenJoystick_)
+        state.screenJoystick_->SetVisible(enable);
+	}
+}
+
 void Input::SetToggleFullscreen(bool enable)
 {
     toggleFullscreen_ = enable;

+ 2 - 0
Source/Engine/Input/Input.h

@@ -142,6 +142,8 @@ public:
     void SetToggleFullscreen(bool enable);
     /// Set whether the operating system mouse cursor is visible. When not visible (default), is kept centered to prevent leaving the window.
     void SetMouseVisible(bool enable);
+	/// Set whether the virtual joystick is visible.
+	void SetScreenJoystickVisible(SDL_JoystickID index, bool enable);
     /// Add screen joystick.
     /** Return the joystick index number when successful or M_MAX_UNSIGNED when error.
      *  If layout file is not given, use the default screen joystick layout.

+ 4 - 4
Source/Samples/Sample.inl

@@ -200,16 +200,16 @@ void Sample::HandleKeyDown(StringHash eventType, VariantMap& eventData)
             {
                 ResourceCache* cache = GetSubsystem<ResourceCache>();
                 screenJoystickSettingsIndex_ = input->AddScreenJoystick(cache->GetResource<XMLFile>("UI/ScreenJoystickSettings_Samples.xml"), cache->GetResource<XMLFile>("UI/DefaultStyle.xml"));
-                input->OpenJoystick(screenJoystickSettingsIndex_);
-                paused_ = true;
+                input->SetScreenJoystickVisible(screenJoystickSettingsIndex_, true);
+				paused_ = true;
             }
             else
             {
                 paused_ = !paused_;
                 if (paused_)
-                    input->OpenJoystick(screenJoystickSettingsIndex_);
+                    input->SetScreenJoystickVisible(screenJoystickSettingsIndex_, false);
                 else
-                    input->CloseJoystick(screenJoystickSettingsIndex_);
+                    input->SetScreenJoystickVisible(screenJoystickSettingsIndex_, true);
             }
         }