diff --git a/src/Gui.c b/src/Gui.c index 3b815e273..d7d96056b 100644 --- a/src/Gui.c +++ b/src/Gui.c @@ -141,12 +141,16 @@ void Gui_LayoutAll(void) { struct Screen* s; int i; + enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); + for (i = 0; i < Gui.ScreensCount; i++) { s = Gui_Screens[i]; s->VTABLE->Layout(s); s->dirty = true; } + + Window_3DS_SetRenderScreen(scr); } void Gui_RefreshAll(void) { @@ -156,10 +160,14 @@ void Gui_RefreshAll(void) { } void Gui_Refresh(struct Screen* s) { + enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); + s->VTABLE->ContextLost(s); s->VTABLE->ContextRecreated(s); s->VTABLE->Layout(s); s->dirty = true; + + Window_3DS_SetRenderScreen(scr); } static void Gui_AddCore(struct Screen* s, int priority) { @@ -183,6 +191,8 @@ static void Gui_AddCore(struct Screen* s, int priority) { priorities[i] = priority; Gui.ScreensCount++; + enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); + s->dirty = true; s->VTABLE->Init(s); s->VTABLE->ContextRecreated(s); @@ -193,6 +203,8 @@ static void Gui_AddCore(struct Screen* s, int priority) { { s->VTABLE->HandlesPointerMove(s, i, Pointers[i].x, Pointers[i].y); } + + Window_3DS_SetRenderScreen(scr); } /* Returns index of the given screen in the screens list, -1 if not */ @@ -287,6 +299,8 @@ void Gui_RenderGui(double delta) { struct Screen* s; int i; + enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); + /* Draw back to front so highest priority screen is on top */ for (i = Gui.ScreensCount - 1; i >= 0; i--) { @@ -296,6 +310,8 @@ void Gui_RenderGui(double delta) { if (s->dirty) { s->VTABLE->BuildMesh(s); s->dirty = false; } s->VTABLE->Render(s, delta); } + + Window_3DS_SetRenderScreen(scr); } diff --git a/src/Menus.c b/src/Menus.c index e52a2a422..c5664f203 100644 --- a/src/Menus.c +++ b/src/Menus.c @@ -261,8 +261,6 @@ static struct Widget* list_widgets[] = { #define LISTSCREEN_EMPTY "-" static void ListScreen_Layout(void* screen) { - enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); - struct ListScreen* s = (struct ListScreen*)screen; int i; @@ -282,8 +280,6 @@ static void ListScreen_Layout(void* screen) { Widget_SetLocation(&s->left, ANCHOR_CENTRE, ANCHOR_CENTRE, -220, 0); Widget_SetLocation(&s->right, ANCHOR_CENTRE, ANCHOR_CENTRE, 220, 0); Widget_SetLocation(&s->title, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -155); - - Window_3DS_SetRenderScreen(scr); } static STRING_REF cc_string ListScreen_UNSAFE_Get(struct ListScreen* s, int index) { @@ -487,12 +483,8 @@ void ListScreen_Show(void) { *--------------------------------------------------------MenuScreen-------------------------------------------------------* *#########################################################################################################################*/ static void MenuScreen_Render2(void* screen, double delta) { - enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); - Menu_RenderBounds(); Screen_Render2Widgets(screen, delta); - - Window_3DS_SetRenderScreen(scr); } @@ -559,15 +551,11 @@ static void PauseScreen_ContextRecreated(void* screen) { } static void PauseScreen_Layout(void* screen) { - enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); - struct PauseScreen* s = (struct PauseScreen*)screen; Menu_LayoutButtons(s->btns, s->descs, s->descsCount); Menu_LayoutBack(&s->back); Widget_SetLocation(&s->quit, ANCHOR_MAX, ANCHOR_MAX, 5, 5); Widget_SetLocation(&s->title, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -100); - - Window_3DS_SetRenderScreen(scr); } static void PauseScreen_Init(void* screen) { @@ -632,14 +620,10 @@ static void ClassicPauseScreen_ContextRecreated(void* screen) { } static void ClassicPauseScreen_Layout(void* screen) { - enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); - struct PauseScreen* s = (struct PauseScreen*)screen; Menu_LayoutButtons(s->btns, s->descs, s->descsCount); Widget_SetLocation(&s->back, ANCHOR_CENTRE, ANCHOR_MAX, 0, Game_ClassicMode ? 80 : 25); Widget_SetLocation(&s->title, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -150); - - Window_3DS_SetRenderScreen(scr); } static void ClassicPauseScreen_Init(void* screen) { @@ -755,14 +739,10 @@ static void OptionsGroupScreen_ContextRecreated(void* screen) { } static void OptionsGroupScreen_Layout(void* screen) { - enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); - struct OptionsGroupScreen* s = (struct OptionsGroupScreen*)screen; Menu_LayoutButtons(s->btns, optsGroup_btns, 8); Widget_SetLocation(&s->desc, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 100); Menu_LayoutBack(&s->done); - - Window_3DS_SetRenderScreen(scr); } static void OptionsGroupScreen_Init(void* screen) { @@ -1012,8 +992,6 @@ static void EditHotkeyScreen_Update(void* screen, double delta) { } static void EditHotkeyScreen_Layout(void* screen) { - enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); - struct EditHotkeyScreen* s = (struct EditHotkeyScreen*)screen; s->barWidth = Display_ScaleX(500); s->barX = Gui_CalcPos(ANCHOR_CENTRE, 0, s->barWidth, WindowInfo.Width); @@ -1031,8 +1009,6 @@ static void EditHotkeyScreen_Layout(void* screen) { Widget_SetLocation(&s->btns[4], ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 130); Widget_SetLocation(&s->input, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -35); Menu_LayoutBack(&s->cancel); - - Window_3DS_SetRenderScreen(scr); } static void EditHotkeyScreen_Init(void* screen) { @@ -1256,8 +1232,6 @@ static void GenLevelScreen_Update(void* screen, double delta) { } static void GenLevelScreen_Layout(void* screen) { - enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); - struct GenLevelScreen* s = (struct GenLevelScreen*)screen; int i, y; for (i = 0; i < 4; i++) { @@ -1270,8 +1244,6 @@ static void GenLevelScreen_Layout(void* screen) { Widget_SetLocation(&s->flatgrass, ANCHOR_CENTRE, ANCHOR_CENTRE, -120, 100); Widget_SetLocation(&s->vanilla, ANCHOR_CENTRE, ANCHOR_CENTRE, 120, 100); Menu_LayoutBack(&s->cancel); - - Window_3DS_SetRenderScreen(scr); } static void GenLevelScreen_Init(void* screen) { @@ -1353,16 +1325,12 @@ static void ClassicGenScreen_ContextRecreated(void* screen) { } static void ClassicGenScreen_Layout(void* screen) { - enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); - struct ClassicGenScreen* s = (struct ClassicGenScreen*)screen; Widget_SetLocation(&s->title, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -150); Widget_SetLocation(&s->btns[0], ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -100); Widget_SetLocation(&s->btns[1], ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -50); Widget_SetLocation(&s->btns[2], ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 0); Widget_SetLocation(&s->cancel, ANCHOR_CENTRE, ANCHOR_MAX, 0, 80); - - Window_3DS_SetRenderScreen(scr); } static void ClassicGenScreen_Init(void* screen) { @@ -1570,8 +1538,6 @@ static void SaveLevelScreen_Update(void* screen, double delta) { } static void SaveLevelScreen_Layout(void* screen) { - enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); - struct SaveLevelScreen* s = (struct SaveLevelScreen*)screen; Widget_SetLocation(&s->input, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -30); Widget_SetLocation(&s->save, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 20); @@ -1579,8 +1545,6 @@ static void SaveLevelScreen_Layout(void* screen) { Widget_SetLocation(&s->file, ANCHOR_CENTRE, ANCHOR_MAX, 0, 70); Menu_LayoutBack(&s->cancel); - - Window_3DS_SetRenderScreen(scr); } static void SaveLevelScreen_Init(void* screen) { @@ -1913,14 +1877,10 @@ static void BindsSourceScreen_ContextRecreated(void* screen) { } static void BindsSourceScreen_Layout(void* screen) { - enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); - struct BindsSourceScreen* s = (struct BindsSourceScreen*)screen; Widget_SetLocation(&s->btns[0], ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -25); Widget_SetLocation(&s->btns[1], ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 25); Menu_LayoutBack(&s->cancel); - - Window_3DS_SetRenderScreen(scr); } static void BindsSourceScreen_Init(void* screen) { @@ -2068,8 +2028,6 @@ static void KeyBindsScreen_ContextRecreated(void* screen) { } static void KeyBindsScreen_Layout(void* screen) { - enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); - struct KeyBindsScreen* s = (struct KeyBindsScreen*)screen; int i, x, y, xDir, leftLen; x = s->btnWidth / 2 + 5; @@ -2090,8 +2048,6 @@ static void KeyBindsScreen_Layout(void* screen) { Widget_SetLocation(&s->left, ANCHOR_CENTRE, ANCHOR_CENTRE, -s->btnWidth - 35, s->arrowsY); Widget_SetLocation(&s->right, ANCHOR_CENTRE, ANCHOR_CENTRE, s->btnWidth + 35, s->arrowsY); - - Window_3DS_SetRenderScreen(scr); } static void KeyBindsScreen_Init(void* screen) { @@ -2373,8 +2329,6 @@ static void MenuInputOverlay_Free(void* screen) { } static void MenuInputOverlay_Layout(void* screen) { - enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); - struct MenuInputOverlay* s = (struct MenuInputOverlay*)screen; if (!Input_TouchMode) { Widget_SetLocation(&s->input, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 110); @@ -2389,8 +2343,6 @@ static void MenuInputOverlay_Layout(void* screen) { Widget_SetLocation(&s->ok, ANCHOR_CENTRE, ANCHOR_CENTRE, 120, 150); Widget_SetLocation(&s->Default, ANCHOR_CENTRE, ANCHOR_CENTRE, -120, 150); } - - Window_3DS_SetRenderScreen(scr); } static void MenuInputOverlay_ContextLost(void* screen) { @@ -2692,14 +2644,10 @@ static void MenuOptionsScreen_Free(void* screen) { } static void MenuOptionsScreen_Layout(void* screen) { - enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); - struct MenuOptionsScreen* s = (struct MenuOptionsScreen*)screen; Screen_Layout(s); Menu_LayoutBack(&s->done); MenuOptionsScreen_LayoutExtHelp(s); - - Window_3DS_SetRenderScreen(scr); } static void MenuOptionsScreen_ContextLost(void* screen) { @@ -3389,15 +3337,11 @@ static void NostalgiaMenuScreen_ContextRecreated(void* screen) { } static void NostalgiaMenuScreen_Layout(void* screen) { - enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); - struct NostalgiaMenuScreen* s = (struct NostalgiaMenuScreen*)screen; Widget_SetLocation(&s->title, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -100); Widget_SetLocation(&s->btnA, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, -25); Widget_SetLocation(&s->btnF, ANCHOR_CENTRE, ANCHOR_CENTRE, 0, 25); Menu_LayoutBack(&s->done); - - Window_3DS_SetRenderScreen(scr); } static void NostalgiaMenuScreen_Init(void* screen) { @@ -4149,15 +4093,11 @@ static void TouchOnscreenScreen_ContextRecreated(void* screen) { } static void TouchOnscreenScreen_Layout(void* screen) { - enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); - struct TouchOnscreenScreen* s = (struct TouchOnscreenScreen*)screen; Menu_LayoutButtons(s->btns, s->btnDescs, ONSCREEN_PAGE_BTNS); Menu_LayoutBack(&s->back); Widget_SetLocation(&s->left, ANCHOR_CENTRE, ANCHOR_CENTRE, -260, 0); Widget_SetLocation(&s->right, ANCHOR_CENTRE, ANCHOR_CENTRE, 260, 0); - - Window_3DS_SetRenderScreen(scr); } static void TouchOnscreenScreen_Init(void* screen) { @@ -4330,13 +4270,9 @@ static void TouchCtrlsScreen_ContextRecreated(void* screen) { } static void TouchCtrlsScreen_Layout(void* screen) { - enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); - struct TouchCtrlsScreen* s = (struct TouchCtrlsScreen*)screen; Menu_LayoutButtons(s->btns, touchCtrls_btns, TOUCHCTRLS_BTNS); Menu_LayoutBack(&s->back); - - Window_3DS_SetRenderScreen(scr); } static void TouchCtrlsScreen_Init(void* screen) { @@ -4428,13 +4364,9 @@ static void TouchMoreScreen_ContextRecreated(void* screen) { } static void TouchMoreScreen_Layout(void* screen) { - enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); - struct TouchMoreScreen* s = (struct TouchMoreScreen*)screen; Menu_LayoutButtons(s->btns, touchMore_btns, TOUCHMORE_BTNS); Menu_LayoutBack(&s->back); - - Window_3DS_SetRenderScreen(scr); } static void TouchMoreScreen_Init(void* screen) { diff --git a/src/Screens.c b/src/Screens.c index d4b2eb9b9..a85f8a3c0 100644 --- a/src/Screens.c +++ b/src/Screens.c @@ -203,13 +203,10 @@ static void HUDScreen_ContextRecreated(void* screen) { static int HUDScreen_LayoutHotbar(void) { enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); - struct HUDScreen* s = &HUDScreen_Instance; s->hotbar.scale = Gui_GetHotbarScale(); Widget_Layout(&s->hotbar); - Window_3DS_SetRenderScreen(scr); - return s->hotbar.height; } @@ -342,6 +339,8 @@ static void HUDScreen_BuildCrosshairsMesh(struct VertexTextured** ptr) { static struct Texture tex = { 0, Tex_Rect(0,0,0,0), Tex_UV(0.0f,0.0f, 15/256.0f,15/256.0f) }; int extent; + enum Screen3DS scr = Window_3DS_SetRenderScreen(TOP_SCREEN); + extent = (int)(CH_EXTENT * Gui_Scale(WindowInfo.Height / 480.0f)); tex.ID = Gui.IconsTex; tex.x = (WindowInfo.Width / 2) - extent; @@ -350,6 +349,8 @@ static void HUDScreen_BuildCrosshairsMesh(struct VertexTextured** ptr) { tex.Width = extent * 2; tex.Height = extent * 2; Gfx_Make2DQuad(&tex, PACKEDCOL_WHITE, ptr); + + Window_3DS_SetRenderScreen(scr); } static void HUDScreen_BuildMesh(void* screen) { @@ -374,6 +375,8 @@ static void HUDScreen_Render(void* screen, double delta) { struct HUDScreen* s = (struct HUDScreen*)screen; if (Game_HideGui) return; + enum Screen3DS scr = Window_3DS_SetRenderScreen(TOP_SCREEN); + Gfx_SetVertexFormat(VERTEX_FORMAT_TEXTURED); Gfx_BindDynamicVb(s->vb); if (Gui.ShowFPS) Widget_Render2(&s->line1, 4); @@ -387,16 +390,18 @@ static void HUDScreen_Render(void* screen, double delta) { /* TODO swap these two lines back */ } - if (Gui_GetBlocksWorld()) return; + if (!Gui_GetBlocksWorld()) { + Gfx_BindDynamicVb(s->vb); + Widget_Render2(&s->hotbar, 12); - Gfx_BindDynamicVb(s->vb); - Widget_Render2(&s->hotbar, 12); - - if (Gui.IconsTex && !tablist_active) { - Gfx_BindTexture(Gui.IconsTex); - Gfx_BindDynamicVb(s->vb); /* Have to rebind for mobile right now... */ - Gfx_DrawVb_IndexedTris(4); + if (Gui.IconsTex && !tablist_active) { + Gfx_BindTexture(Gui.IconsTex); + Gfx_BindDynamicVb(s->vb); /* Have to rebind for mobile right now... */ + Gfx_DrawVb_IndexedTris(4); + } } + + Window_3DS_SetRenderScreen(scr); } static const struct ScreenVTABLE HUDScreen_VTABLE = { @@ -1224,6 +1229,8 @@ static void ChatScreen_BuildMesh(void* screen) { } static void ChatScreen_Layout(void* screen) { + enum Screen3DS scr = Window_3DS_SetRenderScreen(TOP_SCREEN); + struct ChatScreen* s = (struct ChatScreen*)screen; if (ChatScreen_ChatUpdateFont(s)) ChatScreen_Redraw(s); @@ -1265,6 +1272,8 @@ static void ChatScreen_Layout(void* screen) { Widget_SetLocation(&s->more, ANCHOR_MAX, ANCHOR_MIN, 10, 110); } #endif + + Window_3DS_SetRenderScreen(scr); } static int ChatScreen_KeyPress(void* screen, char keyChar) { @@ -1462,17 +1471,19 @@ static void ChatScreen_Init(void* screen) { static void ChatScreen_Render(void* screen, double delta) { struct ChatScreen* s = (struct ChatScreen*)screen; + enum Screen3DS scr = Window_3DS_SetRenderScreen(TOP_SCREEN); if (Game_HideGui && s->grabsInput) { Elem_Render(&s->input.base, delta); } - if (Game_HideGui) return; + if (!Game_HideGui) { + if (s->grabsInput && !Gui.ClassicChat) { + ChatScreen_DrawChatBackground(s); + } - if (s->grabsInput && !Gui.ClassicChat) { - ChatScreen_DrawChatBackground(s); + ChatScreen_DrawChat(s, delta); } - - ChatScreen_DrawChat(s, delta); + Window_3DS_SetRenderScreen(scr); } static void ChatScreen_Free(void* screen) { @@ -2314,10 +2325,7 @@ static void TouchScreen_ContextRecreated(void* screen) { static void TouchScreen_Render(void* screen, double delta) { if (Gui.InputGrab) return; - - enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); Screen_Render2Widgets(screen, delta); - Window_3DS_SetRenderScreen(scr); } static int TouchScreen_PointerDown(void* screen, int id, int x, int y) { @@ -2362,8 +2370,6 @@ static void TouchScreen_PointerUp(void* screen, int id, int x, int y) { } static void TouchScreen_Layout(void* screen) { - enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); - struct TouchScreen* s = (struct TouchScreen*)screen; const struct TouchButtonDesc* desc; float scale = Gui.RawTouchScale; @@ -2400,8 +2406,6 @@ static void TouchScreen_Layout(void* screen) { s->thumbstick.yOffset += height; s->thumbstick.scale = scale; Widget_Layout(&s->thumbstick); - - Window_3DS_SetRenderScreen(scr); } struct LocalPlayerInput touchInput; @@ -2410,8 +2414,6 @@ static void TouchScreen_GetMovement(float* xMoving, float* zMoving) { } static void TouchScreen_Init(void* screen) { - enum Screen3DS scr = Window_3DS_SetRenderScreen(BOTTOM_SCREEN); - struct TouchScreen* s = (struct TouchScreen*)screen; s->widgets = touch_widgets; @@ -2427,8 +2429,6 @@ static void TouchScreen_Init(void* screen) { ThumbstickWidget_Init(&s->thumbstick); touchInput.GetMovement = TouchScreen_GetMovement; LocalPlayer_Instance.input.next = &touchInput; - - Window_3DS_SetRenderScreen(scr); } static void TouchScreen_Free(void* s) {