Changeset View
Changeset View
Standalone View
Standalone View
libbreezecommon/breezeboxshadowrenderer.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (C) 2018 Vlad Zagorodniy <vladzzag@gmail.com> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify | ||||
5 | * it under the terms of the GNU General Public License as published by | ||||
6 | * the Free Software Foundation; either version 2 of the License, or | ||||
7 | * (at your option) any later version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, | ||||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | * GNU General Public License for more details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU General Public License | ||||
15 | * along with this program; if not, write to the Free Software | ||||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||||
17 | */ | ||||
18 | | ||||
19 | #pragma once | ||||
20 | | ||||
21 | // own | ||||
22 | #include "breezecommon_export.h" | ||||
23 | | ||||
24 | // Qt | ||||
25 | #include <QImage> | ||||
26 | #include <QPoint> | ||||
27 | #include <QSize> | ||||
28 | | ||||
29 | namespace Breeze | ||||
30 | { | ||||
31 | | ||||
32 | class BREEZECOMMON_EXPORT BoxShadowRenderer | ||||
33 | { | ||||
34 | public: | ||||
35 | // Compiler generated constructors & destructor are fine. | ||||
36 | | ||||
37 | /** | ||||
38 | * Set the size of the box. | ||||
39 | * @param size The size of the box. | ||||
40 | **/ | ||||
41 | void setBoxSize(const QSize &size); | ||||
42 | | ||||
43 | /** | ||||
44 | * Set the radius of box' corners. | ||||
45 | * @param radius The border radius, in pixels. | ||||
46 | **/ | ||||
47 | void setBorderRadius(qreal radius); | ||||
48 | | ||||
49 | /** | ||||
50 | * Set the device pixel ratio of the resulting shadow texture. | ||||
51 | * @param dpr The device pixel ratio. | ||||
52 | **/ | ||||
53 | void setDevicePixelRatio(qreal dpr); | ||||
54 | | ||||
55 | /** | ||||
56 | * Add a shadow. | ||||
57 | * @param offset The offset of the shadow. | ||||
58 | * @param radius The blur radius. | ||||
59 | * @param color The color of the shadow. | ||||
60 | **/ | ||||
61 | void addShadow(const QPoint &offset, int radius, const QColor &color); | ||||
62 | | ||||
63 | /** | ||||
64 | * Render the shadow. | ||||
65 | **/ | ||||
66 | QImage render() const; | ||||
67 | | ||||
68 | /** | ||||
69 | * Calculate the minimum size of the box. | ||||
70 | * | ||||
71 | * This helper computes the minimum size of the box so the shadow behind it has | ||||
72 | * full its strength. | ||||
73 | * | ||||
74 | * @param radius The blur radius of the shadow. | ||||
75 | **/ | ||||
76 | static QSize calculateMinimumBoxSize(int radius); | ||||
77 | | ||||
78 | /** | ||||
79 | * Calculate the minimum size of the shadow texture. | ||||
80 | * | ||||
81 | * This helper computes the minimum size of the resulting texture so the shadow | ||||
82 | * is not clipped. | ||||
83 | * | ||||
84 | * @param boxSize The size of the box. | ||||
85 | * @param radius The blur radius. | ||||
86 | * @param offset The offset of the shadow. | ||||
87 | **/ | ||||
88 | static QSize calculateMinimumShadowTextureSize(const QSize &boxSize, int radius, const QPoint &offset); | ||||
89 | | ||||
90 | private: | ||||
91 | QSize m_boxSize; | ||||
92 | qreal m_borderRadius = 0.0; | ||||
93 | qreal m_dpr = 1.0; | ||||
94 | | ||||
95 | struct Shadow { | ||||
96 | QPoint offset; | ||||
97 | int radius; | ||||
98 | QColor color; | ||||
99 | }; | ||||
100 | | ||||
101 | QVector<Shadow> m_shadows; | ||||
102 | }; | ||||
103 | | ||||
104 | } // namespace Breeze |