]> git.siccegge.de Git - frida/frida.git/blobdiff - src/gui/widgets/BasicBlockWidget.hxx
Draw edges between BasicBlockWidgets while handling loops
[frida/frida.git] / src / gui / widgets / BasicBlockWidget.hxx
index 10ea402267f5fc1dd1aa0088e3dc533b28644e0e..3c61121c75fa3da7f7e55894dc723c3f15e2e5be 100644 (file)
@@ -1,21 +1,44 @@
+#ifndef INCLUDE__BasicBlockWidget_hxx
+#define INCLUDE__BasicBlockWidget_hxx
+
 #include "gui/qt.hxx"
 #include "disassembler/BasicBlock.hxx"
+#include <vector>
+#include <cassert>
 
 class BasicBlockWidget : public QGraphicsItem
 {
 public:
-    BasicBlockWidget(const QString& name);
+    BasicBlockWidget(const QString& name, BasicBlock * block);
 
        void addItem(uint8_t* bytes, size_t num_bytes, const QString& line);
 
     QRectF boundingRect() const  {
         qreal penWidth = 1;
-        return QRectF(x - penWidth / 2, y - penWidth / 2,
+               QRectF result(x - penWidth / 2, y - penWidth / 2,
                       dx + penWidth, dy + penWidth);
+
+
+               if (next[0])
+                       result |= QRectF(QPointF(x + dx/3, y+dy),
+                                                        mapFromScene(next[0]->getEntry()));
+
+               if (next[1])
+                       result |= QRectF(QPointF(x + 2*dx/3, y+dy),
+                                                        mapFromScene(next[1]->getEntry()));
+
+        return result;
     }
+       void mouseMoveEvent(QGraphicsSceneMouseEvent *event) {
+               QGraphicsItem::mouseMoveEvent(event);
+               std::for_each(previous.begin(), previous.end(),
+                                         [&] (BasicBlockWidget * item) {
+                                                 item->update(boundingRect() | item->boundingRect());
+                                         });
+       }
 
        QPointF getEntry() const {
-               return QPointF(x + dx/2, y);
+               return mapToScene(QPointF(x + dx/2, y));
        }
 
     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
@@ -24,11 +47,37 @@ public:
         painter->setPen(QColor(0x00, 0x00, 0xff, 0xff));
         painter->drawRect(x, y, dx, dy);
         painter->drawText(0, -5, name);
-        _widget.render(painter);
+               if (_widget.rowCount() != 0)
+                       _widget.render(painter);
+
+               painter->setPen(QColor(0x00, 0xff, 0x00, 0xff));
+               if (next[0])
+                       painter->drawLine(QPointF(x + dx/3, y+dy),
+                                                         mapFromScene(next[0]->getEntry()));
+
+               painter->setPen(QColor(0xff, 0x00, 0x00, 0xff));
+               if (next[1])
+                       painter->drawLine(QPointF(x + 2*dx/3, y+dy),
+                                                         mapFromScene(next[1]->getEntry()));
+
     }
+
+       void addPrevious(BasicBlockWidget * widget) {
+               previous.push_back(widget);
+       }
+
+       void addNext(BasicBlockWidget * left, BasicBlockWidget * right) {
+               next[0] = left;
+               next[1] = right;
+       }
+
 private:
     int x, y, dx, dy;
     QTableWidget _widget;
        QString name;
        BasicBlock * block;
+       std::vector<BasicBlockWidget*> previous;
+       BasicBlockWidget* next[2];
 };
+
+#endif