static void create_width_for_height_table (GooCanvasItem *root, gdouble x, gdouble y, gdouble width, gdouble height, gdouble rotation) { GooCanvasItem *table, *item; gchar *text = "This is a long paragraph that will have to be split over a few lines so we can see if its allocated height changes when its allocated width is changed."; table = goo_canvas_table_new (root, #if 1 "width", width, "height", height, #endif NULL); goo_canvas_item_translate (table, x, y); goo_canvas_item_rotate (table, rotation, 0, 0); item = goo_canvas_rect_new (table, 0.0, 0.0, width - 2, 10.0, "fill-color", "red", NULL); goo_canvas_item_set_child_properties (table, item, "row", 0, "column", 0, "x-shrink", TRUE, NULL); #if 1 item = goo_canvas_text_new (table, text, 0, 0, -1, GOO_CANVAS_ANCHOR_NW, NULL); goo_canvas_item_set_child_properties (table, item, "row", 1, "column", 0, "x-expand", TRUE, "x-fill", TRUE, "x-shrink", TRUE, "y-expand", TRUE, "y-fill", TRUE, NULL); g_object_set_data (G_OBJECT (item), "id", "Text Item"); g_signal_connect (item, "button_press_event", G_CALLBACK (on_button_press), NULL); #endif item = goo_canvas_rect_new (table, 0.0, 0.0, width - 2, 10.0, "fill-color", "red", NULL); goo_canvas_item_set_child_properties (table, item, "row", 2, "column", 0, "x-shrink", TRUE, NULL); }
static void show_point(PcbItem *item, int layer) { #define rad 3.0 #define siz 3.5 if (item->flags & PCB_POI) item->canvas_item[layer] = goo_canvas_rect_new(pcb.layer[layer].olay, item->p.x - siz, item->p.y - siz, siz * 2, siz * 2, "stroke-color", "black", "fill-color", item->flags & PCB_SELECTED ? "red" : "yellow", NULL); else if (item->flags & PCB_BEND) item->canvas_item[layer] = goo_canvas_ellipse_new(pcb.layer[layer].olay, item->p.x, item->p.y, 2, 2, "stroke-color", "black", "fill-color", item->flags & PCB_SELECTED ? "green" : "black", NULL); else item->canvas_item[layer] = goo_canvas_ellipse_new(pcb.layer[layer].olay, item->p.x, item->p.y, rad, rad, "stroke-color", "black", "fill-color", item->flags & PCB_SELECTED ? "green" : "white", NULL); #undef rad #undef siz }
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 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); }
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; }
static void create_demo_table (GooCanvasItem *root, gdouble x, gdouble y, gdouble width, gdouble height) { GooCanvasItem *table, *square, *circle, *triangle; table = goo_canvas_table_new (root, "row-spacing", 4.0, "column-spacing", 4.0, "width", width, "height", height, NULL); goo_canvas_item_translate (table, x, y); square = goo_canvas_rect_new (table, 0.0, 0.0, 50.0, 50.0, "fill-color", "red", NULL); goo_canvas_item_set_child_properties (table, square, "row", 0, "column", 0, "x-shrink", TRUE, NULL); g_object_set_data (G_OBJECT (square), "id", "Red square"); g_signal_connect (square, "button_press_event", G_CALLBACK (on_button_press), NULL); circle = goo_canvas_ellipse_new (table, 0.0, 0.0, 25.0, 25.0, "fill-color", "blue", NULL); goo_canvas_item_set_child_properties (table, circle, "row", 0, "column", 1, "x-shrink", TRUE, NULL); g_object_set_data (G_OBJECT (circle), "id", "Blue circle"); g_signal_connect (circle, "button_press_event", G_CALLBACK (on_button_press), NULL); triangle = goo_canvas_polyline_new (table, TRUE, 3, 25.0, 0.0, 0.0, 50.0, 50.0, 50.0, "fill-color", "yellow", NULL); goo_canvas_item_set_child_properties (table, triangle, "row", 0, "column", 2, "x-shrink", TRUE, NULL); g_object_set_data (G_OBJECT (triangle), "id", "Yellow triangle"); g_signal_connect (triangle, "button_press_event", G_CALLBACK (on_button_press), NULL); }
RubberbandInfo * rubberband_info_new (Sheet *sheet) { RubberbandInfo *rubberband_info; cairo_pattern_t *pattern; cairo_matrix_t matrix; NG_DEBUG ("0x%x A", COLOR_A); NG_DEBUG ("0x%x B", COLOR_B); NG_DEBUG ("0x%x A PRE", COLOR_A_PRE); NG_DEBUG ("0x%x B PRE", COLOR_B_PRE); static guint32 stipple_data[8*8] = { COLOR_A_PRE, COLOR_A_PRE, COLOR_A_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_B_PRE,COLOR_B_PRE,COLOR_A_PRE, COLOR_A_PRE, COLOR_A_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_B_PRE,COLOR_A_PRE,COLOR_A_PRE, COLOR_A_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_A_PRE,COLOR_A_PRE,COLOR_A_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_A_PRE, COLOR_A_PRE,COLOR_A_PRE,COLOR_A_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_A_PRE, COLOR_A_PRE, COLOR_A_PRE,COLOR_A_PRE,COLOR_B_PRE, COLOR_B_PRE, COLOR_B_PRE, COLOR_A_PRE, COLOR_A_PRE, COLOR_A_PRE, COLOR_A_PRE,COLOR_B_PRE,COLOR_B_PRE, COLOR_B_PRE, COLOR_A_PRE, COLOR_A_PRE, COLOR_A_PRE, COLOR_A_PRE, COLOR_B_PRE,COLOR_B_PRE,COLOR_B_PRE, COLOR_A_PRE, COLOR_A_PRE, COLOR_A_PRE, COLOR_A_PRE, COLOR_B_PRE, COLOR_B_PRE,COLOR_B_PRE,COLOR_B_PRE}; /* the stipple patten should look like that * 1 1 1 0 0 0 0 1 * 1 1 0 0 0 0 1 1 * 1 0 0 0 0 1 1 1 * 0 0 0 0 1 1 1 1 * * 0 0 0 1 1 1 1 0 * 0 0 1 1 1 1 0 0 * 0 1 1 1 1 0 0 0 * 1 1 1 1 0 0 0 0 */ rubberband_info = g_new (RubberbandInfo, 1); rubberband_info->state = RUBBERBAND_START; pattern = create_stipple ("lightgrey", (guchar*)stipple_data); //scale 5x, see http://cairographics.org/manual/cairo-cairo-pattern-t.html#cairo-pattern-t cairo_matrix_init_scale (&matrix, 1.0, 1.0); cairo_pattern_set_matrix (pattern, &matrix); rubberband_info->rectangle = GOO_CANVAS_RECT (goo_canvas_rect_new ( GOO_CANVAS_ITEM (sheet->object_group), 10.0, 10.0, 10.0, 10.0, "stroke-color", "black", "line-width", 0.2, "fill-pattern", pattern, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL)); cairo_pattern_destroy (pattern); return rubberband_info; }
static void setup_canvas (GtkWidget *canvas) { GooCanvasItem *root; root = goo_canvas_get_root_item (GOO_CANVAS (canvas)); /* Absolute. */ ellipse1 = goo_canvas_ellipse_new (root, 0, 0, 25, 15, "fill-color", "blue", NULL); goo_canvas_item_translate (ellipse1, 100, 100); g_signal_connect (ellipse1, "animation_finished", G_CALLBACK (on_animation_finished), NULL); rect1 = goo_canvas_rect_new (root, -10, -10, 20, 20, "fill-color", "blue", NULL); goo_canvas_item_translate (rect1, 100, 200); rect3 = goo_canvas_rect_new (root, -10, -10, 20, 20, "fill-color", "blue", NULL); goo_canvas_item_translate (rect3, 200, 200); /* Relative. */ ellipse2 = goo_canvas_ellipse_new (root, 0, 0, 25, 15, "fill-color", "red", NULL); goo_canvas_item_translate (ellipse2, 100, 400); rect2 = goo_canvas_rect_new (root, -10, -10, 20, 20, "fill-color", "red", NULL); goo_canvas_item_translate (rect2, 100, 500); rect4 = goo_canvas_rect_new (root, -10, -10, 20, 20, "fill-color", "red", NULL); goo_canvas_item_translate (rect4, 200, 500); }
/* * 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); }
static void draw_a_rect(GooCanvasItem *group, int x1, int y1, int x2, int y2, char *color) { goo_canvas_rect_new(group, x1, y1, x2 - x1, y2 - y1, "fill-color", color, "stroke-color", color, "line-width", 1.0, NULL); }
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)); } }
// This function defines the drawing sheet on which schematic will be drawn GtkWidget * sheet_new (int width, int height) { GooCanvas *sheet_canvas; GooCanvasGroup *sheet_group; GooCanvasPoints *points; Sheet *sheet; GtkWidget *sheet_widget; GooCanvasItem *root; // Creation of the Canvas sheet = SHEET (g_object_new (TYPE_SHEET, NULL)); sheet_canvas = GOO_CANVAS (sheet); g_object_set (G_OBJECT (sheet_canvas), "bounds-from-origin", FALSE, "bounds-padding", 4.0, "background-color-rgb", 0xFFFFFF, NULL); root = goo_canvas_get_root_item (sheet_canvas); sheet_group = GOO_CANVAS_GROUP (goo_canvas_group_new ( root, NULL)); sheet_widget = GTK_WIDGET (sheet); goo_canvas_set_bounds (GOO_CANVAS (sheet_canvas), 0, 0, width + 20, height + 20); // Define vicinity around GooCanvasItem //sheet_canvas->close_enough = 6.0; sheet->priv->width = width; sheet->priv->height = height; // Create the dot grid. sheet->grid = grid_create (GOO_CANVAS_ITEM (sheet_group), width, height); // Everything outside the sheet should be gray. // top // goo_canvas_rect_new (GOO_CANVAS_ITEM (sheet_group), 0.0, 0.0, (double) width + 20.0, 20.0, "fill_color", "gray", "line-width", 0.0, NULL); goo_canvas_rect_new (GOO_CANVAS_ITEM (sheet_group), 0.0, (double) height, (double) width + 20.0, (double) height + 20.0, "fill_color", "gray", "line-width", 0.0, NULL); // right // goo_canvas_rect_new (GOO_CANVAS_ITEM (sheet_group), 0.0, 0.0, 20.0, (double) height + 20.0, "fill_color", "gray", "line-width", 0.0, NULL); goo_canvas_rect_new (GOO_CANVAS_ITEM (sheet_group), (double) width, 0.0, (double) width + 20.0, (double) height + 20.0, "fill_color", "gray", "line-width", 0.0, NULL); // Draw a thin black border around the sheet. points = goo_canvas_points_new (5); points->coords[0] = 20.0; points->coords[1] = 20.0; points->coords[2] = width; points->coords[3] = 20.0; points->coords[4] = width; points->coords[5] = height; points->coords[6] = 20.0; points->coords[7] = height; points->coords[8] = 20.0; points->coords[9] = 20.0; goo_canvas_polyline_new (GOO_CANVAS_ITEM (sheet_group), FALSE, 0, "line-width", 1.0, "points", points, NULL); goo_canvas_points_unref (points); // Finally, create the object group that holds all objects. sheet->object_group = GOO_CANVAS_GROUP (goo_canvas_group_new ( root, "x", 0.0, "y", 0.0, NULL)); NG_DEBUG ("root group %p", sheet->object_group); sheet->priv->selected_group = GOO_CANVAS_GROUP (goo_canvas_group_new ( GOO_CANVAS_ITEM (sheet->object_group), "x", 0.0, "y", 0.0, NULL)); NG_DEBUG ("selected group %p", sheet->priv->selected_group); sheet->priv->floating_group = GOO_CANVAS_GROUP (goo_canvas_group_new ( GOO_CANVAS_ITEM (sheet->object_group), "x", 0.0, "y", 0.0, NULL)); NG_DEBUG ("floating group %p", sheet->priv->floating_group); // Hash table that keeps maps coordinate to a specific dot. sheet->priv->node_dots = g_hash_table_new_full (dot_hash, dot_equal, g_free, NULL); //this requires object_group to be setup properly sheet->priv->rubberband_info = rubberband_info_new (sheet); sheet->priv->create_wire_info = create_wire_info_new (sheet); return sheet_widget; }
void gc_selector_images_start (GcomprisBoard *gcomprisBoard, gchar *dataset, ImageSelectorCallBack iscb, void *user_context) { gint y_start = 0; gchar *dataseturl = NULL; GtkWidget *w; if(sugar_detected()) { sugar_choose_image(iscb, user_context); return; } if(rootitem) return; gc_bar_hide(TRUE); gc_board_pause(TRUE); imageSelectorCallBack = iscb; current_user_context = user_context; rootitem = goo_canvas_group_new (goo_canvas_get_root_item(gc_get_canvas()), NULL); images_selector_displayed = TRUE; goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", "#IMAGE_SELECTOR", "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); y_start += 110; /* * Create the list scrollbar * ------------------------- */ canvas_list_selector = goo_canvas_new (); goo_canvas_widget_new (rootitem, canvas_list_selector, LIST_AREA_X1, LIST_AREA_Y1, LIST_AREA_X2 - LIST_AREA_X1, LIST_AREA_Y2 - LIST_AREA_Y1 - 35.0, NULL); gtk_widget_show (canvas_list_selector); /* Set the new canvas to the background color or it's white */ list_bg_item = goo_canvas_rect_new (goo_canvas_get_root_item(GOO_CANVAS(canvas_list_selector)), 0, 0, (LIST_AREA_X2 - LIST_AREA_X1) * gc_zoom_factor_get(), (LIST_AREA_Y2 - LIST_AREA_Y1) * gc_zoom_factor_get(), "fill-color-rgba", gc_skin_get_color("gcompris/imageselectbg_left"), "line-width", 0.0, NULL); list_adj = \ GTK_ADJUSTMENT (gtk_adjustment_new (0.00, 0.00, 0.00, 10, IMAGE_HEIGHT, (LIST_AREA_Y2 - LIST_AREA_Y1) * gc_zoom_factor_get()) ); w = gtk_vscrollbar_new (list_adj); goo_canvas_widget_new (rootitem, w, LIST_AREA_X2 - 5.0, LIST_AREA_Y1, 30.0, LIST_AREA_Y2 - LIST_AREA_Y1 - 20.0, NULL); gtk_widget_show (w); /* Set the scrollwheel event */ g_signal_connect (list_adj, "value_changed", (GCallback) item_event_scroll, canvas_list_selector); /* * Create the image scrollbar * -------------------------- */ canvas_image_selector = goo_canvas_new (); goo_canvas_widget_new (rootitem, canvas_image_selector, DRAWING_AREA_X1, DRAWING_AREA_Y1, DRAWING_AREA_X2 - DRAWING_AREA_X1, DRAWING_AREA_Y2 - DRAWING_AREA_Y1, NULL); gtk_widget_show (canvas_image_selector); /* Set the new canvas to the background color or it's white */ image_bg_item = \ goo_canvas_rect_new (goo_canvas_get_root_item(GOO_CANVAS(canvas_image_selector)), 0, 0, (DRAWING_AREA_X2 - DRAWING_AREA_X1) * gc_zoom_factor_get(), (DRAWING_AREA_Y2 - DRAWING_AREA_Y1) * gc_zoom_factor_get(), "fill-color-rgba", gc_skin_get_color("gcompris/imageselectbg_right"), "line-width", 0.0, NULL); image_adj = \ GTK_ADJUSTMENT (gtk_adjustment_new (0.00, 0.00, 0.00, 10, IMAGE_HEIGHT, (DRAWING_AREA_Y2 - DRAWING_AREA_Y1) * gc_zoom_factor_get()) ); w = gtk_vscrollbar_new (image_adj); goo_canvas_widget_new (rootitem, w, DRAWING_AREA_X2 - 5.0, DRAWING_AREA_Y1, 30.0, DRAWING_AREA_Y2 - DRAWING_AREA_Y1 - 20.0, NULL); gtk_widget_show (w); /* Set the scrollwheel event */ g_signal_connect (image_adj, "value_changed", (GCallback) item_event_scroll, canvas_image_selector); /* * DISPLAY IMAGES */ /* Initial image position */ isy = 0.0; /* I need the following : -> if dataset is a file read it. -> if dataset is a directory, read all xml file in it. */ dataseturl = \ gc_file_find_absolute(dataset, NULL); /* if the file doesn't exist */ if(g_file_test ((dataseturl), G_FILE_TEST_IS_DIR) ) { g_warning("dataset %s is a directory. Trying to read xml", dataseturl); read_dataset_directory(dataseturl); } else if(dataseturl) { /* Read the given data set file, local or net */ read_xml_file(dataseturl); } else { /* Network code for dataset directory */ GSList *filelist = NULL; GSList *i = NULL; g_free(dataseturl); dataseturl = g_strconcat("boards/", dataset, NULL); /* TODO */ filelist = NULL; //gc_net_dir_read_name(dataseturl, ".xml"); for (i = filelist; i != NULL; i = g_slist_next (i)) { gchar *url = gc_file_find_absolute(i->data, NULL); g_warning("processing dataset=%s\n", (char *)i->data); read_xml_file(url); g_free(url); } g_slist_free(filelist); } g_free(dataseturl); /* * OK Button * --------- */ gc_util_button_text_svg(rootitem, (BOARDWIDTH*0.5), BOARDHEIGHT - 32, "#BUTTON_TEXT", _("OK"), (GCallback) item_event_images_selector, "/ok/"); }
/* ==================================== */ 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; }
/* ===================================================================== * * =====================================================================*/ static GooCanvasItem *submarine_create_item(GooCanvasItem *parent) { GdkPixbuf *pixmap = NULL; GooCanvasItem *item = NULL; char s12[12]; int i; GooCanvasItem *rootItem = goo_canvas_group_new (parent, NULL); pixmap = gc_pixmap_load("submarine/submarine.png"); submarine_width = gdk_pixbuf_get_width(pixmap); submarine_height = gdk_pixbuf_get_height(pixmap); submarine_item = goo_canvas_image_new (rootItem, pixmap, 0, 0, NULL); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif pixmap = gc_pixmap_load("submarine/vanne.svg"); ballast_ar_purge_item = goo_canvas_image_new (rootItem, pixmap, PURGE_AR + schema_x, schema_y -1.0, NULL); g_signal_connect(ballast_ar_purge_item, "button-press-event", (GCallback) ballast_ar_purge_event, NULL); ballast_av_purge_item = goo_canvas_image_new (rootItem, pixmap, PURGE_AV + schema_x, schema_y -1.0, NULL); g_signal_connect(ballast_av_purge_item, "button-press-event", (GCallback) ballast_av_purge_event, NULL); regleur_purge_item = goo_canvas_image_new (rootItem, pixmap, REGLEUR + schema_x, schema_y -2.0, NULL); g_signal_connect(regleur_purge_item, "button-press-event", (GCallback) regleur_purge_event, NULL); item = goo_canvas_image_new (rootItem, pixmap, schema_x + CHASSE_BALLAST_AV_X, schema_y + CHASSE_BALLAST_AV_Y, NULL); g_signal_connect(item, "button-press-event", (GCallback) ballast_av_chasse_event, NULL); item = goo_canvas_image_new (rootItem, pixmap, schema_x + CHASSE_BALLAST_AR_X, schema_y + CHASSE_BALLAST_AR_Y, NULL); g_signal_connect(item, "button-press-event", (GCallback) ballast_ar_chasse_event, NULL); regleur_chasse_item = goo_canvas_image_new (rootItem, pixmap, schema_x + CHASSE_REGLEUR_X, schema_y + CHASSE_REGLEUR_Y, NULL); g_signal_connect(regleur_chasse_item, "button-press-event", (GCallback) regleur_chasse_event, NULL); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif // DEPTH RUDDERS pixmap = gc_pixmap_load("submarine/rudder.png"); barre_av_item = goo_canvas_image_new (rootItem, pixmap, schema_x + BARRE_AV_X, schema_y + BARRE_AV_Y, NULL); barre_ar_item = goo_canvas_image_new (rootItem, pixmap, schema_x + BARRE_AR_X, schema_y + BARRE_AR_Y, NULL); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif // displays the speed on the engine sprintf(s12,"%d",(int)submarine_horizontal_speed); speed_item_back = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + ENGINE_UP_X - ENGINE_DOWN_X +1, (gdouble) schema_y + ENGINE_UP_Y + 10 + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "alignment", PANGO_ALIGN_CENTER, "fill-color", TEXT_COLOR_BACK, NULL); speed_item_front = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + ENGINE_UP_X - ENGINE_DOWN_X, (gdouble) schema_y + ENGINE_UP_Y + 10, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "alignment", PANGO_ALIGN_CENTER, "fill-color", TEXT_COLOR_FRONT, NULL); // displays the ballast_av_air value ballast_av_air_item_rect = goo_canvas_rect_new (rootItem, schema_x + BALLAST_AV_AIR_X1, schema_y + BALLAST_AV_AIR_Y1 + BALLAST_AV_AIR_H, BALLAST_AV_AIR_W, BALLAST_AV_AIR_H, "fill-color", "blue", "line-width", 0.0, NULL); sprintf(s12,"%d",(int)ballast_av_air); ballast_av_air_item_back = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + BALLAST_AV_AIR_TEXT_X + 1, (gdouble) schema_y + BALLAST_AV_AIR_TEXT_Y + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_BACK, NULL); ballast_av_air_item_front = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + BALLAST_AV_AIR_TEXT_X, (gdouble) schema_y + BALLAST_AV_AIR_TEXT_Y, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_FRONT, NULL); setBallastAV(ballast_av_air); // displays the ballast_ar_air value ballast_ar_air_item_rect = goo_canvas_rect_new (rootItem, schema_x + BALLAST_AR_AIR_X1, schema_y + BALLAST_AR_AIR_Y1 + BALLAST_AR_AIR_H, BALLAST_AR_AIR_W, BALLAST_AR_AIR_H, "fill-color", "blue", "line-width", 0.0, NULL); sprintf(s12,"%d",(int)ballast_ar_air); ballast_ar_air_item_back = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + BALLAST_AR_AIR_TEXT_X + 1, (gdouble) schema_y + BALLAST_AR_AIR_TEXT_Y + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_BACK, NULL); ballast_ar_air_item_front = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + BALLAST_AR_AIR_TEXT_X, (gdouble) schema_y + BALLAST_AR_AIR_TEXT_Y, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_FRONT, NULL); setBallastAR(ballast_ar_air); // displays the remaining air value sprintf(s12,"%d", (int)air); air_item_back = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + AIR_X +1, (gdouble) schema_y + AIR_Y + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_BACK, NULL); air_item_front = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + AIR_X, (gdouble) schema_y + AIR_Y, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_FRONT, NULL); // displays the remaining battery value sprintf(s12,"%d", (int)battery); battery_item_back = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + BATTERY_X +1, (gdouble) schema_y + BATTERY_Y + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "alignment", PANGO_ALIGN_CENTER, "fill-color", TEXT_COLOR_BACK, NULL); battery_item_front = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + BATTERY_X, (gdouble) schema_y + BATTERY_Y, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "alignment", PANGO_ALIGN_CENTER, "fill-color", TEXT_COLOR_FRONT, NULL); // displays the remaining regleur value regleur_item_rect = goo_canvas_rect_new (rootItem, schema_x + REGLEUR_X1, schema_y + REGLEUR_Y1 + REGLEUR_H, REGLEUR_W, REGLEUR_H, "fill-color", "blue", "line-width", 0.0, NULL); sprintf(s12,"%d", (int)regleur); regleur_item_back = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + REGLEUR_TEXT_X +1, (gdouble) schema_y + REGLEUR_TEXT_Y + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_BACK, NULL); regleur_item_front = goo_canvas_text_new (rootItem, s12, (gdouble) schema_x + REGLEUR_TEXT_X, (gdouble) schema_y + REGLEUR_TEXT_Y, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_FRONT, NULL); setRegleur(regleur); // displays an alert when some parameters are bad pixmap = gc_pixmap_load("submarine/alert_submarine.png"); alert_submarine = goo_canvas_image_new (rootItem, pixmap, ALERT_SUBMARINE_X, ALERT_SUBMARINE_Y, NULL); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif g_object_set (alert_submarine, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); // when the submarine makes some bubbles ... pixmap = gc_pixmap_load("submarine/bubbling.png"); for (i=0; i<3; i++) { bubbling[i] = goo_canvas_image_new (rootItem, pixmap, 0, 0, NULL); g_object_set (bubbling[i], "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); } #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif // whale item switch(gcomprisBoard->level) { case 1: whale_x = 50; whale_y = MAX_DEPTH - 100; break; case 2: whale_x = 150; whale_y = MAX_DEPTH - 100; break; case 3: whale_x = 250; whale_y = MAX_DEPTH - 100; break; default: whale_x = 380; whale_y = MAX_DEPTH - 100; break; } pixmap = gc_pixmap_load("submarine/whale.png"); whale = goo_canvas_image_new (rootItem, pixmap, whale_x, whale_y, NULL); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif // whale being hit pixmap = gc_pixmap_load("submarine/whale_hit.png"); big_explosion = goo_canvas_image_new (rootItem, pixmap, whale_x, whale_y, NULL); g_object_set (big_explosion, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif // treasure item pixmap = gc_pixmap_load("submarine/crown.png"); treasure_x = (BOARDWIDTH*3)/4; treasure_y = MAX_DEPTH; treasure = goo_canvas_image_new (rootItem, pixmap, 0, 0, NULL); goo_canvas_item_translate(treasure, treasure_x, 0); goo_canvas_item_animate(treasure, treasure_x, treasure_y, 0.6, 0, TRUE, 6*1000, 40, GOO_CANVAS_ANIMATE_FREEZE); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif // the triggers for air compressor and battery charger pixmap = gc_pixmap_load("submarine/manette.png"); air_compressor_item = goo_canvas_image_new (rootItem, pixmap, schema_x + AIR_TRIGGER_X, schema_y + AIR_TRIGGER_Y, NULL); battery_charger_item = goo_canvas_image_new (rootItem, pixmap, schema_x + BATTERY_TRIGGER_X, schema_y + BATTERY_TRIGGER_Y, NULL); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif g_signal_connect(air_compressor_item, "button-press-event", (GCallback) air_compressor_event, NULL); g_signal_connect(battery_charger_item, "button-press-event", (GCallback) battery_charger_event, NULL); /* * Set the right wall * ------------------ */ switch(gcomprisBoard->level) { case 1: gate_top_y = 80; gate_bottom_y = schema_y - 100; break; case 2: gate_top_y = 100; gate_bottom_y = schema_y - 120; break; default: gate_top_y = 120; gate_bottom_y = schema_y - 120; break; } /* At startup, the gate is closed */ gate_top_current_y = gate_bottom_y; top_gate_item = goo_canvas_rect_new (rootItem, BOARDWIDTH - 25, 40, 27, gate_top_current_y - 40, "fill_color_rgba", 0x989677FF, "stroke-color", "black", "line-width", 2.0, NULL); goo_canvas_rect_new (rootItem, BOARDWIDTH - 25, gate_bottom_y, 27, schema_y - gate_bottom_y, "fill_color_rgba", 0x989677FF, "stroke-color", "black", "line-width", 2.0, NULL); timer_id = g_timeout_add(UPDATE_DELAY, update_timeout, NULL); timer_slow_id = g_timeout_add(UPDATE_DELAY_SLOW, update_timeout_slow, NULL); timer_very_slow_id = g_timeout_add(UPDATE_DELAY_VERY_SLOW, update_timeout_very_slow, NULL); return rootItem; }
/* ==================================== */ static GooCanvasItem *fifteen_create_item(GooCanvasItem *parent) { int i; int x, y; GooCanvasItem **board; GooCanvasItem *text; char buf[20]; GdkPixbuf *pixmap = NULL; boardRootItem = goo_canvas_group_new (goo_canvas_get_root_item(gcomprisBoard->canvas), NULL); goo_canvas_item_translate(boardRootItem, (BOARDWIDTH-(4*PIECE_SIZE))/2, (BOARDHEIGHT-(4*PIECE_SIZE))/2); /* Load the cute frame */ pixmap = gc_pixmap_load("fifteen/fifteen_frame.png"); goo_canvas_image_new (boardRootItem, pixmap, -1*((gdk_pixbuf_get_width(pixmap)-(4*PIECE_SIZE))/2), -1*((gdk_pixbuf_get_height(pixmap)-(4*PIECE_SIZE))/2)-2, NULL); gdk_pixbuf_unref(pixmap); board = g_new (GooCanvasItem *, 16); g_object_set_data (G_OBJECT (boardRootItem), "board", board); for (i = 0; i < 15; i++) { y = i / 4; x = i % 4; board[i] = goo_canvas_group_new (boardRootItem, NULL); goo_canvas_item_translate(board[i], (x * PIECE_SIZE), (y * PIECE_SIZE)); goo_canvas_rect_new (board[i], 0.0, 0.0, PIECE_SIZE, PIECE_SIZE, "fill-color", get_piece_color (i), "stroke-color", "black", NULL); sprintf (buf, "%d", i + 1); text = goo_canvas_text_new (board[i], buf, (double) PIECE_SIZE / 2.0, (double) PIECE_SIZE / 2.0, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_medium, "fill-color", "black", NULL); g_object_set_data (G_OBJECT (board[i]), "piece_num", GINT_TO_POINTER (i)); g_object_set_data (G_OBJECT (board[i]), "piece_pos", GINT_TO_POINTER (i)); g_object_set_data (G_OBJECT (board[i]), "text", text); g_signal_connect (board[i], "button-press-event", G_CALLBACK (piece_event), NULL); } board[15] = NULL; /* Select level difficulty */ switch(gcomprisBoard->level) { case 1: scramble(board, 10); break; case 2: scramble(board, 50); break; case 3: case 4: scramble(board, 100); break; case 5: scramble(board, 150); break; default: scramble(board, 256); } return NULL; }
int main (int argc, char *argv[]) { GtkWidget *window, *scrolled_win, *canvas; GooCanvasItem *root, *rect_item, *text_item, *image_item; GdkPixbuf *pb; /* Initialize GTK+. */ gtk_set_locale (); gtk_init (&argc, &argv); pb=gdk_pixbuf_new_from_file("test-screenshot.png", NULL); if(!pb) { printf("error: gdk_pixbuf_new_from_file"); exit(1); } /* Create the window and widgets. */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (window), 740, 700); gtk_widget_show (window); g_signal_connect (window, "delete_event", (GtkSignalFunc) 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, 640, 600); 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)); image_item = goo_canvas_image_new (root, pb, 0, 0, NULL); /* Add a few simple items. */ rect_item = goo_canvas_rect_new (root, 20, 20, 200, 200, "line-width", 5.0, "radius-x", 10.0, "radius-y", 5.0, "stroke-color", "red", NULL); GooCanvasItem *polyline0 = goo_canvas_polyline_new_line (root, 100.0, 100.0, 500.0, 500.0, "stroke-color", "red", "line-width", 5.0, "start-arrow", TRUE, NULL); //text_item = goo_canvas_text_new (root, PACKAGE_STRING, 300, 300, -1, //GTK_ANCHOR_CENTER, //"font", "Sans 24px", //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", (GtkSignalFunc) on_rect_button_press, NULL); /* Pass control to the GTK+ main event loop. */ gtk_main (); return 0; }
/* ==================================== */ static GooCanvasItem *click_on_letter_create_item(GooCanvasItem *parent) { int xOffset, yOffset, i; if (gcomprisBoard->sublevel == 1) { Level *level = &g_array_index (levels, Level, gcomprisBoard->level - 1); n_answer = g_utf8_strlen (level->answers, -1); g_assert( n_answer <= MAX_N_ANSWER ); if ( uppercase_only ) { gchar *answers_up = g_utf8_strup( level->answers, -1 ); gchar *questions_up = g_utf8_strup( level->questions, -1 ); answers = shuffle_utf8(answers_up); questions = shuffle_utf8(questions_up); g_free(answers_up); g_free(questions_up); } else { answers = shuffle_utf8(level->answers); questions = shuffle_utf8(level->questions); } /* Go to next level after this number of 'play' */ gcomprisBoard->number_of_sublevel = g_utf8_strlen (level->questions, -1); } right_letter = g_utf8_strdown(questions[gcomprisBoard->sublevel - 1], -1); boardRootItem = goo_canvas_group_new (goo_canvas_get_root_item(gcomprisBoard->canvas), NULL); if ( ! _repeat() ) { /* Sound was not played, display the letter to find instead */ guint x = 10; guint y = 110; guint width = 80; guint height = 80; goo_canvas_rect_new (boardRootItem, x, y, width, height, "stroke_color_rgba", 0xFFFFFFFFL, "fill_color_rgba", 0x00005550L, "line-width", (double) 2, "radius-x", (double) 10, "radius-y", (double) 10, NULL); goo_canvas_text_new (boardRootItem, questions[gcomprisBoard->sublevel - 1], (double) x + width / 2, (double) y + height / 2, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_huge_bold, "fill_color_rgba", 0xffffffff, NULL); } /* Display the answers */ yOffset = VERTICAL_SEPARATION - carriage_svg_dimension.height; xOffset = 144; gint text_gap_x = -5; gint text_gap_y = -35; RsvgHandle *svg_handle= carriage_svg_handle; RsvgDimensionData svg_dimension = carriage_svg_dimension; for (i = 0; i< n_answer; i++) { if ( i > 0 && i % N_LETTER_PER_LINE == 0 ) { /* Line wrapping */ svg_handle= cloud_svg_handle; svg_dimension = cloud_svg_dimension; xOffset = 144; yOffset -= svg_dimension.height; text_gap_x = 0; text_gap_y = 0; } GooCanvasItem *button_item = \ goo_canvas_svg_new (boardRootItem, svg_handle, "svg-id", "#OFF", NULL); goo_canvas_item_translate( button_item, xOffset, yOffset); GooCanvasItem *text_item = \ goo_canvas_text_new (boardRootItem, answers[i], (double) xOffset + svg_dimension.width / 2 + text_gap_x, (double) yOffset + svg_dimension.height / 2 + text_gap_y, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_huge_bold, "fill_color_rgba", 0x000000ff, NULL); xOffset += HORIZONTAL_SEPARATION + svg_dimension.width; g_signal_connect(text_item, "button_press_event", (GCallback) item_event, answers[i]); g_signal_connect(button_item, "button_press_event", (GCallback) item_event, answers[i]); gc_item_focus_init(text_item, button_item); gc_item_focus_init(button_item, NULL); g_object_set_data(G_OBJECT(button_item), "button_item", button_item); g_object_set_data(G_OBJECT(text_item), "button_item", button_item); } return NULL; }
static void create_events_area (GtkWidget *canvas, gint area_num, GooCanvasPointerEvents pointer_events, gchar *label) { gint row = area_num / 3, col = area_num % 3; gdouble x = col * 200, y = row * 150; GooCanvasItem *root, *rect; char *view_id; GooCanvasLineDash *dash; root = goo_canvas_get_root_item (GOO_CANVAS (canvas)); dash = goo_canvas_line_dash_new (2, 5.0, 5.0); /* Create invisible item. */ rect = goo_canvas_rect_new (root, x + 45, y + 35, 30, 30, "fill-color", "red", "visibility", GOO_CANVAS_ITEM_INVISIBLE, "line-width", 5.0, "pointer-events", pointer_events, NULL); view_id = g_strdup_printf ("%s invisible", label); g_object_set_data_full (G_OBJECT (rect), "id", view_id, g_free); setup_item_signals (rect); /* Display a thin rect around it to indicate it is there. */ #if 1 rect = goo_canvas_rect_new (root, x + 42.5, y + 32.5, 36, 36, "line-dash", dash, "line-width", 1.0, "stroke-color", "gray", NULL); #endif /* Create unpainted item. */ rect = goo_canvas_rect_new (root, x + 85, y + 35, 30, 30, "stroke-pattern", NULL, "line-width", 5.0, "pointer-events", pointer_events, NULL); view_id = g_strdup_printf ("%s unpainted", label); g_object_set_data_full (G_OBJECT (rect), "id", view_id, g_free); setup_item_signals (rect); /* Display a thin rect around it to indicate it is there. */ #if 1 rect = goo_canvas_rect_new (root, x + 82.5, y + 32.5, 36, 36, "line-dash", dash, "line-width", 1.0, "stroke-color", "gray", NULL); #endif /* Create stroked item. */ rect = goo_canvas_rect_new (root, x + 125, y + 35, 30, 30, "line-width", 5.0, "pointer-events", pointer_events, NULL); view_id = g_strdup_printf ("%s stroked", label); g_object_set_data_full (G_OBJECT (rect), "id", view_id, g_free); setup_item_signals (rect); /* Create filled item. */ rect = goo_canvas_rect_new (root, x + 60, y + 75, 30, 30, "fill-color", "red", "stroke-pattern", NULL, "line-width", 5.0, "pointer-events", pointer_events, NULL); view_id = g_strdup_printf ("%s filled", label); g_object_set_data_full (G_OBJECT (rect), "id", view_id, g_free); setup_item_signals (rect); /* Create stroked & filled item. */ rect = goo_canvas_rect_new (root, x + 100, y + 75, 30, 30, "fill-color", "red", "line-width", 5.0, "pointer-events", pointer_events, NULL); view_id = g_strdup_printf ("%s stroked & filled", label); g_object_set_data_full (G_OBJECT (rect), "id", view_id, g_free); setup_item_signals (rect); goo_canvas_text_new (root, label, x + 100, y + 130, -1, GOO_CANVAS_ANCHOR_CENTER, "font", "Sans 12", "fill-color", "blue", NULL); goo_canvas_line_dash_unref (dash); }
/* ===================================================================== * * =====================================================================*/ static GooCanvasItem *submarine_create_item(GooCanvasItem *parent) { GdkPixbuf *pixmap = NULL; char s12[12]; int i, w, h; boardRootItem = \ goo_canvas_group_new (goo_canvas_get_root_item(gcomprisBoard->canvas), NULL); pixmap = gc_pixmap_load("submarine/submarine.png"); submarine_width = gdk_pixbuf_get_width(pixmap); submarine_height = gdk_pixbuf_get_height(pixmap); submarine_item = goo_canvas_image_new (boardRootItem, pixmap, 0,//SUBMARINE_INITIAL_X, 0,//SUBMARINE_INITIAL_DEPTH + SURFACE_IN_BACKGROUND - submarine_height, NULL); gdk_pixbuf_unref(pixmap); pixmap = gc_pixmap_load("submarine/sub_schema.png"); w = gdk_pixbuf_get_width(pixmap); h = gdk_pixbuf_get_height(pixmap); schema_x = (BOARDWIDTH - w)/2 ; schema_y = BOARDHEIGHT - h; goo_canvas_image_new (boardRootItem, pixmap, schema_x, schema_y, NULL); gdk_pixbuf_unref(pixmap); pixmap = gc_pixmap_load("submarine/vanne.png"); ballast_ar_purge_item = goo_canvas_image_new (boardRootItem, pixmap, PURGE_AR + schema_x, schema_y -1.0, NULL); g_signal_connect(ballast_ar_purge_item, "button-press-event", (GtkSignalFunc) ballast_ar_purge_event, NULL); ballast_av_purge_item = goo_canvas_image_new (boardRootItem, pixmap, PURGE_AV + schema_x, schema_y -1.0, NULL); g_signal_connect(ballast_av_purge_item, "button-press-event", (GtkSignalFunc) ballast_av_purge_event, NULL); regleur_purge_item = goo_canvas_image_new (boardRootItem, pixmap, REGLEUR + schema_x, schema_y -2.0, NULL); g_signal_connect(regleur_purge_item, "button-press-event", (GtkSignalFunc) regleur_purge_event, NULL); ballast_av_chasse_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + CHASSE_BALLAST_AV_X, schema_y + CHASSE_BALLAST_AV_Y, NULL); g_signal_connect(ballast_av_chasse_item, "button-press-event", (GtkSignalFunc) ballast_av_chasse_event, NULL); ballast_ar_chasse_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + CHASSE_BALLAST_AR_X, schema_y + CHASSE_BALLAST_AR_Y, NULL); g_signal_connect(ballast_ar_chasse_item, "button-press-event", (GtkSignalFunc) ballast_ar_chasse_event, NULL); regleur_chasse_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + CHASSE_REGLEUR_X, schema_y + CHASSE_REGLEUR_Y, NULL); g_signal_connect(regleur_chasse_item, "button-press-event", (GtkSignalFunc) regleur_chasse_event, NULL); gdk_pixbuf_unref(pixmap); // DEPTH RUDDERS pixmap = gc_pixmap_load("submarine/rudder.png"); w = gdk_pixbuf_get_width(pixmap); h = gdk_pixbuf_get_height(pixmap); barre_av_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + BARRE_AV_X, schema_y + BARRE_AV_Y, NULL); barre_ar_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + BARRE_AR_X, schema_y + BARRE_AR_Y, NULL); gdk_pixbuf_unref(pixmap); #define COMMAND_OFFSET 20.0 pixmap = gc_pixmap_load("submarine/up.png"); int w2 = gdk_pixbuf_get_width(pixmap); barre_av_up_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + BARRE_AV_X + w - w2, schema_y + BARRE_AV_Y - COMMAND_OFFSET, NULL); barre_ar_up_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + BARRE_AR_X + w - w2, schema_y + BARRE_AR_Y - COMMAND_OFFSET, NULL); engine_up_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + ENGINE_UP_X, schema_y + ENGINE_UP_Y, NULL); gdk_pixbuf_unref(pixmap); pixmap = gc_pixmap_load("submarine/down.png"); barre_av_down_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + BARRE_AV_X + w - w2, schema_y + BARRE_AV_Y + COMMAND_OFFSET, NULL); barre_ar_down_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + BARRE_AR_X + w - w2, schema_y + BARRE_AR_Y + COMMAND_OFFSET, NULL); engine_down_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + ENGINE_DOWN_X, schema_y + ENGINE_DOWN_Y, NULL); gdk_pixbuf_unref(pixmap); g_signal_connect(barre_av_up_item, "button-press-event", (GtkSignalFunc) barre_av_event, GINT_TO_POINTER(UP)); g_signal_connect(barre_ar_up_item, "button-press-event", (GtkSignalFunc) barre_ar_event, GINT_TO_POINTER(UP)); g_signal_connect(barre_av_down_item, "button-press-event", (GtkSignalFunc) barre_av_event, GINT_TO_POINTER(DOWN)); g_signal_connect(barre_ar_down_item, "button-press-event", (GtkSignalFunc) barre_ar_event, GINT_TO_POINTER(DOWN)); g_signal_connect(engine_up_item, "button-press-event", (GtkSignalFunc) engine_event, GINT_TO_POINTER(UP)); g_signal_connect(engine_down_item, "button-press-event", (GtkSignalFunc) engine_event, GINT_TO_POINTER(DOWN)); // displays the speed on the engine sprintf(s12,"%d",(int)submarine_horizontal_speed); speed_item_back = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + ENGINE_UP_X - ENGINE_DOWN_X +1, (gdouble) schema_y + ENGINE_UP_Y + 10 + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "alignment", PANGO_ALIGN_CENTER, "fill-color", TEXT_COLOR_BACK, NULL); speed_item_front = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + ENGINE_UP_X - ENGINE_DOWN_X, (gdouble) schema_y + ENGINE_UP_Y + 10, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "alignment", PANGO_ALIGN_CENTER, "fill-color", TEXT_COLOR_FRONT, NULL); // displays the ballast_av_air value ballast_av_air_item_rect = goo_canvas_rect_new (boardRootItem, schema_x + BALLAST_AV_AIR_X1, schema_y + BALLAST_AV_AIR_Y1 + BALLAST_AV_AIR_H, BALLAST_AV_AIR_W, BALLAST_AV_AIR_H, "fill-color", "blue", "line-width", 0.0, NULL); sprintf(s12,"%d",(int)ballast_av_air); ballast_av_air_item_back = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + BALLAST_AV_AIR_TEXT_X + 1, (gdouble) schema_y + BALLAST_AV_AIR_TEXT_Y + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_BACK, NULL); ballast_av_air_item_front = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + BALLAST_AV_AIR_TEXT_X, (gdouble) schema_y + BALLAST_AV_AIR_TEXT_Y, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_FRONT, NULL); setBallastAV(ballast_av_air); // displays the ballast_ar_air value ballast_ar_air_item_rect = goo_canvas_rect_new (boardRootItem, schema_x + BALLAST_AR_AIR_X1, schema_y + BALLAST_AR_AIR_Y1 + BALLAST_AR_AIR_H, BALLAST_AR_AIR_W, BALLAST_AR_AIR_H, "fill-color", "blue", "line-width", 0.0, NULL); sprintf(s12,"%d",(int)ballast_ar_air); ballast_ar_air_item_back = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + BALLAST_AR_AIR_TEXT_X + 1, (gdouble) schema_y + BALLAST_AR_AIR_TEXT_Y + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_BACK, NULL); ballast_ar_air_item_front = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + BALLAST_AR_AIR_TEXT_X, (gdouble) schema_y + BALLAST_AR_AIR_TEXT_Y, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_FRONT, NULL); setBallastAR(ballast_ar_air); // displays the remaining air value sprintf(s12,"%d", (int)air); air_item_back = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + AIR_X +1, (gdouble) schema_y + AIR_Y + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_BACK, NULL); air_item_front = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + AIR_X, (gdouble) schema_y + AIR_Y, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_FRONT, NULL); // displays the remaining battery value sprintf(s12,"%d", (int)battery); battery_item_back = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + BATTERY_X +1, (gdouble) schema_y + BATTERY_Y + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "alignment", PANGO_ALIGN_CENTER, "fill-color", TEXT_COLOR_BACK, NULL); battery_item_front = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + BATTERY_X, (gdouble) schema_y + BATTERY_Y, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "alignment", PANGO_ALIGN_CENTER, "fill-color", TEXT_COLOR_FRONT, NULL); // displays the remaining regleur value regleur_item_rect = goo_canvas_rect_new (boardRootItem, schema_x + REGLEUR_X1, schema_y + REGLEUR_Y1 + REGLEUR_H, REGLEUR_W, REGLEUR_H, "fill-color", "blue", "line-width", 0.0, NULL); sprintf(s12,"%d", (int)regleur); regleur_item_back = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + REGLEUR_TEXT_X +1, (gdouble) schema_y + REGLEUR_TEXT_Y + 1, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_BACK, NULL); regleur_item_front = goo_canvas_text_new (boardRootItem, s12, (gdouble) schema_x + REGLEUR_TEXT_X, (gdouble) schema_y + REGLEUR_TEXT_Y, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", TEXT_COLOR_FRONT, NULL); setRegleur(regleur); // displays an alert when some parameters are bad pixmap = gc_pixmap_load("submarine/alert_submarine.png"); w = gdk_pixbuf_get_width(pixmap); h = gdk_pixbuf_get_height(pixmap); alert_submarine = goo_canvas_image_new (boardRootItem, pixmap, ALERT_SUBMARINE_X, ALERT_SUBMARINE_Y, NULL); gdk_pixbuf_unref(pixmap); g_object_set (alert_submarine, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); // when the submarine makes some bubbles ... pixmap = gc_pixmap_load("submarine/bubbling.png"); for (i=0; i<3; i++) { bubbling[i] = goo_canvas_image_new (boardRootItem, pixmap, 0, 0, NULL); g_object_set (bubbling[i], "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); } gdk_pixbuf_unref(pixmap); // whale item pixmap = gc_pixmap_load("submarine/whale.png"); whale_x = g_random_int_range((int)(BOARDWIDTH/4), (int)(BOARDWIDTH/2)); whale_y = g_random_int_range((int)(SURFACE_IN_BACKGROUND + gdk_pixbuf_get_height(pixmap)*2), (int)MAX_DEPTH); whale = goo_canvas_image_new (boardRootItem, pixmap, whale_x, whale_y, NULL); gdk_pixbuf_unref(pixmap); // whale being hit pixmap = gc_pixmap_load("submarine/whale_hit.png"); big_explosion = goo_canvas_image_new (boardRootItem, pixmap, whale_x, whale_y, NULL); g_object_set (big_explosion, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); gdk_pixbuf_unref(pixmap); // treasure item pixmap = gc_pixmap_load("submarine/crown.png"); treasure_x = (BOARDWIDTH*3)/4; treasure_y = MAX_DEPTH; treasure = goo_canvas_image_new (boardRootItem, pixmap, 0, 0, NULL); goo_canvas_item_translate(treasure, treasure_x, 0); goo_canvas_item_animate(treasure, treasure_x, treasure_y, 0.6, 0, TRUE, 6*1000, 40, GOO_CANVAS_ANIMATE_FREEZE); gdk_pixbuf_unref(pixmap); // the triggers for air compressor and battery charger pixmap = gc_pixmap_load("submarine/manette.png"); air_compressor_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + AIR_TRIGGER_X, schema_y + AIR_TRIGGER_Y, NULL); battery_charger_item = goo_canvas_image_new (boardRootItem, pixmap, schema_x + BATTERY_TRIGGER_X, schema_y + BATTERY_TRIGGER_Y, NULL); gdk_pixbuf_unref(pixmap); g_signal_connect(air_compressor_item, "button-press-event", (GtkSignalFunc) air_compressor_event, NULL); g_signal_connect(battery_charger_item, "button-press-event", (GtkSignalFunc) battery_charger_event, NULL); // the antisubmarine warfare frigate pixmap = gc_pixmap_load("submarine/asw_frigate.png"); w = gdk_pixbuf_get_width(pixmap); frigate_item = goo_canvas_image_new (boardRootItem, pixmap, 0, 0, NULL); goo_canvas_item_translate(frigate_item, BOARDWIDTH, 2); goo_canvas_item_animate(frigate_item, -w, 2.0, 1, 0, TRUE, 30*1000, 40, GOO_CANVAS_ANIMATE_RESTART); gdk_pixbuf_unref(pixmap); /* * Set the right wall * ------------------ */ switch(gcomprisBoard->level) { case 1: gate_top_y = 80; gate_bottom_y = schema_y - 100; break; case 2: gate_top_y = 100; gate_bottom_y = schema_y - 120; break; default: gate_top_y = 120; gate_bottom_y = schema_y - 120; break; } /* At startup, the gate is closed */ gate_top_current_y = gate_bottom_y; top_gate_item = goo_canvas_rect_new (boardRootItem, BOARDWIDTH - 25, 40, 27, gate_top_current_y - 40, "fill_color_rgba", 0x989677FF, "stroke-color", "black", "line-width", 2.0, NULL); goo_canvas_rect_new (boardRootItem, BOARDWIDTH - 25, gate_bottom_y, 27, schema_y - gate_bottom_y, "fill_color_rgba", 0x989677FF, "stroke-color", "black", "line-width", 2.0, NULL); timer_id = g_timeout_add(UPDATE_DELAY, update_timeout, NULL); timer_slow_id = g_timeout_add(UPDATE_DELAY_SLOW, update_timeout_slow, NULL); timer_very_slow_id = g_timeout_add(UPDATE_DELAY_VERY_SLOW, update_timeout_very_slow, NULL); return NULL; }
GtkWidget * create_canvas_features (void) { GtkWidget *vbox; GtkWidget *w; GtkWidget *alignment; GtkWidget *frame; GtkWidget *canvas; GooCanvasItem *root, *item; GooCanvasItem *parent1; GooCanvasItem *parent2; GooCanvasItem *group; vbox = gtk_vbox_new (FALSE, 4); gtk_container_set_border_width (GTK_CONTAINER (vbox), 4); gtk_widget_show (vbox); /* Instructions */ w = gtk_label_new ("Reparent test: click on the items to switch them between parents"); gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0); gtk_widget_show (w); /* Frame and canvas */ alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0); gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0); gtk_widget_show (alignment); frame = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN); gtk_container_add (GTK_CONTAINER (alignment), frame); gtk_widget_show (frame); canvas = goo_canvas_new (); root = goo_canvas_get_root_item (GOO_CANVAS (canvas)); gtk_widget_set_size_request (canvas, 400, 200); goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, 400, 200); gtk_container_add (GTK_CONTAINER (frame), canvas); gtk_widget_show (canvas); /* First parent and box */ parent1 = goo_canvas_group_new (root, NULL); goo_canvas_rect_new (parent1, 0, 0, 200, 200, "fill_color", "tan", NULL); /* Second parent and box */ parent2 = goo_canvas_group_new (root, NULL); goo_canvas_item_translate (parent2, 200, 0); goo_canvas_rect_new (parent2, 0, 0, 200, 200, "fill_color", "#204060", NULL); /* Big circle to be reparented */ item = goo_canvas_ellipse_new (parent1, 100, 100, 90, 90, "stroke_color", "black", "fill_color", "mediumseagreen", "line-width", 3.0, NULL); g_object_set_data (G_OBJECT (item), "parent1", parent1); g_object_set_data (G_OBJECT (item), "parent2", parent2); g_signal_connect (item, "button_press_event", G_CALLBACK (on_button_press), NULL); /* A group to be reparented */ group = goo_canvas_group_new (parent2, NULL); goo_canvas_item_translate (group, 100, 100); goo_canvas_ellipse_new (group, 0, 0, 50, 50, "stroke_color", "black", "fill_color", "wheat", "line_width", 3.0, NULL); goo_canvas_ellipse_new (group, 0, 0, 25, 25, "fill_color", "steelblue", NULL); g_object_set_data (G_OBJECT (group), "parent1", parent1); g_object_set_data (G_OBJECT (group), "parent2", parent2); g_signal_connect (group, "button_press_event", G_CALLBACK (on_button_press), NULL); return vbox; }
/** \brief create the area in which we display the board title and description * */ static void create_info_area(GooCanvasItem *parent, MenuItems *menuitems) { gint x = (double) info_x + info_w/2.0; gint y = info_y; g_assert(parent); /* The description background */ menuitems->bg = goo_canvas_rect_new (parent, info_x, info_y, info_w, info_h, "stroke_color_rgba", 0xFFFFFFFFL, "fill_color_rgba", gc_skin_get_color("menu/description_bg_color"), "line-width", (double) 2, "radius-x", (double) 10, "radius-y", (double) 10, NULL); g_object_set(menuitems->bg, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); menuitems->boardname_item = \ goo_canvas_text_new (parent, "", x, y + 20, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_big, "fill-color-rgba", gc_skin_get_color("menu/text"), "alignment", PANGO_ALIGN_CENTER, NULL); menuitems->description_item = \ goo_canvas_text_new (parent, "", x, y + 70, info_w - 10, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_medium, "fill-color-rgba", gc_skin_get_color("menu/text"), "alignment", PANGO_ALIGN_CENTER, NULL); menuitems->author_item = \ goo_canvas_text_new (parent, "", x, y + 110, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_tiny, "fill-color-rgba", gc_skin_get_color("menu/text"), "alignment", PANGO_ALIGN_CENTER, NULL); }
WireItem * wire_item_new (Sheet *sheet, Wire *wire) { GooCanvasItem *item; WireItem *wire_item; GooCanvasPoints *points; WireItemPriv *priv; SheetPos start_pos, length; g_return_val_if_fail (sheet != NULL, NULL); g_return_val_if_fail (IS_SHEET (sheet), NULL); wire_get_pos_and_length (wire, &start_pos, &length); item = g_object_new (TYPE_WIRE_ITEM, NULL); g_object_set (item, "parent", sheet->object_group, NULL); wire_item = WIRE_ITEM (item); g_object_set (wire_item, "data", wire, NULL); priv = wire_item->priv; priv->resize1 = GOO_CANVAS_RECT (goo_canvas_rect_new ( GOO_CANVAS_ITEM (wire_item), -RESIZER_SIZE, -RESIZER_SIZE, 2 * RESIZER_SIZE, 2 * RESIZER_SIZE, "stroke-color", "blue", "fill-color", "green", "line-width", 1.0, NULL)); g_object_set (priv->resize1, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); priv->resize2 = GOO_CANVAS_RECT (goo_canvas_rect_new ( GOO_CANVAS_ITEM (wire_item), length.x - RESIZER_SIZE, length.y - RESIZER_SIZE, 2 * RESIZER_SIZE, 2 * RESIZER_SIZE, "stroke-color", "blue", "fill-color", "green", "line-width", 1.0, NULL)); g_object_set (priv->resize2, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); points = goo_canvas_points_new (2); points->coords[0] = 0; points->coords[1] = 0; points->coords[2] = length.x; points->coords[3] = length.y; priv->line = GOO_CANVAS_POLYLINE (goo_canvas_polyline_new ( GOO_CANVAS_ITEM (wire_item), FALSE, 0, "points", points, "stroke-color", "blue", "line-width", 1.0, NULL)); goo_canvas_points_unref (points); ITEM_DATA (wire)->rotated_handler_id = g_signal_connect_data (wire, "rotated", G_CALLBACK (wire_rotated_callback), G_OBJECT (wire_item), NULL, 0); g_signal_connect_data (wire, "flipped", G_CALLBACK (wire_flipped_callback), G_OBJECT (wire_item), NULL, 0); ITEM_DATA (wire)->moved_handler_id = g_signal_connect_object (wire, "moved", G_CALLBACK (wire_moved_callback), G_OBJECT (wire_item), 0); g_signal_connect (wire, "changed", G_CALLBACK (wire_changed_callback), wire_item); g_signal_connect (wire, "delete", G_CALLBACK (wire_delete_callback), wire_item); wire_update_bbox (wire); return wire_item; }
static void create_item(GooCanvasItem *parent) { MemoryItem *memoryItem; gint x, y; double height, width; double height2, width2; GdkPixbuf *pixmap = NULL; // Calc width and height of one card width = (base_x2-(currentMode == MODE_TUX ? base_x1_tux : base_x1))/numberOfColumn; height = (base_y2-base_y1)/numberOfLine; // Respect the card ratio if( width * 1.418 > height) width = height * 0.704; else height = width * 1.418; /* Remove a little bit of space for the card shadow */ height2 = height * 0.95; width2 = width * 0.95; if (currentUiMode == UIMODE_SOUND) { goo_canvas_rect_new (parent, (currentMode == MODE_TUX ? base_x1_tux : base_x1) - 20, base_y1 - 15, width * numberOfColumn + 20*2, height * numberOfLine + 15*2, "stroke_color_rgba", 0xFFFFFFFFL, "fill_color_rgba", 0x66666690L, "line-width", (double) 2, "radius-x", (double) 10, "radius-y", (double) 10, NULL); } if (currentMode == MODE_TUX){ GdkPixbuf *pixmap_tux = gc_pixmap_load("memory/tux-teacher.png"); tux = goo_canvas_image_new (parent, pixmap_tux, 50, 140, NULL); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap_tux); #else g_object_unref(pixmap_tux); #endif tux_score = goo_canvas_text_new (parent, "", (double) 115, (double) 235, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_huge_bold, "fill_color_rgba", 0xFF0F0FFF, NULL); player_score = goo_canvas_text_new (parent, "", (double) 100, (double) BASE_CARD_Y2 - 20, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_huge_bold, "fill_color_rgba", 0xFF0F0FFF, NULL); } for(x=0; x<numberOfColumn; x++) { for(y=0; y<numberOfLine; y++) { memoryItem = g_malloc0(sizeof(MemoryItem)); memoryItem->rootItem = \ goo_canvas_group_new (parent, NULL); goo_canvas_item_translate(memoryItem->rootItem, (currentMode == MODE_TUX ? base_x1_tux : base_x1) + x*width, base_y1 + y*height); if (currentUiMode == UIMODE_SOUND) pixmap = gc_pixmap_load("memory/Tux_mute.png"); else pixmap = gc_pixmap_load("memory/backcard.png"); memoryItem->backcardItem = \ goo_canvas_image_new (memoryItem->rootItem, pixmap, 0, 0, NULL); goo_canvas_item_scale(memoryItem->backcardItem, width2 / gdk_pixbuf_get_width(pixmap), height2 / gdk_pixbuf_get_height(pixmap)); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif if (currentUiMode != UIMODE_SOUND){ pixmap = gc_pixmap_load("memory/emptycard.png"); memoryItem->framecardItem = \ goo_canvas_image_new (memoryItem->rootItem, pixmap, 0, 0, NULL); goo_canvas_item_scale(memoryItem->framecardItem, (width2 / gdk_pixbuf_get_width(pixmap)), (height2 / gdk_pixbuf_get_height(pixmap))); g_object_set (memoryItem->framecardItem, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif } // Display the image itself while taking care of its size and maximize the ratio get_image(memoryItem, x, y); if (currentUiMode == UIMODE_SOUND){ pixmap = gc_pixmap_load("memory/Tux_play.png"); memoryItem->frontcardItem = \ goo_canvas_image_new (memoryItem->rootItem, pixmap, 0, 0, NULL); goo_canvas_item_scale(memoryItem->frontcardItem, (width2 / gdk_pixbuf_get_width(pixmap)), (height2 / gdk_pixbuf_get_height(pixmap))); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif } else { if(memoryItem->type & (TYPE_IMAGE|TYPE_ENUMERATE_IMAGE)) { pixmap = gc_pixmap_load(memoryItem->data); memoryItem->frontcardItem = \ goo_canvas_image_new (memoryItem->rootItem, pixmap, 0.0, 0.0, NULL); /* scale only in ENUMERATE (image size too big) */ if(memoryItem->type == TYPE_ENUMERATE_IMAGE) { goo_canvas_item_scale(memoryItem->frontcardItem, (0.9*width2 / gdk_pixbuf_get_width(pixmap)), (0.9*height2 / gdk_pixbuf_get_height(pixmap))); goo_canvas_item_translate(memoryItem->frontcardItem, 0.1 * width2, 0.1 * height2); } else { goo_canvas_item_translate(memoryItem->frontcardItem, (width2 - gdk_pixbuf_get_width(pixmap))/2, (height2 - gdk_pixbuf_get_height(pixmap))/2); } #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif } else { gchar *font; if (memoryItem->type & (TYPE_ADD|TYPE_MINUS|TYPE_MULT|TYPE_DIV)) font = op_fonts[gcomprisBoard->level]; else font = TEXT_FONT; /* It's a letter */ memoryItem->frontcardItem = \ goo_canvas_text_new (memoryItem->rootItem, memoryItem->data, (double) (width2)/2, (double) (height2)/2, -1, GTK_ANCHOR_CENTER, "font", font, "fill_color_rgba", 0x000000FF, NULL); if(memoryItem->type == TYPE_WORDNUMBER){ gcompris_adapt_font_size(GOO_CANVAS_TEXT(memoryItem->frontcardItem), width2, height2); } } } g_object_set (memoryItem->frontcardItem, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); g_signal_connect(memoryItem->rootItem, "button_press_event", (GCallback) item_event, memoryItem); } } //return (NULL); }
static void create_demo_item (GooCanvasItem *table, gint demo_item_type, gint row, gint column, gint rows, gint columns, gchar *text, gdouble width, gdouble xalign, gdouble yalign, PangoAlignment text_alignment) { GooCanvasItem *item = NULL; GtkWidget *widget; GValue value = { 0 }; guint new_row; switch (demo_item_type) { case DEMO_RECT_ITEM: item = goo_canvas_rect_new (table, 0, 0, 38, 19, "fill-color", "red", NULL); break; case DEMO_TEXT_ITEM: case DEMO_TEXT_ITEM_2: case DEMO_TEXT_ITEM_3: item = goo_canvas_text_new (table, text, 0, 0, width, GOO_CANVAS_ANCHOR_NW, "alignment", text_alignment, NULL); break; case DEMO_WIDGET_ITEM: widget = gtk_button_new_with_label (text); item = goo_canvas_widget_new (table, widget, 0, 0, -1, -1, NULL); break; } g_value_init (&value, G_TYPE_UINT); g_value_set_uint (&value, row); goo_canvas_item_set_child_property (table, item, "row", &value); g_value_set_uint (&value, column); goo_canvas_item_set_child_property (table, item, "column", &value); g_value_set_uint (&value, rows); goo_canvas_item_set_child_property (table, item, "rows", &value); g_value_set_uint (&value, columns); goo_canvas_item_set_child_property (table, item, "columns", &value); goo_canvas_item_set_child_properties (table, item, "x-expand", TRUE, "y-expand", TRUE, "x-align", xalign, "y-align", yalign, NULL); /* Test the get function. */ goo_canvas_item_get_child_property (table, item, "row", &value); new_row = g_value_get_uint (&value); if (new_row != row) g_warning ("Got bad row setting: %i should be: %i\n", new_row, row); /* If we make the item's fill the cells then alignment can't be used. */ #if 0 goo_canvas_item_set_child_properties (table, item, "x-fill", TRUE, "y-fill", TRUE, NULL); #endif g_object_set_data (G_OBJECT (item), "id", text); g_signal_connect (item, "button_press_event", G_CALLBACK (on_button_press), NULL); }
WireItem *wire_item_new (Sheet *sheet, Wire *wire) { GooCanvasItem *item; WireItem *wire_item; ItemData *item_data; GooCanvasPoints *points; WireItemPriv *priv; Coords start_pos, length; g_return_val_if_fail (sheet != NULL, NULL); g_return_val_if_fail (IS_SHEET (sheet), NULL); wire_get_pos_and_length (wire, &start_pos, &length); item = g_object_new (TYPE_WIRE_ITEM, NULL); g_object_set (item, "parent", sheet->object_group, NULL); wire_item = WIRE_ITEM (item); g_object_set (wire_item, "data", wire, NULL); priv = wire_item->priv; const int random_color_count = 9; const char *random_color[] = {"blue", "red", "green" /*, "yellow"*/, "orange", "brown", "purple", "pink", "lightblue", "lightgreen"}; priv->resize1 = GOO_CANVAS_RECT ( goo_canvas_rect_new (GOO_CANVAS_ITEM (wire_item), -RESIZER_SIZE, -RESIZER_SIZE, 2 * RESIZER_SIZE, 2 * RESIZER_SIZE, "stroke-color", oregano_options_debug_wires () ? random_color[g_random_int_range (0, random_color_count - 1)] : "blue", "fill-color", "green", "line-width", 1.0, NULL)); g_object_set (priv->resize1, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); priv->resize2 = GOO_CANVAS_RECT (goo_canvas_rect_new ( GOO_CANVAS_ITEM (wire_item), length.x - RESIZER_SIZE, length.y - RESIZER_SIZE, 2 * RESIZER_SIZE, 2 * RESIZER_SIZE, "stroke-color", oregano_options_debug_wires () ? random_color[g_random_int_range (0, random_color_count - 1)] : "blue", "fill-color", "green", "line-width", 1.0, NULL)); g_object_set (priv->resize2, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); points = goo_canvas_points_new (2); points->coords[0] = 0; points->coords[1] = 0; points->coords[2] = length.x; points->coords[3] = length.y; priv->line = GOO_CANVAS_POLYLINE (goo_canvas_polyline_new ( GOO_CANVAS_ITEM (wire_item), FALSE, 0, "points", points, "stroke-color", oregano_options_debug_wires () ? random_color[g_random_int_range (0, random_color_count - 1)] : "blue", "line-width", 1.0, "start-arrow", oregano_options_debug_wires () ? TRUE : FALSE, "end-arrow", oregano_options_debug_wires () ? TRUE : FALSE, NULL)); goo_canvas_points_unref (points); item_data = ITEM_DATA (wire); item_data->rotated_handler_id = g_signal_connect_object ( G_OBJECT (wire), "rotated", G_CALLBACK (wire_rotated_callback), G_OBJECT (wire_item), 0); item_data->flipped_handler_id = g_signal_connect_object ( G_OBJECT (wire), "flipped", G_CALLBACK (wire_flipped_callback), G_OBJECT (wire_item), 0); item_data->moved_handler_id = g_signal_connect_object ( G_OBJECT (wire), "moved", G_CALLBACK (wire_moved_callback), G_OBJECT (wire_item), 0); item_data->changed_handler_id = g_signal_connect_object ( G_OBJECT (wire), "changed", G_CALLBACK (wire_changed_callback), G_OBJECT (wire_item), 0); g_signal_connect (wire, "delete", G_CALLBACK (wire_delete_callback), wire_item); wire_update_bbox (wire); return wire_item; }
/* ==================================== */ static GooCanvasItem *superbrain_create_item(GooCanvasItem *parent) { int i, j; double x; double x1, x2; GooCanvasItem *item = NULL; Piece *piece = NULL; listPiecesClear(); if(current_y_position < SCROLL_LIMIT) { goo_canvas_item_translate(boardRootItem, 0.0, Y_STEP); } x = (BOARDWIDTH - number_of_piece*(PIECE_WIDTH*2+PIECE_GAP))/2 + PLAYING_AREA_X; /* Draw a line to separate cleanly */ x1 = x + PIECE_WIDTH; x2 = (BOARDWIDTH + (number_of_piece-1)*(PIECE_WIDTH*2+PIECE_GAP))/2 - PIECE_WIDTH + PLAYING_AREA_X; goo_canvas_polyline_new (boardRootItem, FALSE, 2, x1, current_y_position + PIECE_HEIGHT + PIECE_GAP/2, x2, current_y_position + PIECE_HEIGHT + PIECE_GAP/2, "stroke-color", "white", "line-width", 1.0, NULL); goo_canvas_polyline_new (boardRootItem, FALSE, 2, x1 + 2, current_y_position + PIECE_HEIGHT + PIECE_GAP/2 + 1, x2 + 2, current_y_position + PIECE_HEIGHT + PIECE_GAP/2 + 1, "stroke-color", "black", "line-width", 1.0, NULL); /* Continuing the line */ x1 = PLAYING_HELP_X; x2 = x1 + number_of_piece*PIECE_WIDTH; goo_canvas_polyline_new (boardRootItem, FALSE, 2, x1, current_y_position + PIECE_HEIGHT + PIECE_GAP/2, x2, current_y_position + PIECE_HEIGHT + PIECE_GAP/2, "stroke-color", "white", "line-width", 1.0, NULL); goo_canvas_polyline_new (boardRootItem, FALSE, 2, x1 + 2, current_y_position + PIECE_HEIGHT + PIECE_GAP/2 + 1, x2 + 2, current_y_position + PIECE_HEIGHT + PIECE_GAP/2 + 1, "stroke-color", "black", "line-width", 1.0, NULL); /* Draw the pieces */ for(i=0; i<number_of_piece; i++) { piece = g_new(Piece, 1); piece->listitem = NULL; listPieces = g_list_append(listPieces, piece); piece->rootitem = goo_canvas_group_new (parent, NULL); // Good piece->good = goo_canvas_rect_new (piece->rootitem, x + i*(PIECE_WIDTH*2 + PIECE_GAP) - PIECE_WIDTH - PIECE_GAP_GOOD, current_y_position - PIECE_HEIGHT - PIECE_GAP_GOOD, PIECE_WIDTH*2 + PIECE_GAP_GOOD*2, PIECE_HEIGHT*2 + PIECE_GAP_GOOD*2, "fill_color_rgba", COLOR_GOOD, "stroke-color", "white", "line-width", 1.0, "tooltip", _("This item is well placed"), NULL); g_object_set (piece->good, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); // Misplaced piece->misplaced = goo_canvas_rect_new (piece->rootitem, x + i*(PIECE_WIDTH*2 + PIECE_GAP) - PIECE_WIDTH - PIECE_GAP_GOOD, current_y_position - PIECE_HEIGHT - PIECE_GAP_GOOD, PIECE_WIDTH*2 + PIECE_GAP_GOOD*2, PIECE_HEIGHT*2 + PIECE_GAP_GOOD*2, "fill_color_rgba", COLOR_MISPLACED, "stroke-color", "black", "line-width", 1.0, "tooltip", _("This item is misplaced"), NULL); g_object_set (piece->misplaced, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); for(j=0; j<number_of_color; j++) { item = goo_canvas_ellipse_new (piece->rootitem, x + i*(PIECE_WIDTH*2 + PIECE_GAP), current_y_position, PIECE_WIDTH, PIECE_HEIGHT, "fill_color_rgba", colors[j], "stroke-color", "white", "line-width", (double)1, NULL); gc_item_focus_init(item, NULL); g_object_set (item, "visibility", GOO_CANVAS_ITEM_INVISIBLE, NULL); piece->listitem = g_list_append(piece->listitem, item); g_signal_connect(item, "button-press-event", (GCallback) item_event, piece); } piece->selecteditem = 0; item = g_list_nth_data(piece->listitem, piece->selecteditem); g_object_set (item, "visibility", GOO_CANVAS_ITEM_VISIBLE, NULL); } return NULL; }
GtkWidget * create_canvas_fifteen (void) { GtkWidget *vbox; GtkWidget *alignment; GtkWidget *frame; GtkWidget *canvas; GtkWidget *button; GooCanvasItem **board; GooCanvasItem *root, *rect, *text; int i, x, y; char buf[20]; vbox = gtk_vbox_new (FALSE, 4); gtk_container_set_border_width (GTK_CONTAINER (vbox), 4); gtk_widget_show (vbox); alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0); gtk_box_pack_start (GTK_BOX (vbox), alignment, TRUE, TRUE, 0); gtk_widget_show (alignment); frame = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN); gtk_container_add (GTK_CONTAINER (alignment), frame); gtk_widget_show (frame); /* Create the canvas and board */ canvas = goo_canvas_new (); g_object_set (G_OBJECT (canvas), "automatic-bounds", TRUE, "bounds-from-origin", FALSE, NULL); root = goo_canvas_get_root_item (GOO_CANVAS (canvas)); gtk_widget_set_size_request (canvas, PIECE_SIZE * 4 + 1, PIECE_SIZE * 4 + 1); #if 0 goo_canvas_set_bounds (GOO_CANVAS (canvas), 0, 0, PIECE_SIZE * 4 + 1, PIECE_SIZE * 4 + 1); #endif gtk_container_add (GTK_CONTAINER (frame), canvas); gtk_widget_show (canvas); board = g_new (GooCanvasItem *, 16); g_object_set_data (G_OBJECT (canvas), "board", board); g_signal_connect (canvas, "destroy", G_CALLBACK (free_stuff), board); for (i = 0; i < 15; i++) { y = i / 4; x = i % 4; board[i] = goo_canvas_group_new (root, NULL); goo_canvas_item_translate (board[i], x * PIECE_SIZE, y * PIECE_SIZE); setup_item_signals (board[i]); rect = goo_canvas_rect_new (board[i], 0, 0, PIECE_SIZE, PIECE_SIZE, "fill_color", get_piece_color (i), "stroke_color", "black", "line-width", 1.0, NULL); sprintf (buf, "%d", i + 1); text = goo_canvas_text_new (board[i], buf, PIECE_SIZE / 2.0, PIECE_SIZE / 2.0, -1, GTK_ANCHOR_CENTER, "font", "Sans bold 24", "fill_color", "black", NULL); g_object_set_data (G_OBJECT (board[i]), "text", text); g_object_set_data (G_OBJECT (board[i]), "piece_num", GINT_TO_POINTER (i)); g_object_set_data (G_OBJECT (board[i]), "piece_pos", GINT_TO_POINTER (i)); } board[15] = NULL; /* Scramble button */ button = gtk_button_new_with_label ("Scramble"); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); g_object_set_data (G_OBJECT (button), "board", board); g_signal_connect (button, "clicked", G_CALLBACK (scramble), canvas); gtk_widget_show (button); return vbox; }
static void display_files(GooCanvasItem *root_item, gchar *rootdir) { GooCanvasItem *item; const gchar *one_dirent; GDir *dir; /* Initial image position */ guint ix = 0.0; guint iy = 30.0; GtkWidget *w; GooCanvasItem *bg_item; GtkWidget *canvas; /* The scrolled part */ GList *dir_list = NULL; GList *file_list = NULL; GList *listrunner; GtkAdjustment *adj; if(!rootitem) return; /* Display the directory content */ dir = g_dir_open(rootdir, 0, NULL); if (!dir) { g_warning("gcompris_file_selector : no root directory found in %s", rootdir); g_free(rootdir); return; } /* Delete the previous file root if any */ if(file_root_item) goo_canvas_item_remove(file_root_item); /* Create a root item to put the image list in it */ file_root_item = goo_canvas_group_new (root_item, NULL); /* * Create the scrollbar * -------------------- */ canvas = goo_canvas_new(); goo_canvas_widget_new (file_root_item, canvas, DRAWING_AREA_X1, DRAWING_AREA_Y1, DRAWING_AREA_X2 - DRAWING_AREA_X1 - 20.0, DRAWING_AREA_Y2 - DRAWING_AREA_Y1 - 35.0, NULL); gtk_widget_show (canvas); /* Set the new canvas to the background color or it's white */ bg_item = goo_canvas_rect_new (goo_canvas_get_root_item(GOO_CANVAS(canvas)), 0, 0, DRAWING_AREA_X2 - DRAWING_AREA_X1 + 200, DRAWING_AREA_Y2 - DRAWING_AREA_Y1, "fill-color-rgba", gc_skin_get_color("gcompris/fileselectbg"), "line-width", 0.0, NULL); adj = \ GTK_ADJUSTMENT (gtk_adjustment_new (0.00, 0.00, IMAGE_HEIGHT, 10, IMAGE_HEIGHT, (DRAWING_AREA_Y2 - DRAWING_AREA_Y1)/3) ); w = gtk_vscrollbar_new (adj); goo_canvas_widget_new (file_root_item, w, DRAWING_AREA_X2 - 15.0, DRAWING_AREA_Y1, 30.0, DRAWING_AREA_Y2 - DRAWING_AREA_Y1 - 20.0, NULL); gtk_widget_show (w); /* Set the scrollwheel event */ g_signal_connect (adj, "value_changed", (GtkSignalFunc) item_event_scroll, canvas); /* Display the directory name * -------------------------- */ item = goo_canvas_text_new (file_root_item, rootdir, (gdouble)control_area_x1, (gdouble)directory_label_y, -1, GTK_ANCHOR_NW, "font", "Sans 7", "fill-color-rgba", gc_skin_get_color("gcompris/fileselectcol"), NULL); /* Insert all files in a sorted list */ while((one_dirent = g_dir_read_name(dir)) != NULL) { gchar *filename; filename = g_strdup_printf("%s/%s", rootdir, (gchar*)(one_dirent)); if(g_file_test(filename, G_FILE_TEST_IS_DIR)) { dir_list = g_list_insert_sorted(dir_list, filename, (GCompareFunc)strcmp); } else { file_list = g_list_insert_sorted(file_list, filename, (GCompareFunc)strcmp); } } /* Concat the directory list and file list */ file_list = g_list_concat(dir_list, file_list); g_list_free(dir_list); dir_list = NULL; /* We have the list sorted, now display it */ listrunner = g_list_first(file_list); while(listrunner) { /* add the file to the display */ gchar *svg_id; gchar *allfilename = listrunner->data; gchar *filename = g_path_get_basename(allfilename); gchar *ext = g_strrstr(filename, "."); gchar *file_wo_ext = g_strdup(filename); if(ext) { gchar *ext2 = g_strrstr(file_wo_ext, "."); *ext2 = '\0'; } if(g_file_test(allfilename, G_FILE_TEST_IS_DIR)) svg_id = "#FOLDER"; else svg_id = "#FILE"; item = goo_canvas_svg_new (goo_canvas_get_root_item(GOO_CANVAS(canvas)), gc_skin_rsvg_get(), "svg-id", svg_id, NULL); SET_ITEM_LOCATION_CENTER(item, ix + (IMAGE_WIDTH + IMAGE_GAP)/2, iy); if(g_file_test(allfilename, G_FILE_TEST_IS_DIR)) { g_signal_connect(item, "button_press_event", (GtkSignalFunc) item_event_directory, allfilename); } else { g_signal_connect(item, "button_press_event", (GtkSignalFunc) item_event_file_selector, allfilename); } gc_item_focus_init(item, NULL); g_object_set_data_full (G_OBJECT (item), "allfilename", allfilename, g_free); /* The type */ if(ext) { GooCanvasItem *_item = \ goo_canvas_text_new (goo_canvas_get_root_item(GOO_CANVAS(canvas)), ext, ix + (IMAGE_WIDTH + IMAGE_GAP)/2, iy + 10, -1, GTK_ANCHOR_CENTER, "font", "Sans 6", "fill-color-rgba", gc_skin_get_color("gcompris/fileselectcol"), NULL); g_signal_connect(_item, "button_press_event", (GtkSignalFunc) item_event_file_selector, allfilename); gc_item_focus_init(_item, item); } /* The filename */ GooCanvasItem *name_item = \ goo_canvas_text_new (goo_canvas_get_root_item(GOO_CANVAS(canvas)), file_wo_ext, ix + (IMAGE_WIDTH + IMAGE_GAP)/2, iy + IMAGE_HEIGHT - 30, -1, GTK_ANCHOR_CENTER, "font", "Sans 7", "fill-color-rgba", gc_skin_get_color("gcompris/fileselectcol"), NULL); g_free(file_wo_ext); g_free(filename); if(g_file_test(allfilename, G_FILE_TEST_IS_DIR)) { g_signal_connect(name_item, "button_press_event", (GtkSignalFunc) item_event_directory, allfilename); } else { g_signal_connect(name_item, "button_press_event", (GtkSignalFunc) item_event_file_selector, allfilename); } gc_item_focus_init(name_item, item); ix += IMAGE_WIDTH + IMAGE_GAP; if(ix >= DRAWING_AREA_X2 - DRAWING_AREA_X1 - (IMAGE_WIDTH + IMAGE_GAP) ) { ix=0; iy+=IMAGE_HEIGHT + IMAGE_GAP; goo_canvas_set_bounds (GOO_CANVAS(canvas), 0, 0, DRAWING_AREA_X2- DRAWING_AREA_X1, iy + IMAGE_HEIGHT + IMAGE_GAP); if(iy >= DRAWING_AREA_Y2-DRAWING_AREA_Y1) { g_object_set(bg_item, "height", (double)iy + IMAGE_HEIGHT + IMAGE_GAP, NULL); g_object_set(adj, "upper", (double)iy - IMAGE_HEIGHT + IMAGE_GAP - 1, NULL); } } listrunner = g_list_next(listrunner); } g_dir_close(dir); g_list_free(file_list); }
/* ==================================== */ static GooCanvasItem * hanoi_create_item(GooCanvasItem *parent) { int i,j; double gap_x, gap_y; double baseline; GooCanvasItem *item = NULL; guint color_to_place; guint used_colors[NUMBER_OF_COLOR]; guint w; boardRootItem = \ goo_canvas_group_new (parent, NULL); if (gcomprisBoard->level == 1) { item = goo_canvas_svg_new (boardRootItem, gc_skin_rsvg_get(), "svg-id", "#BAR_BG", NULL); SET_ITEM_LOCATION_CENTER(item, BOARDWIDTH/2, 50); goo_canvas_text_new (boardRootItem, _("Build the same tower in the empty area as the one you see on the right-hand side."), BOARDWIDTH/2, 50, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_medium, "fill_color_rgba", gc_skin_color_text_button, NULL); } /*----------------------------------------*/ /* Empty the solution */ for(i=0; i<(number_of_item_x+2); i++) { for(j=0; j<number_of_item_y; j++) { position[i][j] = g_malloc(sizeof(PieceItem)); position[i][j]->color = -1; position[i][j]->i = i; position[i][j]->j = j; position[i][j]->on_top = FALSE; } } /* Clear the used colors list */ for(i=0; i<NUMBER_OF_COLOR; i++) used_colors[i] = FALSE; /* Initialize a random goal and store the color index in position[number_of_item_x] */ for(i=0; i<(number_of_item_y); i++) { guint color = (guint)g_random_int_range(0, NUMBER_OF_COLOR-1); position[number_of_item_x+1][i]->color = color; used_colors[color] = TRUE; } /* Randomly place the solution */ for (color_to_place=0; color_to_place<number_of_item_y; color_to_place++) { gboolean done; do { done = FALSE; i = (guint)g_random_int_range(0, number_of_item_x); /* Restrict the goal to lowest items */ j = (guint)g_random_int_range(0, 2); if(position[i][j]->color == -1) { done = TRUE; position[i][j]->color = position[number_of_item_x+1][color_to_place]->color; } } while(!done); } /* Initialize the left open positions */ for(i=0; i<(number_of_item_x); i++) { for(j=0; j<number_of_item_y-1; j++) { if(position[i][j]->color == -1) { /* Take only a color that is not part of the goal */ guint color = (guint)g_random_int_range(0, NUMBER_OF_COLOR-1); while(used_colors[color]) { color++; if(color >= NUMBER_OF_COLOR) color = 0; } position[i][j]->color = color; } } } //dump_solution(); /* Mark the top pieces */ for(i=0; i<(number_of_item_x); i++) { position[i][number_of_item_y-2]->on_top = TRUE; } /*----------------------------------------*/ /* Display it now */ item_width = BOARDWIDTH / (number_of_item_x + 2); item_height = 30; gap_x = item_width * 0.1; gap_y = item_height * 0.25; baseline = BOARDHEIGHT/2 + item_height * number_of_item_y/2; number_of_item = 0; for(i=0; i<(number_of_item_x+2); i++) { if(i == number_of_item_x+1) { /* Create the backgound for the target */ goo_canvas_rect_new (boardRootItem, item_width * i + gap_x/2, baseline - item_height * number_of_item_y - gap_y - 50, item_width - gap_x, item_height * number_of_item_y + gap_y*2 + 100, "fill_color_rgba", 0x036ED8FF, "stroke-color", "black", "line-width", (double)1, NULL); } else if (i == number_of_item_x) { /* Create the backgound for the empty area */ goo_canvas_rect_new (boardRootItem, item_width * i + gap_x/2, baseline - item_height * number_of_item_y - gap_y - 50, item_width - gap_x, item_height * number_of_item_y + gap_y*2 + 100, "fill_color_rgba", 0x48AAF1FF, "stroke-color", "black", "line-width", (double)1, NULL); } /* Create the vertical line */ w = 10; goo_canvas_rect_new (boardRootItem, item_width * i + item_width/2 - w, baseline - item_height * number_of_item_y - gap_y, w*2, (item_height + gap_y/2 - 2) * number_of_item_y, "fill_color_rgba", 0xFF1030FF, "stroke-color", "black", "line-width", (double)1, NULL); /* And the base line */ item = goo_canvas_path_new (boardRootItem, "M 43,19 A 22,20 0 1 1 -1,19 L 20,19 z", "fill_color_rgba", 0xFF1030FF, "stroke-color", "black", "line-width", 1.0, NULL); goo_canvas_item_translate(item, item_width * i + item_width/2 - 20, baseline - 25); for(j=0; j<number_of_item_y; j++) { position[i][j]->x = item_width * i + gap_x; position[i][j]->y = baseline - item_height * j - item_height + gap_y; if(position[i][j]->color != -1) { char car[2]; GooCanvasItem *group = goo_canvas_group_new(boardRootItem, NULL); goo_canvas_item_translate(group, position[i][j]->x, position[i][j]->y); position[i][j]->group = group; item = goo_canvas_rect_new (group, 0, 0, item_width - gap_x * 2, item_height - gap_y, "fill_color_rgba", colorlist[position[i][j]->color], "stroke-color", "black", "line-width", (double)1, NULL); car[0] = symbollist[position[i][j]->color]; car[1] = '\0'; goo_canvas_text_new (group, (char *)car, 20, 0, -1, GTK_ANCHOR_NORTH, "font", "sans bold 14", "fill-color", "white", NULL); if(i != number_of_item_x+1) { g_signal_connect(item, "button_press_event", (GCallback)gc_drag_event, position[i][j]); g_signal_connect(item, "button_release_event", (GCallback)gc_drag_event, position[i][j]); g_signal_connect(item, "enter_notify_event", (GCallback) item_event, position[i][j]); g_signal_connect(item, "leave_notify_event", (GCallback) item_event, position[i][j]); } } } } return NULL; }