]> git.tdb.fi Git - ext/subsurface.git/blobdiff - gtk-gui.c
Change plot routine to take a drawing_area as argument
[ext/subsurface.git] / gtk-gui.c
index 002b804148cb977a10d79a45138b96d1ce8f4799..a5728e2c8e5149e54d30c79cd95df02e40f6665e 100644 (file)
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -205,6 +205,42 @@ static void quit(GtkWidget *w, gpointer data)
        gtk_main_quit();
 }
 
+GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title,
+                               data_func_t data_func, PangoAlignment align, gboolean visible)
+{
+       GtkCellRenderer *renderer;
+       GtkTreeViewColumn *col;
+       double xalign = 0.0; /* left as default */
+
+       renderer = gtk_cell_renderer_text_new();
+       col = gtk_tree_view_column_new();
+
+       gtk_tree_view_column_set_title(col, title);
+       gtk_tree_view_column_set_sort_column_id(col, index);
+       gtk_tree_view_column_set_resizable(col, TRUE);
+       gtk_tree_view_column_pack_start(col, renderer, TRUE);
+       if (data_func)
+               gtk_tree_view_column_set_cell_data_func(col, renderer, data_func, (void *)(long)index, NULL);
+       else
+               gtk_tree_view_column_add_attribute(col, renderer, "text", index);
+       gtk_object_set(GTK_OBJECT(renderer), "alignment", align, NULL);
+       switch (align) {
+       case PANGO_ALIGN_LEFT:
+               xalign = 0.0;
+               break;
+       case PANGO_ALIGN_CENTER:
+               xalign = 0.5;
+               break;
+       case PANGO_ALIGN_RIGHT:
+               xalign = 1.0;
+               break;
+       }
+       gtk_cell_renderer_set_alignment(GTK_CELL_RENDERER(renderer), xalign, 0.5);
+       gtk_tree_view_column_set_visible(col, visible);
+       gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), col);
+       return col;
+}
+
 static void create_radio(GtkWidget *vbox, const char *name, ...)
 {
        va_list args;
@@ -638,18 +674,21 @@ static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer
 {
        struct dive *dive = current_dive;
        struct graphics_context gc = { .printer = 0 };
-       int w,h;
+       static cairo_rectangle_int_t drawing_area;
 
-       w = widget->allocation.width;
-       h = widget->allocation.height;
+       /* the drawing area gives TOTAL width * height - x,y is used as the topx/topy offset
+        * so effective drawing area is width-2x * height-2y */
+       drawing_area.width = widget->allocation.width;
+       drawing_area.height = widget->allocation.height;
+       drawing_area.x = drawing_area.width / 20.0;
+       drawing_area.y = drawing_area.height / 20.0;
 
        gc.cr = gdk_cairo_create(widget->window);
        set_source_rgb(&gc, 0, 0, 0);
        cairo_paint(gc.cr);
 
        if (dive)
-               plot(&gc, w, h, dive);
-
+               plot(&gc, &drawing_area, dive);
        cairo_destroy(gc.cr);
 
        return FALSE;