summaryrefslogtreecommitdiff
path: root/dw/tools.cc
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2015-06-09 23:15:39 +0200
committerSebastian Geerken <devnull@localhost>2015-06-09 23:15:39 +0200
commitc1489885decc91520542f54da489af5290e8a98c (patch)
treee757da14394cb2f3032c993acec6a6eec221a5f0 /dw/tools.cc
parent7c8f69de8bc95c6078ee5fc0b63d263a80f31b44 (diff)
SRDOP: Some refactoring.
Diffstat (limited to 'dw/tools.cc')
-rw-r--r--dw/tools.cc102
1 files changed, 102 insertions, 0 deletions
diff --git a/dw/tools.cc b/dw/tools.cc
new file mode 100644
index 00000000..1db83306
--- /dev/null
+++ b/dw/tools.cc
@@ -0,0 +1,102 @@
+#include "tools.hh"
+
+namespace dw {
+namespace core {
+
+SizeParams::SizeParams ()
+{
+ init ();
+}
+
+SizeParams::~SizeParams ()
+{
+ cleanup ();
+}
+
+void SizeParams::init ()
+{
+ numPos = 0;
+ references = NULL;
+ x = y = NULL;
+}
+
+void SizeParams::cleanup ()
+{
+ if (references)
+ delete[] references;
+ if (x)
+ delete[] x;
+ if (y)
+ delete[] y;
+
+ init ();
+}
+
+void SizeParams::fill (int numPos, Widget **references, int *x, int *y)
+{
+ cleanup ();
+
+ this->numPos = numPos;
+
+ this->references = new Widget*[numPos];
+ this->x = new int[numPos];
+ this->y = new int[numPos];
+
+ for (int i = 0; i < numPos; i++) {
+ this->references[i] = references[i];
+ this->x[i] = x[i];
+ this->y[i] = y[i];
+ }
+}
+
+void SizeParams::forChild (Widget *parent, Widget *child, int xRel, int yRel,
+ SizeParams *childParams)
+{
+ int numChildReferences = child->numSizeRequestReferences ();
+
+ childParams->numPos = 0;
+ childParams->references = new Widget*[numChildReferences];
+ childParams->x = new int[numChildReferences];
+ childParams->y = new int[numChildReferences];
+
+ for (int i = 0; i < numChildReferences; i++) {
+ Widget *childReference = child->sizeRequestReference (i);
+ if (childReference == parent) {
+ references[numPos] = childReference;
+ childParams->x[numPos] = xRel;
+ childParams->y[numPos] = yRel;
+ numPos++;
+ } else {
+ bool found = false;
+ for (int j = 0; !found && j < numPos; j++) {
+ if (childReference == references[j]) {
+ found = true;
+ references[numPos] = childReference;
+ childParams->x[numPos] = x[j] + xRel;
+ childParams->y[numPos] = y[j] + yRel;
+ numPos++;
+ }
+ }
+ }
+ }
+
+}
+
+bool SizeParams::findReference (Widget *reference, int *x, int *y)
+{
+ for (int i = 0; i < numPos; i++) {
+ if (reference == references[i]) {
+ if (x)
+ *x = this->x[i];
+ if (y)
+ *y = this->y[i];
+ return true;
+ }
+ }
+
+ return false;
+}
+
+
+} // namespace core
+} // namespace dw