summaryrefslogtreecommitdiff
authorSam Spilsbury <smspillaz@gmail.com>2009-11-27 15:10:04 (GMT)
committer Sam Spilsbury <smspillaz@gmail.com>2009-11-27 15:10:04 (GMT)
commita155a5303f0ed9d8c6dfc8a833fe8af29a47cbea (patch) (side-by-side diff)
treec123d476d8c3b33342e90f18375b5145fa597bec
parent9071761b15a9c4b545d3e65c513979a9c2a75571 (diff)
downloadelements-a155a5303f0ed9d8c6dfc8a833fe8af29a47cbea.tar.gz
elements-a155a5303f0ed9d8c6dfc8a833fe8af29a47cbea.tar.bz2
Cleanup and more clearly defined API
-rw-r--r--include/elements/elements.h35
-rw-r--r--src/animation.cpp113
-rw-r--r--src/element.cpp2
-rw-r--r--src/elements.cpp14
-rw-r--r--src/private.h42
5 files changed, 118 insertions, 88 deletions
diff --git a/include/elements/elements.h b/include/elements/elements.h
index 50f1e18..212349e 100644
--- a/include/elements/elements.h
+++ b/include/elements/elements.h
@@ -53,10 +53,6 @@
#include <composite/composite.h>
#include <text/text.h>
-/* This is the number used to make sure that elements don't get all
- created in one place. Bigger number, more distance.
- Possibly fixable later. -> s->width? */
-#define BIG_NUMBER 20000
#define COMPIZ_ELEMENTS_ABI 1
class ElementType;
@@ -67,6 +63,7 @@ class ElementTexture;
typedef boost::function<Element * ()> elementAddFunc;
class PrivateElementScreen;
+class PrivateElementAnimation;
class ElementsTextSurface;
class ElementTexture
@@ -136,10 +133,14 @@ class Element
virtual bool init ();
virtual void move ();
virtual void fini ();
+ private:
void defaultInit ();
- void testCreate ();
+ void regenerateOffscreen ();
+
+ friend class ElementAnimation;
+ friend class PrivateElementScreen;
};
class ElementAnimation
@@ -173,14 +174,6 @@ class ElementAnimation
bool active ();
- bool applyTextures (CompString,
- CompOption::Value::Vector *paths,
- CompOption::Value::Vector *iters,
- int size,
- int iter);
-
- bool testAllOffscreen ();
-
static ElementAnimation *
create (CompString type,
int nElement,
@@ -196,22 +189,8 @@ class ElementAnimation
int iter,
bool rotate);
- int mNElement;
- int mSize;
- int mSpeed;
- int mId;
-
- int mNTexture;
-
- ElementType *mType;
-
- bool mActive;
- bool mValid;
-
- bool mRotate;
+ PrivateElementAnimation *priv;
- ElementTexture::List mTexture;
- std::list<Element *> mElements;
friend class PrivateElementScreen;
};
diff --git a/src/animation.cpp b/src/animation.cpp
index 577a1ca..c554664 100644
--- a/src/animation.cpp
+++ b/src/animation.cpp
@@ -68,7 +68,7 @@ ElementAnimation::create (CompString type,
paths = es->priv->optionGetElementImage ();
iters = es->priv->optionGetElementIter ();
- anim->applyTextures (type, &paths, &iters, size, iter);
+ anim->priv->applyTextures (type, &paths, &iters, size, iter);
for (int i = 0; i < anim->nElement (); i++)
{
@@ -76,7 +76,7 @@ ElementAnimation::create (CompString type,
e->anim = anim;
e->defaultInit ();
e->init ();
- anim->mElements.push_back (e);
+ anim->priv->mElements.push_back (e);
}
es->priv->animations.push_back (anim);
@@ -94,12 +94,12 @@ ElementAnimation::create (CompString type,
}
}
-ElementAnimation::ElementAnimation (CompString type,
- int nElement,
- int size,
- int speed,
- int iter,
- bool rotate) :
+PrivateElementAnimation::PrivateElementAnimation (CompString type,
+ int nElement,
+ int size,
+ int speed,
+ int iter,
+ bool rotate) :
mNElement (nElement),
mSize (size),
mSpeed (speed),
@@ -112,15 +112,26 @@ ElementAnimation::ElementAnimation (CompString type,
{
}
+ElementAnimation::ElementAnimation (CompString type,
+ int nElement,
+ int size,
+ int speed,
+ int iter,
+ bool rotate)
+{
+ priv = new PrivateElementAnimation (type, nElement, size, speed, iter,
+ rotate);
+}
+
ElementAnimation::~ElementAnimation ()
{
ELEMENTS_SCREEN (screen);
- while (!mElements.empty ())
+ while (!priv->mElements.empty ())
{
- Element *e = mElements.back ();
+ Element *e = priv->mElements.back ();
e->fini ();
- mElements.remove (e);
+ priv->mElements.remove (e);
}
es->priv->animations.remove (this);
@@ -132,7 +143,7 @@ ElementAnimation::~ElementAnimation ()
*/
bool
-ElementAnimation::testAllOffscreen ()
+PrivateElementAnimation::removeOffscreenElements ()
{
ELEMENTS_SCREEN (screen);
bool ret = true;
@@ -176,11 +187,11 @@ ElementAnimation::testAllOffscreen ()
/* Apply textures to an animation */
bool
-ElementAnimation::applyTextures (CompString type,
- CompOption::Value::Vector *paths,
- CompOption::Value::Vector *iters,
- int size,
- int iter)
+PrivateElementAnimation::applyTextures (CompString type,
+ CompOption::Value::Vector *paths,
+ CompOption::Value::Vector *iters,
+ int size,
+ int iter)
{
mTexture.setTextures (type, paths, iters, size, iter);
@@ -196,7 +207,7 @@ ElementAnimation::start ()
* allocation etc
*/
- mActive = true;
+ priv->mActive = true;
return true;
}
@@ -204,84 +215,84 @@ ElementAnimation::start ()
void
ElementAnimation::stop ()
{
- mActive = false;
+ priv->mActive = false;
}
void
ElementAnimation::setNElement (int n)
{
- if (mNElement > n)
+ if (priv->mNElement > n)
{
- int count = mNElement - n;
+ int count = priv->mNElement - n;
/* Keep on removing elements off the top of list */
while (count--)
{
- Element *e = mElements.back ();
+ Element *e = priv->mElements.back ();
e->fini ();
- mElements.remove (e);
+ priv->mElements.remove (e);
}
}
- else if (n > mNElement)
+ else if (n > priv->mNElement)
{
- int count = n - mNElement;
+ int count = n - priv->mNElement;
/* Add the difference */
while (count--)
{
- Element *e = mType->addFunc ();
- mElements.push_back (e);
+ Element *e = priv->mType->addFunc ();
+ priv->mElements.push_back (e);
}
}
- mNElement = n;
+ priv->mNElement = n;
}
void
ElementAnimation::setSize (int n)
{
- mSize = n;
+ priv->mSize = n;
}
void
ElementAnimation::setSpeed (int n)
{
- mSpeed = n;
+ priv->mSpeed = n;
}
void
ElementAnimation::setId (int n)
{
- mId = n;
+ priv->mId = n;
}
bool
ElementAnimation::setType (CompString name)
{
- mType = ElementType::find (name);
+ priv->mType = ElementType::find (name);
- if (mType)
+ if (priv->mType)
{
/* Fini all elements */
- int nElement = mNElement;
+ int nElement = priv->mNElement;
while (nElement--)
{
- Element *e = mElements.back ();
+ Element *e = priv->mElements.back ();
e->fini ();
- mElements.remove (e);
+ priv->mElements.remove (e);
}
- nElement = mNElement;
+ nElement = priv->mNElement;
/* Re-create all elements with new type */
while (nElement--)
{
- Element *e = mType->addFunc ();
- mElements.push_back (e);
+ Element *e = priv->mType->addFunc ();
+ priv->mElements.push_back (e);
}
}
else
@@ -293,67 +304,67 @@ ElementAnimation::setType (CompString name)
void
ElementAnimation::setRotate (bool r)
{
- mRotate = r;
+ priv->mRotate = r;
}
ElementTexture::List
ElementAnimation::textures ()
{
- return mTexture;
+ return priv->mTexture;
}
std::list<Element *>
ElementAnimation::elements ()
{
- return mElements;
+ return priv->mElements;
}
void
ElementAnimation::setNTexture (int c)
{
- mNTexture = c;
+ priv->mNTexture = c;
}
int
ElementAnimation::nElement ()
{
- return mNElement;
+ return priv->mNElement;
}
int ElementAnimation::size ()
{
- return mSize;
+ return priv->mSize;
}
int ElementAnimation::speed ()
{
- return mSpeed;
+ return priv->mSpeed;
}
int ElementAnimation::id ()
{
- return mId;
+ return priv->mId;
}
int ElementAnimation::nTexture ()
{
- return mNTexture;
+ return priv->mNTexture;
}
ElementType *
ElementAnimation::type ()
{
- return mType;
+ return priv->mType;
}
bool
ElementAnimation::rotate ()
{
- return mRotate;
+ return priv->mRotate;
}
bool
ElementAnimation::active ()
{
- return mActive;
+ return priv->mActive;
}
diff --git a/src/element.cpp b/src/element.cpp
index 409d077..824605e 100644
--- a/src/element.cpp
+++ b/src/element.cpp
@@ -50,7 +50,7 @@
* remove it and re-initiate it. Otherwise move it */
void
-Element::testCreate ()
+Element::regenerateOffscreen ()
{
ELEMENTS_SCREEN (screen);
diff --git a/src/elements.cpp b/src/elements.cpp
index 1394ad6..a753786 100644
--- a/src/elements.cpp
+++ b/src/elements.cpp
@@ -556,12 +556,12 @@ PrivateElementScreen::redrawTimeout ()
if (anim->active ())
{
- foreach (Element *e, anim->mElements)
+ foreach (Element *e, anim->priv->mElements)
{
/* This tests to see if the element is offscreen, if so
* replace it with one at the beginning of its animation
* the screen if not, move it */
- e->testCreate ();
+ e->regenerateOffscreen ();
}
}
else
@@ -571,10 +571,10 @@ PrivateElementScreen::redrawTimeout ()
* finish "nicely", ie they don't just disappear when untoggled)
*/
- if (anim->testAllOffscreen ())
+ if (anim->priv->removeOffscreenElements ())
{
- anim->mTexture.clear ();
- anim->mElements.clear ();
+ anim->priv->mTexture.clear ();
+ anim->priv->mElements.clear ();
delete anim;
/* We must reset the list count here otherwise foreach will
@@ -655,7 +655,7 @@ PrivateElementScreen::updateElementTextures ()
speed = cSpeed.at (anim->id () - 1).i ();
rotate = cRot.at (anim->id () - 1).b ();
- anim->mTexture.clear ();
+ anim->priv->mTexture.clear ();
if (type != anim->type ()->name ())
{
@@ -682,7 +682,7 @@ PrivateElementScreen::updateElementTextures ()
initiate = true;
}
- if (anim->applyTextures (anim->type ()->name (), &cPath, &cIter, size, iter))
+ if (anim->priv->applyTextures (anim->type ()->name (), &cPath, &cIter, size, iter))
{
if (nElement != anim->nElement ())
{
diff --git a/src/private.h b/src/private.h
index b662ba0..6a08db5 100644
--- a/src/private.h
+++ b/src/private.h
@@ -47,7 +47,10 @@
#include <elements/elements.h>
#include "elements_options.h"
-#define GLOW_STAGES 5
+/* This is the number used to make sure that elements don't get all
+ created in one place. Bigger number, more distance.
+ Possibly fixable later. -> s->width? */
+#define BIG_NUMBER 20000
typedef ElementType ElementType_; // Bug in gcc?
@@ -90,6 +93,43 @@ class ElementsTextSurface
friend class PrivateElementScreen;
};
+class PrivateElementAnimation
+{
+ public:
+
+ PrivateElementAnimation (CompString type,
+ int nElement,
+ int size,
+ int speed,
+ int iter,
+ bool rotate);
+
+ bool applyTextures (CompString,
+ CompOption::Value::Vector *paths,
+ CompOption::Value::Vector *iters,
+ int size,
+ int iter);
+
+ bool removeOffscreenElements ();
+
+ int mNElement;
+ int mSize;
+ int mSpeed;
+ int mId;
+
+ int mNTexture;
+
+ ElementType *mType;
+
+ bool mActive;
+ bool mValid;
+
+ bool mRotate;
+
+ ElementTexture::List mTexture;
+ std::list<Element *> mElements;
+};
+
class PrivateElementScreen :
public ElementsOptions,
public GLScreenInterface,