summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDennis Kasprzyk <onestone@compiz-fusion.org>2008-09-25 04:13:12 +0200
committerDennis kasprzyk <onestone@compiz-fusion.org>2008-09-25 04:13:12 +0200
commite86fac1b049392a9bff8dac615b9ff34ec8092fd (patch)
tree08a25bf26812ee06496d1094a5fb0c0587047d7a /src
parentee3270073cbcc771581bb802c0331e2c5cd52878 (diff)
downloadunity-window-decorator-e86fac1b049392a9bff8dac615b9ff34ec8092fd.tar.gz
unity-window-decorator-e86fac1b049392a9bff8dac615b9ff34ec8092fd.tar.bz2
Adden CompRegion class.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/privateregion.h19
-rw-r--r--src/rect.cpp6
-rw-r--r--src/region.cpp339
4 files changed, 362 insertions, 3 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 1bcfe44..e585586 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -12,6 +12,7 @@ bin_PROGRAMS = compiz
compiz_LDADD = @COMPIZ_LIBS@ @GL_LIBS@ -lm
compiz_LDFLAGS = -export-dynamic
compiz_SOURCES = \
+ region.cpp \
atoms.cpp \
timer.cpp \
main.cpp \
diff --git a/src/privateregion.h b/src/privateregion.h
new file mode 100644
index 0000000..f511d6e
--- /dev/null
+++ b/src/privateregion.h
@@ -0,0 +1,19 @@
+#ifndef _PRIVATEREGION_H
+#define _PRIVATEREGION_H
+
+#include <core/rect.h>
+#include <core/region.h>
+
+class PrivateRegion {
+ public:
+ PrivateRegion ();
+ ~PrivateRegion ();
+
+ void makeReal ();
+
+ public:
+ Region region;
+ REGION box;
+};
+
+#endif
diff --git a/src/rect.cpp b/src/rect.cpp
index 1b391ce..209e14f 100644
--- a/src/rect.cpp
+++ b/src/rect.cpp
@@ -27,10 +27,10 @@ CompRect::CompRect (const CompRect& r)
mRegion.rects = &mRegion.extents;
}
-Region
-CompRect::region ()
+const Region
+CompRect::region () const
{
- return &mRegion;
+ return const_cast<const Region> (&mRegion);
}
void
diff --git a/src/region.cpp b/src/region.cpp
new file mode 100644
index 0000000..350aeb6
--- /dev/null
+++ b/src/region.cpp
@@ -0,0 +1,339 @@
+#include <stdio.h>
+
+#include <X11/Xlib-xcb.h>
+#include <X11/Xutil.h>
+#include <X11/Xregion.h>
+
+#include <core/core.h>
+
+#include "privateregion.h"
+
+CompRegion::CompRegion ()
+{
+ priv = new PrivateRegion ();
+}
+
+CompRegion::CompRegion (const CompRegion &c)
+{
+ priv = new PrivateRegion ();
+ priv->box = c.priv->box;
+ if (priv->box.rects)
+ priv->box.rects = &priv->box.extents;
+ if (c.priv->region)
+ {
+ priv->region = XCreateRegion ();
+ XUnionRegion (&emptyRegion, c.priv->region, priv->region);
+ }
+}
+
+CompRegion::CompRegion ( int x, int y, int w, int h)
+{
+ priv = new PrivateRegion ();
+ priv->box.extents = CompRect (x, x + w, y, y + h).region ()->extents;
+ priv->box.numRects = 1;
+ priv->box.rects = &priv->box.extents;
+}
+
+CompRegion::CompRegion (const CompRect &r)
+{
+ priv = new PrivateRegion ();
+ priv->box.extents = r.region ()->extents;
+ priv->box.numRects = 1;
+ priv->box.rects = &priv->box.extents;
+}
+
+CompRegion::~CompRegion ()
+{
+ delete priv;
+}
+
+const Region
+CompRegion::handle () const
+{
+ return (priv->region)? priv->region : &priv->box;
+}
+
+CompRegion &
+CompRegion::operator= (const CompRegion &c)
+{
+ priv->box = c.priv->box;
+ if (priv->box.rects)
+ priv->box.rects = &priv->box.extents;
+ if (c.priv->region)
+ {
+ if (!priv->region)
+ priv->region = XCreateRegion ();
+ XUnionRegion (&emptyRegion, c.priv->region, priv->region);
+ }
+ return *this;
+}
+
+bool
+CompRegion::operator== (const CompRegion &c) const
+{
+ return XEqualRegion(handle (), c.handle ());
+}
+
+bool
+CompRegion::operator!= (const CompRegion &c) const
+{
+ return *this == c;
+}
+
+CompRect
+CompRegion::boundingRect () const
+{
+ BOX b = handle ()->extents;
+ return CompRect (b.x1, b.x2, b.y1, b.y2);
+}
+
+bool
+CompRegion::contains (const CompPoint &p) const
+{
+ return XPointInRegion (handle (), p.x (), p.y ());
+}
+
+bool
+CompRegion::contains (const CompRect &r) const
+{
+ return XRectInRegion (handle (), r.x (), r.y (), r.width (), r.height ())
+ != RectangleOut;
+}
+
+CompRegion
+CompRegion::intersected (const CompRegion &r) const
+{
+ CompRegion reg (r);
+ reg.priv->makeReal ();
+ XIntersectRegion (reg.handle (), handle (), reg.handle ());
+ return reg;
+}
+
+CompRegion
+CompRegion::intersected (const CompRect &r) const
+{
+ CompRegion reg (r);
+ reg.priv->makeReal ();
+ XIntersectRegion (reg.handle (), handle (), reg.handle ());
+ return reg;
+}
+
+bool
+CompRegion::intersects (const CompRegion &r) const
+{
+ return !intersected (r).isEmpty ();
+}
+
+bool
+CompRegion::intersects (const CompRect &r) const
+{
+ return !intersected (r).isEmpty ();
+}
+
+bool
+CompRegion::isEmpty () const
+{
+ return XEmptyRegion (handle ());
+}
+
+int
+CompRegion::numRects () const
+{
+ return handle ()->numRects;
+}
+
+CompRect::vector
+CompRegion::rects () const
+{
+ CompRect::vector rv;
+ if (!numRects ())
+ return rv;
+ if (!priv->region)
+ {
+ rv.push_back (CompRect (priv->box.extents.x1, priv->box.extents.x2,
+ priv->box.extents.y1, priv->box.extents.y2));
+ return rv;
+ }
+
+ BOX b;
+ for (int i = 0; i < priv->region->numRects; i++)
+ {
+ b = priv->region->rects[i];
+ rv.push_back (CompRect (b.x1, b.x2, b.y1, b.y2));
+ }
+ return rv;
+}
+
+CompRegion
+CompRegion::subtracted (const CompRegion &r) const
+{
+ CompRegion rv;
+ rv.priv->makeReal ();
+ XSubtractRegion (handle (), r.handle (), rv.handle ());
+ return rv;
+}
+
+void
+CompRegion::translate (int dx, int dy)
+{
+ priv->makeReal ();
+ XOffsetRegion (handle (), dx, dy);
+}
+
+void
+CompRegion::translate (const CompPoint &p)
+{
+ translate (p.x (), p.y ());
+}
+
+CompRegion
+CompRegion::translated (int dx, int dy) const
+{
+ CompRegion rv (*this);
+ rv.translate (dx, dy);
+ return rv;
+}
+
+CompRegion
+CompRegion::translated (const CompPoint &p) const
+{
+ CompRegion rv (*this);
+ rv.translate (p);
+ return rv;
+}
+
+CompRegion
+CompRegion::united (const CompRegion &r) const
+{
+ CompRegion rv;
+ rv.priv->makeReal ();
+ XUnionRegion (handle (), r.handle (), rv.handle ());
+ return rv;
+}
+
+CompRegion
+CompRegion::united (const CompRect &r) const
+{
+ CompRegion rv;
+ rv.priv->makeReal ();
+ XUnionRegion (handle (), r.region (), rv.handle ());
+ return rv;
+}
+
+CompRegion
+CompRegion::xored (const CompRegion &r) const
+{
+ CompRegion rv;
+ rv.priv->makeReal ();
+ XXorRegion (handle (), r.handle (), rv.handle ());
+ return rv;
+}
+
+
+const CompRegion
+CompRegion::operator& (const CompRegion &r) const
+{
+ return intersected (r);
+}
+
+const CompRegion
+CompRegion::operator& (const CompRect &r) const
+{
+ return intersected (r);
+}
+
+CompRegion &
+CompRegion::operator&= (const CompRegion &r)
+{
+ return *this = *this & r;
+}
+
+CompRegion &
+CompRegion::operator&= (const CompRect &r)
+{
+ return *this = *this & r;
+}
+
+const CompRegion
+CompRegion::operator+ (const CompRegion &r) const
+{
+ return united (r);
+}
+
+const CompRegion
+CompRegion::operator+ (const CompRect &r) const
+{
+ return united (r);
+}
+
+CompRegion &
+CompRegion::operator+= (const CompRegion &r)
+{
+ return *this = *this + r;
+}
+
+CompRegion &
+CompRegion::operator+= (const CompRect &r)
+{
+ return *this = *this + r;
+}
+
+const CompRegion
+CompRegion::operator- (const CompRegion &r) const
+{
+ return subtracted (r);
+}
+
+CompRegion &
+CompRegion::operator-= (const CompRegion &r)
+{
+ return *this = *this - r;
+}
+
+const CompRegion
+CompRegion::operator^ (const CompRegion &r) const
+{
+ return xored (r);
+}
+
+CompRegion &
+CompRegion::operator^= (const CompRegion &r)
+{
+ return *this = *this ^ r;
+}
+
+const CompRegion
+CompRegion::operator| (const CompRegion &r) const
+{
+ united (r);
+}
+
+CompRegion &
+CompRegion::operator|= (const CompRegion &r)
+{
+ return *this = *this | r;
+}
+
+
+PrivateRegion::PrivateRegion ()
+{
+ region = NULL;
+ box = emptyRegion;
+}
+
+PrivateRegion::~PrivateRegion ()
+{
+ if (region)
+ XDestroyRegion (region);
+}
+
+void
+PrivateRegion::makeReal ()
+{
+ if (region)
+ return;
+ region = XCreateRegion ();
+ if (box.numRects)
+ XUnionRegion (&emptyRegion, &box, region);
+}
+