Browse Source

Round the rectangle size to prevent float to int casting issues

And other minor style changes
nce_cpp
James Rowe 9 years ago
parent
commit
48d64ccad5
  1. 6
      src/common/framebuffer_layout.cpp
  2. 5
      src/common/framebuffer_layout.h
  3. 4
      src/common/math_util.h

6
src/common/framebuffer_layout.cpp

@ -14,8 +14,6 @@ static const float TOP_SCREEN_ASPECT_RATIO =
static_cast<float>(VideoCore::kScreenTopHeight) / VideoCore::kScreenTopWidth; static_cast<float>(VideoCore::kScreenTopHeight) / VideoCore::kScreenTopWidth;
static const float BOT_SCREEN_ASPECT_RATIO = static const float BOT_SCREEN_ASPECT_RATIO =
static_cast<float>(VideoCore::kScreenBottomHeight) / VideoCore::kScreenBottomWidth; static_cast<float>(VideoCore::kScreenBottomHeight) / VideoCore::kScreenBottomWidth;
static const float BOT_TO_TOP_SCREEN_RATIO_DIFFERENCE =
BOT_SCREEN_ASPECT_RATIO - TOP_SCREEN_ASPECT_RATIO;
// Finds the largest size subrectangle contained in window area that is confined to the aspect ratio // Finds the largest size subrectangle contained in window area that is confined to the aspect ratio
template <class T> template <class T>
@ -23,8 +21,8 @@ static MathUtil::Rectangle<T> maxRectangle(MathUtil::Rectangle<T> window_area,
float screen_aspect_ratio) { float screen_aspect_ratio) {
float scale = std::min(static_cast<float>(window_area.GetWidth()), float scale = std::min(static_cast<float>(window_area.GetWidth()),
window_area.GetHeight() / screen_aspect_ratio); window_area.GetHeight() / screen_aspect_ratio);
return MathUtil::Rectangle<T>{0, 0, static_cast<T>(scale),
static_cast<T>(scale * screen_aspect_ratio)};
return MathUtil::Rectangle<T>{0, 0, static_cast<T>(std::round(scale)),
static_cast<T>(std::round(scale * screen_aspect_ratio))};
} }
FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height, bool swapped) { FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height, bool swapped) {

5
src/common/framebuffer_layout.h

@ -20,14 +20,16 @@ struct FramebufferLayout {
* Factory method for constructing a default FramebufferLayout * Factory method for constructing a default FramebufferLayout
* @param width Window framebuffer width in pixels * @param width Window framebuffer width in pixels
* @param height Window framebuffer height in pixels * @param height Window framebuffer height in pixels
* @param is_swapped if true, the bottom screen will be displayed above the top screen
* @return Newly created FramebufferLayout object with default screen regions initialized * @return Newly created FramebufferLayout object with default screen regions initialized
*/ */
FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height, bool is_swapped); FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height, bool is_swapped);
/** /**
* Factory method for constructing a FramebufferLayout with only the top screen
* Factory method for constructing a FramebufferLayout with only the top or bottom screen
* @param width Window framebuffer width in pixels * @param width Window framebuffer width in pixels
* @param height Window framebuffer height in pixels * @param height Window framebuffer height in pixels
* @param is_swapped if true, the bottom screen will be displayed (and the top won't be displayed)
* @return Newly created FramebufferLayout object with default screen regions initialized * @return Newly created FramebufferLayout object with default screen regions initialized
*/ */
FramebufferLayout SingleFrameLayout(unsigned width, unsigned height, bool is_swapped); FramebufferLayout SingleFrameLayout(unsigned width, unsigned height, bool is_swapped);
@ -38,6 +40,7 @@ FramebufferLayout SingleFrameLayout(unsigned width, unsigned height, bool is_swa
* This is useful in particular because it matches well with a 1920x1080 resolution monitor * This is useful in particular because it matches well with a 1920x1080 resolution monitor
* @param width Window framebuffer width in pixels * @param width Window framebuffer width in pixels
* @param height Window framebuffer height in pixels * @param height Window framebuffer height in pixels
* @param is_swapped if true, the bottom screen will be the large display
* @return Newly created FramebufferLayout object with default screen regions initialized * @return Newly created FramebufferLayout object with default screen regions initialized
*/ */
FramebufferLayout LargeFrameLayout(unsigned width, unsigned height, bool is_swapped); FramebufferLayout LargeFrameLayout(unsigned width, unsigned height, bool is_swapped);

4
src/common/math_util.h

@ -45,8 +45,8 @@ struct Rectangle {
return Rectangle{left, top + y, right, bottom + y}; return Rectangle{left, top + y, right, bottom + y};
} }
Rectangle<T> Scale(const float s) const { Rectangle<T> Scale(const float s) const {
return Rectangle{left, top, static_cast<T>((right + left) * s),
static_cast<T>((top + bottom) * s)};
return Rectangle{left, top, static_cast<T>(left + GetWidth() * s),
static_cast<T>(top + GetHeight() * s)};
} }
}; };

Loading…
Cancel
Save