]> git.siccegge.de Git - frida/frida.git/blobdiff - src/gui/widgets/CFGScene.cxx
Add CFGScene QGraphicsScene taking care of BasicBlock stuff
[frida/frida.git] / src / gui / widgets / CFGScene.cxx
diff --git a/src/gui/widgets/CFGScene.cxx b/src/gui/widgets/CFGScene.cxx
new file mode 100644 (file)
index 0000000..7bed8f1
--- /dev/null
@@ -0,0 +1,62 @@
+#include "CFGScene.hxx"
+
+void CFGScene::drawBackground(QPainter* painter, const QRectF & rect) {
+    QGraphicsScene::drawBackground(painter, rect);
+
+    spaceWidgets();
+
+    for (BasicBlockWidget * widget : widgets) {
+        QPointF kopf = widget->getEntry();
+        painter->setPen(QColor(0x00, 0xff, 0x00, 0xff));
+        painter->drawLine(kopf, kopf - QPointF(0, 20));
+
+        auto tails = widget->getExits();
+        auto next = widget->getNext();
+        if (NULL != next[0]) {
+            if (NULL != next[1]) {
+                painter->setPen(QColor(0xff, 0x00, 0x00, 0xff));
+                painter->drawLine(std::get<0>(tails), std::get<0>(tails) + QPointF(0, 20));
+                drawLine(painter, std::get<0>(tails) + QPointF(0, 20), next[1]->getEntry() - QPointF(0, 20));
+                painter->setPen(QColor(0x00, 0xff, 0x00, 0xff));
+                painter->drawLine(std::get<2>(tails), std::get<2>(tails) + QPointF(0, 20));
+                drawLine(painter, std::get<2>(tails) + QPointF(0, 20), next[0]->getEntry() - QPointF(0, 20));
+            } else {
+                painter->setPen(QColor(0x00, 0x00, 0x00, 0xff));
+                painter->drawLine(std::get<1>(tails), std::get<1>(tails) + QPointF(0, 20));
+                drawLine(painter, std::get<1>(tails) + QPointF(0, 20), next[0]->getEntry() - QPointF(0, 20));
+            }
+        }
+    }
+}
+
+void CFGScene::drawLine(QPainter* painter, QPointF from, QPointF to, bool left) {
+    if ((to - from).y() > 0) {
+        QPointF angle1(from + QPointF(0, (to - from).y())), angle2(to - QPointF(0, (to - from).y() / 2));
+        painter->drawLine(from,   angle1);
+        painter->drawLine(angle1, to);
+    }
+}
+
+void CFGScene::spaceWidgets() {
+    bool changed = false;
+    do {
+        changed = false;
+        for (BasicBlockWidget * widget : widgets) {
+            QPointF out(std::get<0>(widget->getExits()));
+            BasicBlockWidget ** next = widget->getNext();
+
+            if (NULL != next[0]
+                && (next[0]->getEntry() - widget->getEntry()).y() > 0
+                && (next[0]->getEntry() - out).y() < 50) {
+                next[0]->moveBy(0, 1);
+                changed = true;
+            }
+            if (NULL != next[1]
+                && (next[1]->getEntry() - widget->getEntry()).y() > 0
+                && (next[1]->getEntry() - out).y() < 50) {
+                next[1]->moveBy(0, 1);
+                changed = true;
+            }
+        }
+    } while (changed);
+}