sdiagram.h (4169B)
1 /* sdiagram - simple diagram tool 2 * See LICENSE file for copyright and license details. */ 3 4 #ifndef SDIAGRAM_H 5 #define SDIAGRAM_H 6 7 #include <gtk/gtk.h> 8 #include <sqlite3.h> 9 10 enum { ASSET_COPY, ASSET_SYMLINK }; 11 enum { MODE_NORMAL, MODE_CONNECT }; 12 enum { EDIT_TITLE, EDIT_DESC, EDIT_CONN_LABEL }; 13 14 typedef struct { 15 double bg[4]; 16 double card[4]; 17 double fg[4]; 18 double border[4]; 19 double muted[4]; 20 double muted_fg[4]; 21 double primary[4]; 22 double primary_fg[4]; 23 double conn[4]; 24 double sel[4]; 25 double grid[4]; 26 double hdr[6][3]; 27 int nhdr; 28 } Theme; 29 30 typedef struct { 31 int id; 32 double x, y, w, h; 33 char text[256]; 34 char asset[512]; /* relative path in assets/ dir */ 35 char desc[1024]; /* editable description */ 36 double hdr[3]; /* header color rgb */ 37 int selected; 38 GdkPixbuf *thumb; /* cached image thumbnail */ 39 } Node; 40 41 typedef struct { 42 int id; 43 int from; /* node id */ 44 int to; /* node id */ 45 char label[128]; 46 } Conn; 47 48 typedef struct { 49 Node *nodes; 50 int nnodes; 51 int ncap; 52 53 Conn *conns; 54 int nconns; 55 int ccap; 56 57 char path[1024]; /* diagram directory */ 58 char dbpath[1024]; /* diagram.db path */ 59 char adir[1024]; /* assets/ path */ 60 int amode; /* ASSET_COPY or ASSET_SYMLINK */ 61 62 double panx, pany; 63 double zoom; 64 65 int sel; /* selected node index, -1 = none */ 66 int selconn; /* selected conn index, -1 = none */ 67 int mode; /* MODE_NORMAL or MODE_CONNECT */ 68 int connfrom; /* source node idx for connecting */ 69 int dragging; 70 double dragox, dragoy; 71 int panning; 72 double pansx, pansy; 73 74 int nextid; 75 int modified; 76 int hdr_idx; /* cycles through header presets */ 77 78 int dark; /* 0=light, 1=dark */ 79 const Theme *theme; /* current theme pointer */ 80 81 int edit_mode; /* EDIT_TITLE, EDIT_COMMENT, etc */ 82 int editing; /* node/conn index being edited */ 83 84 double ctx_cx, ctx_cy; /* right-click canvas coords */ 85 86 GtkWidget *window; 87 GtkWidget *overlay; 88 GtkWidget *canvas; 89 GtkWidget *status; 90 GtkWidget *popover; 91 GtkWidget *popentry; 92 GtkWidget *ctxmenu; 93 GtkWidget *theme_btn; 94 GtkWidget *desc_edit; /* inline text view for desc */ 95 GtkCssProvider *theme_css; 96 } Diagram; 97 98 /* data.c */ 99 void data_init(Diagram *d); 100 void data_free(Diagram *d); 101 int node_add(Diagram *d, double x, double y, const char *text); 102 void node_del(Diagram *d, int idx); 103 int node_by_id(Diagram *d, int id); 104 int node_at(Diagram *d, double x, double y); 105 double node_height(Node *n); 106 int conn_add(Diagram *d, int from, int to, const char *label); 107 void conn_del(Diagram *d, int idx); 108 int conn_at(Diagram *d, double x, double y); 109 int asset_import(Diagram *d, int nidx, const char *filepath); 110 void asset_remove(Diagram *d, int nidx); 111 void thumb_load(Node *n, const char *adir); 112 int db_save(Diagram *d); 113 int db_load(Diagram *d, const char *path); 114 int db_new(Diagram *d, const char *path); 115 116 /* canvas.c */ 117 void canvas_draw(GtkDrawingArea *area, cairo_t *cr, 118 int w, int h, gpointer data); 119 void canvas_click(GtkGestureClick *g, int np, 120 double x, double y, gpointer data); 121 void canvas_rclick(GtkGestureClick *g, int np, 122 double x, double y, gpointer data); 123 void canvas_drag_begin(GtkGestureDrag *g, 124 double x, double y, gpointer data); 125 void canvas_drag_update(GtkGestureDrag *g, 126 double ox, double oy, gpointer data); 127 void canvas_drag_end(GtkGestureDrag *g, 128 double ox, double oy, gpointer data); 129 gboolean canvas_scroll(GtkEventControllerScroll *c, 130 double dx, double dy, gpointer data); 131 gboolean canvas_key(GtkEventControllerKey *c, 132 guint kv, guint kc, GdkModifierType st, gpointer data); 133 134 /* sdiagram.c */ 135 void screen_to_canvas(Diagram *d, double sx, double sy, 136 double *cx, double *cy); 137 void canvas_to_screen(Diagram *d, double cx, double cy, 138 double *sx, double *sy); 139 void status_update(Diagram *d); 140 void edit_node_text(Diagram *d, int idx); 141 void edit_node_desc(Diagram *d, int idx); 142 void show_context_menu(Diagram *d, double sx, double sy); 143 void do_open(Diagram *d); 144 void do_save(Diagram *d); 145 void do_save_as(Diagram *d); 146 void do_new(Diagram *d); 147 void do_import_image(Diagram *d); 148 void redraw(Diagram *d); 149 void toggle_theme(Diagram *d); 150 151 #endif /* SDIAGRAM_H */