diff --git a/gtkarea/area.c b/gtkarea/area.c index 54955b03..8e00ce24 100644 --- a/gtkarea/area.c +++ b/gtkarea/area.c @@ -7,6 +7,7 @@ struct areaPrivate { GtkAdjustment *ha; GtkAdjustment *va; + // TODO get rid of the need for these int clientWidth; int clientHeight; // needed for GtkScrollable @@ -118,33 +119,24 @@ static gboolean areaWidget_draw(GtkWidget *w, cairo_t *cr) { areaWidget *a = areaWidget(w); struct areaPrivate *ap = a->priv; - char *msg; - PangoLayout *layout; - int ypos; - int height; + uiAreaDrawParams dp; + double clipX0, clipY0, clipX1, clipY1; - ypos = 5; + // TODO dp.Context - msg = g_strdup_printf("client width %d height %d", - ap->clientWidth, ap->clientHeight); - layout = gtk_widget_create_pango_layout(GTK_WIDGET(a), msg); - cairo_move_to(cr, 5, ypos); - pango_cairo_show_layout(cr, layout); - pango_layout_get_pixel_size(layout, NULL, &height); - ypos += height; - g_object_unref(layout); - g_free(msg); + dp.ClientWidth = ap->clientWidth; + dp.ClientHeight = ap->clientHeight; - msg = g_strdup_printf("hscroll %d vscroll %d", - (int) gtk_adjustment_get_value(ap->ha), - (int) gtk_adjustment_get_value(ap->va)); - layout = gtk_widget_create_pango_layout(GTK_WIDGET(a), msg); - cairo_move_to(cr, 5, ypos); - pango_cairo_show_layout(cr, layout); - pango_layout_get_pixel_size(layout, NULL, &height); - ypos += height; - g_object_unref(layout); - g_free(msg); + cairo_clip_extents(cr, &clipX0, &clipY0, &clipX1, &clipY1); + dp.ClipX = clipX0; + dp.ClipY = clipY0; + dp.ClipWidth = clipX1 - clipX0; + dp.ClipHeight = clipY1 - clipY0; + + dp.HScrollPos = gtk_adjustment_get_value(ap->ha); + dp.VScrollPos = gtk_adjustment_get_value(ap->va); + + (*(ap->ah->Draw))(ap->ah, ap->a, &dp); return FALSE; } @@ -168,6 +160,7 @@ static GParamSpec *pspecAreaHandler; static void onValueChanged(GtkAdjustment *a, gpointer data) { + // there's no way to scroll the contents of a widget, so we have to redraw the entire thing gtk_widget_queue_draw(GTK_WIDGET(data)); } diff --git a/gtkarea/main.c b/gtkarea/main.c index 6d39574e..859905fb 100644 --- a/gtkarea/main.c +++ b/gtkarea/main.c @@ -12,6 +12,11 @@ static struct handler h; static GtkWidget *nhspinb; static GtkWidget *nvspinb; +static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *params) +{ + // TODO +} + static uintmax_t handlerHScrollMax(uiAreaHandler *a, uiArea *area) { return gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(nhspinb)); @@ -44,6 +49,7 @@ int main(void) GtkWidget *scroller; GtkWidget *grid; + h.ah.Draw = handlerDraw; h.ah.HScrollMax = handlerHScrollMax; h.ah.VScrollMax = handlerVScrollMax; @@ -63,8 +69,6 @@ int main(void) gtk_widget_set_valign(scroller, GTK_ALIGN_FILL); gtk_container_add(GTK_CONTAINER(box), scroller); - // TODO area - grid = gtk_grid_new(); gtk_widget_set_halign(grid, GTK_ALIGN_START); gtk_container_add(GTK_CONTAINER(box), grid); diff --git a/gtkarea/ui.h b/gtkarea/ui.h index 91823985..9032f9a7 100644 --- a/gtkarea/ui.h +++ b/gtkarea/ui.h @@ -5,9 +5,25 @@ typedef struct uiAreaHandler uiAreaHandler; typedef struct uiAreaDrawParams uiAreaDrawParams; struct uiAreaHandler { - // TODO draw + void (*Draw)(uiAreaHandler *, uiArea *, uiAreaDrawParams *); uintmax_t (*HScrollMax)(uiAreaHandler *, uiArea *); uintmax_t (*VScrollMax)(uiAreaHandler *, uiArea *); }; -// TODO uiAreaDrawParams +struct uiAreaDrawParams { + // TODO context + + intmax_t ClientWidth; + intmax_t ClientHeight; + + intmax_t ClipX; + intmax_t ClipY; + intmax_t ClipWidth; + intmax_t ClipHeight; + +//TODO xxxx DPIX; +//TODO xxxx DPIY; + + intmax_t HScrollPos; + intmax_t VScrollPos; +};