|
@@ -11,6 +11,7 @@
|
|
#include "../Layer.h"
|
|
#include "../Layer.h"
|
|
#include <LibGUI/Action.h>
|
|
#include <LibGUI/Action.h>
|
|
#include <LibGUI/Menu.h>
|
|
#include <LibGUI/Menu.h>
|
|
|
|
+#include <LibGUI/Painter.h>
|
|
#include <LibGUI/Window.h>
|
|
#include <LibGUI/Window.h>
|
|
|
|
|
|
namespace PixelPaint {
|
|
namespace PixelPaint {
|
|
@@ -56,6 +57,22 @@ void MoveTool::on_mousemove(Layer* layer, MouseEvent& event)
|
|
m_editor->update_tool_cursor();
|
|
m_editor->update_tool_cursor();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (m_scaling) {
|
|
|
|
+ auto& cursor_location = event.image_event().position();
|
|
|
|
+ auto width = abs(m_layer_being_moved->location().x() - cursor_location.x());
|
|
|
|
+ auto height = abs(m_layer_being_moved->location().y() - cursor_location.y());
|
|
|
|
+ if (m_keep_ascept_ratio) {
|
|
|
|
+ if (abs(width - m_layer_being_moved->size().width()) > abs(height - m_layer_being_moved->size().height())) {
|
|
|
|
+ height = width * m_layer_being_moved->size().height() / m_layer_being_moved->size().width();
|
|
|
|
+ } else {
|
|
|
|
+ width = height * m_layer_being_moved->size().width() / m_layer_being_moved->size().height();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ m_new_layer_size = Gfx::IntSize(width, height);
|
|
|
|
+ // TODO: Change this according to which direction the user is scaling
|
|
|
|
+ m_new_scaled_layer_location = Gfx::IntPoint(m_layer_being_moved->location().x(), m_layer_being_moved->location().y());
|
|
|
|
+ }
|
|
|
|
+
|
|
auto& image_event = event.image_event();
|
|
auto& image_event = event.image_event();
|
|
if (!m_layer_being_moved || m_scaling)
|
|
if (!m_layer_being_moved || m_scaling)
|
|
return;
|
|
return;
|
|
@@ -80,21 +97,20 @@ void MoveTool::on_mouseup(Layer* layer, MouseEvent& event)
|
|
return;
|
|
return;
|
|
|
|
|
|
if (m_scaling) {
|
|
if (m_scaling) {
|
|
- auto& cursor_location = event.image_event().position();
|
|
|
|
-
|
|
|
|
- auto new_size = Gfx::IntSize(abs(m_layer_being_moved->location().x() - cursor_location.x()), abs(m_layer_being_moved->location().y() - cursor_location.y()));
|
|
|
|
- // TODO: Change this according to which direction the user is scaling
|
|
|
|
- auto new_location = Gfx::IntPoint(m_layer_being_moved->location().x(), m_layer_being_moved->location().y());
|
|
|
|
- m_editor->active_layer()->resize(new_size, new_location, Gfx::Painter::ScalingMode::BilinearBlend);
|
|
|
|
|
|
+ m_editor->active_layer()->resize(m_new_layer_size, m_new_scaled_layer_location, Gfx::Painter::ScalingMode::BilinearBlend);
|
|
}
|
|
}
|
|
|
|
|
|
m_scaling = false;
|
|
m_scaling = false;
|
|
m_layer_being_moved = nullptr;
|
|
m_layer_being_moved = nullptr;
|
|
|
|
+ m_editor->update_tool_cursor();
|
|
m_editor->did_complete_action(tool_name());
|
|
m_editor->did_complete_action(tool_name());
|
|
}
|
|
}
|
|
|
|
|
|
void MoveTool::on_keydown(GUI::KeyEvent& event)
|
|
void MoveTool::on_keydown(GUI::KeyEvent& event)
|
|
{
|
|
{
|
|
|
|
+ if (event.key() == Key_Shift)
|
|
|
|
+ m_keep_ascept_ratio = true;
|
|
|
|
+
|
|
if (m_scaling)
|
|
if (m_scaling)
|
|
return;
|
|
return;
|
|
|
|
|
|
@@ -128,6 +144,12 @@ void MoveTool::on_keydown(GUI::KeyEvent& event)
|
|
m_editor->layers_did_change();
|
|
m_editor->layers_did_change();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void MoveTool::on_keyup(GUI::KeyEvent& event)
|
|
|
|
+{
|
|
|
|
+ if (event.key() == Key_Shift)
|
|
|
|
+ m_keep_ascept_ratio = false;
|
|
|
|
+}
|
|
|
|
+
|
|
Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> MoveTool::cursor()
|
|
Variant<Gfx::StandardCursor, NonnullRefPtr<Gfx::Bitmap>> MoveTool::cursor()
|
|
{
|
|
{
|
|
if (m_mouse_in_resize_corner || m_scaling)
|
|
if (m_mouse_in_resize_corner || m_scaling)
|