android: fix scaling when editing vgamepad. vgamepad code clean up
This commit is contained in:
parent
21f9e9fbc2
commit
92c5892d4c
|
@ -37,6 +37,8 @@
|
|||
|
||||
namespace vgamepad
|
||||
{
|
||||
static void stopEditing(bool canceled);
|
||||
static void loadLayout();
|
||||
|
||||
struct Control
|
||||
{
|
||||
|
@ -576,7 +578,7 @@ void applyUiScale() {
|
|||
element.applyUiScale();
|
||||
}
|
||||
|
||||
void loadLayout()
|
||||
static void loadLayout()
|
||||
{
|
||||
for (auto& element : Layout) {
|
||||
element.reset();
|
||||
|
@ -585,7 +587,7 @@ void loadLayout()
|
|||
applyLayout();
|
||||
}
|
||||
|
||||
void saveLayout()
|
||||
static void saveLayout()
|
||||
{
|
||||
cfgSetAutoSave(false);
|
||||
for (auto& element : Layout)
|
||||
|
@ -637,7 +639,7 @@ void loadImage(const std::string& path)
|
|||
}
|
||||
}
|
||||
|
||||
void enableAllControls()
|
||||
static void enableAllControls()
|
||||
{
|
||||
for (auto& control : Controls)
|
||||
control.disabled = false;
|
||||
|
@ -881,25 +883,26 @@ void resetEditing() {
|
|||
resetLayout();
|
||||
}
|
||||
|
||||
#ifndef __ANDROID__
|
||||
|
||||
void startEditing() {
|
||||
void startEditing()
|
||||
{
|
||||
enableAllControls();
|
||||
show();
|
||||
setEditMode(true);
|
||||
}
|
||||
|
||||
void pauseEditing() {
|
||||
setEditMode(false);
|
||||
}
|
||||
|
||||
void stopEditing(bool canceled)
|
||||
static void stopEditing(bool canceled)
|
||||
{
|
||||
setEditMode(false);
|
||||
if (canceled)
|
||||
loadLayout();
|
||||
else
|
||||
saveLayout();
|
||||
}
|
||||
|
||||
#endif
|
||||
} // namespace vgamepad
|
||||
|
||||
#endif // __ANDROID__ || TARGET_IPHONE
|
||||
|
|
|
@ -78,13 +78,12 @@ public:
|
|||
|
||||
#if defined(__ANDROID__) || defined(TARGET_IPHONE)
|
||||
|
||||
void enableAllControls();
|
||||
void show();
|
||||
void hide();
|
||||
void draw();
|
||||
void startEditing();
|
||||
void pauseEditing();
|
||||
void stopEditing(bool canceled);
|
||||
void setEditMode(bool editing);
|
||||
void resetEditing();
|
||||
void displayCommands();
|
||||
void loadImage(const std::string& path);
|
||||
|
@ -100,8 +99,6 @@ void applyUiScale();
|
|||
Element layoutHitTest(float x, float y);
|
||||
void translateElement(Element element, float dx, float dy);
|
||||
void scaleElement(Element element, float factor);
|
||||
void loadLayout();
|
||||
void saveLayout();
|
||||
|
||||
#else
|
||||
|
||||
|
|
|
@ -71,20 +71,11 @@ public final class NativeGLActivity extends BaseGLActivity {
|
|||
}
|
||||
|
||||
// Called from native code
|
||||
private void VJoyStartEditing() {
|
||||
public void setVGamepadEditMode(boolean editing) {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mView.setEditVjoyMode(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
// Called from native code
|
||||
private void VJoyStopEditing() {
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mView.setEditVjoyMode(false);
|
||||
mView.setVGamepadEditMode(editing);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -48,8 +48,10 @@ public class EditVirtualJoystickDelegate implements TouchEventHandler
|
|||
public boolean onTouchEvent(MotionEvent event, int width, int height)
|
||||
{
|
||||
scaleGestureDetector.onTouchEvent(event);
|
||||
if (scaleGestureDetector.isInProgress())
|
||||
if (scaleGestureDetector.isInProgress()) {
|
||||
currentElement = -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
int actionMasked = event.getActionMasked();
|
||||
int actionIndex = event.getActionIndex();
|
||||
|
@ -64,7 +66,7 @@ public class EditVirtualJoystickDelegate implements TouchEventHandler
|
|||
lastX = event.getX(actionIndex) / view.getWidth();
|
||||
lastY = event.getY(actionIndex) / view.getHeight();
|
||||
currentElement = VGamepad.layoutHitTest(lastX, lastY);
|
||||
return currentElement != -1;
|
||||
return true; // must return true if we want the scale gesture detector to work
|
||||
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (currentElement != -1 && event.getPointerCount() == 1)
|
||||
|
|
|
@ -173,13 +173,13 @@ public class NativeGLView extends SurfaceView implements SurfaceHolder.Callback
|
|||
}
|
||||
}
|
||||
|
||||
public void setEditVjoyMode(boolean editVjoyMode)
|
||||
public void setVGamepadEditMode(boolean editing)
|
||||
{
|
||||
if (!InputDeviceManager.getInstance().hasTouchscreen())
|
||||
return;
|
||||
if (editVjoyMode && !(vjoyDelegate instanceof EditVirtualJoystickDelegate))
|
||||
if (editing && !(vjoyDelegate instanceof EditVirtualJoystickDelegate))
|
||||
vjoyDelegate = new EditVirtualJoystickDelegate(this);
|
||||
else if (!editVjoyMode && !(vjoyDelegate instanceof VirtualJoystickDelegate))
|
||||
else if (!editing && !(vjoyDelegate instanceof VirtualJoystickDelegate))
|
||||
vjoyDelegate = new VirtualJoystickDelegate(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -52,10 +52,9 @@ static ANativeWindow *g_window = 0;
|
|||
|
||||
// Activity
|
||||
jobject g_activity;
|
||||
extern jmethodID VJoyStartEditingMID;
|
||||
extern jmethodID VJoyStopEditingMID;
|
||||
extern jmethodID showScreenKeyboardMid;
|
||||
static jmethodID onGameStateChangeMid;
|
||||
extern jmethodID setVGamepadEditModeMid;
|
||||
|
||||
static void emuEventCallback(Event event, void *)
|
||||
{
|
||||
|
@ -453,10 +452,9 @@ extern "C" JNIEXPORT void JNICALL Java_com_flycast_emulator_BaseGLActivity_regis
|
|||
{
|
||||
g_activity = env->NewGlobalRef(activity);
|
||||
jclass actClass = env->GetObjectClass(activity);
|
||||
VJoyStartEditingMID = env->GetMethodID(actClass, "VJoyStartEditing", "()V");
|
||||
VJoyStopEditingMID = env->GetMethodID(actClass, "VJoyStopEditing", "()V");
|
||||
showScreenKeyboardMid = env->GetMethodID(actClass, "showScreenKeyboard", "(Z)V");
|
||||
onGameStateChangeMid = env->GetMethodID(actClass, "onGameStateChange", "(Z)V");
|
||||
setVGamepadEditModeMid = env->GetMethodID(actClass, "setVGamepadEditMode", "(Z)V");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,10 +27,8 @@ std::shared_ptr<AndroidKeyboard> keyboard;
|
|||
std::shared_ptr<AndroidVirtualGamepad> virtualGamepad;
|
||||
|
||||
extern jobject g_activity;
|
||||
jmethodID VJoyStartEditingMID;
|
||||
jmethodID VJoyStopEditingMID;
|
||||
jmethodID VJoyEnableControlsMID;
|
||||
jmethodID showScreenKeyboardMid;
|
||||
jmethodID setVGamepadEditModeMid;
|
||||
|
||||
//
|
||||
// VGamepad
|
||||
|
@ -75,25 +73,8 @@ extern "C" JNIEXPORT void JNICALL Java_com_flycast_emulator_emu_VGamepad_transla
|
|||
namespace vgamepad
|
||||
{
|
||||
|
||||
void startEditing()
|
||||
{
|
||||
// FIXME code dup with vgamepad.cpp
|
||||
enableAllControls();
|
||||
show();
|
||||
jni::env()->CallVoidMethod(g_activity, VJoyStartEditingMID);
|
||||
}
|
||||
void pauseEditing() {
|
||||
// needed? could be used by iOS to avoid relying on gui state
|
||||
jni::env()->CallVoidMethod(g_activity, VJoyStopEditingMID);
|
||||
}
|
||||
void stopEditing(bool canceled)
|
||||
{
|
||||
// FIXME code dup with vgamepad.cpp
|
||||
jni::env()->CallVoidMethod(g_activity, VJoyStopEditingMID);
|
||||
if (canceled)
|
||||
loadLayout();
|
||||
else
|
||||
saveLayout();
|
||||
void setEditMode(bool editing) {
|
||||
jni::env()->CallVoidMethod(g_activity, setVGamepadEditModeMid, editing);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -44,7 +44,6 @@
|
|||
#include "ios_mouse.h"
|
||||
#include "oslib/oslib.h"
|
||||
|
||||
//@import AltKit;
|
||||
#import "AltKit-Swift.h"
|
||||
|
||||
static std::string iosJitStatus;
|
||||
|
@ -691,13 +690,6 @@ bool checkTryDebug()
|
|||
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
|
||||
{
|
||||
#if !TARGET_OS_TV
|
||||
if ((gui_state == GuiState::VJoyEdit) != [self.editPadController isControllerVisible])
|
||||
{
|
||||
if (gui_state == GuiState::VJoyEdit)
|
||||
[self.editPadController showController:self.view];
|
||||
else
|
||||
[self.editPadController hideController];
|
||||
}
|
||||
if (emu.running() != [self.padController isControllerVisible] && !IOSGamepad::controllerConnected())
|
||||
{
|
||||
if (emu.running())
|
||||
|
@ -708,6 +700,20 @@ bool checkTryDebug()
|
|||
#endif
|
||||
mainui_rend_frame();
|
||||
}
|
||||
|
||||
- (void)setVGamepadEditMode:(BOOL)editing
|
||||
{
|
||||
#if !TARGET_OS_TV
|
||||
if (editing != [self.editPadController isControllerVisible])
|
||||
{
|
||||
if (editing)
|
||||
[self.editPadController showController:self.view];
|
||||
else
|
||||
[self.editPadController hideController];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
- (void)pickIosFile
|
||||
{
|
||||
|
@ -762,3 +768,12 @@ const char *getIosJitStatus()
|
|||
}
|
||||
return iosJitStatus.c_str();
|
||||
}
|
||||
|
||||
namespace vgamepad
|
||||
{
|
||||
|
||||
void setEditMode(bool editing) {
|
||||
[flycastViewController setVGamepadEditMode:editing];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue