diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/common/common_paths.h | 2 | ||||
| -rw-r--r-- | src/common/emu_window.cpp | 68 | ||||
| -rw-r--r-- | src/common/emu_window.h | 30 | ||||
| -rw-r--r-- | src/common/file_util.cpp | 16 | ||||
| -rw-r--r-- | src/common/file_util.h | 1 | ||||
| -rw-r--r-- | src/common/framebuffer_layout.cpp | 138 | ||||
| -rw-r--r-- | src/common/framebuffer_layout.h | 47 | ||||
| -rw-r--r-- | src/common/logging/backend.cpp | 1 | ||||
| -rw-r--r-- | src/common/logging/log.h | 1 | ||||
| -rw-r--r-- | src/common/math_util.h | 10 | ||||
| -rw-r--r-- | src/common/string_util.cpp | 5 |
12 files changed, 245 insertions, 76 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index aa6eee2a3..74a271f08 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -5,6 +5,7 @@ set(SRCS | |||
| 5 | break_points.cpp | 5 | break_points.cpp |
| 6 | emu_window.cpp | 6 | emu_window.cpp |
| 7 | file_util.cpp | 7 | file_util.cpp |
| 8 | framebuffer_layout.cpp | ||
| 8 | hash.cpp | 9 | hash.cpp |
| 9 | key_map.cpp | 10 | key_map.cpp |
| 10 | logging/filter.cpp | 11 | logging/filter.cpp |
| @@ -35,6 +36,7 @@ set(HEADERS | |||
| 35 | common_types.h | 36 | common_types.h |
| 36 | emu_window.h | 37 | emu_window.h |
| 37 | file_util.h | 38 | file_util.h |
| 39 | framebuffer_layout.h | ||
| 38 | hash.h | 40 | hash.h |
| 39 | key_map.h | 41 | key_map.h |
| 40 | linear_disk_cache.h | 42 | linear_disk_cache.h |
diff --git a/src/common/common_paths.h b/src/common/common_paths.h index a5342a610..37304d236 100644 --- a/src/common/common_paths.h +++ b/src/common/common_paths.h | |||
| @@ -19,7 +19,7 @@ | |||
| 19 | #define EMU_DATA_DIR USER_DIR | 19 | #define EMU_DATA_DIR USER_DIR |
| 20 | #else | 20 | #else |
| 21 | #ifdef _WIN32 | 21 | #ifdef _WIN32 |
| 22 | #define EMU_DATA_DIR "Citra Emulator" | 22 | #define EMU_DATA_DIR "Citra" |
| 23 | #else | 23 | #else |
| 24 | #define EMU_DATA_DIR "citra-emu" | 24 | #define EMU_DATA_DIR "citra-emu" |
| 25 | #endif | 25 | #endif |
diff --git a/src/common/emu_window.cpp b/src/common/emu_window.cpp index 122f1c212..e3a9e08e6 100644 --- a/src/common/emu_window.cpp +++ b/src/common/emu_window.cpp | |||
| @@ -40,7 +40,7 @@ void EmuWindow::CirclePadUpdated(float x, float y) { | |||
| 40 | * @param framebuffer_y Framebuffer y-coordinate to check | 40 | * @param framebuffer_y Framebuffer y-coordinate to check |
| 41 | * @return True if the coordinates are within the touchpad, otherwise false | 41 | * @return True if the coordinates are within the touchpad, otherwise false |
| 42 | */ | 42 | */ |
| 43 | static bool IsWithinTouchscreen(const EmuWindow::FramebufferLayout& layout, unsigned framebuffer_x, | 43 | static bool IsWithinTouchscreen(const Layout::FramebufferLayout& layout, unsigned framebuffer_x, |
| 44 | unsigned framebuffer_y) { | 44 | unsigned framebuffer_y) { |
| 45 | return ( | 45 | return ( |
| 46 | framebuffer_y >= layout.bottom_screen.top && framebuffer_y < layout.bottom_screen.bottom && | 46 | framebuffer_y >= layout.bottom_screen.top && framebuffer_y < layout.bottom_screen.bottom && |
| @@ -89,57 +89,19 @@ void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) { | |||
| 89 | TouchPressed(framebuffer_x, framebuffer_y); | 89 | TouchPressed(framebuffer_x, framebuffer_y); |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | EmuWindow::FramebufferLayout EmuWindow::FramebufferLayout::DefaultScreenLayout(unsigned width, | 92 | void EmuWindow::UpdateCurrentFramebufferLayout(unsigned width, unsigned height) { |
| 93 | unsigned height) { | 93 | Layout::FramebufferLayout layout; |
| 94 | // When hiding the widget, the function receives a size of 0 | 94 | switch (Settings::values.layout_option) { |
| 95 | if (width == 0) | 95 | case Settings::LayoutOption::SingleScreen: |
| 96 | width = 1; | 96 | layout = Layout::SingleFrameLayout(width, height, Settings::values.swap_screen); |
| 97 | if (height == 0) | 97 | break; |
| 98 | height = 1; | 98 | case Settings::LayoutOption::LargeScreen: |
| 99 | 99 | layout = Layout::LargeFrameLayout(width, height, Settings::values.swap_screen); | |
| 100 | EmuWindow::FramebufferLayout res = {width, height, {}, {}}; | 100 | break; |
| 101 | 101 | case Settings::LayoutOption::Default: | |
| 102 | float window_aspect_ratio = static_cast<float>(height) / width; | 102 | default: |
| 103 | float emulation_aspect_ratio = | 103 | layout = Layout::DefaultFrameLayout(width, height, Settings::values.swap_screen); |
| 104 | static_cast<float>(VideoCore::kScreenTopHeight * 2) / VideoCore::kScreenTopWidth; | 104 | break; |
| 105 | |||
| 106 | if (window_aspect_ratio > emulation_aspect_ratio) { | ||
| 107 | // Window is narrower than the emulation content => apply borders to the top and bottom | ||
| 108 | int viewport_height = static_cast<int>(std::round(emulation_aspect_ratio * width)); | ||
| 109 | |||
| 110 | res.top_screen.left = 0; | ||
| 111 | res.top_screen.right = res.top_screen.left + width; | ||
| 112 | res.top_screen.top = (height - viewport_height) / 2; | ||
| 113 | res.top_screen.bottom = res.top_screen.top + viewport_height / 2; | ||
| 114 | |||
| 115 | int bottom_width = static_cast<int>( | ||
| 116 | (static_cast<float>(VideoCore::kScreenBottomWidth) / VideoCore::kScreenTopWidth) * | ||
| 117 | (res.top_screen.right - res.top_screen.left)); | ||
| 118 | int bottom_border = ((res.top_screen.right - res.top_screen.left) - bottom_width) / 2; | ||
| 119 | |||
| 120 | res.bottom_screen.left = bottom_border; | ||
| 121 | res.bottom_screen.right = res.bottom_screen.left + bottom_width; | ||
| 122 | res.bottom_screen.top = res.top_screen.bottom; | ||
| 123 | res.bottom_screen.bottom = res.bottom_screen.top + viewport_height / 2; | ||
| 124 | } else { | ||
| 125 | // Otherwise, apply borders to the left and right sides of the window. | ||
| 126 | int viewport_width = static_cast<int>(std::round(height / emulation_aspect_ratio)); | ||
| 127 | |||
| 128 | res.top_screen.left = (width - viewport_width) / 2; | ||
| 129 | res.top_screen.right = res.top_screen.left + viewport_width; | ||
| 130 | res.top_screen.top = 0; | ||
| 131 | res.top_screen.bottom = res.top_screen.top + height / 2; | ||
| 132 | |||
| 133 | int bottom_width = static_cast<int>( | ||
| 134 | (static_cast<float>(VideoCore::kScreenBottomWidth) / VideoCore::kScreenTopWidth) * | ||
| 135 | (res.top_screen.right - res.top_screen.left)); | ||
| 136 | int bottom_border = ((res.top_screen.right - res.top_screen.left) - bottom_width) / 2; | ||
| 137 | |||
| 138 | res.bottom_screen.left = res.top_screen.left + bottom_border; | ||
| 139 | res.bottom_screen.right = res.bottom_screen.left + bottom_width; | ||
| 140 | res.bottom_screen.top = res.top_screen.bottom; | ||
| 141 | res.bottom_screen.bottom = res.bottom_screen.top + height / 2; | ||
| 142 | } | 105 | } |
| 143 | 106 | NotifyFramebufferLayoutChanged(layout); | |
| 144 | return res; | ||
| 145 | } | 107 | } |
diff --git a/src/common/emu_window.h b/src/common/emu_window.h index 67df63e06..835c4d500 100644 --- a/src/common/emu_window.h +++ b/src/common/emu_window.h | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <tuple> | 7 | #include <tuple> |
| 8 | #include <utility> | 8 | #include <utility> |
| 9 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 10 | #include "common/framebuffer_layout.h" | ||
| 10 | #include "common/math_util.h" | 11 | #include "common/math_util.h" |
| 11 | #include "core/hle/service/hid/hid.h" | 12 | #include "core/hle/service/hid/hid.h" |
| 12 | 13 | ||
| @@ -38,23 +39,6 @@ public: | |||
| 38 | std::pair<unsigned, unsigned> min_client_area_size; | 39 | std::pair<unsigned, unsigned> min_client_area_size; |
| 39 | }; | 40 | }; |
| 40 | 41 | ||
| 41 | /// Describes the layout of the window framebuffer (size and top/bottom screen positions) | ||
| 42 | struct FramebufferLayout { | ||
| 43 | |||
| 44 | /** | ||
| 45 | * Factory method for constructing a default FramebufferLayout | ||
| 46 | * @param width Window framebuffer width in pixels | ||
| 47 | * @param height Window framebuffer height in pixels | ||
| 48 | * @return Newly created FramebufferLayout object with default screen regions initialized | ||
| 49 | */ | ||
| 50 | static FramebufferLayout DefaultScreenLayout(unsigned width, unsigned height); | ||
| 51 | |||
| 52 | unsigned width; | ||
| 53 | unsigned height; | ||
| 54 | MathUtil::Rectangle<unsigned> top_screen; | ||
| 55 | MathUtil::Rectangle<unsigned> bottom_screen; | ||
| 56 | }; | ||
| 57 | |||
| 58 | /// Swap buffers to display the next frame | 42 | /// Swap buffers to display the next frame |
| 59 | virtual void SwapBuffers() = 0; | 43 | virtual void SwapBuffers() = 0; |
| 60 | 44 | ||
| @@ -211,10 +195,16 @@ public: | |||
| 211 | * Gets the framebuffer layout (width, height, and screen regions) | 195 | * Gets the framebuffer layout (width, height, and screen regions) |
| 212 | * @note This method is thread-safe | 196 | * @note This method is thread-safe |
| 213 | */ | 197 | */ |
| 214 | const FramebufferLayout& GetFramebufferLayout() const { | 198 | const Layout::FramebufferLayout& GetFramebufferLayout() const { |
| 215 | return framebuffer_layout; | 199 | return framebuffer_layout; |
| 216 | } | 200 | } |
| 217 | 201 | ||
| 202 | /** | ||
| 203 | * Convenience method to update the current frame layout | ||
| 204 | * Read from the current settings to determine which layout to use. | ||
| 205 | */ | ||
| 206 | void UpdateCurrentFramebufferLayout(unsigned width, unsigned height); | ||
| 207 | |||
| 218 | protected: | 208 | protected: |
| 219 | EmuWindow() { | 209 | EmuWindow() { |
| 220 | // TODO: Find a better place to set this. | 210 | // TODO: Find a better place to set this. |
| @@ -250,7 +240,7 @@ protected: | |||
| 250 | * Update framebuffer layout with the given parameter. | 240 | * Update framebuffer layout with the given parameter. |
| 251 | * @note EmuWindow implementations will usually use this in window resize event handlers. | 241 | * @note EmuWindow implementations will usually use this in window resize event handlers. |
| 252 | */ | 242 | */ |
| 253 | void NotifyFramebufferLayoutChanged(const FramebufferLayout& layout) { | 243 | void NotifyFramebufferLayoutChanged(const Layout::FramebufferLayout& layout) { |
| 254 | framebuffer_layout = layout; | 244 | framebuffer_layout = layout; |
| 255 | } | 245 | } |
| 256 | 246 | ||
| @@ -274,7 +264,7 @@ private: | |||
| 274 | // By default, ignore this request and do nothing. | 264 | // By default, ignore this request and do nothing. |
| 275 | } | 265 | } |
| 276 | 266 | ||
| 277 | FramebufferLayout framebuffer_layout; ///< Current framebuffer layout | 267 | Layout::FramebufferLayout framebuffer_layout; ///< Current framebuffer layout |
| 278 | 268 | ||
| 279 | unsigned client_area_width; ///< Current client width, should be set by window impl. | 269 | unsigned client_area_width; ///< Current client width, should be set by window impl. |
| 280 | unsigned client_area_height; ///< Current client height, should be set by window impl. | 270 | unsigned client_area_height; ///< Current client height, should be set by window impl. |
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 407ed047a..413a8e7e5 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp | |||
| @@ -26,6 +26,9 @@ | |||
| 26 | #define stat _stat64 | 26 | #define stat _stat64 |
| 27 | #define fstat _fstat64 | 27 | #define fstat _fstat64 |
| 28 | #define fileno _fileno | 28 | #define fileno _fileno |
| 29 | // Windows version, at least Vista is required to obtain AppData Path | ||
| 30 | #define WINVER 0x0600 | ||
| 31 | #define _WIN32_WINNT 0x0600 | ||
| 29 | #else | 32 | #else |
| 30 | #ifdef __APPLE__ | 33 | #ifdef __APPLE__ |
| 31 | #include <sys/param.h> | 34 | #include <sys/param.h> |
| @@ -594,6 +597,15 @@ std::string& GetExeDirectory() { | |||
| 594 | } | 597 | } |
| 595 | return exe_path; | 598 | return exe_path; |
| 596 | } | 599 | } |
| 600 | |||
| 601 | std::string AppDataRoamingDirectory() { | ||
| 602 | PWSTR pw_local_path = nullptr; | ||
| 603 | // Only supported by Windows Vista or later | ||
| 604 | SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, nullptr, &pw_local_path); | ||
| 605 | std::string local_path = Common::UTF16ToUTF8(pw_local_path); | ||
| 606 | CoTaskMemFree(pw_local_path); | ||
| 607 | return local_path; | ||
| 608 | } | ||
| 597 | #else | 609 | #else |
| 598 | /** | 610 | /** |
| 599 | * @return The user’s home directory on POSIX systems | 611 | * @return The user’s home directory on POSIX systems |
| @@ -671,6 +683,10 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string& new | |||
| 671 | if (paths[D_USER_IDX].empty()) { | 683 | if (paths[D_USER_IDX].empty()) { |
| 672 | #ifdef _WIN32 | 684 | #ifdef _WIN32 |
| 673 | paths[D_USER_IDX] = GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP; | 685 | paths[D_USER_IDX] = GetExeDirectory() + DIR_SEP USERDATA_DIR DIR_SEP; |
| 686 | if (!FileUtil::IsDirectory(paths[D_USER_IDX])) { | ||
| 687 | paths[D_USER_IDX] = AppDataRoamingDirectory() + DIR_SEP EMU_DATA_DIR DIR_SEP; | ||
| 688 | } | ||
| 689 | |||
| 674 | paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP; | 690 | paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP; |
| 675 | paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP; | 691 | paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP; |
| 676 | #else | 692 | #else |
diff --git a/src/common/file_util.h b/src/common/file_util.h index 204b06f14..ac58607c5 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h | |||
| @@ -154,6 +154,7 @@ std::string GetBundleDirectory(); | |||
| 154 | 154 | ||
| 155 | #ifdef _WIN32 | 155 | #ifdef _WIN32 |
| 156 | std::string& GetExeDirectory(); | 156 | std::string& GetExeDirectory(); |
| 157 | std::string AppDataRoamingDirectory(); | ||
| 157 | #endif | 158 | #endif |
| 158 | 159 | ||
| 159 | size_t WriteStringToFile(bool text_file, const std::string& str, const char* filename); | 160 | size_t WriteStringToFile(bool text_file, const std::string& str, const char* filename); |
diff --git a/src/common/framebuffer_layout.cpp b/src/common/framebuffer_layout.cpp new file mode 100644 index 000000000..46c008d9c --- /dev/null +++ b/src/common/framebuffer_layout.cpp | |||
| @@ -0,0 +1,138 @@ | |||
| 1 | // Copyright 2016 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <cmath> | ||
| 6 | |||
| 7 | #include "common/assert.h" | ||
| 8 | #include "common/framebuffer_layout.h" | ||
| 9 | #include "video_core/video_core.h" | ||
| 10 | |||
| 11 | namespace Layout { | ||
| 12 | |||
| 13 | static const float TOP_SCREEN_ASPECT_RATIO = | ||
| 14 | static_cast<float>(VideoCore::kScreenTopHeight) / VideoCore::kScreenTopWidth; | ||
| 15 | static const float BOT_SCREEN_ASPECT_RATIO = | ||
| 16 | static_cast<float>(VideoCore::kScreenBottomHeight) / VideoCore::kScreenBottomWidth; | ||
| 17 | |||
| 18 | // Finds the largest size subrectangle contained in window area that is confined to the aspect ratio | ||
| 19 | template <class T> | ||
| 20 | static MathUtil::Rectangle<T> maxRectangle(MathUtil::Rectangle<T> window_area, | ||
| 21 | float screen_aspect_ratio) { | ||
| 22 | float scale = std::min(static_cast<float>(window_area.GetWidth()), | ||
| 23 | window_area.GetHeight() / screen_aspect_ratio); | ||
| 24 | return MathUtil::Rectangle<T>{0, 0, static_cast<T>(std::round(scale)), | ||
| 25 | static_cast<T>(std::round(scale * screen_aspect_ratio))}; | ||
| 26 | } | ||
| 27 | |||
| 28 | FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height, bool swapped) { | ||
| 29 | ASSERT(width > 0); | ||
| 30 | ASSERT(height > 0); | ||
| 31 | |||
| 32 | FramebufferLayout res{width, height, true, true, {}, {}}; | ||
| 33 | // Default layout gives equal screen sizes to the top and bottom screen | ||
| 34 | MathUtil::Rectangle<unsigned> screen_window_area{0, 0, width, height / 2}; | ||
| 35 | MathUtil::Rectangle<unsigned> top_screen = | ||
| 36 | maxRectangle(screen_window_area, TOP_SCREEN_ASPECT_RATIO); | ||
| 37 | MathUtil::Rectangle<unsigned> bot_screen = | ||
| 38 | maxRectangle(screen_window_area, BOT_SCREEN_ASPECT_RATIO); | ||
| 39 | |||
| 40 | float window_aspect_ratio = static_cast<float>(height) / width; | ||
| 41 | // both screens height are taken into account by multiplying by 2 | ||
| 42 | float emulation_aspect_ratio = TOP_SCREEN_ASPECT_RATIO * 2; | ||
| 43 | |||
| 44 | if (window_aspect_ratio < emulation_aspect_ratio) { | ||
| 45 | // Apply borders to the left and right sides of the window. | ||
| 46 | top_screen = | ||
| 47 | top_screen.TranslateX((screen_window_area.GetWidth() - top_screen.GetWidth()) / 2); | ||
| 48 | bot_screen = | ||
| 49 | bot_screen.TranslateX((screen_window_area.GetWidth() - bot_screen.GetWidth()) / 2); | ||
| 50 | } else { | ||
| 51 | // Window is narrower than the emulation content => apply borders to the top and bottom | ||
| 52 | // Recalculate the bottom screen to account for the width difference between top and bottom | ||
| 53 | screen_window_area = {0, 0, width, top_screen.GetHeight()}; | ||
| 54 | bot_screen = maxRectangle(screen_window_area, BOT_SCREEN_ASPECT_RATIO); | ||
| 55 | bot_screen = bot_screen.TranslateX((top_screen.GetWidth() - bot_screen.GetWidth()) / 2); | ||
| 56 | if (swapped) { | ||
| 57 | bot_screen = bot_screen.TranslateY(height / 2 - bot_screen.GetHeight()); | ||
| 58 | } else { | ||
| 59 | top_screen = top_screen.TranslateY(height / 2 - top_screen.GetHeight()); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | // Move the top screen to the bottom if we are swapped. | ||
| 63 | res.top_screen = swapped ? top_screen.TranslateY(height / 2) : top_screen; | ||
| 64 | res.bottom_screen = swapped ? bot_screen : bot_screen.TranslateY(height / 2); | ||
| 65 | return res; | ||
| 66 | } | ||
| 67 | |||
| 68 | FramebufferLayout SingleFrameLayout(unsigned width, unsigned height, bool swapped) { | ||
| 69 | ASSERT(width > 0); | ||
| 70 | ASSERT(height > 0); | ||
| 71 | // The drawing code needs at least somewhat valid values for both screens | ||
| 72 | // so just calculate them both even if the other isn't showing. | ||
| 73 | FramebufferLayout res{width, height, !swapped, swapped, {}, {}}; | ||
| 74 | |||
| 75 | MathUtil::Rectangle<unsigned> screen_window_area{0, 0, width, height}; | ||
| 76 | MathUtil::Rectangle<unsigned> top_screen = | ||
| 77 | maxRectangle(screen_window_area, TOP_SCREEN_ASPECT_RATIO); | ||
| 78 | MathUtil::Rectangle<unsigned> bot_screen = | ||
| 79 | maxRectangle(screen_window_area, BOT_SCREEN_ASPECT_RATIO); | ||
| 80 | |||
| 81 | float window_aspect_ratio = static_cast<float>(height) / width; | ||
| 82 | float emulation_aspect_ratio = (swapped) ? BOT_SCREEN_ASPECT_RATIO : TOP_SCREEN_ASPECT_RATIO; | ||
| 83 | |||
| 84 | if (window_aspect_ratio < emulation_aspect_ratio) { | ||
| 85 | top_screen = | ||
| 86 | top_screen.TranslateX((screen_window_area.GetWidth() - top_screen.GetWidth()) / 2); | ||
| 87 | bot_screen = | ||
| 88 | bot_screen.TranslateX((screen_window_area.GetWidth() - bot_screen.GetWidth()) / 2); | ||
| 89 | } else { | ||
| 90 | top_screen = top_screen.TranslateY((height - top_screen.GetHeight()) / 2); | ||
| 91 | bot_screen = bot_screen.TranslateY((height - bot_screen.GetHeight()) / 2); | ||
| 92 | } | ||
| 93 | res.top_screen = top_screen; | ||
| 94 | res.bottom_screen = bot_screen; | ||
| 95 | return res; | ||
| 96 | } | ||
| 97 | |||
| 98 | FramebufferLayout LargeFrameLayout(unsigned width, unsigned height, bool swapped) { | ||
| 99 | ASSERT(width > 0); | ||
| 100 | ASSERT(height > 0); | ||
| 101 | |||
| 102 | FramebufferLayout res{width, height, true, true, {}, {}}; | ||
| 103 | // Split the window into two parts. Give 4x width to the main screen and 1x width to the small | ||
| 104 | // To do that, find the total emulation box and maximize that based on window size | ||
| 105 | float window_aspect_ratio = static_cast<float>(height) / width; | ||
| 106 | float emulation_aspect_ratio = | ||
| 107 | swapped | ||
| 108 | ? VideoCore::kScreenBottomHeight * 4 / | ||
| 109 | (VideoCore::kScreenBottomWidth * 4.0f + VideoCore::kScreenTopWidth) | ||
| 110 | : VideoCore::kScreenTopHeight * 4 / | ||
| 111 | (VideoCore::kScreenTopWidth * 4.0f + VideoCore::kScreenBottomWidth); | ||
| 112 | float large_screen_aspect_ratio = swapped ? BOT_SCREEN_ASPECT_RATIO : TOP_SCREEN_ASPECT_RATIO; | ||
| 113 | float small_screen_aspect_ratio = swapped ? TOP_SCREEN_ASPECT_RATIO : BOT_SCREEN_ASPECT_RATIO; | ||
| 114 | |||
| 115 | MathUtil::Rectangle<unsigned> screen_window_area{0, 0, width, height}; | ||
| 116 | MathUtil::Rectangle<unsigned> total_rect = | ||
| 117 | maxRectangle(screen_window_area, emulation_aspect_ratio); | ||
| 118 | MathUtil::Rectangle<unsigned> large_screen = | ||
| 119 | maxRectangle(total_rect, large_screen_aspect_ratio); | ||
| 120 | MathUtil::Rectangle<unsigned> fourth_size_rect = total_rect.Scale(.25f); | ||
| 121 | MathUtil::Rectangle<unsigned> small_screen = | ||
| 122 | maxRectangle(fourth_size_rect, small_screen_aspect_ratio); | ||
| 123 | |||
| 124 | if (window_aspect_ratio < emulation_aspect_ratio) { | ||
| 125 | large_screen = | ||
| 126 | large_screen.TranslateX((screen_window_area.GetWidth() - total_rect.GetWidth()) / 2); | ||
| 127 | } else { | ||
| 128 | large_screen = large_screen.TranslateY((height - total_rect.GetHeight()) / 2); | ||
| 129 | } | ||
| 130 | // Shift the small screen to the bottom right corner | ||
| 131 | small_screen = | ||
| 132 | small_screen.TranslateX(large_screen.right) | ||
| 133 | .TranslateY(large_screen.GetHeight() + large_screen.top - small_screen.GetHeight()); | ||
| 134 | res.top_screen = swapped ? small_screen : large_screen; | ||
| 135 | res.bottom_screen = swapped ? large_screen : small_screen; | ||
| 136 | return res; | ||
| 137 | } | ||
| 138 | } | ||
diff --git a/src/common/framebuffer_layout.h b/src/common/framebuffer_layout.h new file mode 100644 index 000000000..a125646a3 --- /dev/null +++ b/src/common/framebuffer_layout.h | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | // Copyright 2016 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "common/math_util.h" | ||
| 8 | namespace Layout { | ||
| 9 | /// Describes the layout of the window framebuffer (size and top/bottom screen positions) | ||
| 10 | struct FramebufferLayout { | ||
| 11 | unsigned width; | ||
| 12 | unsigned height; | ||
| 13 | bool top_screen_enabled; | ||
| 14 | bool bottom_screen_enabled; | ||
| 15 | MathUtil::Rectangle<unsigned> top_screen; | ||
| 16 | MathUtil::Rectangle<unsigned> bottom_screen; | ||
| 17 | }; | ||
| 18 | |||
| 19 | /** | ||
| 20 | * Factory method for constructing a default FramebufferLayout | ||
| 21 | * @param width Window framebuffer width in pixels | ||
| 22 | * @param height Window framebuffer height in pixels | ||
| 23 | * @param is_swapped if true, the bottom screen will be displayed above the top screen | ||
| 24 | * @return Newly created FramebufferLayout object with default screen regions initialized | ||
| 25 | */ | ||
| 26 | FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height, bool is_swapped); | ||
| 27 | |||
| 28 | /** | ||
| 29 | * Factory method for constructing a FramebufferLayout with only the top or bottom screen | ||
| 30 | * @param width Window framebuffer width in pixels | ||
| 31 | * @param height Window framebuffer height in pixels | ||
| 32 | * @param is_swapped if true, the bottom screen will be displayed (and the top won't be displayed) | ||
| 33 | * @return Newly created FramebufferLayout object with default screen regions initialized | ||
| 34 | */ | ||
| 35 | FramebufferLayout SingleFrameLayout(unsigned width, unsigned height, bool is_swapped); | ||
| 36 | |||
| 37 | /** | ||
| 38 | * Factory method for constructing a Frame with the a 4x size Top screen with a 1x size bottom | ||
| 39 | * screen on the right | ||
| 40 | * This is useful in particular because it matches well with a 1920x1080 resolution monitor | ||
| 41 | * @param width Window framebuffer width in pixels | ||
| 42 | * @param height Window framebuffer height in pixels | ||
| 43 | * @param is_swapped if true, the bottom screen will be the large display | ||
| 44 | * @return Newly created FramebufferLayout object with default screen regions initialized | ||
| 45 | */ | ||
| 46 | FramebufferLayout LargeFrameLayout(unsigned width, unsigned height, bool is_swapped); | ||
| 47 | } | ||
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 88209081d..7fd397fe5 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp | |||
| @@ -43,6 +43,7 @@ namespace Log { | |||
| 43 | SUB(Service, AM) \ | 43 | SUB(Service, AM) \ |
| 44 | SUB(Service, PTM) \ | 44 | SUB(Service, PTM) \ |
| 45 | SUB(Service, LDR) \ | 45 | SUB(Service, LDR) \ |
| 46 | SUB(Service, MIC) \ | ||
| 46 | SUB(Service, NDM) \ | 47 | SUB(Service, NDM) \ |
| 47 | SUB(Service, NIM) \ | 48 | SUB(Service, NIM) \ |
| 48 | SUB(Service, NWM) \ | 49 | SUB(Service, NWM) \ |
diff --git a/src/common/logging/log.h b/src/common/logging/log.h index 8d3a2d03e..8011534b8 100644 --- a/src/common/logging/log.h +++ b/src/common/logging/log.h | |||
| @@ -60,6 +60,7 @@ enum class Class : ClassType { | |||
| 60 | Service_AM, ///< The AM (Application manager) service | 60 | Service_AM, ///< The AM (Application manager) service |
| 61 | Service_PTM, ///< The PTM (Power status & misc.) service | 61 | Service_PTM, ///< The PTM (Power status & misc.) service |
| 62 | Service_LDR, ///< The LDR (3ds dll loader) service | 62 | Service_LDR, ///< The LDR (3ds dll loader) service |
| 63 | Service_MIC, ///< The MIC (microphone) service | ||
| 63 | Service_NDM, ///< The NDM (Network daemon manager) service | 64 | Service_NDM, ///< The NDM (Network daemon manager) service |
| 64 | Service_NIM, ///< The NIM (Network interface manager) service | 65 | Service_NIM, ///< The NIM (Network interface manager) service |
| 65 | Service_NWM, ///< The NWM (Network wlan manager) service | 66 | Service_NWM, ///< The NWM (Network wlan manager) service |
diff --git a/src/common/math_util.h b/src/common/math_util.h index 41d89666c..cdeaeb733 100644 --- a/src/common/math_util.h +++ b/src/common/math_util.h | |||
| @@ -38,6 +38,16 @@ struct Rectangle { | |||
| 38 | T GetHeight() const { | 38 | T GetHeight() const { |
| 39 | return std::abs(static_cast<typename std::make_signed<T>::type>(bottom - top)); | 39 | return std::abs(static_cast<typename std::make_signed<T>::type>(bottom - top)); |
| 40 | } | 40 | } |
| 41 | Rectangle<T> TranslateX(const T x) const { | ||
| 42 | return Rectangle{left + x, top, right + x, bottom}; | ||
| 43 | } | ||
| 44 | Rectangle<T> TranslateY(const T y) const { | ||
| 45 | return Rectangle{left, top + y, right, bottom + y}; | ||
| 46 | } | ||
| 47 | Rectangle<T> Scale(const float s) const { | ||
| 48 | return Rectangle{left, top, static_cast<T>(left + GetWidth() * s), | ||
| 49 | static_cast<T>(top + GetHeight() * s)}; | ||
| 50 | } | ||
| 41 | }; | 51 | }; |
| 42 | 52 | ||
| 43 | } // namespace MathUtil | 53 | } // namespace MathUtil |
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index 596ae01bf..df1008180 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp | |||
| @@ -11,7 +11,8 @@ | |||
| 11 | #include "common/common_paths.h" | 11 | #include "common/common_paths.h" |
| 12 | #include "common/logging/log.h" | 12 | #include "common/logging/log.h" |
| 13 | #include "common/string_util.h" | 13 | #include "common/string_util.h" |
| 14 | #ifdef _MSC_VER | 14 | |
| 15 | #ifdef _WIN32 | ||
| 15 | #include <codecvt> | 16 | #include <codecvt> |
| 16 | #include <Windows.h> | 17 | #include <Windows.h> |
| 17 | #include "common/common_funcs.h" | 18 | #include "common/common_funcs.h" |
| @@ -270,7 +271,7 @@ std::string ReplaceAll(std::string result, const std::string& src, const std::st | |||
| 270 | return result; | 271 | return result; |
| 271 | } | 272 | } |
| 272 | 273 | ||
| 273 | #ifdef _MSC_VER | 274 | #ifdef _WIN32 |
| 274 | 275 | ||
| 275 | std::string UTF16ToUTF8(const std::u16string& input) { | 276 | std::string UTF16ToUTF8(const std::u16string& input) { |
| 276 | #if _MSC_VER >= 1900 | 277 | #if _MSC_VER >= 1900 |