Skip to content

Commit

Permalink
Implementation of dacap suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Gasparoken committed Oct 28, 2024
1 parent 6edd5f9 commit d280862
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 126 deletions.
2 changes: 1 addition & 1 deletion src/app/tools/ink.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ namespace app {

// Called for each point shape.
virtual void prepareForPointShape(ToolLoop* loop, bool firstPoint, int x, int y,
doc::SymmetryIndex summetry) { }
doc::SymmetryIndex symmetry) { }
virtual void prepareVForPointShape(ToolLoop* loop, int y) { }
virtual void prepareUForPointShapeWholeScanline(ToolLoop* loop, int x1) { }
virtual void prepareUForPointShapeSlicedScanline(ToolLoop* loop, bool leftSlice, int x1) { }
Expand Down
180 changes: 93 additions & 87 deletions src/app/tools/ink_processing.h

Large diffs are not rendered by default.

15 changes: 5 additions & 10 deletions src/app/tools/point_shapes.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "app/util/wrap_point.h"

#include "app/tools/ink.h"
#include "app/tools/symmetry.h"
#include "doc/algorithm/flip_image.h"
#include "doc/primitives.h"
#include "render/gradient.h"
Expand Down Expand Up @@ -218,10 +219,7 @@ class BrushPointShape : public PointShape {
}

