Example #1
0
/**
 * gwy_layer_basic_set_gradient:
 * @layer: A basic data view layer.
 * @gradient: Name of gradient @layer should use.  It should exist.
 *
 * Sets the color gradient a basic layer should use.
 *
 * Since: 1.8
 **/
void
gwy_layer_basic_set_gradient(GwyLayerBasic *layer,
                             const gchar *gradient)
{
    GwyGradient *grad, *old;
    gchar *gradstr;

    g_return_if_fail(GWY_IS_LAYER_BASIC(layer));
    gwy_debug("%s", gradient);

    grad = gwy_gradients_get_gradient(gradient);
    if (!grad || grad == layer->gradient)
        return;

    /* the string we've got as argument can be owned by somethin we are
     * going to destroy */
    gradstr = g_strdup(gradient);
    old = layer->gradient;
    g_signal_handlers_disconnect_matched(layer->gradient, G_SIGNAL_MATCH_DATA,
                                         0, 0, NULL, NULL, layer);
    g_object_ref(grad);
    layer->gradient = grad;
    g_signal_connect_swapped(layer->gradient, "value_changed",
                             G_CALLBACK(gwy_layer_basic_update), layer);
    gwy_container_set_string_by_name(GWY_DATA_VIEW_LAYER(layer)->data,
                                     "/0/base/palette", gradstr);
    g_object_unref(old);
    /* XXX: remove */
    if (!gwy_palette_set_by_name(layer->palette, gradstr))
        g_warning("Palette <%s> doesn't exist, we've got out of sync",
                  gradstr);

    gwy_layer_basic_update(GWY_DATA_VIEW_LAYER(layer));
}
Example #2
0
/**
 * gwy_color_axis_set_gradient:
 * @axis: A color axis.
 * @gradient: Name of gradient @axis should use.  It should exist.
 *
 * Sets the color gradient a color axis should use.
 *
 * Since: 1.8
 **/
void
gwy_color_axis_set_gradient(GwyColorAxis *axis,
                            const gchar *gradient)
{
    GwyGradient *grad, *old;

    g_return_if_fail(GWY_IS_COLOR_AXIS(axis));

    grad = gwy_gradients_get_gradient(gradient);
    if (!grad || grad == axis->gradient)
        return;

    old = axis->gradient;
    g_signal_handlers_disconnect_matched(axis->gradient, G_SIGNAL_MATCH_DATA,
                                         0, 0, NULL, NULL, axis);
    g_object_ref(grad);
    axis->gradient = grad;
    g_signal_connect_swapped(axis->gradient, "value_changed",
                             G_CALLBACK(gwy_color_axis_update), axis);
    g_object_unref(old);
    /* XXX: remove */
    gwy_palette_set_by_name(axis->palette, gradient);

    gwy_color_axis_update(axis);
}
Example #3
0
/* FIXME: this should be the default constructor */
GtkWidget*
gwy_color_axis_new_default(GtkOrientation orientation)
{
    GwyColorAxis *axis;

    gwy_debug(" ");

    axis = (GwyColorAxis*)g_object_new(GWY_TYPE_COLOR_AXIS, NULL);
    axis->orientation = orientation;
    /* TODO: use some font properties, at least */
    if (orientation == GTK_ORIENTATION_VERTICAL)
        axis->par.textarea = 70;
    else
        axis->par.textarea = 20;

    axis->min = 0.0;
    axis->max = 1.0;

    axis->par.font = pango_font_description_from_string("Helvetica 10");
    axis->gradient = gwy_gradients_get_gradient(GWY_GRADIENT_DEFAULT);
    g_object_ref(axis->gradient);
    /* XXX: remove */
    axis->palette = (GwyPalette*)gwy_palette_new(NULL);
    axis->siunit = GWY_SI_UNIT(gwy_si_unit_new("m"));

    return GTK_WIDGET(axis);
}
Example #4
0
static void
gwy_layer_basic_gradient_connect(GwyLayerBasic *basic_layer)
{
    GwyDataViewLayer *layer;
    const guchar *s = NULL;

    g_return_if_fail(!basic_layer->gradient);
    layer = GWY_DATA_VIEW_LAYER(basic_layer);
    if (basic_layer->gradient_key)
        gwy_container_gis_string(layer->data, basic_layer->gradient_key, &s);
    basic_layer->gradient = gwy_gradients_get_gradient(s);
    gwy_resource_use(GWY_RESOURCE(basic_layer->gradient));
    basic_layer->gradient_id
        = g_signal_connect_swapped(basic_layer->gradient, "data-changed",
                                   G_CALLBACK(gwy_layer_basic_changed), layer);
}
Example #5
0
static void
immerse_update_detail_pixbuf(ImmerseControls *controls)
{
    GwyContainer *data;
    GwyDataField *dfield;
    GwyGradient *gradient;
    GdkPixbuf *pixbuf;
    const guchar *name;
    gchar *key;
    GQuark quark;
    gint w, h, xres, yres;

    GWY_OBJECT_UNREF(controls->detail);
    data = gwy_app_data_browser_get(controls->args->detail.datano);
    if (!data)
        return;

    quark = gwy_app_get_data_key_for_id(controls->args->detail.id);
    dfield = gwy_container_get_object(data, quark);
    gwy_data_view_coords_real_to_xy(GWY_DATA_VIEW(controls->view),
                                    gwy_data_field_get_xreal(dfield),
                                    gwy_data_field_get_yreal(dfield),
                                    &w, &h);
    gwy_debug("%dx%d", w, h);
    w = MAX(w, 2);
    h = MAX(h, 2);

    key = g_strdup_printf("/%d/base/palette", controls->args->image.id);
    name = NULL;
    data = gwy_app_data_browser_get(controls->args->image.datano);
    gwy_container_gis_string_by_name(data, key, &name);
    g_free(key);
    gradient = gwy_gradients_get_gradient(name);

    /* Handle real-square properly by using an intermediate
     * pixel-square pixbuf with sufficient resolution */
    xres = gwy_data_field_get_xres(dfield);
    yres = gwy_data_field_get_yres(dfield);
    pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, xres, yres);
    gwy_pixbuf_draw_data_field(pixbuf, dfield, gradient);
    controls->detail = gdk_pixbuf_scale_simple(pixbuf, w, h, GDK_INTERP_TILES);
    g_object_unref(pixbuf);
}
Example #6
0
/**
 * gwy_layer_basic_new:
 *
 * Creates a new basic data displaying layer.
 *
 * By default, is uses a gray gradient or gradient whose name is stored with
 * the data as "/0/base/palette".
 *
 * Other used container values: "/0/show" is shown instead of "/0/data" if
 * present.  If "/0/base/min" and "/0/base/max" is set, it is used as the
 * color scale range instead of fitting it to data value range.
 *
 * Returns: The newly created layer.
 **/
