Example #1
0
static void
gst_editor_link_resize (GstEditorLink * link)
{
  gdouble x1, y1, x2, y2;

  GooCanvas * canvas;

  g_object_get (link, "x1", &x1, "y1", &y1, "x2", &x2, "y2", &y2, NULL);
  canvas = goo_canvas_item_get_canvas (GOO_CANVAS_ITEM (link));
  if (!canvas) {
    g_print ("Warning: gst_editor_link_resize canvas null\n");
    return;
  }
  goo_canvas_convert_from_pixels (canvas, &x1, &y1);
  goo_canvas_convert_to_item_space (canvas, GOO_CANVAS_ITEM (link), &x1, &y1);

  // goo_canvas_item_get_parent(GOO_CANVAS_ITEM (link)),&x1, &y1);
  goo_canvas_convert_from_pixels (canvas, &x2, &y2);
  goo_canvas_convert_to_item_space (canvas, GOO_CANVAS_ITEM (link), &x2, &y2);

  // goo_canvas_item_get_parent(GOO_CANVAS_ITEM (link)), &x2, &y2);
  /* we do this in reverse so that with dot-dash lines it gives the illusion of
     pulling out a rope from the element */
  link->points->coords[2] = x1;
  link->points->coords[3] = y1;
  link->points->coords[0] = x2;
  link->points->coords[1] = y2;
  g_object_set (G_OBJECT (link), "points", link->points, NULL);
}
Example #2
0
/**
 * get the pointer position in goocanvas coordinates
 *
 * @attention shall not be called in event callbacks,
 * except for GDK_MOTION_... where it is useless since
 * the event itself contains the cursor position
 */
