Changeset 5326


Ignore:
Timestamp:
07/28/09 13:38:13 (4 years ago)
Author:
werner
Message:
  • added to do list
  • vectors now have arrow heads
  • breaking gui.c down into smaller parts
  • added status area
  • added zoom and centering

Still a lot more to do.

Location:
developers/werner/fped
Files:
6 added
7 edited

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 
     1OBJS = 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 
    33 
    44CFLAGS_GTK = `pkg-config --cflags gtk+-2.0` 
  • developers/werner/fped/coord.h

    r5325 r5326  
    11/* 
    2  * coord.h - Coordinate representation 
     2 * coord.h - Coordinate representation and basic operations 
    33 * 
    44 * Written 2009 by Werner Almesberger 
     
    5858} 
    5959 
     60 
     61struct coord normalize(struct coord v, unit_type len); 
     62struct coord rotate(struct coord v, double angle); 
     63struct coord add_vec(struct coord a, struct coord b); 
     64struct coord sub_vec(struct coord a, struct coord b); 
     65struct coord neg_vec(struct coord v); 
     66 
    6067#endif /* !COORD_H */ 
  • developers/werner/fped/gui.c

    r5325 r5326  
    1616 
    1717#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" 
    2120#include "gui.h" 
    2221 
     
    6968 
    7069 
    71 static gboolean expose_event_callback(GtkWidget *widget, GdkEventExpose *event, 
    72      gpointer data) 
     70static void show_vars(GtkWidget *var_list) 
    7371{ 
    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; 
    7973 
    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); 
    8875 
    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} 
    9380 
    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 
     82static 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); 
    11491} 
    11592 
     
    11895{ 
    11996        GtkWidget *hbox; 
    120         GtkWidget *frame_list, *sep, *canvas; 
     97        GtkWidget *frame_list, *var_list, *row_list; 
     98        GtkWidget *sep; 
    12199        GdkColor black = { 0, 0, 0, 0 }; 
    122100 
    123101        hbox = gtk_hbox_new(FALSE, 0); 
     102        gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); 
     103 
     104        /* Frame list */ 
    124105 
    125106        frame_list = gtk_tree_view_new(); 
     
    135116        gtk_widget_modify_bg(sep, GTK_STATE_NORMAL, &black); 
    136117 
    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         */ 
    142125 
    143         gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); 
    144 } 
     126        /* Variable list */ 
    145127 
     128        var_list = gtk_tree_view_new(); 
     129        gtk_box_pack_start(GTK_BOX(hbox), var_list, FALSE, TRUE, 0); 
    146130 
    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); 
    150133 
    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); 
    153157} 
    154158 
     
    163167        make_menu_bar(vbox); 
    164168        make_center_area(vbox); 
    165         make_input_area(vbox); 
     169        make_status_area(vbox); 
    166170} 
    167171 
  • developers/werner/fped/gui_inst.c

    r5325 r5326  
    1212 
    1313 
     14#include <stdlib.h> 
    1415#include <gtk/gtk.h> 
    1516 
     
    2324 
    2425 
    25 static struct coord translate(const struct draw_ctx *ctx, struct coord pos) 
     26struct coord translate(const struct draw_ctx *ctx, struct coord pos) 
    2627{ 
    2728        pos.x -= ctx->center.x; 
     
    3334        pos.y += ctx->widget->allocation.height/2; 
    3435fprintf(stderr, "%d %d\n", (int) pos.x, (int) pos.y); 
     36        return pos; 
     37} 
     38 
     39 
     40struct 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; 
    3549        return pos; 
    3650} 
     
    6377 
    6478 
     79#define MAX_POINTS      10 
     80 
     81 
     82static 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 
     98static 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 
    65112/* ----- vec --------------------------------------------------------------- */ 
    66113 
     
    72119 
    73120        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); 
    74123        gdk_draw_line(DA, gc_vec_bg, from.x, from.y, to.x, to.y); 
    75  
    76124} 
    77125 
     
    98146 
    99147        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); 
    101149} 
    102150 
     
    112160        /* @@@ name */ 
    113161        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); 
    115163} 
    116164 
  • developers/werner/fped/gui_inst.h

    r5325 r5326  
    2828 
    2929 
     30struct coord translate(const struct draw_ctx *ctx, struct coord pos); 
     31struct coord canvas_to_coord(const struct draw_ctx *ctx, int x, int y); 
     32 
    3033void gui_draw_vec(struct inst *self, struct draw_ctx *ctx); 
    3134void gui_draw_line(struct inst *self, struct draw_ctx *ctx); 
  • developers/werner/fped/gui_style.h

    r5325 r5326  
    1717#define CANVAS_CLEARANCE        10 
    1818 
    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 
    2122 
    2223#define FRAME_CLEARANCE         5 
  • developers/werner/fped/qfn.fpd

    r5325 r5326  
    2424n = 0, N/4-1 
    2525 
    26 .vec @ P*(n-(N-1)/2), -Ay/2 
     26.vec @ P*(n-N/4/2), -Ay/2 
    2727.frame pad_up . 
Note: See TracChangeset for help on using the changeset viewer.