]> git.siccegge.de Git - frida/frida.git/blob - src/gui/widgets/CFGScene.cxx
7bed8f14b9de2d924b28dc12435a882c9a42028c
[frida/frida.git] / src / gui / widgets / CFGScene.cxx
1 #include "CFGScene.hxx"
2
3 void CFGScene::drawBackground(QPainter* painter, const QRectF & rect) {
4 QGraphicsScene::drawBackground(painter, rect);
5
6 spaceWidgets();
7
8 for (BasicBlockWidget * widget : widgets) {
9 QPointF kopf = widget->getEntry();
10 painter->setPen(QColor(0x00, 0xff, 0x00, 0xff));
11 painter->drawLine(kopf, kopf - QPointF(0, 20));
12
13 auto tails = widget->getExits();
14 auto next = widget->getNext();
15 if (NULL != next[0]) {
16 if (NULL != next[1]) {
17 painter->setPen(QColor(0xff, 0x00, 0x00, 0xff));
18 painter->drawLine(std::get<0>(tails), std::get<0>(tails) + QPointF(0, 20));
19 drawLine(painter, std::get<0>(tails) + QPointF(0, 20), next[1]->getEntry() - QPointF(0, 20));
20 painter->setPen(QColor(0x00, 0xff, 0x00, 0xff));
21 painter->drawLine(std::get<2>(tails), std::get<2>(tails) + QPointF(0, 20));
22 drawLine(painter, std::get<2>(tails) + QPointF(0, 20), next[0]->getEntry() - QPointF(0, 20));
23 } else {
24 painter->setPen(QColor(0x00, 0x00, 0x00, 0xff));
25 painter->drawLine(std::get<1>(tails), std::get<1>(tails) + QPointF(0, 20));
26 drawLine(painter, std::get<1>(tails) + QPointF(0, 20), next[0]->getEntry() - QPointF(0, 20));
27 }
28 }
29 }
30 }
31
32 void CFGScene::drawLine(QPainter* painter, QPointF from, QPointF to, bool left) {
33 if ((to - from).y() > 0) {
34 QPointF angle1(from + QPointF(0, (to - from).y())), angle2(to - QPointF(0, (to - from).y() / 2));
35 painter->drawLine(from, angle1);
36 painter->drawLine(angle1, to);
37 }
38 }
39
40 void CFGScene::spaceWidgets() {
41 bool changed = false;
42 do {
43 changed = false;
44 for (BasicBlockWidget * widget : widgets) {
45 QPointF out(std::get<0>(widget->getExits()));
46 BasicBlockWidget ** next = widget->getNext();
47
48 if (NULL != next[0]
49 && (next[0]->getEntry() - widget->getEntry()).y() > 0
50 && (next[0]->getEntry() - out).y() < 50) {
51 next[0]->moveBy(0, 1);
52 changed = true;
53 }
54 if (NULL != next[1]
55 && (next[1]->getEntry() - widget->getEntry()).y() > 0
56 && (next[1]->getEntry() - out).y() < 50) {
57 next[1]->moveBy(0, 1);
58 changed = true;
59 }
60 }
61 } while (changed);
62 }