1 // Aseprite
2 // Copyright (C) 2001-2018  David Capello
3 //
4 // This program is distributed under the terms of
5 // the End-User License Agreement for Aseprite.
6 
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif
10 
11 #include "app/tools/intertwine.h"
12 
13 #include "app/tools/point_shape.h"
14 #include "app/tools/stroke.h"
15 #include "app/tools/symmetry.h"
16 #include "app/tools/tool_loop.h"
17 #include "doc/algo.h"
18 
19 namespace app {
20 namespace tools {
21 
22 using namespace gfx;
23 using namespace doc;
24 
getStrokeBounds(ToolLoop * loop,const Stroke & stroke)25 gfx::Rect Intertwine::getStrokeBounds(ToolLoop* loop, const Stroke& stroke)
26 {
27   return stroke.bounds();
28 }
29 
doPointshapePoint(int x,int y,ToolLoop * loop)30 void Intertwine::doPointshapePoint(int x, int y, ToolLoop* loop)
31 {
32   Symmetry* symmetry = loop->getSymmetry();
33   if (symmetry) {
34     // Convert the point to the sprite position so we can apply the
35     // symmetry transformation.
36     Stroke main_stroke;
37     main_stroke.addPoint(Point(x, y));
38 
39     Strokes strokes;
40     symmetry->generateStrokes(main_stroke, strokes, loop);
41     for (const auto& stroke : strokes) {
42       // We call transformPoint() moving back each point to the cel
43       // origin.
44       loop->getPointShape()->transformPoint(
45         loop, stroke[0].x, stroke[0].y);
46     }
47   }
48   else {
49     loop->getPointShape()->transformPoint(loop, x, y);
50   }
51 }
52 
doPointshapeHline(int x1,int y,int x2,ToolLoop * loop)53 void Intertwine::doPointshapeHline(int x1, int y, int x2, ToolLoop* loop)
54 {
55   algo_line(x1, y, x2, y, loop, (AlgoPixel)doPointshapePoint);
56 }
57 
doPointshapeLine(int x1,int y1,int x2,int y2,ToolLoop * loop)58 void Intertwine::doPointshapeLine(int x1, int y1, int x2, int y2, ToolLoop* loop)
59 {
60   algo_line(x1, y1, x2, y2, loop, (AlgoPixel)doPointshapePoint);
61 }
62 
63 } // namespace tools
64 } // namespace app
65