Android: Convert ControlGroup to Kotlin
This commit is contained in:
parent
fafbb2199e
commit
7c79ff0100
|
@ -1,66 +0,0 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
|
|
||||||
package org.dolphinemu.dolphinemu.features.input.model.controlleremu;
|
|
||||||
|
|
||||||
import androidx.annotation.Keep;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a C++ ControllerEmu::ControlGroup.
|
|
||||||
*
|
|
||||||
* The lifetime of this class is managed by C++ code. Calling methods on it after it's destroyed
|
|
||||||
* in C++ is undefined behavior!
|
|
||||||
*/
|
|
||||||
public class ControlGroup
|
|
||||||
{
|
|
||||||
public static final int TYPE_OTHER = 0;
|
|
||||||
public static final int TYPE_STICK = 1;
|
|
||||||
public static final int TYPE_MIXED_TRIGGERS = 2;
|
|
||||||
public static final int TYPE_BUTTONS = 3;
|
|
||||||
public static final int TYPE_FORCE = 4;
|
|
||||||
public static final int TYPE_ATTACHMENTS = 5;
|
|
||||||
public static final int TYPE_TILT = 6;
|
|
||||||
public static final int TYPE_CURSOR = 7;
|
|
||||||
public static final int TYPE_TRIGGERS = 8;
|
|
||||||
public static final int TYPE_SLIDER = 9;
|
|
||||||
public static final int TYPE_SHAKE = 10;
|
|
||||||
public static final int TYPE_IMU_ACCELEROMETER = 11;
|
|
||||||
public static final int TYPE_IMU_GYROSCOPE = 12;
|
|
||||||
public static final int TYPE_IMU_CURSOR = 13;
|
|
||||||
|
|
||||||
public static final int DEFAULT_ENABLED_ALWAYS = 0;
|
|
||||||
public static final int DEFAULT_ENABLED_YES = 1;
|
|
||||||
public static final int DEFAULT_ENABLED_NO = 2;
|
|
||||||
|
|
||||||
@Keep
|
|
||||||
private final long mPointer;
|
|
||||||
|
|
||||||
@Keep
|
|
||||||
private ControlGroup(long pointer)
|
|
||||||
{
|
|
||||||
mPointer = pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public native String getUiName();
|
|
||||||
|
|
||||||
public native int getGroupType();
|
|
||||||
|
|
||||||
public native int getDefaultEnabledValue();
|
|
||||||
|
|
||||||
public native boolean getEnabled();
|
|
||||||
|
|
||||||
public native void setEnabled(boolean value);
|
|
||||||
|
|
||||||
public native int getControlCount();
|
|
||||||
|
|
||||||
public native Control getControl(int i);
|
|
||||||
|
|
||||||
public native int getNumericSettingCount();
|
|
||||||
|
|
||||||
public native NumericSetting getNumericSetting(int i);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If getGroupType returns TYPE_ATTACHMENTS, this returns the attachment selection setting.
|
|
||||||
* Otherwise, undefined behavior!
|
|
||||||
*/
|
|
||||||
public native NumericSetting getAttachmentSetting();
|
|
||||||
}
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
package org.dolphinemu.dolphinemu.features.input.model.controlleremu
|
||||||
|
|
||||||
|
import androidx.annotation.Keep
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a C++ ControllerEmu::ControlGroup.
|
||||||
|
*
|
||||||
|
* The lifetime of this class is managed by C++ code. Calling methods on it after it's destroyed
|
||||||
|
* in C++ is undefined behavior!
|
||||||
|
*/
|
||||||
|
@Keep
|
||||||
|
class ControlGroup private constructor(private val pointer: Long) {
|
||||||
|
external fun getUiName(): String
|
||||||
|
|
||||||
|
external fun getGroupType(): Int
|
||||||
|
|
||||||
|
external fun getDefaultEnabledValue(): Int
|
||||||
|
|
||||||
|
external fun getEnabled(): Boolean
|
||||||
|
|
||||||
|
external fun setEnabled(value: Boolean)
|
||||||
|
|
||||||
|
external fun getControlCount(): Int
|
||||||
|
|
||||||
|
external fun getControl(i: Int): Control
|
||||||
|
|
||||||
|
external fun getNumericSettingCount(): Int
|
||||||
|
|
||||||
|
external fun getNumericSetting(i: Int): NumericSetting
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If getGroupType returns TYPE_ATTACHMENTS, this returns the attachment selection setting.
|
||||||
|
* Otherwise, undefined behavior!
|
||||||
|
*/
|
||||||
|
external fun getAttachmentSetting(): NumericSetting
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val TYPE_OTHER = 0
|
||||||
|
const val TYPE_STICK = 1
|
||||||
|
const val TYPE_MIXED_TRIGGERS = 2
|
||||||
|
const val TYPE_BUTTONS = 3
|
||||||
|
const val TYPE_FORCE = 4
|
||||||
|
const val TYPE_ATTACHMENTS = 5
|
||||||
|
const val TYPE_TILT = 6
|
||||||
|
const val TYPE_CURSOR = 7
|
||||||
|
const val TYPE_TRIGGERS = 8
|
||||||
|
const val TYPE_SLIDER = 9
|
||||||
|
const val TYPE_SHAKE = 10
|
||||||
|
const val TYPE_IMU_ACCELEROMETER = 11
|
||||||
|
const val TYPE_IMU_GYROSCOPE = 12
|
||||||
|
const val TYPE_IMU_CURSOR = 13
|
||||||
|
|
||||||
|
const val DEFAULT_ENABLED_ALWAYS = 0
|
||||||
|
const val DEFAULT_ENABLED_YES = 1
|
||||||
|
const val DEFAULT_ENABLED_NO = 2
|
||||||
|
}
|
||||||
|
}
|
|
@ -2254,12 +2254,12 @@ class SettingsFragmentPresenter(
|
||||||
val groupCount = controller.groupCount
|
val groupCount = controller.groupCount
|
||||||
for (i in 0 until groupCount) {
|
for (i in 0 until groupCount) {
|
||||||
val group = controller.getGroup(i)
|
val group = controller.getGroup(i)
|
||||||
val groupType = group.groupType
|
val groupType = group.getGroupType()
|
||||||
if (groupTypeFilter != null && !groupTypeFilter.contains(groupType)) continue
|
if (groupTypeFilter != null && !groupTypeFilter.contains(groupType)) continue
|
||||||
|
|
||||||
sl.add(HeaderSetting(group.uiName, ""))
|
sl.add(HeaderSetting(group.getUiName(), ""))
|
||||||
|
|
||||||
if (group.defaultEnabledValue != ControlGroup.DEFAULT_ENABLED_ALWAYS) {
|
if (group.getDefaultEnabledValue() != ControlGroup.DEFAULT_ENABLED_ALWAYS) {
|
||||||
sl.add(
|
sl.add(
|
||||||
SwitchSetting(
|
SwitchSetting(
|
||||||
context,
|
context,
|
||||||
|
@ -2270,13 +2270,13 @@ class SettingsFragmentPresenter(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val controlCount = group.controlCount
|
val controlCount = group.getControlCount()
|
||||||
for (j in 0 until controlCount) {
|
for (j in 0 until controlCount) {
|
||||||
sl.add(InputMappingControlSetting(group.getControl(j), controller))
|
sl.add(InputMappingControlSetting(group.getControl(j), controller))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (groupType == ControlGroup.TYPE_ATTACHMENTS) {
|
if (groupType == ControlGroup.TYPE_ATTACHMENTS) {
|
||||||
val attachmentSetting = group.attachmentSetting
|
val attachmentSetting = group.getAttachmentSetting()
|
||||||
sl.add(
|
sl.add(
|
||||||
SingleChoiceSetting(
|
SingleChoiceSetting(
|
||||||
context, InputMappingIntSetting(attachmentSetting),
|
context, InputMappingIntSetting(attachmentSetting),
|
||||||
|
@ -2287,7 +2287,7 @@ class SettingsFragmentPresenter(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val numericSettingCount = group.numericSettingCount
|
val numericSettingCount = group.getNumericSettingCount()
|
||||||
for (j in 0 until numericSettingCount) {
|
for (j in 0 until numericSettingCount) {
|
||||||
addNumericSetting(sl, group.getNumericSetting(j))
|
addNumericSetting(sl, group.getNumericSetting(j))
|
||||||
}
|
}
|
||||||
|
|
|
@ -710,7 +710,7 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved)
|
||||||
const jclass control_group_class =
|
const jclass control_group_class =
|
||||||
env->FindClass("org/dolphinemu/dolphinemu/features/input/model/controlleremu/ControlGroup");
|
env->FindClass("org/dolphinemu/dolphinemu/features/input/model/controlleremu/ControlGroup");
|
||||||
s_control_group_class = reinterpret_cast<jclass>(env->NewGlobalRef(control_group_class));
|
s_control_group_class = reinterpret_cast<jclass>(env->NewGlobalRef(control_group_class));
|
||||||
s_control_group_pointer = env->GetFieldID(control_group_class, "mPointer", "J");
|
s_control_group_pointer = env->GetFieldID(control_group_class, "pointer", "J");
|
||||||
s_control_group_constructor = env->GetMethodID(control_group_class, "<init>", "(J)V");
|
s_control_group_constructor = env->GetMethodID(control_group_class, "<init>", "(J)V");
|
||||||
env->DeleteLocalRef(control_group_class);
|
env->DeleteLocalRef(control_group_class);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue