Browse Source

Merge remote-tracking branch 'remotes/thebluefish/master'

Lasse Öörni 11 years ago
parent
commit
5209e6e6a6

+ 2 - 2
Bin/Data/Scripts/NinjaSnowWar.as

@@ -502,7 +502,7 @@ void HandleKeyDown(StringHash eventType, VariantMap& eventData)
             {
                 if (screenJoystickSettingsIndex == M_MAX_UNSIGNED)
                     screenJoystickSettingsIndex = input.AddScreenJoystick(cache.GetResource("XMLFile", "UI/ScreenJoystickSettings_NinjaSnowWar.xml"));
-                input.OpenJoystick(screenJoystickSettingsIndex);
+                input.set_ScreenJoystickVisible(screenJoystickSettingsIndex, true);
             }
         }
         else
@@ -510,7 +510,7 @@ void HandleKeyDown(StringHash eventType, VariantMap& eventData)
             SetMessage("");
             if (screenJoystickSettingsIndex != M_MAX_UNSIGNED)
             {
-                input.CloseJoystick(screenJoystickSettingsIndex);
+                input.set_ScreenJoystickVisible(screenJoystickSettingsIndex, false);
                 input.RemoveScreenJoystick(screenJoystickSettingsIndex);
                 screenJoystickSettingsIndex = M_MAX_UNSIGNED;
             }

+ 92 - 95
Source/Engine/Input/Input.cpp

@@ -103,10 +103,10 @@ void Input::Update()
     mouseButtonPress_ = 0;
     mouseMove_ = IntVector2::ZERO;
     mouseMoveWheel_ = 0;
-    for (Vector<JoystickState>::Iterator i = joysticks_.Begin(); i != joysticks_.End(); ++i)
+    for (HashMap<SDL_JoystickID, JoystickState>::Iterator i = joysticks_.Begin(); i != joysticks_.End(); ++i)
     {
-        for (unsigned j = 0; j < i->buttonPress_.Size(); ++j)
-            i->buttonPress_[j] = false;
+        for (unsigned j = 0; j < i->second_.buttonPress_.Size(); ++j)
+            i->second_.buttonPress_[j] = false;
     }
 
     // Reset touch delta movement
@@ -231,17 +231,20 @@ void Input::SetMouseVisible(bool enable)
     #endif
 }
 
-void Input::SetToggleFullscreen(bool enable)
+void Input::SetScreenJoystickVisible(SDL_JoystickID index, bool enable)
 {
-    toggleFullscreen_ = enable;
+	if(joysticks_.Contains(index))
+	{
+		JoystickState& state = joysticks_[index];
+
+		if (state.screenJoystick_)
+        state.screenJoystick_->SetVisible(enable);
+	}
 }
 
-bool Input::DetectJoysticks()
+void Input::SetToggleFullscreen(bool enable)
 {
-    SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
-    SDL_InitSubSystem(SDL_INIT_JOYSTICK);
-    ResetJoysticks();
-    return true;
+    toggleFullscreen_ = enable;
 }
 
 static void PopulateKeyBindingMap(HashMap<String, int>& keyBindingMap)
@@ -281,7 +284,7 @@ static void PopulateKeyBindingMap(HashMap<String, int>& keyBindingMap)
     }
 }
 
-unsigned Input::AddScreenJoystick(XMLFile* layoutFile, XMLFile* styleFile)
+SDL_JoystickID Input::AddScreenJoystick(XMLFile* layoutFile, XMLFile* styleFile)
 {
     static HashMap<String, int> keyBindingMap;
 
@@ -309,10 +312,8 @@ unsigned Input::AddScreenJoystick(XMLFile* layoutFile, XMLFile* styleFile)
     screenJoystick->SetVisible(false);      // Set to visible when it is opened later
     ui->GetRoot()->AddChild(screenJoystick);
 
-    unsigned index = joysticks_.Size();
-    joysticks_.Resize(index + 1);
-    JoystickState& state = joysticks_[index];
-    joystickIDMap_[SCREEN_JOYSTICK_START_INDEX + index] = index;
+	SDL_JoystickID instanceID = SCREEN_JOYSTICK_START_INDEX + joysticks_.Size();
+    JoystickState& state = joysticks_[instanceID];
     state.name_ = screenJoystick->GetName();
     state.screenJoystick_ = screenJoystick;
 
@@ -412,7 +413,7 @@ unsigned Input::AddScreenJoystick(XMLFile* layoutFile, XMLFile* styleFile)
             }
         }
 
