Changeset View
Changeset View
Standalone View
Standalone View
effects/cube/cube.cpp
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | 50 | CubeEffect::CubeEffect() | |||
---|---|---|---|---|---|
51 | : activated(false) | 51 | : activated(false) | ||
52 | , cube_painting(false) | 52 | , cube_painting(false) | ||
53 | , keyboard_grab(false) | 53 | , keyboard_grab(false) | ||
54 | , painting_desktop(1) | 54 | , painting_desktop(1) | ||
55 | , frontDesktop(0) | 55 | , frontDesktop(0) | ||
56 | , cubeOpacity(1.0) | 56 | , cubeOpacity(1.0) | ||
57 | , opacityDesktopOnly(true) | 57 | , opacityDesktopOnly(true) | ||
58 | , displayDesktopName(false) | 58 | , displayDesktopName(false) | ||
59 | , desktopNameFrame(NULL) | 59 | , desktopNameFrame(nullptr) | ||
60 | , reflection(true) | 60 | , reflection(true) | ||
61 | , desktopChangedWhileRotating(false) | 61 | , desktopChangedWhileRotating(false) | ||
62 | , paintCaps(true) | 62 | , paintCaps(true) | ||
63 | , wallpaper(NULL) | 63 | , wallpaper(nullptr) | ||
64 | , texturedCaps(true) | 64 | , texturedCaps(true) | ||
65 | , capTexture(NULL) | 65 | , capTexture(nullptr) | ||
66 | , reflectionPainting(false) | 66 | , reflectionPainting(false) | ||
67 | , activeScreen(0) | 67 | , activeScreen(0) | ||
68 | , bottomCap(false) | 68 | , bottomCap(false) | ||
69 | , closeOnMouseRelease(false) | 69 | , closeOnMouseRelease(false) | ||
70 | , zoom(0.0) | 70 | , zoom(0.0) | ||
71 | , zPosition(0.0) | 71 | , zPosition(0.0) | ||
72 | , useForTabBox(false) | 72 | , useForTabBox(false) | ||
73 | , tabBoxMode(false) | 73 | , tabBoxMode(false) | ||
74 | , shortcutsRegistered(false) | 74 | , shortcutsRegistered(false) | ||
75 | , mode(Cube) | 75 | , mode(Cube) | ||
76 | , useShaders(false) | 76 | , useShaders(false) | ||
77 | , cylinderShader(0) | 77 | , cylinderShader(nullptr) | ||
78 | , sphereShader(0) | 78 | , sphereShader(nullptr) | ||
79 | , zOrderingFactor(0.0f) | 79 | , zOrderingFactor(0.0f) | ||
80 | , mAddedHeightCoeff1(0.0f) | 80 | , mAddedHeightCoeff1(0.0f) | ||
81 | , mAddedHeightCoeff2(0.0f) | 81 | , mAddedHeightCoeff2(0.0f) | ||
82 | , m_cubeCapBuffer(NULL) | 82 | , m_cubeCapBuffer(nullptr) | ||
83 | , m_proxy(this) | 83 | , m_proxy(this) | ||
84 | , m_cubeAction(new QAction(this)) | 84 | , m_cubeAction(new QAction(this)) | ||
85 | , m_cylinderAction(new QAction(this)) | 85 | , m_cylinderAction(new QAction(this)) | ||
86 | , m_sphereAction(new QAction(this)) | 86 | , m_sphereAction(new QAction(this)) | ||
87 | { | 87 | { | ||
88 | initConfig<CubeConfig>(); | 88 | initConfig<CubeConfig>(); | ||
89 | desktopNameFont.setBold(true); | 89 | desktopNameFont.setBold(true); | ||
90 | desktopNameFont.setPointSize(14); | 90 | desktopNameFont.setPointSize(14); | ||
91 | 91 | | |||
92 | if (effects->compositingType() == OpenGL2Compositing) { | 92 | if (effects->compositingType() == OpenGL2Compositing) { | ||
93 | m_reflectionShader = ShaderManager::instance()->generateShaderFromResources(ShaderTrait::MapTexture, QString(), QStringLiteral("cube-reflection.glsl")); | 93 | m_reflectionShader = ShaderManager::instance()->generateShaderFromResources(ShaderTrait::MapTexture, QString(), QStringLiteral("cube-reflection.glsl")); | ||
94 | m_capShader = ShaderManager::instance()->generateShaderFromResources(ShaderTrait::MapTexture, QString(), QStringLiteral("cube-cap.glsl")); | 94 | m_capShader = ShaderManager::instance()->generateShaderFromResources(ShaderTrait::MapTexture, QString(), QStringLiteral("cube-cap.glsl")); | ||
95 | } else { | 95 | } else { | ||
96 | m_reflectionShader = NULL; | 96 | m_reflectionShader = nullptr; | ||
97 | m_capShader = NULL; | 97 | m_capShader = nullptr; | ||
98 | } | 98 | } | ||
99 | m_textureMirrorMatrix.scale(1.0, -1.0, 1.0); | 99 | m_textureMirrorMatrix.scale(1.0, -1.0, 1.0); | ||
100 | m_textureMirrorMatrix.translate(0.0, -1.0, 0.0); | 100 | m_textureMirrorMatrix.translate(0.0, -1.0, 0.0); | ||
101 | connect(effects, &EffectsHandler::tabBoxAdded, this, &CubeEffect::slotTabBoxAdded); | 101 | connect(effects, &EffectsHandler::tabBoxAdded, this, &CubeEffect::slotTabBoxAdded); | ||
102 | connect(effects, &EffectsHandler::tabBoxClosed, this, &CubeEffect::slotTabBoxClosed); | 102 | connect(effects, &EffectsHandler::tabBoxClosed, this, &CubeEffect::slotTabBoxClosed); | ||
103 | connect(effects, &EffectsHandler::tabBoxUpdated, this, &CubeEffect::slotTabBoxUpdated); | 103 | connect(effects, &EffectsHandler::tabBoxUpdated, this, &CubeEffect::slotTabBoxUpdated); | ||
104 | connect(effects, &EffectsHandler::screenAboutToLock, this, [this]() { | 104 | connect(effects, &EffectsHandler::screenAboutToLock, this, [this]() { | ||
105 | // Set active(false) does not release key grabs until the animation completes | 105 | // Set active(false) does not release key grabs until the animation completes | ||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | 124 | { | |||
174 | zPosition = CubeConfig::zPosition(); | 174 | zPosition = CubeConfig::zPosition(); | ||
175 | 175 | | |||
176 | useForTabBox = CubeConfig::tabBox(); | 176 | useForTabBox = CubeConfig::tabBox(); | ||
177 | invertKeys = CubeConfig::invertKeys(); | 177 | invertKeys = CubeConfig::invertKeys(); | ||
178 | invertMouse = CubeConfig::invertMouse(); | 178 | invertMouse = CubeConfig::invertMouse(); | ||
179 | capDeformationFactor = (float)CubeConfig::capDeformation() / 100.0f; | 179 | capDeformationFactor = (float)CubeConfig::capDeformation() / 100.0f; | ||
180 | useZOrdering = CubeConfig::zOrdering(); | 180 | useZOrdering = CubeConfig::zOrdering(); | ||
181 | delete wallpaper; | 181 | delete wallpaper; | ||
182 | wallpaper = NULL; | 182 | wallpaper = nullptr; | ||
183 | delete capTexture; | 183 | delete capTexture; | ||
184 | capTexture = NULL; | 184 | capTexture = nullptr; | ||
185 | texturedCaps = CubeConfig::texturedCaps(); | 185 | texturedCaps = CubeConfig::texturedCaps(); | ||
186 | 186 | | |||
187 | timeLine.setEasingCurve(QEasingCurve::InOutSine); | 187 | timeLine.setEasingCurve(QEasingCurve::InOutSine); | ||
188 | timeLine.setDuration(rotationDuration); | 188 | timeLine.setDuration(rotationDuration); | ||
189 | 189 | | |||
190 | verticalTimeLine.setEasingCurve(QEasingCurve::InOutSine); | 190 | verticalTimeLine.setEasingCurve(QEasingCurve::InOutSine); | ||
191 | verticalTimeLine.setDuration(rotationDuration); | 191 | verticalTimeLine.setDuration(rotationDuration); | ||
192 | 192 | | |||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Line(s) | 276 | if (!img.isNull()) { | |||
277 | effects->makeOpenGLContextCurrent(); | 277 | effects->makeOpenGLContextCurrent(); | ||
278 | capTexture = new GLTexture(img); | 278 | capTexture = new GLTexture(img); | ||
279 | capTexture->setFilter(GL_LINEAR); | 279 | capTexture->setFilter(GL_LINEAR); | ||
280 | if (!GLPlatform::instance()->isGLES()) { | 280 | if (!GLPlatform::instance()->isGLES()) { | ||
281 | capTexture->setWrapMode(GL_CLAMP_TO_BORDER); | 281 | capTexture->setWrapMode(GL_CLAMP_TO_BORDER); | ||
282 | } | 282 | } | ||
283 | // need to recreate the VBO for the cube cap | 283 | // need to recreate the VBO for the cube cap | ||
284 | delete m_cubeCapBuffer; | 284 | delete m_cubeCapBuffer; | ||
285 | m_cubeCapBuffer = NULL; | 285 | m_cubeCapBuffer = nullptr; | ||
286 | effects->addRepaintFull(); | 286 | effects->addRepaintFull(); | ||
287 | } | 287 | } | ||
288 | watcher->deleteLater(); | 288 | watcher->deleteLater(); | ||
289 | } | 289 | } | ||
290 | 290 | | |||
291 | QImage CubeEffect::loadWallPaper(const QString &file) | 291 | QImage CubeEffect::loadWallPaper(const QString &file) | ||
292 | { | 292 | { | ||
293 | return QImage(file); | 293 | return QImage(file); | ||
▲ Show 20 Lines • Show All 545 Lines • ▼ Show 20 Line(s) | 838 | if (texture) { | |||
839 | texCoords << texX3 << texY3; | 839 | texCoords << texX3 << texY3; | ||
840 | } | 840 | } | ||
841 | verts << x3 << 0.0 << z3; | 841 | verts << x3 << 0.0 << z3; | ||
842 | } | 842 | } | ||
843 | } | 843 | } | ||
844 | } | 844 | } | ||
845 | delete m_cubeCapBuffer; | 845 | delete m_cubeCapBuffer; | ||
846 | m_cubeCapBuffer = new GLVertexBuffer(GLVertexBuffer::Static); | 846 | m_cubeCapBuffer = new GLVertexBuffer(GLVertexBuffer::Static); | ||
847 | m_cubeCapBuffer->setData(verts.count() / 3, 3, verts.constData(), texture ? texCoords.constData() : NULL); | 847 | m_cubeCapBuffer->setData(verts.count() / 3, 3, verts.constData(), texture ? texCoords.constData() : nullptr); | ||
848 | } | 848 | } | ||
849 | 849 | | |||
850 | void CubeEffect::paintCylinderCap() | 850 | void CubeEffect::paintCylinderCap() | ||
851 | { | 851 | { | ||
852 | QRect rect = effects->clientArea(FullArea, activeScreen, effects->currentDesktop()); | 852 | QRect rect = effects->clientArea(FullArea, activeScreen, effects->currentDesktop()); | ||
853 | float cubeAngle = (float)((float)(effects->numberOfDesktops() - 2) / (float)effects->numberOfDesktops() * 180.0f); | 853 | float cubeAngle = (float)((float)(effects->numberOfDesktops() - 2) / (float)effects->numberOfDesktops() * 180.0f); | ||
854 | 854 | | |||
855 | float radian = (cubeAngle * 0.5) * M_PI / 180; | 855 | float radian = (cubeAngle * 0.5) * M_PI / 180; | ||
Show All 38 Lines | 864 | for (int j = 0; j <= steps; j++) { | |||
894 | verts << x3 << 0.0 << z3; | 894 | verts << x3 << 0.0 << z3; | ||
895 | verts << x4 << 0.0 << z4; | 895 | verts << x4 << 0.0 << z4; | ||
896 | verts << x3 << 0.0 << z3; | 896 | verts << x3 << 0.0 << z3; | ||
897 | verts << x2 << 0.0 << z2; | 897 | verts << x2 << 0.0 << z2; | ||
898 | } | 898 | } | ||
899 | } | 899 | } | ||
900 | delete m_cubeCapBuffer; | 900 | delete m_cubeCapBuffer; | ||
901 | m_cubeCapBuffer = new GLVertexBuffer(GLVertexBuffer::Static); | 901 | m_cubeCapBuffer = new GLVertexBuffer(GLVertexBuffer::Static); | ||
902 | m_cubeCapBuffer->setData(verts.count() / 3, 3, verts.constData(), texture ? texCoords.constData() : NULL); | 902 | m_cubeCapBuffer->setData(verts.count() / 3, 3, verts.constData(), texture ? texCoords.constData() : nullptr); | ||
903 | } | 903 | } | ||
904 | 904 | | |||
905 | void CubeEffect::paintSphereCap() | 905 | void CubeEffect::paintSphereCap() | ||
906 | { | 906 | { | ||
907 | QRect rect = effects->clientArea(FullArea, activeScreen, effects->currentDesktop()); | 907 | QRect rect = effects->clientArea(FullArea, activeScreen, effects->currentDesktop()); | ||
908 | float cubeAngle = (float)((float)(effects->numberOfDesktops() - 2) / (float)effects->numberOfDesktops() * 180.0f); | 908 | float cubeAngle = (float)((float)(effects->numberOfDesktops() - 2) / (float)effects->numberOfDesktops() * 180.0f); | ||
909 | float zTexture = rect.width() / 2 * tan(45.0f * M_PI / 180.0f); | 909 | float zTexture = rect.width() / 2 * tan(45.0f * M_PI / 180.0f); | ||
910 | float radius = (rect.width() * 0.5) / cos(cubeAngle * 0.5 * M_PI / 180.0); | 910 | float radius = (rect.width() * 0.5) / cos(cubeAngle * 0.5 * M_PI / 180.0); | ||
Show All 40 Lines | 923 | for (int j = 0; j < 36; j++) { | |||
951 | verts << x2 << yBottom << z2; | 951 | verts << x2 << yBottom << z2; | ||
952 | verts << x2 << yBottom << z2; | 952 | verts << x2 << yBottom << z2; | ||
953 | verts << x3 << yBottom << z3; | 953 | verts << x3 << yBottom << z3; | ||
954 | verts << x4 << yTop << z4; | 954 | verts << x4 << yTop << z4; | ||
955 | } | 955 | } | ||
956 | } | 956 | } | ||
957 | delete m_cubeCapBuffer; | 957 | delete m_cubeCapBuffer; | ||
958 | m_cubeCapBuffer = new GLVertexBuffer(GLVertexBuffer::Static); | 958 | m_cubeCapBuffer = new GLVertexBuffer(GLVertexBuffer::Static); | ||
959 | m_cubeCapBuffer->setData(verts.count() / 3, 3, verts.constData(), texture ? texCoords.constData() : NULL); | 959 | m_cubeCapBuffer->setData(verts.count() / 3, 3, verts.constData(), texture ? texCoords.constData() : nullptr); | ||
960 | } | 960 | } | ||
961 | 961 | | |||
962 | void CubeEffect::postPaintScreen() | 962 | void CubeEffect::postPaintScreen() | ||
963 | { | 963 | { | ||
964 | effects->postPaintScreen(); | 964 | effects->postPaintScreen(); | ||
965 | if (!activated) | 965 | if (!activated) | ||
966 | return; | 966 | return; | ||
967 | 967 | | |||
968 | bool animation = (animationState != AnimationState::None || verticalAnimationState != VerticalAnimationState::None); | 968 | bool animation = (animationState != AnimationState::None || verticalAnimationState != VerticalAnimationState::None); | ||
969 | if (animationState != AnimationState::None && timeLine.done()) { | 969 | if (animationState != AnimationState::None && timeLine.done()) { | ||
970 | /* An animation have just finished! */ | 970 | /* An animation have just finished! */ | ||
971 | if (animationState == AnimationState::Stop) { | 971 | if (animationState == AnimationState::Stop) { | ||
972 | /* If the stop animation is finished, we're done */ | 972 | /* If the stop animation is finished, we're done */ | ||
973 | if (keyboard_grab) | 973 | if (keyboard_grab) | ||
974 | effects->ungrabKeyboard(); | 974 | effects->ungrabKeyboard(); | ||
975 | keyboard_grab = false; | 975 | keyboard_grab = false; | ||
976 | effects->stopMouseInterception(this); | 976 | effects->stopMouseInterception(this); | ||
977 | effects->setCurrentDesktop(frontDesktop); | 977 | effects->setCurrentDesktop(frontDesktop); | ||
978 | effects->setActiveFullScreenEffect(0); | 978 | effects->setActiveFullScreenEffect(nullptr); | ||
979 | delete m_cubeCapBuffer; | 979 | delete m_cubeCapBuffer; | ||
980 | m_cubeCapBuffer = NULL; | 980 | m_cubeCapBuffer = nullptr; | ||
981 | if (desktopNameFrame) | 981 | if (desktopNameFrame) | ||
982 | desktopNameFrame->free(); | 982 | desktopNameFrame->free(); | ||
983 | activated = false; | 983 | activated = false; | ||
984 | // User can press Esc several times, and several Stop animations can be added to queue. We don't want it | 984 | // User can press Esc several times, and several Stop animations can be added to queue. We don't want it | ||
985 | animationState = AnimationState::None; | 985 | animationState = AnimationState::None; | ||
986 | animations.clear(); | 986 | animations.clear(); | ||
987 | verticalAnimationState = VerticalAnimationState::None; | 987 | verticalAnimationState = VerticalAnimationState::None; | ||
988 | verticalAnimations.clear(); | 988 | verticalAnimations.clear(); | ||
▲ Show 20 Lines • Show All 320 Lines • ▼ Show 20 Line(s) | 1299 | if (effects->compositingType() == OpenGL2Compositing && m_capShader && m_capShader->isValid()) { | |||
1309 | } | 1309 | } | ||
1310 | m_capShader->setUniform(GLShader::ModelViewProjectionMatrix, mvp); | 1310 | m_capShader->setUniform(GLShader::ModelViewProjectionMatrix, mvp); | ||
1311 | } | 1311 | } | ||
1312 | GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer(); | 1312 | GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer(); | ||
1313 | vbo->reset(); | 1313 | vbo->reset(); | ||
1314 | QColor color = capColor; | 1314 | QColor color = capColor; | ||
1315 | capColor.setAlphaF(cubeOpacity); | 1315 | capColor.setAlphaF(cubeOpacity); | ||
1316 | vbo->setColor(color); | 1316 | vbo->setColor(color); | ||
1317 | vbo->setData(verts.size() / 2, 2, verts.constData(), NULL); | 1317 | vbo->setData(verts.size() / 2, 2, verts.constData(), nullptr); | ||
1318 | if (!capShader || mode == Cube) { | 1318 | if (!capShader || mode == Cube) { | ||
1319 | // TODO: use sphere and cylinder shaders | 1319 | // TODO: use sphere and cylinder shaders | ||
1320 | vbo->render(GL_TRIANGLES); | 1320 | vbo->render(GL_TRIANGLES); | ||
1321 | } | 1321 | } | ||
1322 | if (capShader) { | 1322 | if (capShader) { | ||
1323 | ShaderManager::instance()->popShader(); | 1323 | ShaderManager::instance()->popShader(); | ||
1324 | } | 1324 | } | ||
1325 | glDisable(GL_BLEND); | 1325 | glDisable(GL_BLEND); | ||
▲ Show 20 Lines • Show All 425 Lines • Show Last 20 Lines |