static void display_welcome (MenuItems *menuitems) { GooCanvasItem *item; RsvgHandle *svg_handle; if (actualSectionItem) g_error("actualSectionItem exists in display_section !"); actualSectionItem = goo_canvas_group_new(boardRootItem, NULL); svg_handle = gc_skin_rsvg_get(); item = goo_canvas_svg_new (actualSectionItem, svg_handle, "svg-id", "#LOGO", NULL); SET_ITEM_LOCATION_CENTER(item, display_x + display_w/2.0, display_y + display_h/3.0); display_sponsor(actualSectionItem); g_signal_connect (item, "enter_notify_event", (GCallback) display_welcome_event, menuitems); g_signal_connect (item, "leave_notify_event", (GCallback) on_leave_notify, menuitems); menu_displayed = TRUE; }
static void display_sponsor(GooCanvasItem *rootitem) { GooCanvasItem *item; GdkPixbuf *pixmap = NULL; /* Location for a potential sponsor */ gchar *sponsor_image = gc_file_find_absolute("sponsor.png"); if(sponsor_image) { pixmap = gc_pixmap_load("sponsor.png"); item = goo_canvas_image_new (rootitem, pixmap, 0.0, 0.0, NULL); SET_ITEM_LOCATION_CENTER(item, display_x + display_w/2.0, display_y + display_h/3.0 + 150); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif g_free(sponsor_image); } }
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); }
void create_mainwindow (GooCanvasItem *rootitem) { GtkWidget *wdrawareagrande; GtkWidget *wdrawareapetite; /* GCompris : suppression of all menus */ g_assert(rootitem != NULL); wdrawareagrande = gtk_drawing_area_new (); gtk_widget_set_name (wdrawareagrande, "wdrawareagrande"); //gtk_widget_set_size_request (wdrawareagrande, // WIDTH_BIGAREA, // WIDTH_BIGAREA // ); //gtk_container_add (GTK_CONTAINER (aspectframe1), wdrawareagrande); gtk_widget_set_events (wdrawareagrande, GDK_EXPOSURE_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_STRUCTURE_MASK); /* Gcompris */ goo_canvas_widget_new ( rootitem, wdrawareagrande, X_BASE_BIGAREA, Y_BASE_BIGAREA, WIDTH_BIGAREA, WIDTH_BIGAREA, NULL ); gtk_widget_show (wdrawareagrande); wdrawareapetite = gtk_drawing_area_new (); gtk_widget_set_name (wdrawareapetite, "wdrawareapetite"); gtk_widget_set_events (wdrawareapetite, GDK_EXPOSURE_MASK | GDK_STRUCTURE_MASK); /* Gcompris */ goo_canvas_widget_new ( rootitem, wdrawareapetite, X_BASE_SMALLAREA, Y_BASE_SMALLAREA, WIDTH_SMALLAREA, WIDTH_SMALLAREA, NULL ); gtk_widget_show (wdrawareapetite); g_signal_connect (GTK_OBJECT (wdrawareagrande), "expose_event", GTK_SIGNAL_FUNC (on_wdrawareagrande_expose_event), NULL); g_signal_connect (GTK_OBJECT (wdrawareagrande), "configure_event", GTK_SIGNAL_FUNC (on_wdrawareagrande_configure_event), NULL); g_signal_connect (GTK_OBJECT (wdrawareagrande), "button_press_event", GTK_SIGNAL_FUNC (on_wdrawareagrande_button_press_event), NULL); g_signal_connect (GTK_OBJECT (wdrawareagrande), "button_release_event", GTK_SIGNAL_FUNC (on_wdrawareagrande_button_release_event), NULL); g_signal_connect (GTK_OBJECT (wdrawareagrande), "motion_notify_event", GTK_SIGNAL_FUNC (on_wdrawareagrande_motion_notify_event), NULL); g_signal_connect (GTK_OBJECT (wdrawareapetite), "configure_event", GTK_SIGNAL_FUNC (on_wdrawareapetite_configure_event), NULL); g_signal_connect (GTK_OBJECT (wdrawareapetite), "expose_event", GTK_SIGNAL_FUNC (on_wdrawareapetite_expose_event), NULL); /* Gcompris */ /* add here buttons */ GdkPixbuf *pixmap_show = NULL; GdkPixbuf *pixmap_outline = NULL; GdkPixbuf *pixmap_symetry = NULL; GooCanvasItem *previous_figure, *next_figure; GooCanvasItem *show_figure, *outline_figure, *symetry; previous_figure = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", "#PREVIOUS", NULL); SET_ITEM_LOCATION_CENTER(previous_figure, X_BASE_SMALLAREA, Y_BASE_SMALLAREA + WIDTH_SMALLAREA + 30); next_figure = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", "#NEXT", NULL); SET_ITEM_LOCATION_CENTER(next_figure, X_BASE_SMALLAREA + WIDTH_SMALLAREA, Y_BASE_SMALLAREA + WIDTH_SMALLAREA + 30); g_signal_connect(previous_figure, "button_press_event", (GtkSignalFunc) on_arrow_clicked, (gpointer) FALSE); gc_item_focus_init(previous_figure, NULL); g_signal_connect(next_figure, "button_press_event", (GtkSignalFunc) on_arrow_clicked, (gpointer) TRUE); gc_item_focus_init(next_figure, NULL); pixmap_show = gc_pixmap_load("tangram/gtans_show.png"); pixmap_outline = gc_pixmap_load("tangram/gtans_outline.png"); show_figure = goo_canvas_image_new (rootitem, pixmap_show, X_BASE_SMALLAREA, Y_BASE_SMALLAREA + WIDTH_SMALLAREA + 80, NULL); outline_figure = goo_canvas_image_new (rootitem, pixmap_outline, X_BASE_SMALLAREA, Y_BASE_SMALLAREA + WIDTH_SMALLAREA + 130, NULL); g_signal_connect(outline_figure, "button_press_event", (GtkSignalFunc) on_outline_clicked, NULL); g_signal_connect(show_figure, "button_press_event", (GtkSignalFunc) on_show_clicked, NULL); gc_item_focus_init(outline_figure, NULL); gc_item_focus_init(show_figure, NULL); pixmap_symetry = gc_pixmap_load("tangram/tool-flip.png"); symetry = goo_canvas_image_new (rootitem, pixmap_symetry, X_BASE_SMALLAREA + WIDTH_SMALLAREA - 50, Y_BASE_SMALLAREA + WIDTH_SMALLAREA + 180, NULL); g_signal_connect(symetry, "button_press_event", (GtkSignalFunc) on_symetry_clicked, NULL); gc_item_focus_init(symetry, NULL); /* rotation buttons */ GdkPixbuf *right_rot = NULL; GdkPixbuf *left_rot = NULL; GdkPixbuf *right_rot_big = NULL; GdkPixbuf *left_rot_big = NULL; GooCanvasItem *l_rot_s, *r_rot_s, *l_rot_b, *r_rot_b; right_rot = gc_pixmap_load("tangram/gtans_rotate.png"); left_rot = gc_pixmap_load("tangram/gtans_rotate-left.png"); r_rot_s = goo_canvas_image_new (rootitem, right_rot, X_BASE_SMALLAREA + WIDTH_SMALLAREA, Y_BASE_SMALLAREA + WIDTH_SMALLAREA + 60, NULL); l_rot_s = goo_canvas_image_new (rootitem, left_rot, X_BASE_SMALLAREA + WIDTH_SMALLAREA - 100, Y_BASE_SMALLAREA + WIDTH_SMALLAREA + 60, NULL); gdk_pixbuf_unref(right_rot); gdk_pixbuf_unref(left_rot); right_rot_big = gc_pixmap_load("tangram/gtans_2x-rotate.png"); left_rot_big = gc_pixmap_load("tangram/gtans_2x-rotate-left.png"); r_rot_b = goo_canvas_image_new (rootitem, right_rot_big, X_BASE_SMALLAREA + WIDTH_SMALLAREA, Y_BASE_SMALLAREA + WIDTH_SMALLAREA + 120, NULL); l_rot_b = goo_canvas_image_new (rootitem, left_rot_big, X_BASE_SMALLAREA + WIDTH_SMALLAREA - 100, Y_BASE_SMALLAREA + WIDTH_SMALLAREA + 120, NULL); gdk_pixbuf_unref(right_rot_big); gdk_pixbuf_unref(left_rot_big); g_signal_connect(r_rot_s, "button_press_event", (GtkSignalFunc) on_rotation_clicked, (gpointer) 0); gc_item_focus_init(r_rot_s, NULL); g_signal_connect(l_rot_s, "button_press_event", (GtkSignalFunc) on_rotation_clicked, (gpointer) 1); gc_item_focus_init(l_rot_s, NULL); g_signal_connect(r_rot_b, "button_press_event", (GtkSignalFunc) on_rotation_clicked, (gpointer) 2); gc_item_focus_init(r_rot_b, NULL); g_signal_connect(l_rot_b, "button_press_event", (GtkSignalFunc) on_rotation_clicked, (gpointer) 3); gc_item_focus_init(l_rot_b, NULL); }
void scale_anim_plate(void) { double delta_y; double angle; double scale; int diff; // in MODE_WEIGHT the granularity is gramm, so we use a different factor scale = (board_mode == MODE_WEIGHT) ? 2000.0 : 10.0; diff = get_weight_plate(0); delta_y = CLAMP(PLATE_Y_DELTA / scale * diff, -PLATE_Y_DELTA, PLATE_Y_DELTA); if(get_weight_plate(1) == 0) delta_y = -PLATE_Y_DELTA; /* Update the sign */ if (diff == 0) g_object_set(sign, "text", "=", NULL); else if (diff < 0) g_object_set(sign, "text", "<", NULL); else g_object_set(sign, "text", ">", NULL); if(last_delta != delta_y) { goo_canvas_item_translate(group_g, 0, -last_delta); goo_canvas_item_translate(group_d, 0, last_delta); last_delta = delta_y; angle = tan(delta_y / 138) * 180 / M_PI; goo_canvas_item_translate(group_g, 0, delta_y); goo_canvas_item_translate(group_d, 0, -delta_y); gc_item_rotate_with_center(bras, -angle, 138, 84); } if(diff == 0 && ask_for_answer) { double x_offset = BOARDWIDTH/2; double y_offset = BOARDHEIGHT*0.7; GooCanvasItem *item = goo_canvas_svg_new (boardRootItem, gc_skin_rsvg_get(), "svg-id", "#BUTTON_TEXT", NULL); SET_ITEM_LOCATION_CENTER(item, x_offset / 2, y_offset); goo_canvas_item_scale(item, 2, 1); answer_item = goo_canvas_text_new(boardRootItem, "", x_offset, y_offset, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_board_title_bold, "fill-color", "white", NULL); answer_string = g_string_new(NULL); key_press(0, NULL, NULL); } else if(diff == 0) process_ok(); }
static void display_confirm(gchar *title, gchar *question_text, gchar *yes_text, gchar *no_text, ConfirmCallBack iscb) { if(rootitem) return; bg_x = BG_X; bg_y = BG_Y; titre_x = T_X; titre_w = T_W; titre_y = T_Y;; titre_h = T_H; text_zone_x = T_Z_X; text_zone_w = T_Z_W; text_zone_y = T_Z_Y; text_zone_h = T_Z_H; button_x = T_B_X; button_w = T_B_W; button_y = T_B_Y; button_h = T_B_Y; button_x_int = T_B_X_INT; gc_bar_hide(TRUE); gc_board_pause(TRUE); confirmCallBack=iscb; rootitem = goo_canvas_group_new (goo_canvas_get_root_item(gc_get_canvas()), NULL); goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", "#DIALOG", "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); /* Title */ goo_canvas_text_new (rootitem, title, titre_x + titre_w/2, titre_y + titre_h/2, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_title, "fill-color-rgba", gc_skin_color_title, NULL); text = goo_canvas_text_new (rootitem, question_text, text_zone_x, text_zone_y, 500, GTK_JUSTIFY_CENTER, "font", gc_skin_font_title, "fill-color-rgba", gc_skin_color_title, NULL); /* * Buttons * ------- */ GooCanvasBounds bounds; // CANCEL no_button = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", "#BUTTON_TEXT", NULL); goo_canvas_item_get_bounds(no_button, &bounds); gint button_width = bounds.x2 - bounds.x1; button_x += button_width / 2; SET_ITEM_LOCATION_CENTER(no_button, button_x, button_y + 2*button_h/3); g_signal_connect(no_button, "button_press_event", (GtkSignalFunc) button_event, "/no/"); gc_item_focus_init(no_button, NULL); // CANCEL CROSS no_cross = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", "#UNCHECKED", NULL); SET_ITEM_LOCATION_CENTER(no_cross, button_x , button_y + 2*button_h/3); g_signal_connect(no_cross, "button_press_event", (GtkSignalFunc) button_event, "/no/"); gc_item_focus_init(no_cross, no_button); goo_canvas_text_new (rootitem, no_text, (gdouble) button_x + button_width/2 + button_x_int , (gdouble) button_y + 2*button_h/3, -1, GTK_ANCHOR_WEST, "font", gc_skin_font_subtitle, "fill-color-rgba", gc_skin_get_color("gcompris/helpfg"), NULL); // OK yes_button = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", "#BUTTON_TEXT", NULL); SET_ITEM_LOCATION_CENTER(yes_button, button_x , button_y + button_h/3); g_signal_connect(yes_button, "button_press_event", (GtkSignalFunc) button_event, "/yes/"); gc_item_focus_init(yes_button, NULL); // OK stick yes_stick = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", "#CHECKED", NULL); SET_ITEM_LOCATION_CENTER(yes_stick, button_x , button_y + button_h/3); g_signal_connect(yes_stick, "button_press_event", (GtkSignalFunc) button_event, "/yes/"); gc_item_focus_init(yes_stick, yes_button); goo_canvas_text_new (rootitem, yes_text, (gdouble) button_x + button_width/2 + button_x_int , (gdouble) button_y + button_h/3, -1, GTK_ANCHOR_WEST, "font", gc_skin_font_subtitle, "fill-color-rgba", gc_skin_get_color("gcompris/helpfg"), NULL); confirm_displayed = TRUE; }
/* * Do all the bar display and register the events */ void gc_about_start () { GdkPixbuf *pixmap = NULL; gdouble y_start = 0; gint y = 0; GooCanvasItem *item; static gchar *content = N_("Author: Bruno Coudoin\n" "Contribution: Pascal Georges, Jose Jorge, Yves Combe\n" "Graphics: Renaud Blanchard, Franck Doucet\n" "Intro Music: Djilali Sebihi\n" "Background Music: Rico Da Halvarez\n" ); /* TRANSLATORS: Replace this string with your names, one name per line. */ gchar *translators = _("translator_credits"); /* Pause the board */ gc_board_pause(TRUE); if(rootitem) { gc_about_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); y_start = bounds.y1; y = bounds.y2 - 26; goo_canvas_text_new (rootitem, _("About GCompris"), (gdouble) BOARDWIDTH/2, (gdouble) y_start + 35, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_title, "fill-color-rgba", gc_skin_color_title, NULL); goo_canvas_text_new (rootitem, _("GCompris Home Page: http://gcompris.net"), (gdouble) BOARDWIDTH/2, (gdouble) y_start + 58, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_color_subtitle, NULL); gchar *text = g_strdup_printf("%s\n%s\n%s", _(content), _("Translators:"), translators); y_start += 100; goo_canvas_text_new (rootitem, text, (gdouble) BOARDWIDTH/2-320, (gdouble) y_start, -1, GTK_ANCHOR_NORTH_WEST, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_color_content, NULL); g_free(text); // Version item = \ goo_canvas_text_new (rootitem, "GCompris V" VERSION, (gdouble) 0, (gdouble) y_start, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_title, "fill-color-rgba", gc_skin_color_subtitle, NULL); goo_canvas_item_get_bounds(item, &bounds); gdouble x = BOARDWIDTH - (bounds.x2 - bounds.x1) - 20; g_object_set( (GooCanvasItem*)item, "x", x, NULL); y_start += 180; /* Location for a potential sponsor */ gchar *sponsor_image = gc_file_find_absolute("sponsor_about.png"); if(sponsor_image) { pixmap = gc_pixmap_load("sponsor_about.png"); goo_canvas_text_new (rootitem, "Version parrainée par", (gdouble) BOARDWIDTH*0.75, (gdouble) y_start - gdk_pixbuf_get_height(pixmap), -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_color_content, NULL); item = goo_canvas_image_new (rootitem, pixmap, (gdouble) (BOARDWIDTH*0.75) - gdk_pixbuf_get_width(pixmap)/2, (gdouble) y_start - gdk_pixbuf_get_height(pixmap) + 15, NULL); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif g_free(sponsor_image); } else { // Default sponsor is the FSF RsvgHandle *svg_handle; svg_handle = gc_skin_rsvg_get(); item = goo_canvas_svg_new (rootitem, svg_handle, "svg-id", "#FSF_LOGO", "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); goo_canvas_item_get_bounds(item, &bounds); SET_ITEM_LOCATION_CENTER(item, (BOARDWIDTH*0.75), y_start + 50 - (bounds.y2 - bounds.y1) / 2); item = goo_canvas_text_new (rootitem, "Free Software Foundation\nhttp://www.fsf.org", (gdouble) (BOARDWIDTH*0.75), (gdouble) y_start + 80, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_color_subtitle, NULL); } // Copyright item = goo_canvas_text_new (rootitem, "Copyright 2000-2013 Bruno Coudoin and Others", (gdouble) BOARDWIDTH/2, (gdouble) y - 55, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_color_content, NULL); // License item = goo_canvas_text_new (rootitem, _("This software is a GNU Package and is released under the GNU General Public License"), (gdouble) BOARDWIDTH/2, (gdouble) y - 40, -1, GTK_ANCHOR_CENTER, "font", "sans 8", "fill-color-rgba", gc_skin_color_content, NULL); // OK gc_util_button_text_svg(rootitem, BOARDWIDTH * 0.5, y, "#BUTTON_TEXT", _("OK"), (GCallback) item_event_ok, "ok"); is_displayed = TRUE; }
/* ==================================== */ 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; }