Layout converter v1 -> unfinished v2

"i want new keyboard for pojavluancher" x20 by @𝙵𝚊𝚔ȇ̈_A𝕣ᴄᴀᴅᴇ#7200
This commit is contained in:
Duy Tran Khanh committed 2021-08-07 10:17:52 +07:00
1 parent e079e86a80
commit 66bee901db
5 files changed
+111 -53

No files matched your search

@@ -483,7 +483,7 @@ public class GLFW
/* volatile */ public static GLFWWindowPosCallback mGLFWWindowPosCallback;
/* volatile */ public static GLFWWindowRefreshCallback mGLFWWindowRefreshCallback;
/* volatile */ public static GLFWWindowSizeCallback mGLFWWindowSizeCallback;
volatile public static int mGLFWWindowWidth, mGLFWWindowHeight;
volatile public static double mGLFWCursorX, mGLFWCursorY, mGLFWCursorLastX, mGLFWCursorLastY;
@@ -497,7 +497,7 @@ public class GLFW
private static ArrayMap<Long, GLFWWindowProperties> mGLFWWindowMap;
public static boolean mGLFWIsGrabbing, mGLFWIsInputReady, mGLFWIsUseStackQueue = false;
public static final byte[] keyDownBuffer = new byte[316];
public static final byte[] keyDownBuffer = new byte[317];
public static long mainContext = 0;
static {
try {
@@ -1091,7 +1091,7 @@ public class GLFW
break;
case CallbackBridge.EVENT_TYPE_KEY:
if (mGLFWKeyCallback != null) {
keyDownBuffer[dataArr[1]-32]=(byte)(int)dataArr[3];
keyDownBuffer[Math.max(0, dataArr[1]-31)]=(byte)(int)dataArr[3];
mGLFWKeyCallback.invoke(ptr, dataArr[1], dataArr[2], dataArr[3], dataArr[4]);
}
break;
@@ -1178,7 +1178,7 @@ public class GLFW
}
public static int glfwGetKey(@NativeType("GLFWwindow *") long window, int key) {
return keyDownBuffer[key-32];
return keyDownBuffer[Math.max(0, key-31)];
}
public static int glfwGetMouseButton(@NativeType("GLFWwindow *") long window, int button) {
+3
View File
@@ -2,6 +2,8 @@
#import "LauncherPreferences.h"
#import "ios_uikit_bridge.h"
#import "customcontrols/CustomControlsUtils.h"
#include "glfw_keycodes.h"
#include "utils.h"
@@ -79,6 +81,7 @@ int width;
if (cc_error != nil) {
showDialog(self, @"Error parsing JSON", cc_error.localizedDescription);
} else {
convertV1ToV2(self.cc_dictionary);
NSMutableArray *cc_controlDataList = self.cc_dictionary[@"mControlDataList"];
CGFloat currentScale = ((NSNumber *)self.cc_dictionary[@"scaledAt"]).floatValue;
CGFloat savedScale = ((NSNumber *)getPreference(@"button_scale")).floatValue;
+49 -45
View File
@@ -4,6 +4,7 @@
#import "ios_uikit_bridge.h"
#import "customcontrols/ControlButton.h"
#import "customcontrols/CustomControlsUtils.h"
#include "glfw_keycodes.h"
#include "utils.h"
@@ -156,17 +157,13 @@ int notchOffset;
if (cc_error != nil) {
showDialog(self, @"Error parsing JSON", cc_error.localizedDescription);
} else {
convertV1ToV2(self.cc_dictionary);
NSMutableArray *cc_controlDataList = self.cc_dictionary[@"mControlDataList"];
CGFloat currentScale = ((NSNumber *)self.cc_dictionary[@"scaledAt"]).floatValue;
CGFloat savedScale = ((NSNumber *)getPreference(@"button_scale")).floatValue;
int cc_version = ((NSNumber *)self.cc_dictionary[@"version"]).intValue;
for (int i = 0; i < (int) cc_controlDataList.count; i++) {
NSMutableDictionary *cc_buttonDict = cc_controlDataList[i];
if (cc_version < 2) {
showDialog(self, @"Notice", @"Custom controls v1 to v2 was not implemented!");
return;
//convertV1ToV2(cc_buttonDict);
}
APPLY_SCALE(cc_buttonDict[@"width"]);
APPLY_SCALE(cc_buttonDict[@"height"]);
APPLY_SCALE(cc_buttonDict[@"strokeWidth"]);
@@ -176,12 +173,14 @@ int notchOffset;
[button addTarget:self action:@selector(executebtn_up:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside];
[self.view addSubview:button];
int firstKeycode = ((NSNumber *)cc_buttonDict[@"keycodes"][0]).intValue;
if (firstKeycode == SPECIALBTN_KEYBOARD) {
inputView.frame = button.frame;
}
if (firstKeycode != SPECIALBTN_TOGGLECTRL) {
togglableVisibleButtons[++togglableVisibleButtonIndex] = button;
for (int i = 0; i < 4; i++) {
int keycodeInt = ((NSNumber *)cc_buttonDict[@"keycodes"][i]).intValue;
if (keycodeInt == SPECIALBTN_KEYBOARD) {
inputView.frame = button.frame;
}
if (keycodeInt != SPECIALBTN_TOGGLECTRL) {
togglableVisibleButtons[++togglableVisibleButtonIndex] = button;
}
}
}
self.cc_dictionary[@"scaledAt"] = @(savedScale);
@@ -478,8 +477,7 @@ NSString* inputStringBefore;
NSString *newText = [inputView.text substringFromIndex:INPUT_SPACE_LENGTH];
int charLength = (int) [newText length];
for (int i = 0; i < charLength; i++) {
// LWJGL2: convert to UTF-8
// LWJGL3: Directly convert unichar to jchar since both are in UTF-16 encoding.
// Directly convert unichar to jchar since both are in UTF-16 encoding.
/*
jchar theChar = (jchar)
@@ -568,45 +566,51 @@ int currentVisibility = 1;
ControlButton *button = (ControlButton *)sender;
int held = action == ACTION_DOWN;
// TODO v2: mulitple keys support
int keycode = ((NSNumber *)button.properties[@"keycodes"][0]).intValue;
if (keycode < 0) {
switch (keycode) {
case SPECIALBTN_KEYBOARD:
if (held == 0) {
[inputView resignFirstResponder];
inputView.alpha = 1.0f;
inputView.text = @"";
}
break;
for (int i = 0; i < 4; i++) {
int keycode = ((NSNumber *)cc_buttonDict[@"keycodes"][i]).intValue;
if (keycode < 0) {
switch (keycode) {
case SPECIALBTN_KEYBOARD:
if (held == 0) {
[inputView resignFirstResponder];
inputView.alpha = 1.0f;
inputView.text = @"";
}
break;
case SPECIALBTN_MOUSEPRI:
Java_org_lwjgl_glfw_CallbackBridge_nativeSendMouseButton(NULL, NULL, GLFW_MOUSE_BUTTON_LEFT, held, 0);
break;
case SPECIALBTN_MOUSEPRI:
Java_org_lwjgl_glfw_CallbackBridge_nativeSendMouseButton(NULL, NULL, GLFW_MOUSE_BUTTON_LEFT, held, 0);
break;
case SPECIALBTN_MOUSESEC:
Java_org_lwjgl_glfw_CallbackBridge_nativeSendMouseButton(NULL, NULL, GLFW_MOUSE_BUTTON_RIGHT, held, 0);
break;
case SPECIALBTN_MOUSESEC:
Java_org_lwjgl_glfw_CallbackBridge_nativeSendMouseButton(NULL, NULL, GLFW_MOUSE_BUTTON_RIGHT, held, 0);
break;
case SPECIALBTN_MOUSEMID:
Java_org_lwjgl_glfw_CallbackBridge_nativeSendMouseButton(NULL, NULL, GLFW_MOUSE_BUTTON_MIDDLE, held, 0);
break;
case SPECIALBTN_MOUSEMID:
Java_org_lwjgl_glfw_CallbackBridge_nativeSendMouseButton(NULL, NULL, GLFW_MOUSE_BUTTON_MIDDLE, held, 0);
break;
case SPECIALBTN_TOGGLECTRL:
[self executebtn_special_togglebtn:held];
break;
case SPECIALBTN_TOGGLECTRL:
[self executebtn_special_togglebtn:held];
break;
case SPECIALBTN_VIRTUALMOUSE:
case SPECIALBTN_SCROLLUP:
case SPECIALBTN_SCROLLDOWN:
NSLog(@"Warning: button %@ sent unimplemented special keycode: %d", button.titleLabel.text, keycode);
break;
case SPECIALBTN_VIRTUALMOUSE:
case SPECIALBTN_SCROLLUP:
case SPECIALBTN_SCROLLDOWN:
NSLog(@"Warning: button %@ sent unimplemented special keycode: %d", button.titleLabel.text, keycode);
break;
default:
NSLog(@"Warning: button %@ sent unknown special keycode: %d", button.titleLabel.text, keycode);
break;
default:
NSLog(@"Warning: button %@ sent unknown special keycode: %d", button.titleLabel.text, keycode);
break;
}
} else {
// there's no key id 0, but we accidentally used -1 as a special key id, so we had to do that
// if (keycode == 0) { keycode = -1; }
// at the moment, send unknown keycode does nothing, may even cause performance issue, so ignore it
if (keycode == 0) continue;
Java_org_lwjgl_glfw_CallbackBridge_nativeSendKey(NULL, NULL, keycode, 0, held, 0);
}
} else {
Java_org_lwjgl_glfw_CallbackBridge_nativeSendKey(NULL, NULL, keycode, 0, held, 0);
}
}
+2 -2
View File
@@ -126,10 +126,10 @@
self.layer.borderColor = [convertARGB2UIColor(propStrokeColor) CGColor];
if (propCornerRadius > 0) {
self.layer.cornerRadius = self.frame.size.width / 200 * propCornerRadius;
self.layer.cornerRadius = MIN(self.frame.size.width, self.frame.size.height) / 200.0 * propCornerRadius;
}
if (propStrokeWidth > 0) {
self.layer.borderWidth = self.frame.size.width / propStrokeWidth;
self.layer.borderWidth = MAX(self.frame.size.width, self.frame.size.height) / 200.0 * propStrokeWidth;
}
self.clipsToBounds = YES;
}
+53 -2
View File
@@ -18,7 +18,7 @@ NSMutableDictionary* createButton(NSString* name, int* keycodes, NSString* dynam
dict[@"height"] = @(height);
dict[@"opacity"] = @(100);
dict[@"cornerRadius"] = @(0);
dict[@"bgColor"] = @(convertUIColor2ARGB([UIColor colorWithRed:0 green:0 blue:0 alpha:0.3]));
dict[@"bgColor"] = @(0x4d000000);
return dict;
}
@@ -43,7 +43,58 @@ int convertUIColor2ARGB(UIColor* color) {
}
void convertV1ToV2(NSMutableDictionary* dict) {
dict[@"opacity"] = @(100 - ((NSNumber *)dict[@"transparency"]).intValue);
if (((NSNumber *)dict[@"version"]).intValue >= 2) {
return;
}
dict[@"scaledAt"] = @(100);
dict[@"version"] = @(2);
for (NSMutableDictionary *btnDict in (NSMutableArray *)dict[@"mControlDataList"]) {
NSMutableArray *keycodes = [NSMutableArray arrayWithCapacity:4];
CGFloat scale = ((NSNumber *)dict[@"scaledAt"]).floatValue;
// default values
btnDict[@"bgColor"] = @(0x4d000000);
btnDict[@"strokeWidth"] = @(0);
// opacity -> reverse transparency
btnDict[@"opacity"] = @(100 - ((NSNumber *)btnDict[@"transparency"]).intValue);
[btnDict removeObjectForKey:@"transparency"];
// pixel of width, height -> dp
btnDict[@"width"] = @(((NSNumber *)btnDict[@"width"]).floatValue / scale * 50.0);
btnDict[@"height"] = @(((NSNumber *)btnDict[@"height"]).floatValue / scale * 50.0);
// isRound -> cornerRadius 35%
if (((NSNumber *)btnDict[@"isRound"]).boolValue == YES) {
btnDict[@"cornerRadius"] = @(35.0f);
}
[btnDict removeObjectForKey:@"isRound"];
// keycode -> keycodes[0]
[keycodes addObject:btnDict[@"keycode"]];
[btnDict removeObjectForKey:@"keycode"];
// alt -> keycodes[i++]
if (((NSNumber *)dict[@"holdAlt"]).boolValue == YES) {
[keycodes addObject:@(GLFW_KEY_LEFT_ALT)];
}
[btnDict removeObjectForKey:@"holdAlt"];
// ctrl -> keycodes[i++]
if (((NSNumber *)dict[@"holdCtrl"]).boolValue == YES) {
[keycodes addObject:@(GLFW_KEY_LEFT_CONTROL)];
}
[btnDict removeObjectForKey:@"holdCtrl"];
// shift -> keycodes[i++]
if (((NSNumber *)dict[@"holdShift"]).boolValue == YES) {
[keycodes addObject:@(GLFW_KEY_LEFT_SHIFT)];
}
[btnDict removeObjectForKey:@"holdShift"];
// set final keycode array
btnDict[@"keycodes"] = keycodes;
}
}
void generateAndSaveDefaultControl() {