Changeset 5326
- Timestamp:
- 07/28/09 13:38:13 (4 years ago)
- Location:
- developers/werner/fped
- Files:
-
- 6 added
- 7 edited
-
Makefile (modified) (1 diff)
-
TODO (added)
-
coord.c (added)
-
coord.h (modified) (2 diffs)
-
gui.c (modified) (5 diffs)
-
gui_canvas.c (added)
-
gui_canvas.h (added)
-
gui_inst.c (modified) (7 diffs)
-
gui_inst.h (modified) (1 diff)
-
gui_status.c (added)
-
gui_status.h (added)
-
gui_style.h (modified) (1 diff)
-
qfn.fpd (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
developers/werner/fped/Makefile
r5325 r5326 1 OBJS = fped.o expr.o obj.o inst.o util.o error.o lex.yy.o y.tab.o \2 gui.o gui_style.o gui_inst.o 1 OBJS = fped.o expr.o coord.o obj.o inst.o util.o error.o lex.yy.o y.tab.o \ 2 gui.o gui_style.o gui_inst.o gui_status.o gui_canvas.o 3 3 4 4 CFLAGS_GTK = `pkg-config --cflags gtk+-2.0` -
developers/werner/fped/coord.h
r5325 r5326 1 1 /* 2 * coord.h - Coordinate representation 2 * coord.h - Coordinate representation and basic operations 3 3 * 4 4 * Written 2009 by Werner Almesberger … … 58 58 } 59 59 60 61 struct coord normalize(struct coord v, unit_type len); 62 struct coord rotate(struct coord v, double angle); 63 struct coord add_vec(struct coord a, struct coord b); 64 struct coord sub_vec(struct coord a, struct coord b); 65 struct coord neg_vec(struct coord v); 66 60 67 #endif /* !COORD_H */ -
developers/werner/fped/gui.c
r5325 r5326 16 16 17 17 #include "obj.h" 18 #include "inst.h" 19 #include "gui_inst.h" 20 #include "gui_style.h" 18 #include "gui_status.h" 19 #include "gui_canvas.h" 21 20 #include "gui.h" 22 21 … … 69 68 70 69 71 static gboolean expose_event_callback(GtkWidget *widget, GdkEventExpose *event, 72 gpointer data) 70 static void show_vars(GtkWidget *var_list) 73 71 { 74 static int need_style = 1; 75 struct bbox bbox; 76 unit_type h, w; 77 int sx, sy; 78 float aw, ah; 72 GtkListStore *list; 79 73 80 struct draw_ctx ctx = { 81 .widget = widget, 82 .scale = 1000, 83 .center = { 84 .x = 0, 85 .y = 0, 86 }, 87 }; 74 list = gtk_list_store_new(1, G_TYPE_STRING); 88 75 89 if (need_style) {90 gui_setup_style(widget->window);91 need_style = 0;92 }76 gtk_tree_view_set_model(GTK_TREE_VIEW(var_list), 77 GTK_TREE_MODEL(list)); 78 g_object_unref(list); 79 } 93 80 94 aw = widget->allocation.width; 95 ah = widget->allocation.height; 96 gdk_draw_rectangle(widget->window, gc_bg, TRUE, 0, 0, aw, ah); 97 bbox = inst_get_bbox(); 98 ctx.center.x = (bbox.min.x+bbox.max.x)/2; 99 ctx.center.y = (bbox.min.y+bbox.max.y)/2; 100 h = bbox.max.x-bbox.min.x; 101 w = bbox.max.y-bbox.min.y; 102 aw -= 2*CANVAS_CLEARANCE; 103 ah -= 2*CANVAS_CLEARANCE; 104 if (aw < 1) 105 aw = 1; 106 if (ah < 1) 107 ah = 1; 108 sx = ceil(h/aw); 109 sy = ceil(w/ah); 110 ctx.scale = sx > sy ? sx : sy > 0 ? sy : 1; 111 112 inst_draw(&ctx); 113 return TRUE; 81 82 static void show_rows(GtkWidget *row_list) 83 { 84 GtkListStore *list; 85 86 list = gtk_list_store_new(1, G_TYPE_STRING); 87 88 gtk_tree_view_set_model(GTK_TREE_VIEW(row_list), 89 GTK_TREE_MODEL(list)); 90 g_object_unref(list); 114 91 } 115 92 … … 118 95 { 119 96 GtkWidget *hbox; 120 GtkWidget *frame_list, *sep, *canvas; 97 GtkWidget *frame_list, *var_list, *row_list; 98 GtkWidget *sep; 121 99 GdkColor black = { 0, 0, 0, 0 }; 122 100 123 101 hbox = gtk_hbox_new(FALSE, 0); 102 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); 103 104 /* Frame list */ 124 105 125 106 frame_list = gtk_tree_view_new(); … … 135 116 gtk_widget_modify_bg(sep, GTK_STATE_NORMAL, &black); 136 117 137 canvas = gtk_drawing_area_new(); 138 gtk_box_pack_start(GTK_BOX(hbox), canvas, TRUE, TRUE, 0); 139 gtk_widget_modify_bg(canvas, GTK_STATE_NORMAL, &black); 140 g_signal_connect (G_OBJECT(canvas), "expose_event", 141 G_CALLBACK(expose_event_callback), NULL); 118 /* 119 * @@@ is this really a good way to present variables ? 120 * 121 * a way to show entire tables may be preferable. also, showing all 122 * tables of a frame at the same time may be more convenient than such 123 * a "peephole" access. 124 */ 142 125 143 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); 144 } 126 /* Variable list */ 145 127 128 var_list = gtk_tree_view_new(); 129 gtk_box_pack_start(GTK_BOX(hbox), var_list, FALSE, TRUE, 0); 146 130 147 static void make_input_area(GtkWidget *vbox) 148 { 149 GtkWidget *entry; 131 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(var_list), 132 -1, "Variable", gtk_cell_renderer_text_new(), "text", 0, NULL); 150 133 151 entry = gtk_entry_new(); 152 gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 0); 134 show_vars(var_list); 135 136 sep = gtk_drawing_area_new(); 137 gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, TRUE, 2); 138 gtk_widget_modify_bg(sep, GTK_STATE_NORMAL, &black); 139 140 /* Row list */ 141 142 row_list = gtk_tree_view_new(); 143 gtk_box_pack_start(GTK_BOX(hbox), row_list, FALSE, TRUE, 0); 144 145 gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(row_list), 146 -1, "Row", gtk_cell_renderer_text_new(), "text", 0, NULL); 147 148 show_rows(row_list); 149 150 sep = gtk_drawing_area_new(); 151 gtk_box_pack_start(GTK_BOX(hbox), sep, FALSE, TRUE, 2); 152 gtk_widget_modify_bg(sep, GTK_STATE_NORMAL, &black); 153 154 /* Canvas */ 155 156 make_canvas(hbox); 153 157 } 154 158 … … 163 167 make_menu_bar(vbox); 164 168 make_center_area(vbox); 165 make_ input_area(vbox);169 make_status_area(vbox); 166 170 } 167 171 -
developers/werner/fped/gui_inst.c
r5325 r5326 12 12 13 13 14 #include <stdlib.h> 14 15 #include <gtk/gtk.h> 15 16 … … 23 24 24 25 25 st atic struct coord translate(const struct draw_ctx *ctx, struct coord pos)26 struct coord translate(const struct draw_ctx *ctx, struct coord pos) 26 27 { 27 28 pos.x -= ctx->center.x; … … 33 34 pos.y += ctx->widget->allocation.height/2; 34 35 fprintf(stderr, "%d %d\n", (int) pos.x, (int) pos.y); 36 return pos; 37 } 38 39 40 struct coord canvas_to_coord(const struct draw_ctx *ctx, int x, int y) 41 { 42 struct coord pos; 43 44 x -= ctx->widget->allocation.width/2; 45 y -= ctx->widget->allocation.height/2; 46 y = -y; 47 pos.x = x*ctx->scale+ctx->center.x; 48 pos.y = y*ctx->scale+ctx->center.y; 35 49 return pos; 36 50 } … … 63 77 64 78 79 #define MAX_POINTS 10 80 81 82 static void draw_poly(struct draw_ctx *ctx, GdkGC *gc, int fill, 83 const struct coord *points, int n_points) 84 { 85 GdkPoint gp[MAX_POINTS]; 86 int i; 87 88 if (n_points > MAX_POINTS) 89 abort(); 90 for (i = 0; i != n_points; i++) { 91 gp[i].x = points[i].x; 92 gp[i].y = points[i].y; 93 } 94 gdk_draw_polygon(DA, gc, fill, gp, n_points); 95 } 96 97 98 static void draw_arrow(struct draw_ctx *ctx, GdkGC *gc, int fill, 99 struct coord from, struct coord to, int len, double angle) 100 { 101 struct coord p[3]; 102 struct coord side; 103 104 side = normalize(sub_vec(to, from), VEC_ARROW_LEN); 105 p[0] = to; 106 p[1] = add_vec(to, rotate(side, 180-VEC_ARROW_ANGLE)); 107 p[2] = add_vec(to, rotate(side, 180+VEC_ARROW_ANGLE)); 108 draw_poly(ctx, gc, fill, p, 3); 109 } 110 111 65 112 /* ----- vec --------------------------------------------------------------- */ 66 113 … … 72 119 73 120 draw_circle(ctx, gc_vec_bg, FALSE, to.x, to.y, VEC_EYE_R); 121 draw_arrow(ctx, gc_vec_bg, TRUE, from, to, 122 VEC_ARROW_LEN, VEC_ARROW_ANGLE); 74 123 gdk_draw_line(DA, gc_vec_bg, from.x, from.y, to.x, to.y); 75 76 124 } 77 125 … … 98 146 99 147 gdk_draw_rectangle(DA, gc_rect_bg, FALSE, 100 min.x, max.y, max.x-min.x +1, min.y-max.y+1);148 min.x, max.y, max.x-min.x, min.y-max.y); 101 149 } 102 150 … … 112 160 /* @@@ name */ 113 161 gdk_draw_rectangle(DA, gc_pad_bg, TRUE, 114 min.x, max.y, max.x-min.x +1, min.y-max.y+1);162 min.x, max.y, max.x-min.x, min.y-max.y); 115 163 } 116 164 -
developers/werner/fped/gui_inst.h
r5325 r5326 28 28 29 29 30 struct coord translate(const struct draw_ctx *ctx, struct coord pos); 31 struct coord canvas_to_coord(const struct draw_ctx *ctx, int x, int y); 32 30 33 void gui_draw_vec(struct inst *self, struct draw_ctx *ctx); 31 34 void gui_draw_line(struct inst *self, struct draw_ctx *ctx); -
developers/werner/fped/gui_style.h
r5325 r5326 17 17 #define CANVAS_CLEARANCE 10 18 18 19 #define VEC_ARROW 6 20 #define VEC_EYE_R 4 19 #define VEC_ARROW_LEN 10 20 #define VEC_ARROW_ANGLE 20 21 #define VEC_EYE_R 5 21 22 22 23 #define FRAME_CLEARANCE 5 -
developers/werner/fped/qfn.fpd
r5325 r5326 24 24 n = 0, N/4-1 25 25 26 .vec @ P*(n- (N-1)/2), -Ay/226 .vec @ P*(n-N/4/2), -Ay/2 27 27 .frame pad_up .
Note: See TracChangeset
for help on using the changeset viewer.
