Orientation lock checkbox

This commit is contained in:
igor725 2021-08-21 04:43:51 +03:00
parent 6e433e5585
commit 93a6b7fdae
No known key found for this signature in database
GPG key ID: 46F13BBE46F8569D
5 changed files with 129 additions and 91 deletions

View file

@ -1411,10 +1411,21 @@ void ServersScreen_SetActive(void) {
static struct SettingsScreen {
LScreen_Layout
struct LButton btnUpdates, btnMode, btnColours, btnBack;
struct LLabel lblUpdates, lblMode, lblColours;
struct LWidget* _widgets[7];
struct LLabel lblUpdates, lblMode, lblColours, lblOrientlock;
struct LCheckbox cbOrientlock;
struct LWidget* _widgets[9];
} SettingsScreen_Instance;
#if defined CC_BUILD_ANDROID
static void SettingsScreen_LockOrientation(void* w, int idx) {
struct LCheckbox* cb = (struct LCheckbox*)w;
cb->value ^= true;
Options_SetBool(OPT_LANDSCAPE_MODE, cb->value);
Window_LockLandscapeOrientation(cb->value);
Launcher_Redraw();
}
#endif
static void SettingsScreen_Init(struct LScreen* s_) {
struct SettingsScreen* s = (struct SettingsScreen*)s_;
s->widgets = s->_widgets;
@ -1428,6 +1439,12 @@ static void SettingsScreen_Init(struct LScreen* s_) {
LButton_Init(s_, &s->btnColours, 110, 35, "Theme");
LLabel_Init(s_, &s->lblColours, "&eChange how the launcher looks");
#if defined CC_BUILD_ANDROID
LLabel_Init(s_, &s->lblOrientlock, "Portrait orientation lock");
LCheckbox_Init(s_, &s->cbOrientlock);
s->cbOrientlock.OnClick = SettingsScreen_LockOrientation;
#endif
LButton_Init(s_, &s->btnBack, 80, 35, "Back");
s->btnMode.OnClick = SwitchToChooseMode;
@ -1440,6 +1457,7 @@ static void SettingsScreen_Show(struct LScreen* s_) {
struct SettingsScreen* s = (struct SettingsScreen*)s_;
s->btnColours.hidden = Options_GetBool(OPT_CLASSIC_MODE, false);
s->lblColours.hidden = s->btnColours.hidden;
s->cbOrientlock.value = Options_GetBool(OPT_LANDSCAPE_MODE, false);
}
static void SettingsScreen_Layout(struct LScreen* s_) {
@ -1453,6 +1471,11 @@ static void SettingsScreen_Layout(struct LScreen* s_) {
LWidget_SetLocation(&s->btnColours, ANCHOR_CENTRE, ANCHOR_CENTRE, -135, -20);
LWidget_SetLocation(&s->lblColours, ANCHOR_CENTRE_MIN, ANCHOR_CENTRE, -70, -20);
#if defined CC_BUILD_ANDROID
LWidget_SetLocation(&s->cbOrientlock, ANCHOR_CENTRE, ANCHOR_CENTRE, -178, 24);
LWidget_SetLocation(&s->lblOrientlock, ANCHOR_CENTRE, ANCHOR_CENTRE, -58, 24);
#endif
LWidget_SetLocation(&s->btnBack, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 170);
}

View file

@ -280,6 +280,7 @@ void Launcher_Run(void) {
Window_Create(640, 400);
#ifdef CC_BUILD_ANDROID
Window_EnterFullscreen();
Window_LockLandscapeOrientation(Options_GetBool(OPT_LANDSCAPE_MODE, false));
#endif
Window_SetTitle(&title);
Window_Show();

View file

@ -54,6 +54,7 @@
#define OPT_FONT_NAME "gui-fontname"
#define OPT_BLACK_TEXT "gui-blacktextshadows"
#define OPT_LANDSCAPE_MODE "landscape-mode"
#define OPT_CLASSIC_MODE "mode-classic"
#define OPT_CUSTOM_BLOCKS "nostalgia-customblocks"
#define OPT_CPE "nostalgia-usecpe"

View file

@ -148,6 +148,8 @@ void Window_OpenKeyboard(const struct OpenKeyboardArgs* args);
void Window_SetKeyboardText(const cc_string* text);
/* Hides/Removes the previously displayed on-screen keyboard. */
void Window_CloseKeyboard(void);
/* Locks/Unlocks the landscape orientation. */
void Window_LockLandscapeOrientation(cc_bool lock);
/* Begins listening for raw input and starts raising PointerEvents.RawMoved. */
/* NOTE: Some backends only raise it when Window_UpdateRawMouse is called. */

View file

@ -19,57 +19,57 @@ static void RefreshWindowBounds(void) {
}
static int MapNativeKey(int code) {
if (code >= AKEYCODE_0 && code <= AKEYCODE_9) return (code - AKEYCODE_0) + '0';
if (code >= AKEYCODE_A && code <= AKEYCODE_Z) return (code - AKEYCODE_A) + 'A';
if (code >= AKEYCODE_F1 && code <= AKEYCODE_F12) return (code - AKEYCODE_F1) + KEY_F1;
if (code >= AKEYCODE_NUMPAD_0 && code <= AKEYCODE_NUMPAD_9) return (code - AKEYCODE_NUMPAD_0) + KEY_KP0;
switch (code) {
/* TODO: AKEYCODE_STAR */
/* TODO: AKEYCODE_POUND */
case AKEYCODE_BACK: return KEY_ESCAPE;
case AKEYCODE_COMMA: return KEY_COMMA;
case AKEYCODE_PERIOD: return KEY_PERIOD;
case AKEYCODE_ALT_LEFT: return KEY_LALT;
case AKEYCODE_ALT_RIGHT: return KEY_RALT;
case AKEYCODE_SHIFT_LEFT: return KEY_LSHIFT;
case AKEYCODE_SHIFT_RIGHT: return KEY_RSHIFT;
case AKEYCODE_TAB: return KEY_TAB;
case AKEYCODE_SPACE: return KEY_SPACE;
case AKEYCODE_ENTER: return KEY_ENTER;
case AKEYCODE_DEL: return KEY_BACKSPACE;
case AKEYCODE_GRAVE: return KEY_TILDE;
case AKEYCODE_MINUS: return KEY_MINUS;
case AKEYCODE_EQUALS: return KEY_EQUALS;
case AKEYCODE_LEFT_BRACKET: return KEY_LBRACKET;
case AKEYCODE_RIGHT_BRACKET: return KEY_RBRACKET;
case AKEYCODE_BACKSLASH: return KEY_BACKSLASH;
case AKEYCODE_SEMICOLON: return KEY_SEMICOLON;
case AKEYCODE_APOSTROPHE: return KEY_QUOTE;
case AKEYCODE_SLASH: return KEY_SLASH;
/* TODO: AKEYCODE_AT */
/* TODO: AKEYCODE_PLUS */
/* TODO: AKEYCODE_MENU */
case AKEYCODE_PAGE_UP: return KEY_PAGEUP;
case AKEYCODE_PAGE_DOWN: return KEY_PAGEDOWN;
case AKEYCODE_ESCAPE: return KEY_ESCAPE;
case AKEYCODE_FORWARD_DEL: return KEY_DELETE;
case AKEYCODE_CTRL_LEFT: return KEY_LCTRL;
case AKEYCODE_CTRL_RIGHT: return KEY_RCTRL;
case AKEYCODE_CAPS_LOCK: return KEY_CAPSLOCK;
case AKEYCODE_SCROLL_LOCK: return KEY_SCROLLLOCK;
case AKEYCODE_META_LEFT: return KEY_LWIN;
case AKEYCODE_META_RIGHT: return KEY_RWIN;
case AKEYCODE_SYSRQ: return KEY_PRINTSCREEN;
case AKEYCODE_BREAK: return KEY_PAUSE;
case AKEYCODE_INSERT: return KEY_INSERT;
case AKEYCODE_NUM_LOCK: return KEY_NUMLOCK;
case AKEYCODE_NUMPAD_DIVIDE: return KEY_KP_DIVIDE;
case AKEYCODE_NUMPAD_MULTIPLY: return KEY_KP_MULTIPLY;
case AKEYCODE_NUMPAD_SUBTRACT: return KEY_KP_MINUS;
case AKEYCODE_NUMPAD_ADD: return KEY_KP_PLUS;
case AKEYCODE_NUMPAD_DOT: return KEY_KP_DECIMAL;
case AKEYCODE_NUMPAD_ENTER: return KEY_KP_ENTER;
if (code >= AKEYCODE_0 && code <= AKEYCODE_9) return (code - AKEYCODE_0) + '0';
if (code >= AKEYCODE_A && code <= AKEYCODE_Z) return (code - AKEYCODE_A) + 'A';
if (code >= AKEYCODE_F1 && code <= AKEYCODE_F12) return (code - AKEYCODE_F1) + KEY_F1;
if (code >= AKEYCODE_NUMPAD_0 && code <= AKEYCODE_NUMPAD_9) return (code - AKEYCODE_NUMPAD_0) + KEY_KP0;
switch (code) {
/* TODO: AKEYCODE_STAR */
/* TODO: AKEYCODE_POUND */
case AKEYCODE_BACK: return KEY_ESCAPE;
case AKEYCODE_COMMA: return KEY_COMMA;
case AKEYCODE_PERIOD: return KEY_PERIOD;
case AKEYCODE_ALT_LEFT: return KEY_LALT;
case AKEYCODE_ALT_RIGHT: return KEY_RALT;
case AKEYCODE_SHIFT_LEFT: return KEY_LSHIFT;
case AKEYCODE_SHIFT_RIGHT: return KEY_RSHIFT;
case AKEYCODE_TAB: return KEY_TAB;
case AKEYCODE_SPACE: return KEY_SPACE;
case AKEYCODE_ENTER: return KEY_ENTER;
case AKEYCODE_DEL: return KEY_BACKSPACE;
case AKEYCODE_GRAVE: return KEY_TILDE;
case AKEYCODE_MINUS: return KEY_MINUS;
case AKEYCODE_EQUALS: return KEY_EQUALS;
case AKEYCODE_LEFT_BRACKET: return KEY_LBRACKET;
case AKEYCODE_RIGHT_BRACKET: return KEY_RBRACKET;
case AKEYCODE_BACKSLASH: return KEY_BACKSLASH;
case AKEYCODE_SEMICOLON: return KEY_SEMICOLON;
case AKEYCODE_APOSTROPHE: return KEY_QUOTE;
case AKEYCODE_SLASH: return KEY_SLASH;
/* TODO: AKEYCODE_AT */
/* TODO: AKEYCODE_PLUS */
/* TODO: AKEYCODE_MENU */
case AKEYCODE_PAGE_UP: return KEY_PAGEUP;
case AKEYCODE_PAGE_DOWN: return KEY_PAGEDOWN;
case AKEYCODE_ESCAPE: return KEY_ESCAPE;
case AKEYCODE_FORWARD_DEL: return KEY_DELETE;
case AKEYCODE_CTRL_LEFT: return KEY_LCTRL;
case AKEYCODE_CTRL_RIGHT: return KEY_RCTRL;
case AKEYCODE_CAPS_LOCK: return KEY_CAPSLOCK;
case AKEYCODE_SCROLL_LOCK: return KEY_SCROLLLOCK;
case AKEYCODE_META_LEFT: return KEY_LWIN;
case AKEYCODE_META_RIGHT: return KEY_RWIN;
case AKEYCODE_SYSRQ: return KEY_PRINTSCREEN;
case AKEYCODE_BREAK: return KEY_PAUSE;
case AKEYCODE_INSERT: return KEY_INSERT;
case AKEYCODE_NUM_LOCK: return KEY_NUMLOCK;
case AKEYCODE_NUMPAD_DIVIDE: return KEY_KP_DIVIDE;
case AKEYCODE_NUMPAD_MULTIPLY: return KEY_KP_MULTIPLY;
case AKEYCODE_NUMPAD_SUBTRACT: return KEY_KP_MINUS;
case AKEYCODE_NUMPAD_ADD: return KEY_KP_PLUS;
case AKEYCODE_NUMPAD_DOT: return KEY_KP_DECIMAL;
case AKEYCODE_NUMPAD_ENTER: return KEY_KP_ENTER;
}
return KEY_NONE;
}
@ -149,48 +149,48 @@ static void JNICALL java_processSurfaceRedrawNeeded(JNIEnv* env, jobject o) {
Event_RaiseVoid(&WindowEvents.Redraw);
}
static void JNICALL java_onStart(JNIEnv* env, jobject o) {
Platform_LogConst("APP - ON START");
}
static void JNICALL java_onStop(JNIEnv* env, jobject o) {
Platform_LogConst("APP - ON STOP");
}
static void JNICALL java_onResume(JNIEnv* env, jobject o) {
Platform_LogConst("APP - ON RESUME");
/* TODO: Resume rendering */
}
static void JNICALL java_onPause(JNIEnv* env, jobject o) {
Platform_LogConst("APP - ON PAUSE");
/* TODO: Disable rendering */
}
static void JNICALL java_onDestroy(JNIEnv* env, jobject o) {
Platform_LogConst("APP - ON DESTROY");
if (WindowInfo.Exists) Window_Close();
/* TODO: signal to java code we're done */
JavaCallVoid(env, "processedDestroyed", "()V", NULL);
}
static void JNICALL java_onGotFocus(JNIEnv* env, jobject o) {
Platform_LogConst("APP - GOT FOCUS");
WindowInfo.Focused = true;
Event_RaiseVoid(&WindowEvents.FocusChanged);
static void JNICALL java_onStart(JNIEnv* env, jobject o) {
Platform_LogConst("APP - ON START");
}
static void JNICALL java_onLostFocus(JNIEnv* env, jobject o) {
Platform_LogConst("APP - LOST FOCUS");
static void JNICALL java_onStop(JNIEnv* env, jobject o) {
Platform_LogConst("APP - ON STOP");
}
static void JNICALL java_onResume(JNIEnv* env, jobject o) {
Platform_LogConst("APP - ON RESUME");
/* TODO: Resume rendering */
}
static void JNICALL java_onPause(JNIEnv* env, jobject o) {
Platform_LogConst("APP - ON PAUSE");
/* TODO: Disable rendering */
}
static void JNICALL java_onDestroy(JNIEnv* env, jobject o) {
Platform_LogConst("APP - ON DESTROY");
if (WindowInfo.Exists) Window_Close();
/* TODO: signal to java code we're done */
JavaCallVoid(env, "processedDestroyed", "()V", NULL);
}
static void JNICALL java_onGotFocus(JNIEnv* env, jobject o) {
Platform_LogConst("APP - GOT FOCUS");
WindowInfo.Focused = true;
Event_RaiseVoid(&WindowEvents.FocusChanged);
}
static void JNICALL java_onLostFocus(JNIEnv* env, jobject o) {
Platform_LogConst("APP - LOST FOCUS");
WindowInfo.Focused = false;
Event_RaiseVoid(&WindowEvents.FocusChanged);
/* TODO: Disable rendering? */
/* TODO: Disable rendering? */
}
static void JNICALL java_onLowMemory(JNIEnv* env, jobject o) {
Platform_LogConst("APP - LOW MEM");
/* TODO: Low memory */
static void JNICALL java_onLowMemory(JNIEnv* env, jobject o) {
Platform_LogConst("APP - LOW MEM");
/* TODO: Low memory */
}
static const JNINativeMethod methods[19] = {
@ -217,7 +217,7 @@ static const JNINativeMethod methods[19] = {
{ "processOnGotFocus", "()V", java_onGotFocus },
{ "processOnLostFocus", "()V", java_onLostFocus },
{ "processOnLowMemory", "()V", java_onLowMemory }
};
};
void Window_Init(void) {
JNIEnv* env;
@ -404,6 +404,17 @@ void Window_CloseKeyboard(void) {
JavaCallVoid(env, "closeKeyboard", "()V", NULL);
}
void Window_LockLandscapeOrientation(cc_bool lock) {
JNIEnv* env;
jvalue args[1];
JavaGetCurrentEnv(env);
/* SCREEN_ORIENTATION_SENSOR_LANDSCAPE = 0x00000006 */
/* SCREEN_ORIENTATION_USER = 0x00000002 */
args[0].i = lock ? 0x00000006 : 0x00000002;
JavaCallVoid(env, "setRequestedOrientation", "(I)V", args);
}
void Window_EnableRawMouse(void) { DefaultEnableRawMouse(); }
void Window_UpdateRawMouse(void) { }
void Window_DisableRawMouse(void) { DefaultDisableRawMouse(); }