Example #1
0
static void wire_flipped_callback (ItemData *data, IDFlip direction, SheetItem *sheet_item)
{
	GooCanvasPoints *points;
	WireItem *item;
	WireItemPriv *priv;
	Coords 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 = goo_canvas_points_new (2);
	points->coords[0] = 0;
	points->coords[1] = 0;
	points->coords[2] = length.x;
	points->coords[3] = length.y;

	g_object_set (item->priv->line, "points", points, NULL);
	goo_canvas_points_unref (points);

	g_object_set (item, "x", start_pos.x, "y", start_pos.y, NULL);

	// Invalidate the bounding box cache.
	priv->cache_valid = FALSE;
}
Example #2
0
static void
wire_changed_callback (Wire *wire, WireItem *item)
{
	SheetPos start_pos, length;
	GooCanvasPoints *points;
	
	wire_get_pos_and_length (wire, &start_pos, &length);

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

	g_object_set (item->priv->line, 
	              "points", points, 
	              NULL);
	goo_canvas_points_unref (points);

	g_object_set (item->priv->resize1,
	              "x", -RESIZER_SIZE, 
	              "y", -RESIZER_SIZE,
	              "width", 2 * RESIZER_SIZE, 
	              "height", 2 * RESIZER_SIZE, 
	              NULL);

	g_object_set (item->priv->resize2,
	              "x", length.x-RESIZER_SIZE, 
	              "y", length.y-RESIZER_SIZE,
	              "width", 2 * RESIZER_SIZE, 
	              "height", 2 * RESIZER_SIZE, 
	              NULL);

	goo_canvas_item_request_update (GOO_CANVAS_ITEM (item->priv->line));
}
Example #3
0
static void wire_rotated_callback (ItemData *data, int angle, SheetItem *sheet_item)
{
	WireItem *wire_item;
	GooCanvasPoints *points;
	Coords 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 = goo_canvas_points_new (2);
	points->coords[0] = 0;
	points->coords[1] = 0;
	points->coords[2] = length.x;
	points->coords[3] = length.y;

	g_object_set (wire_item->priv->line, "points", points, NULL);
	goo_canvas_points_unref (points);

	g_object_set (wire_item, "x", start_pos.x, "y", start_pos.y, NULL);

	g_object_set (wire_item->priv->resize2, "x", length.x - RESIZER_SIZE, "y",
	              length.y - RESIZER_SIZE, NULL);

	// Invalidate the bounding box cache.
	wire_item->priv->cache_valid = FALSE;
}
Example #4
0
static void
set_dimension (GooCanvas *canvas, char *arrow_name, char *text_name,
	       double x1, double y1, double x2, double y2,
	       double tx, double ty, int dim)
{
	GooCanvasPoints *points;
	char buf[100];

	points = goo_canvas_points_new (2);
	points->coords[0] = x1;
	points->coords[1] = y1;
	points->coords[2] = x2;
	points->coords[3] = y2;

	g_object_set (g_object_get_data (G_OBJECT (canvas), arrow_name),
		      "points", points,
		      NULL);

	sprintf (buf, "%d", dim);
	g_object_set (g_object_get_data (G_OBJECT (canvas), text_name),
		      "text", buf,
		      "x", tx,
		      "y", ty,
		      NULL);

	goo_canvas_points_unref (points);
}
Example #5
0
static void
gst_editor_link_init (GstEditorLink * link)
{
  link->points = goo_canvas_points_new (2);
  
//   goo_canvas_item_raise_pos ((GooCanvasItem *) link, 10);
  goo_canvas_item_raise ((GooCanvasItem *) link, NULL);
}
Example #6
0
static void
i7_node_init(I7Node *self)
{
	I7_NODE_USE_PRIVATE;
	priv->id = g_strdup_printf("node-%p", self);
	self->gnode = g_node_new(self);
	self->tree_item = NULL;
	self->tree_points = goo_canvas_points_new(4);

	priv->blessed = FALSE;
	priv->match = I7_NODE_CANT_COMPARE;
	priv->transcript_diffs = NULL;
	priv->transcript_pango_string = NULL;
	priv->expected_diffs = NULL;
	priv->expected_pango_string = NULL;

	/* Create the cairo gradients */
	/* Label */
	priv->label_pattern = cairo_pattern_create_linear(0.0, 0.0, 0.0, 1.0);
	cairo_pattern_add_color_stop_rgba(priv->label_pattern, 1.0, 0.0, 0.33, 0.0, 0.3);
	cairo_pattern_add_color_stop_rgba(priv->label_pattern, 0.67, 0.73, 0.84, 0.73, 0.1);
	cairo_pattern_add_color_stop_rgba(priv->label_pattern, 0.0, 0.5, 0.85, 0.5, 0.0);
	/* Node, unplayed, without blessed transcript text: Tango Chameleon 3 */
	priv->node_pattern[NODE_UNPLAYED_UNBLESSED] = create_node_pattern(0.31, 0.60, 0.02);
	/* Node, unplayed, with blessed transcript text: Tango Chameleon 1 */
	priv->node_pattern[NODE_UNPLAYED_BLESSED] = create_node_pattern(0.54, 0.87, 0.2);
	/* Node, played, without blessed transcript text: Tango Butter 3 */
	priv->node_pattern[NODE_PLAYED_UNBLESSED] = create_node_pattern(0.77, 0.63, 0.0);
	/* Node, played, with blessed transcript text: Tango Butter 1 */
	priv->node_pattern[NODE_PLAYED_BLESSED] = create_node_pattern(0.99, 0.91, 0.31);

	/* Create the canvas items, though some of them can't be drawn yet */
	priv->command_shape_item = goo_canvas_path_model_new(GOO_CANVAS_ITEM_MODEL(self), "",
		"stroke-pattern", NULL,
		"fill-pattern", priv->node_pattern[NODE_UNPLAYED_UNBLESSED],
		NULL);
	priv->label_shape_item = goo_canvas_path_model_new(GOO_CANVAS_ITEM_MODEL(self), "",
		"stroke-pattern", NULL,
		"fill-pattern", priv->label_pattern,
		NULL);
	priv->command_item = goo_canvas_text_model_new(GOO_CANVAS_ITEM_MODEL(self), "", 0.0, 0.0, -1, GTK_ANCHOR_CENTER, NULL);
	priv->label_item = goo_canvas_text_model_new(GOO_CANVAS_ITEM_MODEL(self), "", 0.0, 0.0, -1, GTK_ANCHOR_CENTER, NULL);
	priv->badge_item = goo_canvas_path_model_new(GOO_CANVAS_ITEM_MODEL(self), "",
	  "fill-color", "red",
	  "line-width", 0,
	  "visibility", GOO_CANVAS_ITEM_HIDDEN,
	  NULL);
	g_object_set_data(G_OBJECT(priv->badge_item), "path-drawn", NULL);
	g_object_set_data(G_OBJECT(priv->badge_item), "node-part", GINT_TO_POINTER(I7_NODE_PART_DIFFERS_BADGE));
	/* Avoid drawing the differs badges unless they're actually needed, otherwise
	it really slows down the story startup */

	priv->x = 0.0;
	priv->command_width = -1.0;
	priv->command_height = -1.0;
	priv->label_width = -1.0;
	priv->label_height = -1.0;
}
Example #7
0
static void
wire_changed_callback (Wire *wire, WireItem *item)
{
	Coords start_pos, length;
	GooCanvasPoints *points;

	g_return_if_fail (wire != NULL);
	g_return_if_fail (IS_ITEM_DATA (wire));
	g_return_if_fail (item != NULL);
	g_return_if_fail (IS_WIRE_ITEM (item));


	wire_get_pos_and_length (wire, &start_pos, &length);

	Sheet *sheet = SHEET (goo_canvas_item_get_canvas (GOO_CANVAS_ITEM (item)));
	if (G_UNLIKELY(!sheet)) {
		g_warning ("Failed to determine the Sheet the item is glued to. This should never happen. Ever!");
	} else {
		item_data_snap (ITEM_DATA (wire), sheet->grid);
	}

	// Move the canvas item and invalidate the bbox cache.
	goo_canvas_item_set_simple_transform (GOO_CANVAS_ITEM (item),
	                                      start_pos.x,
	                                      start_pos.y,
	                                      1.0,
	                                      0.0);
	item->priv->cache_valid = FALSE;

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

	// this does handle cleanup of previous points internally
	g_object_set (item->priv->line,
	              "points", points,
	              NULL);
	goo_canvas_points_unref (points);

	g_object_set (item->priv->resize1,
	              "x", -RESIZER_SIZE,
	              "y", -RESIZER_SIZE,
	              "width", 2 * RESIZER_SIZE,
	              "height", 2 * RESIZER_SIZE,
	              NULL);

	g_object_set (item->priv->resize2,
	              "x", length.x-RESIZER_SIZE,
	              "y", length.y-RESIZER_SIZE,
	              "width", 2 * RESIZER_SIZE,
	              "height", 2 * RESIZER_SIZE,
	              NULL);

	goo_canvas_item_request_update (GOO_CANVAS_ITEM (item->priv->line));
}
Example #8
0
static GooCanvasItem *
draw_Trapez(GooCanvasItem *group,
	    struct Trapez t,const char *c1, const char *c2)
{
  GooCanvasPoints *pts=goo_canvas_points_new(4);
  GooCanvasItem *res=NULL;
  pts->coords[0]=t.x_left;
  pts->coords[1]=t.y_left_top;
  pts->coords[2]=t.x_right;
  pts->coords[3]=t.y_right_top;
  pts->coords[4]=t.x_right;
  pts->coords[5]=t.y_right_bottom;
  pts->coords[6]=t.x_left;
  pts->coords[7]=t.y_left_bottom;
  res=goo_canvas_polyline_new(group, FALSE, 0,
			      "points", (GooCanvasPoints*)pts,
			      "fill-color", c1,
			      "stroke-color", c2,
			      "line-width", 1.0,
			      NULL);
  return res;
}
Example #9
0
/*
 * Computes the points' coordinates of the line going from
 * @ref_pk_ent to @fk_ent (which are themselves rectangles)
 *
 * if @shapes is not NULL, then the shapes in the list are reused, and the ones which don't need
 * to exist anymore are removed
 *
 * Returns a list of BrowserCanvasCanvasShapes structures
 */
