1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:57:35 +00:00

DisplaySettings: Add UI for switching the scale factor

For now, only support 1x and 2x scale.

I tried doing something "smarter" first where the UI would try
to keep the physical resolution constant when toggling between
1x and 2x, but many of the smaller 1x resolutions map to 2x
logical resolutions that Compositor rejects (e.g. 1024x768 becomes
512x384, which is less than the minimum 640x480 that Compositor
wants) and it felt complicated and overly magical.

So this instead just gives you a 1x/2x toggle and a dropdown
with logical (!) resolutions. That is, 800x600 @ 2x gives you
a physical resolution of 1600x1200.

If we don't like this after trying it for a while, we can change
the UI then.
This commit is contained in:
Nico Weber 2021-01-15 19:02:17 -05:00 committed by Andreas Kling
parent 05dbfe9ab6
commit f37f281f89
6 changed files with 76 additions and 12 deletions

View file

@ -27,6 +27,7 @@
#include "MonitorWidget.h"
#include <LibGUI/Painter.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Font.h>
namespace DisplaySettings {
@ -110,8 +111,23 @@ void MonitorWidget::paint_event(GUI::PaintEvent& event)
painter.draw_scaled_bitmap(m_monitor_rect, *screen_bitmap, screen_bitmap->rect());
if (!m_desktop_resolution.is_null()) {
painter.draw_text(m_monitor_rect.translated(1, 1), m_desktop_resolution.to_string(), Gfx::TextAlignment::Center, Color::Black);
painter.draw_text(m_monitor_rect, m_desktop_resolution.to_string(), Gfx::TextAlignment::Center, Color::White);
auto displayed_resolution_string = Gfx::IntSize { m_desktop_resolution.width(), m_desktop_resolution.height() }.to_string();
// Render text label scaled with scale factor to hint at its effect.
// FIXME: Once bitmaps have intrinsic scale factors, we could create a bitmap with an intrinsic scale factor of m_desktop_scale_factor
// and that should give us the same effect with less code.
auto text_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGBA32, Gfx::IntSize { painter.font().width(displayed_resolution_string) + 1, painter.font().glyph_height() + 1 });
GUI::Painter text_painter(*text_bitmap);
text_painter.set_font(painter.font());
text_painter.draw_text({}, displayed_resolution_string, Gfx::TextAlignment::BottomRight, Color::Black);
text_painter.draw_text({}, displayed_resolution_string, Gfx::TextAlignment::TopLeft, Color::White);
Gfx::IntRect text_rect = text_bitmap->rect();
text_rect.set_width(text_rect.width() * m_desktop_scale_factor);
text_rect.set_height(text_rect.height() * m_desktop_scale_factor);
text_rect.center_within(m_monitor_rect);
painter.draw_scaled_bitmap(text_rect, *text_bitmap, text_bitmap->rect());
}
}