Add +/- keys for zoom in/out

This commit is contained in:
pancake 2015-06-29 17:00:12 +02:00
parent 7851b75e5c
commit fbc1746ffa

View File

@ -3,6 +3,7 @@
#include <r_core.h>
static const char *mousemodes[] = { "canvas-y", "canvas-x", "node-y", "node-x", NULL };
static int mousemode = 0;
static int zoom = 100;
#define BORDER 3
#define BORDER_WIDTH 4
@ -100,6 +101,9 @@ static void update_node_dimension(RGraph *g, int is_small) {
n->w += BORDER_WIDTH;
n->h += BORDER_HEIGHT;
n->w = R_MAX (MAX_NODE_WIDTH, n->w);
/* scale node by zoom */
n->w = (n->w * zoom) / 100;
n->h = (n->h * zoom) / 100;
}
}
}
@ -157,9 +161,19 @@ static void normal_ANode_print(AGraph *g, ANode *n, int cur) {
}
if (delta_x < strlen(title) && G(n->x + MARGIN_TEXT_X + delta_x, n->y + 1))
W(title + delta_x);
int center_x = 0;
int center_y = 0;
if (zoom>100) {
center_x += ((zoom-100)/20);
center_y += ((zoom-100)/30);
}
if (G(n->x + MARGIN_TEXT_X + delta_x, n->y + MARGIN_TEXT_Y + delta_y)) {
text = r_str_crop (n->text, delta_x, delta_y, n->w - BORDER_WIDTH, n->h);
if (G(n->x + MARGIN_TEXT_X + delta_x + center_x,
n->y + MARGIN_TEXT_Y + delta_y + center_y)) {
text = r_str_crop (n->text,
delta_x, delta_y,
n->w - BORDER_WIDTH,
n->h - BORDER_WIDTH + 1);
if (text) {
W (text);
free (text);
@ -966,9 +980,9 @@ static int agraph_refresh(struct agraph_refresh_data *grd) {
if (fs) {
(void)G (-g->can->sx, -g->can->sy);
snprintf (title, sizeof (title)-1,
"[0x%08"PFMT64x"]> %d VV @ %s (nodes %d edges %d) %s mouse:%s",
"[0x%08"PFMT64x"]> %d VV @ %s (nodes %d edges %d zoom %d%%) %s mouse:%s",
g->fcn->addr, r_stack_size (g->history), g->fcn->name,
g->graph->n_nodes, g->graph->n_edges, g->is_callgraph?"CG":"BB",
g->graph->n_nodes, g->graph->n_edges, zoom, g->is_callgraph?"CG":"BB",
mousemodes[mousemode]);
W (title);
}
@ -1004,11 +1018,8 @@ static void agraph_init(AGraph *g) {
}
static AGraph *agraph_new(RCore *core, RConsCanvas *can, RAnalFunction *fcn) {
AGraph *g;
g = (AGraph *)malloc(sizeof(AGraph));
if (!g)
return NULL;
AGraph *g = R_NEW0 (AGraph);
if (!g) return NULL;
g->core = core;
g->can = can;
@ -1084,6 +1095,20 @@ R_API int r_core_visual_graph(RCore *core, RAnalFunction *_fcn, int is_interacti
wheelspeed = r_config_get_i (core->config, "scr.wheelspeed");
switch (key) {
case '-':
zoom-=10;
if (zoom<0) zoom = 0;
update_node_dimension(g->graph, g->is_small_nodes);
agraph_set_layout (g);
// agraph_update_seek (g, get_anode(g->curnode), R_TRUE);
break;
case '+':
zoom+=10;
update_node_dimension (g->graph, g->is_small_nodes);
agraph_set_layout (g);
// agraph_update_seek (g, get_anode(g->curnode), R_TRUE);
// g->is_instep = R_TRUE;
break;
case '=':
case '|':
{ // TODO: edit
@ -1161,6 +1186,7 @@ R_API int r_core_visual_graph(RCore *core, RAnalFunction *_fcn, int is_interacti
" V - toggle basicblock / call graphs\n"
" x/X - jump to xref/ref\n"
" z/Z - step / step over\n"
" +/- - zoom in/out\n"
" R - relayout\n");
r_cons_flush ();
r_cons_any_key (NULL);
@ -1238,14 +1264,17 @@ R_API int r_core_visual_graph(RCore *core, RAnalFunction *_fcn, int is_interacti
agraph_undo_node(g);
break;
case '.':
agraph_update_seek (g, get_anode(g->curnode), R_TRUE);
zoom = 100;
update_node_dimension (g->graph, g->is_small_nodes);
agraph_set_layout (g);
//agraph_update_seek (g, get_anode (g->curnode), R_TRUE);
g->is_instep = R_TRUE;
break;
case 't':
agraph_follow_true(g);
agraph_follow_true (g);
break;
case 'f':
agraph_follow_false(g);
agraph_follow_false (g);
break;
case '/':
r_core_cmd0 (core, "?i highlight;e scr.highlight=`?y`");