Rewrite Scale In effect in JavaScript
REVIEW: 109075
This commit is contained in:
parent
dd8cf0b678
commit
ed955e9488
7 changed files with 80 additions and 174 deletions
|
@ -104,6 +104,7 @@ add_subdirectory( login )
|
||||||
if( NOT KWIN_MOBILE_EFFECTS )
|
if( NOT KWIN_MOBILE_EFFECTS )
|
||||||
add_subdirectory( fadedesktop )
|
add_subdirectory( fadedesktop )
|
||||||
add_subdirectory( maximize )
|
add_subdirectory( maximize )
|
||||||
|
add_subdirectory( scalein )
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
@ -128,7 +129,6 @@ if( NOT KWIN_MOBILE_EFFECTS )
|
||||||
include( translucency/CMakeLists.txt )
|
include( translucency/CMakeLists.txt )
|
||||||
include( minimizeanimation/CMakeLists.txt )
|
include( minimizeanimation/CMakeLists.txt )
|
||||||
include( resize/CMakeLists.txt )
|
include( resize/CMakeLists.txt )
|
||||||
include( scalein/CMakeLists.txt )
|
|
||||||
include( showfps/CMakeLists.txt )
|
include( showfps/CMakeLists.txt )
|
||||||
include( showpaint/CMakeLists.txt )
|
include( showpaint/CMakeLists.txt )
|
||||||
include( slide/CMakeLists.txt )
|
include( slide/CMakeLists.txt )
|
||||||
|
|
|
@ -1,12 +1 @@
|
||||||
#######################################
|
add_subdirectory( package )
|
||||||
# Effect
|
|
||||||
|
|
||||||
# Source files
|
|
||||||
set( kwin4_effect_builtins_sources ${kwin4_effect_builtins_sources}
|
|
||||||
scalein/scalein.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
# .desktop files
|
|
||||||
install( FILES
|
|
||||||
scalein/scalein.desktop
|
|
||||||
DESTINATION ${SERVICES_INSTALL_DIR}/kwin )
|
|
||||||
|
|
6
effects/scalein/package/CMakeLists.txt
Normal file
6
effects/scalein/package/CMakeLists.txt
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
install(DIRECTORY contents DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/effects/kwin4_effect_scalein)
|
||||||
|
install(FILES metadata.desktop DESTINATION ${DATA_INSTALL_DIR}/${KWIN_NAME}/effects/kwin4_effect_scalein)
|
||||||
|
|
||||||
|
install(FILES metadata.desktop
|
||||||
|
DESTINATION ${SERVICES_INSTALL_DIR}/${KWIN_NAME}
|
||||||
|
RENAME kwin4_effect_scalein.desktop)
|
65
effects/scalein/package/contents/code/main.js
Normal file
65
effects/scalein/package/contents/code/main.js
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
/********************************************************************
|
||||||
|
KWin - the KDE window manager
|
||||||
|
This file is part of the KDE project.
|
||||||
|
|
||||||
|
Copyright (C) 2013 Kai Uwe Broulik <kde@privat.broulik.de>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*********************************************************************/
|
||||||
|
/*global effect, effects, animate, animationTime, Effect, QEasingCurve */
|
||||||
|
var scaleInEffect = {
|
||||||
|
duration: animationTime(250),
|
||||||
|
loadConfig: function () {
|
||||||
|
"use strict";
|
||||||
|
scaleInEffect.duration = animationTime(250);
|
||||||
|
},
|
||||||
|
isScaleWindow: function (window) {
|
||||||
|
"use strict";
|
||||||
|
if (window.popupMenu || window.specialWindow || window.utility ||
|
||||||
|
effect.isGrabbed(window, Effect.WindowAddedGrabRole)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
scaleIn: function (window) {
|
||||||
|
"use strict";
|
||||||
|
animate({
|
||||||
|
window: window,
|
||||||
|
duration: scaleInEffect.duration,
|
||||||
|
curve: QEasingCurve.InOutQuad,
|
||||||
|
animations: [{
|
||||||
|
type: Effect.Opacity,
|
||||||
|
from: 0.0,
|
||||||
|
to: 1.0
|
||||||
|
}, {
|
||||||
|
type: Effect.Scale,
|
||||||
|
from: 0.0,
|
||||||
|
to: 1.0
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
},
|
||||||
|
added: function (window) {
|
||||||
|
"use strict";
|
||||||
|
if (!scaleInEffect.isScaleWindow(window)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
scaleInEffect.scaleIn(window);
|
||||||
|
},
|
||||||
|
init: function () {
|
||||||
|
"use strict";
|
||||||
|
effect.configChanged.connect(scaleInEffect.loadConfig);
|
||||||
|
effects.windowAdded.connect(scaleInEffect.added);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
scaleInEffect.init();
|
|
@ -151,14 +151,15 @@ Comment[zh_CN]=动画显示窗口的出现
|
||||||
Comment[zh_TW]=動畫顯示視窗出現
|
Comment[zh_TW]=動畫顯示視窗出現
|
||||||
|
|
||||||
Type=Service
|
Type=Service
|
||||||
|
X-Plasma-API=javascript
|
||||||
|
X-Plasma-MainScript=code/main.js
|
||||||
X-KDE-ServiceTypes=KWin/Effect
|
X-KDE-ServiceTypes=KWin/Effect
|
||||||
X-KDE-PluginInfo-Author=Luboš Luňák
|
X-KDE-PluginInfo-Author=Luboš Luňák, Kai Uwe Broulik
|
||||||
X-KDE-PluginInfo-Email=l.lunak@kde.org
|
X-KDE-PluginInfo-Email=l.lunak@kde.org, kde@privat.broulik.de
|
||||||
X-KDE-PluginInfo-Name=kwin4_effect_scalein
|
X-KDE-PluginInfo-Name=kwin4_effect_scalein
|
||||||
X-KDE-PluginInfo-Version=0.1.0
|
X-KDE-PluginInfo-Version=0.2.0
|
||||||
X-KDE-PluginInfo-Category=Appearance
|
X-KDE-PluginInfo-Category=Appearance
|
||||||
X-KDE-PluginInfo-Depends=
|
X-KDE-PluginInfo-Depends=
|
||||||
X-KDE-PluginInfo-License=GPL
|
X-KDE-PluginInfo-License=GPL
|
||||||
X-KDE-PluginInfo-EnabledByDefault=false
|
X-KDE-PluginInfo-EnabledByDefault=false
|
||||||
X-KDE-Library=kwin4_effect_builtins
|
|
||||||
X-KDE-Ordering=50
|
X-KDE-Ordering=50
|
|
@ -1,102 +0,0 @@
|
||||||
/********************************************************************
|
|
||||||
KWin - the KDE window manager
|
|
||||||
This file is part of the KDE project.
|
|
||||||
|
|
||||||
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*********************************************************************/
|
|
||||||
|
|
||||||
#include "scalein.h"
|
|
||||||
#include <QTimeLine>
|
|
||||||
#include <QtGui/QVector2D>
|
|
||||||
|
|
||||||
namespace KWin
|
|
||||||
{
|
|
||||||
|
|
||||||
KWIN_EFFECT(scalein, ScaleInEffect)
|
|
||||||
|
|
||||||
ScaleInEffect::ScaleInEffect()
|
|
||||||
: Effect()
|
|
||||||
{
|
|
||||||
connect(effects, SIGNAL(windowAdded(KWin::EffectWindow*)), this, SLOT(slotWindowAdded(KWin::EffectWindow*)));
|
|
||||||
connect(effects, SIGNAL(windowClosed(KWin::EffectWindow*)), this, SLOT(slotWindowClosed(KWin::EffectWindow*)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScaleInEffect::prePaintScreen(ScreenPrePaintData& data, int time)
|
|
||||||
{
|
|
||||||
if (!mTimeLineWindows.isEmpty())
|
|
||||||
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
|
||||||
effects->prePaintScreen(data, time);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScaleInEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
|
|
||||||
{
|
|
||||||
if (mTimeLineWindows.contains(w)) {
|
|
||||||
mTimeLineWindows[ w ]->setCurveShape(QTimeLine::EaseInOutCurve);
|
|
||||||
mTimeLineWindows[ w ]->setCurrentTime(mTimeLineWindows[ w ]->currentTime() + time);
|
|
||||||
if (mTimeLineWindows[ w ]->currentValue() < 1)
|
|
||||||
data.setTransformed();
|
|
||||||
else
|
|
||||||
delete mTimeLineWindows.take(w);
|
|
||||||
}
|
|
||||||
effects->prePaintWindow(w, data, time);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScaleInEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
|
|
||||||
{
|
|
||||||
if (mTimeLineWindows.contains(w) && isScaleWindow(w)) {
|
|
||||||
const qreal value = mTimeLineWindows[ w ]->currentValue();
|
|
||||||
data.multiplyOpacity(value);
|
|
||||||
data *= QVector2D(value, value);
|
|
||||||
data += QPoint(int(w->width() / 2 * (1 - value)), int(w->height() / 2 * (1 - value)));
|
|
||||||
}
|
|
||||||
effects->paintWindow(w, mask, region, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ScaleInEffect::isScaleWindow(EffectWindow* w)
|
|
||||||
{
|
|
||||||
const void* e = w->data(WindowAddedGrabRole).value<void*>();
|
|
||||||
// TODO: isSpecialWindow is rather generic, maybe tell windowtypes separately?
|
|
||||||
if (w->isPopupMenu() || w->isSpecialWindow() || w->isUtility() || (e && e != this))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScaleInEffect::postPaintWindow(EffectWindow* w)
|
|
||||||
{
|
|
||||||
if (mTimeLineWindows.contains(w))
|
|
||||||
w->addRepaintFull(); // trigger next animation repaint
|
|
||||||
effects->postPaintWindow(w);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScaleInEffect::slotWindowAdded(EffectWindow* c)
|
|
||||||
{
|
|
||||||
if (c->isOnCurrentDesktop()) {
|
|
||||||
mTimeLineWindows.insert(c, new QTimeLine(animationTime(250), this));
|
|
||||||
c->addRepaintFull();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScaleInEffect::slotWindowClosed(EffectWindow* c)
|
|
||||||
{
|
|
||||||
delete mTimeLineWindows.take(c);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ScaleInEffect::isActive() const
|
|
||||||
{
|
|
||||||
return !mTimeLineWindows.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
|
@ -1,53 +0,0 @@
|
||||||
/********************************************************************
|
|
||||||
KWin - the KDE window manager
|
|
||||||
This file is part of the KDE project.
|
|
||||||
|
|
||||||
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*********************************************************************/
|
|
||||||
|
|
||||||
#ifndef KWIN_SCALEIN_H
|
|
||||||
#define KWIN_SCALEIN_H
|
|
||||||
|
|
||||||
#include <kwineffects.h>
|
|
||||||
|
|
||||||
class QTimeLine;
|
|
||||||
|
|
||||||
namespace KWin
|
|
||||||
{
|
|
||||||
|
|
||||||
class ScaleInEffect
|
|
||||||
: public Effect
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
ScaleInEffect();
|
|
||||||
virtual void prePaintScreen(ScreenPrePaintData& data, int time);
|
|
||||||
virtual void prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time);
|
|
||||||
virtual void paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data);
|
|
||||||
virtual void postPaintWindow(EffectWindow* w);
|
|
||||||
virtual bool isActive() const;
|
|
||||||
// TODO react also on virtual desktop changes
|
|
||||||
public Q_SLOTS:
|
|
||||||
void slotWindowAdded(KWin::EffectWindow* c);
|
|
||||||
void slotWindowClosed(KWin::EffectWindow *c);
|
|
||||||
private:
|
|
||||||
bool isScaleWindow(EffectWindow* w);
|
|
||||||
QHash< const EffectWindow*, QTimeLine* > mTimeLineWindows;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in a new issue