gboolean sheet_get_pointer (Sheet *sheet, gdouble *x, gdouble *y)
{
	if (!sheet_get_pointer_pixel (sheet, x, y))
		return FALSE;
	goo_canvas_convert_from_pixels (GOO_CANVAS (sheet), x, y);
	return TRUE;
}
Example #3
0
gboolean
rubberband_update (Sheet *sheet, GdkEvent *event)
{
	GList *iter;
	Coords cur, cmin, cmax;
	double dx, dy; // TODO maybe keep track of subpixel changes, make em global/part of the rubberband_info struct and reset on finish
	double width, height,
	       width_ng, height_ng;
	RubberbandInfo *rubberband_info;

	rubberband_info = sheet->priv->rubberband_info;

	g_assert (event->type == GDK_MOTION_NOTIFY);
	cur.x = event->motion.x;
	cur.y = event->motion.y;
	goo_canvas_convert_from_pixels (GOO_CANVAS (sheet), &cur.x, &cur.y);

	width  = fabs(rubberband_info->end.x - rubberband_info->start.x);
	height = fabs(rubberband_info->end.y - rubberband_info->start.y);

	width_ng  = fabs(cur.x - rubberband_info->start.x);
	height_ng = fabs(cur.y - rubberband_info->start.y);

	dx = fabs (width_ng - width);
	dy = fabs (height_ng - height);
	NG_DEBUG ("motion :: dx=%lf, dy=%lf :: x=%lf, y=%lf :: w_ng=%lf, h_ng=%lf", dx, dy, cur.x, cur.y, width_ng, height_ng);

	// TODO FIXME scroll window if needed (use http://developer.gnome.org/goocanvas/stable/GooCanvas.html#goo-canvas-scroll-to)

	if (dx > 0.1 || dy > 0.1) { //a 0.1 change in pixel coords would be the least visible, silently ignore everything else
		rubberband_info->end.x = cur.x;
		rubberband_info->end.y = cur.y;
		cmin.x = MIN(rubberband_info->start.x, rubberband_info->end.x);
		cmin.y = MIN(rubberband_info->start.y, rubberband_info->end.y);
		cmax.x = cmin.x + width_ng;
		cmax.y = cmin.y + height_ng;
#if 1
		for (iter = sheet->priv->items; iter; iter = iter->next) {
			sheet_item_select_in_area (iter->data,
			                           &cmin,
			                           &cmax);
		}
#endif

		g_object_set (GOO_CANVAS_ITEM (rubberband_info->rectangle),
		              "x", cmin.x,
		              "y", cmin.y,
		              "width", width_ng, 
		              "height", height_ng,
		              "visibility", GOO_CANVAS_ITEM_VISIBLE,
		              NULL);
		goo_canvas_item_raise (GOO_CANVAS_ITEM (rubberband_info->rectangle), NULL);
	}
	return TRUE;
}
Example #4
0
void		
sheet_get_pointer (Sheet *sheet, gdouble *x, gdouble *y)
{
	GtkWidget        *widget;
	GtkAdjustment    *hadjustment;
	GtkAdjustment    *vadjustment;
	gdouble           value, x1, y1;
	gint              _x, _y;
	GdkDeviceManager *device_manager;
    GdkDevice        *device_pointer;
    GdkRectangle      allocation;


	// gtk_widget_get_pointer (GTK_WIDGET (sheet), &_x, &_y);
	// replaced by a code copied from evince
	
    if (!gtk_widget_get_realized (GTK_WIDGET (sheet)))
    	return;
	
	device_manager = gdk_display_get_device_manager (
	                gtk_widget_get_display (GTK_WIDGET (sheet)));
    device_pointer = gdk_device_manager_get_client_pointer (device_manager);
    gdk_window_get_device_position (gtk_widget_get_window (GTK_WIDGET (sheet)),
                    device_pointer,
                    &_x, &_y, NULL);
	if (!gtk_widget_get_has_window (GTK_WIDGET (sheet)))
    	return;
	
	gtk_widget_get_allocation (GTK_WIDGET (sheet), &allocation);
	
	_x -= allocation.x;
	_y -= allocation.y;

	x1 = (gdouble) _x;
	y1 = (gdouble) _y;
	
	widget = gtk_widget_get_parent (GTK_WIDGET (sheet));
	hadjustment =  gtk_scrolled_window_get_hadjustment (
	                 GTK_SCROLLED_WINDOW (widget));
	value = gtk_adjustment_get_value (hadjustment);

	x1 += value;
	vadjustment =  gtk_scrolled_window_get_vadjustment (
	                 GTK_SCROLLED_WINDOW (widget));
	value = gtk_adjustment_get_value (vadjustment);
	y1 += value;
	*x = x1;
	*y = y1;
	goo_canvas_convert_from_pixels (GOO_CANVAS (sheet), x, y);
	snap_to_grid (sheet->grid, x, y);
}
Example #5
0
/* get scroll position in meters */
void canvas_t::scroll_get(int &sx, int &sy) const {
  GooCanvas *gc = GOO_CANVAS(widget);
  gdouble zoom = goo_canvas_get_scale(gc);

  gdouble hs = gtk_adjustment_get_value(gc->hadjustment);
  gdouble vs = gtk_adjustment_get_value(gc->vadjustment);
  goo_canvas_convert_from_pixels(gc, &hs, &vs);

  /* convert to position relative to screen center */
  hs += widget->allocation.width/(2*zoom);
  vs += widget->allocation.height/(2*zoom);

  sx = hs;
  sy = vs;
}
Example #6
0
void canvas_t::scroll_step(const osm2go_platform::screenpos &d, int &nx, int &ny)
{
  GooCanvas *gc = GOO_CANVAS(widget);
  gdouble hs = gtk_adjustment_get_value(gc->hadjustment) + d.x();
  gdouble vs = gtk_adjustment_get_value(gc->vadjustment) + d.y();
  goo_canvas_convert_from_pixels(gc, &hs, &vs);

  gdouble zoom = goo_canvas_get_scale(gc);

  // this is intentionally not using scroll_to() as that would result in
  // double -> int -> double conversions and loss of precision
  scrollvalue s = boundedScroll(static_cast<canvas_goocanvas *>(this),
                                scrollvalue(hs + widget->allocation.width / (2 * zoom),
                                            vs + widget->allocation.height / (2 * zoom)));

  nx = s.x;
  ny = s.y;
}
Example #7
0
gboolean
rubberband_start (Sheet *sheet, GdkEvent *event)
{
	GList *list;
	double x, y;
	RubberbandInfo *rubberband_info;

	g_assert (event->type == GDK_BUTTON_PRESS);
	x = event->button.x;
	y = event->button.y;
	goo_canvas_convert_from_pixels (GOO_CANVAS (sheet), &x, &y);
	
	rubberband_info = sheet->priv->rubberband_info;
	rubberband_info->start.x = x; 
	rubberband_info->start.y = y;
	rubberband_info->end.x = x; 
	rubberband_info->end.y = y;
	rubberband_info->state = RUBBERBAND_ACTIVE;
	
	//FIXME TODO recheck
	g_assert (rubberband_info->rectangle!=NULL);
	g_object_set (rubberband_info->rectangle,
	              "x", x,
	              "y", y,
	              "width", 0., 
	              "height", 0.,
	              "visibility", GOO_CANVAS_ITEM_VISIBLE,
	              NULL);
#if 1
	// Mark all the selected objects to preserve their selected state
	// if SHIFT is pressed while rubberbanding.
	if (event->button.state & GDK_SHIFT_MASK) {
		for (list = sheet->priv->selected_objects; list; list = list->next)
			sheet_item_set_preserve_selection (SHEET_ITEM (list->data), TRUE);

		sheet->priv->preserve_selection_items = 
		                   g_list_copy (sheet->priv->selected_objects);
	}
#endif

	sheet_pointer_grab (sheet, event);
	return TRUE;
}
Example #8
0
void 
sheet_setup_rubberband (Sheet *sheet, GdkEventButton *event)
{
	double x, y;
	cairo_pattern_t *pattern;
	static guchar stipple_data[16] = 
	{0, 0, 0, 255,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 255 };

	x = event->x; //the x coordinate of the pointer relative to the window.
	y = event->y; //the y coordinate of the pointer relative to the window.
	goo_canvas_convert_from_pixels (GOO_CANVAS (sheet), &x, &y);

	sheet->priv->rubberband->start_x = x;
	sheet->priv->rubberband->start_y = y;

	sheet->priv->rubberband->state = RUBBER_YES;
	sheet->priv->rubberband->click_start_state = event->state;

	pattern = create_stipple ("lightgrey", stipple_data);

	sheet->priv->rubberband->rectangle = goo_canvas_rect_new (
		GOO_CANVAS_ITEM (sheet->object_group), 
	    x, y, 0.0, 0.0, 
	    "stroke-color", "black",
	    "line-width", 0.2,
	    "fill-pattern", pattern,
	    NULL);

	goo_canvas_pointer_grab (GOO_CANVAS (sheet), GOO_CANVAS_ITEM (sheet->grid), 
		(GDK_POINTER_MOTION_MASK | GDK_BUTTON_RELEASE_MASK),
	    NULL, event->time);
	
	// Mark all the selected objects to preserve their selected state
	// if SHIFT is pressed while rubberbanding.
	if (event->state & GDK_SHIFT_MASK) {
		sheet->priv->preserve_selection_items = 
			g_list_copy (sheet_preserve_selection (sheet));
	}

}
Example #9
0
/*
 * change the zoom by factor <rate>
 * zoom origin when zooming in is the cursor
 * zoom origin when zooming out is the center of the current viewport
 * sane <rate> values are in range of [0.5 .. 2]
 */
