summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/emu_window.h128
-rw-r--r--src/common/log.h1
-rw-r--r--src/common/log_manager.cpp1
-rw-r--r--src/common/math_util.h9
4 files changed, 101 insertions, 38 deletions
diff --git a/src/common/emu_window.h b/src/common/emu_window.h
index 6c2b598f6..4cb94fed1 100644
--- a/src/common/emu_window.h
+++ b/src/common/emu_window.h
@@ -9,17 +9,33 @@
9#include "common/string_util.h" 9#include "common/string_util.h"
10#include "common/key_map.h" 10#include "common/key_map.h"
11 11
12// Abstraction class used to provide an interface between emulation code and the frontend (e.g. SDL, 12/**
13// QGLWidget, GLFW, etc...) 13 * Abstraction class used to provide an interface between emulation code and the frontend
14 * (e.g. SDL, QGLWidget, GLFW, etc...).
15 *
16 * Design notes on the interaction between EmuWindow and the emulation core:
17 * - Generally, decisions on anything visible to the user should be left up to the GUI.
18 * For example, the emulation core should not try to dictate some window title or size.
19 * This stuff is not the core's business and only causes problems with regards to thread-safety
20 * anyway.
21 * - Under certain circumstances, it may be desirable for the core to politely request the GUI
22 * to set e.g. a minimum window size. However, the GUI should always be free to ignore any
23 * such hints.
24 * - EmuWindow may expose some of its state as read-only to the emulation core, however care
25 * should be taken to make sure the provided information is self-consistent. This requires
26 * some sort of synchronization (most of this is still a TODO).
27 * - DO NOT TREAT THIS CLASS AS A GUI TOOLKIT ABSTRACTION LAYER. That's not what it is. Please
28 * re-read the upper points again and think about it if you don't see this.
29 */
14class EmuWindow 30class EmuWindow
15{ 31{
16
17public: 32public:
18 /// Data structure to store an emuwindow configuration 33 /// Data structure to store emuwindow configuration
19 struct WindowConfig { 34 struct WindowConfig {
20 bool fullscreen; 35 bool fullscreen;
21 int res_width; 36 int res_width;
22 int res_height; 37 int res_height;
38 std::pair<unsigned,unsigned> min_client_area_size;
23 }; 39 };
24 40
25 /// Swap buffers to display the next frame 41 /// Swap buffers to display the next frame
@@ -42,52 +58,96 @@ public:
42 /// Signals a key release action to the HID module 58 /// Signals a key release action to the HID module
43 static void KeyReleased(KeyMap::HostDeviceKey key); 59 static void KeyReleased(KeyMap::HostDeviceKey key);
44 60
45 WindowConfig GetConfig() const { 61 /**
46 return m_config; 62 * Returns currently active configuration.
63 * @note Accesses to the returned object need not be consistent because it may be modified in another thread
64 */
65 const WindowConfig& GetActiveConfig() const {
66 return active_config;
47 } 67 }
48 68
69 /**
70 * Requests the internal configuration to be replaced by the specified argument at some point in the future.
71 * @note This method is thread-safe, because it delays configuration changes to the GUI event loop. Hence there is no guarantee on when the requested configuration will be active.
72 */
49 void SetConfig(const WindowConfig& val) { 73 void SetConfig(const WindowConfig& val) {
50 m_config = val; 74 config = val;
51 }
52
53 int GetClientAreaWidth() const {
54 return m_client_area_width;
55 } 75 }
56 76
57 void SetClientAreaWidth(const int val) { 77 /**
58 m_client_area_width = val; 78 * Gets the framebuffer size in pixels.
79 * @note This method is thread-safe
80 */
81 const std::pair<unsigned,unsigned> GetFramebufferSize() const {
82 return framebuffer_size;
59 } 83 }
60 84
61 int GetClientAreaHeight() const { 85 /**
62 return m_client_area_height; 86 * Gets window client area width in logical coordinates.
87 * @note For high-DPI systems, this is smaller than the framebuffer size.
88 * @note This method is thread-safe
89 */
90 std::pair<unsigned,unsigned> GetClientAreaSize() const {
91 return std::make_pair(client_area_width, client_area_height);
63 } 92 }
64 93
65 void SetClientAreaHeight(const int val) { 94protected:
66 m_client_area_height = val; 95 EmuWindow()
96 {
97 // TODO: Find a better place to set this.
98 config.min_client_area_size = std::make_pair(400u, 480u);
99 active_config = config;
67 } 100 }
101 virtual ~EmuWindow() {}
68 102
69 std::string GetWindowTitle() const { 103 /**
70 return m_window_title; 104 * Processes any pending configuration changes from the last SetConfig call.
105 * This method invokes OnMinimalClientAreaChangeRequest if the corresponding configuration
106 * field changed.
107 * @note Implementations will usually want to call this from the GUI thread.
108 * @todo Actually call this in existing implementations.
109 */
110 void ProcessConfigurationChanges() {
111 // TODO: For proper thread safety, we should eventually implement a proper
112 // multiple-writer/single-reader queue...
113
114 if (config.min_client_area_size != active_config.min_client_area_size) {
115 OnMinimalClientAreaChangeRequest(config.min_client_area_size);
116 config.min_client_area_size = active_config.min_client_area_size;
117 }
71 } 118 }
72 119
73 void SetWindowTitle(std::string val) { 120 /**
74 m_window_title = val; 121 * Update internal framebuffer size with the given parameter.
122 * @note EmuWindow implementations will usually use this in window resize event handlers.
123 */
124 void NotifyFramebufferSizeChanged(const std::pair<unsigned,unsigned>& size) {
125 framebuffer_size = size;
75 } 126 }
76 127
77protected: 128 /**
78 EmuWindow(): 129 * Update internal client area size with the given parameter.
79 m_window_title(Common::StringFromFormat("Citra | %s-%s", Common::g_scm_branch, Common::g_scm_desc)), 130 * @note EmuWindow implementations will usually use this in window resize event handlers.
80 m_client_area_width(640), 131 */
81 m_client_area_height(480) 132 void NotifyClientAreaSizeChanged(const std::pair<unsigned,unsigned>& size) {
82 {} 133 client_area_width = size.first;
83 virtual ~EmuWindow() {} 134 client_area_height = size.second;
135 }
84 136
85 std::string m_window_title; ///< Current window title, should be used by window impl. 137private:
138 /**
139 * Handler called when the minimal client area was requested to be changed via SetConfig.
140 * For the request to be honored, EmuWindow implementations will usually reimplement this function.
141 */
142 virtual void OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) {
143 // By default, ignore this request and do nothing.
144 }
86 145
87 int m_client_area_width; ///< Current client width, should be set by window impl. 146 std::pair<unsigned,unsigned> framebuffer_size;
88 int m_client_area_height; ///< Current client height, should be set by window impl.
89 147
90private: 148 unsigned client_area_width; ///< Current client width, should be set by window impl.
91 WindowConfig m_config; ///< Internal configuration 149 unsigned client_area_height; ///< Current client height, should be set by window impl.
92 150
151 WindowConfig config; ///< Internal configuration (changes pending for being applied in ProcessConfigurationChanges)
152 WindowConfig active_config; ///< Internal active configuration
93}; 153};
diff --git a/src/common/log.h b/src/common/log.h
index bfd73f8a5..822cd21eb 100644
--- a/src/common/log.h
+++ b/src/common/log.h
@@ -69,6 +69,7 @@ enum LOG_TYPE {
69 HW, 69 HW,
70 TIME, 70 TIME,
71 NETPLAY, 71 NETPLAY,
72 GUI,
72 73
73 NUMBER_OF_LOGS // Must be last 74 NUMBER_OF_LOGS // Must be last
74}; 75};
diff --git a/src/common/log_manager.cpp b/src/common/log_manager.cpp
index 4d590d98f..687f4e337 100644
--- a/src/common/log_manager.cpp
+++ b/src/common/log_manager.cpp
@@ -75,6 +75,7 @@ LogManager::LogManager()
75 m_Log[LogTypes::ACTIONREPLAY] = new LogContainer("ActionReplay", "ActionReplay"); 75 m_Log[LogTypes::ACTIONREPLAY] = new LogContainer("ActionReplay", "ActionReplay");
76 m_Log[LogTypes::MEMCARD_MANAGER] = new LogContainer("MemCard Manager", "MemCard Manager"); 76 m_Log[LogTypes::MEMCARD_MANAGER] = new LogContainer("MemCard Manager", "MemCard Manager");
77 m_Log[LogTypes::NETPLAY] = new LogContainer("NETPLAY", "Netplay"); 77 m_Log[LogTypes::NETPLAY] = new LogContainer("NETPLAY", "Netplay");
78 m_Log[LogTypes::GUI] = new LogContainer("GUI", "GUI");
78 79
79 m_fileLog = new FileLogListener(FileUtil::GetUserPath(F_MAINLOG_IDX).c_str()); 80 m_fileLog = new FileLogListener(FileUtil::GetUserPath(F_MAINLOG_IDX).c_str());
80 m_consoleLog = new ConsoleListener(); 81 m_consoleLog = new ConsoleListener();
diff --git a/src/common/math_util.h b/src/common/math_util.h
index b32e7bb14..b10a25c13 100644
--- a/src/common/math_util.h
+++ b/src/common/math_util.h
@@ -7,6 +7,7 @@
7#include "common/common.h" 7#include "common/common.h"
8 8
9#include <algorithm> 9#include <algorithm>
10#include <type_traits>
10#include <vector> 11#include <vector>
11 12
12namespace MathUtil 13namespace MathUtil
@@ -109,11 +110,11 @@ struct Rectangle
109 Rectangle(T theLeft, T theTop, T theRight, T theBottom) 110 Rectangle(T theLeft, T theTop, T theRight, T theBottom)
110 : left(theLeft), top(theTop), right(theRight), bottom(theBottom) 111 : left(theLeft), top(theTop), right(theRight), bottom(theBottom)
111 { } 112 { }
112 113
113 bool operator==(const Rectangle& r) { return left==r.left && top==r.top && right==r.right && bottom==r.bottom; } 114 bool operator==(const Rectangle& r) { return left==r.left && top==r.top && right==r.right && bottom==r.bottom; }
114 115
115 T GetWidth() const { return abs(right - left); } 116 T GetWidth() const { return std::abs(static_cast<typename std::make_signed<T>::type>(right - left)); }
116 T GetHeight() const { return abs(bottom - top); } 117 T GetHeight() const { return std::abs(static_cast<typename std::make_signed<T>::type>(bottom - top)); }
117 118
118 // If the rectangle is in a coordinate system with a lower-left origin, use 119 // If the rectangle is in a coordinate system with a lower-left origin, use
119 // this Clamp. 120 // this Clamp.
@@ -127,7 +128,7 @@ struct Rectangle
127 128
128 // If the rectangle is in a coordinate system with an upper-left origin, 129 // If the rectangle is in a coordinate system with an upper-left origin,
129 // use this Clamp. 130 // use this Clamp.
130 void ClampUL(T x1, T y1, T x2, T y2) 131 void ClampUL(T x1, T y1, T x2, T y2)
131 { 132 {
132 if (left < x1) left = x1; 133 if (left < x1) left = x1;
133 if (right > x2) right = x2; 134 if (right > x2) right = x2;