1// Aseprite
2// Copyright (C) 2001-2016 David Capello
3//
4// This program is distributed under the terms of
5// the End-User License Agreement for Aseprite.
6
7#ifndef APP_BRUSH_SLOT_H_INCLUDED
8#define APP_BRUSH_SLOT_H_INCLUDED
9#pragma once
10
11#include "app/color.h"
12#include "app/shade.h"
13#include "app/tools/ink_type.h"
14#include "doc/brush.h"
15
16namespace app {
17
18// Custom brush slot
19class BrushSlot {
20public:
21 enum class Flags {
22 Locked = 0x0001,
23 BrushType = 0x0002,
24 BrushSize = 0x0004,
25 BrushAngle = 0x0008,
26 FgColor = 0x0010,
27 BgColor = 0x0020,
28 InkType = 0x0040,
29 InkOpacity = 0x0080,
30 Shade = 0x0100,
31 PixelPerfect = 0x0200,
32 ImageColor = 0x0400,
33 };
34
35 BrushSlot(Flags flags = Flags(0),
36 const doc::BrushRef& brush = doc::BrushRef(nullptr),
37 const app::Color& fgColor = app::Color::fromMask(),
38 const app::Color& bgColor = app::Color::fromMask(),
39 tools::InkType inkType = tools::InkType::DEFAULT,
40 int inkOpacity = 255,
41 const Shade& shade = Shade(),
42 bool pixelPerfect = false)
43 : m_flags(flags)
44 , m_brush(brush)
45 , m_fgColor(fgColor)
46 , m_bgColor(bgColor)
47 , m_inkType(inkType)
48 , m_inkOpacity(inkOpacity)
49 , m_shade(shade)
50 , m_pixelPerfect(pixelPerfect) {
51 }
52
53 Flags flags() const { return m_flags; }
54 void setFlags(Flags flags) { m_flags = flags; }
55
56 bool isEmpty() const {
57 return int(m_flags) == 0;
58 }
59
60 bool hasFlag(Flags flag) const {
61 return ((int(m_flags) & int(flag)) == int(flag));
62 }
63
64 bool hasBrush() const {
65 return
66 (brush() &&
67 (hasFlag(Flags::BrushType) ||
68 hasFlag(Flags::BrushSize) ||
69 hasFlag(Flags::BrushAngle)));
70 }
71
72 // Can be null if the user deletes the brush.
73 doc::BrushRef brush() const { return m_brush; }
74 app::Color fgColor() const { return m_fgColor; }
75 app::Color bgColor() const { return m_bgColor; }
76 tools::InkType inkType() const { return m_inkType; }
77 int inkOpacity() const { return m_inkOpacity; }
78 const Shade& shade() const { return m_shade; }
79 bool pixelPerfect() const { return m_pixelPerfect; }
80
81 // True if the user locked the brush using the shortcut key to
82 // access it.
83 bool locked() const {
84 return hasFlag(Flags::Locked);
85 }
86
87 void setLocked(bool locked) {
88 if (locked)
89 m_flags = static_cast<Flags>(int(m_flags) | int(Flags::Locked));
90 else
91 m_flags = static_cast<Flags>(int(m_flags) & ~int(Flags::Locked));
92 }
93
94private:
95 Flags m_flags;
96 doc::BrushRef m_brush;
97 app::Color m_fgColor;
98 app::Color m_bgColor;
99 tools::InkType m_inkType;
100 int m_inkOpacity;
101 Shade m_shade;
102 bool m_pixelPerfect;
103};
104
105} // namespace app
106
107#endif
108