Example #1
0
void free_object(void *data) {
	struct channel_data *d=(struct channel_data *)data;	// Cast is necessary...

	gtk_object_destroy(GTK_OBJECT(d->line1));
	gtk_object_destroy(GTK_OBJECT(d->line2));
	gtk_object_destroy(GTK_OBJECT(d->line3));
	gtk_object_destroy(GTK_OBJECT(d->handle1));
	gtk_object_destroy(GTK_OBJECT(d->handle2));
	gtk_object_destroy(GTK_OBJECT(d->handle3));
	gtk_object_destroy(GTK_OBJECT(d->group));
	gnome_canvas_points_free(d->line1_points);
	gnome_canvas_points_free(d->line2_points);
	gnome_canvas_points_free(d->line3_points);

	channel_counter--;

	g_free(d);
}
Example #2
0
static void
bst_canvas_link_adjust_arrow (BstCanvasLink *clink)
{
  GnomeCanvasPoints *gpoints;
  gdouble dx, dy, l, x, y, px, py, cos_theta, sin_theta, *points;
  
  if (!clink->line)
    return;
  gtk_object_get (GTK_OBJECT (clink->line), "points", &gpoints, NULL);
  if (!gpoints)
    gpoints = gnome_canvas_points_new0 (2);
  points = gpoints->coords;
  
  dx = points[0] - points[2];
  dy = points[1] - points[3];
  l = sqrt (dx * dx + dy * dy);
  x = (points[2] + points[0]) / 2;
  y = (points[3] + points[1]) / 2;
  
  gnome_canvas_points_free (gpoints);
  
  sin_theta = l ? dy / l : 0;
  cos_theta = l ? dx / l : 0;
  px = x - ARROW_LENGTH / 2.0 * cos_theta;
  py = y - ARROW_LENGTH / 2.0 * sin_theta;
  x += ARROW_LENGTH / 2.0 * cos_theta;
  y += ARROW_LENGTH / 2.0 * sin_theta;
  
  gpoints = gnome_canvas_points_new (4);
  points = gpoints->coords;
  
  *(points++) = px;
  *(points++) = py;
  *(points++) = x - ARROW_WIDTH * sin_theta;
  *(points++) = y + ARROW_WIDTH * cos_theta;
  *(points++) = x + ARROW_WIDTH * sin_theta;
  *(points++) = y - ARROW_WIDTH * cos_theta;
  *(points++) = px;
  *(points++) = py;
  
  if (clink->arrow)
    g_object_set (clink->arrow, "points", gpoints, NULL);
  gnome_canvas_points_free (gpoints);
}
Example #3
0
static void
bst_canvas_link_adjust_tags (BstCanvasLink *clink)
{
  GnomeCanvasPoints *gpoints;
  gdouble x1, y1, x2, y2, *points;
  
  if (!clink->line)
    return;
  gtk_object_get (GTK_OBJECT (clink->line), "points", &gpoints, NULL);
  if (!gpoints)
    gpoints = gnome_canvas_points_new0 (2);
  points = gpoints->coords;

  x1 = points[0] - TAG_DIAMETER;
  y1 = points[1] - TAG_DIAMETER;
  x2 = points[0] + TAG_DIAMETER;
  y2 = points[1] + TAG_DIAMETER;
  if (clink->tag_start)
    g_object_set (clink->tag_start,
                  "x1", x1,
                  "y1", y1,
                  "x2", x2,
                  "y2", y2,
                  NULL);
  x1 = points[2] - TAG_DIAMETER;
  y1 = points[3] - TAG_DIAMETER;
  x2 = points[2] + TAG_DIAMETER;
  y2 = points[3] + TAG_DIAMETER;
  if (clink->tag_end)
    g_object_set (clink->tag_end,
                  "x1", x1,
                  "y1", y1,
                  "x2", x2,
                  "y2", y2,
                  NULL);
  
  gnome_canvas_points_free (gpoints);
}
Example #4
0
static void
bst_canvas_link_update (BstCanvasLink *clink)
{
  GnomeCanvasItem *item = GNOME_CANVAS_ITEM (clink);
  if (clink->line)
    {
      gdouble start_x = 0, start_y = 0, end_x = 10, end_y = 10;
      if (clink->ocsource)
        {
          bst_canvas_source_ochannel_pos (clink->ocsource, clink->ochannel, &start_x, &start_y);
          gnome_canvas_item_w2i (item, &start_x, &start_y);
        }
      if (clink->icsource)
        {
          bst_canvas_source_ichannel_pos (clink->icsource, clink->ichannel, &end_x, &end_y);
          gnome_canvas_item_w2i (item, &end_x, &end_y);
        }
      GnomeCanvasPoints *gpoints = gnome_canvas_points_new (2);
      gpoints->coords[0] = start_x;
      gpoints->coords[1] = start_y;
      gpoints->coords[2] = end_x;
      gpoints->coords[3] = end_y;
      g_object_set (clink->line,
                    "points", gpoints,
                    NULL);
      gnome_canvas_points_free (gpoints);
    }
  if (clink->tag_start)
    gnome_canvas_item_raise_to_top (clink->tag_start);
  if (clink->tag_end)
    gnome_canvas_item_raise_to_top (clink->tag_end);
  if (clink->ocsource && clink->icsource)
    gnome_canvas_item_keep_above (GNOME_CANVAS_ITEM (clink),
                                  GNOME_CANVAS_ITEM (clink->ocsource),
                                  GNOME_CANVAS_ITEM (clink->icsource));
  bst_canvas_link_adjust_tags (clink);
  bst_canvas_link_adjust_arrow (clink);
}
Example #5
0
/**
 * This function returns the length of the canvas item.
 */
