1// Aseprite Document Library
2// Copyright (c) 2018 David Capello
3//
4// This file is released under the terms of the MIT license.
5// Read LICENSE.txt for more information.
6
7#ifdef HAVE_CONFIG_H
8#include "config.h"
9#endif
10
11#include "doc/algorithm/stroke_selection.h"
12
13#include "doc/algorithm/fill_selection.h"
14#include "doc/algorithm/modify_selection.h"
15#include "doc/mask.h"
16
17namespace doc {
18namespace algorithm {
19
20void stroke_selection(Image* image,
21 const gfx::Rect& imageBounds,
22 const Mask* origMask,
23 const color_t color,
24 const Grid* grid)
25{
26 ASSERT(origMask);
27 ASSERT(origMask->bitmap());
28 if (!origMask || !origMask->bitmap())
29 return;
30
31 gfx::Rect bounds = origMask->bounds();
32 if (bounds.isEmpty())
33 return;
34
35 Mask mask;
36 mask.reserve(bounds);
37 mask.freeze();
38 modify_selection(
39 SelectionModifier::Border,
40 origMask, &mask, 1,
41 BrushType::kCircleBrushType);
42 mask.unfreeze();
43
44 // Both mask must have the same bounds.
45 ASSERT(mask.bounds() == origMask->bounds());
46
47 if (mask.bitmap())
48 fill_selection(image, imageBounds, &mask, color, grid);
49}
50
51} // namespace algorithm
52} // namespace app
53