On Thu, May 7, 2009 at 11:17 AM, Damon Chaplin
<damon karuna eclipse co uk> wrote:
On Thu, 2009-05-07 at 10:19 -0500, Jamie Lahowetz wrote:
> 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.
> //~ 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);
> }
> }
This is your problem. Event signal handlers have to return a gboolean to
indicate whether the signal should be propagated further. If they don't
it can cause weird problems like yours.
Thanks for the quick reply. I made the changes as such but still am blank. I did look for some type of examples for using call backs. It makes sense to me, the function is looking for a logical return so I give it TRUE at the end of the function or it will not continue. Of coarse I'm not a C expert. This setup works in Perl ok, but this is not perl.
#include <gtk/gtk.h>
#include <goocanvas.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.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;
//~ _________________________________________________
//~ 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,GooCanvasItem *canvas)
{
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(canvas,"M 20,20 L 4000,4000","stroke-color","white","line-width",5.0,NULL);
}
}
//~ _________________________________________________
//~ Mouse events
gboolean 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);
}
return 1;
}
//~ _________________________________________________
//~ Zooming
gboolean 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);
return 1;
}
//~ _________________________________________________
//~ 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 *root;
GooCanvasItem *way_group;
GooCanvasItem *radar_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);
//~ radar_group = goo_canvas_group_new(GOO_CANVAS_ITEM(root),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",root);
//~ 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;
}
Damon