GSList *
browser_canvas_util_compute_anchor_shapes (GooCanvasItem *parent, GSList *shapes,
					   BrowserCanvasTable *fk_ent, BrowserCanvasTable *ref_pk_ent, 
					   guint nb_anchors, guint ext, gboolean with_handle)
{
	GSList *retval = shapes;
	guint i;
	gdouble fx1, fy1, fx2, fy2; /* FK entity item (bounds) */
	gdouble rx1, ry1, rx2, ry2; /* REF PK entity item  (bounds) */

	BrowserCanvasCanvasShape *shape;
	gchar *id;

	gdouble rcx, rcy; /* center of ref_pk entity item */
	gdouble cx, cy;

	gdouble rux, ruy; /* current ref_pk point for the arrow line */
	gdouble dx, dy; /* increments to compute the new ref_pk point for the arrow line */
	GooCanvasBounds bounds;

	g_return_val_if_fail (nb_anchors > 0, NULL);

	browser_canvas_table_get_anchor_bounds (fk_ent, &bounds);
	fx1 = bounds.x1;
	fy1 = bounds.y1;
	fx2 = bounds.x2;
	fy2 = bounds.y2;
	browser_canvas_table_get_anchor_bounds (ref_pk_ent, &bounds);
	rx1 = bounds.x1;
	ry1 = bounds.y1;
	rx2 = bounds.x2;
	ry2 = bounds.y2;

	/* compute the cx, cy, dx and dy values */
	rcx = (rx1 + rx2) / 2.;
	rcy = (ry1 + ry2) / 2.;
	cx = (fx1 + fx2) / 2.;
	cy = (fy1 + fy2) / 2.;
	rux = rcx;
	ruy = rcy;
	dx = 0;
	dy = 0;

	for (i = 0; i < nb_anchors; i++) {
		/* TODO:
		   - detect tables overlapping
		*/		
		if ((rcx == cx) && (rcy == cy)) {
			/* tables have the same center (includes case when they are equal) */
			gdouble Dy, Dx;
			GooCanvasPoints *ap, *points;
			GooCanvasItem *item;
			
			points = goo_canvas_points_new (4);
			ap = goo_canvas_points_new (4);

			Dy = (ry2 - ry1) / 2. / (gdouble ) (nb_anchors + 1) * (gdouble) (i + 1);
			Dx = (rx2 - rx1) * (0.8 + 0.1 * i);
			if (! compute_intersect_rect_line (rx1, ry1, rx2, ry2,
							   cx, cy, cx + Dx, cy - Dy,
							   &(ap->coords[0]), &(ap->coords[1]),
							   &(ap->coords[2]), &(ap->coords[3])))
				return retval;
			
			if (ap->coords[0] > ap->coords[2]) {
				points->coords[0] = ap->coords[0];
				points->coords[1] = ap->coords[1];
			}
			else {
				points->coords[0] = ap->coords[2];
				points->coords[1] = ap->coords[3];
			}

			points->coords[2] = cx + Dx;
			points->coords[3] = cy - Dy;

			Dy = (fy2 - fy1) / 2. / (gdouble ) (nb_anchors + 1) * (gdouble) (i + 1);
			Dx = (fx2 - fx1) * (0.8 + 0.1 * i);
			points->coords[4] = cx + Dx;
			points->coords[5] = cy + Dy;

			if (! compute_intersect_rect_line (fx1, fy1, fx2, fy2,
							   cx, cy, cx + Dx, cy + Dy,
							   &(ap->coords[0]), &(ap->coords[1]),
							   &(ap->coords[2]), &(ap->coords[3])))
				return retval;
			
			if (ap->coords[0] > ap->coords[2]) {
				points->coords[6] = ap->coords[0];
				points->coords[7] = ap->coords[1];
			}
			else {
				points->coords[6] = ap->coords[2];
				points->coords[7] = ap->coords[3];
			}
			
			id = g_strdup_printf ("a%d", i);
			shape = browser_canvas_canvas_shape_find (retval, id);
			if (shape) {
				g_object_set (shape->item, "points", points, NULL);
				shape->_used = TRUE;
				g_free (id);
			}
			else {
				item = goo_canvas_polyline_new_line (parent, 
								     points->coords[0], points->coords [1],
								     points->coords[2], points->coords [3],
								     "close-path", FALSE,
								     "points", points, NULL);
				retval = browser_canvas_canvas_shape_add_to_list (retval, id, item);
			}
			goo_canvas_points_unref (ap);
			
			/* extension marks as text */
			if (ext & CANVAS_SHAPE_EXT_JOIN_OUTER_1) {
				id = g_strdup_printf ("a%de1", i);
				shape = browser_canvas_canvas_shape_find (retval, id);
				if (shape) {
					g_object_set (shape->item, 
						      "x", points->coords[2] + 5.,
						      "y", points->coords[3] - 5., NULL);
					shape->_used = TRUE;
					g_free (id);
				}
				else {
					item = goo_canvas_text_new (parent, "*", 
								    points->coords[2] + 5.,
								    points->coords[3] - 5., -1,
								    GOO_CANVAS_ANCHOR_SOUTH, NULL);
					retval = browser_canvas_canvas_shape_add_to_list (retval, id, item);
				}
			}

			if (ext & CANVAS_SHAPE_EXT_JOIN_OUTER_2) {
				id = g_strdup_printf ("a%de2", i);
				if (shape) {
					g_object_set (shape->item, 
						      "x", points->coords[4] + 5.,
						      "y", points->coords[5] + 5., NULL);
					shape->_used = TRUE;
					g_free (id);
				}
				else {
					item = goo_canvas_text_new (parent, "*", 
								    points->coords[4] + 5.,
								    points->coords[5] + 5., -1,
								    GOO_CANVAS_ANCHOR_NORTH, NULL);
					retval = browser_canvas_canvas_shape_add_to_list (retval, id, item);
				}
			}
			
			goo_canvas_points_unref (points);
		}
		else {
			GooCanvasPoints *ap, *points;
			GooCanvasItem *item;

			points = goo_canvas_points_new (2);
			ap = goo_canvas_points_new (4);

			if (nb_anchors > 1) {
				if ((dx == 0) && (dy == 0)) {
					/* compute perpendicular to D={(rcx, rcy), (cx, cy)} */
					gdouble vx = (rcx - cx), vy = (rcy - cy);
					gdouble tmp;
					
					tmp = vx;
					vx = vy;
					vy = - tmp;
					
					/* compute intersect of ref_pkey rectangle and D=[vx, vy] passing at (rcx, rcy) */
					if (! compute_intersect_rect_line (rx1, ry1, rx2, ry2,
									   rcx, rcy, rcx + vx, rcy + vy,
									   &(ap->coords[0]), &(ap->coords[1]),
									   &(ap->coords[2]), &(ap->coords[3])))
						return retval;
					dx = (ap->coords[2] - ap->coords[0]) / (gdouble) (nb_anchors  + 1);
					dy = (ap->coords[3] - ap->coords[1]) / (gdouble) (nb_anchors  + 1);
					rux = ap->coords[0];
					ruy = ap->coords[1];
				}

				rux += dx;
				ruy += dy;
			}
			
			/* compute the 4 intersection points */
			if (! compute_intersect_rect_line (rx1, ry1, rx2, ry2,
							   rux, ruy, cx, cy,
							   &(ap->coords[0]), &(ap->coords[1]),
							   &(ap->coords[2]), &(ap->coords[3])))
				return retval;
			if (! compute_intersect_rect_line (fx1, fy1, fx2, fy2,
							   rux, ruy, cx, cy,
							   &(ap->coords[4]), &(ap->coords[5]),
							   &(ap->coords[6]), &(ap->coords[7])))
				return retval;
			
			/* choosing between point coords(0,1) and coords(2,3) */
			if (((ap->coords[0] - ap->coords[4]) * (ap->coords[0] - ap->coords[4]) + 
			     (ap->coords[1] - ap->coords[5]) * (ap->coords[1] - ap->coords[5])) <
			    ((ap->coords[2] - ap->coords[4]) * (ap->coords[2] - ap->coords[4]) + 
			     (ap->coords[3] - ap->coords[5]) * (ap->coords[3] - ap->coords[5]))) {
				points->coords[0] = ap->coords[0];
				points->coords[1] = ap->coords[1];
			}
			else {
				points->coords[0] = ap->coords[2];
				points->coords[1] = ap->coords[3];
			}
			
			/* choosing between point coords(4,5) and coords(6,7) */
			if (((points->coords[0] - ap->coords[4]) * (points->coords[0] - ap->coords[4]) +
			     (points->coords[1] - ap->coords[5]) * (points->coords[1] - ap->coords[5])) <
			    ((points->coords[0] - ap->coords[6]) * (points->coords[0] - ap->coords[6]) +
			     (points->coords[1] - ap->coords[7]) * (points->coords[1] - ap->coords[7]))) {
				points->coords[2] = ap->coords[4];
				points->coords[3] = ap->coords[5];
			}
			else {
				points->coords[2] = ap->coords[6];
				points->coords[3] = ap->coords[7];
			}
			
			id = g_strdup_printf ("a%d", i);
			shape = browser_canvas_canvas_shape_find (retval, id);
			if (shape) {
				g_object_set (shape->item, "points", points, NULL);
				shape->_used = TRUE;
				g_free (id);
			}
			else {
				item = goo_canvas_polyline_new_line (parent, 
								     points->coords[0], points->coords [1],
								     points->coords[2], points->coords [3],
								     "close-path", FALSE,
								     "points", points, NULL);
				retval = browser_canvas_canvas_shape_add_to_list (retval, id, item);
			}
			goo_canvas_points_unref (ap);

			/* extension marks as text */
			if (ext & CANVAS_SHAPE_EXT_JOIN_OUTER_1) {
				gdouble mxoff = 0., myoff = 0.;
				GooCanvasAnchorType atype;

				compute_text_marks_offsets (points->coords[0], points->coords[1], 
							    points->coords[2], points->coords[3],
							    &mxoff, &myoff, &atype);
				id = g_strdup_printf ("a%de1", i);
				shape = browser_canvas_canvas_shape_find (retval, id);
				if (shape) {
					g_object_set (shape->item, 
						      "x", points->coords[2] + mxoff,
						      "y", points->coords[3] + myoff, 
						      "anchor", atype, NULL);
					shape->_used = TRUE;
					g_free (id);
				}
				else {
					item = goo_canvas_text_new (parent, "*", 
								    points->coords[2] + mxoff,
								    points->coords[3] + myoff, -1,
								    atype, NULL);
					retval = browser_canvas_canvas_shape_add_to_list (retval, id, item);
				}
			}

			if (ext & CANVAS_SHAPE_EXT_JOIN_OUTER_2) {
				gdouble mxoff, myoff;
				GooCanvasAnchorType atype;
				
				compute_text_marks_offsets (points->coords[2], points->coords[3], 
							    points->coords[0], points->coords[1],
							    &mxoff, &myoff, &atype);

				id = g_strdup_printf ("a%de2", i);
				if (shape) {
					g_object_set (shape->item, 
						      "x", points->coords[0] + mxoff,
						      "y", points->coords[1] + myoff, 
						      "anchor", atype, NULL);
					shape->_used = TRUE;
					g_free (id);
				}
				else {
					item = goo_canvas_text_new (parent, "*", 
								    points->coords[0] + mxoff,
								    points->coords[1] + myoff, -1,
								    atype, NULL);
					retval = browser_canvas_canvas_shape_add_to_list (retval, id, item);
				}
			}

			goo_canvas_points_unref (points);
		}
	}

	return retval;
}
Example #10
0
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;
}
Example #11
0
// 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;
}
Example #12
0
/*
 * Compute the anchor shapes to link field1 to field2 from ent1 to ent2
 *
 * if @shapes is not NULL, then the shapes in the list are reused, and the ones which don't need
 * to exist anymore are removed
 *
 * Returns a list of BrowserCanvasCanvasShapes structures
 */
