From b548cfa231bd749d9d7a8180dcccd4996aa01651 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sun, 17 Mar 2024 10:55:04 +1100 Subject: [PATCH] Switch: Respond to exit requests and avoid relying on assumptions about stride of framebuffer --- src/Window_Switch.c | 19 +++++++++++-------- src/_WindowBase.h | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Window_Switch.c b/src/Window_Switch.c index 1109f66bc..f67a15fba 100644 --- a/src/Window_Switch.c +++ b/src/Window_Switch.c @@ -44,6 +44,9 @@ static void Applet_Event(AppletHookType type, void* param) { if (type == AppletHookType_OnOperationMode) { SetResolution(); Event_RaiseVoid(&WindowEvents.Resized); + } else if (type == AppletHookType_OnExitRequest) { + Window_Main.Exists = false; + Window_RequestClose(); } } @@ -141,19 +144,17 @@ static void ProcessJoystickInput_R(HidAnalogStickState* pos) { static void ProcessTouchInput(void) { static int currX, currY, prev_touchcount=0; HidTouchScreenState state={0}; - hidGetTouchScreenStates(&state, 1); + hidGetTouchScreenStates(&state, 1); if (state.count && !prev_touchcount) { // stylus went down currX = state.touches[0].x; currY = state.touches[0].y; Input_AddTouch(0, currX, currY); - } - else if (state.count) { // stylus is down + } else if (state.count) { // stylus is down currX = state.touches[0].x; currY = state.touches[0].y; Input_UpdateTouch(0, currX, currY); - } - else if (!state.count && prev_touchcount) { // stylus was lifted + } else if (!state.count && prev_touchcount) { // stylus was lifted Input_RemoveTouch(0, currX, currY); } @@ -201,15 +202,17 @@ void Window_AllocFramebuffer(struct Bitmap* bmp) { void Window_DrawFramebuffer(Rect2D r, struct Bitmap* bmp) { // Retrieve the framebuffer cc_uint32 stride; - cc_uint32* framebuf = (cc_uint32*) framebufferBegin(&fb, &stride); + cc_uint32* framebuf = (cc_uint32*)framebufferBegin(&fb, &stride); // flip upside down for (cc_uint32 y = r.y; y < r.y + r.Height; y++) { + BitmapCol* src = Bitmap_GetRow(bmp, y); + cc_uint32* dst = framebuf + y * stride / sizeof(cc_uint32); + for (cc_uint32 x = r.x; x < r.x + r.Width; x++) { - cc_uint32 pos = y * stride / sizeof(cc_uint32) + x; - framebuf[pos] = bmp->scan0[pos]; + dst[x] = src[x]; } } diff --git a/src/_WindowBase.h b/src/_WindowBase.h index a6baf5505..769e25182 100644 --- a/src/_WindowBase.h +++ b/src/_WindowBase.h @@ -146,7 +146,7 @@ void GLContext_Create(void) { #elif defined CC_BUILD_GLES EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT, #else - #error "Can't determine appropriate EGL_RENDERABLE_TYPE" + EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, #endif EGL_NONE };