From: Jim Evins Date: Tue, 1 May 2007 01:18:50 +0000 (+0000) Subject: 2007-04-30 Jim Evins X-Git-Tag: glabels-2_3_0~341 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=4ca379add847194fa1375fe127e9800367f655e1;p=glabels 2007-04-30 Jim Evins * src/label.h: Added glLabelRegion structure type. * src/label-object.c: (gl_label_object_get_extent): * src/label-object.h: Modified gl_label_object_get_extent() to fill in a glLabelRegion struct. * src/view.h: * src/view.c: (gl_view_update_region), (draw_select_region_layer), (gl_view_select_region), (gl_view_align_selection_left), (gl_view_align_selection_right), (gl_view_align_selection_hcenter), (gl_view_align_selection_top), (gl_view_align_selection_bottom), (gl_view_align_selection_vcenter), (gl_view_center_selection_horiz), (gl_view_center_selection_vert), (gl_view_move_selection), (gl_view_can_selection_text), (motion_notify_event_cb), (button_press_event_cb), (button_release_event_cb): - Reconcile with new gl_label_object_get_extent() API. - Use glLabelRegion for view->select_region. - Added gl_view_update_region() to clip updates to region. - Use gl_view_update_region() during manipulation of view->select_region. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@655 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 0d94463a..4b91d90a 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,25 @@ +2007-04-30 Jim Evins + + * src/label.h: + Added glLabelRegion structure type. + * src/label-object.c: (gl_label_object_get_extent): + * src/label-object.h: + Modified gl_label_object_get_extent() to fill in a glLabelRegion struct. + * src/view.h: + * src/view.c: (gl_view_update_region), (draw_select_region_layer), + (gl_view_select_region), (gl_view_align_selection_left), + (gl_view_align_selection_right), (gl_view_align_selection_hcenter), + (gl_view_align_selection_top), (gl_view_align_selection_bottom), + (gl_view_align_selection_vcenter), + (gl_view_center_selection_horiz), (gl_view_center_selection_vert), + (gl_view_move_selection), (gl_view_can_selection_text), + (motion_notify_event_cb), (button_press_event_cb), + (button_release_event_cb): + - Reconcile with new gl_label_object_get_extent() API. + - Use glLabelRegion for view->select_region. + - Added gl_view_update_region() to clip updates to region. + - Use gl_view_update_region() during manipulation of view->select_region. + 2007-04-26 Jim Evins * src/mini-preview-pixbuf.c: (draw_paper), (draw_label_outlines), diff --git a/glabels2/src/label-object.c b/glabels2/src/label-object.c index f4b43955..467cd2c5 100644 --- a/glabels2/src/label-object.c +++ b/glabels2/src/label-object.c @@ -567,13 +567,11 @@ gl_label_object_get_size (glLabelObject *object, /*****************************************************************************/ void gl_label_object_get_extent (glLabelObject *object, - gdouble *x1, - gdouble *y1, - gdouble *x2, - gdouble *y2) + glLabelRegion *region) { - gdouble w, h; - gdouble xa1, ya1, xa2, ya2, xa3, ya3, xa4, ya4; + gdouble w, h; + gdouble line_w; + gdouble xa1, ya1, xa2, ya2, xa3, ya3, xa4, ya4; cairo_matrix_t matrix; gl_debug (DEBUG_LABEL, "START"); @@ -581,16 +579,17 @@ gl_label_object_get_extent (glLabelObject *object, g_return_if_fail (object && GL_IS_LABEL_OBJECT (object)); gl_label_object_get_size (object, &w, &h); - - /* setup untransformed corners of bounding box */ - xa1 = 0.0; - ya1 = 0.0; - xa2 = w; - ya2 = 0.0; - xa3 = w; - ya3 = h; - xa4 = 0.0; - ya4 = h; + line_w = gl_label_object_get_line_width (object); + + /* setup untransformed corners of bounding box, account for line width */ + xa1 = - line_w/2; + ya1 = - line_w/2; + xa2 = w + line_w/2; + ya2 = - line_w/2; + xa3 = w + line_w/2; + ya3 = h + line_w/2; + xa4 = - line_w/2; + ya4 = h + line_w/2; /* transform these points */ gl_label_object_get_matrix (object, &matrix); @@ -600,10 +599,10 @@ gl_label_object_get_extent (glLabelObject *object, cairo_matrix_transform_point (&matrix, &xa4, &ya4); /* now find the maximum extent of these points in x and y */ - *x1 = MIN (xa1, MIN (xa2, MIN (xa3, xa4))) + object->priv->x; - *y1 = MIN (ya1, MIN (ya2, MIN (ya3, ya4))) + object->priv->y; - *x2 = MAX (xa1, MAX (xa2, MAX (xa3, xa4))) + object->priv->x; - *y2 = MAX (ya1, MAX (ya2, MAX (ya3, ya4))) + object->priv->y; + region->x1 = MIN (xa1, MIN (xa2, MIN (xa3, xa4))) + object->priv->x; + region->y1 = MIN (ya1, MIN (ya2, MIN (ya3, ya4))) + object->priv->y; + region->x2 = MAX (xa1, MAX (xa2, MAX (xa3, xa4))) + object->priv->x; + region->y2 = MAX (ya1, MAX (ya2, MAX (ya3, ya4))) + object->priv->y; gl_debug (DEBUG_LABEL, "END"); } diff --git a/glabels2/src/label-object.h b/glabels2/src/label-object.h index d94c6c55..d7a62764 100644 --- a/glabels2/src/label-object.h +++ b/glabels2/src/label-object.h @@ -221,11 +221,7 @@ void gl_label_object_get_raw_size (glLabelObject *object, gdouble *h); void gl_label_object_get_extent (glLabelObject *object, - gdouble *x1, - gdouble *y1, - gdouble *x2, - gdouble *y2); - + glLabelRegion *region); gboolean gl_label_object_can_text (glLabelObject *object); diff --git a/glabels2/src/label.h b/glabels2/src/label.h index 374f8102..a3a9e5f4 100644 --- a/glabels2/src/label.h +++ b/glabels2/src/label.h @@ -33,6 +33,13 @@ G_BEGIN_DECLS +typedef struct { + gdouble x1; + gdouble y1; + gdouble x2; + gdouble y2; +} glLabelRegion; + #define GL_TYPE_LABEL (gl_label_get_type ()) #define GL_LABEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GL_TYPE_LABEL, glLabel)) #define GL_LABEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GL_TYPE_LABEL, glLabelClass)) diff --git a/glabels2/src/view.c b/glabels2/src/view.c index 18312ca2..5587b6db 100644 --- a/glabels2/src/view.c +++ b/glabels2/src/view.c @@ -539,7 +539,7 @@ get_home_scale (glView *view) } /*---------------------------------------------------------------------------*/ -/* PRIVATE. Update canvas. */ +/* Schedule canvas update. */ /*---------------------------------------------------------------------------*/ void gl_view_update (glView *view) @@ -566,6 +566,42 @@ gl_view_update (glView *view) gl_debug (DEBUG_VIEW, "END"); } +/*---------------------------------------------------------------------------*/ +/* Schedule canvas region update. */ +/*---------------------------------------------------------------------------*/ +void +gl_view_update_region (glView *view, + cairo_t *cr, + glLabelRegion *region) +{ + GtkWidget *widget; + GdkRectangle rect; + gdouble x, y, w, h; + + gl_debug (DEBUG_VIEW, "START"); + + widget = GTK_WIDGET (view->canvas); + + if (!widget->window) return; + + x = MIN (region->x1, region->x2); + y = MIN (region->y1, region->y2); + w = fabs (region->x2 - region->x1); + h = fabs (region->y2 - region->y1); + + cairo_user_to_device (cr, &x, &y); + cairo_user_to_device_distance (cr, &w, &h); + + rect.x = x - 3; + rect.y = y - 3; + rect.width = w + 6; + rect.height = h + 6; + + gdk_window_invalidate_rect (widget->window, &rect, TRUE); + + gl_debug (DEBUG_VIEW, "END"); +} + /*---------------------------------------------------------------------------*/ /* PRIVATE. Expose handler. */ /*---------------------------------------------------------------------------*/ @@ -927,10 +963,10 @@ draw_select_region_layer (glView *view, if (view->select_region_visible) { - x1 = MIN (view->select_region_x1, view->select_region_x2); - y1 = MIN (view->select_region_y1, view->select_region_y2); - w = fabs (view->select_region_x2 - view->select_region_x1); - h = fabs (view->select_region_y2 - view->select_region_y1); + x1 = MIN (view->select_region.x1, view->select_region.x2); + y1 = MIN (view->select_region.y1, view->select_region.y2); + w = fabs (view->select_region.x2 - view->select_region.x1); + h = fabs (view->select_region.y2 - view->select_region.y1); cairo_rectangle (cr, x1, y1, w, h); @@ -1165,38 +1201,39 @@ gl_view_unselect_all (glView *view) /* Select all objects within given rectangular region (adding to selection). */ /*****************************************************************************/ void -gl_view_select_region (glView *view, - gdouble x1, - gdouble y1, - gdouble x2, - gdouble y2) +gl_view_select_region (glView *view, + glLabelRegion *region) { GList *p; glViewObject *view_object; glLabelObject *object; gdouble r_x1, r_y1; gdouble r_x2, r_y2; - gdouble i_x1, i_y1; - gdouble i_x2, i_y2; + glLabelRegion obj_extent; gl_debug (DEBUG_VIEW, "START"); g_return_if_fail (view && GL_IS_VIEW (view)); - r_x1 = MIN (x1, x2); - r_y1 = MIN (y1, y2); - r_x2 = MAX (x1, x2); - r_y2 = MAX (y1, y2); + r_x1 = MIN (region->x1, region->x2); + r_y1 = MIN (region->y1, region->y2); + r_x2 = MAX (region->x1, region->x2); + r_y2 = MAX (region->y1, region->y2); - for (p = view->object_list; p != NULL; p = p->next) { + for (p = view->object_list; p != NULL; p = p->next) + { view_object = GL_VIEW_OBJECT(p->data); - if (!gl_view_is_object_selected (view, view_object)) { + if (!gl_view_is_object_selected (view, view_object)) + { object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &i_x1, &i_y1, &i_x2, &i_y2); - if ((i_x1 >= r_x1) && (i_x2 <= r_x2) && (i_y1 >= r_y1) - && (i_y2 <= r_y2)) { + gl_label_object_get_extent (object, &obj_extent); + if ((obj_extent.x1 >= r_x1) && + (obj_extent.x2 <= r_x2) && + (obj_extent.y1 >= r_y1) && + (obj_extent.y2 <= r_y2)) + { select_object_real (view, view_object); } @@ -1585,7 +1622,8 @@ gl_view_align_selection_left (glView *view) GList *p; glViewObject *view_object; glLabelObject *object; - gdouble dx, x1min, x1, y1, x2, y2; + gdouble dx, x1_min; + glLabelRegion obj_extent; gl_debug (DEBUG_VIEW, "START"); @@ -1598,20 +1636,23 @@ gl_view_align_selection_left (glView *view) p = view->selected_object_list; view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &x1min, &y1, &x2, &y2); - for (p = p->next; p != NULL; p = p->next) { + gl_label_object_get_extent (object, &obj_extent); + x1_min = obj_extent.x1; + for (p = p->next; p != NULL; p = p->next) + { view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &x1, &y1, &x2, &y2); - if ( x1 < x1min ) x1min = x1; + gl_label_object_get_extent (object, &obj_extent); + if ( obj_extent.x1 < x1_min ) x1_min = obj_extent.x1; } /* now adjust the object positions to line up the left edges */ - for (p = view->selected_object_list; p != NULL; p = p->next) { + for (p = view->selected_object_list; p != NULL; p = p->next) + { view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &x1, &y1, &x2, &y2); - dx = x1min - x1; + gl_label_object_get_extent (object, &obj_extent); + dx = x1_min - obj_extent.x1; gl_label_object_set_position_relative (object, dx, 0.0); } @@ -1628,10 +1669,8 @@ gl_view_align_selection_right (glView *view) GList *p; glViewObject *view_object; glLabelObject *object; - gdouble dx; - gdouble x1, y1; - gdouble x2, y2; - gdouble x2max; + gdouble dx, x2_max; + glLabelRegion obj_extent; gl_debug (DEBUG_VIEW, "START"); @@ -1644,20 +1683,23 @@ gl_view_align_selection_right (glView *view) p = view->selected_object_list; view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &x1, &y1, &x2max, &y2); - for (p = p->next; p != NULL; p = p->next) { + gl_label_object_get_extent (object, &obj_extent); + x2_max = obj_extent.x2; + for (p = p->next; p != NULL; p = p->next) + { view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &x1, &y1, &x2, &y2); - if ( x2 > x2max ) x2max = x2; + gl_label_object_get_extent (object, &obj_extent); + if ( obj_extent.x2 > x2_max ) x2_max = obj_extent.x2; } /* now adjust the object positions to line up the right edges */ - for (p = view->selected_object_list; p != NULL; p = p->next) { + for (p = view->selected_object_list; p != NULL; p = p->next) + { view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &x1, &y1, &x2, &y2); - dx = x2max - x2; + gl_label_object_get_extent (object, &obj_extent); + dx = x2_max - obj_extent.x2; gl_label_object_set_position_relative (object, dx, 0.0); } @@ -1676,8 +1718,7 @@ gl_view_align_selection_hcenter (glView *view) gdouble dx; gdouble dxmin; gdouble xsum, xavg; - gdouble x1, y1; - gdouble x2, y2; + glLabelRegion obj_extent; gdouble xcenter; gint n; @@ -1691,11 +1732,12 @@ gl_view_align_selection_hcenter (glView *view) /* find average center of objects */ xsum = 0.0; n = 0; - for (p = view->selected_object_list; p != NULL; p = p->next) { + for (p = view->selected_object_list; p != NULL; p = p->next) + { view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &x1, &y1, &x2, &y2); - xsum += (x1 + x2) / 2.0; + gl_label_object_get_extent (object, &obj_extent); + xsum += (obj_extent.x1 + obj_extent.x2) / 2.0; n++; } xavg = xsum / n; @@ -1704,17 +1746,19 @@ gl_view_align_selection_hcenter (glView *view) p = view->selected_object_list; view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &x1, &y1, &x2, &y2); - dxmin = fabs (xavg - (x1 + x2)/2.0); - xcenter = (x1 + x2)/2.0; - for (p = p->next; p != NULL; p = p->next) { + gl_label_object_get_extent (object, &obj_extent); + dxmin = fabs (xavg - (obj_extent.x1 + obj_extent.x2)/2.0); + xcenter = (obj_extent.x1 + obj_extent.x2)/2.0; + for (p = p->next; p != NULL; p = p->next) + { view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &x1, &y1, &x2, &y2); - dx = fabs (xavg - (x1 + x2)/2.0); - if ( dx < dxmin ) { + gl_label_object_get_extent (object, &obj_extent); + dx = fabs (xavg - (obj_extent.x1 + obj_extent.x2)/2.0); + if ( dx < dxmin ) + { dxmin = dx; - xcenter = (x1 + x2)/2.0; + xcenter = (obj_extent.x1 + obj_extent.x2)/2.0; } } @@ -1722,8 +1766,8 @@ gl_view_align_selection_hcenter (glView *view) for (p = view->selected_object_list; p != NULL; p = p->next) { view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &x1, &y1, &x2, &y2); - dx = xcenter - (x1 + x2)/2.0; + gl_label_object_get_extent (object, &obj_extent); + dx = xcenter - (obj_extent.x1 + obj_extent.x2)/2.0; gl_label_object_set_position_relative (object, dx, 0.0); } @@ -1739,10 +1783,8 @@ gl_view_align_selection_top (glView *view) GList *p; glViewObject *view_object; glLabelObject *object; - gdouble dy; - gdouble x1, y1; - gdouble x2, y2; - gdouble y1min; + gdouble dy, y1_min; + glLabelRegion obj_extent; gl_debug (DEBUG_VIEW, "START"); @@ -1755,20 +1797,23 @@ gl_view_align_selection_top (glView *view) p = view->selected_object_list; view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &x1, &y1min, &x2, &y2); - for (p = p->next; p != NULL; p = p->next) { + gl_label_object_get_extent (object, &obj_extent); + y1_min = obj_extent.y1; + for (p = p->next; p != NULL; p = p->next) + { view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &x1, &y1, &x2, &y2); - if ( y1 < y1min ) y1min = y1; + gl_label_object_get_extent (object, &obj_extent); + if ( obj_extent.y1 < y1_min ) y1_min = obj_extent.y1; } /* now adjust the object positions to line up the top edges */ - for (p = view->selected_object_list; p != NULL; p = p->next) { + for (p = view->selected_object_list; p != NULL; p = p->next) + { view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &x1, &y1, &x2, &y2); - dy = y1min - y1; + gl_label_object_get_extent (object, &obj_extent); + dy = y1_min - obj_extent.y1; gl_label_object_set_position_relative (object, 0.0, dy); } @@ -1784,10 +1829,8 @@ gl_view_align_selection_bottom (glView *view) GList *p; glViewObject *view_object; glLabelObject *object; - gdouble dy; - gdouble x1, y1; - gdouble x2, y2; - gdouble y2max; + gdouble dy, y2_max; + glLabelRegion obj_extent; gl_debug (DEBUG_VIEW, "START"); @@ -1800,20 +1843,23 @@ gl_view_align_selection_bottom (glView *view) p = view->selected_object_list; view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &x1, &y1, &x2, &y2max); - for (p = p->next; p != NULL; p = p->next) { + gl_label_object_get_extent (object, &obj_extent); + y2_max = obj_extent.y2; + for (p = p->next; p != NULL; p = p->next) + { view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &x1, &y1, &x2, &y2); - if ( y2 > y2max ) y2max = y2; + gl_label_object_get_extent (object, &obj_extent); + if ( obj_extent.y2 > y2_max ) y2_max = obj_extent.y2; } /* now adjust the object positions to line up the bottom edges */ - for (p = view->selected_object_list; p != NULL; p = p->next) { + for (p = view->selected_object_list; p != NULL; p = p->next) + { view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &x1, &y1, &x2, &y2); - dy = y2max - y2; + gl_label_object_get_extent (object, &obj_extent); + dy = y2_max - obj_extent.y2; gl_label_object_set_position_relative (object, 0.0, dy); } @@ -1832,8 +1878,7 @@ gl_view_align_selection_vcenter (glView *view) gdouble dy; gdouble dymin; gdouble ysum, yavg; - gdouble x1, y1; - gdouble x2, y2; + glLabelRegion obj_extent; gdouble ycenter; gint n; @@ -1847,11 +1892,12 @@ gl_view_align_selection_vcenter (glView *view) /* find average center of objects */ ysum = 0.0; n = 0; - for (p = view->selected_object_list; p != NULL; p = p->next) { + for (p = view->selected_object_list; p != NULL; p = p->next) + { view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &x1, &y1, &x2, &y2); - ysum += (y1 + y2) / 2.0; + gl_label_object_get_extent (object, &obj_extent); + ysum += (obj_extent.y1 + obj_extent.y2) / 2.0; n++; } yavg = ysum / n; @@ -1860,26 +1906,29 @@ gl_view_align_selection_vcenter (glView *view) p = view->selected_object_list; view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &x1, &y1, &x2, &y2); - dymin = fabs (yavg - (y1 + y2)/2.0); - ycenter = (y1 + y2)/2.0; - for (p = p->next; p != NULL; p = p->next) { + gl_label_object_get_extent (object, &obj_extent); + dymin = fabs (yavg - (obj_extent.y1 + obj_extent.y2)/2.0); + ycenter = (obj_extent.y1 + obj_extent.y2)/2.0; + for (p = p->next; p != NULL; p = p->next) + { view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &x1, &y1, &x2, &y2); - dy = fabs (yavg - (y1 + y2)/2.0); - if ( dy < dymin ) { + gl_label_object_get_extent (object, &obj_extent); + dy = fabs (yavg - (obj_extent.y1 + obj_extent.y2)/2.0); + if ( dy < dymin ) + { dymin = dy; - ycenter = (y1 + y2)/2.0; + ycenter = (obj_extent.y1 + obj_extent.y2)/2.0; } } /* now adjust the object positions to line up this center */ - for (p = view->selected_object_list; p != NULL; p = p->next) { + for (p = view->selected_object_list; p != NULL; p = p->next) + { view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &x1, &y1, &x2, &y2); - dy = ycenter - (y1 + y2)/2.0; + gl_label_object_get_extent (object, &obj_extent); + dy = ycenter - (obj_extent.y1 + obj_extent.y2)/2.0; gl_label_object_set_position_relative (object, 0.0, dy); } @@ -1898,8 +1947,7 @@ gl_view_center_selection_horiz (glView *view) gdouble dx; gdouble x_label_center; gdouble x_obj_center; - gdouble x1, y1; - gdouble x2, y2; + glLabelRegion obj_extent; gdouble w, h; gl_debug (DEBUG_VIEW, "START"); @@ -1912,11 +1960,12 @@ gl_view_center_selection_horiz (glView *view) x_label_center = w / 2.0; /* adjust the object positions */ - for (p = view->selected_object_list; p != NULL; p = p->next) { + for (p = view->selected_object_list; p != NULL; p = p->next) + { view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &x1, &y1, &x2, &y2); - x_obj_center = (x1 + x2) / 2.0; + gl_label_object_get_extent (object, &obj_extent); + x_obj_center = (obj_extent.x1 + obj_extent.x2) / 2.0; dx = x_label_center - x_obj_center; gl_label_object_set_position_relative (object, dx, 0.0); } @@ -1937,8 +1986,7 @@ gl_view_center_selection_vert (glView *view) gdouble dy; gdouble y_label_center; gdouble y_obj_center; - gdouble x1, y1; - gdouble x2, y2; + glLabelRegion obj_extent; gdouble w, h; gl_debug (DEBUG_VIEW, "START"); @@ -1951,11 +1999,12 @@ gl_view_center_selection_vert (glView *view) y_label_center = h / 2.0; /* adjust the object positions */ - for (p = view->selected_object_list; p != NULL; p = p->next) { + for (p = view->selected_object_list; p != NULL; p = p->next) + { view_object = GL_VIEW_OBJECT (p->data); object = gl_view_object_get_object (view_object); - gl_label_object_get_extent (object, &x1, &y1, &x2, &y2); - y_obj_center = (y1 + y2) / 2.0; + gl_label_object_get_extent (object, &obj_extent); + y_obj_center = (obj_extent.y1 + obj_extent.y2) / 2.0; dy = y_label_center - y_obj_center; gl_label_object_set_position_relative (object, 0.0, dy); } @@ -1979,7 +2028,8 @@ gl_view_move_selection (glView *view, g_return_if_fail (view && GL_IS_VIEW (view)); - for (p = view->selected_object_list; p != NULL; p = p->next) { + for (p = view->selected_object_list; p != NULL; p = p->next) + { object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data)); gl_label_object_set_position_relative (object, dx, dy); @@ -2002,10 +2052,12 @@ gl_view_can_selection_text (glView *view) g_return_val_if_fail (view && GL_IS_VIEW (view), FALSE); - for (p = view->selected_object_list; p != NULL; p = p->next) { + for (p = view->selected_object_list; p != NULL; p = p->next) + { object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data)); - if (gl_label_object_can_text (object)) { + if (gl_label_object_can_text (object)) + { return TRUE; } @@ -3153,9 +3205,10 @@ motion_notify_event_cb (glView *view, break; case GL_VIEW_ARROW_SELECT_REGION: - view->select_region_x2 = x; - view->select_region_y2 = y; - gl_view_update (view); + gl_view_update_region (view, cr, &view->select_region); + view->select_region.x2 = x; + view->select_region.y2 = y; + gl_view_update_region (view, cr, &view->select_region); break; case GL_VIEW_ARROW_MOVE: @@ -3318,11 +3371,10 @@ button_press_event_cb (glView *view, } view->select_region_visible = TRUE; - view->select_region_x1 = x; - view->select_region_y1 = y; - view->select_region_x2 = x; - view->select_region_y2 = y; - gl_view_update (view); + view->select_region.x1 = x; + view->select_region.y1 = y; + view->select_region.x2 = x; + view->select_region.y2 = y; view->state = GL_VIEW_ARROW_SELECT_REGION; } @@ -3433,17 +3485,13 @@ button_release_event_cb (glView *view, break; case GL_VIEW_ARROW_SELECT_REGION: - view->select_region_visible = FALSE; - view->select_region_x2 = x; - view->select_region_y2 = y; + gl_view_update_region (view, cr, &view->select_region); - gl_view_select_region (view, - view->select_region_x1, - view->select_region_y1, - view->select_region_x2, - view->select_region_y2); + view->select_region_visible = FALSE; + view->select_region.x2 = x; + view->select_region.y2 = y; - gl_view_update (view); + gl_view_select_region (view, &view->select_region); view->state = GL_VIEW_IDLE; break; diff --git a/glabels2/src/view.h b/glabels2/src/view.h index 67a344c8..38c3ed80 100644 --- a/glabels2/src/view.h +++ b/glabels2/src/view.h @@ -83,10 +83,7 @@ struct _glView { /* GL_VIEW_ARROW_SELECT_REGION state */ gboolean select_region_visible; - gdouble select_region_x1; - gdouble select_region_y1; - gdouble select_region_x2; - gdouble select_region_y2; + glLabelRegion select_region; /* GL_VIEW_ARROW_RESIZE state */ glViewObject *resize_object; @@ -160,6 +157,10 @@ GtkWidget *gl_view_new (glLabel *label); void gl_view_update (glView *view); +void gl_view_update_region (glView *view, + cairo_t *cr, + glLabelRegion *region); + void gl_view_show_grid (glView *view); void gl_view_hide_grid (glView *view); @@ -188,10 +189,7 @@ void gl_view_select_all (glView *view); void gl_view_unselect_all (glView *view); void gl_view_select_region (glView *view, - gdouble x1, - gdouble y1, - gdouble x2, - gdouble y2); + glLabelRegion *region); gboolean gl_view_is_object_selected (glView *view, glViewObject *view_object);