GSList *
browser_canvas_util_compute_connect_shapes (GooCanvasItem *parent, GSList *shapes,
					  BrowserCanvasTable *ent1, GdaMetaTableColumn *field1, 
					  BrowserCanvasTable *ent2, GdaMetaTableColumn *field2,
					  guint nb_connect, guint ext)
{
	GSList *retval = shapes;
	GooCanvasItem *item;
	GooCanvasPoints *points;
	gdouble xl1, xr1, xl2, xr2, yt1, yt2; /* X boundings and Y top of ent1 and ent2 */
	gdouble x1, x2; /* X positions of the lines extremities close to ent1 and ent2 */
	gdouble x1offset, x2offset; /* offsets for the horizontal part of the lines */
	double sq = 5.;
	double eps = 0.5;
	GooCanvasBounds bounds;

	BrowserCanvasCanvasShape *shape;
	gchar *id;

	if (!field1 || !field2)
		return browser_canvas_util_compute_anchor_shapes (parent, shapes, ent1, ent2, 1, ext, FALSE);

	/* line made of 4 points */
	points = goo_canvas_points_new (4);
	browser_canvas_table_get_anchor_bounds (ent1, &bounds);
	xl1 = bounds.x1;
	yt1 = bounds.y1;
	xr1 = bounds.x2;
	browser_canvas_table_get_anchor_bounds (ent2, &bounds);
	xl2 = bounds.x1;
	yt2 = bounds.y1;
	xr2 = bounds.x2;

	if (xl2 > xr1) {
		x1 = xr1 + eps;
		x2 = xl2 - eps;
		x1offset = 2 * sq;
		x2offset = -2 * sq;
	}
	else {
		if (xl1 >= xr2) {
			x1 = xl1 - eps;
			x2 = xr2 + eps;
			x1offset = - 2 * sq;
			x2offset = 2 * sq;
		}
		else {
			if ((xl1 + xr1) < (xl2 + xr2)) {
				x1 = xl1 - eps;
				x2 = xl2 - eps;
				x1offset = -2 * sq;
				x2offset = -2 * sq;
			}
			else {
				x1 = xr1 + eps;
				x2 = xr2 + eps;
				x1offset = 2 * sq;
				x2offset = 2 * sq;
			}
		}
	}

	points->coords[0] = x1;
	points->coords[1] = browser_canvas_table_get_column_ypos (ent1, field1) + yt1;

	points->coords[2] = x1 + x1offset;
	points->coords[3] = points->coords[1];

	points->coords[4] = x2 + x2offset;
	points->coords[5] = browser_canvas_table_get_column_ypos (ent2, field2) + yt2;

	points->coords[6] = x2;
	points->coords[7] = points->coords[5];

	id = g_strdup_printf ("c%d", nb_connect);
	shape = browser_canvas_canvas_shape_find (retval, id);
	if (shape) {
		g_object_set (shape->item, "points", points, NULL);
		shape->_used = TRUE;
		g_free (id);
	}
	else {
		item = goo_canvas_polyline_new_line (parent, 
						     points->coords[0], points->coords [1],
						     points->coords[2], points->coords [3],
						     "close-path", FALSE,
						     "points", points, NULL);
		retval = browser_canvas_canvas_shape_add_to_list (retval, id, item);
	}

	/* extension marks as text */
	if (ext & CANVAS_SHAPE_EXT_JOIN_OUTER_1) {
		gdouble mxoff = 0., myoff = 0.;
		GooCanvasAnchorType atype;
		
		compute_text_marks_offsets (points->coords[4], points->coords[5], 
					    points->coords[2], points->coords[3],
					    &mxoff, &myoff, &atype);
		
		id = g_strdup_printf ("ce%d1", nb_connect);
		shape = browser_canvas_canvas_shape_find (retval, id);
		if (shape) {
			g_object_set (shape->item, 
				      "x", points->coords[2] + mxoff,
				      "y", points->coords[3] + myoff, 
				      "anchor", atype, NULL);
			shape->_used = TRUE;
			g_free (id);
		}
		else {
			item = goo_canvas_text_new (parent, "*", 
						    points->coords[2] + mxoff,
						    points->coords[3] + myoff, -1,
						    atype, NULL);
			retval = browser_canvas_canvas_shape_add_to_list (retval, id, item);
		}
	}
	
	if (ext & CANVAS_SHAPE_EXT_JOIN_OUTER_2) {
		gdouble mxoff, myoff;
		GooCanvasAnchorType atype;
		
		compute_text_marks_offsets (points->coords[2], points->coords[3], 
					    points->coords[4], points->coords[5],
					    &mxoff, &myoff, &atype);

		id = g_strdup_printf ("ce%d2", nb_connect);
		shape = browser_canvas_canvas_shape_find (retval, id);
		if (shape) {
			g_object_set (shape->item, 
				      "x", points->coords[2] + mxoff,
				      "y", points->coords[3] + myoff, 
				      "anchor", atype, NULL);
			shape->_used = TRUE;
			g_free (id);
		}
		else {
			item = goo_canvas_text_new (parent, "*", 
						    points->coords[2] + mxoff,
						    points->coords[3] + myoff, -1,
						    atype, NULL);
			retval = browser_canvas_canvas_shape_add_to_list (retval, id, item);
		}
	}

	goo_canvas_points_unref (points);

	return retval;
}
Example #13
0
static void
goo_canvas_polyline_get_common_property (GObject              *object,
					 GooCanvasPolylineData *polyline_data,
					 guint                 prop_id,
					 GValue               *value,
					 GParamSpec           *pspec)
{
  GooCanvasPoints *points;
  GooCanvasBounds  extent;

  switch (prop_id)
    {
    case PROP_POINTS:
      if (polyline_data->num_points == 0)
	{
	  g_value_set_boxed (value, NULL);
	}
      else
	{
	  points = goo_canvas_points_new (polyline_data->num_points);
	  memcpy (points->coords, polyline_data->coords,
		  polyline_data->num_points * 2 * sizeof (double));
	  g_value_set_boxed (value, points);
	  goo_canvas_points_unref (points);
	}
      break;
    case PROP_CLOSE_PATH:
      g_value_set_boolean (value, polyline_data->close_path);
      break;
    case PROP_START_ARROW:
      g_value_set_boolean (value, polyline_data->start_arrow);
      break;
    case PROP_END_ARROW:
      g_value_set_boolean (value, polyline_data->end_arrow);
      break;
    case PROP_ARROW_LENGTH:
      g_value_set_double (value, polyline_data->arrow_data
			  ? polyline_data->arrow_data->arrow_length : 5.0);
      break;
    case PROP_ARROW_WIDTH:
      g_value_set_double (value, polyline_data->arrow_data
			  ? polyline_data->arrow_data->arrow_width : 4.0);
      break;
    case PROP_ARROW_TIP_LENGTH:
      g_value_set_double (value, polyline_data->arrow_data
			  ? polyline_data->arrow_data->arrow_tip_length : 4.0);
      break;
    case PROP_X:
      goo_canvas_polyline_get_extent (polyline_data, &extent);
      g_value_set_double (value, extent.x1);
      break;
    case PROP_Y:
      goo_canvas_polyline_get_extent (polyline_data, &extent);
      g_value_set_double (value, extent.y1);
      break;
    case PROP_WIDTH:
      goo_canvas_polyline_get_extent (polyline_data, &extent);
      g_value_set_double (value, extent.x2 - extent.x1);
      break;
    case PROP_HEIGHT:
      goo_canvas_polyline_get_extent (polyline_data, &extent);
      g_value_set_double (value, extent.y2 - extent.y1);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
  }
}
Example #14
0
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;
}
/** \brief Create polylines. */
static void
create_polylines (GtkSatMap *satmap, sat_t *sat, qth_t *qth, sat_map_obj_t *obj)
{
     ssp_t              *ssp,*buff;     /* map coordinates */
     double             lastx,lasty;
     GSList             *points = NULL;
     GooCanvasItemModel *root;
     GooCanvasItemModel *line;
     GooCanvasPoints    *gpoints;
     guint              start;
     guint              i,j,n,num_points;
     guint32            col;

     (void) sat; /* prevent unused parameter compiler warning */
     (void) qth; /* prevent unused parameter compiler warning */

     /* initialise parameters */
     lastx = -50.0;
     lasty = -50.0;
     start = 0;
     num_points = 0;
     n = g_slist_length (obj->track_data.latlon);
     col = mod_cfg_get_int (satmap->cfgdata,
                                 MOD_CFG_MAP_SECTION,
                                 MOD_CFG_MAP_TRACK_COL,
                                 SAT_CFG_INT_MAP_TRACK_COL);

     /* loop over each SSP */
     for (i = 0; i < n; i++) {

          buff = (ssp_t *) g_slist_nth_data (obj->track_data.latlon, i);
          ssp = g_try_new (ssp_t, 1);
          gtk_sat_map_lonlat_to_xy (satmap, buff->lon, buff->lat, &ssp->lon, &ssp->lat);

          /* if this is the first point, just add it to the list */
          if (i == start) {
               points = g_slist_prepend (points, ssp);
               lastx = ssp->lon;
               lasty = ssp->lat;
          }

          else {

               /* if SSP is on the other side of the map */
               if (ssp_wrap_detected (satmap, lastx, ssp->lon)) {

                    points = g_slist_reverse (points);
                    num_points = g_slist_length (points);

                    /* we need at least 2 points to draw a line */
                    if (num_points > 1) {

                         /* convert SSPs to GooCanvasPoints */
                         gpoints = goo_canvas_points_new (num_points);
                         for (j = 0; j < num_points; j++) {
                              buff = (ssp_t *) g_slist_nth_data (points, j);
                              gpoints->coords[2*j] = buff->lon;
                              gpoints->coords[2*j+1] = buff->lat;
                         }

                         /* create a new polyline using the current set of points */
                         root = goo_canvas_get_root_item_model (GOO_CANVAS (satmap->canvas));

                         line = goo_canvas_polyline_model_new (root, FALSE, 0,
                                                                        "points", gpoints,
                                                                        "line-width", 1.0,
                                                                        "stroke-color-rgba", col,
                                                                        "line-cap", CAIRO_LINE_CAP_SQUARE,
                                                                        "line-join", CAIRO_LINE_JOIN_MITER,
                                                                        NULL);
                         goo_canvas_points_unref (gpoints);
                         goo_canvas_item_model_lower (line, obj->marker);
                         
                         /* store line in sat object */
                         obj->track_data.lines = g_slist_append (obj->track_data.lines, line);

                    }

                    /* reset parameters and continue with a new set */
                    g_slist_foreach (points, free_ssp, NULL);
                    g_slist_free (points);
                    points = NULL;
                    start = i;
                    lastx = ssp->lon;
                    lasty = ssp->lat;
                    num_points = 0;

                    /* Add current SSP to the new list */
                    points = g_slist_prepend (points, ssp);
                    lastx = ssp->lon;
                    lasty = ssp->lat;

               }

               /* else if this SSP is separable from the previous */
               else if ((fabs (lastx - ssp->lon) > 1.0 ) || (fabs(lasty - ssp->lat)>1.0)){

                    /* add SSP to list */
                    points = g_slist_prepend (points, ssp);
                    lastx = ssp->lon;
                    lasty = ssp->lon;

               }

               /* else if  do nothing */

          }
     }

     /* create (last) line if we have at least two points */
     points = g_slist_reverse (points);
     num_points = g_slist_length (points);

     if (num_points > 1) {

          /* convert SSPs to GooCanvasPoints */
          gpoints = goo_canvas_points_new (num_points);
          for (j = 0; j < num_points; j++) {
               buff = (ssp_t *) g_slist_nth_data (points, j);
               gpoints->coords[2*j] = buff->lon;
               gpoints->coords[2*j+1] = buff->lat;
          }

          /* create a new polyline using the current set of points */
          root = goo_canvas_get_root_item_model (GOO_CANVAS (satmap->canvas));

          line = goo_canvas_polyline_model_new (root, FALSE, 0,
                                                         "points", gpoints,
                                                         "line-width", 1.0,
                                                         "stroke-color-rgba", col,
                                                         "line-cap", CAIRO_LINE_CAP_SQUARE,
                                                         "line-join", CAIRO_LINE_JOIN_MITER,
                                                         NULL);
          goo_canvas_points_unref (gpoints);
          goo_canvas_item_model_lower (line, obj->marker);

          /* store line in sat object */
          obj->track_data.lines = g_slist_append (obj->track_data.lines, line);

          /* reset parameters and continue with a new set */
          g_slist_foreach (points, free_ssp, NULL);
          g_slist_free (points);

     }
}
/** \brief Manage toggling of Ground Track.
 *  \param item The menu item that was toggled.
 *  \param data Pointer to the GtkPolarView structure.
 *
 */
