mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-07-11 01:25:07 +02:00
Refactor: Call GetLayoutBounds on the screen instead of the context where possible.
This will allow screens to influence the layout bounds in a unified way
This commit is contained in:
+1
-1
@@ -113,7 +113,7 @@ public:
|
||||
// in dps, like dp_xres and dp_yres
|
||||
void SetBounds(const Bounds &b) { bounds_ = b; }
|
||||
const Bounds &GetBounds() const { return bounds_; }
|
||||
Bounds GetLayoutBounds(bool ignoreBottomInset = false) const;
|
||||
Bounds GetLayoutBounds(bool ignoreBottomInset) const;
|
||||
Draw::DrawContext *GetDrawContext() const { return draw_; }
|
||||
const UI::Theme &GetTheme() const {
|
||||
return *theme;
|
||||
|
||||
@@ -137,9 +137,10 @@ void PopupScreen::CreateViews() {
|
||||
anchor->Overflow(false);
|
||||
root_ = anchor;
|
||||
|
||||
const float ySize = FillVertical() ? dc.GetLayoutBounds().h - 30 : WRAP_CONTENT;
|
||||
const Bounds layoutBounds = GetLayoutBounds(dc);
|
||||
const float ySize = FillVertical() ? layoutBounds.h - 30 : WRAP_CONTENT;
|
||||
|
||||
int y = (dc.GetLayoutBounds().h - RootMargins().vert()) * 0.5f + offsetY_;
|
||||
int y = (layoutBounds.h - RootMargins().vert()) * 0.5f + offsetY_;
|
||||
Centering vCentering = Centering::Vertical;
|
||||
if (alignTop_) {
|
||||
if (GetDeviceOrientation() == DeviceOrientation::Landscape) {
|
||||
@@ -155,12 +156,12 @@ void PopupScreen::CreateViews() {
|
||||
|
||||
AnchorLayoutParams *anchorParams;
|
||||
// NOTE: We purely use the popup width here to decide the type of layout, instead of the device orientation.
|
||||
if (dc.GetLayoutBounds().w < popupWidth + 50) {
|
||||
if (layoutBounds.w < popupWidth + 50) {
|
||||
anchorParams = new AnchorLayoutParams(popupWidth, ySize,
|
||||
10, y, 10, NONE, vCentering);
|
||||
} else {
|
||||
anchorParams = new AnchorLayoutParams(popupWidth, ySize,
|
||||
(dc.GetLayoutBounds().w - RootMargins().horiz()) * 0.5, y, NONE, NONE, vCentering | Centering::Horizontal);
|
||||
(layoutBounds.w - RootMargins().horiz()) * 0.5, y, NONE, NONE, vCentering | Centering::Horizontal);
|
||||
}
|
||||
|
||||
box_ = new LinearLayout(ORIENT_VERTICAL, anchorParams);
|
||||
|
||||
@@ -295,7 +295,7 @@ void ScrollView::Draw(UIContext &dc) {
|
||||
}
|
||||
|
||||
// Same at the bottom.
|
||||
const float y2 = dc.GetLayoutBounds().y2();
|
||||
const float y2 = dc.GetLayoutBounds(false).y2();
|
||||
if (shadows_ && bounds_.y2() < y2 && orientation_ == ORIENT_VERTICAL) {
|
||||
float radius = 20.0f;
|
||||
|
||||
|
||||
@@ -200,6 +200,10 @@ void UIScreen::deviceRestored(Draw::DrawContext *draw) {
|
||||
root_->DeviceRestored(draw);
|
||||
}
|
||||
|
||||
Bounds UIScreen::GetLayoutBounds(UIContext &dc) const {
|
||||
return dc.GetLayoutBounds(ignoreBottomInset_);
|
||||
}
|
||||
|
||||
ScreenRenderFlags UIScreen::render(ScreenRenderMode mode) {
|
||||
DoRecreateViews();
|
||||
|
||||
|
||||
@@ -62,6 +62,8 @@ public:
|
||||
protected:
|
||||
virtual void CreateViews() = 0;
|
||||
|
||||
Bounds GetLayoutBounds(UIContext &dc) const;
|
||||
|
||||
void RecreateViews() override { recreateViews_ = true; }
|
||||
DeviceOrientation GetDeviceOrientation() const;
|
||||
bool IsOnTop() const;
|
||||
|
||||
@@ -900,7 +900,8 @@ void VisualMappingScreen::CreateViews() {
|
||||
leftColumn->Add(new Spacer(new LinearLayoutParams(1.0f)));
|
||||
AddStandardBack(leftColumn);
|
||||
|
||||
Bounds bounds = screenManager()->getUIContext()->GetLayoutBounds();
|
||||
// TODO: Properly use layout instead of querying bounds.
|
||||
Bounds bounds = GetLayoutBounds(*screenManager()->getUIContext());
|
||||
// Account for left side.
|
||||
bounds.w -= leftColumnWidth + 10.0f;
|
||||
|
||||
@@ -1024,7 +1025,7 @@ void VisualMappingScreen::MapNext(bool successive) {
|
||||
HandleKeyMapping(mapping);
|
||||
}, I18NCat::KEYMAPPING);
|
||||
|
||||
Bounds bounds = screenManager()->getUIContext()->GetLayoutBounds();
|
||||
Bounds bounds = screenManager()->getUIContext()->GetLayoutBounds(false);
|
||||
dialog->SetPopupOffset(psp_->GetPopupOffset() * bounds.h);
|
||||
dialog->SetDelay(successive ? 0.5f : 0.1f);
|
||||
screenManager()->push(dialog);
|
||||
|
||||
@@ -142,7 +142,7 @@ void CustomButtonMappingScreen::CreateDialogViews(UI::ViewGroup *parent) {
|
||||
array[i] = (0x01 == ((g_Config.CustomButton[id_].key >> i) & 0x01));
|
||||
|
||||
// TODO: Less hacky layout work
|
||||
const Bounds layoutBounds = screenManager()->getUIContext()->GetLayoutBounds();
|
||||
const Bounds layoutBounds = screenManager()->getUIContext()->GetLayoutBounds(false);
|
||||
leftColumn->Add(new ButtonPreview(g_Config.iTouchButtonStyle == 0 ? customKeyShapes[cfg->shape].i : customKeyShapes[cfg->shape].l,
|
||||
customKeyImages[cfg->image].i, customKeyImages[cfg->image].r, customKeyShapes[cfg->shape].f, customKeyShapes[cfg->shape].r, layoutBounds.x + 62, layoutBounds.y + 102));
|
||||
|
||||
|
||||
+6
-6
@@ -220,26 +220,27 @@ void DrawFramebufferList(UIContext *ctx, GPUDebugInterface *gpu, const Bounds &b
|
||||
}
|
||||
|
||||
void DrawControlMapperOverlay(UIContext *ctx, const Bounds &bounds, const ControlMapper &controlMapper) {
|
||||
DrawControlDebug(ctx, controlMapper, ctx->GetLayoutBounds());
|
||||
DrawControlDebug(ctx, controlMapper, ctx->GetLayoutBounds(false));
|
||||
}
|
||||
|
||||
void DrawDebugOverlay(UIContext *ctx, const Bounds &bounds, DebugOverlay overlay) {
|
||||
bool inGame = GetUIState() == UISTATE_INGAME;
|
||||
|
||||
const Bounds layoutBounds = ctx->GetLayoutBounds(false);
|
||||
switch (overlay) {
|
||||
case DebugOverlay::DEBUG_STATS:
|
||||
if (inGame)
|
||||
DrawDebugStats(ctx, ctx->GetLayoutBounds());
|
||||
DrawDebugStats(ctx, layoutBounds);
|
||||
break;
|
||||
case DebugOverlay::FRAME_GRAPH:
|
||||
if (inGame)
|
||||
DrawFrameTimes(ctx, ctx->GetLayoutBounds());
|
||||
DrawFrameTimes(ctx, layoutBounds);
|
||||
break;
|
||||
case DebugOverlay::FRAME_TIMING:
|
||||
DrawFrameTiming(ctx, ctx->GetLayoutBounds());
|
||||
DrawFrameTiming(ctx, layoutBounds);
|
||||
break;
|
||||
case DebugOverlay::Audio:
|
||||
DrawAudioDebugStats(ctx, ctx->GetLayoutBounds());
|
||||
DrawAudioDebugStats(ctx, layoutBounds);
|
||||
break;
|
||||
#if !PPSSPP_PLATFORM(UWP) && !PPSSPP_PLATFORM(SWITCH)
|
||||
case DebugOverlay::GPU_PROFILE:
|
||||
@@ -262,7 +263,6 @@ void DrawDebugOverlay(UIContext *ctx, const Bounds &bounds, DebugOverlay overlay
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static const char *CPUCoreAsString(int core) {
|
||||
switch (core) {
|
||||
case 0: return "Interpreter";
|
||||
|
||||
+1
-1
@@ -736,7 +736,7 @@ void TouchTestScreen::axis(const AxisInput &axis) {
|
||||
}
|
||||
|
||||
void TouchTestScreen::DrawForeground(UIContext &dc) {
|
||||
Bounds bounds = dc.GetLayoutBounds();
|
||||
Bounds bounds = GetLayoutBounds(dc);
|
||||
|
||||
double now = dc.FrameStartTime();
|
||||
double delta = now - lastFrameTime_;
|
||||
|
||||
+3
-3
@@ -1267,7 +1267,7 @@ void EmuScreen::CreateViews() {
|
||||
|
||||
TouchControlConfig &touch = g_Config.GetTouchControlsConfig(deviceOrientation);
|
||||
|
||||
const Bounds &bounds = screenManager()->getUIContext()->GetLayoutBounds();
|
||||
const Bounds &bounds = GetLayoutBounds(*screenManager()->getUIContext());
|
||||
InitPadLayout(&touch, deviceOrientation, bounds.w, bounds.h);
|
||||
|
||||
root_ = CreatePadLayout(touch, bounds.w, bounds.h, &pauseTrigger_, &g_controlMapper);
|
||||
@@ -1969,10 +1969,10 @@ void EmuScreen::renderUI() {
|
||||
|
||||
if (PSP_IsInited()) {
|
||||
if ((DebugOverlay)g_Config.iDebugOverlay == DebugOverlay::CONTROL) {
|
||||
DrawControlMapperOverlay(ctx, ctx->GetLayoutBounds(), g_controlMapper);
|
||||
DrawControlMapperOverlay(ctx, GetLayoutBounds(*ctx), g_controlMapper);
|
||||
}
|
||||
if (g_Config.iShowStatusFlags) {
|
||||
DrawFPS(ctx, ctx->GetLayoutBounds());
|
||||
DrawFPS(ctx, GetLayoutBounds(*ctx));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -235,6 +235,7 @@ static_assert(Draw::SEM_TEXCOORD0 == 3, "Semantic shader hardcoded in glsl above
|
||||
|
||||
GPUDriverTestScreen::GPUDriverTestScreen() {
|
||||
using namespace Draw;
|
||||
ignoreBottomInset_ = false;
|
||||
}
|
||||
|
||||
GPUDriverTestScreen::~GPUDriverTestScreen() {
|
||||
@@ -466,7 +467,7 @@ void GPUDriverTestScreen::DiscardTest(UIContext &dc) {
|
||||
|
||||
// If everything is OK, both the background and the text should be OK.
|
||||
|
||||
Bounds layoutBounds = dc.GetLayoutBounds();
|
||||
Bounds layoutBounds = GetLayoutBounds(dc);
|
||||
|
||||
dc.Begin();
|
||||
dc.SetFontScale(1.0f, 1.0f);
|
||||
@@ -572,7 +573,7 @@ void GPUDriverTestScreen::ShaderTest(UIContext &dc) {
|
||||
rasterNoCull->Release();
|
||||
}
|
||||
|
||||
Bounds layoutBounds = dc.GetLayoutBounds();
|
||||
Bounds layoutBounds = GetLayoutBounds(dc);
|
||||
|
||||
dc.Begin();
|
||||
dc.SetFontScale(1.0f, 1.0f);
|
||||
|
||||
+1
-1
@@ -419,7 +419,7 @@ void LogoScreen::touch(const TouchInput &touch) {
|
||||
void LogoScreen::DrawForeground(UIContext &dc) {
|
||||
using namespace Draw;
|
||||
|
||||
const Bounds &bounds = dc.GetLayoutBounds();
|
||||
const Bounds &bounds = GetLayoutBounds(dc);
|
||||
|
||||
dc.Begin();
|
||||
|
||||
|
||||
+1
-1
@@ -96,7 +96,7 @@ enum class AfterLogoScreen {
|
||||
MEMSTICK_SCREEN_INITIAL_SETUP,
|
||||
};
|
||||
|
||||
class LogoScreen : public UIScreen {
|
||||
class LogoScreen : public UIBaseScreen {
|
||||
public:
|
||||
LogoScreen(AfterLogoScreen afterLogoScreen = AfterLogoScreen::DEFAULT);
|
||||
|
||||
|
||||
@@ -410,8 +410,7 @@ void OSDOverlayScreen::DrawForeground(UIContext &ui) {
|
||||
|
||||
// Special case control for now, since it uses the control mapper that's owned by EmuScreen.
|
||||
if (debugOverlay != DebugOverlay::OFF && debugOverlay != DebugOverlay::CONTROL) {
|
||||
UIContext *uiContext = screenManager()->getUIContext();
|
||||
DrawDebugOverlay(uiContext, uiContext->GetLayoutBounds(), debugOverlay);
|
||||
DrawDebugOverlay(&ui, GetLayoutBounds(ui), debugOverlay);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,4 +50,3 @@ public:
|
||||
private:
|
||||
OnScreenMessagesView *osmView_ = nullptr;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user