UI: Properly size microprofile, make dpi transparent to unaware users.

This commit is contained in:
Dr. Chat 2017-08-03 22:34:12 -05:00
parent 707f4c96ba
commit 5430dd0cd0
5 changed files with 20 additions and 9 deletions

View File

@ -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
}

View File

@ -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() {

View File

@ -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();

View File

@ -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;

View File

@ -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;