Ejemplo n.º 1
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));
}
Ejemplo n.º 2
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));
}
Ejemplo n.º 3
0
/**
 * ppg_visualizer_task_notify_state:
 * @visualizer: (in): A #PpgVisualizer.
 * @pspec: (in): A #GParamSpec.
 * @task: (in): A #PpgTask.
 *
 * Handle the "notify::state" signal from @task. Update the visualizer
 * pattern if necessary.
 *
 * Returns: None.
 * Side effects: None.
 */
static void
ppg_visualizer_task_notify_state (PpgVisualizer *visualizer,
                                  GParamSpec    *pspec,
                                  PpgTask       *task)
{
	PpgVisualizerPrivate *priv;
	cairo_surface_t *surface;
	PpgTaskState state;
	cairo_t *cr;
	gdouble begin_time;
	gdouble height;
	gdouble total_width;
	gdouble span;
	gdouble width;
	gdouble x;
	gdouble y;

	g_return_if_fail(PPG_IS_VISUALIZER(visualizer));
	g_return_if_fail(PPG_IS_TASK(task));
	g_return_if_fail(visualizer->priv->surface);

	priv = visualizer->priv;

	/*
	 * We don't own the reference, so safe to just drop our pointer. Using
	 * GObjects weak pointers here would be a lot of maintenance pain.
	 */
	if (priv->task == task) {
		priv->task = NULL;
	}

	g_object_get(task,
	             "state", &state,
	             "surface", &surface,
	             NULL);

	if (state == PPG_TASK_SUCCESS) {
		g_object_get(task,
		             "begin-time", &begin_time,
		             "height", &height,
		             "width", &width,
		             "x", &x,
		             "y", &y,
		             NULL);

		span = priv->end_time - priv->begin_time;
		g_object_get(visualizer, "width", &total_width, NULL);
		x = (begin_time - priv->begin_time) / span * total_width;

		/*
		 * Only draw what we can do on integer aligned offsets.
		 *
		 * TODO: We need to make sure we render extra area to prevent
		 *       a striping effect.
		 */
		width -= ceil(x) - x;
		x = ceil(x);

		cr = cairo_create(priv->surface);
		cairo_set_source_surface(cr, surface, x, y);
		if (cairo_status(cr) != 0) {
			cairo_destroy(cr);
			GOTO(failure);
		}

		/*
		 * Clip the range of the draw.
		 */
		cairo_rectangle(cr, x, y, width, height);
		cairo_clip_preserve(cr);

		/*
		 * Clear the draw area.
		 */
		cairo_save(cr);
		cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
		cairo_fill_preserve(cr);
		cairo_restore(cr);

		/*
		 * Fill in the rendered image.
		 */
		cairo_fill(cr);
		cairo_destroy(cr);

		goo_canvas_item_request_update(GOO_CANVAS_ITEM(visualizer));
	}

  failure:
	/*
	 * Release our surface that was allocated for the draw request.
	 */
	if ((state & PPG_TASK_FINISHED_MASK) != 0) {
		cairo_surface_destroy(surface);
	}
}