More GTK+ uiArea work. Not sure what I'll do about DPI; GTK+ handles scaling for us...
This commit is contained in:
parent
8344ed5f17
commit
33c1852e21
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
20
gtkarea/ui.h
20
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;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue