mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:27:43 +00:00
ThemeEditor: Implement a way to simulate color blindness in preview
Implement a mechanism that allows us to alter colors so that they mimic those a colorblind person would see. From the color we can then alter the colors for the whole preview so we can simulate everything in the theme including icons/decorations. This filter is also available as a Filter in LibGfx so it can be reused in multiple other places. The color simulation algorithm is based on this one https://github.com/MaPePeR/jsColorblindSimulator publicly available.
This commit is contained in:
parent
1c05d39abc
commit
ebaf211260
7 changed files with 289 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2021, Antonio Di Stefano <tonio9681@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -20,6 +21,7 @@
|
|||
#include <LibGUI/TextEditor.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibGfx/WindowTheme.h>
|
||||
#include <WindowServer/Compositor.h>
|
||||
|
||||
namespace ThemeEditor {
|
||||
|
||||
|
@ -152,6 +154,12 @@ void PreviewWidget::set_theme_from_file(String const& path, int fd)
|
|||
on_theme_load_from_file(path);
|
||||
}
|
||||
|
||||
void PreviewWidget::set_color_filter(OwnPtr<Gfx::ColorBlindnessFilter> color_filter)
|
||||
{
|
||||
m_color_filter = move(color_filter);
|
||||
repaint();
|
||||
}
|
||||
|
||||
void PreviewWidget::paint_event(GUI::PaintEvent& event)
|
||||
{
|
||||
GUI::Frame::paint_event(event);
|
||||
|
@ -219,6 +227,24 @@ void PreviewWidget::paint_event(GUI::PaintEvent& event)
|
|||
paint_window("Active window", active_rect, Gfx::WindowTheme::WindowState::Active, *m_inactive_window_icon);
|
||||
}
|
||||
|
||||
void PreviewWidget::second_paint_event(GUI::PaintEvent&)
|
||||
{
|
||||
if (!m_color_filter)
|
||||
return;
|
||||
|
||||
GUI::Painter painter(*this);
|
||||
|
||||
auto target = painter.target();
|
||||
auto bitmap_clone_or_error = target->clone();
|
||||
if (bitmap_clone_or_error.is_error())
|
||||
return;
|
||||
|
||||
auto clone = bitmap_clone_or_error.release_value();
|
||||
auto rect = target->rect();
|
||||
|
||||
m_color_filter->apply(*target, rect, *clone, rect);
|
||||
}
|
||||
|
||||
void PreviewWidget::resize_event(GUI::ResizeEvent&)
|
||||
{
|
||||
m_gallery->set_relative_rect(Gfx::IntRect(0, 0, 320, 240).centered_within(rect()).translated(0, 20));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue