Ejemplo n.º 1
0
static void
update_autoscale(ViewHelper *self)
{
    GdkRectangle viewport = self->widget_allocation;
    GeglRectangle bbox = gegl_node_get_bounding_box(self->node);
    model_rect_to_view_rect(self, &bbox);

    if (!self->node || viewport.width < 0 || viewport.height < 0
            || bbox.width < 0 || bbox.height < 0)
        return;

    if (self->autoscale_policy == GEGL_GTK_VIEW_AUTOSCALE_WIDGET) {
        /* Request widget size change */
        /* XXX: Should we reset scale/x/y here? */
        g_signal_emit(self, view_helper_signals[SIGNAL_SIZE_CHANGED],
                      0, &bbox, NULL);

    } else if (self->autoscale_policy == GEGL_GTK_VIEW_AUTOSCALE_CONTENT) {
        /* Calculate and set scaling factor to make the content fit inside */
        float width_ratio = bbox.width / (float)viewport.width;
        float height_ratio = bbox.height / (float)viewport.height;
        float max_ratio = width_ratio >= height_ratio ? width_ratio : height_ratio;

        float current_scale = view_helper_get_scale(self);
        view_helper_set_scale(self, current_scale * (1.0 / max_ratio));
    }

}
Ejemplo n.º 2
0
/**
 * gegl_gtk_view_get_scale:
 * @self: A #GeglGtkView
 *
 * Getter for the :scale property
 *
 * Returns:
 **/
float
gegl_gtk_view_get_scale(GeglGtkView *self)
{
    return view_helper_get_scale(GET_PRIVATE(self));
}