GtkWidget * create_clipping_page (void) { GtkWidget *vbox, *scrolled_win, *canvas; vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4); g_object_set (vbox, "margin", 4, NULL); gtk_widget_show (vbox); scrolled_win = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win), GTK_SHADOW_IN); gtk_widget_show (scrolled_win); gtk_box_pack_start (GTK_BOX (vbox), scrolled_win); gtk_widget_set_halign (scrolled_win, GTK_ALIGN_FILL); gtk_widget_set_valign (scrolled_win, GTK_ALIGN_FILL); gtk_widget_set_hexpand (scrolled_win, TRUE); gtk_widget_set_vexpand (scrolled_win, TRUE); canvas = goo_canvas_new (); gtk_widget_set_size_request (canvas, 600, 450); goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 1000); gtk_widget_show (canvas); gtk_container_add (GTK_CONTAINER (scrolled_win), canvas); setup_canvas (GOO_CANVAS (canvas)); return vbox; }
void sheet_change_zoom (const Sheet *sheet, gdouble rate) { gdouble scale; sheet->priv->zoom *= rate; scale = goo_canvas_get_scale (GOO_CANVAS (sheet)); scale = scale * rate; goo_canvas_set_scale (GOO_CANVAS (sheet), scale); }
int main () { GtkWidget *window, *scrolled_win, *canvas; GooCanvasItem *root, *rect_item, *text_item; /* Initialize GTK+. */ gtk_init (); /* Create the window and widgets. */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (window), 640, 600); gtk_widget_show (window); g_signal_connect (window, "delete_event", G_CALLBACK (on_delete_event), NULL); scrolled_win = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win), GTK_SHADOW_IN); gtk_widget_show (scrolled_win); gtk_container_add (GTK_CONTAINER (window), scrolled_win); canvas = goo_canvas_new (); gtk_widget_set_size_request (canvas, 600, 450); goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 1000); gtk_widget_show (canvas); gtk_container_add (GTK_CONTAINER (scrolled_win), canvas); root = goo_canvas_get_root_item (GOO_CANVAS (canvas)); /* Add a few simple items. */ rect_item = goo_canvas_rect_new (root, 100, 100, 400, 400, "line-width", 10.0, "radius-x", 20.0, "radius-y", 10.0, "stroke-color", "yellow", "fill-color", "red", NULL); text_item = goo_canvas_text_new (root, "Hello World", 300, 300, -1, GOO_CANVAS_ANCHOR_CENTER, "font", "Sans 24", NULL); goo_canvas_item_rotate (text_item, 45, 300, 300); /* Connect a signal handler for the rectangle item. */ g_signal_connect (rect_item, "button_press_event", G_CALLBACK (on_rect_button_press), NULL); /* Pass control to the GTK+ main event loop. */ gtk_main (); return 0; }
void setup_canvas (GtkWidget *canvas) { GooCanvasItemModel *root; root = goo_canvas_group_model_new (NULL, NULL); goo_canvas_set_root_item_model (GOO_CANVAS (canvas), root); g_print ("\nTable at default size...\n"); create_table1 (canvas, root, 50, 50, -1, -1, FALSE); g_print ("\nTable at reduced size...\n"); create_table1 (canvas, root, 250, 50, 30, 30, FALSE); g_print ("\nTable at enlarged size...\n"); create_table1 (canvas, root, 450, 50, 100, 100, FALSE); g_print ("\nTable with grid lines at default size...\n"); create_table1 (canvas, root, 50, 250, -1, -1, TRUE); g_print ("\nTable with grid lines at reduced size...\n"); create_table1 (canvas, root, 250, 250, 30, 30, TRUE); g_print ("\nTable with grid lines at enlarged size...\n"); create_table1 (canvas, root, 450, 250, 150, 150, TRUE); g_print ("Multispanning table with grid lines at default size...\n"); create_table2 (canvas, root, 50, 450, -1, -1, TRUE); g_print ("Multispanning table with grid lines at reduced size...\n"); create_table2 (canvas, root, 250, 450, 30, 30, TRUE); g_print ("Multispanning table with grid lines at enlarged size...\n"); create_table2 (canvas, root, 450, 450, 150, 150, TRUE); }
GtkWidget * create_focus_page (void) { GtkWidget *vbox, *label, *scrolled_win, *canvas; vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4); gtk_container_set_border_width (GTK_CONTAINER (vbox), 4); gtk_widget_show (vbox); label = gtk_label_new ("Use Tab, Shift+Tab or the arrow keys to move the keyboard focus between the canvas items."); gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); gtk_widget_show (label); scrolled_win = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win), GTK_SHADOW_IN); gtk_widget_show (scrolled_win); gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE, 0); canvas = goo_canvas_new (); gtk_widget_set_can_focus (canvas, TRUE); gtk_widget_set_size_request (canvas, 600, 450); goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 1000); gtk_widget_show (canvas); gtk_container_add (GTK_CONTAINER (scrolled_win), canvas); g_signal_connect (canvas, "item_created", G_CALLBACK (on_item_created), NULL); setup_canvas (canvas); return vbox; }
static void setup_canvas (GtkWidget *canvas) { GooCanvasItemModel *root; root = goo_canvas_group_model_new (NULL, NULL); goo_canvas_set_root_item_model (GOO_CANVAS (canvas), root); g_object_unref (root); create_focus_box (canvas, 110, 80, 50, 30, "red"); create_focus_box (canvas, 300, 160, 50, 30, "orange"); create_focus_box (canvas, 500, 50, 50, 30, "yellow"); create_focus_box (canvas, 70, 400, 50, 30, "blue"); create_focus_box (canvas, 130, 200, 50, 30, "magenta"); create_focus_box (canvas, 200, 160, 50, 30, "green"); create_focus_box (canvas, 450, 450, 50, 30, "cyan"); create_focus_box (canvas, 300, 350, 50, 30, "grey"); create_focus_box (canvas, 900, 900, 50, 30, "gold"); create_focus_box (canvas, 800, 150, 50, 30, "thistle"); create_focus_box (canvas, 600, 800, 50, 30, "azure"); create_focus_box (canvas, 700, 250, 50, 30, "moccasin"); create_focus_box (canvas, 500, 100, 50, 30, "cornsilk"); create_focus_box (canvas, 200, 750, 50, 30, "plum"); create_focus_box (canvas, 400, 800, 50, 30, "orchid"); }
static scrollvalue boundedScroll(canvas_goocanvas *gcanvas, scrollvalue d) { /* get size of visible area in canvas units (meters) */ canvas_dimensions dim = gcanvas->get_viewport_dimensions() / 2; // Data rect minimum and maximum // limit stops - prevent scrolling beyond these gdouble min_sy_cu = 0.95 * (gcanvas->bounds.min.y - dim.height); gdouble min_sx_cu = 0.95 * (gcanvas->bounds.min.x - dim.width); gdouble max_sy_cu = 0.95 * (gcanvas->bounds.max.y + dim.height); gdouble max_sx_cu = 0.95 * (gcanvas->bounds.max.x + dim.width); scrollvalue ret(std::min(std::max(d.x, min_sx_cu), max_sx_cu), std::min(std::max(d.y, min_sy_cu), max_sy_cu)); /* adjust to screen center */ GooCanvas *gc = GOO_CANVAS(gcanvas->widget); gdouble zoom = goo_canvas_get_scale(gc); gdouble offx = gcanvas->widget->allocation.width / (2 * zoom); gdouble offy = gcanvas->widget->allocation.height / (2 * zoom); goo_canvas_scroll_to(gc, ret.x - offx, ret.y - offy); return ret; }
double canvas_t::set_zoom(double zoom) { /* Limit a proposed zoom factor to sane ranges. * Specifically the map is allowed to be no smaller than the viewport. */ canvas_goocanvas *gcanvas = static_cast<canvas_goocanvas *>(this); /* get size of visible area in pixels and convert to meters of intended */ /* zoom by dividing by zoom (which is basically pix/m) */ const GtkAllocation &dim = widget->allocation; double limit; int delta; if (dim.height < dim.width) { limit = dim.height; delta = gcanvas->bounds.max.y - gcanvas->bounds.min.y; } else { limit = dim.width; delta = gcanvas->bounds.max.x - gcanvas->bounds.min.x; } limit *= 0.95 / zoom; if (delta < limit) { zoom /= (delta / limit); printf("Can't zoom further out (%f)\n", zoom); } goo_canvas_set_scale(GOO_CANVAS(widget), zoom); return zoom; }
static void create_focus_box (GtkWidget *canvas, gdouble x, gdouble y, gdouble width, gdouble height, gchar *color) { GooCanvasItem *root, *item; root = goo_canvas_get_root_item (GOO_CANVAS (canvas)); item = goo_canvas_rect_new (root, x, y, width, height, "stroke-pattern", NULL, "fill-color", color, "line-width", 5.0, "can-focus", TRUE, NULL); g_object_set_data (G_OBJECT (item), "id", color); g_signal_connect (item, "focus_in_event", G_CALLBACK (on_focus_in), NULL); g_signal_connect (item, "focus_out_event", G_CALLBACK (on_focus_out), NULL); g_signal_connect (item, "button_press_event", G_CALLBACK (on_button_press), NULL); g_signal_connect (item, "key_press_event", G_CALLBACK (on_key_press), NULL); }
static AtkObject* goo_canvas_accessible_ref_child (AtkObject *object, gint child_num) { GtkAccessible *accessible; GtkWidget *widget; GooCanvasItem *root; AtkObject *atk_object; /* Canvas only has one child, so return NULL if index is non zero */ if (child_num != 0) return NULL; accessible = GTK_ACCESSIBLE (object); widget = accessible->widget; /* Check if widget still exists. */ if (widget == NULL) return NULL; root = goo_canvas_get_root_item (GOO_CANVAS (widget)); if (!root) return NULL; atk_object = atk_gobject_accessible_for_object (G_OBJECT (root)); g_object_ref (atk_object); return atk_object; }
/** * get the pointer position in goocanvas coordinates * * @attention shall not be called in event callbacks, * except for GDK_MOTION_... where it is useless since * the event itself contains the cursor position */ gboolean sheet_get_pointer (Sheet *sheet, gdouble *x, gdouble *y) { if (!sheet_get_pointer_pixel (sheet, x, y)) return FALSE; goo_canvas_convert_from_pixels (GOO_CANVAS (sheet), x, y); return TRUE; }
static void node_dot_added_callback (Schematic *schematic, Coords *pos, Sheet *sheet) { NodeItem *node_item; Coords *key; g_return_if_fail (sheet != NULL); g_return_if_fail (IS_SHEET (sheet)); node_item = g_hash_table_lookup (sheet->priv->node_dots, pos); if (node_item == NULL) { node_item = NODE_ITEM (g_object_new (TYPE_NODE_ITEM, NULL)); g_object_set (node_item, "parent", goo_canvas_get_root_item (GOO_CANVAS (sheet)), "x", pos->x, "y", pos->y, NULL); } node_item_show_dot (node_item, TRUE); key = g_new0 (Coords, 1); key->x = pos->x; key->y = pos->y; g_hash_table_insert (sheet->priv->node_dots, key, node_item); }
static DrawCanvasItem * draw_canvas_get_item_at (DrawCanvas *canvas, gdouble x, gdouble y, gboolean is_pointer_event) { GooCanvasItem *item; g_return_val_if_fail(DRAW_IS_CANVAS(canvas), NULL); /* * Fetch the item underneath the pointer. If the item is not a * DrawCanvasItem or the item is part of a selection group, work our way * up until we find that top-most grabbable item. */ item = goo_canvas_get_item_at(GOO_CANVAS(canvas), x, y, is_pointer_event); for (; item; item = goo_canvas_item_get_parent(item)) { /* * TODO: Check if part of a selection/group. */ if (DRAW_IS_CANVAS_ITEM(item)) { return DRAW_CANVAS_ITEM(item); } } return NULL; }
void init_display() { int i; pcb.scale = 1.0; for (i = 0; i < pcb.layers; i++) { pcb.layer[i].canvas = GOO_CANVAS(goo_canvas_new()); gtk_object_ref(GTK_OBJECT(pcb.layer[i].canvas)); goo_canvas_set_bounds(pcb.layer[i].canvas, 0, 0, pcb.width, pcb.height); pcb.layer[i].root = goo_canvas_get_root_item(pcb.layer[i].canvas); goo_canvas_image_new(pcb.layer[i].root, pcb.layer[i].img, 0, 0, NULL); init_layer_events(pcb.layer[i].root); show_overlays(i); } pcb.window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size(GTK_WINDOW(pcb.window), 800, 600); gtk_window_set_title(GTK_WINDOW(pcb.window), pcb.filename); init_window_events(pcb.window); pcb.scrolled = gtk_scrolled_window_new(NULL, NULL); gtk_widget_show(pcb.scrolled); gtk_container_add(GTK_CONTAINER(pcb.window), pcb.scrolled); redisplay(); }
static gboolean on_button_press_event_cb (GooCanvasItem *item, GooCanvasItem *target_item, GdkEventButton *event, gpointer user_data) { GooCanvasItemModel *model = goo_canvas_item_get_model (item); if (event->state & GDK_CONTROL_MASK) { if (event->button == 1 || event->button == 3) { if (event->button == 1) drag_mode = MODE_MOVE; else drag_mode = MODE_RESIZE; drag_item = item; drag_x = event->x; drag_y = event->y; g_object_get (G_OBJECT (model), "x", &item_x, "y", &item_y, "width", &item_width, "height", &item_height, NULL); goo_canvas_pointer_grab (GOO_CANVAS (user_data), item, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_RELEASE_MASK, NULL, event->time); return TRUE; } } return FALSE; }
GtkWidget * create_paths_page (void) { GtkWidget *vbox, *hbox, *w, *scrolled_win, *canvas; vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4); gtk_widget_show (vbox); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE); gtk_widget_show (hbox); scrolled_win = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win), GTK_SHADOW_IN); gtk_widget_show (scrolled_win); gtk_box_pack_start (GTK_BOX (vbox), scrolled_win, TRUE, TRUE); canvas = goo_canvas_new (); gtk_widget_set_size_request (canvas, 600, 450); goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 1000); gtk_widget_show (canvas); gtk_container_add (GTK_CONTAINER (scrolled_win), canvas); setup_canvas (canvas); w = gtk_button_new_with_label ("Move Path"); gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE); gtk_widget_show (w); g_signal_connect (w, "clicked", G_CALLBACK (move_path_clicked), canvas); return vbox; }
static void create_canvas (GtkTable *table, gint row, gchar *text, gchar *id) { GtkWidget *label, *canvas; GooCanvasItemModel *root, *rect; char *view_id; label = gtk_label_new (text); gtk_table_attach (table, label, 0, 1, row, row + 1, 0, 0, 0, 0); gtk_widget_show (label); canvas = goo_canvas_new (); g_signal_connect (canvas, "item_created", G_CALLBACK (on_item_created), NULL); gtk_widget_set_size_request (canvas, 200, 100); goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 200, 100); gtk_table_attach (table, canvas, 1, 2, row, row + 1, 0, 0, 0, 0); gtk_widget_show (canvas); root = goo_canvas_group_model_new (NULL, NULL); goo_canvas_set_root_item_model (GOO_CANVAS (canvas), root); g_object_unref (root); rect = goo_canvas_rect_model_new (root, 0, 0, 200, 100, "stroke-pattern", NULL, "fill-color", "yellow", NULL); view_id = g_strdup_printf ("%s-yellow", id); g_object_set_data_full (G_OBJECT (rect), "id", view_id, g_free); rect = goo_canvas_rect_model_new (root, 20, 20, 60, 60, "stroke-pattern", NULL, "fill-color", "blue", NULL); view_id = g_strdup_printf ("%s-blue", id); g_object_set_data_full (G_OBJECT (rect), "id", view_id, g_free); rect = goo_canvas_rect_model_new (root, 120, 20, 60, 60, "stroke-pattern", NULL, "fill-color", "red", NULL); view_id = g_strdup_printf ("%s-red", id); g_object_set_data_full (G_OBJECT (rect), "id", view_id, g_free); }
static GtkWidget* create_window (GooCanvasItemModel *model) { GtkWidget *window, *vbox, *label, *scrolled_win, *canvas; /* Create the window and widgets. */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (window), 640, 600); gtk_widget_show (window); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4); g_object_set (vbox, "margin", 4, NULL); gtk_widget_show (vbox); gtk_container_add (GTK_CONTAINER (window), vbox); label = gtk_label_new ("Use Ctrl+Left Click to move items or Ctrl+Right Click to resize items"); g_object_set (label, "halign", GTK_ALIGN_START, NULL); gtk_box_pack_start (GTK_BOX (vbox), label); gtk_widget_show (label); /* Create top canvas. */ scrolled_win = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_win), GTK_SHADOW_IN); gtk_widget_show (scrolled_win); gtk_box_pack_start (GTK_BOX (vbox), scrolled_win); gtk_widget_set_halign (scrolled_win, GTK_ALIGN_FILL); gtk_widget_set_valign (scrolled_win, GTK_ALIGN_FILL); gtk_widget_set_hexpand (scrolled_win, TRUE); gtk_widget_set_vexpand (scrolled_win, TRUE); canvas = goo_canvas_new (); g_object_set (G_OBJECT (canvas), "integer-layout", TRUE, NULL); /* gtk_widget_set_size_request (canvas, 600, 250);*/ goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 1000, 1000); gtk_widget_show (canvas); gtk_container_add (GTK_CONTAINER (scrolled_win), canvas); g_signal_connect (canvas, "item_created", G_CALLBACK (on_item_created), NULL); goo_canvas_set_root_item_model (GOO_CANVAS (canvas), model); return window; }
/** \brief Delete the ground track for a satellite. * \param satmap The satellite map widget. * \param sat Pointer to the satellite object. * \param qth Pointer to the QTH data. * \param obj the satellite object. * \param clear_ssp Flag indicating whether SSP data should be cleared as well (TRUE=yes); * */ void ground_track_delete (GtkSatMap *satmap, sat_t *sat, qth_t *qth, sat_map_obj_t *obj, gboolean clear_ssp) { guint i,n; gint j; GooCanvasItemModel *line; GooCanvasItemModel *root; (void) qth; /* avoid unusued parameter compiler warning */ sat_log_log (SAT_LOG_LEVEL_DEBUG, _("%s: Deleting ground track for %s"), __FUNCTION__, sat->nickname); root = goo_canvas_get_root_item_model (GOO_CANVAS (satmap->canvas)); /* remove plylines */ if (obj->track_data.lines != NULL) { n = g_slist_length (obj->track_data.lines); for (i = 0; i < n; i++) { /* get line */ line = GOO_CANVAS_ITEM_MODEL (g_slist_nth_data (obj->track_data.lines, i)); /* find its ID and remove it */ j = goo_canvas_item_model_find_child (root, line); if (j == -1) { sat_log_log (SAT_LOG_LEVEL_ERROR, _("%s: Could not find part %d of ground track"), __FUNCTION__, j); } else { goo_canvas_item_model_remove_child (root, j); } } g_slist_free (obj->track_data.lines); obj->track_data.lines = NULL; } /* clear SSP too? */ if (clear_ssp == TRUE) { if (obj->track_data.latlon != NULL) { /* free allocated ssp_t */ g_slist_foreach (obj->track_data.latlon, free_ssp, NULL); /* free the SList itself */ g_slist_free (obj->track_data.latlon); obj->track_data.latlon = NULL; } obj->track_orbit = 0; } }
static void create_canvas (GtkGrid *grid, gint row, gchar *text, gchar *id) { GtkWidget *label, *canvas; GooCanvasItem *root, *rect; char *view_id; label = gtk_label_new (text); gtk_grid_attach (grid, label, 0, row, 1, 1); gtk_widget_show (label); canvas = goo_canvas_new (); gtk_widget_set_size_request (canvas, 200, 100); goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 200, 100); gtk_grid_attach (grid, canvas, 1, row, 1, 1); gtk_widget_show (canvas); root = goo_canvas_get_root_item (GOO_CANVAS (canvas)); rect = goo_canvas_rect_new (root, 0, 0, 200, 100, "stroke-pattern", NULL, "fill-color", "yellow", NULL); view_id = g_strdup_printf ("%s-yellow", id); g_object_set_data_full (G_OBJECT (rect), "id", view_id, g_free); setup_item_signals (rect); rect = goo_canvas_rect_new (root, 20, 20, 60, 60, "stroke-pattern", NULL, "fill-color", "blue", NULL); view_id = g_strdup_printf ("%s-blue", id); g_object_set_data_full (G_OBJECT (rect), "id", view_id, g_free); setup_item_signals (rect); rect = goo_canvas_rect_new (root, 120, 20, 60, 60, "stroke-pattern", NULL, "fill-color", "red", NULL); view_id = g_strdup_printf ("%s-red", id); g_object_set_data_full (G_OBJECT (rect), "id", view_id, g_free); setup_item_signals (rect); }
gboolean rubberband_update (Sheet *sheet, GdkEvent *event) { GList *iter; Coords cur, cmin, cmax; double dx, dy; // TODO maybe keep track of subpixel changes, make em global/part of the rubberband_info struct and reset on finish double width, height, width_ng, height_ng; RubberbandInfo *rubberband_info; rubberband_info = sheet->priv->rubberband_info; g_assert (event->type == GDK_MOTION_NOTIFY); cur.x = event->motion.x; cur.y = event->motion.y; goo_canvas_convert_from_pixels (GOO_CANVAS (sheet), &cur.x, &cur.y); width = fabs(rubberband_info->end.x - rubberband_info->start.x); height = fabs(rubberband_info->end.y - rubberband_info->start.y); width_ng = fabs(cur.x - rubberband_info->start.x); height_ng = fabs(cur.y - rubberband_info->start.y); dx = fabs (width_ng - width); dy = fabs (height_ng - height); NG_DEBUG ("motion :: dx=%lf, dy=%lf :: x=%lf, y=%lf :: w_ng=%lf, h_ng=%lf", dx, dy, cur.x, cur.y, width_ng, height_ng); // TODO FIXME scroll window if needed (use http://developer.gnome.org/goocanvas/stable/GooCanvas.html#goo-canvas-scroll-to) if (dx > 0.1 || dy > 0.1) { //a 0.1 change in pixel coords would be the least visible, silently ignore everything else rubberband_info->end.x = cur.x; rubberband_info->end.y = cur.y; cmin.x = MIN(rubberband_info->start.x, rubberband_info->end.x); cmin.y = MIN(rubberband_info->start.y, rubberband_info->end.y); cmax.x = cmin.x + width_ng; cmax.y = cmin.y + height_ng; #if 1 for (iter = sheet->priv->items; iter; iter = iter->next) { sheet_item_select_in_area (iter->data, &cmin, &cmax); } #endif g_object_set (GOO_CANVAS_ITEM (rubberband_info->rectangle), "x", cmin.x, "y", cmin.y, "width", width_ng, "height", height_ng, "visibility", GOO_CANVAS_ITEM_VISIBLE, NULL); goo_canvas_item_raise (GOO_CANVAS_ITEM (rubberband_info->rectangle), NULL); } return TRUE; }
void sheet_keyboard_ungrab (Sheet *sheet, GdkEvent *event) { g_return_if_fail (sheet); g_return_if_fail (IS_SHEET (sheet)); #ifndef DEBUG_DISABLE_GRABBING if (sheet->priv->keyboard_grabbed) { sheet->priv->keyboard_grabbed = FALSE; goo_canvas_keyboard_ungrab (GOO_CANVAS (sheet), GOO_CANVAS_ITEM (sheet->grid), extract_time (event)); } #endif }
void sheet_setup_rubberband (Sheet *sheet, GdkEventButton *event) { double x, y; cairo_pattern_t *pattern; static guchar stipple_data[16] = {0, 0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255 }; x = event->x; //the x coordinate of the pointer relative to the window. y = event->y; //the y coordinate of the pointer relative to the window. goo_canvas_convert_from_pixels (GOO_CANVAS (sheet), &x, &y); sheet->priv->rubberband->start_x = x; sheet->priv->rubberband->start_y = y; sheet->priv->rubberband->state = RUBBER_YES; sheet->priv->rubberband->click_start_state = event->state; pattern = create_stipple ("lightgrey", stipple_data); sheet->priv->rubberband->rectangle = goo_canvas_rect_new ( GOO_CANVAS_ITEM (sheet->object_group), x, y, 0.0, 0.0, "stroke-color", "black", "line-width", 0.2, "fill-pattern", pattern, NULL); goo_canvas_pointer_grab (GOO_CANVAS (sheet), GOO_CANVAS_ITEM (sheet->grid), (GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK), NULL, event->time); // Mark all the selected objects to preserve their selected state // if SHIFT is pressed while rubberbanding. if (event->state & GDK_SHIFT_MASK) { sheet->priv->preserve_selection_items = g_list_copy (sheet_preserve_selection (sheet)); } }
void sheet_get_pointer (Sheet *sheet, gdouble *x, gdouble *y) { GtkWidget *widget; GtkAdjustment *hadjustment; GtkAdjustment *vadjustment; gdouble value, x1, y1; gint _x, _y; GdkDeviceManager *device_manager; GdkDevice *device_pointer; GdkRectangle allocation; // gtk_widget_get_pointer (GTK_WIDGET (sheet), &_x, &_y); // replaced by a code copied from evince if (!gtk_widget_get_realized (GTK_WIDGET (sheet))) return; device_manager = gdk_display_get_device_manager ( gtk_widget_get_display (GTK_WIDGET (sheet))); device_pointer = gdk_device_manager_get_client_pointer (device_manager); gdk_window_get_device_position (gtk_widget_get_window (GTK_WIDGET (sheet)), device_pointer, &_x, &_y, NULL); if (!gtk_widget_get_has_window (GTK_WIDGET (sheet))) return; gtk_widget_get_allocation (GTK_WIDGET (sheet), &allocation); _x -= allocation.x; _y -= allocation.y; x1 = (gdouble) _x; y1 = (gdouble) _y; widget = gtk_widget_get_parent (GTK_WIDGET (sheet)); hadjustment = gtk_scrolled_window_get_hadjustment ( GTK_SCROLLED_WINDOW (widget)); value = gtk_adjustment_get_value (hadjustment); x1 += value; vadjustment = gtk_scrolled_window_get_vadjustment ( GTK_SCROLLED_WINDOW (widget)); value = gtk_adjustment_get_value (vadjustment); y1 += value; *x = x1; *y = y1; goo_canvas_convert_from_pixels (GOO_CANVAS (sheet), x, y); snap_to_grid (sheet->grid, x, y); }
/* get scroll position in meters */ void canvas_t::scroll_get(int &sx, int &sy) const { GooCanvas *gc = GOO_CANVAS(widget); gdouble zoom = goo_canvas_get_scale(gc); gdouble hs = gtk_adjustment_get_value(gc->hadjustment); gdouble vs = gtk_adjustment_get_value(gc->vadjustment); goo_canvas_convert_from_pixels(gc, &hs, &vs); /* convert to position relative to screen center */ hs += widget->allocation.width/(2*zoom); vs += widget->allocation.height/(2*zoom); sx = hs; sy = vs; }
static gboolean on_button_release_event_cb (GooCanvasItem *item, GooCanvasItem *target_item, GdkEventButton *event, gpointer user_data) { if (drag_item == item && drag_item != NULL) { goo_canvas_pointer_ungrab (GOO_CANVAS (user_data), drag_item, event->time); drag_item = NULL; return TRUE; } return FALSE; }
static GooCanvasItemModel * create_time_tick (GtkPolarView *pv, gdouble time, gfloat x, gfloat y) { GooCanvasItemModel *item; time_t t; gchar buff[7]; GtkAnchorType anchor; GooCanvasItemModel *root; guint32 col; root = goo_canvas_get_root_item_model (GOO_CANVAS (pv->canvas)); col = mod_cfg_get_int (pv->cfgdata, MOD_CFG_POLAR_SECTION, MOD_CFG_POLAR_TRACK_COL, SAT_CFG_INT_POLAR_TRACK_COL); /* convert julian date to struct tm */ t = (time - 2440587.5)*86400.; /* format either local time or UTC depending on check box */ if (sat_cfg_get_bool (SAT_CFG_BOOL_USE_LOCAL_TIME)) strftime (buff, 8, "%H:%M", localtime (&t)); else strftime (buff, 8, "%H:%M", gmtime (&t)); buff[6]='\0'; if (x > pv->cx) { anchor = GTK_ANCHOR_EAST; x -= 5; } else { anchor = GTK_ANCHOR_WEST; x += 5; } item = goo_canvas_text_model_new (root, buff, (gdouble) x, (gdouble) y, -1, anchor, "font", "Sans 7", "fill-color-rgba", col, NULL); goo_canvas_item_model_lower (item, NULL); return item; }
gboolean sheet_keyboard_grab (Sheet *sheet, GdkEvent *event) { g_return_val_if_fail (sheet, FALSE); g_return_val_if_fail (IS_SHEET (sheet), FALSE); #ifndef DEBUG_DISABLE_GRABBING if (sheet->priv->keyboard_grabbed == FALSE && goo_canvas_keyboard_grab (GOO_CANVAS (sheet), GOO_CANVAS_ITEM (sheet->grid), TRUE, /*do not reroute signals through sheet->grid*/ extract_time (event)) == GDK_GRAB_SUCCESS) { sheet->priv->keyboard_grabbed = TRUE; } return (sheet->priv->keyboard_grabbed == TRUE); #else return TRUE; #endif }
gboolean sheet_pointer_grab (Sheet *sheet, GdkEvent *event) { g_return_val_if_fail (sheet, FALSE); g_return_val_if_fail (IS_SHEET (sheet), FALSE); #ifndef DEBUG_DISABLE_GRABBING if (sheet->priv->pointer_grabbed == 0 && goo_canvas_pointer_grab (GOO_CANVAS (sheet), GOO_CANVAS_ITEM (sheet->grid), GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK, NULL, extract_time (event)) == GDK_GRAB_SUCCESS) { sheet->priv->pointer_grabbed = 1; } return (sheet->priv->pointer_grabbed == 1); #else return TRUE; #endif }
GtkWidget * create_events_page (void) { GtkWidget *vbox, *frame, *label, *canvas; vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 4); g_object_set (vbox, "margin", 4, NULL); gtk_widget_show (vbox); /* Instructions */ label = gtk_label_new ("Move the mouse over the items to check they receive the right motion events.\nThe first 2 items in each group are 1) invisible and 2) visible but unpainted."); gtk_box_pack_start (GTK_BOX (vbox), label); gtk_widget_show (label); /* Frame and canvas */ frame = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN); gtk_box_pack_start (GTK_BOX (vbox), frame); gtk_widget_show (frame); g_object_set (frame, "halign", GTK_ALIGN_CENTER, "valign", GTK_ALIGN_CENTER, NULL); canvas = goo_canvas_new (); gtk_widget_set_size_request (canvas, 600, 450); goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 600, 450); gtk_container_add (GTK_CONTAINER (frame), canvas); gtk_widget_show (canvas); create_events_area (canvas, 0, GOO_CANVAS_EVENTS_NONE, "none"); create_events_area (canvas, 1, GOO_CANVAS_EVENTS_VISIBLE_PAINTED, "visible-painted"); create_events_area (canvas, 2, GOO_CANVAS_EVENTS_VISIBLE_FILL, "visible-fill"); create_events_area (canvas, 3, GOO_CANVAS_EVENTS_VISIBLE_STROKE, "visible-stroke"); create_events_area (canvas, 4, GOO_CANVAS_EVENTS_VISIBLE, "visible"); create_events_area (canvas, 5, GOO_CANVAS_EVENTS_PAINTED, "painted"); create_events_area (canvas, 6, GOO_CANVAS_EVENTS_FILL, "fill"); create_events_area (canvas, 7, GOO_CANVAS_EVENTS_STROKE, "stroke"); create_events_area (canvas, 8, GOO_CANVAS_EVENTS_ALL, "all"); return vbox; }