From 34692ab826abc8f8faa61bdb2280b742424528f1 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 7 Dec 2013 15:14:29 -0500 Subject: Remove unnecessary Src/ folders --- Source/Core/DolphinWX/Android/ButtonManager.cpp | 223 ++++++++++++++++++++++++ 1 file changed, 223 insertions(+) create mode 100644 Source/Core/DolphinWX/Android/ButtonManager.cpp (limited to 'Source/Core/DolphinWX/Android/ButtonManager.cpp') diff --git a/Source/Core/DolphinWX/Android/ButtonManager.cpp b/Source/Core/DolphinWX/Android/ButtonManager.cpp new file mode 100644 index 0000000000..f3127678fa --- /dev/null +++ b/Source/Core/DolphinWX/Android/ButtonManager.cpp @@ -0,0 +1,223 @@ +// Copyright (C) 2003 Dolphin Project. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 2.0. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License 2.0 for more details. + +// A copy of the GPL 2.0 should have been included with the program. +// If not, see http://www.gnu.org/licenses/ + +// Official SVN repository and contact information can be found at +// http://code.google.com/p/dolphin-emu/ + +#include +#include "GLInterface.h" +#include "Android/ButtonManager.h" + +extern void DrawButton(GLuint tex, float *coords); + +namespace ButtonManager +{ + // Pair key is padID, BUTTONTYPE + std::map, Button*> m_buttons; + std::map, Axis*> m_axises; + std::unordered_map m_controllers; + const char* configStrings[] = { "InputA", + "InputB", + "InputStart", + "InputX", + "InputY", + "InputZ", + "DPadUp", + "DPadDown", + "DPadLeft", + "DPadRight", + "MainUp", + "MainDown", + "MainLeft", + "MainRight", + "CStickUp", + "CStickDown", + "CStickLeft", + "CStickRight", + "InputL", + "InputR" }; + const int configStringNum = 20; + + void AddBind(std::string dev, sBind *bind) + { + auto it = m_controllers.find(dev); + if (it != m_controllers.end()) + { + it->second->AddBind(bind); + return; + } + m_controllers[dev] = new InputDevice(dev); + m_controllers[dev]->AddBind(bind); + } + + void Init() + { + // Initialize our touchscreen buttons + for (int a = 0; a < 4; ++a) + { + m_buttons[std::make_pair(a, BUTTON_A)] = new Button(); + m_buttons[std::make_pair(a, BUTTON_B)] = new Button(); + m_buttons[std::make_pair(a, BUTTON_START)] = new Button(); + m_buttons[std::make_pair(a, BUTTON_X)] = new Button(); + m_buttons[std::make_pair(a, BUTTON_Y)] = new Button(); + m_buttons[std::make_pair(a, BUTTON_Z)] = new Button(); + m_buttons[std::make_pair(a, BUTTON_UP)] = new Button(); + m_buttons[std::make_pair(a, BUTTON_DOWN)] = new Button(); + m_buttons[std::make_pair(a, BUTTON_LEFT)] = new Button(); + m_buttons[std::make_pair(a, BUTTON_RIGHT)] = new Button(); + + m_axises[std::make_pair(a, STICK_MAIN_UP)] = new Axis(); + m_axises[std::make_pair(a, STICK_MAIN_DOWN)] = new Axis(); + m_axises[std::make_pair(a, STICK_MAIN_LEFT)] = new Axis(); + m_axises[std::make_pair(a, STICK_MAIN_RIGHT)] = new Axis(); + m_axises[std::make_pair(a, STICK_C_UP)] = new Axis(); + m_axises[std::make_pair(a, STICK_C_DOWN)] = new Axis(); + m_axises[std::make_pair(a, STICK_C_LEFT)] = new Axis(); + m_axises[std::make_pair(a, STICK_C_RIGHT)] = new Axis(); + m_buttons[std::make_pair(a, TRIGGER_L)] = new Button(); + m_buttons[std::make_pair(a, TRIGGER_R)] = new Button(); + } + // Init our controller bindings + IniFile ini; + ini.Load(File::GetUserPath(D_CONFIG_IDX) + std::string("Dolphin.ini")); + for (int a = 0; a < configStringNum; ++a) + { + for (int padID = 0; padID < 4; ++padID) + { + std::ostringstream config; + config << configStrings[a] << "_" << padID; + BindType type; + int bindnum; + char dev[128]; + bool hasbind = false; + char modifier = 0; + std::string value; + ini.Get("Android", config.str().c_str(), &value, "None"); + if (value == "None") + continue; + if (std::string::npos != value.find("Axis")) + { + hasbind = true; + type = BIND_AXIS; + sscanf(value.c_str(), "Device '%[^\']'-Axis %d%c", dev, &bindnum, &modifier); + } + else if (std::string::npos != value.find("Button")) + { + hasbind = true; + type = BIND_BUTTON; + sscanf(value.c_str(), "Device '%[^\']'-Button %d", dev, &bindnum); + } + if (hasbind) + AddBind(std::string(dev), new sBind(padID, (ButtonType)a, type, bindnum, modifier == '-' ? -1.0f : 1.0f)); + } + } + + } + bool GetButtonPressed(int padID, ButtonType button) + { + bool pressed = false; + pressed = m_buttons[std::make_pair(padID, button)]->Pressed(); + + for (auto it = m_controllers.begin(); it != m_controllers.end(); ++it) + pressed |= it->second->ButtonValue(padID, button); + + return pressed; + } + float GetAxisValue(int padID, ButtonType axis) + { + float value = m_axises[std::make_pair(padID, axis)]->AxisValue(); + auto it = m_controllers.begin(); + if (it == m_controllers.end()) + return value; + return value != 0.0f ? value : it->second->AxisValue(padID, axis); + } + void TouchEvent(int padID, ButtonType button, int action) + { + m_buttons[std::make_pair(padID, button)]->SetState(action ? BUTTON_PRESSED : BUTTON_RELEASED); + } + void TouchAxisEvent(int padID, ButtonType axis, float value) + { + m_axises[std::make_pair(padID, axis)]->SetValue(value); + } + void GamepadEvent(std::string dev, int button, int action) + { + auto it = m_controllers.find(dev); + if (it != m_controllers.end()) + { + it->second->PressEvent(button, action); + return; + } + m_controllers[dev] = new InputDevice(dev); + m_controllers[dev]->PressEvent(button, action); + } + void GamepadAxisEvent(std::string dev, int axis, float value) + { + auto it = m_controllers.find(dev); + if (it != m_controllers.end()) + { + it->second->AxisEvent(axis, value); + return; + } + m_controllers[dev] = new InputDevice(dev); + m_controllers[dev]->AxisEvent(axis, value); + } + void Shutdown() + { + for(auto it = m_buttons.begin(); it != m_buttons.end(); ++it) + delete it->second; + for (auto it = m_controllers.begin(); it != m_controllers.end(); ++it) + delete it->second; + m_controllers.clear(); + m_buttons.clear(); + } + + // InputDevice + void InputDevice::PressEvent(int button, int action) + { + if (_inputbinds.find(button) == _inputbinds.end()) + return; + _buttons[_inputbinds[button]->_buttontype] = action == 0 ? true : false; + } + void InputDevice::AxisEvent(int axis, float value) + { + if (_inputbinds.find(axis) == _inputbinds.end()) + return; + _axises[_inputbinds[axis]->_buttontype] = value; + } + bool InputDevice::ButtonValue(int padID, ButtonType button) + { + auto it = _binds.find(button); + if (it == _binds.end()) + return false; + if (it->second->_padID != padID) + return false; + if (it->second->_bindtype == BIND_BUTTON) + return _buttons[it->second->_buttontype]; + else + return AxisValue(padID, button); + } + float InputDevice::AxisValue(int padID, ButtonType axis) + { + auto it = _binds.find(axis); + if (it == _binds.end()) + return 0.0f; + if (it->second->_padID != padID) + return 0.0f; + if (it->second->_bindtype == BIND_BUTTON) + return ButtonValue(padID, axis); + else + return _axises[it->second->_buttontype] * it->second->_neg; + } + +} -- cgit v1.2.3 From 3d4d3f6b112ab5d6da21ab5e8a9147585df29327 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Mon, 13 Jan 2014 03:14:09 -0600 Subject: [GLExtensions] Remove a bunch of unneeded headers. Fix Linux+EGL compiling. Move include to glx.h around to work around it including global GL/gl.h --- Source/Core/DolphinWX/Android/ButtonManager.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'Source/Core/DolphinWX/Android/ButtonManager.cpp') diff --git a/Source/Core/DolphinWX/Android/ButtonManager.cpp b/Source/Core/DolphinWX/Android/ButtonManager.cpp index f3127678fa..ceabbb581c 100644 --- a/Source/Core/DolphinWX/Android/ButtonManager.cpp +++ b/Source/Core/DolphinWX/Android/ButtonManager.cpp @@ -19,8 +19,6 @@ #include "GLInterface.h" #include "Android/ButtonManager.h" -extern void DrawButton(GLuint tex, float *coords); - namespace ButtonManager { // Pair key is padID, BUTTONTYPE -- cgit v1.2.3 From 2c8340e1dc3b05d7f314c363ebc9278f40eb5350 Mon Sep 17 00:00:00 2001 From: Scott Moreau Date: Mon, 20 Jan 2014 00:46:21 -0700 Subject: Move GLInterface.h into GLInterface directory --- Source/Core/DolphinWX/Android/ButtonManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/DolphinWX/Android/ButtonManager.cpp') diff --git a/Source/Core/DolphinWX/Android/ButtonManager.cpp b/Source/Core/DolphinWX/Android/ButtonManager.cpp index ceabbb581c..f451d64412 100644 --- a/Source/Core/DolphinWX/Android/ButtonManager.cpp +++ b/Source/Core/DolphinWX/Android/ButtonManager.cpp @@ -16,7 +16,7 @@ // http://code.google.com/p/dolphin-emu/ #include -#include "GLInterface.h" +#include "GLInterface/GLInterface.h" #include "Android/ButtonManager.h" namespace ButtonManager -- cgit v1.2.3 From 3fe05e0a9f6908c1cf9a3caad6bff1d8decf04a3 Mon Sep 17 00:00:00 2001 From: Matthew Parlane Date: Sat, 8 Feb 2014 18:50:37 +1300 Subject: Fix IniFile to use string& instead of char* Also removes .c_str() usages where found. --- Source/Core/DolphinWX/Android/ButtonManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/DolphinWX/Android/ButtonManager.cpp') diff --git a/Source/Core/DolphinWX/Android/ButtonManager.cpp b/Source/Core/DolphinWX/Android/ButtonManager.cpp index f451d64412..5c71a7197a 100644 --- a/Source/Core/DolphinWX/Android/ButtonManager.cpp +++ b/Source/Core/DolphinWX/Android/ButtonManager.cpp @@ -101,7 +101,7 @@ namespace ButtonManager bool hasbind = false; char modifier = 0; std::string value; - ini.Get("Android", config.str().c_str(), &value, "None"); + ini.Get("Android", config.str(), &value, "None"); if (value == "None") continue; if (std::string::npos != value.find("Axis")) -- cgit v1.2.3 From 404624bf0b0125e5a408021c616ee9b9e2dde382 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Wed, 12 Feb 2014 16:00:34 +0100 Subject: Turn loops into range-based form and some things suggested by cppcheck and compiler warnings. --- Source/Core/DolphinWX/Android/ButtonManager.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'Source/Core/DolphinWX/Android/ButtonManager.cpp') diff --git a/Source/Core/DolphinWX/Android/ButtonManager.cpp b/Source/Core/DolphinWX/Android/ButtonManager.cpp index 5c71a7197a..7d4fb97f3d 100644 --- a/Source/Core/DolphinWX/Android/ButtonManager.cpp +++ b/Source/Core/DolphinWX/Android/ButtonManager.cpp @@ -127,8 +127,8 @@ namespace ButtonManager bool pressed = false; pressed = m_buttons[std::make_pair(padID, button)]->Pressed(); - for (auto it = m_controllers.begin(); it != m_controllers.end(); ++it) - pressed |= it->second->ButtonValue(padID, button); + for (const auto& ctrl : m_controllers) + pressed |= ctrl.second->ButtonValue(padID, button); return pressed; } @@ -172,10 +172,10 @@ namespace ButtonManager } void Shutdown() { - for(auto it = m_buttons.begin(); it != m_buttons.end(); ++it) - delete it->second; - for (auto it = m_controllers.begin(); it != m_controllers.end(); ++it) - delete it->second; + for (const auto& button : m_buttons) + delete button.second; + for (const auto& controller : m_controllers) + delete controller.second; m_controllers.clear(); m_buttons.clear(); } -- cgit v1.2.3 From 3fd87a7636ff434118a5d7f7334550be8db55c0b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 16 Feb 2014 23:51:41 -0500 Subject: Second and final pass of clearing out tabs. --- Source/Core/DolphinWX/Android/ButtonManager.cpp | 42 +++++++++++++------------ 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'Source/Core/DolphinWX/Android/ButtonManager.cpp') diff --git a/Source/Core/DolphinWX/Android/ButtonManager.cpp b/Source/Core/DolphinWX/Android/ButtonManager.cpp index 7d4fb97f3d..257237252f 100644 --- a/Source/Core/DolphinWX/Android/ButtonManager.cpp +++ b/Source/Core/DolphinWX/Android/ButtonManager.cpp @@ -25,26 +25,28 @@ namespace ButtonManager std::map, Button*> m_buttons; std::map, Axis*> m_axises; std::unordered_map m_controllers; - const char* configStrings[] = { "InputA", - "InputB", - "InputStart", - "InputX", - "InputY", - "InputZ", - "DPadUp", - "DPadDown", - "DPadLeft", - "DPadRight", - "MainUp", - "MainDown", - "MainLeft", - "MainRight", - "CStickUp", - "CStickDown", - "CStickLeft", - "CStickRight", - "InputL", - "InputR" }; + const char* configStrings[] = { + "InputA", + "InputB", + "InputStart", + "InputX", + "InputY", + "InputZ", + "DPadUp", + "DPadDown", + "DPadLeft", + "DPadRight", + "MainUp", + "MainDown", + "MainLeft", + "MainRight", + "CStickUp", + "CStickDown", + "CStickLeft", + "CStickRight", + "InputL", + "InputR" + }; const int configStringNum = 20; void AddBind(std::string dev, sBind *bind) -- cgit v1.2.3 From 2afe2152712981e21d6bda6f029292ed2b1cf91e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 17 Feb 2014 05:18:15 -0500 Subject: Convert all includes to relative paths. --- Source/Core/DolphinWX/Android/ButtonManager.cpp | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'Source/Core/DolphinWX/Android/ButtonManager.cpp') diff --git a/Source/Core/DolphinWX/Android/ButtonManager.cpp b/Source/Core/DolphinWX/Android/ButtonManager.cpp index 257237252f..a8ebafdd20 100644 --- a/Source/Core/DolphinWX/Android/ButtonManager.cpp +++ b/Source/Core/DolphinWX/Android/ButtonManager.cpp @@ -1,23 +1,11 @@ -// Copyright (C) 2003 Dolphin Project. - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, version 2.0. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License 2.0 for more details. - -// A copy of the GPL 2.0 should have been included with the program. -// If not, see http://www.gnu.org/licenses/ - -// Official SVN repository and contact information can be found at -// http://code.google.com/p/dolphin-emu/ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. #include -#include "GLInterface/GLInterface.h" -#include "Android/ButtonManager.h" + +#include "DolphinWX/Android/ButtonManager.h" +#include "DolphinWX/GLInterface/GLInterface.h" namespace ButtonManager { -- cgit v1.2.3 From 315a8ba1c04bf8cffd9b04096be898ac462fa89e Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 23 Feb 2014 23:03:39 +0100 Subject: Various changes suggested by cppcheck - remove unused variables - reduce the scope where it makes sense - correct limits (did you know that strcat()'s last parameter does not include the \0 that is always added?) - set some free()'d pointers to NULL --- Source/Core/DolphinWX/Android/ButtonManager.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Source/Core/DolphinWX/Android/ButtonManager.cpp') diff --git a/Source/Core/DolphinWX/Android/ButtonManager.cpp b/Source/Core/DolphinWX/Android/ButtonManager.cpp index a8ebafdd20..e945f0638a 100644 --- a/Source/Core/DolphinWX/Android/ButtonManager.cpp +++ b/Source/Core/DolphinWX/Android/ButtonManager.cpp @@ -114,8 +114,7 @@ namespace ButtonManager } bool GetButtonPressed(int padID, ButtonType button) { - bool pressed = false; - pressed = m_buttons[std::make_pair(padID, button)]->Pressed(); + bool pressed = m_buttons[std::make_pair(padID, button)]->Pressed(); for (const auto& ctrl : m_controllers) pressed |= ctrl.second->ButtonValue(padID, button); -- cgit v1.2.3 From e1bbda1e1884665ff52d5250458e40b7227a53bc Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Wed, 23 Apr 2014 03:49:25 -0500 Subject: [Android] Fix a bunch of input bugs. Looking at the old code for the ButtonManager was a brainfsck. This fixes a ton of bugs I kept uncovering as I was moving along. Fixes the gamepad configuration file being incorrect. No longer treats touchscreen in a special way. Ends up as a regular device with a "Touchscreen" device name. Was incorrectly converting a index from integer to ButtonType. Wouldn't work due to the addition of some unused(in JNI) enumerators in ButtonType. Fixes an issue where a map had a key as an axis which was causing its binding to be overwritten for every axis that was used twice (eg main stick left and right); Fixes Triggers not working at all. Fixes DPad not working at all. Fixes C-Stick only half working. Removes touch screen specific nativelibrary types onTouchAxisEvent and onTouchEvent. Adds a configuration version configuration option. Allows easy configuration overwriting if the options need to be changed during updating. Supersedes github PR #291. --- Source/Core/DolphinWX/Android/ButtonManager.cpp | 159 ++++++++++++++---------- 1 file changed, 92 insertions(+), 67 deletions(-) (limited to 'Source/Core/DolphinWX/Android/ButtonManager.cpp') diff --git a/Source/Core/DolphinWX/Android/ButtonManager.cpp b/Source/Core/DolphinWX/Android/ButtonManager.cpp index e945f0638a..a1684ba5a6 100644 --- a/Source/Core/DolphinWX/Android/ButtonManager.cpp +++ b/Source/Core/DolphinWX/Android/ButtonManager.cpp @@ -9,11 +9,9 @@ namespace ButtonManager { - // Pair key is padID, BUTTONTYPE - std::map, Button*> m_buttons; - std::map, Axis*> m_axises; + const std::string touchScreenKey = "Touchscreen"; std::unordered_map m_controllers; - const char* configStrings[] = { + std::vector configStrings = { "InputA", "InputB", "InputStart", @@ -35,7 +33,28 @@ namespace ButtonManager "InputL", "InputR" }; - const int configStringNum = 20; + std::vector configTypes = { + BUTTON_A, + BUTTON_B, + BUTTON_START, + BUTTON_X, + BUTTON_Y, + BUTTON_Z, + BUTTON_UP, + BUTTON_DOWN, + BUTTON_LEFT, + BUTTON_RIGHT, + STICK_MAIN_UP, + STICK_MAIN_DOWN, + STICK_MAIN_LEFT, + STICK_MAIN_RIGHT, + STICK_C_UP, + STICK_C_DOWN, + STICK_C_LEFT, + STICK_C_RIGHT, + TRIGGER_L, + TRIGGER_R + }; void AddBind(std::string dev, sBind *bind) { @@ -51,35 +70,35 @@ namespace ButtonManager void Init() { - // Initialize our touchscreen buttons + // Initialize our touchScreenKey buttons for (int a = 0; a < 4; ++a) { - m_buttons[std::make_pair(a, BUTTON_A)] = new Button(); - m_buttons[std::make_pair(a, BUTTON_B)] = new Button(); - m_buttons[std::make_pair(a, BUTTON_START)] = new Button(); - m_buttons[std::make_pair(a, BUTTON_X)] = new Button(); - m_buttons[std::make_pair(a, BUTTON_Y)] = new Button(); - m_buttons[std::make_pair(a, BUTTON_Z)] = new Button(); - m_buttons[std::make_pair(a, BUTTON_UP)] = new Button(); - m_buttons[std::make_pair(a, BUTTON_DOWN)] = new Button(); - m_buttons[std::make_pair(a, BUTTON_LEFT)] = new Button(); - m_buttons[std::make_pair(a, BUTTON_RIGHT)] = new Button(); + AddBind(touchScreenKey, new sBind(a, BUTTON_A, BIND_BUTTON, BUTTON_A, 1.0f)); + AddBind(touchScreenKey, new sBind(a, BUTTON_B, BIND_BUTTON, BUTTON_B, 1.0f)); + AddBind(touchScreenKey, new sBind(a, BUTTON_START, BIND_BUTTON, BUTTON_START, 1.0f)); + AddBind(touchScreenKey, new sBind(a, BUTTON_X, BIND_BUTTON, BUTTON_X, 1.0f)); + AddBind(touchScreenKey, new sBind(a, BUTTON_Y, BIND_BUTTON, BUTTON_Y, 1.0f)); + AddBind(touchScreenKey, new sBind(a, BUTTON_Z, BIND_BUTTON, BUTTON_Z, 1.0f)); + AddBind(touchScreenKey, new sBind(a, BUTTON_UP, BIND_BUTTON, BUTTON_UP, 1.0f)); + AddBind(touchScreenKey, new sBind(a, BUTTON_DOWN, BIND_BUTTON, BUTTON_DOWN, 1.0f)); + AddBind(touchScreenKey, new sBind(a, BUTTON_LEFT, BIND_BUTTON, BUTTON_LEFT, 1.0f)); + AddBind(touchScreenKey, new sBind(a, BUTTON_RIGHT, BIND_BUTTON, BUTTON_RIGHT, 1.0f)); - m_axises[std::make_pair(a, STICK_MAIN_UP)] = new Axis(); - m_axises[std::make_pair(a, STICK_MAIN_DOWN)] = new Axis(); - m_axises[std::make_pair(a, STICK_MAIN_LEFT)] = new Axis(); - m_axises[std::make_pair(a, STICK_MAIN_RIGHT)] = new Axis(); - m_axises[std::make_pair(a, STICK_C_UP)] = new Axis(); - m_axises[std::make_pair(a, STICK_C_DOWN)] = new Axis(); - m_axises[std::make_pair(a, STICK_C_LEFT)] = new Axis(); - m_axises[std::make_pair(a, STICK_C_RIGHT)] = new Axis(); - m_buttons[std::make_pair(a, TRIGGER_L)] = new Button(); - m_buttons[std::make_pair(a, TRIGGER_R)] = new Button(); + AddBind(touchScreenKey, new sBind(a, STICK_MAIN_UP, BIND_AXIS, STICK_MAIN_UP, -1.0f)); + AddBind(touchScreenKey, new sBind(a, STICK_MAIN_DOWN, BIND_AXIS, STICK_MAIN_DOWN, 1.0f)); + AddBind(touchScreenKey, new sBind(a, STICK_MAIN_LEFT, BIND_AXIS, STICK_MAIN_LEFT, -1.0f)); + AddBind(touchScreenKey, new sBind(a, STICK_MAIN_RIGHT, BIND_AXIS, STICK_MAIN_RIGHT, 1.0f)); + AddBind(touchScreenKey, new sBind(a, STICK_C_UP, BIND_AXIS, STICK_C_UP, -1.0f)); + AddBind(touchScreenKey, new sBind(a, STICK_C_DOWN, BIND_AXIS, STICK_C_DOWN, 1.0f)); + AddBind(touchScreenKey, new sBind(a, STICK_C_LEFT, BIND_AXIS, STICK_C_LEFT, -1.0f)); + AddBind(touchScreenKey, new sBind(a, STICK_C_RIGHT, BIND_AXIS, STICK_C_RIGHT, 1.0f)); + AddBind(touchScreenKey, new sBind(a, TRIGGER_L, BIND_AXIS, TRIGGER_L, 1.0f)); + AddBind(touchScreenKey, new sBind(a, TRIGGER_R, BIND_AXIS, TRIGGER_R, 1.0f)); } // Init our controller bindings IniFile ini; ini.Load(File::GetUserPath(D_CONFIG_IDX) + std::string("Dolphin.ini")); - for (int a = 0; a < configStringNum; ++a) + for (u32 a = 0; a < configStrings.size(); ++a) { for (int padID = 0; padID < 4; ++padID) { @@ -89,7 +108,7 @@ namespace ButtonManager int bindnum; char dev[128]; bool hasbind = false; - char modifier = 0; + char modifier = '+'; std::string value; ini.Get("Android", config.str(), &value, "None"); if (value == "None") @@ -107,14 +126,14 @@ namespace ButtonManager sscanf(value.c_str(), "Device '%[^\']'-Button %d", dev, &bindnum); } if (hasbind) - AddBind(std::string(dev), new sBind(padID, (ButtonType)a, type, bindnum, modifier == '-' ? -1.0f : 1.0f)); + AddBind(std::string(dev), new sBind(padID, configTypes[a], type, bindnum, modifier == '-' ? -1.0f : 1.0f)); } } } bool GetButtonPressed(int padID, ButtonType button) { - bool pressed = m_buttons[std::make_pair(padID, button)]->Pressed(); + bool pressed = m_controllers[touchScreenKey]->ButtonValue(padID, button); for (const auto& ctrl : m_controllers) pressed |= ctrl.second->ButtonValue(padID, button); @@ -123,19 +142,17 @@ namespace ButtonManager } float GetAxisValue(int padID, ButtonType axis) { - float value = m_axises[std::make_pair(padID, axis)]->AxisValue(); - auto it = m_controllers.begin(); - if (it == m_controllers.end()) - return value; - return value != 0.0f ? value : it->second->AxisValue(padID, axis); - } - void TouchEvent(int padID, ButtonType button, int action) - { - m_buttons[std::make_pair(padID, button)]->SetState(action ? BUTTON_PRESSED : BUTTON_RELEASED); - } - void TouchAxisEvent(int padID, ButtonType axis, float value) - { - m_axises[std::make_pair(padID, axis)]->SetValue(value); + float value = m_controllers[touchScreenKey]->AxisValue(padID, axis); + if (value == 0.0f) + { + for (const auto& ctrl : m_controllers) + { + value = ctrl.second->AxisValue(padID, axis); + if (value != 0.0f) + return value; + } + } + return value; } void GamepadEvent(std::string dev, int button, int action) { @@ -161,50 +178,58 @@ namespace ButtonManager } void Shutdown() { - for (const auto& button : m_buttons) - delete button.second; for (const auto& controller : m_controllers) delete controller.second; m_controllers.clear(); - m_buttons.clear(); } // InputDevice void InputDevice::PressEvent(int button, int action) { - if (_inputbinds.find(button) == _inputbinds.end()) - return; - _buttons[_inputbinds[button]->_buttontype] = action == 0 ? true : false; + for (const auto& binding : _inputbinds) + { + if (binding.second->_bind == button) + { + if (binding.second->_bindtype == BIND_BUTTON) + _buttons[binding.second->_buttontype] = action == BUTTON_PRESSED ? true : false; + else + _axises[binding.second->_buttontype] = action == BUTTON_PRESSED ? 1.0f : 0.0f; + } + } } void InputDevice::AxisEvent(int axis, float value) { - if (_inputbinds.find(axis) == _inputbinds.end()) - return; - _axises[_inputbinds[axis]->_buttontype] = value; + for (const auto& binding : _inputbinds) + { + if (binding.second->_bind == axis) + { + if (binding.second->_bindtype == BIND_AXIS) + _axises[binding.second->_buttontype] = value; + else + _buttons[binding.second->_buttontype] = value > 0.5f ? true : false; + } + } } bool InputDevice::ButtonValue(int padID, ButtonType button) { - auto it = _binds.find(button); - if (it == _binds.end()) - return false; - if (it->second->_padID != padID) + const auto& binding = _inputbinds.find(std::make_pair(padID, button)); + if (binding == _inputbinds.end()) return false; - if (it->second->_bindtype == BIND_BUTTON) - return _buttons[it->second->_buttontype]; + + if (binding->second->_bindtype == BIND_BUTTON) + return _buttons[binding->second->_buttontype]; else - return AxisValue(padID, button); + return (_axises[binding->second->_buttontype] * binding->second->_neg) > 0.5f; } float InputDevice::AxisValue(int padID, ButtonType axis) { - auto it = _binds.find(axis); - if (it == _binds.end()) + const auto& binding = _inputbinds.find(std::make_pair(padID, axis)); + if (binding == _inputbinds.end()) return 0.0f; - if (it->second->_padID != padID) - return 0.0f; - if (it->second->_bindtype == BIND_BUTTON) - return ButtonValue(padID, axis); + + if (binding->second->_bindtype == BIND_AXIS) + return _axises[binding->second->_buttontype] * binding->second->_neg; else - return _axises[it->second->_buttontype] * it->second->_neg; + return _buttons[binding->second->_buttontype] == BUTTON_PRESSED ? 1.0f : 0.0f; } - } -- cgit v1.2.3 From f05d3f6e5d6da8be530c0cd4ffaaec0382240ec5 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 16 Jun 2014 01:12:43 -0400 Subject: Use only section-based ini reading. --- Source/Core/DolphinWX/Android/ButtonManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/DolphinWX/Android/ButtonManager.cpp') diff --git a/Source/Core/DolphinWX/Android/ButtonManager.cpp b/Source/Core/DolphinWX/Android/ButtonManager.cpp index a1684ba5a6..5c2e5d1cc3 100644 --- a/Source/Core/DolphinWX/Android/ButtonManager.cpp +++ b/Source/Core/DolphinWX/Android/ButtonManager.cpp @@ -110,7 +110,7 @@ namespace ButtonManager bool hasbind = false; char modifier = '+'; std::string value; - ini.Get("Android", config.str(), &value, "None"); + ini.GetOrCreateSection("Android")->Get(config.str(), &value, "None"); if (value == "None") continue; if (std::string::npos != value.find("Axis")) -- cgit v1.2.3 From cd8b65bd8a73f1c8fd7c8ac1abeda1b5c1b5c50e Mon Sep 17 00:00:00 2001 From: Moshe Kaplan Date: Wed, 23 Jul 2014 10:03:49 -0400 Subject: Prevent potential buffer overflow in sscanf --- Source/Core/DolphinWX/Android/ButtonManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Source/Core/DolphinWX/Android/ButtonManager.cpp') diff --git a/Source/Core/DolphinWX/Android/ButtonManager.cpp b/Source/Core/DolphinWX/Android/ButtonManager.cpp index 5c2e5d1cc3..c6d70f3c5e 100644 --- a/Source/Core/DolphinWX/Android/ButtonManager.cpp +++ b/Source/Core/DolphinWX/Android/ButtonManager.cpp @@ -117,13 +117,13 @@ namespace ButtonManager { hasbind = true; type = BIND_AXIS; - sscanf(value.c_str(), "Device '%[^\']'-Axis %d%c", dev, &bindnum, &modifier); + sscanf(value.c_str(), "Device '%127[^\']'-Axis %d%c", dev, &bindnum, &modifier); } else if (std::string::npos != value.find("Button")) { hasbind = true; type = BIND_BUTTON; - sscanf(value.c_str(), "Device '%[^\']'-Button %d", dev, &bindnum); + sscanf(value.c_str(), "Device '%127[^\']'-Button %d", dev, &bindnum); } if (hasbind) AddBind(std::string(dev), new sBind(padID, configTypes[a], type, bindnum, modifier == '-' ? -1.0f : 1.0f)); -- cgit v1.2.3 From 2d974b60864e0917881d687e29a328c032888a03 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 9 Aug 2014 09:49:45 -0400 Subject: GLInterface: Destroy GLWin Everything is now safely tucked inside each individual GLInterface. --- Source/Core/DolphinWX/Android/ButtonManager.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Source/Core/DolphinWX/Android/ButtonManager.cpp') diff --git a/Source/Core/DolphinWX/Android/ButtonManager.cpp b/Source/Core/DolphinWX/Android/ButtonManager.cpp index c6d70f3c5e..8d6d241a36 100644 --- a/Source/Core/DolphinWX/Android/ButtonManager.cpp +++ b/Source/Core/DolphinWX/Android/ButtonManager.cpp @@ -4,8 +4,10 @@ #include +#include "Common/FileUtil.h" +#include "Common/IniFile.h" +#include "Common/Thread.h" #include "DolphinWX/Android/ButtonManager.h" -#include "DolphinWX/GLInterface/GLInterface.h" namespace ButtonManager { -- cgit v1.2.3 From 3168361e32ea051828d9025049b0358771e5ff8a Mon Sep 17 00:00:00 2001 From: Rohit Nirmal Date: Mon, 22 Sep 2014 17:45:42 -0400 Subject: Android: Silence some more warnings. --- Source/Core/DolphinWX/Android/ButtonManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/DolphinWX/Android/ButtonManager.cpp') diff --git a/Source/Core/DolphinWX/Android/ButtonManager.cpp b/Source/Core/DolphinWX/Android/ButtonManager.cpp index 8d6d241a36..7b1004415f 100644 --- a/Source/Core/DolphinWX/Android/ButtonManager.cpp +++ b/Source/Core/DolphinWX/Android/ButtonManager.cpp @@ -58,7 +58,7 @@ namespace ButtonManager TRIGGER_R }; - void AddBind(std::string dev, sBind *bind) + static void AddBind(std::string dev, sBind *bind) { auto it = m_controllers.find(dev); if (it != m_controllers.end()) -- cgit v1.2.3 From 29fc52cfa17dcc7327c1a081918721cd7cfcf40b Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Sun, 22 Feb 2015 20:36:30 -0600 Subject: [Android] Stop eating button events we don't handle. We were eating /all/ button events except the back button. This would cause issues where Android wouldn't receive button press events for things like volume rockers. So you couldn't change the audio ingame, even if that button isn't bound to an input. Now we return to Android if we've handled that button press, so it works fine. --- Source/Core/DolphinWX/Android/ButtonManager.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'Source/Core/DolphinWX/Android/ButtonManager.cpp') diff --git a/Source/Core/DolphinWX/Android/ButtonManager.cpp b/Source/Core/DolphinWX/Android/ButtonManager.cpp index 7b1004415f..53e64513ba 100644 --- a/Source/Core/DolphinWX/Android/ButtonManager.cpp +++ b/Source/Core/DolphinWX/Android/ButtonManager.cpp @@ -156,16 +156,14 @@ namespace ButtonManager } return value; } - void GamepadEvent(std::string dev, int button, int action) + bool GamepadEvent(std::string dev, int button, int action) { auto it = m_controllers.find(dev); if (it != m_controllers.end()) - { - it->second->PressEvent(button, action); - return; - } + return it->second->PressEvent(button, action); + m_controllers[dev] = new InputDevice(dev); - m_controllers[dev]->PressEvent(button, action); + return m_controllers[dev]->PressEvent(button, action); } void GamepadAxisEvent(std::string dev, int axis, float value) { @@ -186,8 +184,9 @@ namespace ButtonManager } // InputDevice - void InputDevice::PressEvent(int button, int action) + bool InputDevice::PressEvent(int button, int action) { + bool handled = false; for (const auto& binding : _inputbinds) { if (binding.second->_bind == button) @@ -196,8 +195,10 @@ namespace ButtonManager _buttons[binding.second->_buttontype] = action == BUTTON_PRESSED ? true : false; else _axises[binding.second->_buttontype] = action == BUTTON_PRESSED ? 1.0f : 0.0f; + handled = true; } } + return handled; } void InputDevice::AxisEvent(int axis, float value) { -- cgit v1.2.3 From 8a2f70b2efa141a75f76ac47e846eb12e5788f3c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 21 May 2015 22:22:52 -0400 Subject: ButtonManager: Pass strings by const reference --- Source/Core/DolphinWX/Android/ButtonManager.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Core/DolphinWX/Android/ButtonManager.cpp') diff --git a/Source/Core/DolphinWX/Android/ButtonManager.cpp b/Source/Core/DolphinWX/Android/ButtonManager.cpp index 53e64513ba..b96c263df6 100644 --- a/Source/Core/DolphinWX/Android/ButtonManager.cpp +++ b/Source/Core/DolphinWX/Android/ButtonManager.cpp @@ -58,7 +58,7 @@ namespace ButtonManager TRIGGER_R }; - static void AddBind(std::string dev, sBind *bind) + static void AddBind(const std::string& dev, sBind *bind) { auto it = m_controllers.find(dev); if (it != m_controllers.end()) @@ -156,7 +156,7 @@ namespace ButtonManager } return value; } - bool GamepadEvent(std::string dev, int button, int action) + bool GamepadEvent(const std::string& dev, int button, int action) { auto it = m_controllers.find(dev); if (it != m_controllers.end()) @@ -165,7 +165,7 @@ namespace ButtonManager m_controllers[dev] = new InputDevice(dev); return m_controllers[dev]->PressEvent(button, action); } - void GamepadAxisEvent(std::string dev, int axis, float value) + void GamepadAxisEvent(const std::string& dev, int axis, float value) { auto it = m_controllers.find(dev); if (it != m_controllers.end()) -- cgit v1.2.3 From cefcb0ace9d363b3679b4e93bcc9ec05f1e5f4f8 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Mon, 18 May 2015 01:08:10 +0200 Subject: Update license headers to GPLv2+ --- Source/Core/DolphinWX/Android/ButtonManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/DolphinWX/Android/ButtonManager.cpp') diff --git a/Source/Core/DolphinWX/Android/ButtonManager.cpp b/Source/Core/DolphinWX/Android/ButtonManager.cpp index b96c263df6..7c1dfa1a3f 100644 --- a/Source/Core/DolphinWX/Android/ButtonManager.cpp +++ b/Source/Core/DolphinWX/Android/ButtonManager.cpp @@ -1,5 +1,5 @@ // Copyright 2014 Dolphin Emulator Project -// Licensed under GPLv2 +// Licensed under GPLv2+ // Refer to the license.txt file included. #include -- cgit v1.2.3 From 30ebb2459eb97ba544547183854775df8460b475 Mon Sep 17 00:00:00 2001 From: Tillmann Karras Date: Sun, 24 May 2015 06:55:12 +0200 Subject: Set copyright year to when a file was created --- Source/Core/DolphinWX/Android/ButtonManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/Core/DolphinWX/Android/ButtonManager.cpp') diff --git a/Source/Core/DolphinWX/Android/ButtonManager.cpp b/Source/Core/DolphinWX/Android/ButtonManager.cpp index 7c1dfa1a3f..c48ecc11a1 100644 --- a/Source/Core/DolphinWX/Android/ButtonManager.cpp +++ b/Source/Core/DolphinWX/Android/ButtonManager.cpp @@ -1,4 +1,4 @@ -// Copyright 2014 Dolphin Emulator Project +// Copyright 2013 Dolphin Emulator Project // Licensed under GPLv2+ // Refer to the license.txt file included. -- cgit v1.2.3