GtkObject*
gwy_layer_basic_new(void)
{
    GtkObject *object;
    GwyLayerBasic *layer;

    gwy_debug(" ");

    object = g_object_new(GWY_TYPE_LAYER_BASIC, NULL);
    layer = (GwyLayerBasic*)object;

    layer->gradient = gwy_gradients_get_gradient(GWY_GRADIENT_DEFAULT);
    g_object_ref(layer->gradient);
    /* XXX: remove */
    layer->palette = (GwyPalette*)gwy_palette_new(NULL);
    gwy_palette_set_by_name(layer->palette, GWY_GRADIENT_DEFAULT);

    return object;
}
Example #7
0
/**
 * gwy_color_axis_new:
 * @orientation: The orientation of the axis.
 * @min: The minimum.
 * @max: The maximum.
 * @pal: The palette the color axis should use.
 *
 * Creates a new color axis.
 *
 * Returns: The newly created color axis as a #GtkWidget.
 **/
GtkWidget*
gwy_color_axis_new(GtkOrientation orientation,
                   gdouble min,
                   gdouble max,
                   GwyPalette *pal)
{
    GwyColorAxis *axis;

    gwy_debug("");
    g_return_val_if_fail(GWY_IS_PALETTE(pal), NULL);

    axis = gtk_type_new(gwy_color_axis_get_type());
    axis->orientation = orientation;
    /* TODO: use some font properties, at least */
    if (orientation == GTK_ORIENTATION_VERTICAL)
        axis->par.textarea = 70;
    else
        axis->par.textarea = 20;
    axis->min = min;
    axis->max = max;

    /* XXX */
    axis->par.font = pango_font_description_new();
    pango_font_description_set_family(axis->par.font, "Helvetica");
    pango_font_description_set_style(axis->par.font, PANGO_STYLE_NORMAL);
    pango_font_description_set_variant(axis->par.font, PANGO_VARIANT_NORMAL);
    pango_font_description_set_weight(axis->par.font, PANGO_WEIGHT_NORMAL);
    pango_font_description_set_size(axis->par.font, 10*PANGO_SCALE);

    axis->gradient = gwy_gradients_get_gradient(GWY_GRADIENT_DEFAULT);
    g_object_ref(axis->gradient);
    /* XXX: remove */
    axis->palette = (GwyPalette*)gwy_palette_new(NULL);
    gwy_color_axis_set_palette(axis, pal);
    axis->siunit = GWY_SI_UNIT(gwy_si_unit_new("m"));

    return GTK_WIDGET(axis);
}