summaryrefslogtreecommitdiff
path: root/src/photowheel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/photowheel.cpp')
-rw-r--r--src/photowheel.cpp360
1 files changed, 360 insertions, 0 deletions
diff --git a/src/photowheel.cpp b/src/photowheel.cpp
new file mode 100644
index 0000000..d70a1c0
--- /dev/null
+++ b/src/photowheel.cpp
@@ -0,0 +1,360 @@
+/****************
+Copyright stuff goes here =)
+...
+Based on Gears (see below)
+Joel Bosveld (Joel.Bosveld@gmail.com)
+*****************************/
+
+/*
+ * Compiz cube gears plugin
+ *
+ * gears.c
+ *
+ * This is an example plugin to show how to render something inside
+ * of the transparent cube
+ *
+ * Copyright : (C) 2007 by Dennis Kasprzyk
+ * E-mail : onestone@opencompositing.org
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * Based on glxgears.c:
+ * http://cvsweb.xfree86.org/cvsweb/xc/programs/glxgears/glxgears.c
+ */
+
+#include "photowheel.h"
+
+COMPIZ_PLUGIN_20090315 (photowheel, PhotowheelPluginVTable);
+
+void
+PhotowheelScreen::paramChange (CompOption *option,
+ Options num)
+{
+ h = optionGetHeight ();
+ l = optionGetWidth ();
+ rspeed = optionGetSpeed ();
+ xpos = optionGetXpos ();
+ ypos = optionGetYpos ();
+ zpos = optionGetZpos ();
+ transformOrder = optionGetOrder ();
+ enableCull = optionGetCull ();
+}
+
+
+void
+PhotowheelScreen::capChange (CompOption *option,
+ Options num)
+
+{
+ int i;
+ unsigned short *top = optionGetTopColor ();
+ unsigned short *bot = optionGetBottomColor ();
+/*
+ if (!firsttime)
+ {
+ glDeleteLists (dList, 1);
+ }
+*/
+ dList = glGenLists (1);
+ glNewList (dList, GL_COMPILE);
+ glBegin (GL_POLYGON);
+
+ glColor4us (top[0], top[1], top[2], top[3]);
+
+ for( i = n - 1; i > -1; i--)
+ {
+ glVertex3f( cos(i*2*PI/n), 1, sin(i*2*PI/n) );
+ }
+
+ glEnd();
+
+ glBegin (GL_POLYGON);
+
+ glColor4us (bot[0], bot[1], bot[2], bot[3]);
+
+ for (i = 0; i < n; i++)
+ {
+ glVertex3f( cos(i*2*PI/n), -1, sin(i*2*PI/n) );
+ }
+
+ glEnd();
+ glEndList();
+}
+
+void
+PhotowheelScreen::textureChange (CompOption *option,
+ Options num)
+{
+ int i;
+ int i2;
+
+ GLTexture::Matrix mat;
+ CompSize tSize;
+
+ CompOption::Value::Vector imgFiles = optionGetPhotoTextures ();
+
+ n = imgFiles.size ();
+/*
+ if(!firsttime)
+ {
+ for (i = 0; i < n; i++)
+ {
+ photoTexture.at (i).tex.clear ();
+ glDeleteLists (photoTexture.at (i).dList, 1);
+ }
+ }
+*/
+ if (imgFiles.empty () || !imgFiles.size ())
+ {
+ compLogMessage ("photowheel", CompLogLevelWarn,
+ "Could not load image(s)!");
+ return;
+ }
+
+ for (i = 0; i < n; i++)
+ {
+ CompString imgName = imgFiles[i].s ();
+
+ photoTexture.push_back (PhotowheelTexture ());
+
+ photoTexture.at (i).tex = GLTexture::readImageToTexture (imgName, tSize);
+
+ if (photoTexture.at (i).tex.empty ())
+ compLogMessage ("photo", CompLogLevelWarn,
+ "Failed to load image: %s",
+ imgFiles[i].s ().c_str ());
+
+ foreach (GLTexture* texture, photoTexture.at (i).tex)
+ {
+ mat = texture->matrix ();
+ photoTexture.at (i).dList = glGenLists (1);
+
+ i2 = i + 1;
+ if (i2 == n)
+ i2 = 0;
+
+ glNewList (photoTexture.at (i).dList, GL_COMPILE);
+ glBegin(GL_QUADS);
+
+ glTexCoord2f (COMP_TEX_COORD_X (mat, tSize.width ()),
+ COMP_TEX_COORD_Y (mat, 0));
+ /* Top Left Of The Texture and Quad */
+ glVertex3f( cos(i*2*PI/n), 1.0f, sin(i*2*PI/n) );
+
+ glTexCoord2f (COMP_TEX_COORD_X (mat, 0),
+ COMP_TEX_COORD_Y (mat, 0));
+ /* Top Right Of The Texture and Quad */
+ glVertex3f( cos(i2*2*PI/n), 1.0f, sin(i2*2*PI/n) );
+
+ glTexCoord2f (COMP_TEX_COORD_X (mat, 0),
+ COMP_TEX_COORD_Y (mat, tSize.height ()));
+ /* Bottom Right Of The Texture and Quad */
+ glVertex3f( cos(i2*2*PI/n), -1.0f, sin(i2*2*PI/n) );
+
+ glTexCoord2f (COMP_TEX_COORD_X (mat, tSize.width ()),
+ COMP_TEX_COORD_Y (mat, tSize.height ()));
+ /* Bottom Left Of The Texture and Quad */
+ glVertex3f( cos(i*2*PI/n), -1.0f, sin(i*2*PI/n) );
+
+ glEnd();
+ glEndList ();
+ }
+ }
+
+ capChange (NULL, num);
+}
+
+void
+PhotowheelScreen::cubeClearTargetOutput (float xRotate,
+ float vRotate)
+{
+ csScreen->cubeClearTargetOutput (xRotate, vRotate);
+
+ glClear (GL_DEPTH_BUFFER_BIT);
+}
+
+void
+PhotowheelScreen::cubePaintInside (const GLScreenPaintAttrib &sAttrib,
+ const GLMatrix &transform,
+ CompOutput *output,
+ int size)
+{
+ int i;
+ Bool enabled;
+
+ GLScreenPaintAttrib sA = sAttrib;
+
+ sA.yRotate += csScreen->invert () * (360.0f / size) *
+ (csScreen->xRotations () - (screen->vp ().x () *
+ csScreen->nOutput ()));
+
+ GLMatrix mT = transform;
+
+ gScreen->glApplyTransform (sA, output, &mT);
+
+ glPushMatrix();
+ glLoadMatrixf (mT.getMatrix ());
+ glTranslatef (csScreen->outputXOffset (), -csScreen->outputYOffset (), 0.0f);
+ glScalef (csScreen->outputXScale (), csScreen->outputYScale (), 1.0f);
+
+ glPushAttrib (GL_COLOR_BUFFER_BIT | GL_TEXTURE_BIT);
+
+ glEnable (GL_BLEND);
+
+ glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
+ enabled = glIsEnabled (GL_CULL_FACE);
+
+ if(enableCull)
+ glEnable(GL_CULL_FACE);
+ else
+ glDisable(GL_CULL_FACE);
+
+ glPushMatrix();
+
+ glDisable (GL_LIGHTING);
+ glDisable (GL_COLOR_MATERIAL);
+ glEnable (GL_DEPTH_TEST);
+
+ glScalef (0.25f, 0.25f, 0.25f);
+
+ if(transformOrder)
+ glTranslatef(xpos, ypos, zpos);
+
+ glRotatef(angle, 0.0f, 1.0f, 0.0f);
+
+ if (!transformOrder)
+ glTranslatef(xpos, ypos, zpos);
+
+ angle += rspeed;
+
+ if (angle >= 360.0f)
+ angle = 0.0f;
+
+ glScalef (l, h, l);
+
+ for (i = 0; i < n; i++)
+ {
+ foreach (GLTexture* texture, photoTexture.at (i).tex)
+ {
+ texture->enable (GLTexture::Good);
+ glCallList (photoTexture.at (i).dList);
+ texture->disable ();
+ }
+ }
+
+ glCallList(dList);
+
+ glPopMatrix();
+
+ glEnable (GL_COLOR_MATERIAL);
+
+ if (gScreen->lighting ())
+ glEnable (GL_LIGHTING);
+
+ glDisable (GL_DEPTH_TEST);
+ glDisable (GL_BLEND);
+
+ /* resets settings to original */
+ if (enabled)
+ glEnable (GL_CULL_FACE);
+ else
+ glDisable (GL_CULL_FACE);
+
+ glPopMatrix();
+ glPopAttrib();
+
+ damage = true;
+
+ csScreen->cubePaintInside (sAttrib, transform, output, size);
+}
+
+void
+PhotowheelScreen::preparePaint (int ms)
+{
+ cScreen->preparePaint (ms);
+}
+
+void
+PhotowheelScreen::donePaint ()
+{
+ if (damage)
+ {
+ cScreen->damageScreen ();
+ damage = false;
+ }
+
+ cScreen->donePaint ();
+}
+
+PhotowheelScreen::PhotowheelScreen (CompScreen *screen) :
+ PluginClassHandler <PhotowheelScreen, CompScreen> (screen),
+ screen (screen),
+ cScreen (CompositeScreen::get (screen)),
+ gScreen (GLScreen::get (screen)),
+ csScreen (CubeScreen::get (screen)),
+ damage(false),
+ /* firsttime (true), */
+ angle(0.0)
+{
+ ScreenInterface::setHandler (screen, true);
+ CompositeScreenInterface::setHandler (cScreen, true);
+ GLScreenInterface::setHandler (gScreen, true);
+ CubeScreenInterface::setHandler (csScreen, true);
+
+ rspeed = optionGetSpeed ();
+ xpos = optionGetXpos ();
+ ypos = optionGetYpos ();
+ zpos = optionGetZpos ();
+ transformOrder = optionGetOrder ();
+
+ optionSetPhotoTexturesNotify (boost::bind (&PhotowheelScreen::
+ textureChange, this, _1, _2));
+ optionSetHeightNotify (boost::bind (&PhotowheelScreen::
+ paramChange, this, _1, _2));
+ optionSetWidthNotify (boost::bind (&PhotowheelScreen::
+ paramChange, this, _1, _2));
+ optionSetSpeedNotify (boost::bind (&PhotowheelScreen::
+ paramChange, this, _1, _2));
+ optionSetXposNotify (boost::bind (&PhotowheelScreen::
+ paramChange, this, _1, _2));
+ optionSetYposNotify (boost::bind (&PhotowheelScreen::
+ paramChange, this, _1, _2));
+ optionSetZposNotify (boost::bind (&PhotowheelScreen::
+ paramChange, this, _1, _2));
+ optionSetOrderNotify (boost::bind (&PhotowheelScreen::
+ paramChange, this, _1, _2));
+
+ optionSetTopColorNotify (boost::bind (&PhotowheelScreen::
+ capChange, this, _1, _2));
+ optionSetBottomColorNotify (boost::bind (&PhotowheelScreen::
+ capChange, this, _1, _2));
+ optionSetCullNotify (boost::bind (&PhotowheelScreen::
+ paramChange, this, _1, _2));
+}
+
+PhotowheelScreen::~PhotowheelScreen ()
+{
+}
+
+bool
+PhotowheelPluginVTable::init ()
+{
+ if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))
+ return false;
+ if (!CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI))
+ return false;
+ if (!CompPlugin::checkPluginABI ("opengl", COMPIZ_OPENGL_ABI))
+ return false;
+
+ return true;
+}