diff --git a/src/LBackend.c b/src/LBackend.c index 49d69f860..3552c6ccf 100644 --- a/src/LBackend.c +++ b/src/LBackend.c @@ -579,10 +579,27 @@ static cc_uint64 caretStart; static Rect2D caretRect, lastCaretRect; #define Rect2D_Equals(a, b) a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height +static void LInput_OpenKeyboard(struct LInput* w) { + struct OpenKeyboardArgs args; + + if (w->kbShowing) return; + w->kbShowing = true; + OpenKeyboardArgs_Init(&args, &w->text, w->inputType); + OnscreenKeyboard_Open(&args); +} + +static void LInput_OnClick(void* widget) { + struct LInput* w = (struct LInput*)widget; + LInput_OpenKeyboard(w); +} + void LBackend_InputInit(struct LInput* w, int width) { w->width = Display_ScaleX(width); w->height = Display_ScaleY(LINPUT_HEIGHT); w->minWidth = w->width; + + if (Window_Main.SoftKeyboard) + w->OnClick = LInput_OnClick; /* Text may end up being wider than minimum width */ if (w->text.length) LBackend_InputUpdate(w); @@ -681,20 +698,20 @@ void LBackend_InputTick(struct LInput* w) { } void LBackend_InputSelect(struct LInput* w, int idx, cc_bool wasSelected) { - struct OpenKeyboardArgs args; caretStart = Stopwatch_Measure(); w->caretShow = true; + w->kbShowing = false; LInput_MoveCaretToCursor(w, idx); LBackend_MarkDirty(w); - - if (wasSelected) return; - OpenKeyboardArgs_Init(&args, &w->text, w->inputType); - OnscreenKeyboard_Open(&args); + + if (Window_Main.SoftKeyboard && Input_TouchMode) + LInput_OpenKeyboard(w); } void LBackend_InputUnselect(struct LInput* w) { caretStart = 0; w->caretShow = false; + w->kbShowing = false; LBackend_MarkDirty(w); OnscreenKeyboard_Close(); } diff --git a/src/LWidgets.h b/src/LWidgets.h index 64be2e10e..9ce429abb 100644 --- a/src/LWidgets.h +++ b/src/LWidgets.h @@ -99,6 +99,7 @@ struct LInput { cc_uint8 inputType; /* Whether caret is currently visible */ cc_bool caretShow; + cc_bool kbShowing; /* Filter applied to text received from the clipboard. Can be NULL. */ void (*ClipboardFilter)(cc_string* str); /* Callback invoked when the text is changed. Can be NULL. */ diff --git a/src/Vectors.c b/src/Vectors.c index 7bee5f2c2..e835596dd 100644 --- a/src/Vectors.c +++ b/src/Vectors.c @@ -176,34 +176,32 @@ void Matrix_LookRot(struct Matrix* result, Vec3 pos, Vec2 rot) { Matrix_Mul(result, &trans, result); } -/* TODO: Move to matrix instance instead */ -static float -frustum00, frustum01, frustum02, frustum03, -frustum10, frustum11, frustum12, frustum13, -frustum20, frustum21, frustum22, frustum23, -frustum30, frustum31, frustum32, frustum33, -frustum40, frustum41, frustum42, frustum43; -static void FrustumCulling_Normalise(float* plane0, float* plane1, float* plane2, float* plane3) { - float val1 = *plane0, val2 = *plane1, val3 = *plane2; +struct Plane { float a, b, c, d; }; +static struct Plane frustumR, frustumL, frustumB, frustumT, frustumF; + +static void FrustumCulling_Normalise(struct Plane* plane) { + float val1 = plane->a, val2 = plane->b, val3 = plane->c; float t = Math_SqrtF(val1 * val1 + val2 * val2 + val3 * val3); - *plane0 /= t; *plane1 /= t; *plane2 /= t; *plane3 /= t; + plane->a /= t; plane->b /= t; plane->c /= t; plane->d /= t; } cc_bool FrustumCulling_SphereInFrustum(float x, float y, float z, float radius) { - float d = frustum00 * x + frustum01 * y + frustum02 * z + frustum03; + float d; + + d = frustumR.a * x + frustumR.b * y + frustumR.c * z + frustumR.d; if (d <= -radius) return false; - d = frustum10 * x + frustum11 * y + frustum12 * z + frustum13; + d = frustumL.a * x + frustumL.b * y + frustumL.c * z + frustumL.d; if (d <= -radius) return false; - d = frustum20 * x + frustum21 * y + frustum22 * z + frustum23; + d = frustumB.a * x + frustumB.b * y + frustumB.c * z + frustumB.d; if (d <= -radius) return false; - d = frustum30 * x + frustum31 * y + frustum32 * z + frustum33; + d = frustumT.a * x + frustumT.b * y + frustumT.c * z + frustumT.d; if (d <= -radius) return false; - d = frustum40 * x + frustum41 * y + frustum42 * z + frustum43; + d = frustumF.a * x + frustumF.b * y + frustumF.c * z + frustumF.d; if (d <= -radius) return false; /* Don't test NEAR plane, it's pointless */ return true; @@ -214,47 +212,47 @@ void FrustumCulling_CalcFrustumEquations(struct Matrix* projection, struct Matri Matrix_Mul(&clip, modelView, projection); /* Extract the RIGHT plane */ - frustum00 = clip.row1.w - clip.row1.x; - frustum01 = clip.row2.w - clip.row2.x; - frustum02 = clip.row3.w - clip.row3.x; - frustum03 = clip.row4.w - clip.row4.x; - FrustumCulling_Normalise(&frustum00, &frustum01, &frustum02, &frustum03); + frustumR.a = clip.row1.w - clip.row1.x; + frustumR.b = clip.row2.w - clip.row2.x; + frustumR.c = clip.row3.w - clip.row3.x; + frustumR.d = clip.row4.w - clip.row4.x; + FrustumCulling_Normalise(&frustumR); /* Extract the LEFT plane */ - frustum10 = clip.row1.w + clip.row1.x; - frustum11 = clip.row2.w + clip.row2.x; - frustum12 = clip.row3.w + clip.row3.x; - frustum13 = clip.row4.w + clip.row4.x; - FrustumCulling_Normalise(&frustum10, &frustum11, &frustum12, &frustum13); + frustumL.a = clip.row1.w + clip.row1.x; + frustumL.b = clip.row2.w + clip.row2.x; + frustumL.c = clip.row3.w + clip.row3.x; + frustumL.d = clip.row4.w + clip.row4.x; + FrustumCulling_Normalise(&frustumL); /* Extract the BOTTOM plane */ - frustum20 = clip.row1.w + clip.row1.y; - frustum21 = clip.row2.w + clip.row2.y; - frustum22 = clip.row3.w + clip.row3.y; - frustum23 = clip.row4.w + clip.row4.y; - FrustumCulling_Normalise(&frustum20, &frustum21, &frustum22, &frustum23); + frustumB.a = clip.row1.w + clip.row1.y; + frustumB.b = clip.row2.w + clip.row2.y; + frustumB.c = clip.row3.w + clip.row3.y; + frustumB.d = clip.row4.w + clip.row4.y; + FrustumCulling_Normalise(&frustumB); /* Extract the TOP plane */ - frustum30 = clip.row1.w - clip.row1.y; - frustum31 = clip.row2.w - clip.row2.y; - frustum32 = clip.row3.w - clip.row3.y; - frustum33 = clip.row4.w - clip.row4.y; - FrustumCulling_Normalise(&frustum30, &frustum31, &frustum32, &frustum33); + frustumT.a = clip.row1.w - clip.row1.y; + frustumT.b = clip.row2.w - clip.row2.y; + frustumT.c = clip.row3.w - clip.row3.y; + frustumT.d = clip.row4.w - clip.row4.y; + FrustumCulling_Normalise(&frustumT); /* Extract the FAR plane (Different for each graphics backend) */ #if (CC_GFX_BACKEND == CC_GFX_BACKEND_D3D9) || (CC_GFX_BACKEND == CC_GFX_BACKEND_D3D11) /* OpenGL and Direct3D require slightly different behaviour for NEAR clipping planes */ /* https://www.gamedevs.org/uploads/fast-extraction-viewing-frustum-planes-from-world-view-projection-matrix.pdf */ /* (and because reverse Z is used, 'NEAR' plane is actually the 'FAR' clipping plane) */ - frustum40 = clip.row1.z; - frustum41 = clip.row2.z; - frustum42 = clip.row3.z; - frustum43 = clip.row4.z; + frustumF.a = clip.row1.z; + frustumF.b = clip.row2.z; + frustumF.c = clip.row3.z; + frustumF.d = clip.row4.z; #else - frustum40 = clip.row1.w - clip.row1.z; - frustum41 = clip.row2.w - clip.row2.z; - frustum42 = clip.row3.w - clip.row3.z; - frustum43 = clip.row4.w - clip.row4.z; + frustumF.a = clip.row1.w - clip.row1.z; + frustumF.b = clip.row2.w - clip.row2.z; + frustumF.c = clip.row3.w - clip.row3.z; + frustumF.d = clip.row4.w - clip.row4.z; #endif - FrustumCulling_Normalise(&frustum40, &frustum41, &frustum42, &frustum43); + FrustumCulling_Normalise(&frustumF); } diff --git a/src/Window_GCWii.c b/src/Window_GCWii.c index c6ce3e658..f548b6e7a 100644 --- a/src/Window_GCWii.c +++ b/src/Window_GCWii.c @@ -81,6 +81,7 @@ void Window_Init(void) { Input.Sources = INPUT_SOURCE_GAMEPAD; DisplayInfo.ContentOffsetX = 10; DisplayInfo.ContentOffsetY = 10; + Window_Main.SoftKeyboard = SOFT_KEYBOARD_VIRTUAL; #if defined HW_RVL WPAD_Init(); diff --git a/src/Window_PS2.c b/src/Window_PS2.c index df7edb0f3..b2238ba0b 100644 --- a/src/Window_PS2.c +++ b/src/Window_PS2.c @@ -55,6 +55,7 @@ void Window_Init(void) { Input.Sources = INPUT_SOURCE_GAMEPAD; DisplayInfo.ContentOffsetX = 10; DisplayInfo.ContentOffsetY = 10; + Window_Main.SoftKeyboard = SOFT_KEYBOARD_VIRTUAL; padInit(0); padPortOpen(0, 0, padBuf0); @@ -80,7 +81,7 @@ static void ResetGfxState(void) { fb_colors[0].height = DisplayInfo.Height; fb_colors[0].mask = 0; fb_colors[0].psm = GS_PSM_32; - fb_colors[0].address = graph_vram_allocate(fb_colors[0].width, fb_colors[0].height, fb_colors[1].psm, GRAPH_ALIGN_PAGE); + fb_colors[0].address = graph_vram_allocate(fb_colors[0].width, fb_colors[0].height, fb_colors[0].psm, GRAPH_ALIGN_PAGE); fb_colors[1].width = DisplayInfo.Width; fb_colors[1].height = DisplayInfo.Height; diff --git a/src/Window_PS3.c b/src/Window_PS3.c index 716c31993..058375545 100644 --- a/src/Window_PS3.c +++ b/src/Window_PS3.c @@ -63,6 +63,7 @@ void Window_Init(void) { Input.Sources = INPUT_SOURCE_GAMEPAD; DisplayInfo.ContentOffsetX = 20; DisplayInfo.ContentOffsetY = 20; + Window_Main.SoftKeyboard = SOFT_KEYBOARD_VIRTUAL; ioPadInit(MAX_PORT_NUM); ioKbInit(MAX_KB_PORT_NUM); diff --git a/src/Window_PSP.c b/src/Window_PSP.c index 72fe03104..104027b32 100644 --- a/src/Window_PSP.c +++ b/src/Window_PSP.c @@ -42,6 +42,7 @@ void Window_Init(void) { Window_Main.Exists = true; Window_Main.UIScaleX = DEFAULT_UI_SCALE_X; Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; + Window_Main.SoftKeyboard = SOFT_KEYBOARD_VIRTUAL; Input.Sources = INPUT_SOURCE_GAMEPAD; sceDisplaySetMode(0, SCREEN_WIDTH, SCREEN_HEIGHT); diff --git a/src/Window_Xbox.c b/src/Window_Xbox.c index ed951d72b..cb9323595 100644 --- a/src/Window_Xbox.c +++ b/src/Window_Xbox.c @@ -81,6 +81,7 @@ void Window_Init(void) { Input.Sources = INPUT_SOURCE_GAMEPAD; DisplayInfo.ContentOffsetX = 10; DisplayInfo.ContentOffsetY = 10; + Window_Main.SoftKeyboard = SOFT_KEYBOARD_VIRTUAL; #ifndef CC_BUILD_CXBX usbh_core_init(); diff --git a/src/Window_Xbox360.c b/src/Window_Xbox360.c index bf503084c..c2058ef3d 100644 --- a/src/Window_Xbox360.c +++ b/src/Window_Xbox360.c @@ -42,6 +42,7 @@ void Window_Init(void) { Window_Main.UIScaleY = DEFAULT_UI_SCALE_Y; Input.Sources = INPUT_SOURCE_GAMEPAD; + Window_Main.SoftKeyboard = SOFT_KEYBOARD_VIRTUAL; usb_init(); usb_do_poll(); diff --git a/src/freetype/ftconfig.h b/src/freetype/ftconfig.h index bb7ecc8c4..66f9a6f74 100644 --- a/src/freetype/ftconfig.h +++ b/src/freetype/ftconfig.h @@ -46,7 +46,7 @@ FT_BEGIN_HEADER /* ClassiCube patch - don't export FreeType symbols to avoid conflicting with system */ -#if defined(__GNUC__) +#if defined(__GNUC__) && !defined(_WIN32) #define FT_EXPORT( x ) __attribute__((visibility("hidden"))) extern x #define FT_BASE( x ) __attribute__((visibility("hidden"))) extern x #elif defined(__cplusplus)