~vanvugt/compiz-animation-plugin/fix-915236

« back to all changes in this revision

Viewing changes to src/transform.cpp

  • Committer: Erkin Bahceci
  • Date: 2009-07-15 16:05:10 UTC
  • Revision ID: git-v1:6eeaa209932c6039edd4c362c352f242468a118a
Initial C++ port. Dodge and magic lamp changes.

- New dodge mode: all windows moving (made the default).
- Fixed dodge artifacts/weirdness showing up in certain situations.
- Magic Lamp renamed to Magic Lamp Wavy.
- Vacuum renamed to Magic Lamp, allowed for minimize (made the default).
- Separated restack stuff (dodge and focus-fade) from animation core.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Animation plugin for compiz
 
3
 *
 
4
 * transform.cpp
 
5
 *
 
6
 * Copyright : (C) 2006 Erkin Bahceci
 
7
 * E-mail    : erkinbah@gmail.com
 
8
 *
 
9
 * Based on Wobbly and Minimize plugins by
 
10
 *           : David Reveman
 
11
 * E-mail    : davidr@novell.com>
 
12
 *
 
13
 * Particle system added by : (C) 2006 Dennis Kasprzyk
 
14
 * E-mail                   : onestone@beryl-project.org
 
15
 *
 
16
 * Beam-Up added by : Florencio Guimaraes
 
17
 * E-mail           : florencio@nexcorp.com.br
 
18
 *
 
19
 * Hexagon tessellator added by : Mike Slegeir
 
20
 * E-mail                       : mikeslegeir@mail.utexas.edu>
 
21
 *
 
22
 * This program is free software; you can redistribute it and/or
 
23
 * modify it under the terms of the GNU General Public License
 
24
 * as published by the Free Software Foundation; either version 2
 
25
 * of the License, or (at your option) any later version.
 
26
 *
 
27
 * This program is distributed in the hope that it will be useful,
 
28
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
29
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
30
 * GNU General Public License for more details.
 
31
 *
 
32
 * You should have received a copy of the GNU General Public License
 
33
 * along with this program; if not, write to the Free Software
 
34
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
35
 */
 
36
 
 
37
#include "private.h"
 
38
 
 
39
TransformAnim::TransformAnim (CompWindow *w,
 
40
                              WindowEvent curWindowEvent,
 
41
                              float duration,
 
42
                              const AnimEffect info,
 
43
                              const CompRect &icon) :
 
44
    Animation::Animation (w, curWindowEvent, duration, info, icon)
 
45
{
 
46
}
 
47
 
 
48
void
 
49
TransformAnim::init ()
 
50
{
 
51
    adjustDuration ();
 
52
}
 
53
 
 
54
void
 
55
TransformAnim::updateBB (CompOutput &output)
 
56
{
 
57
    GLMatrix wTransform;
 
58
 
 
59
    prepareTransform (output, wTransform, mTransform);
 
60
 
 
61
    CompRect outRect (mAWindow->savedRectsValid () ?
 
62
                      mAWindow->savedOutRect () :
 
63
                      mWindow->outputRect ());
 
64
    float corners[4*3] = {
 
65
        outRect.x (), outRect.y (), 0,
 
66
        outRect.x () + outRect.width (), outRect.y (), 0,
 
67
        outRect.x (), outRect.y () + outRect.height (), 0,
 
68
        outRect.x () + outRect.width (), outRect.y () + outRect.height (), 0
 
69
    };
 
70
    mAWindow->expandBBWithPoints3DTransform (output,
 
71
                                             wTransform,
 
72
                                             corners,
 
73
                                             0,
 
74
                                             4);
 
75
}
 
76
 
 
77
void
 
78
TransformAnim::step ()
 
79
{
 
80
    mTransform.reset ();
 
81
    applyTransform ();
 
82
}
 
83
 
 
84
void
 
85
TransformAnim::updateTransform (GLMatrix &wTransform)
 
86
{
 
87
    wTransform *= mTransform;
 
88
}
 
89
 
 
90
/// Scales z by 0 and does perspective distortion so that it
 
91
/// looks the same wherever on the screen.
 
92
void
 
93
TransformAnim::perspectiveDistortAndResetZ (GLMatrix &transform)
 
94
{
 
95
    float v = -1.0 / ::screen->width ();
 
96
    /*
 
97
      This does
 
98
      transform = M * transform, where M is
 
99
      1, 0, 0, 0,
 
100
      0, 1, 0, 0,
 
101
      0, 0, 0, v,
 
102
      0, 0, 0, 1
 
103
    */
 
104
 
 
105
    transform[8] = v * transform[12];
 
106
    transform[9] = v * transform[13];
 
107
    transform[10] = v * transform[14];
 
108
    transform[11] = v * transform[15];
 
109
}
 
110
 
 
111
void
 
112
TransformAnim::applyPerspectiveSkew (CompOutput &output,
 
113
                                     GLMatrix &transform,
 
114
                                     Point &center)
 
115
{
 
116
    GLfloat skewx = -(((center.x () - output.region ()->extents.x1) -
 
117
                       output.width () / 2) * 1.15);
 
118
    GLfloat skewy = -(((center.y () - output.region ()->extents.y1) -
 
119
                       output.height () / 2) * 1.15);
 
120
 
 
121
    /* transform = M * transform, where M is the skew matrix
 
122
        {1,0,0,0,
 
123
         0,1,0,0,
 
124
         skewx,skewy,1,0,
 
125
         0,0,0,1};
 
126
    */
 
127
 
 
128
    transform[8] = skewx * transform[0] + skewy * transform[4] + transform[8];
 
129
    transform[9] = skewx * transform[1] + skewy * transform[5] + transform[9];
 
130
    transform[10] = skewx * transform[2] + skewy * transform[6] + transform[10];
 
131
    transform[11] = skewx * transform[3] + skewy * transform[7] + transform[11];
 
132
}
 
133
 
 
134
Point
 
135
TransformAnim::getCenter ()
 
136
{
 
137
    CompRect inRect (mAWindow->savedRectsValid () ?
 
138
                     mAWindow->savedInRect () :
 
139
                     mWindow->inputRect ());
 
140
    Point center (inRect.x () + inRect.width () / 2,
 
141
                  inRect.y () + inRect.height () / 2);
 
142
    return center;
 
143
}
 
144