Re: Handling long SVG strings in Path



I tried just placing the simple coordinates directly into the Path call instead of reading them from a file, it is still not showing up. Here is my entire code if that helps.

#include <gtk/gtk.h>
#include <goocanvas.h>
#include <stdio.h>
#define MAX_LEN 5000
 
//~ Global Variables
double ps = 0.01;
double top_lat = 43.0;
double top_long = -105.0;
double bot_lat = 38.0;
double bot_long = -100.0;
int hght = 5000;
int wdth = 5000;
GooCanvasItem *root;
 
//~ _________________________________________________
//~ Delete/destroy events
static gboolean delete_event(GtkWidget *widget,GdkEvent *event,gpointer data)
{
    return FALSE;
}
 
static void destroy( GtkWidget *widget,gpointer data )
{
    gtk_main_quit ();
}
 
//~ _________________________________________________
//~ Read GIS data
void read_gis(char *gis)
{     
    FILE * gis_file;
    gchar *path_data;
     
    gis_file = fopen(gis,"r");
    if (gis_file != NULL)
    {
        char path[MAX_LEN + 1];
        fgets(path, MAX_LEN + 1, gis_file);
        printf("%s\n",path);
        fclose (gis_file);
         
        path_data = path;
        //~ goo_canvas_path_new(root,path_data,"stroke-color","white","line-width",5.0,NULL);
        goo_canvas_path_new(root,"M 20,20 L 4000,4000","stroke-color","white","line-width",5.0,NULL);
    }
}
 
//~ _________________________________________________
//~ Mouse events
static void event_handler(GtkWidget *widget,GdkEvent *event,GtkObject *adj)
{
    GdkEventType type;
    type = event->type;
    //~ printf("Event Type: %d\n",type);
     
    //~ double click
    if (type == 5)
    {
        gdouble x;
        x = ((GdkEventButton*)event)->x;
        gdouble y;
        y = ((GdkEventButton*)event)->y;
         
        printf("Mouse Coords: %f %f\n",x,y);
    }
}
 
//~ _________________________________________________
//~ Zooming
static void zoom(GtkAdjustment *adj,GooCanvas *canvas)
{
    gfloat real_zoom;
     
    real_zoom = gtk_adjustment_get_value(adj);
    real_zoom = real_zoom / 100;
    goo_canvas_set_scale(canvas,real_zoom);
}
 
//~ _________________________________________________
//~ Main Loop
int main( int   argc,char *argv[] )
{
    //~ Type Declaration
    GtkWidget *window;
    GtkWidget *scwin;
    GtkWidget *vbox;
    GtkWidget *hbox;
    GtkObject *adj;
    GtkWidget *zoom_spin;
    GtkWidget *zoom_label;
    GtkWidget *canvas;
    GooCanvasItem *way_group;
    GooCanvasItem *way_lines;
    GooCanvasPoints *points;
    int way_ref = 0;
     
    //~ gtk_init
    gtk_init (&argc, &argv);
    
    //~ New Declarations
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    scwin = gtk_scrolled_window_new(NULL,NULL);
    vbox = gtk_vbox_new(FALSE,5);
    hbox = gtk_hbox_new(FALSE,5);
    adj = gtk_adjustment_new(100, 10, 200, 10, 0, 0);
    zoom_spin = gtk_spin_button_new(GTK_ADJUSTMENT(adj),0,0);
    zoom_label = gtk_label_new("Zoom: ");
    canvas = goo_canvas_new();
     
    //~ Signals
    g_signal_connect (G_OBJECT (window), "delete_event",G_CALLBACK (delete_event), NULL);
    g_signal_connect (G_OBJECT (window), "destroy",G_CALLBACK (destroy), NULL);
     
    //~ Properties and Others
    gtk_container_set_border_width(GTK_CONTAINER(window),10);
    gtk_window_set_default_size(GTK_WINDOW(window),800,600);
    gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scwin),GTK_POLICY_ALWAYS,GTK_POLICY_ALWAYS);
    g_object_set(G_OBJECT(canvas),"background-color","black",NULL);
    root = goo_canvas_get_root_item(GOO_CANVAS(canvas));
    goo_canvas_set_bounds(GOO_CANVAS(canvas),0,0,hght,wdth);
    points = goo_canvas_points_new(way_ref);
    way_group = goo_canvas_group_new(GOO_CANVAS_ITEM(root),NULL);
    way_lines = goo_canvas_polyline_new(GOO_CANVAS_ITEM(root),TRUE,0,NULL,"stroke_color","black","line_width",3,NULL);
    g_object_set(G_OBJECT(way_lines),"points",points,NULL);
     
    //~ Adding and Packing
    gtk_container_add(GTK_CONTAINER(window),vbox);
    gtk_container_add(GTK_CONTAINER(scwin),canvas);
    gtk_box_pack_start(GTK_BOX(hbox),zoom_label,FALSE,FALSE,1);
    gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,1);
    gtk_box_pack_start_defaults(GTK_BOX(vbox),scwin);
    gtk_box_pack_start(GTK_BOX(hbox),zoom_spin,FALSE,FALSE,1);
     
    gtk_widget_show_all(window);
    
    read_gis("/mnt/share/uas/GRRUVI2_uc/vortex2.gis");
     
    //~ Signal Connects
    g_signal_connect (G_OBJECT (canvas),"event",G_CALLBACK (event_handler),adj);
    g_signal_connect(G_OBJECT (adj),"value_changed", G_CALLBACK (zoom), canvas);
     
    gtk_main();
     
    return 0;
}

On Thu, May 7, 2009 at 9:40 AM, Damon Chaplin <damon karuna eclipse co uk> wrote:

On Thu, 2009-05-07 at 09:25 -0500, Jamie Lahowetz wrote:
> I went with the fopen to open a file containing the SVG data. The
> problem that I'm encountering is that nothing is being drawn on the
> canvas. I thought that maybe it was because the string was to long. So
> I made it very small, something like "M 20 20 L 4000 4000", which
> should draw a simple line. But, alas this produced no line. Not sure
> what the problem is but here is the code, any help would be
> appreciated.
>
> #define MAX_LEN 5000
>
> void read_gis(char *gis)
> {
>     FILE * gis_file;
>     gchar *path_data;
>
>     gis_file = fopen(gis,"r");
>     if (gis_file != NULL)
>     {
>         char path[MAX_LEN + 1];
>         fgets(path, MAX_LEN + 1, gis_file);
>         printf("%s\n",path);
>         fclose (gis_file);
>
>         path_data = path;
>
> goo_canvas_path_new(root,path_data,"stroke-color","white","line-width",5.0,NULL);
>     }
> }

That works here (with a black canvas so the white path can be seen!).

Damon





--
Jamie Ryan Lahowetz
University of Nebraska - Lincoln
Graduate Student - Geosciences
402.304.0766
jlahowetz gmail com


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]