mirror of
https://github.com/RGBCube/serenity
synced 2025-05-25 22:35:07 +00:00

This commit adds a Tool::MouseEvent struct, which contains events that may be needed by tools: layer-relative, image-relative and raw (editor- relative) event. The raw event is used by ZoomTool to properly pan the view. This fixes a bug which caused image to snap out of sight.
33 lines
733 B
C++
33 lines
733 B
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include "PickerTool.h"
|
|
#include "ImageEditor.h"
|
|
#include "Layer.h"
|
|
|
|
namespace PixelPaint {
|
|
|
|
PickerTool::PickerTool()
|
|
{
|
|
}
|
|
|
|
PickerTool::~PickerTool()
|
|
{
|
|
}
|
|
|
|
void PickerTool::on_mousedown(Layer& layer, MouseEvent& event)
|
|
{
|
|
auto& layer_event = event.layer_event();
|
|
if (!layer.rect().contains(layer_event.position()))
|
|
return;
|
|
auto color = layer.bitmap().get_pixel(layer_event.position());
|
|
if (layer_event.button() == GUI::MouseButton::Left)
|
|
m_editor->set_primary_color(color);
|
|
else if (layer_event.button() == GUI::MouseButton::Right)
|
|
m_editor->set_secondary_color(color);
|
|
}
|
|
|
|
}
|