Example #1
0
static int
gnomecanvaspoints_to_value(GValue *value, PyObject *object)
{
    GnomeCanvasPoints *points;
    gint i, len;

    if (!PySequence_Check(object))
        return -1;
    len = PySequence_Length(object);
    if (len % 2 != 0)
        return -1;

    points = gnome_canvas_points_new(len / 2);
    for (i = 0; i < len; i++) {
        PyObject *item = PySequence_GetItem(object, i);

        points->coords[i] = PyFloat_AsDouble(item);
        if (PyErr_Occurred()) {
            gnome_canvas_points_unref(points);
            PyErr_Clear();
            Py_DECREF(item);
            return -1;
        }
        Py_DECREF(item);
    }
    g_value_set_boxed(value, points);
    gnome_canvas_points_unref(points);
    return 0;
}
Example #2
0
static void
wire_changed_callback (Wire *wire, WireItem *item)
{
	SheetPos start_pos, length;
	GnomeCanvasPoints *points;

	wire_get_pos_and_length (wire, &start_pos, &length);

	points = gnome_canvas_points_new (2);
	points->coords[0] = 0;
	points->coords[1] = 0;
	points->coords[2] = length.x;
	points->coords[3] = length.y;

	gnome_canvas_item_set (GNOME_CANVAS_ITEM (item->priv->line),
		"points", points,
		NULL);
	gnome_canvas_points_unref (points);

	gnome_canvas_item_set (GNOME_CANVAS_ITEM (item->priv->resize1),
		"x1", -RESIZER_SIZE,
		"y1", -RESIZER_SIZE,
		"x2", RESIZER_SIZE,
		"y2", RESIZER_SIZE,
		NULL);

	gnome_canvas_item_set (GNOME_CANVAS_ITEM (item->priv->resize2),
		"x1", length.x-RESIZER_SIZE,
		"y1", length.y-RESIZER_SIZE,
		"x2", length.x+RESIZER_SIZE,
		"y2", length.y+RESIZER_SIZE,
		NULL);
}
Example #3
0
/* Goes through all known links and checks whether there already exists
 * a corresponding canvas_link. If not, create it.*/
static gint
check_new_link (link_id_t * link_id, link_t * link, GtkWidget * canvas)
{
  canvas_link_t *new_canvas_link;
  GnomeCanvasGroup *group;
  GnomeCanvasPoints *points;
  guint i = 0;

  if (!g_tree_lookup (canvas_links, link_id))
    {
      group = gnome_canvas_root (GNOME_CANVAS (canvas));

      new_canvas_link = g_malloc (sizeof (canvas_link_t));
      g_assert(new_canvas_link);
      new_canvas_link->canvas_link_id = *link_id;

      /* We set the lines position using groups positions */
      points = gnome_canvas_points_new (3);

      for (; i <= 5; i++)
	points->coords[i] = 0.0;

      new_canvas_link->src_item
	= gnome_canvas_item_new (group,
				 gnome_canvas_polygon_get_type (),
				 "points", points, "fill_color", "tan", NULL);
      addref_canvas_obj(G_OBJECT (new_canvas_link->src_item));

      new_canvas_link->dst_item
	= gnome_canvas_item_new (group,
				 gnome_canvas_polygon_get_type (),
				 "points", points, "fill_color", "tan", NULL);
      addref_canvas_obj(G_OBJECT (new_canvas_link->dst_item));

      g_tree_insert (canvas_links,
		     &new_canvas_link->canvas_link_id, new_canvas_link);
      gnome_canvas_item_lower_to_bottom (new_canvas_link->src_item);
      gnome_canvas_item_lower_to_bottom (new_canvas_link->dst_item);

      gnome_canvas_points_unref (points);

      g_signal_connect (G_OBJECT (new_canvas_link->src_item), "event",
			(GtkSignalFunc) link_item_event, new_canvas_link);
      g_signal_connect (G_OBJECT (new_canvas_link->dst_item), "event",
			(GtkSignalFunc) link_item_event, new_canvas_link);

    }

  return FALSE;
}				/* check_new_link */
Example #4
0
static void
wire_rotated_callback (ItemData *data, int angle, SheetItem *sheet_item)
{
	WireItem *wire_item;
	GnomeCanvasPoints *points;
	SheetPos start_pos, length;

	g_return_if_fail (sheet_item != NULL);
	g_return_if_fail (IS_WIRE_ITEM (sheet_item));

	wire_item = WIRE_ITEM (sheet_item);

	wire_get_pos_and_length (WIRE (data), &start_pos, &length);

	points = gnome_canvas_points_new (2);
	points->coords[0] = 0;
	points->coords[1] = 0;
	points->coords[2] = length.x;
	points->coords[3] = length.y;

	gnome_canvas_item_set (GNOME_CANVAS_ITEM (wire_item->priv->line),
		"points", points,
		NULL);
	gnome_canvas_points_unref (points);

	gnome_canvas_item_set (GNOME_CANVAS_ITEM (wire_item),
		"x", start_pos.x,
		"y", start_pos.y,
		NULL);

	gnome_canvas_item_set (
		GNOME_CANVAS_ITEM (wire_item-> priv->resize2),
		"x1", length.x-RESIZER_SIZE,
		"y1", length.y-RESIZER_SIZE,
		"x2", length.x+RESIZER_SIZE,
		"y2", length.y+RESIZER_SIZE,
		NULL
	);

	/*
	 * Invalidate the bounding box cache.
	 */
	wire_item->priv->cache_valid = FALSE;
}
Example #5
0
static void
wire_flipped_callback (ItemData *data,
	gboolean horizontal, SheetItem *sheet_item)
{
	GnomeCanvasPoints *points;
	WireItem *item;
	WireItemPriv *priv;
	SheetPos start_pos, length;

	g_return_if_fail (sheet_item != NULL);
	g_return_if_fail (IS_WIRE_ITEM (sheet_item));

	item = WIRE_ITEM (sheet_item);
	priv = item->priv;

	wire_get_pos_and_length (WIRE (data), &start_pos, &length);

	points = gnome_canvas_points_new (2);
	points->coords[0] = 0;
	points->coords[1] = 0;
	points->coords[2] = length.x;
	points->coords[3] = length.y;

	gnome_canvas_item_set (GNOME_CANVAS_ITEM (item->priv->line),
			       "points", points,
			       NULL);
	gnome_canvas_points_unref (points);

	gnome_canvas_item_set (GNOME_CANVAS_ITEM (item),
			       "x", start_pos.x,
			       "y", start_pos.y,
			       NULL);

	/*
	 * Invalidate the bounding box cache.
	 */
	priv->cache_valid = FALSE;
}
Example #6
0
/* given the src and dst node centers, plus a size, draws a triangle in the 
 * specified color on the provided canvas item*/
