1 #ifndef R2_AGRAPH_H
2 #define R2_AGRAPH_H
3 
4 #include <r_types.h>
5 #include <r_cons.h>
6 #include <r_util/r_graph.h>
7 
8 typedef struct r_ascii_node_t {
9 	RGraphNode *gnode;
10 	char *title;
11 	char *body;
12 	char *color;
13 
14 	int x;
15 	int y;
16 	int w;
17 	int h;
18 
19 	int layer;
20 	int layer_height;
21 	int layer_width;
22 	int pos_in_layer;
23 	int is_dummy;
24 	int is_reversed;
25 	int klass;
26 	int difftype;
27 	bool is_mini;
28 } RANode;
29 
30 typedef struct r_core_graph_hits_t {
31 	char *old_word ;
32 	RVector word_list;
33 	int word_nth;
34 } RAGraphHits;
35 
36 
37 #define R_AGRAPH_MODE_NORMAL 0
38 #define R_AGRAPH_MODE_OFFSET 1
39 #define R_AGRAPH_MODE_MINI 2
40 #define R_AGRAPH_MODE_TINY 3
41 #define R_AGRAPH_MODE_SUMMARY 4
42 #define R_AGRAPH_MODE_COMMENTS 5
43 #define R_AGRAPH_MODE_MAX 6
44 
45 typedef void (*RANodeCallback)(RANode *n, void *user);
46 typedef void (*RAEdgeCallback)(RANode *from, RANode *to, void *user);
47 
48 typedef struct r_ascii_graph_t {
49 	RConsCanvas *can;
50 	RGraph *graph;
51 	const RGraphNode *curnode;
52 	char *title;
53 	Sdb *db;
54 	Sdb *nodes; // Sdb with title(key)=RANode*(value)
55 
56 	int layout;
57 	int is_instep;
58 	bool is_tiny;
59 	bool is_dis;
60 	int edgemode;
61 	int mode;
62 	bool is_callgraph;
63 	bool is_interactive;
64 	int zoom;
65 	int movspeed;
66 	bool hints;
67 
68 	RANode *update_seek_on;
69 	bool need_reload_nodes;
70 	bool need_set_layout;
71 	int need_update_dim;
72 	int force_update_seek;
73 
74 	/* events */
75 	RANodeCallback on_curnode_change;
76 	void *on_curnode_change_data;
77 	bool dummy; // enable the dummy nodes for better layouting
78 	bool show_node_titles;
79 	bool show_node_body;
80 	bool show_node_bubble;
81 
82 	int x, y;
83 	int w, h;
84 
85 	/* layout algorithm info */
86 	RList *back_edges;
87 	RList *long_edges;
88 	struct layer_t *layers;
89 	unsigned int n_layers;
90 	RList *dists; /* RList<struct dist_t> */
91 	RList *edges; /* RList<AEdge> */
92 	RAGraphHits ghits;
93 } RAGraph;
94 
95 #ifdef R_API
96 R_API RAGraph *r_agraph_new(RConsCanvas *can);
97 R_API void r_agraph_free(RAGraph *g);
98 R_API void r_agraph_reset(RAGraph *g);
99 R_API void r_agraph_set_title(RAGraph *g, const char *title);
100 R_API RANode *r_agraph_get_first_node(const RAGraph *g);
101 R_API RANode *r_agraph_get_node(const RAGraph *g, const char *title);
102 R_API RANode *r_agraph_add_node(const RAGraph *g, const char *title, const char *body, const char *color);
103 R_API bool r_agraph_del_node(const RAGraph *g, const char *title);
104 R_API void r_agraph_add_edge(const RAGraph *g, RANode *a, RANode *b);
105 R_API void r_agraph_add_edge_at(const RAGraph *g, RANode *a, RANode *b, int nth);
106 R_API void r_agraph_del_edge(const RAGraph *g, RANode *a, RANode *b);
107 R_API void r_agraph_print(RAGraph *g);
108 R_API void r_agraph_print_json(RAGraph *g, PJ *pj);
109 R_API Sdb *r_agraph_get_sdb(RAGraph *g);
110 R_API void r_agraph_foreach(RAGraph *g, RANodeCallback cb, void *user);
111 R_API void r_agraph_foreach_edge(RAGraph *g, RAEdgeCallback cb, void *user);
112 R_API void r_agraph_set_curnode(RAGraph *g, RANode *node);
113 R_API RAGraph *create_agraph_from_graph(const RGraph/*<RGraphNodeInfo>*/ *graph);
114 #endif
115 
116 #endif
117