Add a helper to turn on transparency in pre-paint calls.

svn path=/trunk/KDE/kdebase/workspace/; revision=689910
This commit is contained in:
Luboš Luňák 2007-07-19 13:32:46 +00:00
parent 22c8626868
commit 96aba51960
10 changed files with 40 additions and 18 deletions

View file

@ -916,6 +916,11 @@ QRect EffectWindowImpl::rect() const
return toplevel->rect();
}
QRect EffectWindowImpl::contentsRect() const
{
return QRect( toplevel->clientPos(), toplevel->clientSize());
}
bool EffectWindowImpl::isMovable() const
{
if( Client* c = dynamic_cast< Client* >( toplevel ))

View file

@ -167,6 +167,7 @@ class EffectWindowImpl : public EffectWindow
virtual bool isUserMove() const;
virtual bool isUserResize() const;
virtual QRect iconGeometry() const;
virtual QRect contentsRect() const;
virtual bool isDesktop() const;
virtual bool isDock() const;

View file

@ -57,10 +57,7 @@ void BoxSwitchEffect::prePaintWindow( EffectWindow* w, WindowPrePaintData& data,
if( mMode == TabBoxWindowsMode )
{
if( windows.contains( w ) && w != selected_window )
{
data.mask |= PAINT_WINDOW_TRANSLUCENT;
data.mask &= ~PAINT_WINDOW_OPAQUE;
}
data.setTranslucent();
}
else
{

View file

@ -121,8 +121,8 @@ void ExplosionEffect::prePaintWindow( EffectWindow* w, WindowPrePaintData& data,
mWindows[ w ] += time / 700.0; // complete change in 700ms
if( mWindows[ w ] < 1 )
{
data.mask |= PAINT_WINDOW_TRANSLUCENT | PAINT_WINDOW_TRANSFORMED;
data.mask &= ~PAINT_WINDOW_OPAQUE;
data.setTranslucent();
data.mask |= PAINT_WINDOW_TRANSFORMED;
w->enablePainting( EffectWindow::PAINT_DISABLED_BY_DELETE );
}
else

View file

@ -42,10 +42,7 @@ void FadeEffect::prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int
windows[ w ].fadeInStep += fadeInStep;
windows[ w ].fadeOutStep += fadeOutStep;
if( windows[ w ].opacity < 1.0 )
{
data.mask &= ~PAINT_WINDOW_OPAQUE;
data.mask |= PAINT_WINDOW_TRANSLUCENT;
}
data.setTranslucent();
if( windows[ w ].deleted )
{
if( windows[ w ].opacity <= 0.0 )

View file

@ -49,8 +49,8 @@ void HowtoEffect::prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int
{
// Since the effect will make the window translucent, explicitly change
// the flags so that the window will be painted only as translucent.
data.mask |= PAINT_WINDOW_TRANSLUCENT;
data.mask &= ~PAINT_WINDOW_OPAQUE;
// Use a helper that also takes care of changing the clipping rectangle.
data.setTranslucent();
}
else
{

View file

@ -25,23 +25,23 @@ MakeTransparentEffect::MakeTransparentEffect()
void MakeTransparentEffect::prePaintWindow( EffectWindow* w, WindowPrePaintData& data, int time )
{
if( decoration != 1.0 )
if( decoration != 1.0 && w->hasDecoration())
{
data.mask |= PAINT_WINDOW_TRANSLUCENT;
data.mask &= ~PAINT_WINDOW_OPAQUE;
// don't clear PAINT_WINDOW_OPAQUE, contents are not affected
data.clip &= w->contentsRect().translated( w->pos()); // decoration cannot clip
}
if(( moveresize != 1.0 && ( w->isUserMove() || w->isUserResize()))
|| ( dialogs != 1.0 && w->isDialog()))
{
data.mask |= PAINT_WINDOW_TRANSLUCENT;
data.mask &= ~PAINT_WINDOW_OPAQUE;
data.setTranslucent();
}
effects->prePaintWindow( w, data, time );
}
void MakeTransparentEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
{
if( decoration != 1.0 )
if( decoration != 1.0 && w->hasDecoration())
data.decoration_opacity *= decoration;
if( dialogs != 1.0 && w->isDialog())
data.opacity *= dialogs;

View file

@ -107,7 +107,7 @@ void PresentWindowsEffect::prePaintWindow( EffectWindow* w, WindowPrePaintData&
// If it's minimized window or on another desktop and effect is not
// fully active, then apply some transparency
if( mActiveness < 1.0f && (w->isMinimized() || !w->isOnCurrentDesktop() ))
data.mask |= Effect::PAINT_WINDOW_TRANSLUCENT;
data.setTranslucent();
// Change window's hover according to cursor pos
WindowData& windata = mWindowData[w];
const float hoverchangetime = 200;

View file

@ -22,6 +22,13 @@ License. See the file "COPYING" for the exact licensing terms.
namespace KWin
{
void WindowPrePaintData::setTranslucent()
{
mask |= Effect::PAINT_WINDOW_TRANSLUCENT;
mask &= ~Effect::PAINT_WINDOW_OPAQUE;
clip = QRegion(); // cannot clip, will be transparent
}
WindowPaintData::WindowPaintData()
: opacity( 1.0 )
, contents_opacity( 1.0 )
@ -282,6 +289,11 @@ bool EffectWindow::isOnDesktop( int d ) const
return desktop() == d || isOnAllDesktops();
}
bool EffectWindow::hasDecoration() const
{
return contentsRect() != QRect( 0, 0, width(), height());
}
//****************************************
// EffectWindowGroup

View file

@ -313,6 +313,11 @@ class KWIN_EXPORT EffectWindow
virtual bool isUserMove() const = 0;
virtual bool isUserResize() const = 0;
virtual QRect iconGeometry() const = 0;
/**
* Geometry of the actual window contents inside the whole (including decorations) window.
*/
virtual QRect contentsRect() const = 0;
bool hasDecoration() const;
virtual QString caption() const = 0;
virtual QPixmap icon() const = 0;
@ -428,6 +433,11 @@ class KWIN_EXPORT WindowPrePaintData
QRegion paint;
QRegion clip;
WindowQuadList quads;
/**
* Simple helper than sets data to say the window will be painted as non-opaque.
* Takes also care of changing the regions.
*/
void setTranslucent();
};
class KWIN_EXPORT WindowPaintData