GtkWidget *create_diagram(int param, int width, int height, event_diagram_callback ev_callback) { CrZoomer *zoomer; CrPanner *panner; CrRotator *rotator; GdkColor white = {0, 0xffff, 0xffff, 0xffff}; event_callback = ev_callback; diagram = cr_canvas_new("maintain_aspect", TRUE, "auto_scale", FALSE, "maintain_center", TRUE, "repaint_mode", TRUE, NULL); cr_canvas_set_scroll_factor(CR_CANVAS(diagram), 3, 3); gtk_widget_set_size_request(diagram, width, height); panner = cr_panner_new(CR_CANVAS(diagram), "button", 1, NULL); cr_canvas_center_on (diagram, 0, height / 2); data_dumped_set_update_callback(diagram_update); gtk_widget_modify_bg(diagram, GTK_STATE_NORMAL, &white); /* Get root item */ g_object_get(diagram, "root", &root); g_signal_connect (G_OBJECT (diagram), "key_press_event", G_CALLBACK (on_key_press), NULL); return diagram; }
static GtkWidget * create_extra_view(CrItem *top_group) { GtkWidget *window, *canvas; window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), "Slave View"); g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (gtk_main_quit), NULL); canvas = cr_canvas_new(NULL); cr_item_add(CR_CANVAS(canvas)->root, top_group); gtk_widget_set_size_request(canvas, 400,400); gtk_container_add (GTK_CONTAINER (window), canvas); gtk_widget_show_all(window); gtk_window_move(GTK_WINDOW(window), gdk_screen_width() - window->allocation.width, 0); }
int main(int argc, char **argv) { GtkWidget *window, *scrolled_window, *canvas, *vbox, *hbox, *hbox2, *label, *button; CrItem *top_group; CrZoomer *zoomer; CrPanner *panner; CrRotator *rotator; gtk_init(&argc, &argv); /* use for breakpoints: g_log_set_handler ("GLib-GObject", G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, log_func, NULL); g_log_set_handler ("GLib", G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, log_func, NULL); */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), "CR Custom Items Demo"); g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (gtk_main_quit), NULL); vbox = gtk_vbox_new(FALSE, 0); gtk_container_add (GTK_CONTAINER (window), vbox); canvas = cr_canvas_new("maintain_aspect", TRUE, "auto_scale", TRUE, "maintain_center", TRUE, NULL); cr_canvas_set_scroll_factor(CR_CANVAS(canvas), 3, 3); /* by using a canvas group item just below the root, we can open a * separate slave window that will not respond to the zooming operations * made on the main window. */ top_group = g_object_new(CR_TYPE_ITEM, NULL); cr_item_add(CR_CANVAS(canvas)->root, top_group); scrolled_window = gtk_scrolled_window_new(NULL, NULL); gtk_container_add(GTK_CONTAINER(scrolled_window), canvas); gtk_widget_set_size_request(canvas, 400,400); gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0); hbox = gtk_hbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); button = gtk_button_new_with_label("Ellipse"); g_signal_connect_swapped(button, "clicked", G_CALLBACK( add_ellipse), top_group); gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); button = gtk_button_new_with_label("Rect"); g_signal_connect_swapped(button, "clicked", G_CALLBACK( add_rectangle), top_group); gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); button = gtk_button_new_with_label("Line"); g_signal_connect_swapped(button, "clicked", G_CALLBACK( add_line), top_group); gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); button = gtk_button_new_with_label("Text"); g_signal_connect_swapped(button, "clicked", G_CALLBACK( add_text), top_group); gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); button = gtk_button_new_with_label("Pixbuf"); g_signal_connect_swapped(button, "clicked", G_CALLBACK( add_pixbuf), top_group); gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); button = gtk_button_new_with_label("Vector"); g_signal_connect_swapped(button, "clicked", G_CALLBACK( add_vector), top_group); gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); button = gtk_button_new_with_label("Arrows"); g_signal_connect_swapped(button, "clicked", G_CALLBACK( add_arrow), top_group); gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); button = gtk_button_new_with_label("Grab"); g_signal_connect_swapped(button, "clicked", G_CALLBACK( add_grab), top_group); gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0); hbox2 = gtk_hbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0); zoomer = cr_zoomer_new(CR_CANVAS(canvas), "fill_color_rgba", 0xaa00aa77, "outline_color_rgba", 0xffffffff, NULL); button = gtk_button_new_with_label("Zoom Box"); g_signal_connect_swapped(button, "clicked", G_CALLBACK(cr_zoomer_activate), zoomer); gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); button = gtk_button_new_with_label("Zoom X2"); g_signal_connect(button, "clicked", G_CALLBACK(on_zoom_in), canvas); gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); button = gtk_button_new_with_label("Zoom /2"); g_signal_connect(button, "clicked", G_CALLBACK(on_zoom_out), canvas); gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); panner = cr_panner_new(CR_CANVAS(canvas), "button", 1, NULL); button = gtk_button_new_with_label("Pan"); g_signal_connect_swapped(button, "clicked", G_CALLBACK(cr_panner_activate), panner); gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); rotator = cr_rotator_new(CR_CANVAS(canvas), NULL); button = gtk_button_new_with_label("Rotate"); gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); g_signal_connect_swapped(button, "clicked", G_CALLBACK (cr_rotator_activate), rotator); button = gtk_button_new_with_label("Clear"); g_signal_connect(button, "clicked", G_CALLBACK( on_clear ), top_group); gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); button = gtk_button_new_with_label("Quit"); g_signal_connect(button, "clicked", G_CALLBACK( gtk_main_quit), NULL); gtk_box_pack_start (GTK_BOX (hbox2), button, FALSE, FALSE, 0); create_extra_view(top_group); g_object_unref(top_group); gtk_widget_show_all(window); gtk_main(); return 0; }