static void draw_oneside_link(double xs, double ys, double xd, double yd,
                              const basic_stats_t *link_stats, 
                              guint32 scaledColor, GnomeCanvasItem *item)
{
  GnomeCanvasPoints *points;
  gdouble versorx, versory, modulus, link_size;

  link_size = get_link_size(link_stats) / 2;

  /* limit the maximum size to avoid overload */
  if (link_size > MAX_LINK_SIZE)
    link_size = MAX_LINK_SIZE; 

  versorx = -(yd - ys);
  versory = xd - xs;
  modulus = sqrt (pow (versorx, 2) + pow (versory, 2));
  if (modulus == 0)
    {
      link_size = 0;
      modulus = 1;
    }

  points = gnome_canvas_points_new (3);
  points->coords[0] = xd;
  points->coords[1] = yd;
  points->coords[2] = xs + versorx * link_size / modulus;
  points->coords[3] = ys + versory * link_size / modulus;
  points->coords[4] = xs - versorx * link_size / modulus;
  points->coords[5] = ys - versory * link_size / modulus;

  gnome_canvas_item_set (item, 
                          "points", points,
                          "fill_color_rgba", scaledColor, NULL);

  /* If we got this far, the link can be shown. Make sure it is */
  gnome_canvas_item_show (item);
  gnome_canvas_points_unref (points);
}
Example #7
0
static void midi_section_init(MidiSection* self)
{
    MidiSectionPrivate* p = MIDI_SECTION_GET_PRIVATE(self);
    GtkBox* box = GTK_BOX(self);
    GtkWidget* pad;
    GtkWidget* view;
    GtkWidget* scroll;
    GnomeCanvas* canvas;
    GnomeCanvasPoints* points;
    int x1, x2, y1, y2;

    p->patch = -1;
    p->ignore = FALSE;
    x1 = 0;
    y1 = 0;
    x2 = (PHIN_KEYBOARD_KEY_WIDTH * MIDI_NOTES);
    y2 = HEIGHT;

    /* adjustment */
    p->adj = (GtkAdjustment*) gtk_adjustment_new(0, 0, 0, 0, 0, 0);

    /* viewport */
    view = gtk_viewport_new(p->adj, NULL);
    gtk_box_pack_start(box, view, FALSE, FALSE, 0);
    gtk_viewport_set_shadow_type(GTK_VIEWPORT(view), GTK_SHADOW_NONE);
    gtk_widget_set_size_request(view, 0, y2);
    gtk_widget_show(view);

    /* canvas */
    canvas = (GnomeCanvas*) gnome_canvas_new();
    gtk_widget_set_size_request(GTK_WIDGET(canvas), x2,	y2);
    gnome_canvas_set_scroll_region(canvas, 0, 0, x2 - 1, y2 -1);
    gtk_container_add(GTK_CONTAINER(view), GTK_WIDGET(canvas));
    g_signal_connect(G_OBJECT(canvas), "event",
		     G_CALLBACK(range_cb), (gpointer)p);
    gtk_widget_show(GTK_WIDGET(canvas));

    /* range display backdrop */
    gnome_canvas_item_new(gnome_canvas_root(canvas),
			  gnome_canvas_rect_get_type(),
			  "x1", (gdouble)0,
			  "y1", (gdouble)0,
			  "x2", (gdouble)x2,
			  "y2", (gdouble)y2,
			  "fill-color-rgba", BG_COLOR,
			  NULL);
    /* range */
    p->range = gnome_canvas_item_new(gnome_canvas_root(canvas),
					gnome_canvas_rect_get_type(),
					"x1", (gdouble)x1,
					"y1", (gdouble)y1,
					"x2", (gdouble)PHIN_KEYBOARD_KEY_WIDTH,
					"y2", (gdouble)y2,
					"fill-color-rgba", RANGE_COLOR,
					"outline-color", "black",
					NULL);
    gnome_canvas_item_hide(p->range);
    
    /* range root note */
    p->note = gnome_canvas_item_new(gnome_canvas_root(canvas),
				       gnome_canvas_rect_get_type(),
				       "x1", (gdouble)x1,
				       "y1", (gdouble)y1,
				       "x2", (gdouble)PHIN_KEYBOARD_KEY_WIDTH,
				       "y2", (gdouble)y2,
				       "fill-color-rgba", NOTE_COLOR,
				       "outline-color", "black",
				       NULL);
    gnome_canvas_item_hide(p->note);

    p->canvas = canvas;

    /* range display border */
    points = gnome_canvas_points_new(4);

    points->coords[0] = x1;
    points->coords[1] = y2;
    points->coords[2] = x1;
    points->coords[3] = y1;
    points->coords[4] = x2-1;
    points->coords[5] = y1;
    points->coords[6] = x2-1;
    points->coords[7] = y2;

    gnome_canvas_item_new(gnome_canvas_root(canvas),
			  gnome_canvas_line_get_type(),
			  "points", points,
			  "width-units", (gdouble)1,
			  "fill-color-rgba", 0,
			  NULL);
    gnome_canvas_points_unref(points);


    /* keyboard */
    p->keyboard = phin_hkeyboard_new(p->adj, MIDI_NOTES, TRUE);
    gtk_box_pack_start(box, p->keyboard, FALSE, FALSE, 0);
    gtk_widget_show(p->keyboard);

    /* vpad */
    pad = gui_vpad_new(GUI_SCROLLSPACE);
    gtk_box_pack_start(box, pad, FALSE, FALSE, 0);
    gtk_widget_show(pad);

    /* scrollbar */
    scroll = gtk_hscrollbar_new(p->adj);
    gtk_box_pack_start(box, scroll, FALSE, FALSE, 0);
    gtk_widget_show(scroll);

    /* done */
    connect(p);
}
Example #8
0
void ui_common_study_preferences_widgets(GtkWidget * packing_table,
					 gint table_row,
					 GtkWidget ** proi_width_spin,
					 GnomeCanvasItem ** proi_item,
#ifdef AMIDE_LIBGNOMECANVAS_AA
					 GtkWidget ** proi_transparency_spin,
#else
					 GtkWidget ** pline_style_menu,
					 GtkWidget ** pfill_roi_button,
#endif
					 GtkWidget ** playout_button1,
					 GtkWidget ** playout_button2,
					 GtkWidget ** ppanel_layout_button1,
					 GtkWidget ** ppanel_layout_button2,
					 GtkWidget ** ppanel_layout_button3,
					 GtkWidget ** pmaintain_size_button,
					 GtkWidget ** ptarget_size_spin) {

  GtkWidget * label;
  GtkObject * adjustment;
  GtkWidget * roi_canvas;
  GnomeCanvasPoints * roi_line_points;
  GtkWidget * image;
  GtkWidget * hseparator;
#ifndef AMIDE_LIBGNOMECANVAS_AA
  GdkLineStyle i_line_style;
#endif


  /* widgets to change the roi's size */
  label = gtk_label_new(_("ROI Width (pixels)"));
  gtk_table_attach(GTK_TABLE(packing_table), label, 
		   0,1, table_row, table_row+1,
		   0, 0, X_PADDING, Y_PADDING);
  gtk_widget_show(label);

  adjustment = gtk_adjustment_new(AMITK_PREFERENCES_MIN_ROI_WIDTH,
				  AMITK_PREFERENCES_MIN_ROI_WIDTH,
				  AMITK_PREFERENCES_MAX_ROI_WIDTH,1.0, 1.0, 0.0);
  *proi_width_spin = gtk_spin_button_new(GTK_ADJUSTMENT(adjustment), 1.0, 0);
  gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(*proi_width_spin),FALSE);
  gtk_spin_button_set_snap_to_ticks(GTK_SPIN_BUTTON(*proi_width_spin), TRUE);
  gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(*proi_width_spin), TRUE);
  gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(*proi_width_spin), GTK_UPDATE_ALWAYS);
  gtk_table_attach(GTK_TABLE(packing_table), *proi_width_spin, 1,2, 
		   table_row, table_row+1, GTK_FILL, 0, X_PADDING, Y_PADDING);
  gtk_widget_show(*proi_width_spin);

  /* a little canvas indicator thingie to show the user who the new preferences will look */
