summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDr. Chat <arkolbed@gmail.com>2017-08-03 22:34:12 -0500
committerDr. Chat <arkolbed@gmail.com>2017-08-03 22:34:12 -0500
commit5430dd0cd02ff82ac14ce25398e79bef2112d41b (patch)
tree059e742465425225da19c9409bdba57ac54c6299
parent707f4c96ba697ce13291e50e382d9de2e9736b58 (diff)
UI: Properly size microprofile, make dpi transparent to unaware users.
-rw-r--r--src/xenia/base/profiling.cc2
-rw-r--r--src/xenia/ui/microprofile_drawer.cc4
-rw-r--r--src/xenia/ui/window.cc4
-rw-r--r--src/xenia/ui/window.h3
-rw-r--r--src/xenia/ui/window_win.cc16
5 files changed, 20 insertions, 9 deletions
diff --git a/src/xenia/base/profiling.cc b/src/xenia/base/profiling.cc
index c1d474b01..69d4e090e 100644
--- a/src/xenia/base/profiling.cc
+++ b/src/xenia/base/profiling.cc
@@ -241,7 +241,7 @@ void Profiler::Present() {
return;
}
drawer_->Begin();
- MicroProfileDraw(window_->width(), window_->height());
+ MicroProfileDraw(window_->scaled_width(), window_->scaled_height());
drawer_->End();
#endif // XE_OPTION_PROFILING_UI
}
diff --git a/src/xenia/ui/microprofile_drawer.cc b/src/xenia/ui/microprofile_drawer.cc
index e4006d0f5..c73d0a18d 100644
--- a/src/xenia/ui/microprofile_drawer.cc
+++ b/src/xenia/ui/microprofile_drawer.cc
@@ -178,8 +178,8 @@ void MicroprofileDrawer::SetupFont() {
MicroprofileDrawer::~MicroprofileDrawer() = default;
void MicroprofileDrawer::Begin() {
- graphics_context_->immediate_drawer()->Begin(window_->width(),
- window_->height());
+ graphics_context_->immediate_drawer()->Begin(window_->scaled_width(),
+ window_->scaled_height());
}
void MicroprofileDrawer::End() {
diff --git a/src/xenia/ui/window.cc b/src/xenia/ui/window.cc
index 2abe73115..2edff242a 100644
--- a/src/xenia/ui/window.cc
+++ b/src/xenia/ui/window.cc
@@ -193,8 +193,8 @@ void Window::OnPaint(UIEvent* e) {
io.DeltaTime = (now_ns - last_paint_time_ns_) / 10000000.0f;
last_paint_time_ns_ = now_ns;
}
- io.DisplaySize =
- ImVec2(static_cast<float>(width()), static_cast<float>(height()));
+ io.DisplaySize = ImVec2(static_cast<float>(scaled_width()),
+ static_cast<float>(scaled_height()));
ImGui::NewFrame();
context_->BeginSwap();
diff --git a/src/xenia/ui/window.h b/src/xenia/ui/window.h
index a9021538d..07831fe96 100644
--- a/src/xenia/ui/window.h
+++ b/src/xenia/ui/window.h
@@ -76,6 +76,9 @@ class Window {
int32_t width() const { return width_; }
int32_t height() const { return height_; }
+ int32_t scaled_width() const { return int32_t(width_ * get_dpi_scale()); }
+ int32_t scaled_height() const { return int32_t(height_ * get_dpi_scale()); }
+
virtual void Resize(int32_t width, int32_t height) {
width_ = width;
height_ = height;
diff --git a/src/xenia/ui/window_win.cc b/src/xenia/ui/window_win.cc
index 2c9bfe54c..a0aade0b0 100644
--- a/src/xenia/ui/window_win.cc
+++ b/src/xenia/ui/window_win.cc
@@ -325,8 +325,9 @@ void Win32Window::Resize(int32_t width, int32_t height) {
// Scale width and height
int32_t scaled_width, scaled_height;
- scaled_width = int32_t(width * get_dpi_scale());
- scaled_height = int32_t(height * get_dpi_scale());
+ float dpi_scale = get_dpi_scale();
+ scaled_width = int32_t(width * dpi_scale);
+ scaled_height = int32_t(height * dpi_scale);
RECT rc = {0, 0, 0, 0};
GetWindowRect(hwnd_, &rc);
@@ -358,8 +359,9 @@ void Win32Window::Resize(int32_t left, int32_t top, int32_t right,
RECT rc = {left, top, right, bottom};
// Scale width and height
- rc.right = int32_t((right - left) * get_dpi_scale()) + left;
- rc.bottom = int32_t((bottom - top) * get_dpi_scale()) + top;
+ float dpi_scale = get_dpi_scale();
+ rc.right = int32_t((right - left) * dpi_scale) + left;
+ rc.bottom = int32_t((bottom - top) * dpi_scale) + top;
bool has_menu = !is_fullscreen() && (main_menu_ ? true : false);
AdjustWindowRect(&rc, GetWindowLong(hwnd_, GWL_STYLE), has_menu);
@@ -379,6 +381,12 @@ void Win32Window::OnResize(UIEvent* e) {
GetClientRect(hwnd_, &client_rect);
int32_t width = client_rect.right - client_rect.left;
int32_t height = client_rect.bottom - client_rect.top;
+
+ // Rescale to base DPI.
+ float dpi_scale = get_dpi_scale();
+ width = int32_t(width / dpi_scale);
+ height = int32_t(height / dpi_scale);
+
if (width != width_ || height != height_) {
width_ = width;
height_ = height;