Changeset View
Changeset View
Standalone View
Standalone View
effects/minimizeanimation/minimizeanimation.cpp
Show All 40 Lines | 38 | { | |||
---|---|---|---|---|---|
41 | m_duration = std::chrono::milliseconds(static_cast<int>(animationTime(250))); | 41 | m_duration = std::chrono::milliseconds(static_cast<int>(animationTime(250))); | ||
42 | } | 42 | } | ||
43 | 43 | | |||
44 | bool MinimizeAnimationEffect::supported() | 44 | bool MinimizeAnimationEffect::supported() | ||
45 | { | 45 | { | ||
46 | return effects->animationsSupported(); | 46 | return effects->animationsSupported(); | ||
47 | } | 47 | } | ||
48 | 48 | | |||
49 | void MinimizeAnimationEffect::prePaintScreen(ScreenPrePaintData& data, int time) | 49 | void MinimizeAnimationEffect::prePaintScreen(ScreenPrePaintData &data, int time) | ||
50 | { | 50 | { | ||
51 | const std::chrono::milliseconds delta(time); | 51 | const std::chrono::milliseconds delta(time); | ||
52 | 52 | | |||
53 | auto animationIt = m_animations.begin(); | 53 | auto animationIt = m_animations.begin(); | ||
54 | while (animationIt != m_animations.end()) { | 54 | while (animationIt != m_animations.end()) { | ||
55 | (*animationIt).update(delta); | 55 | (*animationIt).update(delta); | ||
56 | ++animationIt; | 56 | ++animationIt; | ||
57 | } | 57 | } | ||
58 | 58 | | |||
59 | // We need to mark the screen windows as transformed. Otherwise the | 59 | // We need to mark the screen windows as transformed. Otherwise the | ||
60 | // whole screen won't be repainted, resulting in artefacts. | 60 | // whole screen won't be repainted, resulting in artefacts. | ||
61 | data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS; | 61 | data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS; | ||
62 | 62 | | |||
63 | effects->prePaintScreen(data, time); | 63 | effects->prePaintScreen(data, time); | ||
64 | } | 64 | } | ||
65 | 65 | | |||
66 | void MinimizeAnimationEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time) | 66 | void MinimizeAnimationEffect::prePaintWindow(EffectWindow *w, WindowPrePaintData &data, int time) | ||
67 | { | 67 | { | ||
68 | // Schedule window for transformation if the animation is still in | 68 | // Schedule window for transformation if the animation is still in | ||
69 | // progress | 69 | // progress | ||
70 | if (m_animations.contains(w)) { | 70 | if (m_animations.contains(w)) { | ||
71 | // We'll transform this window | 71 | // We'll transform this window | ||
72 | data.setTransformed(); | 72 | data.setTransformed(); | ||
73 | w->enablePainting(EffectWindow::PAINT_DISABLED_BY_MINIMIZE); | 73 | w->enablePainting(EffectWindow::PAINT_DISABLED_BY_MINIMIZE); | ||
74 | } | 74 | } | ||
75 | 75 | | |||
76 | effects->prePaintWindow(w, data, time); | 76 | effects->prePaintWindow(w, data, time); | ||
77 | } | 77 | } | ||
78 | 78 | | |||
79 | void MinimizeAnimationEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data) | 79 | void MinimizeAnimationEffect::paintWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data) | ||
80 | { | 80 | { | ||
81 | const auto animationIt = m_animations.constFind(w); | 81 | const auto animationIt = m_animations.constFind(w); | ||
82 | if (animationIt != m_animations.constEnd()) { | 82 | if (animationIt != m_animations.constEnd()) { | ||
83 | // 0 = not minimized, 1 = fully minimized | 83 | // 0 = not minimized, 1 = fully minimized | ||
84 | const qreal progress = (*animationIt).value(); | 84 | const qreal progress = (*animationIt).value(); | ||
85 | 85 | | |||
86 | QRect geo = w->geometry(); | 86 | QRect geo = w->geometry(); | ||
87 | QRect icon = w->iconGeometry(); | 87 | QRect icon = w->iconGeometry(); | ||
88 | // If there's no icon geometry, minimize to the center of the screen | 88 | // If there's no icon geometry, minimize to the center of the screen | ||
89 | if (!icon.isValid()) | 89 | if (!icon.isValid()) { | ||
90 | icon = QRect(effects->virtualScreenGeometry().center(), QSize(0, 0)); | 90 | icon = QRect(effects->virtualScreenGeometry().center(), QSize(0, 0)); | ||
91 | } | ||||
91 | 92 | | |||
92 | data *= QVector2D(interpolate(1.0, icon.width() / (double)geo.width(), progress), | 93 | data *= QVector2D(interpolate(1.0, icon.width() / (double)geo.width(), progress), | ||
93 | interpolate(1.0, icon.height() / (double)geo.height(), progress)); | 94 | interpolate(1.0, icon.height() / (double)geo.height(), progress)); | ||
94 | data.setXTranslation(interpolate(data.xTranslation(), icon.x() - geo.x(), progress)); | 95 | data.setXTranslation(interpolate(data.xTranslation(), icon.x() - geo.x(), progress)); | ||
95 | data.setYTranslation(interpolate(data.yTranslation(), icon.y() - geo.y(), progress)); | 96 | data.setYTranslation(interpolate(data.yTranslation(), icon.y() - geo.y(), progress)); | ||
96 | data.multiplyOpacity(interpolate(1.0, 0.1, progress)); | 97 | data.multiplyOpacity(interpolate(1.0, 0.1, progress)); | ||
97 | } | 98 | } | ||
98 | 99 | | |||
Show All 20 Lines | |||||
119 | 120 | | |||
120 | void MinimizeAnimationEffect::windowDeleted(EffectWindow *w) | 121 | void MinimizeAnimationEffect::windowDeleted(EffectWindow *w) | ||
121 | { | 122 | { | ||
122 | m_animations.remove(w); | 123 | m_animations.remove(w); | ||
123 | } | 124 | } | ||
124 | 125 | | |||
125 | void MinimizeAnimationEffect::windowMinimized(EffectWindow *w) | 126 | void MinimizeAnimationEffect::windowMinimized(EffectWindow *w) | ||
126 | { | 127 | { | ||
127 | if (effects->activeFullScreenEffect()) | 128 | if (effects->activeFullScreenEffect()) { | ||
128 | return; | 129 | return; | ||
130 | } | ||||
129 | 131 | | |||
130 | TimeLine &timeLine = m_animations[w]; | 132 | TimeLine &timeLine = m_animations[w]; | ||
131 | 133 | | |||
132 | if (timeLine.running()) { | 134 | if (timeLine.running()) { | ||
133 | timeLine.toggleDirection(); | 135 | timeLine.toggleDirection(); | ||
134 | } else { | 136 | } else { | ||
135 | timeLine.setDirection(TimeLine::Forward); | 137 | timeLine.setDirection(TimeLine::Forward); | ||
136 | timeLine.setDuration(m_duration); | 138 | timeLine.setDuration(m_duration); | ||
137 | timeLine.setEasingCurve(QEasingCurve::InOutSine); | 139 | timeLine.setEasingCurve(QEasingCurve::InOutSine); | ||
138 | } | 140 | } | ||
139 | 141 | | |||
140 | effects->addRepaintFull(); | 142 | effects->addRepaintFull(); | ||
141 | } | 143 | } | ||
142 | 144 | | |||
143 | void MinimizeAnimationEffect::windowUnminimized(EffectWindow *w) | 145 | void MinimizeAnimationEffect::windowUnminimized(EffectWindow *w) | ||
144 | { | 146 | { | ||
145 | if (effects->activeFullScreenEffect()) | 147 | if (effects->activeFullScreenEffect()) { | ||
146 | return; | 148 | return; | ||
149 | } | ||||
147 | 150 | | |||
148 | TimeLine &timeLine = m_animations[w]; | 151 | TimeLine &timeLine = m_animations[w]; | ||
149 | 152 | | |||
150 | if (timeLine.running()) { | 153 | if (timeLine.running()) { | ||
151 | timeLine.toggleDirection(); | 154 | timeLine.toggleDirection(); | ||
152 | } else { | 155 | } else { | ||
153 | timeLine.setDirection(TimeLine::Backward); | 156 | timeLine.setDirection(TimeLine::Backward); | ||
154 | timeLine.setDuration(m_duration); | 157 | timeLine.setDuration(m_duration); | ||
Show All 13 Lines |