#ifdef AMIDE_LIBGNOMECANVAS_AA
  roi_canvas = gnome_canvas_new_aa();
#else
  roi_canvas = gnome_canvas_new();
#endif
  gtk_widget_set_size_request(roi_canvas, 100, 100);
  gnome_canvas_set_scroll_region(GNOME_CANVAS(roi_canvas), 0.0, 0.0, 100.0, 100.0);
  gtk_table_attach(GTK_TABLE(packing_table),  roi_canvas, 2,3,table_row,table_row+2,
		   GTK_FILL, 0,  X_PADDING, Y_PADDING);
  gtk_widget_show(roi_canvas);

  /* the box */
  roi_line_points = gnome_canvas_points_new(5);
  roi_line_points->coords[0] = 25.0; /* x1 */
  roi_line_points->coords[1] = 25.0; /* y1 */
  roi_line_points->coords[2] = 75.0; /* x2 */
  roi_line_points->coords[3] = 25.0; /* y2 */
  roi_line_points->coords[4] = 75.0; /* x3 */
  roi_line_points->coords[5] = 75.0; /* y3 */
  roi_line_points->coords[6] = 25.0; /* x4 */
  roi_line_points->coords[7] = 75.0; /* y4 */
  roi_line_points->coords[8] = 25.0; /* x4 */
  roi_line_points->coords[9] = 25.0; /* y4 */

  
  *proi_item = gnome_canvas_item_new(gnome_canvas_root(GNOME_CANVAS(roi_canvas)), 
#ifdef AMIDE_LIBGNOMECANVAS_AA
				     gnome_canvas_polygon_get_type(),
#else
				     gnome_canvas_line_get_type(),
#endif
				     "points", roi_line_points, 
				     NULL);
  gnome_canvas_points_unref(roi_line_points);
  table_row++;