void
sheet_change_zoom (Sheet *sheet, gdouble rate)
{
	g_return_if_fail (sheet);
	g_return_if_fail (IS_SHEET (sheet));
//////////////////////////////////////////////7

	gdouble x, y;
	gdouble rx, ry;
	gdouble px, py;
	gdouble dx, dy;
	gdouble cx, cy;
	gdouble dcx, dcy;
	GtkAdjustment *hadj, *vadj;
	GooCanvas *canvas;

	canvas = GOO_CANVAS (sheet);

	// if we scroll out, just scroll to the center
	if (rate < 1.) {
		goo_canvas_set_scale (canvas, rate * goo_canvas_get_scale (canvas));
		return;
	}

	// top left corner in pixels
	if (sheet_get_adjustments (sheet, &hadj, &vadj)) {
		x = gtk_adjustment_get_value (hadj);
		y = gtk_adjustment_get_value (vadj);
	} else {
		x = y = 0.;
	}

	// get pointer position in pixels
	sheet_get_pointer_pixel (sheet, &px, &py);

	// get the page size in pixels
	dx = gtk_adjustment_get_page_size (hadj);
	dy = gtk_adjustment_get_page_size (vadj);
	// calculate the center of the widget in pixels
	cx = x + dx/2;
	cy = y + dy/2;
	
	// calculate the delta between the center and the pointer in pixels
	// this is required as the center is the zoom target
	dcx = px - cx;
	dcy = py - cy;

	// increase the top left position in pixels by our calculated delta
	x += dcx;
	y += dcy;

	//convert to canvas coords
	goo_canvas_convert_from_pixels (canvas, &x, &y);

	//the center of the canvas is now our cursor position
	goo_canvas_scroll_to (canvas, x, y);

	//calculate a correction term
	//for the case that we can not scroll the pane far enough to
	//compensate the whole off-due-to-wrong-center-error
	rx = gtk_adjustment_get_value (hadj);
	ry = gtk_adjustment_get_value (vadj);
	goo_canvas_convert_from_pixels (canvas, &rx, &ry);
	//the correction term in goo coordinates, to be subtracted from the backscroll distance
	rx -= x;
	ry -= y;

	// no the center is our cursor position and we can safely call scale
	goo_canvas_set_scale (canvas, rate * goo_canvas_get_scale (canvas));

	// top left corner in pixels after scaling
	if (sheet_get_adjustments (sheet, &hadj, &vadj)) {
		x = gtk_adjustment_get_value (hadj);
		y = gtk_adjustment_get_value (vadj);
	} else {
		x = y = 0.;
	}
	// not sure if the below part is required, could be zer0
	NG_DEBUG ("rx %lf\n", rx);
	NG_DEBUG ("ry %lf\n", ry);
	NG_DEBUG ("dcx %lf\n", dcx);
	NG_DEBUG ("dcy %lf\n", dcy);
	NG_DEBUG ("\n\n");
	// gtk_adjustment_get_page_size is constant
	x -= (dcx) / sheet->priv->zoom;
	y -= (dcy) / sheet->priv->zoom;
	goo_canvas_convert_from_pixels (canvas, &x, &y);

	goo_canvas_scroll_to (canvas, x-rx, y-ry);

	gtk_widget_queue_draw (GTK_WIDGET (canvas));
}
Example #10
0
/**
 * change the zoom by factor
 *
 * zoom origin when zooming in is the cursor
 * zoom origin when zooming out is the center of the current viewport
 *
 * @param sheet
 * @param factor values should be in the range of [0.5 .. 2]
 */
