mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-24 06:39:46 -06:00
[Android-overlay] Support touch screen axises in native. Have a non-configurable main joystick on screen at this point.
This commit is contained in:
@ -25,6 +25,7 @@ extern void DrawButton(GLuint tex, float *coords);
|
||||
namespace ButtonManager
|
||||
{
|
||||
std::unordered_map<int, Button*> m_buttons;
|
||||
std::unordered_map<int, Axis*> m_axises;
|
||||
std::unordered_map<std::string, InputDevice*> m_controllers;
|
||||
const char *configStrings[] = { "InputA",
|
||||
"InputB",
|
||||
@ -74,6 +75,16 @@ namespace ButtonManager
|
||||
m_buttons[BUTTON_LEFT] = new Button();
|
||||
m_buttons[BUTTON_RIGHT] = new Button();
|
||||
|
||||
m_axises[STICK_MAIN_UP] = new Axis();
|
||||
m_axises[STICK_MAIN_DOWN] = new Axis();
|
||||
m_axises[STICK_MAIN_LEFT] = new Axis();
|
||||
m_axises[STICK_MAIN_RIGHT] = new Axis();
|
||||
m_axises[STICK_C_UP] = new Axis();
|
||||
m_axises[STICK_C_DOWN] = new Axis();
|
||||
m_axises[STICK_C_LEFT] = new Axis();
|
||||
m_axises[STICK_C_RIGHT] = new Axis();
|
||||
m_axises[TRIGGER_L] = new Axis();
|
||||
m_axises[TRIGGER_R] = new Axis();
|
||||
|
||||
// Init our controller bindings
|
||||
IniFile ini;
|
||||
@ -118,16 +129,22 @@ namespace ButtonManager
|
||||
}
|
||||
float GetAxisValue(ButtonType axis)
|
||||
{
|
||||
float value = 0.0f;
|
||||
value = m_axises[axis]->AxisValue();
|
||||
|
||||
auto it = m_controllers.begin();
|
||||
if (it == m_controllers.end())
|
||||
return 0.0f;
|
||||
return value;
|
||||
return it->second->AxisValue(axis);
|
||||
}
|
||||
void TouchEvent(int button, int action)
|
||||
{
|
||||
m_buttons[button]->SetState(action ? BUTTON_PRESSED : BUTTON_RELEASED);
|
||||
}
|
||||
|
||||
void TouchAxisEvent(int axis, float value)
|
||||
{
|
||||
m_axises[axis]->SetValue(value);
|
||||
}
|
||||
void GamepadEvent(std::string dev, int button, int action)
|
||||
{
|
||||
auto it = m_controllers.find(dev);
|
||||
@ -160,11 +177,6 @@ namespace ButtonManager
|
||||
m_buttons.clear();
|
||||
}
|
||||
|
||||
void DrawButtons()
|
||||
{
|
||||
// XXX: Make platform specific drawing
|
||||
}
|
||||
|
||||
// InputDevice
|
||||
void InputDevice::PressEvent(int button, int action)
|
||||
{
|
||||
|
@ -67,7 +67,18 @@ namespace ButtonManager
|
||||
void SetState(ButtonState state) { m_state = state; }
|
||||
bool Pressed() { return m_state == BUTTON_PRESSED; }
|
||||
|
||||
~Button() { }
|
||||
~Button() {}
|
||||
};
|
||||
class Axis
|
||||
{
|
||||
private:
|
||||
float m_value;
|
||||
public:
|
||||
Axis() : m_value(0.0f) {}
|
||||
void SetValue(float value) { m_value = value; }
|
||||
float AxisValue() { return m_value; }
|
||||
|
||||
~Axis() {}
|
||||
};
|
||||
|
||||
struct sBind
|
||||
@ -107,10 +118,10 @@ namespace ButtonManager
|
||||
};
|
||||
|
||||
void Init();
|
||||
void DrawButtons();
|
||||
bool GetButtonPressed(ButtonType button);
|
||||
float GetAxisValue(ButtonType axis);
|
||||
void TouchEvent(int button, int action);
|
||||
void TouchAxisEvent(int axis, float value);
|
||||
void GamepadEvent(std::string dev, int button, int action);
|
||||
void GamepadAxisEvent(std::string dev, int axis, float value);
|
||||
void Shutdown();
|
||||
|
@ -241,6 +241,10 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onTouchEvent
|
||||
{
|
||||
ButtonManager::TouchEvent(Button, Action);
|
||||
}
|
||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onTouchAxisEvent(JNIEnv *env, jobject obj, jint Button, jfloat Action)
|
||||
{
|
||||
ButtonManager::TouchAxisEvent(Button, Action);
|
||||
}
|
||||
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadEvent(JNIEnv *env, jobject obj, jstring jDevice, jint Button, jint Action)
|
||||
{
|
||||
const char *Device = env->GetStringUTFChars(jDevice, NULL);
|
||||
@ -375,15 +379,6 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv *
|
||||
VideoBackend::ActivateBackend(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend);
|
||||
WiimoteReal::LoadSettings();
|
||||
|
||||
// Load our Android specific settings
|
||||
IniFile ini;
|
||||
bool onscreencontrols = true;
|
||||
ini.Load(File::GetUserPath(D_CONFIG_IDX) + std::string("Dolphin.ini"));
|
||||
ini.Get("Android", "ScreenControls", &onscreencontrols, true);
|
||||
|
||||
if (onscreencontrols)
|
||||
OSD::AddCallback(OSD::OSD_ONFRAME, ButtonManager::DrawButtons);
|
||||
|
||||
// No use running the loop when booting fails
|
||||
if ( BootManager::BootCore( g_filename.c_str() ) )
|
||||
while (PowerPC::GetState() != PowerPC::CPU_POWERDOWN)
|
||||
|
Reference in New Issue
Block a user