#ifdef AMIDE_LIBGNOMECANVAS_AA
  /* widget to change the transparency level */
  /* only works for anti-aliased canvases */
  /* widgets to change the roi's size */

  label = gtk_label_new(_("ROI Transparency"));
  gtk_table_attach(GTK_TABLE(packing_table), label, 
		   0, 1, table_row, table_row+1,
		   0, 0, X_PADDING, Y_PADDING);
  gtk_widget_show(label);

  *proi_transparency_spin = gtk_spin_button_new_with_range(0.0,1.0,AMITK_PREFERENCES_DEFAULT_CANVAS_ROI_TRANSPARENCY);
  gtk_spin_button_set_increments(GTK_SPIN_BUTTON(*proi_transparency_spin),0.1,0.1);
  gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(*proi_transparency_spin),FALSE);
  gtk_table_attach(GTK_TABLE(packing_table), *proi_transparency_spin, 1,2, 
		   table_row, table_row+1, GTK_FILL, 0, X_PADDING, Y_PADDING);
  gtk_widget_show(*proi_transparency_spin);
  table_row++;
#else
  /* widgets to change the roi's line style */
  /* Anti-aliased canvas doesn't yet support this */
  /* also need to remove #ifndef for relevant lines in amitk_canvas_object.c and other locations  */
  label = gtk_label_new(_("ROI Line Style:"));
  gtk_table_attach(GTK_TABLE(packing_table), label, 0,1,
  		   table_row, table_row+1, 0, 0, X_PADDING, Y_PADDING);
  gtk_widget_show(label);

  *pline_style_menu = gtk_combo_box_new_text();
  for (i_line_style=0; i_line_style<=GDK_LINE_DOUBLE_DASH; i_line_style++) 
     gtk_combo_box_append_text(GTK_COMBO_BOX(*pline_style_menu),
			       line_style_names[i_line_style]);
  gtk_widget_set_size_request (*pline_style_menu, 125, -1);
  gtk_table_attach(GTK_TABLE(packing_table),  *pline_style_menu, 1,2, 
  		   table_row,table_row+1, GTK_FILL, 0,  X_PADDING, Y_PADDING);
  gtk_widget_show(*pline_style_menu);
  table_row++;

  /* do we want to fill in isocontour roi's */
  label = gtk_label_new(_("Draw Isocontours/Freehands Filled:"));
  gtk_table_attach(GTK_TABLE(packing_table), label, 
		   0,1, table_row, table_row+1, 0, 0, X_PADDING, Y_PADDING);
  gtk_widget_show(label);

  *pfill_roi_button = gtk_check_button_new();
  gtk_table_attach(GTK_TABLE(packing_table), *pfill_roi_button,
		   1,2, table_row, table_row+1, 0, 0, X_PADDING, Y_PADDING);
  gtk_widget_show(*pfill_roi_button);
  table_row++;
