ladybird/Userland/Applications/DisplaySettings/MonitorWidget.h
Andreas Kling 3046b3467c DisplaySettings: Improve wallpaper preview code
Previously, this code would create a bitmap with the size of the screen
resolution, draw the new wallpaper into it, and then scale it down for
display inside the MonitorWidget.

This was done on every paint event, which made the code quite slow and
allocation-happy.

Instead of this, we now scale down the new wallpaper to a miniature
of the same scale as the little MonitorWidget screen. The miniature is
then used for tiling, etc. The miniature is cached and reused across
paint events if nothing else changes.
2021-05-20 17:52:38 +02:00

53 lines
1.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (c) 2020, Hüseyin Aslıtürk <asliturk@hotmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibGUI/Widget.h>
namespace DisplaySettings {
class MonitorWidget final : public GUI::Widget {
C_OBJECT(MonitorWidget);
public:
bool set_wallpaper(String path);
String wallpaper();
void set_wallpaper_mode(String mode);
String wallpaper_mode();
void set_desktop_resolution(Gfx::IntSize resolution);
Gfx::IntSize desktop_resolution();
void set_desktop_scale_factor(int scale_factor) { m_desktop_scale_factor = scale_factor; }
int desktop_scale_factor() const { return m_desktop_scale_factor; }
void set_background_color(Gfx::Color background_color);
Gfx::Color background_color();
private:
MonitorWidget();
void redraw_desktop_if_needed();
virtual void paint_event(GUI::PaintEvent& event) override;
Gfx::IntRect m_monitor_rect;
RefPtr<Gfx::Bitmap> m_monitor_bitmap;
RefPtr<Gfx::Bitmap> m_desktop_bitmap;
bool m_desktop_dirty { true };
String m_desktop_wallpaper_path;
RefPtr<Gfx::Bitmap> m_wallpaper_bitmap;
String m_desktop_wallpaper_mode;
Gfx::IntSize m_desktop_resolution;
int m_desktop_scale_factor { 1 };
Gfx::Color m_desktop_color;
};
}