コード例 #1
0
ファイル: part-browser.c プロジェクト: hriesz/oregano-old
// part_browser_create
//
// Creates a new part browser. This is only called once per schematic window.
GtkWidget *
part_browser_create (SchematicView *schematic_view)
{
	Browser *br;
	GtkBuilder *gui;
	GError *perror = NULL;
	char *msg;
	GtkWidget *w, *view;
	GtkCellRenderer *cell_text;
	GtkTreeViewColumn *cell_column;
	static GtkTargetEntry dnd_types[] =
		{ { "x-application/oregano-part", 0, DRAG_PART_INFO } };

	static int dnd_num_types = sizeof (dnd_types) / sizeof (dnd_types[0]);
	GtkTreePath *path;

	if ((gui = gtk_builder_new ()) == NULL) {
		oregano_error (_("Could not create part browser"));
		return NULL;
	} 
	else 
		gtk_builder_set_translation_domain (gui, NULL);

	br = g_new0 (Browser, 1);
	br->preview = NULL;
	br->schematic_view = schematic_view;
	br->hidden = FALSE;

	schematic_view_set_browser (schematic_view, br);

	if (gtk_builder_add_from_file (gui, OREGANO_UIDIR "/part-browser.ui", 
	    &perror) <= 0) {
		msg = perror->message;
		oregano_error_with_title (_("Could not create part browser"), msg);
		g_error_free (perror);
		return NULL;
	}

	view = GTK_WIDGET (gtk_builder_get_object (gui, "viewport1"));
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (view), 
	    GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

	gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (view),
	                                            115);
	
	w = goo_canvas_new ();
	gtk_container_add (GTK_CONTAINER (view), GTK_WIDGET (w));
	
	br->canvas = w;

	g_signal_connect (w, "realize", (GCallback) preview_realized, br);

	//gtk_widget_set_size_request (w, PREVIEW_WIDTH,
	//	PREVIEW_HEIGHT + PREVIEW_TEXT_HEIGHT);
	goo_canvas_set_bounds (GOO_CANVAS (w), 0, 0, PREVIEW_WIDTH,
		(PREVIEW_HEIGHT + PREVIEW_TEXT_HEIGHT));

	br->description = GOO_CANVAS_TEXT (goo_canvas_text_new (
	           goo_canvas_get_root_item (GOO_CANVAS (br->canvas)), 
	           "", 0.0, PREVIEW_HEIGHT - 9.0, 100.0, GOO_CANVAS_ANCHOR_NORTH_WEST,
	           "font", "sans 9", 
	           NULL));  

	// Set up dnd. 
	g_signal_connect (G_OBJECT (br->canvas), "drag_data_get",
		G_CALLBACK (drag_data_get), br);

	gtk_drag_source_set (br->canvas, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
		dnd_types, dnd_num_types, GDK_ACTION_MOVE);

	br->filter_entry = GTK_ENTRY (gtk_builder_get_object (gui, "part_search"));

	g_signal_connect (G_OBJECT (br->filter_entry), "changed",
		G_CALLBACK (part_search_change), br);
	g_signal_connect (G_OBJECT (br->filter_entry), "activate",
		G_CALLBACK (part_search_activate), br);

	// Buttons. 
	w = GTK_WIDGET (gtk_builder_get_object (gui, "place_button"));
	g_signal_connect (G_OBJECT (w), "clicked",
		G_CALLBACK (place_cmd), br);

	// Update the libraries option menu 
	br->library = g_list_nth_data (oregano.libraries, 0);
	part_browser_setup_libs (br, gui);

	// Parts list. 
	w = GTK_WIDGET (gtk_builder_get_object (gui, "parts_list"));
	br->list = w;

	// Create the List Model for TreeView, this is a Real model 
	br->real_model = GTK_TREE_MODEL (gtk_list_store_new (1, G_TYPE_STRING));
	cell_text = gtk_cell_renderer_text_new ();
	cell_column = gtk_tree_view_column_new_with_attributes (
		"", cell_text, 
	    "text", 0,
	    NULL);

	// Create the sort model for the items, this sort the real model 
	br->sort_model = gtk_tree_model_sort_new_with_model (
		GTK_TREE_MODEL (br->real_model));

	gtk_tree_sortable_set_sort_column_id (
		GTK_TREE_SORTABLE (br->sort_model),
		0, GTK_SORT_ASCENDING);

	// Create the filter sorted model. This filter items based on user
	//   request for fast item search 
	br->filter_model = gtk_tree_model_filter_new (br->sort_model, NULL);
	gtk_tree_model_filter_set_visible_func (
		GTK_TREE_MODEL_FILTER (br->filter_model),
		part_list_filter_func, br, NULL);

	// If we have TreeFilter use it, if not, just use sorting model only 
	if (br->filter_model)
		gtk_tree_view_set_model (GTK_TREE_VIEW (w), br->filter_model);
	else
		gtk_tree_view_set_model (GTK_TREE_VIEW (w), br->sort_model);

	gtk_tree_view_append_column (GTK_TREE_VIEW (w), cell_column);
	update_list (br);

	// Set up TreeView dnd.
	g_signal_connect (G_OBJECT (w), "drag_data_get",
		G_CALLBACK (drag_data_get), br);

	gtk_drag_source_set (w, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
		dnd_types, dnd_num_types, GDK_ACTION_MOVE);

	g_signal_connect (G_OBJECT (w), "cursor_changed", 
		G_CALLBACK (select_row), br);
	g_signal_connect (G_OBJECT (w), "row_activated", 
	    G_CALLBACK (part_selected), br);

	br->viewport = GTK_WIDGET (gtk_builder_get_object (gui, 
	    "part_browser_vbox"));

	path = gtk_tree_path_new_first ();
	gtk_tree_view_set_cursor (GTK_TREE_VIEW (w), path, NULL, FALSE);
	gtk_tree_path_free (path);

	gtk_widget_unparent (br->viewport);
	return br->viewport;
}
コード例 #2
0
ファイル: memory.c プロジェクト: MkPereira/gcompris
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);
}