-        element->SetVar(VAR_SCREEN_JOYSTICK_INDEX, index);
+        element->SetVar(VAR_SCREEN_JOYSTICK_INDEX, instanceID);
     }
 
     // Make sure all the children are non-focusable so they do not mistakenly to be considered as active UI input controls by application
@@ -432,7 +433,7 @@ unsigned Input::AddScreenJoystick(XMLFile* layoutFile, XMLFile* styleFile)
     SubscribeToEvent(E_TOUCHMOVE, HANDLER(Input, HandleScreenJoystickTouch));
     SubscribeToEvent(E_TOUCHEND, HANDLER(Input, HandleScreenJoystickTouch));
 
-    return index;
+    return instanceID;
 }
 
 bool Input::RemoveScreenJoystick(unsigned index)
@@ -507,43 +508,29 @@ unsigned Input::LoadGestures(Deserializer& source)
     return SDL_LoadDollarTemplates(-1, wrapper.GetRWOps());
 }
 
-bool Input::OpenJoystick(unsigned index)
+SDL_JoystickID Input::OpenJoystick(unsigned index)
 {
-    if (index >= joysticks_.Size())
+    SDL_Joystick* joystick = SDL_JoystickOpen(index);
+	if (!joystick)
     {
-        LOGERRORF("Joystick index #%d is out of bounds", index);
-        return false;
+        LOGERRORF("Cannot open joystick #%d", index);
+        return -1;
     }
 
-    // Check if already opened
-    JoystickState& state = joysticks_[index];
-    if (joysticks_[index].joystick_ || (state.screenJoystick_ && state.screenJoystick_->IsVisible()))
-        return true;
+    // Map SDL joystick index to internal index (which starts at 0)
+    int sdl_joy_instance_id = SDL_JoystickInstanceID(joystick);
 
-    if (state.screenJoystick_)
-        state.screenJoystick_->SetVisible(true);
-    else
-    {
-        SDL_Joystick* joystick = SDL_JoystickOpen(index);
-        if (!joystick)
-        {
-            LOGERRORF("Cannot open joystick #%d (%s)", index, joysticks_[index].name_.CString());
-            return false;
-        }
+	JoystickState& state = joysticks_[sdl_joy_instance_id];
 
-        // Map SDL joystick index to internal index (which starts at 0)
-        int sdl_joy_instance_id = SDL_JoystickInstanceID(joystick);
-        joystickIDMap_[sdl_joy_instance_id] = index;
+    state.joystick_ = joystick;
+    if (SDL_IsGameController(index))
+       state.controller_ = SDL_GameControllerOpen(index);
 
-        state.joystick_ = joystick;
-        if (SDL_IsGameController(index))
-            state.controller_ = SDL_GameControllerOpen(index);
+    state.buttons_.Resize(SDL_JoystickNumButtons(joystick));
+    state.buttonPress_.Resize(state.buttons_.Size());
+    state.axes_.Resize(SDL_JoystickNumAxes(joystick));
+    state.hats_.Resize(SDL_JoystickNumHats(joystick));
 
-        state.buttons_.Resize(SDL_JoystickNumButtons(joystick));
-        state.buttonPress_.Resize(state.buttons_.Size());
-        state.axes_.Resize(SDL_JoystickNumAxes(joystick));
-        state.hats_.Resize(SDL_JoystickNumHats(joystick));
-    }
 
     for (unsigned i = 0; i < state.buttons_.Size(); ++i)
     {
@@ -555,26 +542,7 @@ bool Input::OpenJoystick(unsigned index)
     for (unsigned i = 0; i < state.hats_.Size(); ++i)
         state.hats_[i] = HAT_CENTER;
 
-    return true;
-}
-
-void Input::CloseJoystick(unsigned index)
-{
-    if (index >= joysticks_.Size())
-        return;
-
-    JoystickState& state = joysticks_[index];
-    if (joysticks_[index].joystick_)
-    {
-        SDL_JoystickClose(state.joystick_);
-        state.joystick_ = 0;
-        state.controller_ = 0;
-        state.buttons_.Clear();
-        state.axes_.Clear();
-        state.hats_.Clear();
-    }
-    else if (state.screenJoystick_ && state.screenJoystick_->IsVisible())
-        state.screenJoystick_->SetVisible(false);
+    return sdl_joy_instance_id;
 }
 
 int Input::GetKeyFromName(const String& name) const
@@ -698,14 +666,19 @@ TouchState* Input::GetTouch(unsigned index) const
     return const_cast<TouchState*>(&i->second_);
 }
 
