diff options
author | Hüseyin ASLITÜRK <asliturk@hotmail.com> | 2020-04-15 17:40:46 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-15 16:40:46 +0200 |
commit | abd09ab0305bd12739412e1f66756b73c1256ee2 (patch) | |
tree | ae28e8a4334d84241f2d08a293ce271f58dfac81 /Applications/DisplayProperties | |
parent | d6318f2cc67f6bf3734d82784b13d73b94d76897 (diff) | |
download | serenity-abd09ab0305bd12739412e1f66756b73c1256ee2.zip |
DisplayProperties: Make the preview calculation more accurate (#1807)
Diffstat (limited to 'Applications/DisplayProperties')
-rw-r--r-- | Applications/DisplayProperties/MonitorWidget.cpp | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/Applications/DisplayProperties/MonitorWidget.cpp b/Applications/DisplayProperties/MonitorWidget.cpp index f0f78172af..1bd44888bc 100644 --- a/Applications/DisplayProperties/MonitorWidget.cpp +++ b/Applications/DisplayProperties/MonitorWidget.cpp @@ -27,8 +27,6 @@ #include "MonitorWidget.h" #include <LibGUI/Painter.h> -//#define DEBUG_MODE - MonitorWidget::MonitorWidget() { m_monitor_bitmap = Gfx::Bitmap::load_from_file("/res/monitor.png"); @@ -78,34 +76,32 @@ Gfx::Color MonitorWidget::background_color() void MonitorWidget::paint_event(GUI::PaintEvent& event) { -#ifdef DEBUG_MODE - dbg() << "Paint event fired." - << " Color:" << m_desktop_color.to_string() << "." - << " Resolution:" << m_desktop_resolution.to_string() << "." - << " Wallpaper:" << m_desktop_wallpaper_path << "."; -#endif - - GUI::Painter painter(*this); - painter.add_clip_rect(event.rect()); - - painter.blit({ 0, 0 }, *m_monitor_bitmap, m_monitor_bitmap->rect()); - - painter.fill_rect(m_monitor_rect, m_desktop_color); + Gfx::Rect screen_rect = { 0, 0, m_desktop_resolution.width(), m_desktop_resolution.height() }; + auto screen_bitmap = Gfx::Bitmap::create(m_monitor_bitmap->format(), m_desktop_resolution); + GUI::Painter screen_painter(*screen_bitmap); + screen_painter.fill_rect(screen_rect, m_desktop_color); if (!m_desktop_wallpaper_bitmap.is_null()) { if (m_desktop_wallpaper_mode == "simple") { - painter.blit({ 8, 9 }, *m_desktop_wallpaper_bitmap, { 88, 51, 200, 150 }); + screen_painter.blit({ 0, 0 }, *m_desktop_wallpaper_bitmap, m_desktop_wallpaper_bitmap->rect()); } else if (m_desktop_wallpaper_mode == "center") { - painter.draw_scaled_bitmap({ 88, 51, 160, 90 }, *m_desktop_wallpaper_bitmap, m_desktop_wallpaper_bitmap->rect()); + Gfx::Point offset { screen_rect.width() / 2 - m_desktop_wallpaper_bitmap->size().width() / 2, screen_rect.height() / 2 - m_desktop_wallpaper_bitmap->size().height() / 2 }; + screen_painter.blit_offset(screen_rect.location(), *m_desktop_wallpaper_bitmap, screen_rect, offset); } else if (m_desktop_wallpaper_mode == "tile") { - painter.draw_tiled_bitmap(m_monitor_rect, *m_desktop_wallpaper_bitmap); + screen_painter.draw_tiled_bitmap(screen_bitmap->rect(), *m_desktop_wallpaper_bitmap); } else if (m_desktop_wallpaper_mode == "scaled") { - painter.draw_scaled_bitmap(m_monitor_rect, *m_desktop_wallpaper_bitmap, m_desktop_wallpaper_bitmap->rect()); + screen_painter.draw_scaled_bitmap(screen_bitmap->rect(), *m_desktop_wallpaper_bitmap, m_desktop_wallpaper_bitmap->rect()); } else { ASSERT_NOT_REACHED(); } } + GUI::Painter painter(*this); + painter.add_clip_rect(event.rect()); + + painter.blit({ 0, 0 }, *m_monitor_bitmap, m_monitor_bitmap->rect()); + painter.draw_scaled_bitmap(m_monitor_rect, *screen_bitmap, screen_bitmap->rect()); + if (!m_desktop_resolution.is_null()) painter.draw_text(m_monitor_rect, m_desktop_resolution.to_string(), Gfx::TextAlignment::Center); } |