From c1480206a1ca6fd9ca248cbc9dd49a4f26ef24da Mon Sep 17 00:00:00 2001 From: Dimitri Sophinos Date: Wed, 18 Oct 2023 18:36:02 -0400 Subject: [PATCH] draw toggleable keyboard to bottom screen --- .gitignore | 3 +- platform/3ds/Makefile | 6 +-- platform/3ds/gfx/kb_draft.png | Bin 0 -> 1126 bytes platform/3ds/gfx/keyboard.t3s | 2 + platform/3ds/source/3dsHost.cpp | 22 ++++++-- platform/3ds/source/Keyboard.cpp | 85 +++++++++++++++++++++++++++++++ platform/3ds/source/Keyboard.h | 24 +++++++++ 7 files changed, 135 insertions(+), 7 deletions(-) create mode 100644 platform/3ds/gfx/kb_draft.png create mode 100644 platform/3ds/gfx/keyboard.t3s create mode 100644 platform/3ds/source/Keyboard.cpp create mode 100644 platform/3ds/source/Keyboard.h diff --git a/.gitignore b/.gitignore index 21b2f855..f0ded003 100644 --- a/.gitignore +++ b/.gitignore @@ -44,8 +44,9 @@ platform/bittboy/FAKE08 platform/miyoomini/FAKE08 platform/gcw0/FAKE08 platform/gcw0/fake08_gcw0.opk +platform/3ds/romfs/gfx/ source/carts.zip -/platform/windows/*.stackdump +platform/windows/*.stackdump platform/libretro/fake08_libretro.dylib platform/libretro/libs/ platform/libretro/obj/ diff --git a/platform/3ds/Makefile b/platform/3ds/Makefile index 97fbe297..e41ca9c1 100644 --- a/platform/3ds/Makefile +++ b/platform/3ds/Makefile @@ -46,9 +46,9 @@ SOURCES := ${SOURCES} source DATA := data INCLUDES := ${INCLUDES} GRAPHICS := gfx -GFXBUILD := $(BUILD) -#ROMFS := romfs -#GFXBUILD := $(ROMFS)/gfx +#GFXBUILD := $(BUILD) +ROMFS := romfs +GFXBUILD := $(ROMFS)/gfx #--------------------------------------------------------------------------------- # options for code generation diff --git a/platform/3ds/gfx/kb_draft.png b/platform/3ds/gfx/kb_draft.png new file mode 100644 index 0000000000000000000000000000000000000000..8f9dd083e6f563266186bb23cb33219cdb80f28f GIT binary patch literal 1126 zcmV-s1eyDZP)Px#1ZP1_K>z@;j|==^1poj52~bQ_MSy^S00030|NlOvptS%1010qNS#tmY4#NNd z4#NS*Z>VGd00ZVpL_t(|+U=Uba-%Q|hI`q4LopNIdw};LZ=eHu${O1w5|#~ZMK&zf zWExcCFC)p=KZcKH&6+i9)~wn47#Q2fK*8?e?=<|*9I;LuB0BSwObeEia?%vtwJ?NEy|UE%2l6$<)W;d z^=xxF;A}4V7#b0S12^WRmUx;AEuzn>fbmR(2#jYUZxO$n7&ivQ7Xee0Jg}Jh<)>~X zAh^ST(Rbx;Q(mEJ$mT%DqLke*4_O&DsfCUM8p=5^wx+RdfN7D+=Tv}PAE|mE0CBzQ zT?h!8#*8bt_^BuXWMVbrI21TJK<-9u#=yDaDZYvxU zz8bI)vNe#3br2!T(;O4}*|0GOHjVw8kk0^wxNm`c<`i?P+~F1aC<37Y<)WRf;JW%G zzUnuiSizH$WM@7qMC+F7z`h0$fE7i^%2kCnigFwfNlvVr)ONf@FN!@7a^dTW!dD6Tc%X=qYh76f z<^G6X10*9khlU!vI}B(Z@)>|2_bqab$*0~GW2HXd9f;Pz@lljajccz*Xh3B9mPDN~ zaB{{#9E^eEV_*Yolt9Sn6<}u!^eMCj;ymXZ16;WQ75I$k)O$YO$dlI16Bp&GhGwmE!%pif=AQg#FVm6Cuydl3k5CSYc53249uTm#J|ajh-4 zKij~e9E$?{yOo)#0sj-=G*|;&9f;7y&u(C64Fm>E!YGK~9|J#!DsX-%FuVJKy)y<5 z-4oa?eG9-@2lU-Ij9m>lZUW~V(tcp*yA$ZAwB9GB4vZr)=Fm}8Mex|i{t2+#0zPxt zL*GYcEo5sTe51-9ILBKJ`E%E>f&D}`P5fDLF0w3WmFU*%?7w&(c}EdT%j07*qoM6N<$f-o`b5&!@I literal 0 HcmV?d00001 diff --git a/platform/3ds/gfx/keyboard.t3s b/platform/3ds/gfx/keyboard.t3s new file mode 100644 index 00000000..96ccf127 --- /dev/null +++ b/platform/3ds/gfx/keyboard.t3s @@ -0,0 +1,2 @@ +--atlas -f rgba8888 -z none +kb_draft.png diff --git a/platform/3ds/source/3dsHost.cpp b/platform/3ds/source/3dsHost.cpp index 80b88355..9347c93d 100644 --- a/platform/3ds/source/3dsHost.cpp +++ b/platform/3ds/source/3dsHost.cpp @@ -20,6 +20,8 @@ using namespace std; #include "../../../source/PicoRam.h" #include "../../../source/filehelpers.h" +#include "Keyboard.h" + #define SCREEN_WIDTH 400; #define SCREEN_HEIGHT 240; @@ -36,6 +38,7 @@ const int __3ds_TopScreenHeight = SCREEN_HEIGHT; const int __3ds_BottomScreenWidth = SCREEN_2_WIDTH; const int __3ds_BottomScreenHeight = SCREEN_2_HEIGHT; +static Keyboard kb; const int PicoScreenWidth = 128; const int PicoScreenHeight = 128; @@ -321,12 +324,14 @@ void Host::oneTimeSetup(Audio* audio){ } gfxInitDefault(); - //gfxSetWide(consoleModel != 3); + gfxSetWide(consoleModel != 3); //C3D_Init(C3D_DEFAULT_CMDBUF_SIZE); default is 0x40000 C3D_Init(0x10000); //C2D_Init(C2D_DEFAULT_MAX_OBJECTS); //4096 C2D_Init(32); //need very few objects? this probably doesn't really help perf C2D_Prepare(); + + kb.Init(); //the keyboard's texture needs to be loaded *before* the p8 screen is created, otherwise it gets corrupted topTarget = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT); /* @@ -384,6 +389,8 @@ void Host::oneTimeCleanup(){ saveSettingsIni(); audioCleanup(); + + kb.Cleanup(); C3D_TexDelete(pico_tex); @@ -424,6 +431,7 @@ void Host::changeStretch(){ } void Host::forceStretch(StretchOption newStretch) { + kb.UpdateStretch(stretch); setRenderParamsFromStretch(stretch); if (stretch == AltScreenPixelPerfect) { mouseOffsetX = (__3ds_BottomScreenWidth - PicoScreenWidth) / 2; @@ -449,6 +457,12 @@ InputState_t Host::scanInput(){ //Read the touch screen coordinates hidTouchRead(&touch); + + //update keyboard + if(currKDown32 & KEY_X){ + kb.Toggle(); + forceStretch(stretch); + } if (touch.px > 0 && touch.py > 0) { touchLocationX = (touch.px - mouseOffsetX) * scaleX; @@ -634,6 +648,7 @@ void Host::drawFrame(uint8_t* picoFb, uint8_t* screenPaletteMap, uint8_t drawMod C2D_TargetClear(bottomTarget, CLEAR_COLOR); C2D_SceneBegin(bottomTarget); + if (bottomSubTexWidth > 0 && bottomSubTexHeight > 0) { pico_subtex->width = bottomSubTexWidth; @@ -665,10 +680,11 @@ void Host::drawFrame(uint8_t* picoFb, uint8_t* screenPaletteMap, uint8_t drawMod flipHorizontal, flipVertical); } - - //keyboard goes here probably C2D_Flush(); + + kb.Draw(); + C3D_FrameEnd(0); } diff --git a/platform/3ds/source/Keyboard.cpp b/platform/3ds/source/Keyboard.cpp new file mode 100644 index 00000000..d64fa2de --- /dev/null +++ b/platform/3ds/source/Keyboard.cpp @@ -0,0 +1,85 @@ +#include "Keyboard.h" + +#include + +#include "../../source/logger.h" +#include "../../source/host.h" + + +Keyboard::Keyboard(){ + +}; + +void Keyboard::Init(){ + Logger_Write("Initializing keyboard\n"); + + romfsInit(); + spritesheet = C2D_SpriteSheetLoad("romfs:/gfx/keyboard.t3x"); + C2D_SpriteFromSheet(&kbSprite, spritesheet, 0); + C2D_SpriteSetPos(&kbSprite,0,0); + + enabled = false; +} + +void Keyboard::Toggle(){ + enabled = !enabled; + if(enabled){ + + Logger_Write("KB Enabled\n"); + } + else { + Logger_Write("KB Disabled\n"); + } +} + +void Keyboard::UpdateStretch(StretchOption& stretch) { + if(enabled){ + if(!useEnableStretch){ + useEnableStretch = true; + if(enableStretch == AltScreenStretch){ //first time keyboard has changed the stretch, match current stretch + if(stretch == AltScreenPixelPerfect){ + enableStretch = PixelPerfect; + } + else if(stretch == AltScreenStretch){ + enableStretch = StretchToFit; + } + else { + enableStretch = stretch; + } + } + disableStretch = stretch; + stretch = enableStretch; + + } + else { + if(stretch == AltScreenPixelPerfect){ + stretch = PixelPerfect; + } + if(stretch == AltScreenStretch){ + stretch = StretchToFit; + } + } + } + else { + if(useEnableStretch){ + useEnableStretch = false; + if(enableStretch != AltScreenStretch){ + enableStretch = stretch; + stretch = disableStretch; + } + } + } +} + + +void Keyboard::Draw(){ + //Logger_Write("Drawing keyboard\n"); + if(enabled){ + C2D_DrawSprite(&kbSprite); + } + +} + +void Keyboard::Cleanup(){ + C2D_SpriteSheetFree(spritesheet); +} \ No newline at end of file diff --git a/platform/3ds/source/Keyboard.h b/platform/3ds/source/Keyboard.h new file mode 100644 index 00000000..f1bcab24 --- /dev/null +++ b/platform/3ds/source/Keyboard.h @@ -0,0 +1,24 @@ +#pragma once + +#include + +#include "../../source/host.h" + +class Keyboard { + + bool enabled = false; + C2D_SpriteSheet spritesheet; + C2D_Sprite kbSprite; + + bool useEnableStretch = false; + StretchOption disableStretch; + StretchOption enableStretch = AltScreenStretch; + +public: + Keyboard(); + void Init(); + void Toggle(); + void UpdateStretch(StretchOption& stretch); + void Draw(); + void Cleanup(); +}; \ No newline at end of file