#endif

  hseparator = gtk_hseparator_new();
  gtk_table_attach(GTK_TABLE(packing_table), hseparator, 
		   0, 3, table_row, table_row+1,
		   GTK_FILL, 0, X_PADDING, Y_PADDING);
  table_row++;
  gtk_widget_show(hseparator);


  label = gtk_label_new(_("Canvas Layout:"));
  gtk_table_attach(GTK_TABLE(packing_table), label, 
		   0,1, table_row, table_row+1,
		   0, 0, X_PADDING, Y_PADDING);
  gtk_widget_show(label);

  /* the radio buttons */
  *playout_button1 = gtk_radio_button_new(NULL);
  image = gtk_image_new_from_stock("amide_icon_layout_linear",GTK_ICON_SIZE_DIALOG);
  gtk_button_set_image(GTK_BUTTON(*playout_button1), image);
  gtk_table_attach(GTK_TABLE(packing_table), *playout_button1,
  		   1,2, table_row, table_row+1,
  		   0, 0, X_PADDING, Y_PADDING);
  g_object_set_data(G_OBJECT(*playout_button1), "layout", GINT_TO_POINTER(AMITK_LAYOUT_LINEAR));
  gtk_widget_show(*playout_button1);

  *playout_button2 = gtk_radio_button_new(NULL);
  gtk_radio_button_set_group(GTK_RADIO_BUTTON(*playout_button2), 
			     gtk_radio_button_get_group(GTK_RADIO_BUTTON(*playout_button1)));
  image = gtk_image_new_from_stock("amide_icon_layout_orthogonal",GTK_ICON_SIZE_DIALOG);
  gtk_button_set_image(GTK_BUTTON(*playout_button2), image);
  gtk_table_attach(GTK_TABLE(packing_table), *playout_button2, 2,3, table_row, table_row+1,
  		   0, 0, X_PADDING, Y_PADDING);
  g_object_set_data(G_OBJECT(*playout_button2), "layout", GINT_TO_POINTER(AMITK_LAYOUT_ORTHOGONAL));
  gtk_widget_show(*playout_button2);

  table_row++;


  label = gtk_label_new(_("Multiple Canvases Layout:"));
  gtk_table_attach(GTK_TABLE(packing_table), label, 
		   0,1, table_row, table_row+1,
		   0, 0, X_PADDING, Y_PADDING);
  gtk_widget_show(label);

  /* the radio buttons */
  *ppanel_layout_button1 = gtk_radio_button_new(NULL);
  image = gtk_image_new_from_stock("amide_icon_panels_mixed", GTK_ICON_SIZE_LARGE_TOOLBAR);
  gtk_button_set_image(GTK_BUTTON(*ppanel_layout_button1), image);
  gtk_table_attach(GTK_TABLE(packing_table), *ppanel_layout_button1,
  		   1,2, table_row, table_row+1,
  		   0, 0, X_PADDING, Y_PADDING);
  g_object_set_data(G_OBJECT(*ppanel_layout_button1), "panel_layout", GINT_TO_POINTER(AMITK_PANEL_LAYOUT_MIXED));
  gtk_widget_show(*ppanel_layout_button1);

  *ppanel_layout_button2 = gtk_radio_button_new(NULL);
  gtk_radio_button_set_group(GTK_RADIO_BUTTON(*ppanel_layout_button2), 
			     gtk_radio_button_get_group(GTK_RADIO_BUTTON(*ppanel_layout_button1)));
  image = gtk_image_new_from_stock("amide_icon_panels_linear_x", GTK_ICON_SIZE_LARGE_TOOLBAR);
  gtk_button_set_image(GTK_BUTTON(*ppanel_layout_button2), image);
  gtk_table_attach(GTK_TABLE(packing_table), *ppanel_layout_button2,
  		   2,3, table_row, table_row+1,
  		   0, 0, X_PADDING, Y_PADDING);
  g_object_set_data(G_OBJECT(*ppanel_layout_button2), "panel_layout", GINT_TO_POINTER(AMITK_PANEL_LAYOUT_LINEAR_X));
  gtk_widget_show(*ppanel_layout_button2);

  *ppanel_layout_button3 = gtk_radio_button_new(NULL);
  gtk_radio_button_set_group(GTK_RADIO_BUTTON(*ppanel_layout_button3), 
			     gtk_radio_button_get_group(GTK_RADIO_BUTTON(*ppanel_layout_button1)));
  image = gtk_image_new_from_stock("amide_icon_panels_linear_y", GTK_ICON_SIZE_LARGE_TOOLBAR);
  gtk_button_set_image(GTK_BUTTON(*ppanel_layout_button3), image);
  gtk_table_attach(GTK_TABLE(packing_table), *ppanel_layout_button3,
  		   3,4, table_row, table_row+1,
  		   0, 0, X_PADDING, Y_PADDING);
  g_object_set_data(G_OBJECT(*ppanel_layout_button3), "panel_layout", GINT_TO_POINTER(AMITK_PANEL_LAYOUT_LINEAR_Y));
  gtk_widget_show(*ppanel_layout_button3);

  table_row++;


  /* do we want the size of the canvas to not resize */
  label = gtk_label_new(_("Maintain view size constant:"));
  gtk_table_attach(GTK_TABLE(packing_table), label, 
		   0,1, table_row, table_row+1, 0, 0, X_PADDING, Y_PADDING);
  gtk_widget_show(label);

  *pmaintain_size_button = gtk_check_button_new();
  gtk_table_attach(GTK_TABLE(packing_table), *pmaintain_size_button, 
		   1,2, table_row, table_row+1, 0, 0, X_PADDING, Y_PADDING);
  gtk_widget_show(*pmaintain_size_button);
  table_row++;


  /* widgets to change the amount of empty space in the center of the target */
  label = gtk_label_new(_("Target Empty Area (pixels)"));
  gtk_table_attach(GTK_TABLE(packing_table), label, 
		   0,1, table_row, table_row+1, 0, 0, X_PADDING, Y_PADDING);
  gtk_widget_show(label);

  adjustment = gtk_adjustment_new(AMITK_PREFERENCES_MIN_TARGET_EMPTY_AREA, 
				  AMITK_PREFERENCES_MIN_TARGET_EMPTY_AREA, 
				  AMITK_PREFERENCES_MAX_TARGET_EMPTY_AREA, 1.0, 1.0, 0.0);
  *ptarget_size_spin = gtk_spin_button_new(GTK_ADJUSTMENT(adjustment), 1.0, 0);
  gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(*ptarget_size_spin),FALSE);
  gtk_spin_button_set_snap_to_ticks(GTK_SPIN_BUTTON(*ptarget_size_spin), TRUE);
  gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(*ptarget_size_spin), TRUE);
  gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(*ptarget_size_spin), GTK_UPDATE_ALWAYS);

  gtk_table_attach(GTK_TABLE(packing_table), *ptarget_size_spin, 1,2, 
		   table_row, table_row+1, GTK_FILL, 0, X_PADDING, Y_PADDING);
  gtk_widget_show(*ptarget_size_spin);


  return;
}
Example #9
0
void ui_common_draw_view_axis(GnomeCanvas * canvas, gint row, gint column, 
			      AmitkView view, AmitkLayout layout, 
			      gint axis_width, gint axis_height) {

  const gchar * x_axis_label;
  gdouble x_axis_label_x_location;
  gdouble x_axis_label_y_location;
  GtkAnchorType x_axis_label_anchor;
  GnomeCanvasPoints * x_axis_line_points;

  const gchar * y_axis_label;
  gdouble y_axis_label_x_location;
  gdouble y_axis_label_y_location;
  GtkAnchorType y_axis_label_anchor;
  GnomeCanvasPoints * y_axis_line_points;

  x_axis_line_points = gnome_canvas_points_new(2);
  x_axis_line_points->coords[0] = column*axis_width + AXIS_MARGIN; /* x1 */

  y_axis_line_points = gnome_canvas_points_new(2);
  y_axis_line_points->coords[0] = column*axis_width + AXIS_MARGIN; /* x1 */

  switch(view) {
  case AMITK_VIEW_CORONAL:
    /* the x axis */
    x_axis_line_points->coords[1] = row*axis_height + AXIS_HEADER; /* y1 */
    x_axis_line_points->coords[2] = column*axis_width + axis_width-AXIS_MARGIN; /* x2 */
    x_axis_line_points->coords[3] = row*axis_height + AXIS_HEADER; /* y2 */

    /* the x label */
    x_axis_label = amitk_axis_get_name(AMITK_AXIS_X);
    x_axis_label_x_location = column*axis_width + axis_width-AXIS_MARGIN-AXIS_TEXT_MARGIN;
    x_axis_label_y_location = row*axis_height + AXIS_HEADER+AXIS_TEXT_MARGIN;
    x_axis_label_anchor = GTK_ANCHOR_NORTH_EAST;
    
    /* the z axis */
    y_axis_line_points->coords[1] = row*axis_height + AXIS_HEADER; /* y1 */
    y_axis_line_points->coords[2] = column*axis_width + AXIS_MARGIN; /* x2 */
    y_axis_line_points->coords[3] = row*axis_height + axis_height-AXIS_MARGIN; /* y2 */
    
    /* the z label */
    y_axis_label = amitk_axis_get_name(AMITK_AXIS_Z);
    y_axis_label_x_location = column*axis_width + AXIS_MARGIN+AXIS_TEXT_MARGIN;
    y_axis_label_y_location = row*axis_height + axis_height-AXIS_MARGIN-AXIS_TEXT_MARGIN;
    y_axis_label_anchor = GTK_ANCHOR_NORTH_WEST;
    break;
  case AMITK_VIEW_SAGITTAL:
    /* the y axis */
      x_axis_line_points->coords[3] = row*axis_height + AXIS_HEADER; /* y2 */
    if (layout == AMITK_LAYOUT_ORTHOGONAL) {
      x_axis_line_points->coords[1] = row*axis_height + axis_height-AXIS_MARGIN; /* y1 */
      x_axis_line_points->coords[2] = column*axis_width + AXIS_MARGIN; /* x2 */
    } else { /* AMITK_LAYOUT_LINEAR */ 
      x_axis_line_points->coords[1] = row*axis_height + AXIS_HEADER; /* y1 */
      x_axis_line_points->coords[2] = column*axis_width + axis_width-AXIS_MARGIN; /* x2 */
    }
    
    /* the y label */
    x_axis_label = amitk_axis_get_name(AMITK_AXIS_Y);
    x_axis_label_y_location = row*axis_height + AXIS_HEADER+AXIS_TEXT_MARGIN;
    if (layout == AMITK_LAYOUT_ORTHOGONAL) {
      x_axis_label_x_location = column*axis_width + AXIS_MARGIN+AXIS_TEXT_MARGIN;
      x_axis_label_anchor = GTK_ANCHOR_NORTH_WEST;
    } else {/* AMITK_LAYOUT_LINEAR */
      x_axis_label_x_location = column*axis_width + axis_width-AXIS_MARGIN-AXIS_TEXT_MARGIN;
      x_axis_label_anchor = GTK_ANCHOR_NORTH_EAST;
    }
    
    /* the z axis */
    y_axis_line_points->coords[3] = row*axis_height + axis_height-AXIS_MARGIN; /* y2 */
    if (layout == AMITK_LAYOUT_ORTHOGONAL) {
      y_axis_line_points->coords[1] = row*axis_height + axis_height-AXIS_MARGIN; /* y1 */
      y_axis_line_points->coords[2] = column*axis_width + axis_width-AXIS_MARGIN; /* x2 */
    } else { /* AMITK_LAYOUT_LINEAR */ 
      y_axis_line_points->coords[1] = row*axis_height + AXIS_HEADER; /* y1 */
      y_axis_line_points->coords[2] = column*axis_width + AXIS_MARGIN; /* x2 */
    }
    
    /* the z label */
    y_axis_label = amitk_axis_get_name(AMITK_AXIS_Z);
    y_axis_label_y_location = row*axis_height + axis_height-AXIS_MARGIN-AXIS_TEXT_MARGIN;
    if (layout == AMITK_LAYOUT_ORTHOGONAL) {
      y_axis_label_x_location = column*axis_width + axis_width-AXIS_MARGIN-AXIS_TEXT_MARGIN;
      y_axis_label_anchor = GTK_ANCHOR_SOUTH_EAST;
    } else {
      y_axis_label_x_location = column*axis_width + AXIS_MARGIN+AXIS_TEXT_MARGIN;
      y_axis_label_anchor = GTK_ANCHOR_NORTH_WEST;
    }
    break;
  case AMITK_VIEW_TRANSVERSE:
  default:
    /* the x axis */
    x_axis_line_points->coords[1] = row*axis_height + axis_height-AXIS_MARGIN; /* y1 */
    x_axis_line_points->coords[2] = column*axis_width + axis_width-AXIS_MARGIN; /* x2 */
    x_axis_line_points->coords[3] = row*axis_height + axis_height-AXIS_MARGIN; /* y2 */
  
    /* the x label */
    x_axis_label = amitk_axis_get_name(AMITK_AXIS_X);
    x_axis_label_x_location = column*axis_width + axis_width-AXIS_MARGIN-AXIS_TEXT_MARGIN;
    x_axis_label_y_location = row*axis_height + axis_height-AXIS_MARGIN-AXIS_TEXT_MARGIN;
    x_axis_label_anchor = GTK_ANCHOR_SOUTH_EAST;

    /* the y axis */
    y_axis_line_points->coords[1] = row*axis_height + axis_height-AXIS_MARGIN; /* y1 */
    y_axis_line_points->coords[2] = column*axis_width + AXIS_MARGIN; /* x2 */
    y_axis_line_points->coords[3] = row*axis_height + AXIS_HEADER; /* y2 */

    /* the y label */
    y_axis_label = amitk_axis_get_name(AMITK_AXIS_Y);
    y_axis_label_x_location = column*axis_width + AXIS_MARGIN+AXIS_TEXT_MARGIN;
    y_axis_label_y_location = row*axis_height + AXIS_HEADER+AXIS_TEXT_MARGIN;
    y_axis_label_anchor = GTK_ANCHOR_NORTH_WEST;

    break;
  }

  /* the view label */
  gnome_canvas_item_new(gnome_canvas_root(canvas), gnome_canvas_text_get_type(),
			"anchor", GTK_ANCHOR_NORTH, "text", amitk_view_get_name(view),
			"x", (gdouble) (column+0.5)*axis_width,
			"y", (gdouble) (row+0.5)*axis_height, 
			"fill_color", "black", 
			"font_desc", amitk_fixed_font_desc, NULL);

  /* the x axis */
  gnome_canvas_item_new(gnome_canvas_root(canvas), gnome_canvas_line_get_type(),
			"points", x_axis_line_points, "fill_color", "black",
			"width_pixels", 3, "last_arrowhead", TRUE, 
			"arrow_shape_a", (gdouble) AXIS_ARROW_LENGTH,
			"arrow_shape_b", (gdouble) AXIS_ARROW_EDGE,
			"arrow_shape_c", (gdouble) AXIS_ARROW_WIDTH,
			NULL);

  /* the x label */
  gnome_canvas_item_new(gnome_canvas_root(canvas), gnome_canvas_text_get_type(),
			"anchor", x_axis_label_anchor,"text", x_axis_label,
			"x", x_axis_label_x_location, "y", x_axis_label_y_location,
			"fill_color", "black", "font_desc", amitk_fixed_font_desc, NULL); 

  /* the y axis */
  gnome_canvas_item_new(gnome_canvas_root(canvas), gnome_canvas_line_get_type(),
			"points", y_axis_line_points, "fill_color", "black",
			"width_pixels", 3, "last_arrowhead", TRUE, 
			"arrow_shape_a", (gdouble) AXIS_ARROW_LENGTH,
			"arrow_shape_b", (gdouble) AXIS_ARROW_EDGE,
			"arrow_shape_c", (gdouble) AXIS_ARROW_WIDTH,
			NULL);

  gnome_canvas_points_unref(x_axis_line_points);
  gnome_canvas_points_unref(y_axis_line_points);

  /* the y label */
  gnome_canvas_item_new(gnome_canvas_root(canvas),gnome_canvas_text_get_type(),
			"anchor", y_axis_label_anchor, "text", y_axis_label,
			"x", y_axis_label_x_location,"y", y_axis_label_y_location,
			"fill_color", "black", "font_desc", amitk_fixed_font_desc, NULL); 

  return;
}
Example #10
0
/* so much gayness in here, either I suck or gnome-canvas does; most
 * likely, we both do */
