Skip to content

Commit

Permalink
draw toggleable keyboard to bottom screen
Browse files Browse the repository at this point in the history
  • Loading branch information
DPS2004 committed Oct 18, 2023
1 parent f5db8c9 commit c148020
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
6 changes: 3 additions & 3 deletions platform/3ds/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Binary file added platform/3ds/gfx/kb_draft.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions platform/3ds/gfx/keyboard.t3s
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--atlas -f rgba8888 -z none
kb_draft.png
22 changes: 19 additions & 3 deletions platform/3ds/source/3dsHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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);
/*
Expand Down Expand Up @@ -384,6 +389,8 @@ void Host::oneTimeCleanup(){
saveSettingsIni();

audioCleanup();

kb.Cleanup();

C3D_TexDelete(pico_tex);

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
85 changes: 85 additions & 0 deletions platform/3ds/source/Keyboard.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include "Keyboard.h"

#include <citro2d.h>

#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);
}
24 changes: 24 additions & 0 deletions platform/3ds/source/Keyboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <citro2d.h>

#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();
};

0 comments on commit c148020

Please sign in to comment.