-const String& Input::GetJoystickName(unsigned index) const
+const String& Input::GetJoystickName(SDL_JoystickID index) const
 {
-    return index < joysticks_.Size() ? joysticks_[index].name_ : String::EMPTY;
+	HashMap<SDL_JoystickID, JoystickState>::ConstIterator itr =	joysticks_.Find(index);
+
+	if(itr != joysticks_.End())
+		return itr->second_.name_;
+	else
+        return String::EMPTY;
 }
 
-JoystickState* Input::GetJoystick(unsigned index)
+JoystickState* Input::GetJoystick(SDL_JoystickID index)
 {
-    if (index < joysticks_.Size())
+    if (joysticks_.Contains(index))
     {
         JoystickState& state = joysticks_[index];
 
@@ -771,9 +744,12 @@ void Input::Initialize()
 void Input::ResetJoysticks()
 {
     joysticks_.Clear();
-    joysticks_.Resize(SDL_NumJoysticks());
-    for (unsigned i = 0; i < joysticks_.Size(); ++i)
-        joysticks_[i].name_ = SDL_JoystickNameForIndex(i);
+
+    int size = SDL_NumJoysticks();
+    for (unsigned i = 0; i < size; ++i)
+	{
+        OpenJoystick(i);
+	}
 }
 
 void Input::GainFocus()
@@ -816,12 +792,12 @@ void Input::ResetState()
     scancodePress_.Clear();
 
     /// \todo Check if this is necessary
-    for (Vector<JoystickState>::Iterator i = joysticks_.Begin(); i != joysticks_.End(); ++i)
+    for (HashMap<SDL_JoystickID, JoystickState>::Iterator i = joysticks_.Begin(); i != joysticks_.End(); ++i)
     {
-        for (unsigned j = 0; j < i->buttons_.Size(); ++j)
-            i->buttons_[j] = false;
-        for (unsigned j = 0; j < i->hats_.Size(); ++j)
-            i->hats_[j] = HAT_CENTER;
+		for (unsigned j = 0; j < i->second_.buttons_.Size(); ++j)
+            i->second_.buttons_[j] = false;
+        for (unsigned j = 0; j < i->second_.hats_.Size(); ++j)
+            i->second_.hats_[j] = HAT_CENTER;
     }
 
     // When clearing touch states, send the corresponding touch end events
@@ -1141,18 +1117,42 @@ void Input::HandleSDLEvent(void* sdlEvent)
         }
         break;
 
+	case SDL_JOYDEVICEADDED:
+		{
+			using namespace JoystickConnected;
+
+			SDL_JoystickID joyID = OpenJoystick(evt.jdevice.which);
+
+			VariantMap& eventData = GetEventDataMap();
+            eventData[P_JOYSTICK] = joyID;
+			SendEvent(E_JOYSTICKCONNECTED, eventData);
+		}
+		break;
+
+	case SDL_JOYDEVICEREMOVED:
+		{
+			using namespace JoystickDisconnected;
+
+			joysticks_.Erase(evt.jdevice.which);
+
+			VariantMap& eventData = GetEventDataMap();
+            eventData[P_JOYSTICK] = evt.jdevice.which;
+			SendEvent(E_JOYSTICKDISCONNECTED, eventData);
+		}
+		break;
+
     case SDL_JOYBUTTONDOWN:
         {
             using namespace JoystickButtonDown;
 
             unsigned button = evt.jbutton.button;
-            unsigned joystickIndex = joystickIDMap_[evt.jbutton.which];
+			SDL_JoystickID joystickIndex = evt.jbutton.which;
 
             VariantMap& eventData = GetEventDataMap();
             eventData[P_JOYSTICK] = joystickIndex;
             eventData[P_BUTTON] = button;
 
-            if (joystickIndex < joysticks_.Size() && button < joysticks_[joystickIndex].buttons_.Size()) {
+            if (button < joysticks_[joystickIndex].buttons_.Size()) {
                 joysticks_[joystickIndex].buttons_[button] = true;
                 joysticks_[joystickIndex].buttonPress_[button] = true;
                 SendEvent(E_JOYSTICKBUTTONDOWN, eventData);
@@ -1165,13 +1165,13 @@ void Input::HandleSDLEvent(void* sdlEvent)
             using namespace JoystickButtonUp;
 
             unsigned button = evt.jbutton.button;
-            unsigned joystickIndex = joystickIDMap_[evt.jbutton.which];
+			SDL_JoystickID joystickIndex = evt.jbutton.which;
 
             VariantMap& eventData = GetEventDataMap();
             eventData[P_JOYSTICK] = joystickIndex;
             eventData[P_BUTTON] = button;
 
-            if (joystickIndex < joysticks_.Size() && button < joysticks_[joystickIndex].buttons_.Size()) {
+            if (button < joysticks_[joystickIndex].buttons_.Size()) {
                 joysticks_[joystickIndex].buttons_[button] = false;
                 SendEvent(E_JOYSTICKBUTTONUP, eventData);
             }
@@ -1182,15 +1182,14 @@ void Input::HandleSDLEvent(void* sdlEvent)
         {
             using namespace JoystickAxisMove;
 
-            unsigned joystickIndex = joystickIDMap_[evt.jaxis.which];
+			SDL_JoystickID joystickIndex = evt.jaxis.which;
 
             VariantMap& eventData = GetEventDataMap();
             eventData[P_JOYSTICK] = joystickIndex;
             eventData[P_AXIS] = evt.jaxis.axis;
             eventData[P_POSITION] = Clamp((float)evt.jaxis.value / 32767.0f, -1.0f, 1.0f);
 
-            if (joystickIndex < joysticks_.Size() && evt.jaxis.axis <
-                joysticks_[joystickIndex].axes_.Size())
+            if (evt.jaxis.axis < joysticks_[joystickIndex].axes_.Size())
             {
                 joysticks_[joystickIndex].axes_[evt.jaxis.axis] = eventData[P_POSITION].GetFloat();
                 SendEvent(E_JOYSTICKAXISMOVE, eventData);
@@ -1202,15 +1201,14 @@ void Input::HandleSDLEvent(void* sdlEvent)
         {
             using namespace JoystickHatMove;
 
-            unsigned joystickIndex = joystickIDMap_[evt.jaxis.which];
+			SDL_JoystickID joystickIndex = evt.jaxis.which;
 
             VariantMap& eventData = GetEventDataMap();
             eventData[P_JOYSTICK] = joystickIndex;
             eventData[P_HAT] = evt.jhat.hat;
             eventData[P_POSITION] = evt.jhat.value;
 
-            if (joystickIndex < joysticks_.Size() && evt.jhat.hat <
-                joysticks_[joystickIndex].hats_.Size())
+            if (evt.jhat.hat < joysticks_[joystickIndex].hats_.Size())
             {
                 joysticks_[joystickIndex].hats_[evt.jhat.hat] = evt.jhat.value;
                 SendEvent(E_JOYSTICKHATMOVE, eventData);
@@ -1223,13 +1221,13 @@ void Input::HandleSDLEvent(void* sdlEvent)
             using namespace ControllerButtonDown;
 
             unsigned button = evt.cbutton.button;
-            unsigned joystickIndex = joystickIDMap_[evt.cbutton.which];
+			SDL_JoystickID joystickIndex = evt.cbutton.which;
 
             VariantMap& eventData = GetEventDataMap();
             eventData[P_JOYSTICK] = joystickIndex;
             eventData[P_BUTTON] = button;
 
-            if (joystickIndex < joysticks_.Size() && button < joysticks_[joystickIndex].buttons_.Size()) {
+            if (button < joysticks_[joystickIndex].buttons_.Size()) {
                 joysticks_[joystickIndex].buttons_[button] = true;
                 joysticks_[joystickIndex].buttonPress_[button] = true;
                 SendEvent(E_CONTROLLERBUTTONDOWN, eventData);
@@ -1242,13 +1240,13 @@ void Input::HandleSDLEvent(void* sdlEvent)
             using namespace ControllerButtonUp;
 
             unsigned button = evt.cbutton.button;
-            unsigned joystickIndex = joystickIDMap_[evt.cbutton.which];
+			SDL_JoystickID joystickIndex = evt.cbutton.which;
 
             VariantMap& eventData = GetEventDataMap();
             eventData[P_JOYSTICK] = joystickIndex;
             eventData[P_BUTTON] = button;
 
-            if (joystickIndex < joysticks_.Size() && button < joysticks_[joystickIndex].buttons_.Size()) {
+            if (button < joysticks_[joystickIndex].buttons_.Size()) {
                 joysticks_[joystickIndex].buttons_[button] = false;
                 SendEvent(E_CONTROLLERBUTTONUP, eventData);
             }
@@ -1259,15 +1257,14 @@ void Input::HandleSDLEvent(void* sdlEvent)
         {
             using namespace ControllerAxisMove;
 
-            unsigned joystickIndex = joystickIDMap_[evt.caxis.which];
+			SDL_JoystickID joystickIndex = evt.caxis.which;
 
             VariantMap& eventData = GetEventDataMap();
             eventData[P_JOYSTICK] = joystickIndex;
             eventData[P_AXIS] = evt.caxis.axis;
             eventData[P_POSITION] = Clamp((float)evt.caxis.value / 32767.0f, -1.0f, 1.0f);
 
-            if (joystickIndex < joysticks_.Size() && evt.caxis.axis <
-                joysticks_[joystickIndex].axes_.Size())
+            if (evt.caxis.axis < joysticks_[joystickIndex].axes_.Size())
             {
                 joysticks_[joystickIndex].axes_[evt.caxis.axis] = eventData[P_POSITION].GetFloat();
                 SendEvent(E_CONTROLLERAXISMOVE, eventData);

+ 10 - 12
Source/Engine/Input/Input.h

@@ -107,6 +107,8 @@ struct JoystickState
 
     /// SDL joystick.
     SDL_Joystick* joystick_;
+	/// SDL joystick instance ID
+	SDL_JoystickID instanceID_;
     /// SDL game controller.
     SDL_GameController* controller_;
     /// UI element containing the screen joystick.
@@ -140,12 +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);
-    /// Open a joystick. Return true if successful.
-    bool OpenJoystick(unsigned index);
-    /// Close a joystick.
-    void CloseJoystick(unsigned index);
-    /// Redetect joysticks. Return true if successful.
-    bool DetectJoysticks();
+	/// 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.
@@ -153,7 +151,7 @@ public:
      *
      *  This method should only be called in main thread.
      */
-    unsigned AddScreenJoystick(XMLFile* layoutFile = 0, XMLFile* styleFile = 0);
+    SDL_JoystickID AddScreenJoystick(XMLFile* layoutFile = 0, XMLFile* styleFile = 0);
     /// Remove screen joystick by index.
     /** Return true if successful.
      *
@@ -218,9 +216,9 @@ public:
     /// Return number of connected joysticks.
     unsigned GetNumJoysticks() const { return joysticks_.Size(); }
     /// Return joystick name by index.
-    const String& GetJoystickName(unsigned index) const;
+    const String& GetJoystickName(SDL_JoystickID index) const;
     /// Return joystick state by index. Automatically open if not opened yet.
-    JoystickState* GetJoystick(unsigned index);
+    JoystickState* GetJoystick(SDL_JoystickID index);
     /// Return whether fullscreen toggle is enabled.
     bool GetToggleFullscreen() const { return toggleFullscreen_; }
     /// Return whether on-screen keyboard is supported.
@@ -237,6 +235,8 @@ public:
 private:
     /// Initialize when screen mode initially set.
     void Initialize();
+	/// Open a joystick. Return -1 if no joystick.
+    SDL_JoystickID OpenJoystick(unsigned index);
     /// Setup internal joystick structures.
     void ResetJoysticks();
     /// Prepare input state for application gaining input focus.
@@ -279,7 +279,7 @@ private:
     /// String for text input.
     String textInput_;
     /// Opened joysticks.
-    Vector<JoystickState> joysticks_;
+    HashMap<SDL_JoystickID, JoystickState> joysticks_;
     /// Mouse buttons' down state.
     unsigned mouseButtonDown_;
     /// Mouse buttons' pressed state.
@@ -306,8 +306,6 @@ private:
     bool suppressNextMouseMove_;
     /// Initialized flag.
     bool initialized_;
-    /// Map SDL joystick ID to internal index.
-    HashMap<int, unsigned> joystickIDMap_;
 };
 
 }

+ 12 - 0
Source/Engine/Input/InputEvents.h

@@ -95,6 +95,18 @@ EVENT(E_TEXTINPUT, TextInput)
     PARAM(P_QUALIFIERS, Qualifiers);        // int
 }
 
+/// Joystick button pressed.
+EVENT(E_JOYSTICKCONNECTED, JoystickConnected)
+{
+    PARAM(P_JOYSTICK, Joystick);            // int
+}
+
+/// Joystick button pressed.
+EVENT(E_JOYSTICKDISCONNECTED, JoystickDisconnected)
+{
+    PARAM(P_JOYSTICK, Joystick);            // int
+}
+
 /// Joystick button pressed.
 EVENT(E_JOYSTICKBUTTONDOWN, JoystickButtonDown)
 {

+ 0 - 3
Source/Engine/LuaScript/pkgs/Input/Input.pkg

@@ -32,9 +32,6 @@ class Input : public Object
 {
     void SetToggleFullscreen(bool enable);
     void SetMouseVisible(bool enable);
-    bool OpenJoystick(unsigned index);
-    void CloseJoystick(unsigned index);
-    bool DetectJoysticks();
     unsigned AddScreenJoystick(XMLFile* layoutFile = 0, XMLFile* styleFile = 0);
     bool RemoveScreenJoystick(unsigned index);
     void SetScreenKeyboardVisible(bool enable);

+ 1 - 3
Source/Engine/Script/InputAPI.cpp

@@ -468,9 +468,6 @@ static void RegisterInput(asIScriptEngine* engine)
     engine->RegisterObjectMethod("JoystickState", "int get_hatPosition(uint) const", asMETHOD(JoystickState, GetHatPosition), asCALL_THISCALL);
 
     RegisterObject<Input>(engine, "Input");
-    engine->RegisterObjectMethod("Input", "bool OpenJoystick(uint)", asMETHOD(Input, OpenJoystick), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Input", "void CloseJoystick(uint)", asMETHOD(Input, CloseJoystick), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Input", "bool DetectJoysticks()", asMETHOD(Input, DetectJoysticks), asCALL_THISCALL);
     engine->RegisterObjectMethod("Input", "uint AddScreenJoystick(XMLFile@+ layoutFile = null, XMLFile@+ styleFile = null)", asMETHOD(Input, AddScreenJoystick), asCALL_THISCALL);
     engine->RegisterObjectMethod("Input", "bool RemoveScreenJoystick(uint)", asMETHOD(Input, RemoveScreenJoystick), asCALL_THISCALL);
     engine->RegisterObjectMethod("Input", "bool RecordGesture()", asMETHOD(Input, RecordGesture), asCALL_THISCALL);
@@ -484,6 +481,7 @@ static void RegisterInput(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Input", "int GetScancodeFromName(const String&in) const", asMETHOD(Input, GetScancodeFromName), asCALL_THISCALL);
     engine->RegisterObjectMethod("Input", "String GetScancodeName(int) const", asMETHOD(Input, GetScancodeName), asCALL_THISCALL);
     engine->RegisterObjectMethod("Input", "void set_mouseVisible(bool)", asMETHOD(Input, SetMouseVisible), asCALL_THISCALL);
+	engine->RegisterObjectMethod("Input", "void set_ScreenJoystickVisible(int, bool)", asMETHOD(Input, SetScreenJoystickVisible), asCALL_THISCALL);
     engine->RegisterObjectMethod("Input", "bool get_mouseVisible() const", asMETHOD(Input, IsMouseVisible), asCALL_THISCALL);
     engine->RegisterObjectMethod("Input", "void set_screenKeyboardVisible(bool)", asMETHOD(Input, SetScreenKeyboardVisible), asCALL_THISCALL);
     engine->RegisterObjectMethod("Input", "bool get_screenKeyboardVisible() const", asMETHOD(Input, IsScreenKeyboardVisible), asCALL_THISCALL);

+ 5 - 5
Source/Samples/Sample.inl

@@ -90,7 +90,7 @@ void Sample::InitTouchInput()
         ResourceCache* cache = GetSubsystem<ResourceCache>();
         Input* input = GetSubsystem<Input>();
         screenJoystickIndex_ = input->AddScreenJoystick(cache->GetResource<XMLFile>("UI/ScreenJoystick_Samples.xml"), cache->GetResource<XMLFile>("UI/DefaultStyle.xml"));
-        input->OpenJoystick(screenJoystickIndex_);
+        input->SetScreenJoystickVisible(screenJoystickSettingsIndex_, true);
     }
 }
 
@@ -199,16 +199,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);
             }
         }