1 // Aseprite
2 // Copyright (C) 2001-2015  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/point_shape.h"
12 
13 #include "app/tools/ink.h"
14 #include "app/tools/tool_loop.h"
15 #include "app/util/wrap_value.h"
16 #include "doc/image.h"
17 
18 namespace app {
19 namespace tools {
20 
21 using namespace doc;
22 using namespace filters;
23 
doInkHline(int x1,int y,int x2,ToolLoop * loop)24 void PointShape::doInkHline(int x1, int y, int x2, ToolLoop* loop)
25 {
26   TiledMode tiledMode = loop->getTiledMode();
27   int x, w, size; // width or height
28 
29   // In case the ink needs original cel coordinates, we have to
30   // translate the x1/y/x2 coordinate.
31   if (loop->getInk()->needsCelCoordinates()) {
32     gfx::Point origin = loop->getCelOrigin();
33     x1 -= origin.x;
34     x2 -= origin.x;
35     y -= origin.y;
36   }
37 
38   // Tiled in Y axis
39   if (int(tiledMode) & int(TiledMode::Y_AXIS)) {
40     size = loop->getDstImage()->height();      // size = image height
41     y = wrap_value(y, size);
42   }
43   else if (y < 0 || y >= loop->getDstImage()->height())
44     return;
45 
46   // Tiled in X axis
47   if (int(tiledMode) & int(TiledMode::X_AXIS)) {
48     if (x1 > x2)
49       return;
50 
51     size = loop->getDstImage()->width();      // size = image width
52     w = x2-x1+1;
53     if (w >= size)
54       loop->getInk()->inkHline(0, y, size-1, loop);
55     else {
56       x = x1;
57       x = wrap_value(x, size);
58 
59       if (x+w-1 <= size-1)
60         loop->getInk()->inkHline(x, y, x+w-1, loop);
61       else {
62         loop->getInk()->inkHline(x, y, size-1, loop);
63         loop->getInk()->inkHline(0, y, w-(size-x)-1, loop);
64       }
65     }
66   }
67   // Clipped in X axis
68   else {
69     if (x1 < 0)
70       x1 = 0;
71 
72     if (x2 >= loop->getDstImage()->width())
73       x2 = loop->getDstImage()->width()-1;
74 
75     if (x2-x1+1 < 1)
76       return;
77 
78     loop->getInk()->inkHline(x1, y, x2, loop);
79   }
80 }
81 
82 } // namespace tools
83 } // namespace app
84