static void
        track_toggled (GtkCheckMenuItem *item, gpointer data)
{
    GtkPolarView       *pv = GTK_POLAR_VIEW (data);
    sat_obj_t          *obj = NULL;
    sat_t              *sat;
    qth_t              *qth;
    gint               idx,i;
    GooCanvasItemModel *root;
    pass_detail_t      *detail;
    guint              num;
    GooCanvasPoints    *points;
    gfloat             x,y;
    guint32            col;
    guint              tres,ttidx;


    /* get satellite object */
    obj = SAT_OBJ(g_object_get_data (G_OBJECT (item), "obj"));
    sat = SAT(g_object_get_data (G_OBJECT (item), "sat"));
    qth = (qth_t *)(g_object_get_data (G_OBJECT (item), "qth"));

    if (obj == NULL) {
        sat_log_log (SAT_LOG_LEVEL_BUG,
                     _("%s:%d: Failed to get satellite object."),
                     __FILE__, __LINE__);
        return;
    }

    /* toggle flag */
    obj->showtrack = !obj->showtrack;
    gtk_check_menu_item_set_active (item, obj->showtrack);

    root = goo_canvas_get_root_item_model (GOO_CANVAS (pv->canvas));

    if (obj->showtrack) {
        /* add sky track */

        /* create points */
        num = g_slist_length (obj->pass->details);
        if (num == 0) {
            sat_log_log (SAT_LOG_LEVEL_BUG,
                         _("%s:%d: Pass has no details."),
                         __FILE__, __LINE__);
            return;
        }

        /* time resolution for time ticks; we need
                   3 additional points to AOS and LOS ticks.
                */
        tres = (num-2) / (TRACK_TICK_NUM-1);

        points = goo_canvas_points_new (num);

        /* first point should be (aos_az,0.0) */
        azel_to_xy (pv, obj->pass->aos_az, 0.0, &x, &y);
        points->coords[0] = (double) x;
        points->coords[1] = (double) y;
        obj->trtick[0] = create_time_tick (pv, obj->pass->aos, x, y);

        ttidx = 1;

        for (i = 1; i < num-1; i++) {
            detail = PASS_DETAIL(g_slist_nth_data (obj->pass->details, i));
            if (detail->el >=0.0)
                azel_to_xy (pv, detail->az, detail->el, &x, &y);
            points->coords[2*i] = (double) x;
            points->coords[2*i+1] = (double) y;

            if (!(i % tres)) {
                /* create a time tick */
                if (ttidx<TRACK_TICK_NUM)
                    obj->trtick[ttidx] = create_time_tick (pv, detail->time, x, y);
                ttidx++;
            }
        }

        /* last point should be (los_az, 0.0)  */
        azel_to_xy (pv, obj->pass->los_az, 0.0, &x, &y);
        points->coords[2*(num-1)] = (double) x;
        points->coords[2*(num-1)+1] = (double) y;

        /* create poly-line */
        col = mod_cfg_get_int (pv->cfgdata,
                               MOD_CFG_POLAR_SECTION,
                               MOD_CFG_POLAR_TRACK_COL,
                               SAT_CFG_INT_POLAR_TRACK_COL);

        obj->track = goo_canvas_polyline_model_new (root, FALSE, 0,
                                                    "points", points,
                                                    "line-width", 1.0,
                                                    "stroke-color-rgba", col,
                                                    "line-cap", CAIRO_LINE_CAP_SQUARE,
                                                    "line-join", CAIRO_LINE_JOIN_MITER,
                                                    NULL);
        goo_canvas_points_unref (points);

        /* put track on the bottom of the sack */
        goo_canvas_item_model_lower (obj->track, NULL);

    }
    else {
        /* delete sky track */
        idx = goo_canvas_item_model_find_child (root, obj->track);

        if (idx != -1) {
            goo_canvas_item_model_remove_child (root, idx);
        }

        for (i = 0; i < TRACK_TICK_NUM; i++) {
            idx = goo_canvas_item_model_find_child (root, obj->trtick[i]);

            if (idx != -1) {
                goo_canvas_item_model_remove_child (root, idx);
            }
        }
    }

}
Example #17
0
static VALUE
rg_initialize(VALUE self, VALUE num_points)
{
    G_INITIALIZE(self, goo_canvas_points_new(NUM2INT(num_points)));
    return Qnil;
}
Example #18
0
static void
set_arrow_shape (GooCanvas *canvas)
{
	int width;
	int shape_a, shape_b, shape_c;
	GooCanvasPoints *points;
	char buf[100];

	width = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (canvas), "width"));
	shape_a = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (canvas), "shape_a"));
	shape_b = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (canvas), "shape_b"));
	shape_c = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (canvas), "shape_c"));

	/* Big arrow */

	g_object_set (g_object_get_data (G_OBJECT (canvas), "big_arrow"),
		      "line-width", 10.0 * width,
		      "arrow-tip-length", (double) (shape_a),
		      "arrow-length", (double) (shape_b),
		      "arrow-width", (double) (shape_c),
		      NULL);

	/* Outline */

	points = goo_canvas_points_new (5);
	points->coords[0] = RIGHT - 10 * shape_a * width;
	points->coords[1] = MIDDLE - 10 * width / 2;
	points->coords[2] = RIGHT - 10 * shape_b * width;
	points->coords[3] = MIDDLE - 10 * (shape_c * width / 2.0);
	points->coords[4] = RIGHT;
	points->coords[5] = MIDDLE;
	points->coords[6] = points->coords[2];
	points->coords[7] = MIDDLE + 10 * (shape_c * width / 2.0);
	points->coords[8] = points->coords[0];
	points->coords[9] = MIDDLE + 10 * width / 2;
	g_object_set (g_object_get_data (G_OBJECT (canvas), "outline"),
		      "points", points,
		      NULL);
	goo_canvas_points_unref (points);

	/* Drag boxes */

	move_drag_box (g_object_get_data (G_OBJECT (canvas), "width_drag_box"),
		       LEFT,
		       MIDDLE - 10 * width / 2.0);

	move_drag_box (g_object_get_data (G_OBJECT (canvas), "shape_a_drag_box"),
		       RIGHT - 10 * shape_a * width,
		       MIDDLE);

	move_drag_box (g_object_get_data (G_OBJECT (canvas), "shape_b_c_drag_box"),
		       RIGHT - 10 * shape_b * width,
		       MIDDLE - 10 * (shape_c * width / 2.0));

	/* Dimensions */

	set_dimension (canvas, "width_arrow", "width_text",
		       LEFT - 10,
		       MIDDLE - 10 * width / 2.0,
		       LEFT - 10,
		       MIDDLE + 10 * width / 2.0,
		       LEFT - 15,
		       MIDDLE,
		       width);

	set_dimension (canvas, "shape_a_arrow", "shape_a_text",
		       RIGHT - 10 * shape_a * width,
		       MIDDLE + 10 * (shape_c * width / 2.0) + 10,
		       RIGHT,
		       MIDDLE + 10 * (shape_c * width / 2.0) + 10,
		       RIGHT - 10 * shape_a * width / 2.0,
		       MIDDLE + 10 * (shape_c * width / 2.0) + 15,
		       shape_a);

	set_dimension (canvas, "shape_b_arrow", "shape_b_text",
		       RIGHT - 10 * shape_b * width,
		       MIDDLE + 10 * (shape_c * width / 2.0) + 35,
		       RIGHT,
		       MIDDLE + 10 * (shape_c * width / 2.0) + 35,
		       RIGHT - 10 * shape_b * width / 2.0,
		       MIDDLE + 10 * (shape_c * width / 2.0) + 40,
		       shape_b);

	set_dimension (canvas, "shape_c_arrow", "shape_c_text",
		       RIGHT + 10,
		       MIDDLE - 10 * shape_c * width / 2.0,
		       RIGHT + 10,
		       MIDDLE + 10 * shape_c * width / 2.0,
		       RIGHT + 15,
		       MIDDLE,
		       shape_c);

	/* Info */

	sprintf (buf, "line-width: %d", width);
	g_object_set (g_object_get_data (G_OBJECT (canvas), "width_info"),
		      "text", buf,
		      NULL);

	sprintf (buf, "arrow-tip-length: %d (* line-width)", shape_a);
	g_object_set (g_object_get_data (G_OBJECT (canvas), "shape_a_info"),
		      "text", buf,
		      NULL);

	sprintf (buf, "arrow-length: %d (* line-width)", shape_b);
	g_object_set (g_object_get_data (G_OBJECT (canvas), "shape_b_info"),
		      "text", buf,
		      NULL);
	sprintf (buf, "arrow-width: %d (* line-width)", shape_c);
	g_object_set (g_object_get_data (G_OBJECT (canvas), "shape_c_info"),
		      "text", buf,
		      NULL);

	/* Sample arrows */

	g_object_set (g_object_get_data (G_OBJECT (canvas), "sample_1"),
		      "line-width", (double) width,
		      "arrow-tip-length", (double) shape_a,
		      "arrow-length", (double) shape_b,
		      "arrow-width", (double) shape_c,
		      NULL);
	g_object_set (g_object_get_data (G_OBJECT (canvas), "sample_2"),
		      "line-width", (double) width,
		      "arrow-tip-length", (double) shape_a,
		      "arrow-length", (double) shape_b,
		      "arrow-width", (double) shape_c,
		      NULL);
	g_object_set (g_object_get_data (G_OBJECT (canvas), "sample_3"),
		      "line-width", (double) width,
		      "arrow-tip-length", (double) shape_a,
		      "arrow-length", (double) shape_b,
		      "arrow-width", (double) shape_c,
		      NULL);
}
Example #19
0
/*
 * Display a random wind speed
 */
