mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-16 16:16:04 -04:00
[Custom controls] Re-calculate position after update button size
This commit is contained in:
parent
e91f847134
commit
487151c7fb
@ -76,7 +76,7 @@ public class ControlButton extends Button implements OnLongClickListener, OnTouc
|
|||||||
throw new IllegalArgumentException("Field " + ControlData.class.getName() + ".specialButtonListener must be View.OnClickListener or View.OnTouchListener, but is " + properties.specialButtonListener.getClass().getName());
|
throw new IllegalArgumentException("Field " + ControlData.class.getName() + ".specialButtonListener must be View.OnClickListener or View.OnTouchListener, but is " + properties.specialButtonListener.getClass().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
setLayoutParams(new FrameLayout.LayoutParams(properties.width, properties.height));
|
setLayoutParams(new FrameLayout.LayoutParams((int) properties.width, (int) properties.height));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -86,23 +86,32 @@ public class ControlButton extends Button implements OnLongClickListener, OnTouc
|
|||||||
mProperties.width = params.width;
|
mProperties.width = params.width;
|
||||||
mProperties.height = params.height;
|
mProperties.height = params.height;
|
||||||
|
|
||||||
|
// Re-calculate position
|
||||||
|
mProperties.update();
|
||||||
|
setTranslationX(mProperties.x);
|
||||||
|
setTranslationY(mProperties.y);
|
||||||
|
|
||||||
setModified(true);
|
setModified(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTranslationX(float x) {
|
public void setTranslationX(float x) {
|
||||||
super.setTranslationX(x);
|
super.setTranslationX(x);
|
||||||
mProperties.x = x;
|
|
||||||
|
|
||||||
setModified(true);
|
if (!mProperties.isDynamicBtn) {
|
||||||
|
mProperties.x = x;
|
||||||
|
setModified(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTranslationY(float y) {
|
public void setTranslationY(float y) {
|
||||||
super.setTranslationY(y);
|
super.setTranslationY(y);
|
||||||
mProperties.y = y;
|
|
||||||
|
|
||||||
setModified(true);
|
if (!mProperties.isDynamicBtn) {
|
||||||
|
mProperties.y = y;
|
||||||
|
setModified(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateProperties() {
|
public void updateProperties() {
|
||||||
|
@ -69,8 +69,8 @@ public class ControlData implements Cloneable
|
|||||||
public String name;
|
public String name;
|
||||||
public float x;
|
public float x;
|
||||||
public float y;
|
public float y;
|
||||||
public int width = pixelOf50dp;
|
public float width = pixelOf50dp;
|
||||||
public int height = pixelOf50dp;
|
public float height = pixelOf50dp;
|
||||||
public int keycode;
|
public int keycode;
|
||||||
public boolean hidden;
|
public boolean hidden;
|
||||||
public boolean holdCtrl;
|
public boolean holdCtrl;
|
||||||
@ -99,7 +99,7 @@ public class ControlData implements Cloneable
|
|||||||
this(name, keycode, x, y, isSquare ? pixelOf50dp : pixelOf80dp, isSquare ? pixelOf50dp : pixelOf30dp);
|
this(name, keycode, x, y, isSquare ? pixelOf50dp : pixelOf80dp, isSquare ? pixelOf50dp : pixelOf30dp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ControlData(String name, int keycode, float x, float y, int width, int height) {
|
public ControlData(String name, int keycode, float x, float y, float width, float height) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.keycode = keycode;
|
this.keycode = keycode;
|
||||||
this.x = x;
|
this.x = x;
|
||||||
@ -121,7 +121,7 @@ public class ControlData implements Cloneable
|
|||||||
this(name, keycode, dynamicX, dynamicY, isSquare ? pixelOf50dp : pixelOf80dp, isSquare ? pixelOf50dp : pixelOf30dp);
|
this(name, keycode, dynamicX, dynamicY, isSquare ? pixelOf50dp : pixelOf80dp, isSquare ? pixelOf50dp : pixelOf30dp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ControlData(String name, int keycode, String dynamicX, String dynamicY, int width, int height) {
|
public ControlData(String name, int keycode, String dynamicX, String dynamicY, float width, float height) {
|
||||||
this(name, keycode, 0, 0, width, height);
|
this(name, keycode, 0, 0, width, height);
|
||||||
this.dynamicX = dynamicX;
|
this.dynamicX = dynamicX;
|
||||||
this.dynamicY = dynamicY;
|
this.dynamicY = dynamicY;
|
||||||
@ -146,10 +146,10 @@ public class ControlData implements Cloneable
|
|||||||
Map<String, String> keyValueMap = new ArrayMap<>();
|
Map<String, String> keyValueMap = new ArrayMap<>();
|
||||||
keyValueMap.put("top", "0");
|
keyValueMap.put("top", "0");
|
||||||
keyValueMap.put("left", "0");
|
keyValueMap.put("left", "0");
|
||||||
keyValueMap.put("right", Integer.toString(CallbackBridge.windowWidth - width));
|
keyValueMap.put("right", Float.toString(CallbackBridge.windowWidth - width));
|
||||||
keyValueMap.put("bottom", Integer.toString(CallbackBridge.windowHeight - height));
|
keyValueMap.put("bottom", Float.toString(CallbackBridge.windowHeight - height));
|
||||||
keyValueMap.put("width", Integer.toString(width));
|
keyValueMap.put("width", Float.toString(width));
|
||||||
keyValueMap.put("height", Integer.toString(height));
|
keyValueMap.put("height", Float.toString(height));
|
||||||
keyValueMap.put("screen_width", Integer.toString(CallbackBridge.windowWidth));
|
keyValueMap.put("screen_width", Integer.toString(CallbackBridge.windowWidth));
|
||||||
keyValueMap.put("screen_height", Integer.toString(CallbackBridge.windowHeight));
|
keyValueMap.put("screen_height", Integer.toString(CallbackBridge.windowHeight));
|
||||||
keyValueMap.put("margin", Integer.toString(pixelOf2dp));
|
keyValueMap.put("margin", Integer.toString(pixelOf2dp));
|
||||||
|
@ -8,6 +8,7 @@ import net.kdt.pojavlaunch.*;
|
|||||||
import android.support.v7.app.*;
|
import android.support.v7.app.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import net.kdt.pojavlaunch.prefs.*;
|
||||||
|
|
||||||
public class ControlLayout extends FrameLayout
|
public class ControlLayout extends FrameLayout
|
||||||
{
|
{
|
||||||
@ -46,6 +47,8 @@ public class ControlLayout extends FrameLayout
|
|||||||
|
|
||||||
for (ControlData button : controlLayout.mControlDataList) {
|
for (ControlData button : controlLayout.mControlDataList) {
|
||||||
button.isHideable = button.keycode != ControlData.SPECIALBTN_TOGGLECTRL && button.keycode != ControlData.SPECIALBTN_VIRTUALMOUSE;
|
button.isHideable = button.keycode != ControlData.SPECIALBTN_TOGGLECTRL && button.keycode != ControlData.SPECIALBTN_VIRTUALMOUSE;
|
||||||
|
button.width = button.width / controlLayout.scaledAt * LauncherPreferences.PREF_BUTTONSIZE;
|
||||||
|
button.height = button.height / controlLayout.scaledAt * LauncherPreferences.PREF_BUTTONSIZE;
|
||||||
addControlView(button);
|
addControlView(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import org.lwjgl.glfw.*;
|
|||||||
|
|
||||||
public class CustomControls
|
public class CustomControls
|
||||||
{
|
{
|
||||||
|
public float scaledAt;
|
||||||
public List<ControlData> mControlDataList;
|
public List<ControlData> mControlDataList;
|
||||||
public CustomControls() {
|
public CustomControls() {
|
||||||
this(new ArrayList<ControlData>());
|
this(new ArrayList<ControlData>());
|
||||||
@ -14,6 +15,7 @@ public class CustomControls
|
|||||||
|
|
||||||
public CustomControls(List<ControlData> mControlDataList) {
|
public CustomControls(List<ControlData> mControlDataList) {
|
||||||
this.mControlDataList = mControlDataList;
|
this.mControlDataList = mControlDataList;
|
||||||
|
this.scaledAt = 1f;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate default control
|
// Generate default control
|
||||||
|
Loading…
x
Reference in New Issue
Block a user