mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:17:34 +00:00
PaintBrush: Initial support for transparency. (#1883)
This commit is contained in:
parent
84317df579
commit
6a66207efa
4 changed files with 13 additions and 10 deletions
|
@ -55,9 +55,10 @@ static void flood_fill(Gfx::Bitmap& bitmap, const Gfx::Point& start_position, Co
|
||||||
while (!queue.is_empty()) {
|
while (!queue.is_empty()) {
|
||||||
auto position = queue.dequeue();
|
auto position = queue.dequeue();
|
||||||
|
|
||||||
if (bitmap.get_pixel<Gfx::BitmapFormat::RGB32>(position.x(), position.y()) != target_color)
|
if (bitmap.get_pixel<Gfx::BitmapFormat::RGBA32>(position.x(), position.y()) != target_color)
|
||||||
continue;
|
continue;
|
||||||
bitmap.set_pixel<Gfx::BitmapFormat::RGB32>(position.x(), position.y(), fill_color);
|
|
||||||
|
bitmap.set_pixel<Gfx::BitmapFormat::RGBA32>(position.x(), position.y(), fill_color);
|
||||||
|
|
||||||
if (position.x() != 0)
|
if (position.x() != 0)
|
||||||
queue.enqueue(position.translated(-1, 0));
|
queue.enqueue(position.translated(-1, 0));
|
||||||
|
|
|
@ -55,7 +55,7 @@ void EraseTool::on_mousedown(GUI::MouseEvent& event)
|
||||||
return;
|
return;
|
||||||
Gfx::Rect r = build_rect(event.position(), m_widget->bitmap().rect());
|
Gfx::Rect r = build_rect(event.position(), m_widget->bitmap().rect());
|
||||||
GUI::Painter painter(m_widget->bitmap());
|
GUI::Painter painter(m_widget->bitmap());
|
||||||
painter.fill_rect(r, get_color());
|
painter.clear_rect(r, get_color());
|
||||||
m_widget->update();
|
m_widget->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ void EraseTool::on_mousemove(GUI::MouseEvent& event)
|
||||||
if (event.buttons() & GUI::MouseButton::Left || event.buttons() & GUI::MouseButton::Right) {
|
if (event.buttons() & GUI::MouseButton::Left || event.buttons() & GUI::MouseButton::Right) {
|
||||||
Gfx::Rect r = build_rect(event.position(), m_widget->bitmap().rect());
|
Gfx::Rect r = build_rect(event.position(), m_widget->bitmap().rect());
|
||||||
GUI::Painter painter(m_widget->bitmap());
|
GUI::Painter painter(m_widget->bitmap());
|
||||||
painter.fill_rect(r, get_color());
|
painter.clear_rect(r, get_color());
|
||||||
m_widget->update();
|
m_widget->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,5 +112,5 @@ Color EraseTool::get_color() const
|
||||||
{
|
{
|
||||||
if (m_use_secondary_color)
|
if (m_use_secondary_color)
|
||||||
return m_widget->secondary_color();
|
return m_widget->secondary_color();
|
||||||
return Color(Color::White);
|
return Color(255, 255, 255, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Tool.h"
|
#include "Tool.h"
|
||||||
#include <LibGfx/Point.h>
|
|
||||||
#include <LibGUI/ActionGroup.h>
|
#include <LibGUI/ActionGroup.h>
|
||||||
|
#include <LibGfx/Point.h>
|
||||||
|
|
||||||
class EraseTool final : public Tool {
|
class EraseTool final : public Tool {
|
||||||
public:
|
public:
|
||||||
|
@ -45,7 +45,7 @@ private:
|
||||||
Gfx::Rect build_rect(const Gfx::Point& pos, const Gfx::Rect& widget_rect);
|
Gfx::Rect build_rect(const Gfx::Point& pos, const Gfx::Rect& widget_rect);
|
||||||
RefPtr<GUI::Menu> m_context_menu;
|
RefPtr<GUI::Menu> m_context_menu;
|
||||||
|
|
||||||
bool m_use_secondary_color { true };
|
bool m_use_secondary_color { false };
|
||||||
int m_thickness { 1 };
|
int m_thickness { 1 };
|
||||||
GUI::ActionGroup m_thickness_actions;
|
GUI::ActionGroup m_thickness_actions;
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,9 +26,9 @@
|
||||||
|
|
||||||
#include "PaintableWidget.h"
|
#include "PaintableWidget.h"
|
||||||
#include "Tool.h"
|
#include "Tool.h"
|
||||||
|
#include <LibGUI/Painter.h>
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <LibGfx/Palette.h>
|
#include <LibGfx/Palette.h>
|
||||||
#include <LibGUI/Painter.h>
|
|
||||||
|
|
||||||
static PaintableWidget* s_the;
|
static PaintableWidget* s_the;
|
||||||
|
|
||||||
|
@ -46,8 +46,8 @@ PaintableWidget::PaintableWidget()
|
||||||
pal.set_color(ColorRole::Window, Color::MidGray);
|
pal.set_color(ColorRole::Window, Color::MidGray);
|
||||||
set_palette(pal);
|
set_palette(pal);
|
||||||
set_background_color(Color::MidGray);
|
set_background_color(Color::MidGray);
|
||||||
m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGB32, { 600, 400 });
|
m_bitmap = Gfx::Bitmap::create(Gfx::BitmapFormat::RGBA32, { 600, 400 });
|
||||||
m_bitmap->fill(Color::White);
|
m_bitmap->fill(Color(255, 255, 255, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
PaintableWidget::~PaintableWidget()
|
PaintableWidget::~PaintableWidget()
|
||||||
|
@ -57,7 +57,9 @@ PaintableWidget::~PaintableWidget()
|
||||||
void PaintableWidget::paint_event(GUI::PaintEvent& event)
|
void PaintableWidget::paint_event(GUI::PaintEvent& event)
|
||||||
{
|
{
|
||||||
GUI::Painter painter(*this);
|
GUI::Painter painter(*this);
|
||||||
|
|
||||||
painter.add_clip_rect(event.rect());
|
painter.add_clip_rect(event.rect());
|
||||||
|
painter.fill_rect_with_checkerboard(m_bitmap->rect(), { 8, 8 }, palette().base().darkened(0.9), palette().base());
|
||||||
painter.blit({ 0, 0 }, *m_bitmap, m_bitmap->rect());
|
painter.blit({ 0, 0 }, *m_bitmap, m_bitmap->rect());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue