void ApplicationModel::snapToGrid(void) { GooCanvasItemModel* model = (GooCanvasItemModel*) this->gobj(); GooCanvas* canvas = (GooCanvas*) parentWindow->m_Canvas->gobj(); if(model && canvas) { GooCanvasItem* item = goo_canvas_get_item(canvas, model); GooCanvasBounds bi; goo_canvas_item_get_bounds(item, &bi); double xs, ys; g_object_get (parentWindow->m_Grid, "x_step", &xs, "y_step", &ys, NULL); double c_x = (int) (((int)bi.x1) % (int)xs); double c_y = (int) (((int)bi.y1) % (int)ys); //printf("cx:%f, cy:%f\n", c_x, c_y); //printf("x:%f, y:%f\n", bi.x1, bi.y1); if(parentWindow->m_snapToGrid) goo_canvas_item_translate(item, -c_x, -c_y); // force update goo_canvas_item_get_bounds(item, &bi); this->points.clear(); GyPoint pt; pt.x = bi.x1; pt.y = bi.y1; this->points.push_back(pt); updateCoordination(); } }
Gdk::Point MidpointModel::getContactPoint(void) { GooCanvasItemModel* model = (GooCanvasItemModel*) this->gobj(); GooCanvas* canvas = (GooCanvas*) parentWindow->m_Canvas->gobj(); if(model && canvas) { GooCanvasItem* item = goo_canvas_get_item(canvas, model); GooCanvasBounds bi; goo_canvas_item_get_bounds(item, &bi); goo_canvas_item_get_bounds(item, &bi); return Gdk::Point((int)(bi.x2-POINT_SIZE/2.0), (int)(bi.y2-POINT_SIZE/2.0)); } return Gdk::Point(-1, -1); }
// Retrieves the bounding box. We use a caching scheme for this // since it's too expensive to calculate it every time we need it. inline static void get_cached_bounds (PartItem *item, Coords *p1, Coords *p2) { PartItemPriv *priv; priv = item->priv; if (!priv->cache_valid) { Coords start_pos, end_pos; GooCanvasBounds bounds; goo_canvas_item_get_bounds (GOO_CANVAS_ITEM (item), &bounds); start_pos.x = bounds.x1; start_pos.y = bounds.y1; end_pos.x = bounds.x2; end_pos.y = bounds.y2; priv->bbox_start = start_pos; priv->bbox_end = end_pos; priv->cache_valid = TRUE; } memcpy (p1, &priv->bbox_start, sizeof (Coords)); memcpy (p2, &priv->bbox_end, sizeof (Coords)); }
// Retrieves the bounding box. We use a caching scheme for this // since it's too expensive to calculate it every time we need it. inline static void get_boundingbox (WireItem *item, Coords *p1, Coords *p2) { g_return_if_fail (item != NULL); g_return_if_fail (IS_WIRE_ITEM (item)); WireItemPriv *priv; priv = item->priv; if (!priv->cache_valid) { Coords start_pos, end_pos; GooCanvasBounds bounds; //, canvas_bounds; goo_canvas_item_get_bounds (GOO_CANVAS_ITEM (item), &bounds); priv->bbox_start.x = bounds.x1; priv->bbox_start.y = bounds.y1; priv->bbox_end.x = bounds.x2; priv->bbox_end.y = bounds.y2; priv->cache_valid = TRUE; } if (p1) *p1 = priv->bbox_start; if (p2) *p2 = priv->bbox_end; }
static void draw_selection_update_bounds (DrawSelection *selection) { GooCanvasBounds bounds = { -1, -1, -1, -1 }; GooCanvasBounds b; GList *iter; g_assert(DRAW_IS_SELECTION(selection)); for (iter = selection->priv->selected; iter; iter = iter->next) { goo_canvas_item_get_bounds(iter->data, &b); if ((b.x1 < bounds.x1) || bounds.x1 == -1) bounds.x1 = b.x1; if ((b.x2 > bounds.x2) || bounds.x2 == -1) bounds.x2 = b.x2; if ((b.y1 < bounds.y1) || bounds.y1 == -1) bounds.y1 = b.y1; if ((b.y2 > bounds.y2) || bounds.y2 == -1) bounds.y2 = b.y2; } g_object_set(selection, "x", bounds.x1, "y", bounds.y1, "width", (bounds.x2 - bounds.x1), "height", (bounds.y2 - bounds.y1), NULL); }
static VALUE rg_y2(VALUE self) { GooCanvasBounds bounds; goo_canvas_item_get_bounds(SELF(self), &bounds); return rb_float_new(bounds.y2); }
/* Move the plane */ static void planegame_move_plane(GooCanvasItem *item) { GooCanvasBounds bounds; goo_canvas_item_get_bounds(item, &bounds); if(plane_x > BOARDWIDTH - (bounds.x2 - bounds.x1) && planespeed_x > 0) planespeed_x=0; if(plane_x < 0 && planespeed_x < 0) planespeed_x = 0; if(plane_y > BOARDHEIGHT - (bounds.y2 - bounds.y1) && planespeed_y > 0) planespeed_y = 0; if(plane_y < 0 && planespeed_y < 0) planespeed_y=0; goo_canvas_item_translate(item, planespeed_x, planespeed_y); plane_x += planespeed_x; plane_y += planespeed_y; }
/*-------------------------------------------------------------------------------*/ static void display_previous_next(guint x_start, guint y_start, gchar *eventname_previous, gchar *eventname_next) { GooCanvasItem *item; GooCanvasBounds bounds; item = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", "#PREVIOUS", NULL); goo_canvas_item_get_bounds(item, &bounds); SET_ITEM_LOCATION(item, x_start - (bounds.x2 - bounds.x1) - 10, y_start - pixmap_width/2); g_signal_connect(item, "button_press_event", (GCallback) item_event_ok, eventname_previous); gc_item_focus_init(item, NULL); item = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", "#NEXT", NULL); SET_ITEM_LOCATION(item, x_start, y_start - pixmap_width/2); g_signal_connect(item, "button_press_event", (GCallback) item_event_ok, eventname_next); gc_item_focus_init(item, NULL); }
static void planegame_cloud_colision(GooCanvasItem *item) { GooCanvasBounds ib, pb; goo_canvas_item_get_bounds(planeitem, &pb); goo_canvas_item_get_bounds(item, &ib); if(ib.x2<0) { goo_canvas_item_remove(item); return; } if( ISIN(ib.x1, ib.y1, pb.x1, pb.y1, pb.x2, pb.y2) || ISIN(ib.x2, ib.y1, pb.x1, pb.y1, pb.x2, pb.y2) || ISIN(ib.x1, ib.y2, pb.x1, pb.y1, pb.x2, pb.y2) || ISIN(ib.x2, ib.y2, pb.x1, pb.y1, pb.x2, pb.y2) ) { gint number = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "cloud_number")); if(plane_target == number) { planegame_speak_number(number); plane_target++; goo_canvas_item_remove(item); if(gcomprisBoard->level==1) gc_score_set(plane_target); if(plane_target == plane_last_target) { /* Try the next level */ gcomprisBoard->level++; if(gcomprisBoard->level>gcomprisBoard->maxlevel) gcomprisBoard->level = gcomprisBoard->maxlevel; planegame_next_level(); gc_sound_play_ogg ("sounds/bonus.wav", NULL); } } } }
/* ==================================== */ static gboolean animate_step() { if(!gcomprisBoard) return FALSE; GooCanvasBounds bounds; goo_canvas_item_get_bounds(timer_item, &bounds); if(GOO_IS_CANVAS_SVG(timer_item)) goo_canvas_item_translate(timer_item, timer_step_x1, timer_step_y1); else if(GOO_IS_CANVAS_RECT(timer_item)) g_object_set(timer_item, "x", bounds.x1 + timer_step_x1, "y", bounds.y1 + timer_step_y1, "height", bounds.y2 - bounds.y1 - timer_step_y1, NULL); /* Special case for raising/lowering the boat */ if(boat_position==BOAT_POS_MIDDLE && timer_item==canal_middle_item) { goo_canvas_item_translate(tuxboat_item, 0, timer_step_y1); gc_item_focus_remove(tuxboat_item, NULL); } if((bounds.y1 >= timer_item_limit_y && timer_step_y1 > 0) || (bounds.y1 <= timer_item_limit_y && timer_step_y1 < 0)) { gtk_timeout_remove (timer_id); timer_id = 0; animation = FALSE; update_water(); gc_item_focus_init(tuxboat_item, NULL); g_object_set (tuxboat_item, "svg-id", "#BOAT_NO_SAIL", NULL); } else if((bounds.x1 >= timer_item_limit_x && timer_step_x1 > 0) || (bounds.x1 <= timer_item_limit_x && timer_step_x1 < 0)) { gtk_timeout_remove (timer_id); timer_id = 0; animation = FALSE; update_water(); if (gamewon) { gc_bonus_display(TRUE, GC_BONUS_FLOWER); gamewon = FALSE; } gc_item_focus_init(tuxboat_item, NULL); g_object_set (tuxboat_item, "svg-id", "#BOAT_NO_SAIL", NULL); } return TRUE; }
/* * Request score * */ static void request_score() { double x_offset = 390; double y_offset = 150; gchar *tmpstr; /* Set the maximum text to calc the background */ tmpstr = g_strdup_printf(_("Points = %s"), "00000"); answer_item = goo_canvas_text_new (boardRootItem, tmpstr, (double) x_offset, (double) y_offset, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", "white", NULL); g_free(tmpstr); GooCanvasBounds bounds; goo_canvas_item_get_bounds (answer_item, &bounds); goo_canvas_convert_to_item_space(goo_canvas_item_get_canvas(answer_item), answer_item, &bounds.x1, &bounds.y1); goo_canvas_convert_to_item_space(goo_canvas_item_get_canvas(answer_item), answer_item, &bounds.x2, &bounds.y2); int gap = 15; GooCanvasItem *item = \ goo_canvas_rect_new (boardRootItem, bounds.x1 - gap, bounds.y1 - gap, (bounds.x2 - bounds.x1) + gap*2, (bounds.y2 - bounds.y1) + gap*2, "stroke_color_rgba", 0xFFFFFFFFL, "fill_color_rgba", 0X5599FFCCL, "line-width", (double) 2, "radius-x", (double) 10, "radius-y", (double) 10, NULL); goo_canvas_item_raise(answer_item, item); /* Set the correct initial text */ tmpstr = g_strdup_printf(_("Points = %s"), answer_string); g_object_set(answer_item, "text", tmpstr, NULL); g_free(tmpstr); }
void ExternalPortModel::snapToGrid(void) { GooCanvasItemModel* model = (GooCanvasItemModel*) this->gobj(); GooCanvas* canvas = (GooCanvas*) parentWindow->m_Canvas->gobj(); if(model && canvas) { GooCanvasItem* item = goo_canvas_get_item(canvas, model); GooCanvasBounds bi; goo_canvas_item_get_bounds(item, &bi); double xs, ys; g_object_get (parentWindow->m_Grid, "x_step", &xs, "y_step", &ys, NULL); double c_x = (int) (((int)bi.x1) % (int)xs); double c_y = (int) (((int)bi.y1) % (int)ys); if(parentWindow->m_snapToGrid) goo_canvas_item_translate(item, -c_x, -c_y); // force update goo_canvas_item_get_bounds(item, &bi); updateArrowCoordination(); } }
static void gletters_move_item(GooCanvasItem *item) { GooCanvasBounds bounds; goo_canvas_item_translate(item, 0, 2.0); goo_canvas_item_get_bounds (item, &bounds); if(bounds.y1>BOARDHEIGHT) { item2del_list = g_list_append (item2del_list, item); player_loose(); } }
static void update_tux(gint direction) { gint rotation = 0; GooCanvasBounds bounds; gdouble scale; /* Our svg image of tux is faced south */ switch(direction) { case EAST: rotation = -90; break; case WEST: rotation = 90; break; case NORTH: rotation = 180; break; case SOUTH: rotation = 0; break; } goo_canvas_item_set_transform(tuxitem, NULL); goo_canvas_item_get_bounds(tuxitem, &bounds); scale = (gdouble) cellsize / (bounds.x2 - bounds.x1); goo_canvas_item_scale(tuxitem, scale, scale); goo_canvas_item_rotate( tuxitem, rotation, (bounds.x2-bounds.x1)/2, (bounds.y2-bounds.y1)/2); // update the running shoes if(run_fast_possible && run_fast) { goo_canvas_item_set_transform(tuxshoes, NULL); scale = (gdouble) cellsize / (bounds.x2 - bounds.x1); goo_canvas_item_scale(tuxshoes, scale, scale); goo_canvas_item_rotate( tuxshoes, rotation, (bounds.x2-bounds.x1)/2, (bounds.y2-bounds.y1)/2); } }
Gdk::Point ExternalPortModel::getContactPoint(ArrowModel* arrow) { GooCanvasItemModel* model = (GooCanvasItemModel*) poly->gobj(); GooCanvas* canvas = (GooCanvas*) parentWindow->m_Canvas->gobj(); if(model && canvas) { GooCanvasItem* item = goo_canvas_get_item(canvas, model); if(item) { GooCanvasBounds bi; goo_canvas_item_get_bounds(item, &bi); if(type == INPUTD) return Gdk::Point((int)(bi.x1+PORT_DEPTH), (int)(bi.y2-((bi.y2-bi.y1)/2.0))); return Gdk::Point((int)(bi.x2), (int)(bi.y2-((bi.y2-bi.y1)/2.0))); } } return Gdk::Point(-1, -1); }
/** Setting the bar location * @param[in] x the bar x coordinate, -1 to set the default * @param[in] y the bar y coordinate, -1 to set the default * @param[in] zoom the bar zoom factor, -1 to set the default */ static void bar_location (int x, int y, double zoom) { // Make the y coord be assigned at its bottom int ny = (y == -1 ? _default_y : y); ny += BARHEIGHT - (zoom == -1 ? _default_zoom : zoom) * BARHEIGHT; goo_canvas_item_set_transform(rootitem, NULL); GooCanvasBounds bounds; goo_canvas_item_get_bounds(rootitem, &bounds); int nx = (x == -1 ? (BOARDWIDTH - (bounds.x2 - bounds.x1))/2 : x); goo_canvas_item_translate(rootitem, nx, ny); goo_canvas_item_scale(rootitem, (zoom == -1 ? _default_zoom : zoom), (zoom == -1 ? _default_zoom : zoom)); //#endif }
/* ===================================================================== * * =====================================================================*/ static gboolean regleur_chasse_event(GooCanvasItem *item, GooCanvas *target, GdkEventButton *event, gpointer data) { GooCanvasBounds bounds; if(board_paused || !boardRootItem) return FALSE; goo_canvas_item_get_bounds(item, &bounds); gc_sound_play_ogg ("sounds/bleep.wav", NULL); regleur_chasse_open = !regleur_chasse_open; goo_canvas_item_rotate(item, 90.0, bounds.x1 + (bounds.x2 - bounds.x1) / 2, bounds.y1 + (bounds.y2 - bounds.y1) / 2); return FALSE; }
/* Called with items_lock locked */ static void wordsgame_move_item(LettersItem *item) { GooCanvasBounds bounds; goo_canvas_item_translate(item->rootitem, 0, 2.0); goo_canvas_item_get_bounds (item->rootitem, &bounds); if(bounds.y1>BOARDHEIGHT) { if (item == item_on_focus) item_on_focus = NULL; g_ptr_array_remove (items, item); g_ptr_array_add (items2del, item); g_timeout_add (100,(GSourceFunc) wordsgame_delete_items, NULL); player_loose(); } }
static gboolean i7_goo_canvas_item_get_onscreen_coordinates(GooCanvasItem *item, GooCanvas *canvas, gint *x, gint *y) { GooCanvasBounds bounds; GtkAllocation allocation; gdouble canvas_x, canvas_y; gdouble top, bottom, left, right, item_x, item_y; /* Find out the size and coordinates of the current viewport */ goo_canvas_get_bounds(canvas, &canvas_x, &canvas_y, NULL, NULL); GtkWidget *scrolled_window = gtk_widget_get_parent(GTK_WIDGET(canvas)); g_assert(GTK_IS_SCROLLED_WINDOW(scrolled_window)); GtkAdjustment *adj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(scrolled_window)); left = canvas_x + gtk_adjustment_get_value(adj); right = left + gtk_adjustment_get_page_size(adj); adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(scrolled_window)); top = canvas_y + gtk_adjustment_get_value(adj); bottom = top + gtk_adjustment_get_page_size(adj); /* Make sure item is currently displayed */ goo_canvas_item_get_bounds(item, &bounds); if(bounds.x1 > right || bounds.x2 < left || bounds.y1 > bottom || bounds.y2 < top) { g_warning("Node not onscreen in canvas"); return FALSE; } /* Find out the onscreen coordinates of the canvas viewport */ gtk_widget_get_allocation(GTK_WIDGET(canvas), &allocation); if(x) { item_x = bounds.x1; *x = (gint)(item_x - left) + allocation.x; } if(y) { item_y = bounds.y1; *y = (gint)(item_y - top) + allocation.y; } return TRUE; }
/* Returns the extents of the item, in pixels relative to the main canvas window. */ static void goo_canvas_item_accessible_get_item_extents (GooCanvasItem *item, GdkRectangle *rect) { GooCanvas *canvas; GooCanvasBounds bounds; canvas = goo_canvas_item_get_canvas (item); if (!canvas) { rect->x = rect->y = rect->width = rect->height = 0; return; } /* Get the bounds in device units. */ goo_canvas_item_get_bounds (item, &bounds); /* Static items are in pixels so don't need converting. */ if (!goo_canvas_item_get_is_static (item)) { /* Convert to pixels within the entire canvas. */ goo_canvas_convert_to_pixels (canvas, &bounds.x1, &bounds.y1); goo_canvas_convert_to_pixels (canvas, &bounds.x2, &bounds.y2); /* Convert to pixels within the visible window. */ bounds.x1 -= canvas->hadjustment->value; bounds.y1 -= canvas->vadjustment->value; bounds.x2 -= canvas->hadjustment->value; bounds.y2 -= canvas->vadjustment->value; } /* Round up or down to integers. */ rect->x = floor (bounds.x1); rect->y = floor (bounds.y1); rect->width = ceil (bounds.x1) - rect->x; rect->height = ceil (bounds.y1) - rect->y; }
// Retrieves the bounding box. We use a caching scheme for this // since it's too expensive to calculate it every time we need it. inline static void get_boundingbox (WireItem *item, SheetPos *p1, SheetPos *p2) { WireItemPriv *priv; priv = item->priv; if (!priv->cache_valid) { SheetPos start_pos, end_pos; GooCanvasBounds bounds; //, canvas_bounds; goo_canvas_item_get_bounds (GOO_CANVAS_ITEM (item), &bounds); start_pos.x = bounds.x1; start_pos.y = bounds.y1; end_pos.x = bounds.x2; end_pos.y = bounds.y2; priv->bbox_start = start_pos; priv->bbox_end = end_pos; priv->cache_valid = TRUE; } memcpy (p1, &priv->bbox_start, sizeof (SheetPos)); memcpy (p2, &priv->bbox_end, sizeof (SheetPos)); }
/* * Do all the bar display and register the events */ static void bar_start (GooCanvas *theCanvas) { GcomprisProperties *properties = gc_prop_get(); RsvgHandle *svg_handle; GooCanvasBounds bounds; _default_y = BOARDHEIGHT - BARHEIGHT; _default_zoom = 1.0; bar_reset_sound_id(); rootitem = goo_canvas_group_new (goo_canvas_get_root_item(theCanvas), NULL); svg_handle = gc_skin_rsvg_get(); bar_item = goo_canvas_svg_new (rootitem, svg_handle, "svg-id", "#BAR_BG", "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); SET_ITEM_LOCATION(bar_item, 0, 0); /* * The Order in which buttons are created represents * also the order in which they will be displayed */ // EXIT if(properties->disable_quit == 0) buttons = g_slist_append(buttons, new_button(rootitem, svg_handle, GC_BAR_EXIT, "#EXIT")); // ABOUT buttons = g_slist_append(buttons, new_button(rootitem, svg_handle, GC_BAR_ABOUT, "#ABOUT")); // CONFIG if(properties->disable_config == 0) buttons = g_slist_append(buttons, new_button(rootitem, svg_handle, GC_BAR_CONFIG, "#CONFIG")); // HELP buttons = g_slist_append(buttons, new_button(rootitem, svg_handle, GC_BAR_HELP, "#HELP")); // LEVEL (Multiple buttons for this one) GooCanvasItem *rootitem_level = goo_canvas_group_new (rootitem, NULL); g_object_set (rootitem_level, "visibility", GOO_CANVAS_ITEM_VISIBLE, NULL); g_object_set_data (G_OBJECT(rootitem_level), "flag", GUINT_TO_POINTER(GC_BAR_LEVEL)); buttons = g_slist_append(buttons, rootitem_level); GooCanvasItem *item = new_button(rootitem_level, svg_handle, GC_BAR_LEVEL_DOWN, "#LEVEL_DOWN"); g_object_set (item, "visibility", (properties->disable_level ? GOO_CANVAS_ITEM_INVISIBLE : GOO_CANVAS_ITEM_VISIBLE), NULL); item = new_button(rootitem_level, svg_handle, GC_BAR_LEVEL, "#LEVEL_UP"); goo_canvas_item_translate(item, 50, 0); g_object_set (item, "visibility", (properties->disable_level ? GOO_CANVAS_ITEM_INVISIBLE : GOO_CANVAS_ITEM_VISIBLE), NULL); goo_canvas_item_get_bounds(item, &bounds); level_item = goo_canvas_text_new (rootitem_level, "", bounds.x1 - 10, (bounds.y2 - bounds.y1) / 2 + 8, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color-rgba", gc_skin_color_text_button, NULL); current_level = 1; // REPEAT (Default) buttons = g_slist_append(buttons, new_button(rootitem, svg_handle, GC_BAR_REPEAT, "#REPEAT")); // REPEAT ICON buttons = g_slist_append(buttons, new_button(rootitem, svg_handle, GC_BAR_REPEAT_ICON, "#REPEAT")); // HOME buttons = g_slist_append(buttons, new_button(rootitem, svg_handle, GC_BAR_HOME, "#HOME")); update_exit_button(); bar_set(0); _hidden = FALSE; }
/* ==================================== */ static GooCanvasItem *canal_lock_create_item(GooCanvasItem *boardRootItem) { RsvgHandle *svg_handle; svg_handle = gc_rsvg_load("canal_lock/canal_lock.svgz"); /* The background */ goo_canvas_svg_new (boardRootItem, svg_handle, "svg-id", "#BACKGROUND", "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); /* The boat */ tuxboat_item = goo_canvas_svg_new (boardRootItem, svg_handle, "svg-id", "#BOAT_NO_SAIL", NULL); g_signal_connect(tuxboat_item, "button-press-event", (GtkSignalFunc) item_event, NULL); gc_item_focus_init(tuxboat_item, NULL); GooCanvasBounds bounds; goo_canvas_item_get_bounds(tuxboat_item, &bounds); tuxboat_width = bounds.x2 - bounds.x1 + 20; /* The left lights */ goo_canvas_svg_new (boardRootItem, svg_handle, "svg-id", "#LEFT_RED_OFF", "visibility", GOO_CANVAS_ITEM_VISIBLE, "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); goo_canvas_svg_new (boardRootItem, svg_handle, "svg-id", "#LEFT_GREEN_OFF", "visibility", GOO_CANVAS_ITEM_VISIBLE, "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); left_red_on_item = goo_canvas_svg_new (boardRootItem, svg_handle, "svg-id", "#LEFT_RED_ON", "visibility", GOO_CANVAS_ITEM_INVISIBLE, "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); left_green_on_item = goo_canvas_svg_new (boardRootItem, svg_handle, "svg-id", "#LEFT_GREEN_ON", "visibility", GOO_CANVAS_ITEM_INVISIBLE, "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); goo_canvas_svg_new (boardRootItem, svg_handle, "svg-id", "#LEFT_LIGHT_BASE", "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); /* The right lights */ goo_canvas_svg_new (boardRootItem, svg_handle, "svg-id", "#RIGHT_RED_OFF", "visibility", GOO_CANVAS_ITEM_VISIBLE, "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); goo_canvas_svg_new (boardRootItem, svg_handle, "svg-id", "#RIGHT_GREEN_OFF", "visibility", GOO_CANVAS_ITEM_VISIBLE, "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); right_red_on_item = goo_canvas_svg_new (boardRootItem, svg_handle, "svg-id", "#RIGHT_RED_ON", "visibility", GOO_CANVAS_ITEM_INVISIBLE, "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); right_green_on_item = goo_canvas_svg_new (boardRootItem, svg_handle, "svg-id", "#RIGHT_GREEN_ON", "visibility", GOO_CANVAS_ITEM_INVISIBLE, "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); goo_canvas_svg_new (boardRootItem, svg_handle, "svg-id", "#RIGHT_LIGHT_BASE", "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); /* This is the middle canal */ canal_middle_item = goo_canvas_rect_new (boardRootItem, LEFT_CANAL_WIDTH, BASE_LINE - LEFT_CANAL_HEIGHT, MIDDLE_CANAL_WIDTH, LEFT_CANAL_HEIGHT, "fill_color_rgba", CANAL_COLOR, "line-width", (double) 0, NULL); goo_canvas_item_raise(tuxboat_item, canal_middle_item); /* This is the left lock */ lock_left_item = goo_canvas_rect_new (boardRootItem, LEFT_CANAL_WIDTH - LOCK_WIDTH / 2, BASE_LINE - LOCK_HEIGHT_MAX, LOCK_WIDTH, LOCK_HEIGHT_MAX, "fill_color_rgba", LOCK_COLOR, "line-width", (double) 0, NULL); set_lock_event(lock_left_item); /* This is the right lock */ lock_right_item = goo_canvas_rect_new (boardRootItem, LEFT_CANAL_WIDTH + MIDDLE_CANAL_WIDTH - LOCK_WIDTH / 2, BASE_LINE - LOCK_HEIGHT_MAX, LOCK_WIDTH, LOCK_HEIGHT_MAX, "fill_color_rgba", LOCK_COLOR, "line-width", (double) 0, NULL); set_lock_event(lock_right_item); /* And to finish, the 2 canal locks */ canallock_left_item = goo_canvas_rect_new (boardRootItem, LEFT_CANAL_WIDTH + MIDDLE_CANAL_WIDTH * 0.1, SUBCANAL_BASE_LINE - SUBCANAL_HEIGHT, LOCK_WIDTH / 2, SUBCANAL_HEIGHT, "fill_color_rgba", CANALLOCK_COLOR, "line-width", (double) 0, NULL); set_lock_event(canallock_left_item); canallock_right_item = goo_canvas_rect_new (boardRootItem, LEFT_CANAL_WIDTH + MIDDLE_CANAL_WIDTH * 0.9, SUBCANAL_BASE_LINE - SUBCANAL_HEIGHT, LOCK_WIDTH / 2, SUBCANAL_HEIGHT, "fill_color_rgba", CANALLOCK_COLOR, "line-width", (double) 0, NULL); set_lock_event(canallock_right_item); g_object_unref (svg_handle); return NULL; }
void gc_help_start (GcomprisBoard *gcomprisBoard) { gchar *item_id = "#UP"; GooCanvasItem *item; gint y = 0; gint y_start = 0; gint x_start = 0; gchar *name = NULL; gchar *text_to_display = NULL; if(rootitem) return; gc_board_pause(TRUE); caller_cursor = gc_cursor_get(); gc_cursor_set(GCOMPRIS_DEFAULT_CURSOR); item_selected = NULL; item_selected_text = NULL; name = gcomprisBoard->title; gc_help_has_board(gcomprisBoard); rootitem = goo_canvas_group_new (goo_canvas_get_root_item(gc_get_canvas()), NULL); item = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", "#DIALOG", "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); GooCanvasBounds bounds; guint pixmap_width = 40; goo_canvas_item_get_bounds(item, &bounds); x_start = bounds.x1; y_start = bounds.y1; y = bounds.y2 - 26; y_start += 15; if(gcomprisBoard->section && gcomprisBoard->name) { text_to_display = g_strdup_printf("%s/%s", gcomprisBoard->section, gcomprisBoard->name); goo_canvas_text_new (rootitem, text_to_display, BOARDWIDTH*0.10, y_start, -1, GTK_ANCHOR_NW, "font", gc_skin_font_board_tiny, "fill-color-rgba", gc_skin_color_title, NULL); g_free(text_to_display); } y_start += 30; goo_canvas_text_new (rootitem, name, BOARDWIDTH/2, y_start, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_title, "fill-color-rgba", gc_skin_color_title, NULL); y_start += 80; // Prerequisite Button if(prerequisite) { item_prerequisite = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", item_id, NULL); SET_ITEM_LOCATION(item_prerequisite, (BOARDWIDTH*0.2) - pixmap_width/2, y_start - 10) g_signal_connect(item_prerequisite, "button_press_event", (GtkSignalFunc) item_event_help, "prerequisite"); gc_item_focus_init(item_prerequisite, NULL); item_prerequisite_text = \ goo_canvas_text_new (rootitem, _("Prerequisite"), BOARDWIDTH*0.20, y_start + GAP_TO_BUTTON, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_get_color("gcompris/helpunselect"), NULL); g_signal_connect(item_prerequisite_text, "button_press_event", (GtkSignalFunc) item_event_help, "prerequisite"); } // Goal Button if(goal) { item_goal = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", item_id, NULL); SET_ITEM_LOCATION(item_goal, (BOARDWIDTH*0.4) - pixmap_width/2, y_start - 10); g_signal_connect(item_goal, "button_press_event", (GtkSignalFunc) item_event_help, "goal"); gc_item_focus_init(item_goal, NULL); item_goal_text = goo_canvas_text_new (rootitem, _("Goal"), BOARDWIDTH*0.4, y_start + GAP_TO_BUTTON, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_get_color("gcompris/helpunselect"), NULL); g_signal_connect(item_goal_text, "button_press_event", (GtkSignalFunc) item_event_help, "goal"); } // Manual Button if(manual) { item_manual = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", item_id, NULL); SET_ITEM_LOCATION(item_manual, (BOARDWIDTH*0.6) - pixmap_width/2, y_start - 10); g_signal_connect(item_manual, "button_press_event", (GtkSignalFunc) item_event_help, "manual"); gc_item_focus_init(item_manual, NULL); item_manual_text = goo_canvas_text_new (rootitem, _("Manual"), BOARDWIDTH*0.6, y_start + GAP_TO_BUTTON, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_get_color("gcompris/helpunselect"), NULL); g_signal_connect(item_manual_text, "button_press_event", (GtkSignalFunc) item_event_help, "manual"); } // Credit Button if(credit) { item_credit = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", item_id, NULL); SET_ITEM_LOCATION(item_credit, (BOARDWIDTH*0.8) - pixmap_width/2, y_start - 10); g_signal_connect(item_credit, "button_press_event", (GtkSignalFunc) item_event_help, "credit"); gc_item_focus_init(item_credit, NULL); item_credit_text = goo_canvas_text_new (rootitem, _("Credit"), BOARDWIDTH*0.8, y_start + GAP_TO_BUTTON, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_get_color("gcompris/helpunselect"), NULL); g_signal_connect(item_credit_text, "button_press_event", (GtkSignalFunc) item_event_help, "credit"); } // CONTENT // default text to display if(prerequisite) { text_to_display = prerequisite; select_item(item_prerequisite, item_prerequisite_text); } else if(goal) { text_to_display = goal; select_item(item_goal, item_goal_text); } else if(manual) { text_to_display = manual; select_item(item_manual, item_manual_text); } else if(credit) { text_to_display = credit; select_item(item_credit, item_credit_text); } y_start += 45; /* Create a scrolled area for the text content */ GtkWidget *view; GtkWidget *sw; view = gtk_text_view_new (); gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD); gtk_text_view_set_editable(GTK_TEXT_VIEW (view), FALSE); gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW (view), FALSE); gtk_signal_connect(GTK_OBJECT(view), "button-press-event", (GtkSignalFunc) event_disable_right_click_popup, NULL); PangoFontDescription *font_desc; font_desc = pango_font_description_from_string (gc_skin_font_content); gtk_widget_modify_font (view, font_desc); pango_font_description_free (font_desc); GdkColor fg_color; GdkColor bg_color; gc_skin_get_gdkcolor("gcompris/helpfg", &fg_color); gc_skin_get_gdkcolor("gcompris/helpbg", &bg_color); gtk_widget_modify_base(view, GTK_STATE_NORMAL, &bg_color); gtk_widget_modify_text(view, GTK_STATE_NORMAL, &fg_color); buffer_content = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add (GTK_CONTAINER (sw), view); goo_canvas_widget_new (rootitem, sw, x_start + 40, y_start, 618.0, 280.0, NULL); gtk_widget_show_all (sw); set_content(text_to_display); // OK gc_util_button_text_svg(rootitem, BOARDWIDTH * 0.5, y, "#BUTTON_TEXT", _("OK"), (GtkSignalFunc) item_event_help, "ok"); gc_bar_hide(TRUE); help_displayed = TRUE; }
/* Setting list of available icons in the control bar */ static void bar_set (const GComprisBarFlags flags) { // Always reset the zoom factor or the calculation // will be wrong goo_canvas_item_set_transform(rootitem, NULL); _hidden = FALSE; goo_canvas_item_raise(rootitem, NULL); /* Non yet initialized : Something Wrong */ if(get_item(GC_BAR_LEVEL) == NULL) { g_message("in bar_set_level, level_item uninitialized : should not happen\n"); return; } current_flags = flags; if(gc_help_has_board(gc_board_get_current())) current_flags |= GC_BAR_HELP; if(flags&GC_BAR_ABOUT) current_flags |= GC_BAR_ABOUT; if(flags&GC_BAR_CONFIG) current_flags |= GC_BAR_CONFIG; if(flags&GC_BAR_REPEAT_ICON) current_flags |= GC_BAR_REPEAT_ICON; if(flags&GC_BAR_REPEAT) current_flags |= GC_BAR_REPEAT; update_exit_button(); GSList *list; double x = 0; for (list = buttons; list != NULL; list = list->next) { GooCanvasItem *item = (GooCanvasItem *)list->data; GComprisBarFlags flag = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT (item), "flag")); if (flag & current_flags) { GooCanvasBounds bounds; SET_ITEM_LOCATION(item, x, -20); goo_canvas_item_get_bounds(item, &bounds); gc_item_focus_init(item, NULL); x += bounds.x2 - bounds.x1 + BAR_GAP; g_object_set (item, "visibility", GOO_CANVAS_ITEM_VISIBLE, NULL); } else g_object_set (item, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); } /* Scale the bar back to fit the buttons, no more */ SET_ITEM_LOCATION(bar_item, 0, 0); GooCanvasBounds bounds; goo_canvas_item_get_bounds(bar_item, &bounds); goo_canvas_item_scale(bar_item, x / (bounds.x2 - bounds.x1), 1); // Always center the bar with its new bounds //SET_ITEM_LOCATION(rootitem, 0, _default_y); bar_location (-1, -1, -1); }
void i7_node_calculate_size(I7Node *self, GooCanvasItemModel *skein, GooCanvas *canvas) { I7_NODE_USE_PRIVATE; GooCanvasBounds size; GooCanvasItem *item; double command_width, command_height; double label_width = 0.0, label_height = 0.0; gboolean command_width_changed, command_height_changed; gboolean label_width_changed, label_height_changed; /* Calculate the bounds of the command text and label text */ item = goo_canvas_get_item(canvas, priv->command_item); goo_canvas_item_get_bounds(item, &size); command_width = size.x2 - size.x1; command_height = size.y2 - size.y1; if(i7_node_has_label(self)) { item = goo_canvas_get_item(canvas, priv->label_item); goo_canvas_item_get_bounds(item, &size); label_width = size.x2 - size.x1; label_height = size.y2 - size.y1; } command_width_changed = command_width != 0.0 && priv->command_width != command_width; command_height_changed = command_height != 0.0 && priv->command_height != command_height; label_width_changed = label_width != 0.0 && priv->label_width != label_width; label_height_changed = label_height != 0.0 && priv->label_height != label_height; if(command_width_changed || command_height_changed) redraw_command(self, command_width, command_height); if(command_height_changed) g_object_set(priv->label_item, "x", 0.0, "y", -command_height, NULL); /* Draw the label background */ if(i7_node_has_label(self)) { if(label_width_changed || label_height_changed) redraw_label(self, label_width, label_height); if(label_width_changed || label_height_changed || command_height_changed) g_object_set(priv->label_shape_item, "x", -0.5 * label_width - label_height, "y", -command_height - 0.5 * label_height, NULL); } else { g_object_set(priv->label_shape_item, "data", "", "visibility", GOO_CANVAS_ITEM_HIDDEN, NULL); } /* Move the differs badge */ g_object_set(priv->badge_item, "x", command_width / 2, "y", command_height / 2 - DIFFERS_BADGE_RADIUS, "width", DIFFERS_BADGE_RADIUS * 2, "height", DIFFERS_BADGE_RADIUS * 2, NULL); }
static void update_preview (Browser *br) { LibraryPart *library_part; gdouble new_x, new_y, x1, y1, x2, y2; gdouble text_width; gdouble width, height; GooCanvasBounds bounds; gdouble scale; cairo_matrix_t transf, affine; gchar *part_name; char *description; GtkTreeModel *model; GtkTreeIter iter; GtkTreeSelection *selection; // Get the current selected row selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (br->list)); model = gtk_tree_view_get_model (GTK_TREE_VIEW (br->list)); if (!GTK_IS_TREE_SELECTION (selection)) return; if (!gtk_tree_selection_get_selected (selection, NULL, &iter)) { return; } gtk_tree_model_get (model, &iter, 0, &part_name, -1); library_part = library_get_part (br->library, part_name); // If there is already a preview part-item, destroy its group and create a // new one. if (br->preview != NULL) { goo_canvas_item_remove (GOO_CANVAS_ITEM (br->preview)); } br->preview = GOO_CANVAS_GROUP (goo_canvas_group_new ( goo_canvas_get_root_item (GOO_CANVAS (br->canvas)), NULL)); goo_canvas_set_bounds (GOO_CANVAS (br->canvas), 0.0, 0.0, 250.0, 110.0); g_object_get (br->preview, "width", &width, "height", &height, NULL); if (!library_part) return; part_item_create_canvas_items_for_preview (br->preview, library_part); // Unconstraint the canvas width & height to adjust for the part description g_object_set (br->preview, "width", -1.0, "height", -1.0, NULL); // Get the coordonates */ goo_canvas_item_get_bounds (GOO_CANVAS_ITEM (br->preview), &bounds); x1 = bounds.x1; x2 = bounds.x2; y1 = bounds.y1; y2 = bounds.y2; // Translate in such a way that the canvas centre remains in (0, 0) cairo_matrix_init_translate (&transf, -(x2 + x1) / 2.0f + PREVIEW_WIDTH / 2, -(y2 + y1) / 2.0f + PREVIEW_HEIGHT / 2); // Compute the scale of the widget if ((x2 - x1 != 0) || (y2 - y1 != 0)) { if ((x2 - x1) < (y2 - y1)) scale = 0.60f * PREVIEW_HEIGHT / (y2 - y1); else scale = 0.60f * PREVIEW_WIDTH / (x2 - x1); } else scale = 5; cairo_matrix_init_scale (&affine, scale, scale); cairo_matrix_multiply (&transf, &transf, &affine); // Apply the transformation goo_canvas_item_set_transform (GOO_CANVAS_ITEM (br->preview), &transf); // Compute the motion to centre the Preview widget new_x = 100 + (PREVIEW_WIDTH - x1 - x2) / 2; new_y = (PREVIEW_HEIGHT - y1 - y2) / 2 - 10; // Apply the transformation if (scale > 5.0) scale = 3.0; goo_canvas_item_set_simple_transform (GOO_CANVAS_ITEM (br->preview), new_x, new_y, scale, 0.0); description = g_strdup (library_part->description); wrap_string (description, 20); g_object_set (br->description, "text", description, NULL); g_free (description); g_object_get (G_OBJECT (br->description), "width", &text_width, NULL); goo_canvas_item_set_simple_transform (GOO_CANVAS_ITEM (br->description), 50.0, -20.0, 1.0, 0.0); g_free (part_name); }
/* * Do all the bar display and register the events */ void gc_config_start () { GcomprisProperties *properties = gc_prop_get(); gint y_start = 0; gint x_start = 0; gint x_text_start = 0; gint y = 0; GooCanvasItem *item; /* Pause the board */ gc_board_pause(TRUE); if(rootitem) { gc_config_stop(); return; } gc_bar_hide(TRUE); rootitem = goo_canvas_group_new (goo_canvas_get_root_item(gc_get_canvas()), NULL); item = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", "#DIALOG", "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); GooCanvasBounds bounds; goo_canvas_item_get_bounds(item, &bounds); x_start = bounds.x1; y_start = bounds.y1; y = bounds.y2 - 26; goo_canvas_text_new (rootitem, _("GCompris Configuration"), (gdouble) BOARDWIDTH/2, (gdouble) y_start + 40, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_title, "fill-color-rgba", gc_skin_color_title, NULL); pixmap_checked = "#CHECKED"; pixmap_unchecked = "#UNCHECKED"; pixmap_width = 30; x_start += 60; x_text_start = x_start + 80; //-------------------------------------------------- // Locale y_start += 105; display_previous_next(x_start, y_start, "locale_previous", "locale_next"); y_flag_start = y_start - pixmap_width/2; /* A repeat icon to reset the selection */ item = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", "#REPEAT", NULL); goo_canvas_item_get_bounds(item, &bounds); double zoom = 0.50; goo_canvas_item_scale(item, zoom, zoom); goo_canvas_item_translate(item, (-1 * bounds.x1 + x_start - 100) * zoom, (-1 * bounds.y1 + y_start - 145) * zoom); g_signal_connect(item, "button_press_event", (GCallback) item_event_ok, "locale_reset"); gc_item_focus_init(item, NULL); /* * The current locale is the one found in the config file */ current_locale = properties->locale; set_locale_flag(current_locale); item_locale_text = goo_canvas_text_new (rootitem, gc_locale_get_name(current_locale), (gdouble) x_text_start, (gdouble) y_start, -1, GTK_ANCHOR_WEST, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_color_content, NULL); // Fullscreen / Window y_start += Y_GAP; item = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", (properties->fullscreen ? pixmap_checked : pixmap_unchecked), NULL); SET_ITEM_LOCATION(item, x_start, y_start - pixmap_width/2); g_signal_connect(item, "button_press_event", (GCallback) item_event_ok, "fullscreen"); gc_item_focus_init(item, NULL); goo_canvas_text_new (rootitem, _("Fullscreen"), (gdouble) x_text_start, (gdouble) y_start, -1, GTK_ANCHOR_WEST, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_color_content, NULL); // Rememberlevel y_start += Y_GAP; item = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", (properties->rememberlevel ? pixmap_checked : pixmap_unchecked), NULL); SET_ITEM_LOCATION(item, x_start, y_start - pixmap_width/2); g_signal_connect(item, "button_press_event", (GCallback) item_event_ok, "rememberlevel"); gc_item_focus_init(item, NULL); goo_canvas_text_new (rootitem, _("Remember level for default user"), (gdouble) x_text_start, (gdouble) y_start, -1, GTK_ANCHOR_WEST, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_color_content, NULL); // Music y_start += Y_GAP; item = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", (properties->music ? pixmap_checked : pixmap_unchecked), NULL); SET_ITEM_LOCATION(item, x_start, y_start - pixmap_width/2); g_signal_connect(item, "button_press_event", (GCallback) item_event_ok, "music"); gc_item_focus_init(item, NULL); goo_canvas_text_new (rootitem, _("Music"), (gdouble) x_text_start, (gdouble) y_start, -1, GTK_ANCHOR_WEST, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_color_content, NULL); // Effect y_start += Y_GAP; item = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", (properties->fx ? pixmap_checked : pixmap_unchecked), NULL); SET_ITEM_LOCATION(item, x_start, y_start - pixmap_width/2); g_signal_connect(item, "button_press_event", (GCallback) item_event_ok, "effect"); gc_item_focus_init(item, NULL); goo_canvas_text_new (rootitem, _("Effect"), (gdouble) x_text_start, (gdouble) y_start, -1, GTK_ANCHOR_WEST, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_color_content, NULL); // Zoom y_start += Y_GAP; item = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", (properties->zoom ? pixmap_checked : pixmap_unchecked), NULL); SET_ITEM_LOCATION(item, x_start, y_start - pixmap_width/2); g_signal_connect(item, "button_press_event", (GCallback) item_event_ok, "zoom"); gc_item_focus_init(item, NULL); goo_canvas_text_new (rootitem, _("Zoom"), (gdouble) x_text_start, (gdouble) y_start, -1, GTK_ANCHOR_WEST, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_color_content, NULL); // Timer y_start += Y_GAP; display_previous_next(x_start, y_start, "timer_previous", "timer_next"); item_timer_text = goo_canvas_text_new (rootitem, gettext(timername[properties->timer]), (gdouble) x_text_start, (gdouble) y_start, -1, GTK_ANCHOR_WEST, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_color_content, NULL); // Font y_start += Y_GAP; { int i; PangoFontFamily ** families; int n_families; PangoFontMap * fontmap; const gchar *current_familly_name = NULL; fontmap = pango_cairo_font_map_get_default(); pango_font_map_list_families (fontmap, & families, & n_families); for (i = 0; i < n_families; i++) { PangoFontFamily * family = families[i]; const gchar * family_name; family_name = pango_font_family_get_name (family); /* Skip font to exclude */ guint j = 0; gboolean exclude = FALSE; while(excluded_fonts[j] != NULL) { if( !g_ascii_strncasecmp(excluded_fonts[j], family_name, strlen(excluded_fonts[j])) ) { exclude = TRUE; break; } j++; } if(exclude) continue; fontlist = g_list_insert_sorted (fontlist, (gpointer)family_name, (GCompareFunc)strcmp); if(!strcmp(properties->fontface, family_name)) current_familly_name = family_name; } g_free (families); current_font_index = font_index = g_list_index(fontlist, current_familly_name); display_previous_next(x_start, y_start, "font_previous", "font_next"); /* A repeat icon to reset the selection */ item = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", "#REPEAT", NULL); goo_canvas_item_get_bounds(item, &bounds); double zoom = 0.50; goo_canvas_item_scale(item, zoom, zoom); goo_canvas_item_translate(item, (-1 * bounds.x1 + x_start - 100) * zoom, (-1 * bounds.y1 + y_start + 650) * zoom); g_signal_connect(item, "button_press_event", (GCallback) item_event_ok, "fontface_reset"); gc_item_focus_init(item, NULL); gchar *first_font_name = g_strdup_printf(_("Font: %s"), (char *)g_list_nth_data(fontlist, font_index)); item_font_text = goo_canvas_text_new (rootitem, first_font_name, (gdouble) x_text_start, (gdouble) y_start, -1, GTK_ANCHOR_WEST, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_color_content, NULL); } // Difficulty Filter y_start += Y_GAP; stars_group_x = x_start + 45; stars_group_y = y_start - 25; gchar *text = g_strdup_printf("<i>%s</i>", gettext(filtername)); item_filter_text = goo_canvas_text_new (rootitem, text, x_text_start, y_start, 400, GTK_ANCHOR_WEST, "use-markup", TRUE, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_color_content, NULL); g_free(text); // OK gc_util_button_text_svg(rootitem, BOARDWIDTH * 0.5, y, "#BUTTON_TEXT", _("OK"), (GCallback) item_event_ok, "ok"); is_displayed = TRUE; }
// Event handler for a "floating" group of objects. int sheet_item_floating_event (Sheet *sheet, const GdkEvent *event) { SheetPriv *priv; GList *list; static Coords pos; static int keep = 0; // Remember the last position of the mouse cursor. static double last_x, last_y; // Mouse cursor position in window coordinates, snapped to the grid spacing. double snapped_x, snapped_y; // Move the selected item(s) by this movement. double dx, dy; g_return_val_if_fail (sheet != NULL, FALSE); g_return_val_if_fail (IS_SHEET (sheet), FALSE); g_return_val_if_fail (sheet->priv->floating_objects != NULL, FALSE); priv = sheet->priv; switch (event->type) { case GDK_BUTTON_RELEASE: g_signal_stop_emission_by_name (sheet, "event"); break; case GDK_BUTTON_PRESS: if (sheet->state != SHEET_STATE_FLOAT) return TRUE; switch (event->button.button) { case 2: case 4: case 5: return FALSE; case 1: // do not free the floating items, but use them like a stamp keep = event->button.state & GDK_CONTROL_MASK; // Continue adding if CTRL is pressed if (!keep) { sheet->state = SHEET_STATE_NONE; g_signal_stop_emission_by_name (sheet, "event"); if (g_signal_handler_is_connected (sheet, sheet->priv->float_handler_id)) g_signal_handler_disconnect (sheet, sheet->priv->float_handler_id); sheet->priv->float_handler_id = 0; } // Get pointer position in canvas coordinates sheet_get_pointer (sheet, &pos.x, &pos.y); for (list = priv->floating_objects; list; list = list->next) { SheetItem *floating_item; ItemData *floating_data; // Create a real item. floating_item = list->data; if (!keep) { floating_data = sheet_item_get_data (floating_item); g_object_set (floating_item, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); } else { floating_data = item_data_clone (sheet_item_get_data (floating_item)); } g_object_ref (G_OBJECT (floating_data)); item_data_set_pos (floating_data, &pos); schematic_add_item (schematic_view_get_schematic_from_sheet (sheet), floating_data); if (!keep) g_object_unref (G_OBJECT (floating_item)); } if (keep) { g_object_set (G_OBJECT (sheet->priv->floating_group), "x", pos.x, "y", pos.y, NULL); } else { g_list_free (sheet->priv->floating_objects); sheet->priv->floating_objects = NULL; } pos.x = 0.0; pos.y = 0.0; break; case 3: // Cancel the "float-placement" for button-3 clicks. g_signal_stop_emission_by_name (sheet, "event"); sheet_item_cancel_floating (sheet); break; } break; case GDK_2BUTTON_PRESS: case GDK_3BUTTON_PRESS: g_signal_stop_emission_by_name (sheet, "event"); return TRUE; case GDK_MOTION_NOTIFY: if (sheet->state != SHEET_STATE_FLOAT && sheet->state != SHEET_STATE_FLOAT_START) return FALSE; g_signal_stop_emission_by_name (sheet, "event"); if (sheet->state == SHEET_STATE_FLOAT_START) { sheet->state = SHEET_STATE_FLOAT; // Reparent the selected objects so that we can move them // efficiently. for (list = priv->floating_objects; list; list = list->next) { sheet_item_reparent (SHEET_ITEM (list->data), priv->floating_group); // Set the floating item visible g_object_set (G_OBJECT (list->data), "visibility", GOO_CANVAS_ITEM_VISIBLE, NULL); } last_x = 0.0; last_y = 0.0; } // Get pointer position independantly of the zoom sheet_get_pointer (sheet, &snapped_x, &snapped_y); // Calculate which amount to move the selected objects by. dx = snapped_x - last_x; dy = snapped_y - last_y; last_x = snapped_x; last_y = snapped_y; for (list = priv->floating_objects; list; list = list->next) { goo_canvas_item_translate (GOO_CANVAS_ITEM (list->data), dx, dy); } g_list_free_full (list, g_object_unref); break; case GDK_KEY_PRESS: switch (event->key.keyval) { case GDK_KEY_r: case GDK_KEY_R: sheet_rotate_ghosts (sheet); { gdouble x, y; GooCanvasBounds bounds; sheet_get_pointer (sheet, &x, &y); // Center the objects around the mouse pointer. goo_canvas_item_get_bounds ( GOO_CANVAS_ITEM (priv->floating_group), &bounds); snapped_x = x - (bounds.x1 + bounds.x2) / 2; snapped_y = y - (bounds.y1 + bounds.y2) / 2; snap_to_grid (sheet->grid, &snapped_x, &snapped_y); goo_canvas_item_translate ( GOO_CANVAS_ITEM (priv->floating_group), snapped_x, snapped_y); last_x = snapped_x; last_y = snapped_y; } break; default: return FALSE; } default: return FALSE; } return TRUE; }
// Event handler for a SheetItem gboolean sheet_item_event (GooCanvasItem *sheet_item, GooCanvasItem *sheet_target_item, GdkEvent *event, Sheet *sheet) { // Remember the last position of the mouse cursor. static double last_x, last_y; GooCanvas *canvas; SheetPriv *priv; GList *list; // Mouse cursor position in window coordinates, snapped to the grid spacing. double snapped_x, snapped_y; // Move the selected item(s) by this movement. double dx, dy; g_return_val_if_fail (sheet_item != NULL, FALSE); g_return_val_if_fail (sheet != NULL, FALSE); priv = sheet->priv; canvas = GOO_CANVAS (sheet); switch (event->type) { case GDK_BUTTON_PRESS: // Grab focus to sheet for correct use of events gtk_widget_grab_focus (GTK_WIDGET (sheet)); switch (event->button.button) { case 1: g_signal_stop_emission_by_name (sheet_item, "button_press_event"); sheet->state = SHEET_STATE_DRAG_START; sheet_get_pointer (sheet, &last_x, &last_y); break; case 3: g_signal_stop_emission_by_name (sheet_item, "button_press_event"); if (sheet->state != SHEET_STATE_NONE) return TRUE; // Bring up a context menu for right button clicks. if (!SHEET_ITEM (sheet_item)->priv->selected && !((event->button.state & GDK_SHIFT_MASK) == GDK_SHIFT_MASK)) sheet_select_all (sheet, FALSE); sheet_item_select (SHEET_ITEM (sheet_item), TRUE); sheet_item_run_menu (SHEET_ITEM (sheet_item), sheet, (GdkEventButton *) event); break; default: return FALSE; } break; case GDK_2BUTTON_PRESS: // Do not interfere with object dragging. if (sheet->state == SHEET_STATE_DRAG) return FALSE; switch (event->button.button) { case 1: if (sheet->state == SHEET_STATE_DRAG_START) sheet->state = SHEET_STATE_NONE; g_signal_stop_emission_by_name (sheet_item, "button_press_event"); g_signal_emit_by_name (sheet_item, "double_clicked"); break; default: return FALSE; } break; case GDK_3BUTTON_PRESS: g_signal_stop_emission_by_name (sheet_item, "button_press_event"); return TRUE; case GDK_BUTTON_RELEASE: switch (event->button.button) { case 1: if (sheet->state != SHEET_STATE_DRAG && sheet->state != SHEET_STATE_DRAG_START) return TRUE; g_signal_stop_emission_by_name (sheet_item, "button-release-event"); if (sheet->state == SHEET_STATE_DRAG_START) { sheet->state = SHEET_STATE_NONE; if (!(event->button.state & GDK_SHIFT_MASK)) sheet_select_all (sheet, FALSE); if (IS_SHEET_ITEM (sheet_item)) sheet_item_select (SHEET_ITEM (sheet_item), TRUE); return TRUE; } // Get the mouse motion sheet_get_pointer (sheet, &snapped_x, &snapped_y); snapped_x -= last_x; snapped_y -= last_y; sheet->state = SHEET_STATE_NONE; goo_canvas_pointer_ungrab (canvas, GOO_CANVAS_ITEM (sheet_item), event->button.time); // Reparent the selected objects to the normal group // to have correct behaviour for (list = priv->selected_objects; list; list = list->next) { sheet_item_reparent (SHEET_ITEM (list->data), sheet->object_group); } for (list = priv->selected_objects; list; list = list->next) { ItemData *item_data; Coords pos; item_data = SHEET_ITEM (list->data)->priv->data; pos.x = snapped_x; pos.y = snapped_y; item_data_move (item_data, &pos); item_data_register (item_data); } g_list_free_full (list, g_object_unref); break; } case GDK_KEY_PRESS: switch (event->key.keyval) { case GDK_KEY_r: sheet_rotate_selection (sheet); { gdouble x, y; GooCanvasBounds bounds; sheet_get_pointer (sheet, &x, &y); // Center the objects around the mouse pointer. goo_canvas_item_get_bounds ( GOO_CANVAS_ITEM (priv->floating_group), &bounds); dx = x - (bounds.x1 + bounds.x2) / 2; dy = y - (bounds.y1 + bounds.y2) / 2; snap_to_grid (sheet->grid, &dx, &dy); goo_canvas_item_translate ( GOO_CANVAS_ITEM (priv->floating_group), dx, dy); last_x = snapped_x; last_y = snapped_y; } break; default: return FALSE; } return TRUE; case GDK_MOTION_NOTIFY: if (sheet->state != SHEET_STATE_DRAG && sheet->state != SHEET_STATE_DRAG_START) return FALSE; if (sheet->state == SHEET_STATE_DRAG_START) { sheet->state = SHEET_STATE_DRAG; // Update the selection if needed. if (IS_SHEET_ITEM (sheet_item) && (!SHEET_ITEM (sheet_item)->priv->selected)) { if (!(event->button.state & GDK_SHIFT_MASK)) { sheet_select_all (sheet, FALSE); } sheet_item_select (SHEET_ITEM (sheet_item), TRUE); } // Reparent the selected objects so that we can move them // efficiently. for (list = priv->selected_objects; list; list = list->next) { ItemData *item_data; item_data = SHEET_ITEM (list->data)->priv->data; item_data_unregister (item_data); sheet_item_reparent (SHEET_ITEM (list->data), priv->selected_group); } goo_canvas_pointer_grab (canvas, GOO_CANVAS_ITEM (sheet_item), GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, NULL, event->button.time); } // Set last_x & last_y to the pointer position sheet_get_pointer (sheet, &snapped_x, &snapped_y); dx = snapped_x - last_x; dy = snapped_y - last_y; // Check that we don't move outside the sheet... // Horizontally: /* if (cx1 <= 0) { // leftmost edge dx = dx - x1; snap_to_grid (sheet->grid, &dx, NULL); snapped_x = last_x + dx; } else if (cx2 >= sheet_width) { // rightmost edge dx = dx - (x2 - sheet_width / priv->zoom); snap_to_grid (sheet->grid, &dx, NULL); snapped_x = last_x + dx; } // And vertically: if (cy1 <= 0) { // upper edge dy = dy - y1; snap_to_grid (sheet->grid, NULL, &dy); snapped_y = last_y + dy; } else if (cy2 >= sheet_height) { // lower edge dy = dy - (y2 - sheet_height / priv->zoom); snap_to_grid (sheet->grid, NULL, &dy); snapped_y = last_y + dy; } //last_x = snapped_x; //last_y = snapped_y; */ goo_canvas_item_set_transform (GOO_CANVAS_ITEM (priv->selected_group), NULL); goo_canvas_item_translate (GOO_CANVAS_ITEM (priv->selected_group), dx, dy); return TRUE; default: return FALSE; } return TRUE; }