Ejemplo n.º 1
0
static void
foo_canvas_widget_update (FooCanvasItem *item, double i2w_dx, double i2w_dy, int flags)
{
    FooCanvasWidget *witem;

    witem = FOO_CANVAS_WIDGET (item);

    if (parent_class->update)
        (* parent_class->update) (item, i2w_dx, i2w_dy, flags);

    if (witem->widget) {
        GtkRequisition req;
        if (witem->size_pixels) {
            witem->cwidth = (int) (witem->width + 0.5);
            witem->cheight = (int) (witem->height + 0.5);
        } else {
            witem->cwidth = (int) (witem->width * item->canvas->pixels_per_unit + 0.5);
            witem->cheight = (int) (witem->height * item->canvas->pixels_per_unit + 0.5);
        }
        req.width = witem->cwidth;
        req.height = witem->cheight;
        gtk_widget_size_request (witem->widget, &req);
    } else {
        witem->cwidth = 0.0;
        witem->cheight = 0.0;
    }

    recalc_bounds (witem);
}
Ejemplo n.º 2
0
    bool object_selection_t::remove_object_index(size_t obj_ind)
    {
        // not 100% sure if it erases the object at this position, or with this key
        // I think it's with the key
        auto n = object_indices.erase(obj_ind);
        recalc_bounds();

        return n > 0;
    }
Ejemplo n.º 3
0
    bool object_selection_t::add_object_index(size_t obj_ind)
    {
        auto x = object_indices.insert(obj_ind);
        recalc_bounds();

        //second value of pair returned by insert is a bool that is true
        //if the insertion took place
        return x.second;
    }
Ejemplo n.º 4
0
 void object_selection_t::clear_selection()
 {
     object_indices.clear();
     recalc_bounds();
 }
Ejemplo n.º 5
0
static void
foo_canvas_widget_set_property (GObject            *object,
                                guint               param_id,
                                const GValue       *value,
                                GParamSpec         *pspec)
{
    FooCanvasItem *item;
    FooCanvasWidget *witem;
    GObject *obj;
    int update;
    int calc_bounds;

    g_return_if_fail (object != NULL);
    g_return_if_fail (FOO_IS_CANVAS_WIDGET (object));

    item = FOO_CANVAS_ITEM (object);
    witem = FOO_CANVAS_WIDGET (object);

    update = FALSE;
    calc_bounds = FALSE;

    switch (param_id) {
    case PROP_WIDGET:
        if (witem->widget) {
            g_signal_handler_disconnect (G_OBJECT (witem->widget), witem->destroy_id);
            gtk_container_remove (GTK_CONTAINER (item->canvas), witem->widget);
        }

        obj = g_value_get_object (value);
        if (obj) {
            witem->widget = GTK_WIDGET (obj);
            witem->destroy_id = g_signal_connect (G_OBJECT (obj),
                                                  "destroy", G_CALLBACK (do_destroy), witem);
            gtk_layout_put (GTK_LAYOUT (item->canvas), witem->widget,
                            witem->cx + item->canvas->zoom_xofs,
                            witem->cy + item->canvas->zoom_yofs);
        }

        update = TRUE;
        break;

    case PROP_X:
        if (witem->x != g_value_get_double (value))
        {
            witem->x = g_value_get_double (value);
            calc_bounds = TRUE;
        }
        break;

    case PROP_Y:
        if (witem->y != g_value_get_double (value))
        {
            witem->y = g_value_get_double (value);
            calc_bounds = TRUE;
        }
        break;

    case PROP_WIDTH:
        if (witem->width != fabs (g_value_get_double (value)))
        {
            witem->width = fabs (g_value_get_double (value));
            update = TRUE;
        }
        break;

    case PROP_HEIGHT:
        if (witem->height != fabs (g_value_get_double (value)))
        {
            witem->height = fabs (g_value_get_double (value));
            update = TRUE;
        }
        break;

    case PROP_ANCHOR:
        if (witem->anchor != (GtkAnchorType)g_value_get_enum (value))
        {
            witem->anchor = g_value_get_enum (value);
            update = TRUE;
        }
        break;

    case PROP_SIZE_PIXELS:
        if (witem->size_pixels != g_value_get_boolean (value))
        {
            witem->size_pixels = g_value_get_boolean (value);
            update = TRUE;
        }
        break;

    default:
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
        break;
    }

    if (update)
        (* FOO_CANVAS_ITEM_GET_CLASS (item)->update) (item, 0, 0, 0);

    if (calc_bounds)
        recalc_bounds (witem);
}