2018-01-09 19:36:07 -08:00
|
|
|
// Copyright 2018 Yuzu Emulator Team
|
2016-05-02 23:07:17 -07:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-01-11 19:24:09 -08:00
|
|
|
#include <cmath>
|
|
|
|
|
2016-05-02 23:07:17 -07:00
|
|
|
#include "common/assert.h"
|
2017-05-27 16:10:25 -07:00
|
|
|
#include "core/frontend/framebuffer_layout.h"
|
2016-05-02 23:07:17 -07:00
|
|
|
|
|
|
|
namespace Layout {
|
|
|
|
|
2016-11-05 00:47:05 -07:00
|
|
|
// Finds the largest size subrectangle contained in window area that is confined to the aspect ratio
|
|
|
|
template <class T>
|
|
|
|
static MathUtil::Rectangle<T> maxRectangle(MathUtil::Rectangle<T> window_area,
|
|
|
|
float screen_aspect_ratio) {
|
|
|
|
float scale = std::min(static_cast<float>(window_area.GetWidth()),
|
|
|
|
window_area.GetHeight() / screen_aspect_ratio);
|
2016-11-09 23:36:07 -08:00
|
|
|
return MathUtil::Rectangle<T>{0, 0, static_cast<T>(std::round(scale)),
|
|
|
|
static_cast<T>(std::round(scale * screen_aspect_ratio))};
|
2016-05-02 23:07:17 -07:00
|
|
|
}
|
|
|
|
|
2018-01-09 19:36:07 -08:00
|
|
|
FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height) {
|
2016-05-02 23:07:17 -07:00
|
|
|
ASSERT(width > 0);
|
|
|
|
ASSERT(height > 0);
|
2016-11-05 00:47:05 -07:00
|
|
|
// The drawing code needs at least somewhat valid values for both screens
|
|
|
|
// so just calculate them both even if the other isn't showing.
|
2018-01-09 19:36:07 -08:00
|
|
|
FramebufferLayout res{width, height};
|
2016-11-05 00:47:05 -07:00
|
|
|
|
2018-01-09 19:36:07 -08:00
|
|
|
const float emulation_aspect_ratio{static_cast<float>(ScreenUndocked::Height) /
|
|
|
|
ScreenUndocked::Width};
|
2016-11-05 00:47:05 -07:00
|
|
|
MathUtil::Rectangle<unsigned> screen_window_area{0, 0, width, height};
|
2018-01-09 19:36:07 -08:00
|
|
|
MathUtil::Rectangle<unsigned> screen = maxRectangle(screen_window_area, emulation_aspect_ratio);
|
2017-08-25 14:53:07 -07:00
|
|
|
|
|
|
|
float window_aspect_ratio = static_cast<float>(height) / width;
|
|
|
|
|
|
|
|
if (window_aspect_ratio < emulation_aspect_ratio) {
|
2018-01-09 19:36:07 -08:00
|
|
|
screen = screen.TranslateX((screen_window_area.GetWidth() - screen.GetWidth()) / 2);
|
2017-08-25 14:53:07 -07:00
|
|
|
} else {
|
2018-01-09 19:36:07 -08:00
|
|
|
screen = screen.TranslateY((height - screen.GetHeight()) / 2);
|
2017-08-25 14:53:07 -07:00
|
|
|
}
|
2018-01-09 19:36:07 -08:00
|
|
|
res.screen = screen;
|
2017-08-25 14:53:07 -07:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Layout
|