Skip to content

Commit

Permalink
input: Add option to make show screen button a toggle (#1383)
Browse files Browse the repository at this point in the history
  • Loading branch information
goeiecool9999 authored Oct 18, 2024
1 parent d657545 commit f9a4b2d
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/Cafe/CafeSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ void cemu_initForGame()
// replace any known function signatures with our HLE implementations and patch bugs in the games
GamePatch_scan();
}
LatteGPUState.alwaysDisplayDRC = ActiveSettings::DisplayDRCEnabled();
LatteGPUState.isDRCPrimary = ActiveSettings::DisplayDRCEnabled();
InfoLog_PrintActiveSettings();
Latte_Start();
// check for debugger entrypoint bp
Expand Down
2 changes: 1 addition & 1 deletion src/Cafe/HW/Latte/Core/Latte.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct LatteGPUState_t
uint32 gx2InitCalled; // incremented every time GX2Init() is called
// OpenGL control
uint32 glVendor; // GLVENDOR_*
bool alwaysDisplayDRC = false;
bool isDRCPrimary = false;
// temporary (replace with proper solution later)
bool tvBufferUsesSRGB;
bool drcBufferUsesSRGB;
Expand Down
47 changes: 19 additions & 28 deletions src/Cafe/HW/Latte/Core/LatteRenderTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -989,8 +989,6 @@ void LatteRenderTarget_copyToBackbuffer(LatteTextureView* textureView, bool isPa
g_renderer->ImguiEnd();
}

bool ctrlTabHotkeyPressed = false;

void LatteRenderTarget_itHLECopyColorBufferToScanBuffer(MPTR colorBufferPtr, uint32 colorBufferWidth, uint32 colorBufferHeight, uint32 colorBufferSliceIndex, uint32 colorBufferFormat, uint32 colorBufferPitch, Latte::E_HWTILEMODE colorBufferTilemode, uint32 colorBufferSwizzle, uint32 renderTarget)
{
cemu_assert_debug(colorBufferSliceIndex == 0); // todo - support for non-zero slice
Expand All @@ -1000,38 +998,31 @@ void LatteRenderTarget_itHLECopyColorBufferToScanBuffer(MPTR colorBufferPtr, uin
return;
}

auto getVPADScreenActive = [](size_t n) -> std::pair<bool, bool> {
auto controller = InputManager::instance().get_vpad_controller(n);
if (!controller)
return {false,false};
auto pressed = controller->is_screen_active();
auto toggle = controller->is_screen_active_toggle();
return {pressed && !toggle, pressed && toggle};
};

const bool tabPressed = gui_isKeyDown(PlatformKeyCodes::TAB);
const bool ctrlPressed = gui_isKeyDown(PlatformKeyCodes::LCONTROL);
const auto [vpad0Active, vpad0Toggle] = getVPADScreenActive(0);
const auto [vpad1Active, vpad1Toggle] = getVPADScreenActive(1);

bool showDRC = swkbd_hasKeyboardInputHook() == false && tabPressed;
bool& alwaysDisplayDRC = LatteGPUState.alwaysDisplayDRC;
const bool altScreenRequested = (!ctrlPressed && tabPressed) || vpad0Active || vpad1Active;
const bool togglePressed = (ctrlPressed && tabPressed) || vpad0Toggle || vpad1Toggle;
static bool togglePressedLast = false;

if (ctrlPressed && tabPressed)
{
if (ctrlTabHotkeyPressed == false)
{
alwaysDisplayDRC = !alwaysDisplayDRC;
ctrlTabHotkeyPressed = true;
}
}
else
ctrlTabHotkeyPressed = false;
bool& isDRCPrimary = LatteGPUState.isDRCPrimary;

if (alwaysDisplayDRC)
showDRC = !tabPressed;
if(togglePressed && !togglePressedLast)
isDRCPrimary = !isDRCPrimary;
togglePressedLast = togglePressed;

if (!showDRC)
{
auto controller = InputManager::instance().get_vpad_controller(0);
if (controller && controller->is_screen_active())
showDRC = true;
if (!showDRC)
{
controller = InputManager::instance().get_vpad_controller(1);
if (controller && controller->is_screen_active())
showDRC = true;
}
}
bool showDRC = swkbd_hasKeyboardInputHook() == false && (isDRCPrimary ^ altScreenRequested);

if ((renderTarget & RENDER_TARGET_DRC) && g_renderer->IsPadWindowActive())
LatteRenderTarget_copyToBackbuffer(texView, true);
Expand Down
24 changes: 23 additions & 1 deletion src/gui/input/panels/VPADInputPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <wx/statline.h>
#include <wx/textctrl.h>
#include <wx/slider.h>
#include <wx/checkbox.h>


#include "gui/helpers/wxControlObject.h"
Expand Down Expand Up @@ -131,11 +132,23 @@ VPADInputPanel::VPADInputPanel(wxWindow* parent)
}