void
wire_item_get_length (WireItem *item, SheetPos *pos)
{
	WireItemPriv *priv;
	GnomeCanvasPoints *points;

	g_return_if_fail (item != NULL);
	g_return_if_fail (IS_WIRE_ITEM (item));
	g_return_if_fail (pos != NULL);

	priv = item->priv;

	g_object_get(G_OBJECT(priv->line), "points", &points, NULL);

	/*
	 * This is not strictly neccessary, since the first point is always
	 * (0,0) but it's more correct and good to have if this changes in the
	 * future.
	 */
	pos->x = points->coords[2] - points->coords[0];
	pos->y = points->coords[3] - points->coords[1];
	gnome_canvas_points_free (points);
}
Example #6
0
static void create_buysell(ChartInstance *ci) {
	char	color_string[8];
	struct tm *tm_time;
	int	i;
	char	text_string[20];
	double	text_offset;

	struct buysell_data *data=(struct buysell_data *)ci->instance_data;
	ci->fixed_group=NULL;
	ci->move_group=NULL;
	data->arrow=NULL;

	if (ci->quote_count>1) {
		tm_time=localtime(&data->time);

		data->day=-1;
		for (i=1;i<ci->quote_count+1;i++) {
			if ( (ci->quote_vector[i].year==tm_time->tm_year) &&
			     (ci->quote_vector[i].month==tm_time->tm_mon) &&
			     (ci->quote_vector[i].day==tm_time->tm_mday)) {
			
				data->day=i-1;
				break;
			}
		}

		if (data->day==-1) {
			data->time=ci->quote_vector[1].timestamp;
			data->day=0;
		}

		sprintf(color_string,"#%.2X%.2X%.2X",data->r,data->g,data->b);

		ci->fixed_group=(GnomeCanvasGroup *)gnome_canvas_item_new(gnome_canvas_root(chart_canvas),
				GNOME_TYPE_CANVAS_GROUP,
				"x",0.0,
				"y",0.0,
				NULL);

		bs_points=gnome_canvas_points_new(2);

		bs_points->coords[0]=CHARTER_X(data->day);
		bs_points->coords[1]=CHARTER_Y(data->price);
		bs_points->coords[2]=CHARTER_X(data->day);
		bs_points->coords[3]=CHARTER_Y(data->price);

		if (data->buy) {
			bs_points->coords[3]+=10;
			text_offset=10;
		} else {
			bs_points->coords[3]-=10;
			text_offset=-30;
		}

		data->arrow=gnome_canvas_item_new(ci->fixed_group,
				GNOME_TYPE_CANVAS_LINE,
				"points",bs_points,
				"width_units",1.0,
                                "fill_color", color_string,
				"first_arrowhead",TRUE,
				"last_arrowhead",FALSE,
				"arrow_shape_a",5.0,
				"arrow_shape_b",5.0,
				"arrow_shape_c",2.5,
				NULL);	

		sprintf(text_string,"%.2f",data->amount);
		data->text=gnome_canvas_item_new (ci->fixed_group,
                               GNOME_TYPE_CANVAS_TEXT,
                               "text",text_string,
                               "x", CHARTER_X(data->day),
                               "y", CHARTER_Y(data->price)+text_offset,
                               "font", "-b&h-lucida-medium-r-normal-*-*-100-*-*-p-*-iso8859-1",
                               "anchor", GTK_ANCHOR_N,
                               "fill_color", "black",
                               NULL);

		sprintf(text_string,"%.2f",data->price);
		data->text2=gnome_canvas_item_new (ci->fixed_group,
                               GNOME_TYPE_CANVAS_TEXT,
                               "text",text_string,
                               "x", CHARTER_X(data->day),
                               "y", CHARTER_Y(data->price)+text_offset+10,
                               "font", "-b&h-lucida-medium-r-normal-*-*-100-*-*-p-*-iso8859-1",
                               "anchor", GTK_ANCHOR_N,
                               "fill_color", "black",
                               NULL);
		
		gnome_canvas_points_free(bs_points);

	}
}
Example #7
0
WireItem *
wire_item_new (Sheet *sheet, Wire *wire)
{
	WireItem *item;
	GnomeCanvasPoints *points;
	WireItemPriv *priv;
	SheetPos start_pos, length;

	g_return_val_if_fail (sheet != NULL, NULL);
	g_return_val_if_fail (IS_SHEET (sheet), NULL);

	//g_object_ref (G_OBJECT(wire));
	/* XXX Ver si hay equivalente gtk_object_sink (GTK_OBJECT (wire)); */

	wire_get_pos_and_length (wire, &start_pos, &length);

	/*
	 * Because of the GnomeCanvasGroup inheritance, a small hack is needed
	 * here. The group starts at the startpoint of the wire, and the line
	 * goes from (0,0) to (length.x, length.y).
	 */
	item = WIRE_ITEM (gnome_canvas_item_new (
		sheet->object_group,
		wire_item_get_type (),
		"data", wire,
		"x", (double) start_pos.x,
		"y", (double) start_pos.y,
		NULL));

	priv = item->priv;

	priv->resize1 = GNOME_CANVAS_RECT (gnome_canvas_item_new (
		GNOME_CANVAS_GROUP (item),
		gnome_canvas_rect_get_type (),
		"x1", -RESIZER_SIZE,
		"y1", -RESIZER_SIZE,
		"x2", RESIZER_SIZE,
		"y2", RESIZER_SIZE,
		"fill_color", "red",
		"fill_color_rgba", 0x3cb37180,
		"outline_color", "blue",
		"width_pixels", 1,
		NULL));

	priv->resize2 = GNOME_CANVAS_RECT (gnome_canvas_item_new (
		GNOME_CANVAS_GROUP (item),
		gnome_canvas_rect_get_type (),
		"x1", length.x-RESIZER_SIZE,
		"y1", length.y-RESIZER_SIZE,
		"x2", length.x+RESIZER_SIZE,
		"y2", length.y+RESIZER_SIZE,
		"fill_color", "red",
		"fill_color_rgba", 0x3cb37180,
		"outline_color", "blue",
		"width_pixels", 1,
		NULL));
	gnome_canvas_item_hide (GNOME_CANVAS_ITEM (priv->resize1));
	gnome_canvas_item_hide (GNOME_CANVAS_ITEM (priv->resize2));

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

	priv->line = GNOME_CANVAS_LINE (gnome_canvas_item_new (
		GNOME_CANVAS_GROUP (item),
		gnome_canvas_line_get_type (),
		"points", points,
		"fill_color", "blue",
		"width_pixels", 1,
		NULL));

	gnome_canvas_points_free (points);

	g_signal_connect_object(G_OBJECT(wire),	"rotated",
		G_CALLBACK(wire_rotated_callback), G_OBJECT(item), 0);
	g_signal_connect_object(G_OBJECT(wire), "flipped",
		G_CALLBACK(wire_flipped_callback), G_OBJECT(item), 0);
	g_signal_connect_object(G_OBJECT(wire), "moved",
		G_CALLBACK(wire_moved_callback),  G_OBJECT(item), 0);

	g_signal_connect (G_OBJECT (wire), "changed", G_CALLBACK (wire_changed_callback), item);
	g_signal_connect (G_OBJECT (wire), "delete", G_CALLBACK (wire_delete_callback), item);
	wire_update_bbox (wire);

	return item;
}