Skip to content
Snippets Groups Projects
Commit 515bbe45 authored by Daniel Müller's avatar Daniel Müller
Browse files

* Drawing tools are now more precise when zoomed

parent be39d45d
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,7 @@ PixelsDraftItemNode::PixelsDraftItemNode(ImageEditorScene* scene, const std::sha ...@@ -21,7 +21,7 @@ PixelsDraftItemNode::PixelsDraftItemNode(ImageEditorScene* scene, const std::sha
bool PixelsDraftItemNode::contains(const QPointF& point) const bool PixelsDraftItemNode::contains(const QPointF& point) const
{ {
if (auto draftItem = pixelsDraftItem()) // Make sure that the underlying draft item still exists if (auto draftItem = pixelsDraftItem()) // Make sure that the underlying draft item still exists
return draftItem->pixelsData().isSet(point.toPoint()); return draftItem->pixelsData().isSet(MathUtils::floor(point));
else else
return DraftItemNode::contains(point); return DraftItemNode::contains(point);
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "Grinder.h" #include "Grinder.h"
#include "FloodFillTool.h" #include "FloodFillTool.h"
#include "ui/image/ImageEditor.h" #include "ui/image/ImageEditor.h"
#include "util/MathUtils.h"
#include "res/Resources.h" #include "res/Resources.h"
const char* FloodFillTool::tool_type = "FloodFillTool"; const char* FloodFillTool::tool_type = "FloodFillTool";
...@@ -34,13 +35,13 @@ void FloodFillTool::createProperties() ...@@ -34,13 +35,13 @@ void FloodFillTool::createProperties()
ImageEditorTool::InputEventResult FloodFillTool::mousePressed(const QGraphicsSceneMouseEvent* event) ImageEditorTool::InputEventResult FloodFillTool::mousePressed(const QGraphicsSceneMouseEvent* event)
{ {
floodFill(event->scenePos().toPoint()); floodFill(MathUtils::floor(event->scenePos()));
return InputEventResult::Process; return InputEventResult::Process;
} }
VisualSceneInputHandler::InputEventResult FloodFillTool::rightMousePressed(const QGraphicsSceneMouseEvent* event) VisualSceneInputHandler::InputEventResult FloodFillTool::rightMousePressed(const QGraphicsSceneMouseEvent* event)
{ {
floodFill(event->scenePos().toPoint(), true); floodFill(MathUtils::floor(event->scenePos()), true);
return InputEventResult::Process; return InputEventResult::Process;
} }
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "PaintbrushTool.h" #include "PaintbrushTool.h"
#include "ui/image/ImageEditor.h" #include "ui/image/ImageEditor.h"
#include "image/ImageUtils.h" #include "image/ImageUtils.h"
#include "util/MathUtils.h"
#include "res/Resources.h" #include "res/Resources.h"
const char* PaintbrushTool::tool_type = "PaintbrushTool"; const char* PaintbrushTool::tool_type = "PaintbrushTool";
...@@ -35,7 +36,7 @@ void PaintbrushTool::createProperties() ...@@ -35,7 +36,7 @@ void PaintbrushTool::createProperties()
ImageEditorTool::InputEventResult PaintbrushTool::mousePressed(const QGraphicsSceneMouseEvent* event) ImageEditorTool::InputEventResult PaintbrushTool::mousePressed(const QGraphicsSceneMouseEvent* event)
{ {
auto pos = event->scenePos().toPoint(); auto pos = MathUtils::floor(event->scenePos());
_lastPixelPos = pos; _lastPixelPos = pos;
paintPixel(pos, _eraseByDefault); paintPixel(pos, _eraseByDefault);
return InputEventResult::Process; return InputEventResult::Process;
...@@ -43,7 +44,7 @@ ImageEditorTool::InputEventResult PaintbrushTool::mousePressed(const QGraphicsSc ...@@ -43,7 +44,7 @@ ImageEditorTool::InputEventResult PaintbrushTool::mousePressed(const QGraphicsSc
ImageEditorTool::InputEventResult PaintbrushTool::mouseMoved(const QGraphicsSceneMouseEvent* event) ImageEditorTool::InputEventResult PaintbrushTool::mouseMoved(const QGraphicsSceneMouseEvent* event)
{ {
auto pos = event->scenePos().toPoint(); auto pos = MathUtils::floor(event->scenePos());
paintPixel(pos, _eraseByDefault); paintPixel(pos, _eraseByDefault);
_lastPixelPos = pos; _lastPixelPos = pos;
return InputEventResult::Process; return InputEventResult::Process;
...@@ -51,7 +52,7 @@ ImageEditorTool::InputEventResult PaintbrushTool::mouseMoved(const QGraphicsScen ...@@ -51,7 +52,7 @@ ImageEditorTool::InputEventResult PaintbrushTool::mouseMoved(const QGraphicsScen
VisualSceneInputHandler::InputEventResult PaintbrushTool::rightMousePressed(const QGraphicsSceneMouseEvent* event) VisualSceneInputHandler::InputEventResult PaintbrushTool::rightMousePressed(const QGraphicsSceneMouseEvent* event)
{ {
auto pos = event->scenePos().toPoint(); auto pos = MathUtils::floor(event->scenePos());
_lastPixelPos = pos; _lastPixelPos = pos;
paintPixel(pos, !_eraseByDefault); paintPixel(pos, !_eraseByDefault);
return InputEventResult::Process; return InputEventResult::Process;
...@@ -59,7 +60,7 @@ VisualSceneInputHandler::InputEventResult PaintbrushTool::rightMousePressed(cons ...@@ -59,7 +60,7 @@ VisualSceneInputHandler::InputEventResult PaintbrushTool::rightMousePressed(cons
VisualSceneInputHandler::InputEventResult PaintbrushTool::rightMouseMoved(const QGraphicsSceneMouseEvent* event) VisualSceneInputHandler::InputEventResult PaintbrushTool::rightMouseMoved(const QGraphicsSceneMouseEvent* event)
{ {
auto pos = event->scenePos().toPoint(); auto pos = MathUtils::floor(event->scenePos());
paintPixel(pos, !_eraseByDefault); paintPixel(pos, !_eraseByDefault);
_lastPixelPos = pos; _lastPixelPos = pos;
return InputEventResult::Process; return InputEventResult::Process;
......
...@@ -11,3 +11,13 @@ double MathUtils::vectorLength(double x, double y) ...@@ -11,3 +11,13 @@ double MathUtils::vectorLength(double x, double y)
// Simple L2 norm // Simple L2 norm
return std::sqrt(x * x + y * y); return std::sqrt(x * x + y * y);
} }
QPoint MathUtils::ceil(QPointF pos)
{
return QPoint{static_cast<int>(std::ceil(pos.x())), static_cast<int>(std::ceil(pos.y()))};
}
QPoint MathUtils::floor(QPointF pos)
{
return QPoint{static_cast<int>(std::floor(pos.x())), static_cast<int>(std::floor(pos.y()))};
}
...@@ -18,6 +18,9 @@ namespace grndr ...@@ -18,6 +18,9 @@ namespace grndr
template<typename T> template<typename T>
static T clamp(T& val, T min, T max) { if (val < min) val = min; if (val > max) val = max; return val; } static T clamp(T& val, T min, T max) { if (val < min) val = min; if (val > max) val = max; return val; }
static QPoint ceil(QPointF pos);
static QPoint floor(QPointF pos);
private: private:
MathUtils() { } MathUtils() { }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment