app: allow to position overlay widgets absolutely

This commit is contained in:
Michael Natterer
2010-02-20 14:46:29 +01:00
parent 9bc0ea5466
commit d488cc650a
4 changed files with 94 additions and 39 deletions

View File

@ -363,10 +363,10 @@ gimp_overlay_box_add_child (GimpOverlayBox *box,
}
void
gimp_overlay_box_set_child_packing (GimpOverlayBox *box,
GtkWidget *widget,
gdouble xalign,
gdouble yalign)
gimp_overlay_box_set_child_alignment (GimpOverlayBox *box,
GtkWidget *widget,
gdouble xalign,
gdouble yalign)
{
GimpOverlayChild *child = gimp_overlay_child_find (box, widget);
@ -375,13 +375,40 @@ gimp_overlay_box_set_child_packing (GimpOverlayBox *box,
xalign = CLAMP (xalign, 0.0, 1.0);
yalign = CLAMP (yalign, 0.0, 1.0);
if (child->xalign != xalign ||
if (child->has_position ||
child->xalign != xalign ||
child->yalign != yalign)
{
gimp_overlay_child_invalidate (box, child);
child->xalign = xalign;
child->yalign = yalign;
child->has_position = FALSE;
child->xalign = xalign;
child->yalign = yalign;
gtk_widget_queue_resize (widget);
}
}
}
void
gimp_overlay_box_set_child_position (GimpOverlayBox *box,
GtkWidget *widget,
gdouble x,
gdouble y)
{
GimpOverlayChild *child = gimp_overlay_child_find (box, widget);
if (child)
{
if (! child->has_position ||
child->x != x ||
child->y != y)
{
gimp_overlay_child_invalidate (box, child);
child->has_position = TRUE;
child->x = x;
child->y = y;
gtk_widget_queue_resize (widget);
}
@ -453,13 +480,21 @@ gimp_overlay_box_scroll (GimpOverlayBox *box,
/* Undraw all overlays */
for (list = box->children; list; list = g_list_next (list))
gimp_overlay_child_invalidate (box, list->data);
{
GimpOverlayChild *child = list->data;
gimp_overlay_child_invalidate (box, child);
}
gdk_window_scroll (window, offset_x, offset_y);
/* Re-draw all overlays */
for (list = box->children; list; list = g_list_next (list))
gimp_overlay_child_invalidate (box, list->data);
{
GimpOverlayChild *child = list->data;
gimp_overlay_child_invalidate (box, child);
}
/* Make sure expose events are processed before scrolling again */
gdk_window_process_updates (window, FALSE);

View File

@ -45,28 +45,32 @@ struct _GimpOverlayBoxClass
};
GType gimp_overlay_box_get_type (void) G_GNUC_CONST;
GType gimp_overlay_box_get_type (void) G_GNUC_CONST;
GtkWidget * gimp_overlay_box_new (void);
GtkWidget * gimp_overlay_box_new (void);
void gimp_overlay_box_add_child (GimpOverlayBox *canvas,
GtkWidget *child,
gdouble xalign,
gdouble yalign);
void gimp_overlay_box_set_child_packing (GimpOverlayBox *canvas,
GtkWidget *child,
gdouble xalign,
gdouble yalign);
void gimp_overlay_box_set_child_angle (GimpOverlayBox *canvas,
GtkWidget *child,
gdouble angle);
void gimp_overlay_box_set_child_opacity (GimpOverlayBox *canvas,
GtkWidget *child,
gdouble opacity);
void gimp_overlay_box_add_child (GimpOverlayBox *box,
GtkWidget *child,
gdouble xalign,
gdouble yalign);
void gimp_overlay_box_set_child_alignment (GimpOverlayBox *box,
GtkWidget *child,
gdouble xalign,
gdouble yalign);
void gimp_overlay_box_set_child_position (GimpOverlayBox *box,
GtkWidget *child,
gdouble x,
gdouble y);
void gimp_overlay_box_set_child_angle (GimpOverlayBox *box,
GtkWidget *child,
gdouble angle);
void gimp_overlay_box_set_child_opacity (GimpOverlayBox *box,
GtkWidget *child,
gdouble opacity);
void gimp_overlay_box_scroll (GimpOverlayBox *canvas,
gint offset_x,
gint offset_y);
void gimp_overlay_box_scroll (GimpOverlayBox *box,
gint offset_x,
gint offset_y);
#endif /* __GIMP_OVERLAY_BOX_H__ */

View File

@ -69,11 +69,14 @@ gimp_overlay_child_new (GimpOverlayBox *box,
child = g_slice_new0 (GimpOverlayChild);
child->widget = widget;
child->xalign = CLAMP (xalign, 0.0, 1.0);
child->yalign = CLAMP (yalign, 0.0, 1.0);
child->angle = angle;
child->opacity = CLAMP (opacity, 0.0, 1.0);
child->widget = widget;
child->xalign = CLAMP (xalign, 0.0, 1.0);
child->yalign = CLAMP (yalign, 0.0, 1.0);
child->x = 0.0;
child->y = 0.0;
child->has_position = FALSE;
child->angle = angle;
child->opacity = CLAMP (opacity, 0.0, 1.0);
cairo_matrix_init_identity (&child->matrix);
@ -271,14 +274,22 @@ gimp_overlay_child_size_allocate (GimpOverlayBox *box,
available_width = allocation.width - 2 * border;
available_height = allocation.height - 2 * border;
x = border;
y = border;
if (child->has_position)
{
x = child->x;
y = child->y;
}
else
{
x = border;
y = border;
if (available_width > bounds.width)
x += child->xalign * (available_width - bounds.width) - bounds.x;
if (available_width > bounds.width)
x += child->xalign * (available_width - bounds.width) - bounds.x;
if (available_height > bounds.height)
y += child->yalign * (available_height - bounds.height) - bounds.y;
if (available_height > bounds.height)
y += child->yalign * (available_height - bounds.height) - bounds.y;
}
cairo_matrix_init_translate (&child->matrix, x, y);

View File

@ -29,8 +29,13 @@ struct _GimpOverlayChild
{
GtkWidget *widget;
GdkWindow *window;
gboolean has_position;
gdouble xalign;
gdouble yalign;
gdouble x;
gdouble y;
gdouble angle;
gdouble opacity;