void
sheet_change_zoom (Sheet *sheet, gdouble factor)
{
	g_return_if_fail (sheet);
	g_return_if_fail (IS_SHEET (sheet));

	Coords adju, r, pointer, delta, center, pagesize;
	GtkAdjustment *hadj = NULL, *vadj = NULL;
	GooCanvas *canvas;
	gboolean b = FALSE;

	canvas = GOO_CANVAS (sheet);

	// if we scroll out, just use the center as focus
	// mouse curser centered scroll out "feels" awkward
	if (factor < 1.) {
		goo_canvas_set_scale (canvas, factor * goo_canvas_get_scale (canvas));
		return;
	}

	// get pointer position in pixels
	// just skip the correction if we can not get the pointer
	if (!sheet_get_pointer_pixel (sheet, &pointer.x, &pointer.y)) {
		goo_canvas_set_scale (canvas, factor * goo_canvas_get_scale (canvas));
		g_warning ("Failed to get cursor position.");
		return;
	}

	// top left corner in pixels
	b = sheet_get_adjustments (sheet, &hadj, &vadj);
	if (b) {
		adju.x = gtk_adjustment_get_value (hadj);
		adju.y = gtk_adjustment_get_value (vadj);
		// get the page size in pixels
		pagesize.x = gtk_adjustment_get_page_size (hadj);
		pagesize.y = gtk_adjustment_get_page_size (vadj);
	} else {
		//FIXME untested codepath, check for variable space conversion
		//FIXME Pixel vs GooUnits
		gdouble left, right, top, bottom;
		goo_canvas_get_bounds (canvas, &left, &top, &right, &bottom);
		pagesize.x = bottom - top;
		pagesize.y = right - left;
		adju.x = adju.y = 0.;
	}

	// calculate the center of the widget in pixels
	center.x = adju.x + pagesize.x/2.;
	center.y = adju.y + pagesize.y/2.;

	// calculate the delta between the center and the pointer in pixels
	// this is required as the center is the zoom target
	delta.x = pointer.x - center.x;
	delta.y = pointer.y - center.y;

	// increase the top left position in pixels by our calculated delta
	adju.x += delta.x;
	adju.y += delta.y;

	//convert to canvas coords
	goo_canvas_convert_from_pixels (canvas, &adju.x, &adju.y);

	//the center of the canvas is now our cursor position
	goo_canvas_scroll_to (canvas, adju.x, adju.y);

	//calculate a correction term
	//for the case that we can not scroll the pane far enough to
	//compensate the whole off-due-to-wrong-center-error

	if (b) {
		r.x = gtk_adjustment_get_value (hadj);
		r.y = gtk_adjustment_get_value (vadj);
		goo_canvas_convert_from_pixels (canvas, &r.x, &r.y);
		//the correction term in goo coordinates, to be subtracted from the backscroll distance
		r.x -= adju.x;
		r.y -= adju.y;
	} else {
		r.x = r.y = 0.;
	}

	// no the center is our cursor position and we can safely call scale
	goo_canvas_set_scale (canvas, factor * goo_canvas_get_scale (canvas));

	// top left corner in pixels after scaling
	if (b) {
		adju.x = gtk_adjustment_get_value (hadj);
		adju.y = gtk_adjustment_get_value (vadj);
	} else {
		adju.x = adju.y = 0.;
	}

	// gtk_adjustment_get_page_size is constant before and after scale
	adju.x -= (delta.x) / sheet->priv->zoom;
	adju.y -= (delta.y) / sheet->priv->zoom;
	goo_canvas_convert_from_pixels (canvas, &adju.x, &adju.y);

	goo_canvas_scroll_to (canvas, adju.x-r.x, adju.y-r.y);

	gtk_widget_queue_draw (GTK_WIDGET (canvas));
}
Example #11
0
lpos_t canvas_t::window2world(const osm2go_platform::screenpos &p) const
{
  double sx = p.x(), sy = p.y();
  goo_canvas_convert_from_pixels(GOO_CANVAS(widget), &sx, &sy);
  return lpos_t(sx, sy);
}