// Blow Mic
row = 9;
row = 8;
add_button_row(main_sizer, row, column, VPADController::kButtonId_Mic, _("blow mic"));
row++;

add_button_row(main_sizer, row, column, VPADController::kButtonId_Screen, _("show screen"));
row++;

auto toggleScreenText = new wxStaticText(this, wxID_ANY, _("toggle screen"));
main_sizer->Add(toggleScreenText,
wxGBPosition(row, column),
wxDefaultSpan,
wxALL | wxALIGN_CENTER_VERTICAL, 5);
m_togglePadViewCheckBox = new wxCheckBox(this, wxID_ANY, {}, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
wxString toggleScreenTT = _("Makes the \"show screen\" button toggle between the TV and gamepad screens");
m_togglePadViewCheckBox->SetToolTip(toggleScreenTT);
toggleScreenText->SetToolTip(toggleScreenTT);
main_sizer->Add(m_togglePadViewCheckBox, wxGBPosition(row,column+1), wxDefaultSpan, wxALL | wxEXPAND, 5);

//////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -168,6 +181,8 @@ void VPADInputPanel::on_timer(const EmulatedControllerPtr& emulated_controller,
{
InputPanel::on_timer(emulated_controller, controller_base);

static_cast<VPADController*>(emulated_controller.get())->set_screen_toggle(m_togglePadViewCheckBox->GetValue());

if(emulated_controller)
{
const auto axis = emulated_controller->get_axis();
Expand All @@ -182,3 +197,10 @@ void VPADInputPanel::OnVolumeChange(wxCommandEvent& event)
{

}
void VPADInputPanel::load_controller(const EmulatedControllerPtr& controller)
{
InputPanel::load_controller(controller);

const bool isToggle = static_cast<VPADController*>(controller.get())->is_screen_active_toggle();
m_togglePadViewCheckBox->SetValue(isToggle);
}
3 changes: 3 additions & 0 deletions src/gui/input/panels/VPADInputPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
#include "gui/input/panels/InputPanel.h"

class wxInputDraw;
class wxCheckBox;

class VPADInputPanel : public InputPanel
{
public:
VPADInputPanel(wxWindow* parent);

void on_timer(const EmulatedControllerPtr& emulated_controller, const ControllerPtr& controller) override;
virtual void load_controller(const EmulatedControllerPtr& controller) override;

private:
void OnVolumeChange(wxCommandEvent& event);

wxInputDraw* m_left_draw, * m_right_draw;
wxCheckBox* m_togglePadViewCheckBox;

void add_button_row(wxGridBagSizer *sizer, sint32 row, sint32 column, const VPADController::ButtonId &button_id);
void add_button_row(wxGridBagSizer *sizer, sint32 row, sint32 column, const VPADController::ButtonId &button_id, const wxString &label);
Expand Down
11 changes: 11 additions & 0 deletions src/input/emulated/VPADController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,3 +686,14 @@ bool VPADController::set_default_mapping(const std::shared_ptr<ControllerBase>&

return mapping_updated;
}

void VPADController::load(const pugi::xml_node& node)
{
if (const auto value = node.child("toggle_display"))
m_screen_active_toggle = ConvertString<bool>(value.child_value());
}

void VPADController::save(pugi::xml_node& node)
{
node.append_child("toggle_display").append_child(pugi::node_pcdata).set_value(fmt::format("{}", (int)m_screen_active_toggle).c_str());
}
6 changes: 6 additions & 0 deletions src/input/emulated/VPADController.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class VPADController : public EmulatedController

bool is_mic_active() { return m_mic_active; }
bool is_screen_active() { return m_screen_active; }
bool is_screen_active_toggle() { return m_screen_active_toggle; }
void set_screen_toggle(bool toggle) {m_screen_active_toggle = toggle;}

static std::string_view get_button_name(ButtonId id);

Expand All @@ -86,9 +88,13 @@ class VPADController : public EmulatedController

bool set_default_mapping(const std::shared_ptr<ControllerBase>& controller) override;

void load(const pugi::xml_node& node) override;
void save(pugi::xml_node& node) override;

private:
bool m_mic_active = false;
bool m_screen_active = false;
bool m_screen_active_toggle = false;
uint32be m_last_holdvalue = 0;

std::chrono::high_resolution_clock::time_point m_last_hold_change{}, m_last_pulse{};
Expand Down

0 comments on commit f9a4b2d

Please sign in to comment.