1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
13 #include <docmodel/dllapi.h>
15 #include <docmodel/theme/ThemeColorType.hxx>
16 #include <docmodel/color/Transformation.hxx>
17 #include <tools/color.hxx>
21 /** Definition of a theme color
23 * A theme color is defined by the type of theme color and a set of
24 * transformations that in addition manipulate the resulting color
25 * (i.e. tints, shades).
27 class DOCMODEL_DLLPUBLIC ThemeColor
29 ThemeColorType meType
= ThemeColorType::Unknown
;
30 std::vector
<Transformation
> maTransformations
;
33 ThemeColor() = default;
35 ThemeColorType
getType() const { return meType
; }
37 void setType(ThemeColorType eType
) { meType
= eType
; }
39 void clearTransformations() { maTransformations
.clear(); }
41 void setTransformations(std::vector
<Transformation
> const& rTransformations
)
43 maTransformations
= rTransformations
;
46 void addTransformation(Transformation
const& rTransform
)
48 maTransformations
.push_back(rTransform
);
51 void removeTransformations(TransformationType eType
)
53 maTransformations
.erase(std::remove_if(maTransformations
.begin(), maTransformations
.end(),
54 [eType
](Transformation
const& rTransform
) {
55 return rTransform
.meType
== eType
;
57 maTransformations
.end());
60 std::vector
<Transformation
> const& getTransformations() const { return maTransformations
; }
62 /** Applies the defined transformations to the input color */
63 Color
applyTransformations(Color
const& rColor
) const
67 for (auto const& rTransform
: maTransformations
)
69 switch (rTransform
.meType
)
71 case TransformationType::Tint
:
72 aColor
.ApplyTintOrShade(rTransform
.mnValue
);
74 case TransformationType::Shade
:
75 aColor
.ApplyTintOrShade(-rTransform
.mnValue
);
77 case TransformationType::LumMod
:
78 aColor
.ApplyLumModOff(rTransform
.mnValue
, 0);
80 case TransformationType::LumOff
:
81 aColor
.ApplyLumModOff(10000, rTransform
.mnValue
);
90 bool operator==(const ThemeColor
& rThemeColor
) const
92 return meType
== rThemeColor
.meType
93 && maTransformations
.size() == rThemeColor
.maTransformations
.size()
94 && std::equal(maTransformations
.begin(), maTransformations
.end(),
95 rThemeColor
.maTransformations
.begin());
99 } // end of namespace model
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */