~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kwin/effects/_test/demo_shakymove.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************
 
2
 KWin - the KDE window manager
 
3
 This file is part of the KDE project.
 
4
 
 
5
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
 
6
 
 
7
You can Freely distribute this program under the GNU General Public
 
8
License. See the file "COPYING" for the exact licensing terms.
 
9
******************************************************************/
 
10
 
 
11
#include "demo_shakymove.h"
 
12
 
 
13
namespace KWin
 
14
{
 
15
 
 
16
KWIN_EFFECT(demo_shakymove, ShakyMoveEffect)
 
17
 
 
18
ShakyMoveEffect::ShakyMoveEffect()
 
19
{
 
20
    connect(&timer, SIGNAL(timeout()), SLOT(tick()));
 
21
}
 
22
 
 
23
static const int shaky_diff[] = { 0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1 };
 
24
static const int SHAKY_MAX = sizeof(shaky_diff) / sizeof(shaky_diff[ 0 ]);
 
25
 
 
26
void ShakyMoveEffect::prePaintScreen(ScreenPrePaintData& data, int time)
 
27
{
 
28
    if (!windows.isEmpty())
 
29
        data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
 
30
    effects->prePaintScreen(data, time);
 
31
}
 
32
 
 
33
void ShakyMoveEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
 
34
{
 
35
    if (windows.contains(w))
 
36
        data.setTransformed();
 
37
    effects->prePaintWindow(w, data, time);
 
38
}
 
39
 
 
40
void ShakyMoveEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
 
41
{
 
42
    if (windows.contains(w))
 
43
        data.xTranslate += shaky_diff[ windows[ w ]];
 
44
    effects->paintWindow(w, mask, region, data);
 
45
}
 
46
 
 
47
void ShakyMoveEffect::windowUserMovedResized(EffectWindow* c, bool first, bool last)
 
48
{
 
49
    if (first) {
 
50
        if (windows.isEmpty())
 
51
            timer.start(50);
 
52
        windows[ c ] = 0;
 
53
    } else if (last) {
 
54
        windows.remove(c);
 
55
        // just repaint whole screen, transformation is involved
 
56
        effects->addRepaintFull();
 
57
        if (windows.isEmpty())
 
58
            timer.stop();
 
59
    }
 
60
}
 
61
 
 
62
void ShakyMoveEffect::windowClosed(EffectWindow* c)
 
63
{
 
64
    windows.remove(c);
 
65
    if (windows.isEmpty())
 
66
        timer.stop();
 
67
}
 
68
 
 
69
// TODO use time provided with prePaintWindow() instead
 
70
void ShakyMoveEffect::tick()
 
71
{
 
72
    for (QHash< const EffectWindow*, int >::Iterator it = windows.begin();
 
73
            it != windows.end();
 
74
            ++it) {
 
75
        if (*it == SHAKY_MAX - 1)
 
76
            *it = 0;
 
77
        else
 
78
            ++(*it);
 
79
        // just repaint whole screen, transformation is involved
 
80
        effects->addRepaintFull();
 
81
    }
 
82
}
 
83
 
 
84
} // namespace
 
85
 
 
86
#include "demo_shakymove.moc"