Skip to content

Commit

Permalink
Add single screen layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
Hydr8gon committed May 28, 2024
1 parent b41cb3b commit 1e71088
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 32 deletions.
6 changes: 4 additions & 2 deletions src/android/java/com/hydra/noods/NooRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,10 @@ public void onDrawFrame(GL10 unused)
else
{
// Draw the DS top and bottom screens
drawScreen(getTopX(), getTopY(), getTopWidth(), getTopHeight(), 0.0f, 0.0f, 1.0f, 0.5f);
drawScreen(getBotX(), getBotY(), getBotWidth(), getBotHeight(), 0.0f, 0.5f, 1.0f, 1.0f);
if (SettingsMenu.getScreenArrangement() != 3 || SettingsMenu.getScreenSizing() < 2)
drawScreen(getTopX(), getTopY(), getTopWidth(), getTopHeight(), 0.0f, 0.0f, 1.0f, 0.5f);
if (SettingsMenu.getScreenArrangement() != 3 || SettingsMenu.getScreenSizing() == 2)
drawScreen(getBotX(), getBotY(), getBotWidth(), getBotHeight(), 0.0f, 0.5f, 1.0f, 1.0f);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/android/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<item>Automatic</item>
<item>Vertical</item>
<item>Horizontal</item>
<item>Single Screen</item>
</string-array>

<string-array name="screen_sizing_entries">
Expand Down
24 changes: 12 additions & 12 deletions src/common/screen_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ void ScreenLayout::update(int winWidth, int winHeight, bool gbaMode)
this->winWidth = winWidth;
this->winHeight = winHeight;

if (gbaMode && gbaCrop)
if (screenArrangement == 3 || (gbaMode && gbaCrop)) // Single screen
{
// Determine the screen dimensions based on the current rotation
int width = (screenRotation ? 160 : 240);
int height = (screenRotation ? 240 : 160);
int width = (gbaMode && gbaCrop) ? (screenRotation ? 160 : 240) : (screenRotation ? 192 : 256);
int height = (gbaMode && gbaCrop) ? (screenRotation ? 240 : 160) : (screenRotation ? 256 : 192);

// Set the minimum dimensions for the layout
minWidth = width;
Expand All @@ -71,26 +71,26 @@ void ScreenLayout::update(int winWidth, int winHeight, bool gbaMode)
if (integerScale) scale = (int)scale;

// Calculate the dimensions of the screen
topWidth = scale * width;
topHeight = scale * height;
topWidth = botWidth = scale * width;
topHeight = botHeight = scale * height;

// Position the screen horizontally
if (screenPosition == 3) // Left
topX = 0;
topX = botX = 0;
else if (screenPosition == 4) // Right
topX = winWidth - topWidth;
topX = botX = winWidth - topWidth;
else // Center, Top, Bottom
topX = (winWidth - topWidth) / 2;
topX = botX = (winWidth - topWidth) / 2;

// Position the screen vertically
if (screenPosition == 1) // Top
topY = 0;
topY = botY = 0;
else if (screenPosition == 2) // Bottom
topY = winHeight - topHeight;
topY = botY = winHeight - topHeight;
else // Center, Left, Right
topY = (winHeight - topHeight) / 2;
topY = botY = (winHeight - topHeight) / 2;
}
else // NDS mode
else // Dual screens
{
// Determine the screen arrangement based on the current settings
// In automatic mode, the arrangement is horizontal if rotated and vertical otherwise
Expand Down
24 changes: 15 additions & 9 deletions src/console/console_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ bool ConsoleUI::running;
std::string ConsoleUI::ndsPath, ConsoleUI::gbaPath;
std::string ConsoleUI::basePath, ConsoleUI::curPath;

ScreenLayout ConsoleUI::layout;
uint32_t ConsoleUI::framebuffer[256 * 192 * 8];
ScreenLayout ConsoleUI::layout;
bool ConsoleUI::gbaMode;
bool ConsoleUI::changed;

Expand Down Expand Up @@ -249,14 +249,20 @@ void ConsoleUI::mainLoop(MenuTouch (*specialTouch)(), ScreenLayout *touchLayout)
else // DS mode
{
// Draw the DS top screen
topTexture = createTexture(&framebuffer[0], 256 << shift, 192 << shift);
drawTexture(topTexture, 0, 0, 256 << shift, 192 << shift, layout.topX, layout.topY,
layout.topWidth, layout.topHeight, screenFilter, ScreenLayout::screenRotation);
if (ScreenLayout::screenArrangement != 3 || ScreenLayout::screenSizing < 2)
{
topTexture = createTexture(&framebuffer[0], 256 << shift, 192 << shift);
drawTexture(topTexture, 0, 0, 256 << shift, 192 << shift, layout.topX, layout.topY,
layout.topWidth, layout.topHeight, screenFilter, ScreenLayout::screenRotation);
}

// Draw the DS bottom screen
botTexture = createTexture(&framebuffer[(256 * 192) << (shift * 2)], 256 << shift, 192 << shift);
drawTexture(botTexture, 0, 0, 256 << shift, 192 << shift, layout.botX, layout.botY,
layout.botWidth, layout.botHeight, screenFilter, ScreenLayout::screenRotation);
if (ScreenLayout::screenArrangement != 3 || ScreenLayout::screenSizing == 2)
{
botTexture = createTexture(&framebuffer[(256 * 192) << (shift * 2)], 256 << shift, 192 << shift);
drawTexture(botTexture, 0, 0, 256 << shift, 192 << shift, layout.botX, layout.botY,
layout.botWidth, layout.botHeight, screenFilter, ScreenLayout::screenRotation);
}
}

// Draw the FPS counter if enabled
Expand Down Expand Up @@ -755,7 +761,7 @@ void ConsoleUI::settingsMenu()
const std::vector<std::string> toggle = { "Off", "On" };
const std::vector<std::string> position = { "Center", "Top", "Bottom", "Left", "Right" };
const std::vector<std::string> rotation = { "None", "Clockwise", "Counter-Clockwise" };
const std::vector<std::string> arrangement = { "Automatic", "Vertical", "Horizontal" };
const std::vector<std::string> arrangement = { "Automatic", "Vertical", "Horizontal", "Single Screen" };
const std::vector<std::string> sizing = { "Even", "Enlarge Top", "Enlarge Bottom" };
const std::vector<std::string> gap = { "None", "Quarter", "Half", "Full" };
const std::vector<std::string> theme = { "Dark", "Light" };
Expand Down Expand Up @@ -799,7 +805,7 @@ void ConsoleUI::settingsMenu()
case 4: Settings::highRes3D = (Settings::highRes3D + 1) % 2; break;
case 5: ScreenLayout::screenPosition = (ScreenLayout::screenPosition + 1) % 5; break;
case 6: ScreenLayout::screenRotation = (ScreenLayout::screenRotation + 1) % 3; break;
case 7: ScreenLayout::screenArrangement = (ScreenLayout::screenArrangement + 1) % 3; break;
case 7: ScreenLayout::screenArrangement = (ScreenLayout::screenArrangement + 1) % 4; break;
case 8: ScreenLayout::screenSizing = (ScreenLayout::screenSizing + 1) % 3; break;
case 9: ScreenLayout::screenGap = (ScreenLayout::screenGap + 1) % 4; break;
case 10: ScreenLayout::integerScale = (ScreenLayout::integerScale + 1) % 2; break;
Expand Down
2 changes: 1 addition & 1 deletion src/console/console_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class ConsoleUI
public:
static Core *core;
static bool running;
static uint32_t framebuffer[256 * 192 * 8];
static ScreenLayout layout;
static bool gbaMode;

Expand Down Expand Up @@ -111,7 +112,6 @@ class ConsoleUI

static std::string ndsPath, gbaPath;
static std::string basePath, curPath;
static uint32_t framebuffer[256 * 192 * 8];
static bool changed;

static std::thread *coreThread, *saveThread;
Expand Down
21 changes: 20 additions & 1 deletion src/console/main_wiiu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@
#include <SDL2/SDL.h>

#include "console_ui.h"
#include "../settings.h"

#define MAX_DRAWS 1024
extern const uint8_t shader_wiiu_gsh[];

ScreenLayout gpLayout;
GX2Texture *gpTexture;
int tvWidth, tvHeight;
int bufOffset;
bool firstScreen;
Expand Down Expand Up @@ -72,6 +75,13 @@ void ConsoleUI::endFrame()
WHBGfxFinishRenderDRC();
WHBGfxFinishRender();

// Free the gamepad screen texture if it was overridden
if (gpTexture)
{
destroyTexture(gpTexture);
gpTexture = nullptr;
}

// Reset the frame status
bufOffset = 0;
firstScreen = true;
Expand Down Expand Up @@ -194,12 +204,21 @@ void ConsoleUI::drawTexture(void *texture, float tx, float ty, float tw, float t
GX2SetPixelSampler(&samplers[filter], group.pixelShader->samplerVars[0].location);
GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, 4, 0, 1);

// Override the gamepad screen texture with the other screen in single screen mode
GX2Texture *tempTexture = nullptr;
if (running && tw >= 240 && ScreenLayout::screenArrangement == 3)
{
int shift = Settings::highRes3D;
uint32_t *data = &ConsoleUI::framebuffer[(256 * 192 * (ScreenLayout::screenSizing < 2)) << (shift * 2)];
tempTexture = gpTexture = (GX2Texture*)createTexture(data, 256 << shift, 192 << shift);
}

// Draw a texture on the gamepad
WHBGfxBeginRenderDRC();
GX2RSetAttributeBuffer(&posBuffer, 0, posBuffer.elemSize, bufOffset * 2 + 8 * sizeof(float));
GX2RSetAttributeBuffer(&texBuffer, 1, texBuffer.elemSize, bufOffset);
GX2RSetAttributeBuffer(&colBuffer, 2, colBuffer.elemSize, bufOffset * 2);
GX2SetPixelTexture((GX2Texture*)texture, group.pixelShader->samplerVars[0].location);
GX2SetPixelTexture(tempTexture ? tempTexture : (GX2Texture*)texture, group.pixelShader->samplerVars[0].location);
GX2SetPixelSampler(&samplers[filter], group.pixelShader->samplerVars[0].location);
GX2DrawEx(GX2_PRIMITIVE_MODE_QUADS, 4, 0, 1);

Expand Down
16 changes: 13 additions & 3 deletions src/desktop/layout_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ enum LayoutEvent
ARRANGE_AUTO,
ARRANGE_VERT,
ARRANGE_HORI,
ARRANGE_SING,
SIZE_EVEN,
SIZE_TOP,
SIZE_BOT,
Expand All @@ -59,6 +60,7 @@ EVT_RADIOBUTTON(ROTATE_CCW, LayoutDialog::rotateCcw)
EVT_RADIOBUTTON(ARRANGE_AUTO, LayoutDialog::arrangeAuto)
EVT_RADIOBUTTON(ARRANGE_VERT, LayoutDialog::arrangeVert)
EVT_RADIOBUTTON(ARRANGE_HORI, LayoutDialog::arrangeHori)
EVT_RADIOBUTTON(ARRANGE_SING, LayoutDialog::arrangeSing)
EVT_RADIOBUTTON(SIZE_EVEN, LayoutDialog::sizeEven)
EVT_RADIOBUTTON(SIZE_TOP, LayoutDialog::sizeTop)
EVT_RADIOBUTTON(SIZE_BOT, LayoutDialog::sizeBot)
Expand Down Expand Up @@ -106,21 +108,22 @@ LayoutDialog::LayoutDialog(NooApp *app): wxDialog(nullptr, wxID_ANY, "Screen Lay
wxRadioButton *rotateBtns[3];
wxBoxSizer *rotateSizer = new wxBoxSizer(wxHORIZONTAL);
rotateSizer->Add(new wxStaticText(this, wxID_ANY, "Rotation:", wxDefaultPosition,
wxSize(wxDefaultSize.GetWidth(), size)), 1, wxALIGN_CENTRE | wxRIGHT, size / 8);
wxSize(wxDefaultSize.GetWidth(), size)), 0, wxALIGN_CENTRE | wxRIGHT, size / 8);
rotateSizer->Add(rotateBtns[0] = new wxRadioButton(this, ROTATE_NONE, "None",
wxDefaultPosition, wxDefaultSize, wxRB_GROUP), 0, wxLEFT, size / 8);
rotateSizer->Add(rotateBtns[1] = new wxRadioButton(this, ROTATE_CW, "Clockwise"), 0, wxLEFT, size / 8);
rotateSizer->Add(rotateBtns[2] = new wxRadioButton(this, ROTATE_CCW, "Counter-Clockwise"), 0, wxLEFT, size / 8);

// Set up the arrangement settings
wxRadioButton *arrangeBtns[3];
wxRadioButton *arrangeBtns[4];
wxBoxSizer *arrangeSizer = new wxBoxSizer(wxHORIZONTAL);
arrangeSizer->Add(new wxStaticText(this, wxID_ANY, "Arrangement:", wxDefaultPosition,
wxSize(wxDefaultSize.GetWidth(), size)), 0, wxALIGN_CENTRE | wxRIGHT, size / 8);
arrangeSizer->Add(arrangeBtns[0] = new wxRadioButton(this, ARRANGE_AUTO, "Automatic",
wxDefaultPosition, wxDefaultSize, wxRB_GROUP), 0, wxLEFT, size / 8);
arrangeSizer->Add(arrangeBtns[1] = new wxRadioButton(this, ARRANGE_VERT, "Vertical"), 0, wxLEFT, size / 8);
arrangeSizer->Add(arrangeBtns[2] = new wxRadioButton(this, ARRANGE_HORI, "Horizontal"), 0, wxLEFT, size / 8);
arrangeSizer->Add(arrangeBtns[3] = new wxRadioButton(this, ARRANGE_SING, "Single Screen"), 0, wxLEFT, size / 8);

// Set up the sizing settings
wxRadioButton *sizeBtns[3];
Expand Down Expand Up @@ -155,7 +158,7 @@ LayoutDialog::LayoutDialog(NooApp *app): wxDialog(nullptr, wxID_ANY, "Screen Lay
posBtns[ScreenLayout::screenPosition]->SetValue(true);
if (ScreenLayout::screenRotation < 3)
rotateBtns[ScreenLayout::screenRotation]->SetValue(true);
if (ScreenLayout::screenArrangement < 3)
if (ScreenLayout::screenArrangement < 4)
arrangeBtns[ScreenLayout::screenArrangement]->SetValue(true);
if (ScreenLayout::screenSizing < 3)
sizeBtns[ScreenLayout::screenSizing]->SetValue(true);
Expand Down Expand Up @@ -271,6 +274,13 @@ void LayoutDialog::arrangeHori(wxCommandEvent &event)
app->updateLayouts();
}

void LayoutDialog::arrangeSing(wxCommandEvent &event)
{
// Set the screen arrangement setting to single screen
ScreenLayout::screenArrangement = 3;
app->updateLayouts();
}

void LayoutDialog::sizeEven(wxCommandEvent &event)
{
// Set the screen sizing setting to even
Expand Down
1 change: 1 addition & 0 deletions src/desktop/layout_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class LayoutDialog: public wxDialog
void arrangeAuto(wxCommandEvent &event);
void arrangeVert(wxCommandEvent &event);
void arrangeHori(wxCommandEvent &event);
void arrangeSing(wxCommandEvent &event);
void sizeEven(wxCommandEvent &event);
void sizeTop(wxCommandEvent &event);
void sizeBot(wxCommandEvent &event);
Expand Down
10 changes: 6 additions & 4 deletions src/desktop/noo_canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ void NooCanvas::draw(wxPaintEvent &event)
else
{
// Draw the DS top and bottom screens
drawScreen(layout.topX, layout.topY, layout.topWidth, layout.topHeight,
256 << resShift, 192 << resShift, &framebuffer[0]);
drawScreen(layout.botX, layout.botY, layout.botWidth, layout.botHeight,
256 << resShift, 192 << resShift, &framebuffer[(256 * 192) << (resShift * 2)]);
if (ScreenLayout::screenArrangement != 3 || ScreenLayout::screenSizing < 2)
drawScreen(layout.topX, layout.topY, layout.topWidth, layout.topHeight,
256 << resShift, 192 << resShift, &framebuffer[0]);
if (ScreenLayout::screenArrangement != 3 || ScreenLayout::screenSizing == 2)
drawScreen(layout.botX, layout.botY, layout.botWidth, layout.botHeight,
256 << resShift, 192 << resShift, &framebuffer[(256 * 192) << (resShift * 2)]);
}
}

Expand Down

0 comments on commit 1e71088

Please sign in to comment.