Beispiel #1
0
static void
gwy_graph_label_unrealize(GtkWidget *widget)
{
    GwyGraphLabel *label;

    label = GWY_GRAPH_LABEL(widget);

    if (GTK_WIDGET_CLASS(gwy_graph_label_parent_class)->unrealize)
        GTK_WIDGET_CLASS(gwy_graph_label_parent_class)->unrealize(widget);
}
Beispiel #2
0
static void
gwy_graph_label_size_request(GtkWidget *widget,
                             GtkRequisition *requisition)
{
    GwyGraphLabel *label;

    gwy_debug("");

    label = GWY_GRAPH_LABEL(widget);
    requisition->width = label->reqwidth;
    requisition->height = label->reqheight;
}
Beispiel #3
0
static void
gwy_graph_label_finalize(GObject *object)
{
    GwyGraphLabel *label;

    label = GWY_GRAPH_LABEL(object);

    gwy_signal_handler_disconnect(label->graph_model, label->model_notify_id);
    gwy_signal_handler_disconnect(label->graph_model, label->curve_notify_id);
    gwy_object_unref(label->graph_model);

    pango_font_description_free(label->font_desc);
    g_array_free(label->samplepos, TRUE);

    G_OBJECT_CLASS(gwy_graph_label_parent_class)->finalize(object);
}
Beispiel #4
0
static void
gwy_graph_label_size_allocate(GtkWidget *widget,
                              GtkAllocation *allocation)
{
    GwyGraphLabel *label;

    gwy_debug("");

    widget->allocation = *allocation;
    if (GTK_WIDGET_REALIZED(widget)) {
        label = GWY_GRAPH_LABEL(widget);

        gdk_window_move_resize(widget->window,
                               allocation->x, allocation->y,
                               allocation->width, allocation->height);
    }
}
Beispiel #5
0
static gboolean
gwy_graph_label_expose(GtkWidget *widget,
                       GdkEventExpose *event)
{
    GwyGraphLabel *label;

    gwy_debug("");

    if (event->count > 0)
        return FALSE;

    label = GWY_GRAPH_LABEL(widget);
    gdk_window_clear_area(widget->window,
                          0, 0,
                          widget->allocation.width,
                          widget->allocation.height);
    gwy_graph_label_draw_label(widget);

    return FALSE;
}
Beispiel #6
0
static void
gwy_graph_label_realize(GtkWidget *widget)
{
    GwyGraphLabel *label;
    GdkWindowAttr attributes;
    gint i, attributes_mask;
    GtkStyle *style;

    gwy_debug("realizing a GwyGraphLabel (%ux%u)",
              widget->allocation.width, widget->allocation.height);

    GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
    label = GWY_GRAPH_LABEL(widget);

    attributes.x = widget->allocation.x;
    attributes.y = widget->allocation.y;
    attributes.width = widget->allocation.width;
    attributes.height = widget->allocation.height;
    attributes.wclass = GDK_INPUT_OUTPUT;
    attributes.window_type = GDK_WINDOW_CHILD;
    attributes.event_mask = gtk_widget_get_events(widget)
                            | GDK_EXPOSURE_MASK;
    attributes.visual = gtk_widget_get_visual(widget);
    attributes.colormap = gtk_widget_get_colormap(widget);

    attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
    widget->window = gdk_window_new(gtk_widget_get_parent_window(widget),
                                    &attributes, attributes_mask);
    gdk_window_set_user_data(widget->window, widget);
    widget->style = gtk_style_attach(widget->style, widget->window);

    /* set background to white forever */
    style = gtk_style_copy(widget->style);
    for (i = 0; i < 5; i++) {
        style->bg_gc[i] = widget->style->white_gc;
        style->bg[i] = widget->style->white;
    }
    gtk_style_set_background(style, widget->window, GTK_STATE_NORMAL);
    g_object_unref(style);
}
Beispiel #7
0
static void
gwy_graph_label_draw_label(GtkWidget *widget)
{
    gint winheight, winwidth, windepth, winx, winy;
    GwyGraphLabel *label;
    PangoLayout *layout;
    GdkGC *mygc;

    mygc = gdk_gc_new(widget->window);

    label = GWY_GRAPH_LABEL(widget);
    layout = gtk_widget_create_pango_layout(widget, NULL);

    gdk_window_get_geometry(widget->window,
                            &winx, &winy, &winwidth, &winheight, &windepth);
    gwy_graph_label_draw_on_drawable(label, GDK_DRAWABLE(widget->window),
                                     mygc, layout,
                                     0, 0, winwidth, winheight);
    g_object_unref(mygc);
    g_object_unref(layout);

}
Beispiel #8
0
GdkPixbuf*
gwy_graph_export_pixmap(GwyGraph *graph,
                        G_GNUC_UNUSED gboolean export_title,
                        G_GNUC_UNUSED gboolean export_axis,
                        G_GNUC_UNUSED gboolean export_labels)
{
    GdkColor color = { 0, 65535, 65535, 65535 };
    GdkPixbuf *pixbuf;
    GdkColormap *cmap;
    GdkGC *gc;
    GdkVisual *visual;
    GdkPixmap *pixmap;
    PangoLayout *layout;
    PangoContext *context;
    gint width, height, topheight, bottomheight, rightwidth, leftwidth;
    gint labelx, labely, labelw, labelh;

    width = (GTK_WIDGET(graph))->allocation.width;
    height = (GTK_WIDGET(graph))->allocation.height;

    topheight = (GTK_WIDGET(graph->axis[GTK_POS_TOP]))->allocation.height;
    bottomheight = (GTK_WIDGET(graph->axis[GTK_POS_BOTTOM]))->allocation.height;
    leftwidth = (GTK_WIDGET(graph->axis[GTK_POS_LEFT]))->allocation.width;
    rightwidth = (GTK_WIDGET(graph->axis[GTK_POS_RIGHT]))->allocation.width;

    labelx = (GTK_WIDGET(graph->area->lab))->allocation.x + leftwidth;
    labely = (GTK_WIDGET(graph->area->lab))->allocation.y + topheight;
    labelw = (GWY_GRAPH_LABEL(graph->area->lab))->reqwidth;
    labelh = (GWY_GRAPH_LABEL(graph->area->lab))->reqheight;

    visual = gdk_visual_get_best();
    cmap = gdk_colormap_new(visual, FALSE);

    pixmap = gdk_pixmap_new(NULL, width, height, visual->depth);
    gdk_drawable_set_colormap(pixmap, cmap);

    gc = gdk_gc_new(pixmap);
    gdk_gc_set_colormap(gc, cmap);

    gdk_gc_set_rgb_fg_color(gc, &color);
    gdk_draw_rectangle(pixmap, gc, TRUE, 0, 0, width, height);

    gwy_graph_area_draw_on_drawable(graph->area, pixmap, gc,
                                    leftwidth, topheight,
                                    width - leftwidth - rightwidth,
                                    height - topheight - bottomheight);

    /* Draw axes */
    gwy_axis_draw_on_drawable(graph->axis[GTK_POS_TOP], pixmap, gc,
                              leftwidth, 0,
                              width - leftwidth - rightwidth, topheight);
    gwy_axis_draw_on_drawable(graph->axis[GTK_POS_BOTTOM], pixmap, gc,
                              leftwidth, height - bottomheight,
                              width - leftwidth - rightwidth, bottomheight);
    gwy_axis_draw_on_drawable(graph->axis[GTK_POS_LEFT], pixmap, gc,
                              0, topheight,
                              leftwidth, height - topheight - bottomheight);
    gwy_axis_draw_on_drawable(graph->axis[GTK_POS_RIGHT], pixmap, gc,
                              width - rightwidth, topheight,
                              rightwidth, height - topheight - bottomheight);

    context = gdk_pango_context_get_for_screen(gdk_screen_get_default());
    pango_context_set_font_description(context, graph->area->lab->font_desc);
    layout = pango_layout_new(context);
    gwy_graph_label_draw_on_drawable(graph->area->lab, pixmap, gc, layout,
                                     labelx, labely, labelw, labelh);

    pixbuf = gdk_pixbuf_get_from_drawable(NULL, pixmap, cmap,
                                          0, 0, 0, 0,
                                          -1, -1);

    g_object_unref(pixmap);
    g_object_unref(layout);
    g_object_unref(context);
    g_object_unref(gc);
    g_object_unref(cmap);

    return pixbuf;
}