Skip to content

Commit

Permalink
Graph edge highlight (radareorg#1693)
Browse files Browse the repository at this point in the history
* Highlight edges to and from current block in graph.
  • Loading branch information
karliss authored Jul 30, 2019
1 parent fe42069 commit a5dc85c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
10 changes: 10 additions & 0 deletions src/widgets/DisassemblerGraphView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ DisassemblerGraphView::DisassemblerGraphView(QWidget *parent, CutterSeekable* se
// Add header as widget to layout so it stretches to the layout width
layout->setContentsMargins(0, 0, 0, 0);
layout->setAlignment(Qt::AlignTop);

this->scale_thickness_multiplier = true;
}

void DisassemblerGraphView::connectSeekChanged(bool disconn)
Expand Down Expand Up @@ -601,6 +603,11 @@ GraphView::EdgeConfiguration DisassemblerGraphView::edgeConfiguration(GraphView:
}
ec.start_arrow = false;
ec.end_arrow = true;
if (from.entry == currentBlockAddress) {
ec.width_scale = 2.0;
} else if (to->entry == currentBlockAddress) {
ec.width_scale = 2.0;
}
return ec;
}

Expand Down Expand Up @@ -922,6 +929,8 @@ void DisassemblerGraphView::blockClicked(GraphView::GraphBlock &block, QMouseEve
return;
}

currentBlockAddress = block.entry;

highlight_token = getToken(instr, pos.x());

RVA addr = instr->addr;
Expand Down Expand Up @@ -983,6 +992,7 @@ bool DisassemblerGraphView::helpEvent(QHelpEvent *event)

void DisassemblerGraphView::blockTransitionedTo(GraphView::GraphBlock *to)
{
currentBlockAddress = to->entry;
if (transition_dont_seek) {
transition_dont_seek = false;
return;
Expand Down
1 change: 1 addition & 0 deletions src/widgets/DisassemblerGraphView.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ private slots:
int charOffset;
int baseline;
bool emptyGraph;
ut64 currentBlockAddress = RVA_INVALID;

DisassemblyContextMenu *blockMenu;
QMenu *contextMenu;
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/DisassemblyWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -918,9 +918,9 @@ void DisassemblyLeftPanel::paintEvent(QPaintEvent *event)

bool jumpDown = l.arrow > l.offset;
p.setPen(jumpDown ? penDown : penUp);
if (l.offset == currOffset) {
if (l.offset == currOffset || l.arrow == currOffset) {
QPen pen = p.pen();
pen.setWidth((penSizePix * 3) / 2);
pen.setWidthF((penSizePix * 3) / 2.0);
p.setPen(pen);
}
bool endVisible = true;
Expand Down
8 changes: 6 additions & 2 deletions src/widgets/GraphView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,12 @@ void GraphView::paintGraphCache()
QPolygonF polyline = recalculatePolygon(edge.polyline);
EdgeConfiguration ec = edgeConfiguration(block, &blocks[edge.target]);
QPen pen(ec.color);
pen.setWidth(pen.width() / ec.width_scale);
if (pen.width() * current_scale < 2) {
pen.setStyle(ec.lineStyle);
pen.setWidthF(pen.width() * ec.width_scale);
if (scale_thickness_multiplier * ec.width_scale > 1.01 && pen.widthF() * current_scale < 2) {
pen.setWidthF(ec.width_scale / current_scale);
}
if (pen.widthF() * current_scale < 2) {
pen.setWidth(0);
}
p.setPen(pen);
Expand Down
5 changes: 2 additions & 3 deletions src/widgets/GraphView.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class GraphView : public QAbstractScrollArea
bool start_arrow = false;
bool end_arrow = true;
qreal width_scale = 1.0;
Qt::PenStyle lineStyle = Qt::PenStyle::SolidLine;
};

explicit GraphView(QWidget *parent);
Expand Down Expand Up @@ -96,6 +97,7 @@ class GraphView : public QAbstractScrollArea

int width = 0;
int height = 0;
bool scale_thickness_multiplier = false;

void clampViewOffset();
void setViewOffsetInternal(QPoint pos, bool emitSignal = true);
Expand Down Expand Up @@ -125,9 +127,6 @@ class GraphView : public QAbstractScrollArea
int scroll_base_y = 0;
bool scroll_mode = false;

// Todo: remove charheight/charwidth cause it should be handled in child class
qreal charWidth = 10.0;

bool useGL;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/OverviewView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ GraphView::EdgeConfiguration OverviewView::edgeConfiguration(GraphView::GraphBlo
auto baseEcIt = edgeConfigurations.find({from.entry, to->entry});
if (baseEcIt != edgeConfigurations.end())
ec = baseEcIt->second;
ec.width_scale = getViewScale();
ec.width_scale = 1.0 / getViewScale();
return ec;
}

Expand Down

0 comments on commit a5dc85c

Please sign in to comment.