static void display_windspeed()
{
  guint second = 0;
  guint needle_zoom = 15;
  gchar *tmpstr;
  GooCanvasPoints *canvasPoints;
  canvasPoints = goo_canvas_points_new (2);

  if(speedRootItem!=NULL)
    goo_canvas_item_remove(speedRootItem);

  speedRootItem = goo_canvas_group_new (goo_canvas_get_root_item(gcomprisBoard->canvas),
					NULL);


  /* Speed orientation */
  second = g_random_int()%60;
  ang = second * M_PI / 30;

  /* Speed force */
  wind_speed = targetDefinition[gcomprisBoard->level-1].target_min_wind_speed \
    + g_random_int()%(targetDefinition[gcomprisBoard->level-1].target_max_wind_speed \
	      - targetDefinition[gcomprisBoard->level-1].target_min_wind_speed);

  canvasPoints->coords[0]=SPEED_CENTER_X;
  canvasPoints->coords[1]=SPEED_CENTER_Y;
  canvasPoints->coords[2]=SPEED_CENTER_X + wind_speed * sin(ang) * needle_zoom;
  canvasPoints->coords[3]=SPEED_CENTER_Y - wind_speed * cos(ang) * needle_zoom;
  double w = 4.0;
  goo_canvas_polyline_new (speedRootItem, FALSE, 0,
			   "points", canvasPoints,
			   "stroke-color-rgba", 0Xa05a2cffL,
			   "fill-color-rgba", 0Xa05a2cffL,
			   "line-width", w,
			   "end-arrow", TRUE,
			   "arrow-tip-length", 7.0,
			   "arrow-length", 5.0,
			   "arrow-width", 4.0,
			   NULL);

  goo_canvas_points_unref(canvasPoints);

  /* Draw the center of the speedometer */
  goo_canvas_ellipse_new (speedRootItem,
			 SPEED_CENTER_X,
			 SPEED_CENTER_Y,
			 10.0,
			 10.0,
			 "fill_color_rgba", 0Xa05a2cffL,
			 "stroke-color", "black",
			 "line-width", (double)2,
			 NULL);

  tmpstr = g_strdup_printf(_("Wind speed = %d\nkilometers/hour"), (guint)wind_speed);
  goo_canvas_text_new (speedRootItem,
		       tmpstr,
		       (double) SPEED_CENTER_X,
		       (double) SPEED_CENTER_Y + 110,
		       -1,
		       GTK_ANCHOR_CENTER,
		       "font", gc_skin_font_board_medium,
		       "fill-color", "white",
		       NULL);
  g_free(tmpstr);

}