diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2011-01-16 00:52:43 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2011-01-16 01:11:31 +0800 |
commit | d1b440a268b6f43f86114df12b543f7e7c6d6588 (patch) | |
tree | 8717cb7ffa86737f3344917062bacdc746e570bd /libgnomecanvas | |
parent | a4d8c30310cfcd95a54153930336ff8196adde76 (diff) | |
download | gsoc2013-evolution-d1b440a268b6f43f86114df12b543f7e7c6d6588.tar.gz gsoc2013-evolution-d1b440a268b6f43f86114df12b543f7e7c6d6588.tar.zst gsoc2013-evolution-d1b440a268b6f43f86114df12b543f7e7c6d6588.zip |
Remove some unused gnome-canvas options.
Simplifies the drawing code a bit.
Public API removed:
GnomeCanvas.center_scroll_region (is always TRUE)
GnomeCanvas.pixels_per_unit (is always 1.0)
gnome_canvas_set_center_scroll_region()
gnome_canvas_get_center_scroll_region()
gnome_canvas_set_pixels_per_unit()
Diffstat (limited to 'libgnomecanvas')
-rw-r--r-- | libgnomecanvas/gnome-canvas-rich-text.c | 20 | ||||
-rw-r--r-- | libgnomecanvas/gnome-canvas-text.c | 12 | ||||
-rw-r--r-- | libgnomecanvas/gnome-canvas-widget.c | 13 | ||||
-rw-r--r-- | libgnomecanvas/gnome-canvas.c | 188 | ||||
-rw-r--r-- | libgnomecanvas/gnome-canvas.h | 17 |
5 files changed, 34 insertions, 216 deletions
diff --git a/libgnomecanvas/gnome-canvas-rich-text.c b/libgnomecanvas/gnome-canvas-rich-text.c index 16fa5dce41..87804bdc1c 100644 --- a/libgnomecanvas/gnome-canvas-rich-text.c +++ b/libgnomecanvas/gnome-canvas-rich-text.c @@ -902,10 +902,8 @@ selection_motion_event_handler (GnomeCanvasRichText *text, GdkEvent *event, if (event->type != GDK_MOTION_NOTIFY) return FALSE; - newx = (event->motion.x - text->_priv->x) * - GNOME_CANVAS_ITEM (text)->canvas->pixels_per_unit; - newy = (event->motion.y - text->_priv->y) * - GNOME_CANVAS_ITEM (text)->canvas->pixels_per_unit; + newx = (event->motion.x - text->_priv->x); + newy = (event->motion.y - text->_priv->y); gtk_text_layout_get_iter_at_pixel (text->_priv->layout, &newplace, newx, newy); mark = gtk_text_buffer_get_mark(get_buffer(text), "insert"); @@ -1223,8 +1221,8 @@ gnome_canvas_rich_text_button_press_event (GnomeCanvasItem *item, GdkEventType event_type; gdouble newx, newy; - newx = (event->x - text->_priv->x) * item->canvas->pixels_per_unit; - newy = (event->y - text->_priv->y) * item->canvas->pixels_per_unit; + newx = (event->x - text->_priv->x); + newy = (event->y - text->_priv->y); gtk_text_layout_get_iter_at_pixel (text->_priv->layout, &iter, newx, newy); @@ -1352,8 +1350,8 @@ gnome_canvas_rich_text_button_release_event (GnomeCanvasItem *item, GnomeCanvasRichText *text = GNOME_CANVAS_RICH_TEXT (item); gdouble newx, newy; - newx = (event->x - text->_priv->x) * item->canvas->pixels_per_unit; - newy = (event->y - text->_priv->y) * item->canvas->pixels_per_unit; + newx = (event->x - text->_priv->x); + newy = (event->y - text->_priv->y); if (event->button == 1) { if (text->_priv->drag_start_x >= 0) { @@ -1714,12 +1712,10 @@ changed_handler (GtkTextLayout *layout, gint start_y, printf("Layout %p is being changed.\n", text->_priv->layout); #endif - if (text->_priv->layout->default_style->font_scale != - GNOME_CANVAS_ITEM (text)->canvas->pixels_per_unit) { + if (text->_priv->layout->default_style->font_scale != 1.0) { GtkTextTagTable *tag_table; - text->_priv->layout->default_style->font_scale = - GNOME_CANVAS_ITEM (text)->canvas->pixels_per_unit; + text->_priv->layout->default_style->font_scale = 1.0; tag_table = gtk_text_buffer_get_tag_table (get_buffer (text)); gtk_text_tag_table_foreach (tag_table, scale_fonts, text); diff --git a/libgnomecanvas/gnome-canvas-text.c b/libgnomecanvas/gnome-canvas-text.c index 870b3272b1..a2dce90d64 100644 --- a/libgnomecanvas/gnome-canvas-text.c +++ b/libgnomecanvas/gnome-canvas-text.c @@ -569,8 +569,8 @@ get_bounds (GnomeCanvasText *text, /* Get canvas pixel coordinates for clip rectangle position */ gnome_canvas_w2c (item->canvas, wx, wy, &text->clip_cx, &text->clip_cy); - text->clip_cwidth = text->clip_width * item->canvas->pixels_per_unit; - text->clip_cheight = text->clip_height * item->canvas->pixels_per_unit; + text->clip_cwidth = text->clip_width; + text->clip_cheight = text->clip_height; /* Bounds */ @@ -1055,11 +1055,11 @@ gnome_canvas_text_get_property (GObject *object, break; case PROP_TEXT_WIDTH: - g_value_set_double (value, text->max_width / text->item.canvas->pixels_per_unit); + g_value_set_double (value, text->max_width); break; case PROP_TEXT_HEIGHT: - g_value_set_double (value, text->height / text->item.canvas->pixels_per_unit); + g_value_set_double (value, text->height); break; default: @@ -1299,8 +1299,8 @@ gnome_canvas_text_bounds (GnomeCanvasItem *item, width = text->clip_width; height = text->clip_height; } else { - width = text->max_width / item->canvas->pixels_per_unit; - height = text->height / item->canvas->pixels_per_unit; + width = text->max_width; + height = text->height; } *x2 = *x1 + width; diff --git a/libgnomecanvas/gnome-canvas-widget.c b/libgnomecanvas/gnome-canvas-widget.c index d6ac27c447..b97910276b 100644 --- a/libgnomecanvas/gnome-canvas-widget.c +++ b/libgnomecanvas/gnome-canvas-widget.c @@ -388,13 +388,8 @@ gnome_canvas_widget_update (GnomeCanvasItem *item, (* parent_class->update) (item, matrix, flags); if (witem->widget) { - if (witem->size_pixels) { - witem->cwidth = (gint) (witem->width + 0.5); - witem->cheight = (gint) (witem->height + 0.5); - } else { - witem->cwidth = (gint) (witem->width * item->canvas->pixels_per_unit + 0.5); - witem->cheight = (gint) (witem->height * item->canvas->pixels_per_unit + 0.5); - } + witem->cwidth = (gint) (witem->width + 0.5); + witem->cheight = (gint) (witem->height + 0.5); gtk_widget_set_size_request (witem->widget, witem->cwidth, witem->cheight); } else { @@ -432,8 +427,8 @@ gnome_canvas_widget_point (GnomeCanvasItem *item, gdouble x, gdouble y, gnome_canvas_c2w (item->canvas, witem->cx, witem->cy, &x1, &y1); - x2 = x1 + (witem->cwidth - 1) / item->canvas->pixels_per_unit; - y2 = y1 + (witem->cheight - 1) / item->canvas->pixels_per_unit; + x2 = x1 + (witem->cwidth - 1); + y2 = y1 + (witem->cheight - 1); /* Is point inside widget bounds? */ diff --git a/libgnomecanvas/gnome-canvas.c b/libgnomecanvas/gnome-canvas.c index 5d6ba83d85..aa76dd393c 100644 --- a/libgnomecanvas/gnome-canvas.c +++ b/libgnomecanvas/gnome-canvas.c @@ -1866,17 +1866,10 @@ gnome_canvas_init (GnomeCanvas *canvas) canvas->scroll_x2 = layout_width; canvas->scroll_y2 = layout_height; - canvas->pixels_per_unit = 1.0; - canvas->pick_event.type = GDK_LEAVE_NOTIFY; canvas->pick_event.crossing.x = 0; canvas->pick_event.crossing.y = 0; - /* This may not be what people want, but it is set to be turned on by - * default to have the same initial behavior as the canvas in GNOME 1.4. - */ - canvas->center_scroll_region = TRUE; - gtk_scrollable_set_hadjustment (GTK_SCROLLABLE (canvas), NULL); gtk_scrollable_set_vadjustment (GTK_SCROLLABLE (canvas), NULL); @@ -2090,11 +2083,9 @@ scroll_to (GnomeCanvas *canvas, gint cx, gint cy) canvas_height = allocation.height; scroll_width = - floor ((canvas->scroll_x2 - canvas->scroll_x1) * - canvas->pixels_per_unit + 0.5); + floor ((canvas->scroll_x2 - canvas->scroll_x1) + 0.5); scroll_height = - floor ((canvas->scroll_y2 - canvas->scroll_y1) * - canvas->pixels_per_unit + 0.5); + floor ((canvas->scroll_y2 - canvas->scroll_y1) + 0.5); right_limit = scroll_width - canvas_width; bottom_limit = scroll_height - canvas_height; @@ -2104,12 +2095,8 @@ scroll_to (GnomeCanvas *canvas, gint cx, gint cy) if (right_limit < 0) { cx = 0; - - if (canvas->center_scroll_region) { - canvas->zoom_xofs = (canvas_width - scroll_width) / 2; - scroll_width = canvas_width; - } else - canvas->zoom_xofs = 0; + canvas->zoom_xofs = (canvas_width - scroll_width) / 2; + scroll_width = canvas_width; } else if (cx < 0) { cx = 0; canvas->zoom_xofs = 0; @@ -2121,12 +2108,8 @@ scroll_to (GnomeCanvas *canvas, gint cx, gint cy) if (bottom_limit < 0) { cy = 0; - - if (canvas->center_scroll_region) { - canvas->zoom_yofs = (canvas_height - scroll_height) / 2; - scroll_height = canvas_height; - } else - canvas->zoom_yofs = 0; + canvas->zoom_yofs = (canvas_height - scroll_height) / 2; + scroll_height = canvas_height; } else if (cy < 0) { cy = 0; canvas->zoom_yofs = 0; @@ -2412,8 +2395,8 @@ pick_current_item (GnomeCanvas *canvas, GdkEvent *event) /* world coords */ - x = canvas->scroll_x1 + x / canvas->pixels_per_unit; - y = canvas->scroll_y1 + y / canvas->pixels_per_unit; + x = canvas->scroll_x1 + x; + y = canvas->scroll_y1 + y; /* find the closest item */ @@ -2995,135 +2978,6 @@ gnome_canvas_get_scroll_region (GnomeCanvas *canvas, } /** - * gnome_canvas_set_center_scroll_region: - * @canvas: A canvas. - * @center_scroll_region: Whether to center the scrolling region in the canvas - * window when it is smaller than the canvas' allocation. - * - * When the scrolling region of the canvas is smaller than the canvas window, - * e.g. the allocation of the canvas, it can be either centered on the window - * or simply made to be on the upper-left corner on the window. This function - * lets you configure this property. - **/ -void -gnome_canvas_set_center_scroll_region (GnomeCanvas *canvas, - gboolean center_scroll_region) -{ - GtkScrollable *scrollable; - GtkAdjustment *hadjustment; - GtkAdjustment *vadjustment; - gdouble hadjustment_value; - gdouble vadjustment_value; - - g_return_if_fail (GNOME_IS_CANVAS (canvas)); - - scrollable = GTK_SCROLLABLE (canvas); - hadjustment = gtk_scrollable_get_hadjustment (scrollable); - vadjustment = gtk_scrollable_get_vadjustment (scrollable); - - hadjustment_value = gtk_adjustment_get_value (hadjustment); - vadjustment_value = gtk_adjustment_get_value (vadjustment); - - canvas->center_scroll_region = center_scroll_region != 0; - - scroll_to (canvas, hadjustment_value, vadjustment_value); -} - -/** - * gnome_canvas_get_center_scroll_region: - * @canvas: A canvas. - * - * Returns whether the canvas is set to center the scrolling region in the window - * if the former is smaller than the canvas' allocation. - * - * Return value: Whether the scroll region is being centered in the canvas window. - **/ -gboolean -gnome_canvas_get_center_scroll_region (GnomeCanvas *canvas) -{ - g_return_val_if_fail (GNOME_IS_CANVAS (canvas), FALSE); - - return canvas->center_scroll_region ? TRUE : FALSE; -} - -/** - * gnome_canvas_set_pixels_per_unit: - * @canvas: A canvas. - * @n: The number of pixels that correspond to one canvas unit. - * - * Sets the zooming factor of a canvas by specifying the number of pixels that - * correspond to one canvas unit. - * - * The anchor point for zooming, i.e. the point that stays fixed and all others - * zoom inwards or outwards from it, depends on whether the canvas is set to - * center the scrolling region or not. You can control this using the - * gnome_canvas_set_center_scroll_region() function. If the canvas is set to - * center the scroll region, then the center of the canvas window is used as the - * anchor point for zooming. Otherwise, the upper-left corner of the canvas - * window is used as the anchor point. - **/ -void -gnome_canvas_set_pixels_per_unit (GnomeCanvas *canvas, gdouble n) -{ - GtkScrollable *scrollable; - GtkAdjustment *hadjustment; - GtkAdjustment *vadjustment; - gdouble ax, ay; - gint x1, y1; - gint anchor_x, anchor_y; - - g_return_if_fail (GNOME_IS_CANVAS (canvas)); - g_return_if_fail (n > GNOME_CANVAS_EPSILON); - - scrollable = GTK_SCROLLABLE (canvas); - hadjustment = gtk_scrollable_get_hadjustment (scrollable); - vadjustment = gtk_scrollable_get_vadjustment (scrollable); - - if (canvas->center_scroll_region) { - GtkAllocation allocation; - - gtk_widget_get_allocation (GTK_WIDGET (canvas), &allocation); - - anchor_x = allocation.width / 2; - anchor_y = allocation.height / 2; - } else - anchor_x = anchor_y = 0; - - /* Find the coordinates of the anchor point in units. */ - if (hadjustment) { - gdouble value = gtk_adjustment_get_value (hadjustment); - ax = (value + anchor_x) / canvas->pixels_per_unit + - canvas->scroll_x1 + canvas->zoom_xofs; - } else { - ax = (0.0 + anchor_x) / canvas->pixels_per_unit + - canvas->scroll_x1 + canvas->zoom_xofs; - } - if (vadjustment) { - gdouble value = gtk_adjustment_get_value (vadjustment); - ay = (value + anchor_y) / canvas->pixels_per_unit + - canvas->scroll_y1 + canvas->zoom_yofs; - } else { - ay = (0.0 + anchor_y) / canvas->pixels_per_unit + - canvas->scroll_y1 + canvas->zoom_yofs; - } - - /* Now calculate the new offset of the upper left corner. */ - x1 = ((ax - canvas->scroll_x1) * n) - anchor_x; - y1 = ((ay - canvas->scroll_y1) * n) - anchor_y; - - canvas->pixels_per_unit = n; - - scroll_to (canvas, x1, y1); - - if (!(canvas->root->flags & GNOME_CANVAS_ITEM_NEED_AFFINE)) { - canvas->root->flags |= GNOME_CANVAS_ITEM_NEED_AFFINE; - gnome_canvas_request_update (canvas); - } - - canvas->need_repick = TRUE; -} - -/** * gnome_canvas_scroll_to: * @canvas: A canvas. * @cx: Horizontal scrolling offset in canvas pixel units. @@ -3288,12 +3142,8 @@ gnome_canvas_w2c_matrix (GnomeCanvas *canvas, cairo_matrix_t *matrix) g_return_if_fail (GNOME_IS_CANVAS (canvas)); g_return_if_fail (matrix != NULL); - cairo_matrix_init_scale (matrix, - canvas->pixels_per_unit, - canvas->pixels_per_unit); - cairo_matrix_translate (matrix, - -canvas->scroll_x1, - -canvas->scroll_y1); + cairo_matrix_init_translate ( + matrix, -canvas->scroll_x1, -canvas->scroll_y1); } /** @@ -3310,12 +3160,8 @@ gnome_canvas_c2w_matrix (GnomeCanvas *canvas, cairo_matrix_t *matrix) g_return_if_fail (GNOME_IS_CANVAS (canvas)); g_return_if_fail (matrix != NULL); - cairo_matrix_init_translate (matrix, - canvas->scroll_x1, - canvas->scroll_y1); - cairo_matrix_scale (matrix, - 1 / canvas->pixels_per_unit, - 1 / canvas->pixels_per_unit); + cairo_matrix_init_translate ( + matrix, canvas->scroll_x1, canvas->scroll_y1); } /** @@ -3424,12 +3270,10 @@ gnome_canvas_window_to_world (GnomeCanvas *canvas, gdouble winx, gdouble winy, g_return_if_fail (GNOME_IS_CANVAS (canvas)); if (worldx) - *worldx = canvas->scroll_x1 + ((winx - canvas->zoom_xofs) - / canvas->pixels_per_unit); + *worldx = canvas->scroll_x1 + (winx - canvas->zoom_xofs); if (worldy) - *worldy = canvas->scroll_y1 + ((winy - canvas->zoom_yofs) - / canvas->pixels_per_unit); + *worldy = canvas->scroll_y1 + (winy - canvas->zoom_yofs); } /** @@ -3449,10 +3293,10 @@ gnome_canvas_world_to_window (GnomeCanvas *canvas, gdouble worldx, gdouble world g_return_if_fail (GNOME_IS_CANVAS (canvas)); if (winx) - *winx = (canvas->pixels_per_unit)*(worldx - canvas->scroll_x1) + canvas->zoom_xofs; + *winx = (worldx - canvas->scroll_x1) + canvas->zoom_xofs; if (winy) - *winy = (canvas->pixels_per_unit)*(worldy - canvas->scroll_y1) + canvas->zoom_yofs; + *winy = (worldy - canvas->scroll_y1) + canvas->zoom_yofs; } static gboolean diff --git a/libgnomecanvas/gnome-canvas.h b/libgnomecanvas/gnome-canvas.h index 3236e20a5f..5c46464f85 100644 --- a/libgnomecanvas/gnome-canvas.h +++ b/libgnomecanvas/gnome-canvas.h @@ -373,9 +373,6 @@ struct _GnomeCanvas { gdouble scroll_x1, scroll_y1; gdouble scroll_x2, scroll_y2; - /* Scaling factor to be used for display */ - gdouble pixels_per_unit; - /* Idle handler ID */ guint idle_id; @@ -397,11 +394,6 @@ struct _GnomeCanvas { /* Event mask specified when grabbing an item */ guint grabbed_event_mask; - /* Whether the canvas should center the scroll region in the middle of - * the window if the scroll region is smaller than the window. - */ - guint center_scroll_region : 1; - /* Whether items need update at next idle loop iteration */ guint need_update : 1; @@ -453,15 +445,6 @@ void gnome_canvas_set_scroll_region (GnomeCanvas *canvas, void gnome_canvas_get_scroll_region (GnomeCanvas *canvas, gdouble *x1, gdouble *y1, gdouble *x2, gdouble *y2); -/* Whether the canvas centers the scroll region if it is smaller than the window */ -void gnome_canvas_set_center_scroll_region (GnomeCanvas *canvas, gboolean center_scroll_region); - -/* Returns whether the canvas is set to center the scroll region if it is smaller than the window */ -gboolean gnome_canvas_get_center_scroll_region (GnomeCanvas *canvas); - -/* Sets the number of pixels that correspond to one unit in world coordinates */ -void gnome_canvas_set_pixels_per_unit (GnomeCanvas *canvas, gdouble n); - /* Scrolls the canvas to the specified offsets, given in canvas pixel coordinates */ void gnome_canvas_scroll_to (GnomeCanvas *canvas, gint cx, gint cy); |