~ubuntu-branches/ubuntu/wily/oxygen/wily

« back to all changes in this revision

Viewing changes to liboxygen/oxygenshadowcache.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell, Scarlett Clark, Jonathan Riddell
  • Date: 2015-08-10 23:18:51 UTC
  • mfrom: (1.1.9)
  • Revision ID: package-import@ubuntu.com-20150810231851-wtw33zvkigya4f7t
Tags: 4:5.3.95-0ubuntu1
[ Scarlett Clark ]
* Vivid backport. 

[ Jonathan Riddell ]
* new upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
namespace Oxygen
37
37
{
38
38
 
 
39
    //* square utility function
 
40
    static qreal square( qreal x )
 
41
    { return x*x; }
 
42
 
 
43
    //* functions used to draw shadows
 
44
    class Parabolic
 
45
    {
 
46
        public:
 
47
 
 
48
        //* constructor
 
49
        Parabolic( qreal amplitude, qreal width ):
 
50
            amplitude_( amplitude ),
 
51
            width_( width )
 
52
        {}
 
53
 
 
54
        //* destructor
 
55
        virtual ~Parabolic( void )
 
56
        {}
 
57
 
 
58
        //* value
 
59
        virtual qreal operator() ( qreal x ) const
 
60
        { return qMax( 0.0, amplitude_*(1.0 - square(x/width_) ) ); }
 
61
 
 
62
        private:
 
63
 
 
64
        qreal amplitude_;
 
65
        qreal width_;
 
66
 
 
67
    };
 
68
 
 
69
    //* functions used to draw shadows
 
70
    class Gaussian
 
71
    {
 
72
        public:
 
73
 
 
74
        //* constructor
 
75
        Gaussian( qreal amplitude, qreal width ):
 
76
            amplitude_( amplitude ),
 
77
            width_( width )
 
78
        {}
 
79
 
 
80
        //* destructor
 
81
        virtual ~Gaussian( void )
 
82
        {}
 
83
 
 
84
        //* value
 
85
        virtual qreal operator() ( qreal x ) const
 
86
        { return qMax( 0.0, amplitude_*(std::exp( -square(x/width_) -0.05 ) ) ); }
 
87
 
 
88
        private:
 
89
 
 
90
        qreal amplitude_;
 
91
        qreal width_;
 
92
 
 
93
    };
 
94
 
39
95
    //_______________________________________________________
40
96
    ShadowCache::ShadowCache( Helper& helper ):
41
97
        _helper( helper ),
127
183
        if( _enabled && _shadowCache.contains(hash) ) return _shadowCache.object(hash);
128
184
 
129
185
        // create tileSet otherwise
130
 
        qreal size( shadowSize() + overlap );
131
 
        TileSet* tileSet = new TileSet( pixmap( key, key.active ), size, size, size, size, size, size, 1, 1);
 
186
        const qreal size( shadowSize() + overlap );
 
187
        TileSet* tileSet = new TileSet( pixmap( key ), size, size, size, size, size, size, 1, 1);
132
188
        _shadowCache.insert( hash, tileSet );
133
189
 
134
190
        return tileSet;
150
206
        if( _enabled && _animatedShadowCache.contains(hash) ) return _animatedShadowCache.object(hash);
151
207
 
152
208
        // create shadow and tileset otherwise
153
 
        qreal size( shadowSize() + overlap );
 
209
        const qreal size( shadowSize() + overlap );
 
210
        TileSet* tileSet = new TileSet( animatedPixmap( key, opacity ), size, size, 1, 1);
 
211
        _animatedShadowCache.insert( hash, tileSet );
 
212
        return tileSet;
 
213
 
 
214
    }
 
215
 
 
216
 
 
217
    //_______________________________________________________
 
218
    QPixmap ShadowCache::animatedPixmap( const Key& key, qreal opacity )
 
219
    {
 
220
 
 
221
        // create shadow and tileset otherwise
 
222
        const qreal size( shadowSize() + overlap );
154
223
 
155
224
        QPixmap shadow( _helper.highDpiPixmap( size*2 ) );
156
 
        // QPixmap shadow( size*2, size*2 );
157
225
        shadow.fill( Qt::transparent );
158
226
        QPainter painter( &shadow );
159
227
        painter.setRenderHint( QPainter::Antialiasing );
180
248
        painter.drawPixmap( QPointF(0,0), activeShadow );
181
249
        painter.end();
182
250
 
183
 
        TileSet* tileSet = new TileSet( shadow, size, size, 1, 1);
184
 
        _animatedShadowCache.insert( hash, tileSet );
185
 
        return tileSet;
 
251
        return shadow;
186
252
 
187
253
    }
188
254
 
204
270
        shadowSize += overlap;
205
271
 
206
272
        QPixmap shadow( _helper.highDpiPixmap( size*2 ) );
207
 
        // QPixmap shadow( size*2, size*2 );
208
273
        shadow.fill( Qt::transparent );
209
274
 
210
275
        QPainter painter( &shadow );