static void draw_key(PhatKeyboard* self, gint index, gint pos, guint bg,
                     guint hi, guint low, guint pre, guint on, guint shad)
{
    _Key* key = &self->keys[index];
    GnomeCanvasPoints* points;
    gint x1;
    gint y1;
    gint x2;
    gint y2;

    if (self->orientation == GTK_ORIENTATION_VERTICAL)
    {
        x1 = 0;
        y1 = pos + 1;           /* teh gayz0r */
        x2 = PHAT_KEYBOARD_KEY_LENGTH - 1;
        y2 = pos - PHAT_KEYBOARD_KEY_WIDTH + 1;
    }
    else
    {
        x1 = pos + PHAT_KEYBOARD_KEY_WIDTH - 1;
        y1 = 0;
        x2 = pos;
        y2 = PHAT_KEYBOARD_KEY_LENGTH - 1;
    }
    
    /* key group */
    key->group = (GnomeCanvasGroup*) gnome_canvas_item_new(gnome_canvas_root(self->canvas),
                                                           gnome_canvas_group_get_type(),
                                                           NULL);
    g_signal_connect(G_OBJECT(key->group), "event",
                     G_CALLBACK(key_press_cb), (gpointer)key);
    key->index = index;
    key->hold = 0;
    key->keyboard = self;
    
    /* draw main key rect */
    gnome_canvas_item_new(key->group,
                          gnome_canvas_rect_get_type(),
                          "x1", (gdouble)x1,
                          "y1", (gdouble)y1,
                          "x2", (gdouble)x2,
                          "y2", (gdouble)y2,
                          "fill-color-rgba", bg,
                          NULL);

    
    /* draw prelight rect */
    key->pre = gnome_canvas_item_new(key->group,
                                     gnome_canvas_rect_get_type(),
                                     "x1", (gdouble)x1,
                                     "y1", (gdouble)y1,
                                     "x2", (gdouble)x2,
                                     "y2", (gdouble)y2,
                                     "fill-color-rgba", pre,
                                     NULL);
    gnome_canvas_item_hide(key->pre);
    
    /* draw key highlight */
    points = gnome_canvas_points_new(3);

    if (self->orientation == GTK_ORIENTATION_VERTICAL)
    {
        points->coords[0] = x1+1;
        points->coords[1] = y1;
        points->coords[2] = x1+1;
        points->coords[3] = y2+1;
        points->coords[4] = x2;
        points->coords[5] = y2+1;
    }
    else
    {
        points->coords[0] = x1;
        points->coords[1] = y1+1;
        points->coords[2] = x2;
        points->coords[3] = y1+1;
        points->coords[4] = x2;
        points->coords[5] = y2;
    }

    gnome_canvas_item_new(key->group,
                          gnome_canvas_line_get_type(),
                          "points", points,
                          "width-units", (gdouble)1,
                          "fill-color-rgba", hi,
                          NULL);

    gnome_canvas_points_unref(points);
                        
    /* draw key border */
    points = gnome_canvas_points_new(4);
    
    if (self->orientation == GTK_ORIENTATION_VERTICAL)
    {
        points->coords[0] = x1;
        points->coords[1] = y1;
        points->coords[2] = x1;
        points->coords[3] = y2;
        points->coords[4] = x2;
        points->coords[5] = y2;
        points->coords[6] = x2;
        points->coords[7] = y1;
    }
    else
    {
        points->coords[0] = x2;
        points->coords[1] = y1;
        points->coords[2] = x1;
        points->coords[3] = y1;
        points->coords[4] = x1;
        points->coords[5] = y2;
        points->coords[6] = x2;
        points->coords[7] = y2;
    }

    gnome_canvas_item_new(key->group,
                          gnome_canvas_line_get_type(),
                          "points", points,
                          "width-units", (gdouble)1,
                          "fill-color-rgba", low,
                          NULL);
    
    gnome_canvas_points_unref(points);

    if (self->orientation == GTK_ORIENTATION_VERTICAL)
    {
        /* draw active rect */
        key->on = gnome_canvas_item_new(key->group,
                                        gnome_canvas_rect_get_type(),
                                        "x1", (gdouble)x1+1,
                                        "y1", (gdouble)y1,
                                        "x2", (gdouble)x2,
                                        "y2", (gdouble)y2+1,
                                        "fill-color-rgba", on,
                                        NULL);
    }
    else
    {
        /* draw active rect */
        key->on = gnome_canvas_item_new(key->group,
                                        gnome_canvas_rect_get_type(),
                                        "x1", (gdouble)x1,
                                        "y1", (gdouble)y1+1,
                                        "x2", (gdouble)x2,
                                        "y2", (gdouble)y2,
                                        "fill-color-rgba", on,
                                        NULL);
    }
    
    gnome_canvas_item_hide(key->on);
    
    /* draw active shadow */
    points = gnome_canvas_points_new(6);

    if (self->orientation == GTK_ORIENTATION_VERTICAL)
    {
        points->coords[0] = x1+1;
        points->coords[1] = y1;
    
        points->coords[2] = x1+1;
        points->coords[3] = y2+1;
    
        points->coords[4] = x2;
        points->coords[5] = y2+1;
    
        points->coords[6] = x2;
        points->coords[7] = y2 + 3;
    
        points->coords[8] = x1 + 3;
        points->coords[9] = y2 + 3;
    
        points->coords[10] = x1 + 3;
        points->coords[11] = y1;
    }
    else
    {
        points->coords[0] = x1;
        points->coords[1] = y1 + 1;
    
        points->coords[2] = x2;
        points->coords[3] = y1 + 1;
    
        points->coords[4] = x2;
        points->coords[5] = y2;
    
        points->coords[6] = x2 + 2;
        points->coords[7] = y2;
    
        points->coords[8] = x2 + 2;
        points->coords[9] = y1 + 3;
    
        points->coords[10] = x1;
        points->coords[11] = y1 + 3;
    }
        
    
    key->shad = gnome_canvas_item_new(key->group,
                                      gnome_canvas_polygon_get_type(),
                                      "points", points,
                                      "fill-color-rgba", shad,
                                      NULL);
    gnome_canvas_item_hide(key->shad);
    gnome_canvas_points_unref(points);

    /* draw label if applicable */
    if (self->label && (index % 12) == 0)
    {
        gchar* s = g_strdup_printf("%d", index / 12 + 1);

        if (self->orientation == GTK_ORIENTATION_VERTICAL)
        {
            gnome_canvas_item_new(key->group,
                                  gnome_canvas_text_get_type(),
                                  "text", s,
                                  "x", (gdouble)(x2 - 2),
                                  "y", (gdouble)(y1 - (PHAT_KEYBOARD_KEY_WIDTH / 2)),
                                  "anchor", GTK_ANCHOR_EAST,
                                  "fill-color-rgba", (gint)KEY_TEXT_BG,
                                  "font", "sans",
                                  "size-points", (gdouble)TEXT_POINTS,
                                  NULL);
        }
        else
        {
            gnome_canvas_item_new(key->group,
                                  gnome_canvas_text_get_type(),
                                  "text", s,
                                  "x", (gdouble)(x1 - (PHAT_KEYBOARD_KEY_WIDTH / 2)),
                                  "y", (gdouble)(y2 - 2),
                                  "anchor", GTK_ANCHOR_SOUTH,
                                  "fill-color-rgba", (gint)KEY_TEXT_BG,
                                  "font", "sans",
                                  "size-points", (gdouble)TEXT_POINTS,
                                  "justification", GTK_JUSTIFY_CENTER,
                                  NULL);
        }
    
        g_free(s);
    }
}