]> git.siccegge.de Git - frida/frida.git/blobdiff - src/gui/widgets/CFGScene.cxx
Add comments on how the graph is drawn
[frida/frida.git] / src / gui / widgets / CFGScene.cxx
index 7e31acbd8dc1af8f05b82c700c10d155b9f191cb..aa27f2c1722caed1bfc2bb5e277ec10ab5495573 100644 (file)
@@ -30,6 +30,12 @@ void CFGScene::drawBackground(QPainter* painter, const QRectF & rect) {
        }
 }
 
+/* Forward edges:  Forward (downward) edges are just drawn straight
+ *                 down and then to the right side
+ * Backward edges: Consider the smallest rectangle that contains both,
+ *                 source and destination block. Draw the edge along
+ *                 the shorter side of that rectangle
+ */
 void CFGScene::drawLine(QPainter* painter, BasicBlockWidget * from, BasicBlockWidget * to, int8_t side) {
        QPointF from_p = from->getExits()[side+1] + QPointF(0, 20);
        QPointF to_p = to->getEntry() - QPointF(0, 20);
@@ -66,6 +72,13 @@ void CFGScene::drawLine(QPainter* painter, BasicBlockWidget * from, BasicBlockWi
 
 void CFGScene::spaceWidgets() {
        bool changed = false;
+
+       /* While some BasicBlockWidget overlaps with a direct predecessor,
+        * move that widget down one step. Move each widget at most once
+        * per iteration so that widgets with severall incoming edges
+        * don't outrun these with less -- preserving order by address
+        * where appropriate.
+        */
        do {
                changed = false;
                for (BasicBlockWidget * widget : widgets) {
@@ -86,6 +99,9 @@ void CFGScene::spaceWidgets() {
                }
        } while (changed);
 
+       /* If there are still BasicBlockWidgets overlapping (BasicBlocks
+        * that don't have a direct edge) spread them sideways.
+        */
        for (BasicBlockWidget * widget : widgets) {
                QRectF relevantRect = widget->boundingRect();
                relevantRect.moveTo(widget->scenePos());
@@ -107,3 +123,15 @@ void CFGScene::spaceWidgets() {
                }
        }
 }
+
+void CFGScene::highlightBlock(BasicBlockWidget* block) {
+       QGraphicsView* view = *(views().begin());
+       if (highlightedBlock) {
+               highlightedBlock->setColor(highlightedBlock->defaultColor);
+               update(highlightedBlock->boundingRect());
+       }
+       highlightedBlock = block;
+       view->centerOn(block);
+       block->setColor(block->highlightColor);
+       update(block->boundingRect());
+}