Ejemplo n.º 1
0
static void
_adg_arrange(AdgEntity *entity)
{
    AdgAlignmentPrivate *data;
    const CpmlExtents *extents;
    CpmlExtents new_extents;
    cairo_matrix_t ctm, ctm_inverted, old_map;

    if (_ADG_OLD_ENTITY_CLASS->arrange == NULL)
        return;

    data = adg_alignment_get_instance_private((AdgAlignment *) entity);
    extents = adg_entity_get_extents(entity);
    data->shift.x = 0;
    data->shift.y = 0;

    /* The shift is performed only when relevant */
    if (data->factor.x != 0 || data->factor.y != 0) {
        /* Force the ctm to be the identity matrix */
        adg_matrix_copy(&old_map, adg_entity_get_global_map(entity));
        adg_matrix_copy(&ctm, adg_entity_get_global_map(entity));
        adg_matrix_transform(&ctm, adg_entity_get_local_matrix(entity),
                             ADG_TRANSFORM_AFTER);
        adg_matrix_copy(&ctm_inverted, &ctm);
        cairo_matrix_invert(&ctm_inverted);
        adg_entity_transform_global_map(entity, &ctm_inverted,
                                        ADG_TRANSFORM_AFTER);
        adg_entity_global_changed(entity);

        /* Calculating the shift */
        _ADG_OLD_ENTITY_CLASS->arrange(entity);
        extents = adg_entity_get_extents(entity);
        if (extents->is_defined) {
            data->shift.x = -extents->size.x * data->factor.x;
            data->shift.y = -extents->size.y * data->factor.y;
            cpml_vector_transform(&data->shift, &ctm);
        }

        /* Restore the old global map */
        adg_entity_set_global_map(entity, &old_map);
        adg_entity_global_changed(entity);
    }

    /* Add the shift to the extents */
    _ADG_OLD_ENTITY_CLASS->arrange(entity);
    cpml_extents_copy(&new_extents, adg_entity_get_extents(entity));
    new_extents.org.x += data->shift.x;
    new_extents.org.y += data->shift.y;
    adg_entity_set_extents(entity, &new_extents);
}
Ejemplo n.º 2
0
Archivo: adg-adim.c Proyecto: bert/adg
static void
_adg_global_changed(AdgEntity *entity)
{
    AdgADimPrivate *data = ((AdgADim *) entity)->data;

    _adg_unset_trail((AdgADim *) entity);

    if (_ADG_OLD_ENTITY_CLASS->global_changed)
        _ADG_OLD_ENTITY_CLASS->global_changed(entity);

    if (data->marker1 != NULL)
        adg_entity_global_changed((AdgEntity *) data->marker1);

    if (data->marker2 != NULL)
        adg_entity_global_changed((AdgEntity *) data->marker2);
}
Ejemplo n.º 3
0
Archivo: adg-dim.c Proyecto: bert/adg
static void
_adg_global_changed(AdgEntity *entity)
{
    AdgDimPrivate *data = ((AdgDim *) entity)->data;

    if (_ADG_OLD_ENTITY_CLASS->global_changed)
        _ADG_OLD_ENTITY_CLASS->global_changed(entity);

    if (data->quote.entity)
        adg_entity_global_changed((AdgEntity *) data->quote.entity);
}
Ejemplo n.º 4
0
Archivo: adg-dim.c Proyecto: bert/adg
static void
_adg_arrange(AdgEntity *entity)
{
    AdgDim *dim;
    AdgDimPrivate *data;
    AdgEntity *quote_entity;
    AdgContainer *quote_container;
    AdgEntity *value_entity;
    AdgEntity *min_entity;
    AdgEntity *max_entity;
    const CpmlPair *shift;
    cairo_matrix_t map;

    dim = (AdgDim *) entity;
    data = dim->data;

    /* Resolve the dim style */
    if (data->dim_style == NULL)
        data->dim_style = (AdgDimStyle *)
            adg_entity_style(entity, data->dim_dress);

    if (data->quote.entity == NULL)
        data->quote.entity = g_object_new(ADG_TYPE_ALIGNMENT,
                                          "local-mix", ADG_MIX_NONE,
                                          "parent", dim, NULL);

    quote_entity = (AdgEntity *) data->quote.entity;
    quote_container = (AdgContainer *) data->quote.entity;

    if (data->quote.value == NULL) {
        AdgDimClass *klass;
        AdgDress dress;
        const gchar *tag;
        gchar *value;
        gchar *text;

        klass = ADG_DIM_GET_CLASS(dim);
        dress = adg_dim_style_get_value_dress(data->dim_style);
        tag = adg_dim_style_get_number_tag(data->dim_style);
        value = klass->default_value ? klass->default_value(dim) : NULL;

        data->quote.value = g_object_new(ADG_TYPE_BEST_TEXT,
                                         "local-mix", ADG_MIX_PARENT,
                                         "font-dress", dress, NULL);
        adg_container_add(quote_container, (AdgEntity *) data->quote.value);

        if (data->value)
            text = adg_string_replace(data->value, tag, value);
        else
            text = g_strdup(value);

        g_free(value);

        adg_textual_set_text(data->quote.value, text);
        g_free(text);
    }

    if (data->quote.min == NULL && data->min != NULL) {
        AdgDress dress = adg_dim_style_get_min_dress(data->dim_style);

        data->quote.min = g_object_new(ADG_TYPE_BEST_TEXT,
                                       "local-mix", ADG_MIX_PARENT,
                                       "font-dress", dress, NULL);

        adg_container_add(quote_container, (AdgEntity *) data->quote.min);
        adg_textual_set_text(data->quote.min, data->min);
    }

    if (data->quote.max == NULL && data->max != NULL) {
        AdgDress dress = adg_dim_style_get_max_dress(data->dim_style);

        data->quote.max = g_object_new(ADG_TYPE_BEST_TEXT,
                                       "local-mix", ADG_MIX_PARENT,
                                       "font-dress", dress, NULL);

        adg_container_add(quote_container, (AdgEntity *) data->quote.max);
        adg_textual_set_text(data->quote.max, data->max);
    }

    value_entity = (AdgEntity *) data->quote.value;
    min_entity = (AdgEntity *) data->quote.min;
    max_entity = (AdgEntity *) data->quote.max;
    shift = adg_dim_style_get_quote_shift(data->dim_style);

    adg_entity_set_global_map(quote_entity, adg_matrix_identity());
    adg_entity_global_changed(quote_entity);

    cairo_matrix_init_translate(&map, 0, shift->y);
    adg_entity_set_global_map(value_entity, &map);
    adg_entity_arrange(value_entity);

    /* Limit values (min and max) */
    if (min_entity != NULL || max_entity != NULL) {
        const CpmlPair *limits_shift;
        gdouble spacing;
        CpmlPair size;
        CpmlPair org_min, org_max;

        limits_shift = adg_dim_style_get_limits_shift(data->dim_style);
        spacing = adg_dim_style_get_limits_spacing(data->dim_style);
        size = adg_entity_get_extents(value_entity)->size;
        org_min.x = size.x + limits_shift->x;
        org_min.y = -size.y / 2 + limits_shift->y;
        org_max = org_min;

        if (min_entity && max_entity) {
            /* Prearrange the min entity to get its extents */
            adg_entity_arrange(min_entity);
            size = adg_entity_get_extents(min_entity)->size;

            org_min.y += spacing / 2;
            org_max.y = org_min.y - size.y - spacing / 2;
        }

        if (min_entity != NULL) {
            cairo_matrix_init_translate(&map, org_min.x, org_min.y);
            adg_entity_set_global_map(min_entity, &map);
            adg_entity_arrange(min_entity);
        }

        if (max_entity != NULL) {
            cairo_matrix_init_translate(&map, org_max.x, org_max.y);
            adg_entity_set_global_map(max_entity, &map);
            adg_entity_arrange(max_entity);
        }
    }
}