Replace custom RotationData with QGraphicsRotation

This commit is contained in:
Martin Gräßlin 2012-05-27 19:28:02 +02:00
parent a394fade64
commit 966047ccd2
10 changed files with 120 additions and 150 deletions

View file

@ -461,8 +461,6 @@ void CoverSwitchEffect::paintScene(EffectWindow* frontWindow, const EffectWindow
int width = area.width(); int width = area.width();
int leftWindowCount = leftWindows.count(); int leftWindowCount = leftWindows.count();
int rightWindowCount = rightWindows.count(); int rightWindowCount = rightWindows.count();
RotationData rot;
rot.axis = RotationData::YAxis;
// Problem during animation: a window which is painted after another window // Problem during animation: a window which is painted after another window
@ -701,8 +699,7 @@ void CoverSwitchEffect::paintWindowCover(EffectWindow* w, bool reflectedWindow,
} }
} }
data.zTranslate *= timeLine.currentValue(); data.zTranslate *= timeLine.currentValue();
if (data.rotation) data.rotation.setAngle(data.rotation.angle() * timeLine.currentValue());
data.rotation->angle *= timeLine.currentValue();
} }
} }
if (stop) { if (stop) {
@ -732,8 +729,7 @@ void CoverSwitchEffect::paintWindowCover(EffectWindow* w, bool reflectedWindow,
} }
} }
data.zTranslate *= (1.0 - timeLine.currentValue()); data.zTranslate *= (1.0 - timeLine.currentValue());
if (data.rotation) data.rotation.setAngle(data.rotation.angle() * (1.0 - timeLine.currentValue()));
data.rotation->angle *= (1.0 - timeLine.currentValue());
} }
} }
@ -788,7 +784,6 @@ void CoverSwitchEffect::paintFrontWindow(EffectWindow* frontWindow, int width, i
if (rightWindows == 0) { if (rightWindows == 0) {
rightWindows = 1; rightWindows = 1;
} }
RotationData rot; // this has to survive the if (animation) context as it's used as pointer - bug #297757
if (animation) { if (animation) {
float distance = 0.0; float distance = 0.0;
if (direction == Right) { if (direction == Right) {
@ -796,10 +791,9 @@ void CoverSwitchEffect::paintFrontWindow(EffectWindow* frontWindow, int width, i
distance = -frontWindow->geometry().width() * 0.5f + area.width() * 0.5f + distance = -frontWindow->geometry().width() * 0.5f + area.width() * 0.5f +
(((float)displayWidth() * 0.5 * scaleFactor) - (float)area.width() * 0.5f) / rightWindows; (((float)displayWidth() * 0.5 * scaleFactor) - (float)area.width() * 0.5f) / rightWindows;
data.xTranslate += distance * timeLine.currentValue(); data.xTranslate += distance * timeLine.currentValue();
rot.axis = RotationData::YAxis; data.rotation.setAxis(Qt::YAxis);
rot.angle = -angle * timeLine.currentValue(); data.rotation.setAngle(-angle * timeLine.currentValue());
rot.xRotationPoint = frontWindow->geometry().width(); data.rotation.setOrigin(QVector3D(frontWindow->geometry().width(), 0.0, 0.0));
data.rotation = &rot;
} else { } else {
// move to left // move to left
distance = frontWindow->geometry().width() * 0.5f - area.width() * 0.5f + distance = frontWindow->geometry().width() * 0.5f - area.width() * 0.5f +
@ -808,10 +802,8 @@ void CoverSwitchEffect::paintFrontWindow(EffectWindow* frontWindow, int width, i
if (specialHandlingForward) if (specialHandlingForward)
factor = 2.0; factor = 2.0;
data.xTranslate += distance * timeLine.currentValue() * factor; data.xTranslate += distance * timeLine.currentValue() * factor;
rot.axis = RotationData::YAxis; data.rotation.setAxis(Qt::YAxis);
rot.angle = angle * timeLine.currentValue(); data.rotation.setAngle(angle * timeLine.currentValue());
rot.xRotationPoint = 0.0;
data.rotation = &rot;
} }
} }
if (specialHandlingForward) { if (specialHandlingForward) {
@ -838,26 +830,20 @@ void CoverSwitchEffect::paintWindows(const EffectWindowList& windows, bool left,
// handling for additional window from other side // handling for additional window from other side
// has to appear on this side after half of the time // has to appear on this side after half of the time
if (animation && timeLine.currentValue() >= 0.5 && additionalWindow != NULL) { if (animation && timeLine.currentValue() >= 0.5 && additionalWindow != NULL) {
RotationData rot;
rot.axis = RotationData::YAxis;
rot.angle = angle;
rot.angle = angle * rotateFactor;
WindowPaintData data(additionalWindow); WindowPaintData data(additionalWindow);
data.rotation.setAxis(Qt::YAxis);
data.rotation.setAngle(angle * rotateFactor);
if (left) { if (left) {
data.xTranslate += -xTranslate - additionalWindow->geometry().x(); data.xTranslate += -xTranslate - additionalWindow->geometry().x();
rot.xRotationPoint = 0.0;
} }
else { else {
data.xTranslate += xTranslate + area.width() - data.xTranslate += xTranslate + area.width() -
additionalWindow->geometry().x() - additionalWindow->geometry().width(); additionalWindow->geometry().x() - additionalWindow->geometry().width();
rot.xRotationPoint = additionalWindow->geometry().width(); data.rotation.setOrigin(QVector3D(additionalWindow->geometry().width(), 0.0, 0.0));
} }
data.rotation = &rot;
data.opacity *= (timeLine.currentValue() - 0.5) * 2.0; data.opacity *= (timeLine.currentValue() - 0.5) * 2.0;
paintWindowCover(additionalWindow, reflectedWindows, data); paintWindowCover(additionalWindow, reflectedWindows, data);
} }
RotationData rot;
rot.axis = RotationData::YAxis;
// normal behaviour // normal behaviour
for (int i = 0; i < windows.count(); i++) { for (int i = 0; i < windows.count(); i++) {
window = windows.at(i); window = windows.at(i);
@ -865,7 +851,8 @@ void CoverSwitchEffect::paintWindows(const EffectWindowList& windows, bool left,
continue; continue;
} }
WindowPaintData data(window); WindowPaintData data(window);
rot.angle = angle; data.rotation.setAxis(Qt::YAxis);
data.rotation.setAngle(angle);
if (left) if (left)
data.xTranslate += -xTranslate + xTranslate * i / windowCount - window->geometry().x(); data.xTranslate += -xTranslate + xTranslate * i / windowCount - window->geometry().x();
else else
@ -876,7 +863,7 @@ void CoverSwitchEffect::paintWindows(const EffectWindowList& windows, bool left,
// right most window on left side -> move to front // right most window on left side -> move to front
// have to move one window distance plus half the difference between the window and the desktop size // have to move one window distance plus half the difference between the window and the desktop size
data.xTranslate += (xTranslate / windowCount + (width - window->geometry().width()) * 0.5f) * timeLine.currentValue(); data.xTranslate += (xTranslate / windowCount + (width - window->geometry().width()) * 0.5f) * timeLine.currentValue();
rot.angle = (angle - angle * timeLine.currentValue()); data.rotation.setAngle(angle - angle * timeLine.currentValue());
} }
// right most window does not have to be moved // right most window does not have to be moved
else if (!left && (i == 0)); // do nothing else if (!left && (i == 0)); // do nothing
@ -888,7 +875,7 @@ void CoverSwitchEffect::paintWindows(const EffectWindowList& windows, bool left,
if ((i == windowCount - 1) && !left) { if ((i == windowCount - 1) && !left) {
// left most window on right side -> move to front // left most window on right side -> move to front
data.xTranslate -= (xTranslate / windowCount + (width - window->geometry().width()) * 0.5f) * timeLine.currentValue(); data.xTranslate -= (xTranslate / windowCount + (width - window->geometry().width()) * 0.5f) * timeLine.currentValue();
rot.angle = (angle - angle * timeLine.currentValue()); data.rotation.setAngle(angle - angle * timeLine.currentValue());
} }
// left most window does not have to be moved // left most window does not have to be moved
else if (i == 0 && left); // do nothing else if (i == 0 && left); // do nothing
@ -898,12 +885,9 @@ void CoverSwitchEffect::paintWindows(const EffectWindowList& windows, bool left,
} }
} }
} }
if (left) if (!left)
rot.xRotationPoint = 0.0; data.rotation.setOrigin(QVector3D(window->geometry().width(), 0.0, 0.0));
else data.rotation.setAngle(data.rotation.angle() * rotateFactor);
rot.xRotationPoint = window->geometry().width();
rot.angle *= rotateFactor;
data.rotation = &rot;
// make window most to edge transparent if animation // make window most to edge transparent if animation
if (animation && i == 0 && ((direction == Left && left) || (direction == Right && !left))) { if (animation && i == 0 && ((direction == Left && left) || (direction == Right && !left))) {
// only for the first half of the animation // only for the first half of the animation

View file

@ -37,6 +37,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QKeyEvent> #include <QKeyEvent>
#include <QtConcurrentRun> #include <QtConcurrentRun>
#include <QVector2D> #include <QVector2D>
#include <QVector3D>
#include <math.h> #include <math.h>
@ -743,12 +744,9 @@ void CubeEffect::paintCube(int mask, QRegion region, ScreenPaintData& data)
painting_desktop = effects->numberOfDesktops(); painting_desktop = effects->numberOfDesktops();
} }
ScreenPaintData newData = data; ScreenPaintData newData = data;
RotationData rot = RotationData(); newData.rotation.setAxis(Qt::YAxis);
rot.axis = RotationData::YAxis; newData.rotation.setAngle(internalCubeAngle * i);
rot.angle = internalCubeAngle * i; newData.rotation.setOrigin(QVector3D(rect.width() / 2, 0.0, -point));
rot.xRotationPoint = rect.width() / 2;
rot.zRotationPoint = -point;
newData.rotation = &rot;
newData.zTranslate = -zTranslate; newData.zTranslate = -zTranslate;
effects->paintScreen(mask, region, newData); effects->paintScreen(mask, region, newData);
} }
@ -1381,11 +1379,9 @@ void CubeEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPa
if (shader) { if (shader) {
data.xTranslate = -rect.width(); data.xTranslate = -rect.width();
} else { } else {
RotationData rot = RotationData(); data.rotation.setAxis(Qt::YAxis);
rot.axis = RotationData::YAxis; data.rotation.setOrigin(QVector3D(rect.width() - w->x(), 0.0, 0.0));
rot.xRotationPoint = rect.width() - w->x(); data.rotation.setAngle(-360.0f / effects->numberOfDesktops());
rot.angle = 360.0f / effects->numberOfDesktops();
data.rotation = &rot;
float cubeAngle = (float)((float)(effects->numberOfDesktops() - 2) / (float)effects->numberOfDesktops() * 180.0f); float cubeAngle = (float)((float)(effects->numberOfDesktops() - 2) / (float)effects->numberOfDesktops() * 180.0f);
float point = rect.width() / 2 * tan(cubeAngle * 0.5f * M_PI / 180.0f); float point = rect.width() / 2 * tan(cubeAngle * 0.5f * M_PI / 180.0f);
QMatrix4x4 matrix; QMatrix4x4 matrix;
@ -1407,11 +1403,9 @@ void CubeEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPa
if (shader) { if (shader) {
data.xTranslate = rect.width(); data.xTranslate = rect.width();
} else { } else {
RotationData rot = RotationData(); data.rotation.setAxis(Qt::YAxis);
rot.axis = RotationData::YAxis; data.rotation.setOrigin(QVector3D(-w->x(), 0.0, 0.0));
rot.xRotationPoint = -w->x(); data.rotation.setAngle(-360.0f / effects->numberOfDesktops());
rot.angle = -360.0f / effects->numberOfDesktops();
data.rotation = &rot;
float cubeAngle = (float)((float)(effects->numberOfDesktops() - 2) / (float)effects->numberOfDesktops() * 180.0f); float cubeAngle = (float)((float)(effects->numberOfDesktops() - 2) / (float)effects->numberOfDesktops() * 180.0f);
float point = rect.width() / 2 * tan(cubeAngle * 0.5f * M_PI / 180.0f); float point = rect.width() / 2 * tan(cubeAngle * 0.5f * M_PI / 180.0f);
QMatrix4x4 matrix; QMatrix4x4 matrix;

View file

@ -118,14 +118,12 @@ void CubeSlideEffect::paintSlideCube(int mask, QRegion region, ScreenPaintData&
ScreenPaintData firstFaceData = data; ScreenPaintData firstFaceData = data;
ScreenPaintData secondFaceData = data; ScreenPaintData secondFaceData = data;
RotationData firstFaceRot = RotationData();
RotationData secondFaceRot = RotationData();
RotationDirection direction = slideRotations.head(); RotationDirection direction = slideRotations.head();
int secondDesktop; int secondDesktop;
switch(direction) { switch(direction) {
case Left: case Left:
firstFaceRot.axis = RotationData::YAxis; firstFaceData.rotation.setAxis(Qt::YAxis);
secondFaceRot.axis = RotationData::YAxis; secondFaceData.rotation.setAxis(Qt::YAxis);
if (usePagerLayout) if (usePagerLayout)
secondDesktop = effects->desktopToLeft(front_desktop, true); secondDesktop = effects->desktopToLeft(front_desktop, true);
else { else {
@ -133,12 +131,12 @@ void CubeSlideEffect::paintSlideCube(int mask, QRegion region, ScreenPaintData&
if (secondDesktop == 0) if (secondDesktop == 0)
secondDesktop = effects->numberOfDesktops(); secondDesktop = effects->numberOfDesktops();
} }
firstFaceRot.angle = 90.0f * timeLine.currentValue(); firstFaceData.rotation.setAngle(90.0f * timeLine.currentValue());
secondFaceRot.angle = -90.0f * (1.0f - timeLine.currentValue()); secondFaceData.rotation.setAngle(-90.0f * (1.0f - timeLine.currentValue()));
break; break;
case Right: case Right:
firstFaceRot.axis = RotationData::YAxis; firstFaceData.rotation.setAxis(Qt::YAxis);
secondFaceRot.axis = RotationData::YAxis; secondFaceData.rotation.setAxis(Qt::YAxis);
if (usePagerLayout) if (usePagerLayout)
secondDesktop = effects->desktopToRight(front_desktop, true); secondDesktop = effects->desktopToRight(front_desktop, true);
else { else {
@ -146,23 +144,23 @@ void CubeSlideEffect::paintSlideCube(int mask, QRegion region, ScreenPaintData&
if (secondDesktop > effects->numberOfDesktops()) if (secondDesktop > effects->numberOfDesktops())
secondDesktop = 1; secondDesktop = 1;
} }
firstFaceRot.angle = -90.0f * timeLine.currentValue(); firstFaceData.rotation.setAngle(-90.0f * timeLine.currentValue());
secondFaceRot.angle = 90.0f * (1.0f - timeLine.currentValue()); secondFaceData.rotation.setAngle(90.0f * (1.0f - timeLine.currentValue()));
break; break;
case Upwards: case Upwards:
firstFaceRot.axis = RotationData::XAxis; firstFaceData.rotation.setAxis(Qt::XAxis);
secondFaceRot.axis = RotationData::XAxis; secondFaceData.rotation.setAxis(Qt::XAxis);
secondDesktop = effects->desktopAbove(front_desktop, true); secondDesktop = effects->desktopAbove(front_desktop, true);
firstFaceRot.angle = -90.0f * timeLine.currentValue(); firstFaceData.rotation.setAngle(-90.0f * timeLine.currentValue());
secondFaceRot.angle = 90.0f * (1.0f - timeLine.currentValue()); secondFaceData.rotation.setAngle(90.0f * (1.0f - timeLine.currentValue()));
point = rect.height() / 2 * tan(45.0f * M_PI / 180.0f); point = rect.height() / 2 * tan(45.0f * M_PI / 180.0f);
break; break;
case Downwards: case Downwards:
firstFaceRot.axis = RotationData::XAxis; firstFaceData.rotation.setAxis(Qt::XAxis);
secondFaceRot.axis = RotationData::XAxis; secondFaceData.rotation.setAxis(Qt::XAxis);
secondDesktop = effects->desktopBelow(front_desktop, true); secondDesktop = effects->desktopBelow(front_desktop, true);
firstFaceRot.angle = 90.0f * timeLine.currentValue(); firstFaceData.rotation.setAngle(90.0f * timeLine.currentValue());
secondFaceRot.angle = -90.0f * (1.0f - timeLine.currentValue()); secondFaceData.rotation.setAngle(-90.0f * (1.0f - timeLine.currentValue()));
point = rect.height() / 2 * tan(45.0f * M_PI / 180.0f); point = rect.height() / 2 * tan(45.0f * M_PI / 180.0f);
break; break;
default: default:
@ -170,10 +168,7 @@ void CubeSlideEffect::paintSlideCube(int mask, QRegion region, ScreenPaintData&
return; return;
} }
// front desktop // front desktop
firstFaceRot.xRotationPoint = rect.width() / 2; firstFaceData.rotation.setOrigin(QVector3D(rect.width() / 2, rect.height() / 2, -point));
firstFaceRot.yRotationPoint = rect.height() / 2;
firstFaceRot.zRotationPoint = -point;
firstFaceData.rotation = &firstFaceRot;
other_desktop = secondDesktop; other_desktop = secondDesktop;
firstDesktop = true; firstDesktop = true;
effects->paintScreen(mask, region, firstFaceData); effects->paintScreen(mask, region, firstFaceData);
@ -181,10 +176,7 @@ void CubeSlideEffect::paintSlideCube(int mask, QRegion region, ScreenPaintData&
other_desktop = painting_desktop; other_desktop = painting_desktop;
painting_desktop = secondDesktop; painting_desktop = secondDesktop;
firstDesktop = false; firstDesktop = false;
secondFaceRot.xRotationPoint = rect.width() / 2; secondFaceData.rotation.setOrigin(QVector3D(rect.width() / 2, rect.height() / 2, -point));
secondFaceRot.yRotationPoint = rect.height() / 2;
secondFaceRot.zRotationPoint = -point;
secondFaceData.rotation = &secondFaceRot;
effects->paintScreen(mask, region, secondFaceData); effects->paintScreen(mask, region, secondFaceData);
cube_painting = false; cube_painting = false;
painting_desktop = effects->currentDesktop(); painting_desktop = effects->currentDesktop();

View file

@ -289,14 +289,13 @@ void FlipSwitchEffect::paintScreen(int mask, QRegion region, ScreenPaintData& da
} }
int winMask = PAINT_WINDOW_TRANSFORMED | PAINT_WINDOW_TRANSLUCENT; int winMask = PAINT_WINDOW_TRANSFORMED | PAINT_WINDOW_TRANSLUCENT;
RotationData rot;
rot.axis = RotationData::YAxis;
rot.angle = m_angle * m_startStopTimeLine.currentValue();
// fade in/out one window at the end of the stack during animation // fade in/out one window at the end of the stack during animation
if (m_animation && !m_scheduledDirections.isEmpty()) { if (m_animation && !m_scheduledDirections.isEmpty()) {
EffectWindow* w = m_flipOrderedWindows.last(); EffectWindow* w = m_flipOrderedWindows.last();
if (ItemInfo *info = m_windows.value(w,0)) { if (ItemInfo *info = m_windows.value(w,0)) {
WindowPaintData data(w); WindowPaintData data(w);
data.rotation.setAxis(Qt::YAxis);
data.rotation.setAngle(m_angle * m_startStopTimeLine.currentValue());
data.opacity = info->opacity; data.opacity = info->opacity;
data.brightness = info->brightness; data.brightness = info->brightness;
data.saturation = info->saturation; data.saturation = info->saturation;
@ -317,7 +316,6 @@ void FlipSwitchEffect::paintScreen(int mask, QRegion region, ScreenPaintData& da
if (effects->numScreens() > 1) { if (effects->numScreens() > 1) {
adjustWindowMultiScreen(w, data); adjustWindowMultiScreen(w, data);
} }
data.rotation = &rot;
effects->drawWindow(w, winMask, infiniteRegion(), data); effects->drawWindow(w, winMask, infiniteRegion(), data);
} }
} }
@ -327,6 +325,8 @@ void FlipSwitchEffect::paintScreen(int mask, QRegion region, ScreenPaintData& da
if (!info) if (!info)
continue; continue;
WindowPaintData data(w); WindowPaintData data(w);
data.rotation.setAxis(Qt::YAxis);
data.rotation.setAngle(m_angle * m_startStopTimeLine.currentValue());
data.opacity = info->opacity; data.opacity = info->opacity;
data.brightness = info->brightness; data.brightness = info->brightness;
data.saturation = info->saturation; data.saturation = info->saturation;
@ -378,7 +378,6 @@ void FlipSwitchEffect::paintScreen(int mask, QRegion region, ScreenPaintData& da
adjustWindowMultiScreen(w, data); adjustWindowMultiScreen(w, data);
} }
data.rotation = &rot;
effects->drawWindow(w, winMask, infiniteRegion(), data); effects->drawWindow(w, winMask, infiniteRegion(), data);
} }

View file

@ -98,10 +98,8 @@ void GlideEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowP
InfoHash::const_iterator info = windows.constFind(w); InfoHash::const_iterator info = windows.constFind(w);
if (info != windows.constEnd()) { if (info != windows.constEnd()) {
const double progress = info->timeLine->currentValue(); const double progress = info->timeLine->currentValue();
RotationData rot; data.rotation.setAxis(Qt::XAxis);
rot.axis = RotationData::XAxis; data.rotation.setAngle(angle * (1 - progress));
rot.angle = angle * (1 - progress);
data.rotation = &rot;
data.opacity *= progress; data.opacity *= progress;
switch(effect) { switch(effect) {
default: default:

View file

@ -89,10 +89,9 @@ void SheetEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowP
InfoMap::const_iterator info = windows.constFind(w); InfoMap::const_iterator info = windows.constFind(w);
if (info != windows.constEnd()) { if (info != windows.constEnd()) {
const double progress = info->timeLine->currentValue(); const double progress = info->timeLine->currentValue();
RotationData rot; QGraphicsRotation rot;
rot.axis = RotationData::XAxis; data.rotation.setAxis(Qt::XAxis);
rot.angle = 60.0 * (1.0 - progress); data.rotation.setAngle(60.0 * (1.0 - progress));
data.rotation = &rot;
data.yScale *= progress; data.yScale *= progress;
data.zScale *= progress; data.zScale *= progress;
data.yTranslate -= (w->y() - info->parentY) * (1.0 - progress); data.yTranslate -= (w->y() - info->parentY) * (1.0 - progress);

View file

@ -463,10 +463,9 @@ void AnimationEffect::paintWindow( EffectWindow* w, int mask, QRegion region, Wi
break; break;
} }
case Rotation: { case Rotation: {
RotationData rot; data.rotation.setAxis((Qt::Axis)metaData(Axis, anim->meta));
rot.axis = (RotationData::RotationAxis)metaData(Axis, anim->meta);
const float prgrs = progress(*anim); const float prgrs = progress(*anim);
rot.angle = anim->from[0] + prgrs*(anim->to[0] - anim->from[0]); data.rotation.setAngle(anim->from[0] + prgrs*(anim->to[0] - anim->from[0]));
const QRect geo = w->rect(); const QRect geo = w->rect();
const uint sAnchor = metaData(SourceAnchor, anim->meta), const uint sAnchor = metaData(SourceAnchor, anim->meta),
@ -477,10 +476,7 @@ void AnimationEffect::paintWindow( EffectWindow* w, int mask, QRegion region, Wi
QPointF pt2(xCoord(geo, tAnchor), yCoord(geo, tAnchor)); QPointF pt2(xCoord(geo, tAnchor), yCoord(geo, tAnchor));
pt += static_cast<qreal>(prgrs)*(pt2 - pt); pt += static_cast<qreal>(prgrs)*(pt2 - pt);
} }
data.rotation.setOrigin(QVector3D(pt));
rot.xRotationPoint = pt.x();
rot.yRotationPoint = pt.y();
data.rotation = &rot;
break; break;
} }
case Generic: case Generic:

View file

@ -73,11 +73,31 @@ WindowPaintData::WindowPaintData(EffectWindow* w)
, saturation(1) , saturation(1)
, brightness(1) , brightness(1)
, shader(NULL) , shader(NULL)
, rotation(NULL)
{ {
quads = w->buildQuads(); quads = w->buildQuads();
} }
WindowPaintData::WindowPaintData(const WindowPaintData &other)
: opacity(other.opacity)
, contents_opacity(other.contents_opacity)
, decoration_opacity(other.decoration_opacity)
, xScale(other.xScale)
, yScale(other.yScale)
, zScale(other.zScale)
, xTranslate(other.xTranslate)
, yTranslate(other.yTranslate)
, zTranslate(other.zTranslate)
, saturation(other.saturation)
, brightness(other.brightness)
, quads(other.quads)
, shader(other.shader)
{
rotation.setOrigin(other.rotation.origin());
rotation.setAxis(other.rotation.axis());
rotation.setAngle(other.rotation.angle());
}
ScreenPaintData::ScreenPaintData() ScreenPaintData::ScreenPaintData()
: xScale(1) : xScale(1)
, yScale(1) , yScale(1)
@ -85,17 +105,34 @@ ScreenPaintData::ScreenPaintData()
, xTranslate(0) , xTranslate(0)
, yTranslate(0) , yTranslate(0)
, zTranslate(0) , zTranslate(0)
, rotation(NULL)
{ {
} }
RotationData::RotationData() ScreenPaintData::ScreenPaintData(const ScreenPaintData &other)
: axis(ZAxis) : xScale(other.xScale)
, angle(0.0) , yScale(other.yScale)
, xRotationPoint(0.0) , zScale(other.zScale)
, yRotationPoint(0.0) , xTranslate(other.xTranslate)
, zRotationPoint(0.0) , yTranslate(other.yTranslate)
, zTranslate(other.zTranslate)
{ {
rotation.setOrigin(other.rotation.origin());
rotation.setAxis(other.rotation.axis());
rotation.setAngle(other.rotation.angle());
}
ScreenPaintData &ScreenPaintData::operator=(const ScreenPaintData &rhs)
{
this->xScale = rhs.xScale;
this->yScale = rhs.yScale;
this->zScale = rhs.zScale;
this->xTranslate = rhs.xTranslate;
this->yTranslate = rhs.yTranslate;
this->zTranslate = rhs.zTranslate;
this->rotation.setOrigin(rhs.rotation.origin());
this->rotation.setAxis(rhs.rotation.axis());
this->rotation.setAngle(rhs.rotation.angle());
return *this;
} }
//**************************************** //****************************************

View file

@ -29,6 +29,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QtCore/QPair> #include <QtCore/QPair>
#include <QtCore/QSet> #include <QtCore/QSet>
#include <QtCore/QRect> #include <QtCore/QRect>
#include <QtGui/QGraphicsRotation>
#include <QtGui/QRegion> #include <QtGui/QRegion>
#include <QtCore/QVector> #include <QtCore/QVector>
@ -60,7 +61,6 @@ class Effect;
class WindowQuad; class WindowQuad;
class GLShader; class GLShader;
class XRenderPicture; class XRenderPicture;
class RotationData;
class WindowQuadList; class WindowQuadList;
class WindowPrePaintData; class WindowPrePaintData;
class WindowPaintData; class WindowPaintData;
@ -1652,6 +1652,7 @@ class KWIN_EXPORT WindowPaintData
{ {
public: public:
WindowPaintData(EffectWindow* w); WindowPaintData(EffectWindow* w);
WindowPaintData(const WindowPaintData &other);
/** /**
* Window opacity, in range 0 = transparent to 1 = fully opaque * Window opacity, in range 0 = transparent to 1 = fully opaque
* Opacity for contents is opacity*contents_opacity, the same * Opacity for contents is opacity*contents_opacity, the same
@ -1686,20 +1687,22 @@ public:
* Shader to be used for rendering, if any. * Shader to be used for rendering, if any.
*/ */
GLShader* shader; GLShader* shader;
RotationData* rotation; QGraphicsRotation rotation;
}; };
class KWIN_EXPORT ScreenPaintData class KWIN_EXPORT ScreenPaintData
{ {
public: public:
ScreenPaintData(); ScreenPaintData();
ScreenPaintData(const ScreenPaintData &other);
double xScale; double xScale;
double yScale; double yScale;
double zScale; double zScale;
int xTranslate; int xTranslate;
int yTranslate; int yTranslate;
double zTranslate; double zTranslate;
RotationData* rotation; QGraphicsRotation rotation;
ScreenPaintData& operator=(const ScreenPaintData &rhs);
}; };
class KWIN_EXPORT ScreenPrePaintData class KWIN_EXPORT ScreenPrePaintData
@ -1709,22 +1712,6 @@ public:
QRegion paint; QRegion paint;
}; };
class KWIN_EXPORT RotationData
{
public:
RotationData();
enum RotationAxis {
XAxis,
YAxis,
ZAxis
};
RotationAxis axis;
float angle;
float xRotationPoint;
float yRotationPoint;
float zRotationPoint;
};
/** /**
* @short Helper class for restricting painting area only to allowed area. * @short Helper class for restricting painting area only to allowed area.
* *

View file

@ -136,23 +136,15 @@ QMatrix4x4 SceneOpenGL::transformation(int mask, const ScreenPaintData &data) co
matrix.translate(data.xTranslate, data.yTranslate, data.zTranslate); matrix.translate(data.xTranslate, data.yTranslate, data.zTranslate);
matrix.scale(data.xScale, data.yScale, data.zScale); matrix.scale(data.xScale, data.yScale, data.zScale);
if (!data.rotation) if (data.rotation.angle() == 0.0)
return matrix; return matrix;
// Apply the rotation // Apply the rotation
const qreal xAxis = (data.rotation->axis == RotationData::XAxis ? 1.0 : 0.0); // cannot use data.rotation->applyTo(&matrix) as QGraphicsRotation uses projectedRotate to map back to 2D
const qreal yAxis = (data.rotation->axis == RotationData::YAxis ? 1.0 : 0.0); matrix.translate(data.rotation.origin());
const qreal zAxis = (data.rotation->axis == RotationData::ZAxis ? 1.0 : 0.0); const QVector3D axis = data.rotation.axis();
matrix.rotate(data.rotation.angle(), axis.x(), axis.y(), axis.z());
matrix.translate(data.rotation->xRotationPoint, matrix.translate(-data.rotation.origin());
data.rotation->yRotationPoint,
data.rotation->zRotationPoint);
matrix.rotate(data.rotation->angle, xAxis, yAxis, zAxis);
matrix.translate(-data.rotation->xRotationPoint,
-data.rotation->yRotationPoint,
-data.rotation->zRotationPoint);
return matrix; return matrix;
} }
@ -427,23 +419,15 @@ QMatrix4x4 SceneOpenGL::Window::transformation(int mask, const WindowPaintData &
matrix.translate(data.xTranslate, data.yTranslate, data.zTranslate); matrix.translate(data.xTranslate, data.yTranslate, data.zTranslate);
matrix.scale(data.xScale, data.yScale, data.zScale); matrix.scale(data.xScale, data.yScale, data.zScale);
if (!data.rotation) if (data.rotation.angle() == 0.0)
return matrix; return matrix;
// Apply the rotation // Apply the rotation
const qreal xAxis = (data.rotation->axis == RotationData::XAxis ? 1.0 : 0.0); // cannot use data.rotation.applyTo(&matrix) as QGraphicsRotation uses projectedRotate to map back to 2D
const qreal yAxis = (data.rotation->axis == RotationData::YAxis ? 1.0 : 0.0); matrix.translate(data.rotation.origin());
const qreal zAxis = (data.rotation->axis == RotationData::ZAxis ? 1.0 : 0.0); const QVector3D axis = data.rotation.axis();
matrix.rotate(data.rotation.angle(), axis.x(), axis.y(), axis.z());
matrix.translate(data.rotation->xRotationPoint, matrix.translate(-data.rotation.origin());
data.rotation->yRotationPoint,
data.rotation->zRotationPoint);
matrix.rotate(data.rotation->angle, xAxis, yAxis, zAxis);
matrix.translate(-data.rotation->xRotationPoint,
-data.rotation->yRotationPoint,
-data.rotation->zRotationPoint);
return matrix; return matrix;
} }