1
0
Fork 0
forked from suyu/suyu

EmuWindow: Add support for specifying minimal client area sizes.

This commit is contained in:
Tony Wasserka 2014-10-12 22:46:33 +02:00
parent bd8f491e4c
commit 722ce22589
5 changed files with 58 additions and 8 deletions

View file

@ -46,6 +46,15 @@ void EmuWindow_GLFW::OnClientAreaResizeEvent(GLFWwindow* win, int width, int hei
_dbg_assert_(GUI, width > 0); _dbg_assert_(GUI, width > 0);
_dbg_assert_(GUI, height > 0); _dbg_assert_(GUI, height > 0);
// TODO: It's actually more interesting to us what the framebuffer size ends up being.
int adjusted_width = std::max<unsigned>(width, GetEmuWindow(win)->GetActiveConfig().min_client_area_size.first);
int adjusted_height = std::max<unsigned>(height, GetEmuWindow(win)->GetActiveConfig().min_client_area_size.second);
if (adjusted_width != width || adjusted_height != height) {
glfwSetWindowSize(win, adjusted_width, adjusted_height);
return;
}
GetEmuWindow(win)->NotifyClientAreaSizeChanged(std::pair<unsigned,unsigned>(width, height)); GetEmuWindow(win)->NotifyClientAreaSizeChanged(std::pair<unsigned,unsigned>(width, height));
} }
@ -136,3 +145,15 @@ void EmuWindow_GLFW::ReloadSetKeymaps() {
KeyMap::SetKeyMapping({Settings::values.pad_sup_key, keyboard_id}, HID_User::PAD_CIRCLE_UP); KeyMap::SetKeyMapping({Settings::values.pad_sup_key, keyboard_id}, HID_User::PAD_CIRCLE_UP);
KeyMap::SetKeyMapping({Settings::values.pad_sdown_key, keyboard_id}, HID_User::PAD_CIRCLE_DOWN); KeyMap::SetKeyMapping({Settings::values.pad_sdown_key, keyboard_id}, HID_User::PAD_CIRCLE_DOWN);
} }
void EmuWindow_GLFW::OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) {
std::pair<int,int> current_size;
glfwGetWindowSize(m_render_window, &current_size.first, &current_size.second);
_dbg_assert_(GUI, (int)minimal_size.first > 0 && (int)minimal_size.second > 0);
int new_width = std::max(current_size.first, (int)minimal_size.first);
int new_height = std::max(current_size.second, (int)minimal_size.second);
if (current_size != std::make_pair(new_width, new_height))
glfwSetWindowSize(m_render_window, new_width, new_height);
}

View file

@ -37,6 +37,8 @@ public:
void ReloadSetKeymaps() override; void ReloadSetKeymaps() override;
private: private:
void OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) override;
static EmuWindow_GLFW* GetEmuWindow(GLFWwindow* win); static EmuWindow_GLFW* GetEmuWindow(GLFWwindow* win);
GLFWwindow* m_render_window; ///< Internal GLFW render window GLFWwindow* m_render_window; ///< Internal GLFW render window

View file

@ -129,6 +129,9 @@ GRenderWindow::GRenderWindow(QWidget* parent) : QWidget(parent), emu_thread(this
setLayout(layout); setLayout(layout);
connect(&emu_thread, SIGNAL(started()), this, SLOT(moveContext())); connect(&emu_thread, SIGNAL(started()), this, SLOT(moveContext()));
setMinimumSize(GetActiveConfig().min_client_area_size.first,
GetActiveConfig().min_client_area_size.second);
OnFramebufferSizeChanged(); OnFramebufferSizeChanged();
NotifyClientAreaSizeChanged(std::pair<unsigned,unsigned>(child->width(), child->height())); NotifyClientAreaSizeChanged(std::pair<unsigned,unsigned>(child->width(), child->height()));
@ -275,3 +278,7 @@ void GRenderWindow::OnClientAreaResized(unsigned width, unsigned height)
{ {
NotifyClientAreaSizeChanged(std::make_pair(width, height)); NotifyClientAreaSizeChanged(std::make_pair(width, height));
} }
void GRenderWindow::OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) {
setMinimumSize(minimal_size.first, minimal_size.second);
}

View file

@ -121,6 +121,8 @@ public slots:
void moveContext(); // overridden void moveContext(); // overridden
private: private:
void OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) override;
QGLWidget* child; QGLWidget* child;
EmuThread emu_thread; EmuThread emu_thread;

View file

@ -20,6 +20,7 @@ public:
bool fullscreen; bool fullscreen;
int res_width; int res_width;
int res_height; int res_height;
std::pair<unsigned,unsigned> min_client_area_size;
}; };
/// Swap buffers to display the next frame /// Swap buffers to display the next frame
@ -42,8 +43,8 @@ public:
/// Signals a key release action to the HID module /// Signals a key release action to the HID module
static void KeyReleased(KeyMap::HostDeviceKey key); static void KeyReleased(KeyMap::HostDeviceKey key);
WindowConfig GetConfig() const { const WindowConfig& GetActiveConfig() const {
return config; return active_config;
} }
void SetConfig(const WindowConfig& val) { void SetConfig(const WindowConfig& val) {
@ -72,24 +73,40 @@ public:
window_title = val; window_title = val;
} }
// Only call this from the GUI thread!
void ProcessConfigurationChanges() {
// TODO: For proper thread safety, we should eventually implement a proper
// multiple-writer/single-reader queue...
if (config.min_client_area_size != active_config.min_client_area_size) {
OnMinimalClientAreaChangeRequest(config.min_client_area_size);
config.min_client_area_size = active_config.min_client_area_size;
}
}
protected: protected:
EmuWindow() : // TODO: What the hell... -.- - don't hardcode dimensions here without applying them in a sensible manner... EmuWindow() :
window_title(Common::StringFromFormat("Citra | %s-%s", Common::g_scm_branch, Common::g_scm_desc)) window_title(Common::StringFromFormat("Citra | %s-%s", Common::g_scm_branch, Common::g_scm_desc))
m_client_area_width(640), {
m_client_area_height(480), // TODO
{} config.min_client_area_size = std::make_pair(300u, 500u);
active_config = config;
}
virtual ~EmuWindow() {} virtual ~EmuWindow() {}
std::pair<unsigned,unsigned> NotifyFramebufferSizeChanged(const std::pair<unsigned,unsigned>& size) { std::pair<unsigned,unsigned> NotifyFramebufferSizeChanged(const std::pair<unsigned,unsigned>& size) {
framebuffer_size = size; framebuffer_size = size;
} }
void NotifyClientAreaSizeChanged(std::pair<unsigned,unsigned> size) { void NotifyClientAreaSizeChanged(const std::pair<unsigned,unsigned>& size) {
client_area_width = size.first; client_area_width = size.first;
client_area_height = size.second; client_area_height = size.second;
} }
private: private:
virtual void OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) {
}
std::string window_title; ///< Current window title, should be used by window impl. std::string window_title; ///< Current window title, should be used by window impl.
std::pair<unsigned,unsigned> framebuffer_size; std::pair<unsigned,unsigned> framebuffer_size;
@ -97,5 +114,6 @@ private:
unsigned client_area_width; ///< Current client width, should be set by window impl. unsigned client_area_width; ///< Current client width, should be set by window impl.
unsigned client_area_height; ///< Current client height, should be set by window impl. unsigned client_area_height; ///< Current client height, should be set by window impl.
WindowConfig config; ///< Internal configuration WindowConfig config; ///< Internal configuration (changes pending for being applied in ProcessConfigurationChanges)
WindowConfig active_config; ///< Internal active configuration
}; };