if (brush->type() == kImageBrushType &&
(pt.symmetry == doc::SymmetryIndex::ROTATED_90 ||
pt.symmetry == doc::SymmetryIndex::ROTATED_270 ||
pt.symmetry == doc::SymmetryIndex::ROT_FLIP_90 ||
pt.symmetry == doc::SymmetryIndex::ROT_FLIP_270)) {
does_symmetry_rotate_image(pt.symmetry)) {
x += brush->bounds().y;
y += brush->bounds().x;
}
Expand Down Expand Up @@ -268,10 +266,7 @@ class BrushPointShape : public PointShape {
void getModifiedArea(ToolLoop* loop, int x, int y,
doc::SymmetryIndex symmetry, Rect& area) override {
auto bounds = loop->getBrush()->bounds();
if (symmetry == doc::SymmetryIndex::ROTATED_90 ||
symmetry == doc::SymmetryIndex::ROTATED_270 ||
symmetry == doc::SymmetryIndex::ROT_FLIP_90 ||
symmetry == doc::SymmetryIndex::ROT_FLIP_270)
if (does_symmetry_rotate_image(symmetry))
area = gfx::Rect(bounds.y, bounds.x, bounds.h, bounds.w);
else
area = bounds;
Expand All @@ -280,8 +275,8 @@ class BrushPointShape : public PointShape {
}

private:
CompressedImage& getCompressedImage(doc::SymmetryIndex index) {//symmetryMode
auto& compressPtr = m_compressedImages[index];
CompressedImage& getCompressedImage(doc::SymmetryIndex index) {
auto& compressPtr = m_compressedImages[int(index)];
if (!compressPtr) {
compressPtr.reset(new CompressedImage(m_lastBrush->getSymmetryImage(index),
m_lastBrush->getSymmetryMask(index),
Expand Down
10 changes: 4 additions & 6 deletions src/app/tools/symmetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,13 @@ void Symmetry::calculateSymmetricalStroke(const Stroke& refStroke,
gfx::Point brushCenter(0, 0);
auto brush = loop->getBrush();
if (!loop->getPointShape()->isFloodFill()) {
if (symmetry == doc::SymmetryIndex::ORIGINAL ||
symmetry == doc::SymmetryIndex::FLIPPED_X ||
symmetry == doc::SymmetryIndex::FLIPPED_Y ||
symmetry == doc::SymmetryIndex::FLIPPED_XY) {
if (!does_symmetry_rotate_image(symmetry)) {
brushSize = brush->bounds().size();
brushCenter = brush->center();
}
else {
brushSize = gfx::Size(brush->bounds().size().h,
brush->bounds().size().w);
brushSize = gfx::Size(brush->bounds().h,
brush->bounds().w);
brushCenter = gfx::Point(brush->center().y,
brush->center().x);
}
Expand Down Expand Up @@ -171,6 +168,7 @@ void Symmetry::calculateSymmetricalStroke(const Stroke& refStroke,
}
default:
pt2.y = 2 * (m_y + brushCenter.y) - pt.y - brushSize.h;
break;
}
stroke.addPoint(pt2);
}
Expand Down
7 changes: 7 additions & 0 deletions src/app/tools/symmetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ namespace tools {

class ToolLoop;

static inline bool does_symmetry_rotate_image(doc::SymmetryIndex symmetry) {
return symmetry == doc::SymmetryIndex::ROTATED_90 ||
symmetry == doc::SymmetryIndex::ROTATED_270 ||
symmetry == doc::SymmetryIndex::ROT_FLIP_90 ||
symmetry == doc::SymmetryIndex::ROT_FLIP_270;
}

class Symmetry {
public:
Symmetry(gen::SymmetryMode symmetryMode, double x, double y)
Expand Down
1 change: 0 additions & 1 deletion src/app/ui/context_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2475,7 +2475,6 @@ void ContextBar::setActiveBrushBySlot(tools::Tool* tool, int slot)
// the slot.
if (brush.hasFlag(BrushSlot::Flags::ImageColor))
brush.brush()->resetImageColors();
brush.brush()->resetSymmetries();
setActiveBrush(brush.brush());
}
else {
Expand Down
25 changes: 9 additions & 16 deletions src/doc/brush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ void Brush::setImage(const Image* image,
m_backupImage.reset();
m_mainColor.reset();
m_bgColor.reset();
resetSymmetries();

resetBounds();
}
Expand Down Expand Up @@ -297,7 +296,6 @@ void Brush::resetImageColors()
m_image.reset(Image::createCopy(m_backupImage.get()));
m_mainColor.reset();
m_bgColor.reset();
resetSymmetries();
}
}

Expand All @@ -316,7 +314,6 @@ void Brush::clean()
m_image.reset();
m_maskBitmap.reset();
m_backupImage.reset();
resetSymmetries();
}

static void algo_hline(int x1, int y, int x2, void *data)
Expand All @@ -326,18 +323,14 @@ static void algo_hline(int x1, int y, int x2, void *data)

void Brush::resetSymmetries()
{
if (m_symmetryImages.empty()) {
for (int i=0; i<8; i++) {
m_symmetryImages.push_back(ImageRef());
m_symmetryMasks.push_back(ImageRef());
}
}
else {
for (int i=0; i<8; i++) {
m_symmetryImages[i].reset();
m_symmetryMasks[i].reset();
}
}
m_symmetryImages.resize(0);
m_symmetryMasks.resize(0);
}

void Brush::reserveSymmetries()
{
m_symmetryImages.resize(int(SymmetryIndex::ELEMENTS));
m_symmetryMasks.resize(int(SymmetryIndex::ELEMENTS));
}

Image* Brush::getSymmetryImage(const SymmetryIndex index)
Expand All @@ -346,7 +339,7 @@ Image* Brush::getSymmetryImage(const SymmetryIndex index)
return m_image.get();

if (m_symmetryImages.empty())
resetSymmetries();
reserveSymmetries();

if (!m_symmetryImages[index]) {
switch (index) {
Expand Down
4 changes: 3 additions & 1 deletion src/doc/brush.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ namespace doc {
ROTATED_270 = 4,
ROT_FLIP_90 = 5,
ROTATED_90 = 6,
ROT_FLIP_270 = 7
ROT_FLIP_270 = 7,
ELEMENTS = 8
};

class Brush;
Expand Down Expand Up @@ -105,6 +106,7 @@ namespace doc {
}

void resetSymmetries();
void reserveSymmetries();
Image* getSymmetryImage(const SymmetryIndex index);
Image* getSymmetryMask(const SymmetryIndex index);

Expand Down
8 changes: 4 additions & 4 deletions tests/scripts/tools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,8 @@ function drawing_with_symmetry(imageColorMode, colorInImage,
expect_eq(cel.bounds, Rectangle(0, 0, 8, 3))
expect_img(cel.image,
{ 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0 })
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0 })

local b = Brush { size=1 }
app.fgColor = c
Expand Down Expand Up @@ -457,7 +457,7 @@ function drawing_with_symmetry(imageColorMode, colorInImage,
expect_eq(cel.bounds, Rectangle(0, 0, 8, 3))
expect_img(cel.image,
{ 0, c, 0, 0, 0, 0, c, 0,
c, c, c, 0, 0, c, c, c,
c, c, c, 0, 0, c, c, c,
0, c, 0, 0, 0, 0, c, 0 })
app.undo()

Expand All @@ -467,7 +467,7 @@ function drawing_with_symmetry(imageColorMode, colorInImage,
expect_eq(cel.bounds, Rectangle(1, 0, 6, 3))
expect_img(cel.image,
{ 0, c, 0, 0, c, 0,
c, c, c, c, c, c,
c, c, c, c, c, c,
0, c, 0, 0, c, 0 })
app.undo()

Expand Down

0 comments on commit d280862

Please sign in to comment.