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 *ha;
|
||||||
GtkAdjustment *va;
|
GtkAdjustment *va;
|
||||||
|
// TODO get rid of the need for these
|
||||||
int clientWidth;
|
int clientWidth;
|
||||||
int clientHeight;
|
int clientHeight;
|
||||||
// needed for GtkScrollable
|
// needed for GtkScrollable
|
||||||
|
@ -118,33 +119,24 @@ static gboolean areaWidget_draw(GtkWidget *w, cairo_t *cr)
|
||||||
{
|
{
|
||||||
areaWidget *a = areaWidget(w);
|
areaWidget *a = areaWidget(w);
|
||||||
struct areaPrivate *ap = a->priv;
|
struct areaPrivate *ap = a->priv;
|
||||||
char *msg;
|
uiAreaDrawParams dp;
|
||||||
PangoLayout *layout;
|
double clipX0, clipY0, clipX1, clipY1;
|
||||||
int ypos;
|
|
||||||
int height;
|
|
||||||
|
|
||||||
ypos = 5;
|
// TODO dp.Context
|
||||||
|
|
||||||
msg = g_strdup_printf("client width %d height %d",
|
dp.ClientWidth = ap->clientWidth;
|
||||||
ap->clientWidth, ap->clientHeight);
|
dp.ClientHeight = 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);
|
|
||||||
|
|
||||||
msg = g_strdup_printf("hscroll %d vscroll %d",
|
cairo_clip_extents(cr, &clipX0, &clipY0, &clipX1, &clipY1);
|
||||||
(int) gtk_adjustment_get_value(ap->ha),
|
dp.ClipX = clipX0;
|
||||||
(int) gtk_adjustment_get_value(ap->va));
|
dp.ClipY = clipY0;
|
||||||
layout = gtk_widget_create_pango_layout(GTK_WIDGET(a), msg);
|
dp.ClipWidth = clipX1 - clipX0;
|
||||||
cairo_move_to(cr, 5, ypos);
|
dp.ClipHeight = clipY1 - clipY0;
|
||||||
pango_cairo_show_layout(cr, layout);
|
|
||||||
pango_layout_get_pixel_size(layout, NULL, &height);
|
dp.HScrollPos = gtk_adjustment_get_value(ap->ha);
|
||||||
ypos += height;
|
dp.VScrollPos = gtk_adjustment_get_value(ap->va);
|
||||||
g_object_unref(layout);
|
|
||||||
g_free(msg);
|
(*(ap->ah->Draw))(ap->ah, ap->a, &dp);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -168,6 +160,7 @@ static GParamSpec *pspecAreaHandler;
|
||||||
|
|
||||||
static void onValueChanged(GtkAdjustment *a, gpointer data)
|
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));
|
gtk_widget_queue_draw(GTK_WIDGET(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,11 @@ static struct handler h;
|
||||||
static GtkWidget *nhspinb;
|
static GtkWidget *nhspinb;
|
||||||
static GtkWidget *nvspinb;
|
static GtkWidget *nvspinb;
|
||||||
|
|
||||||
|
static void handlerDraw(uiAreaHandler *a, uiArea *area, uiAreaDrawParams *params)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
static uintmax_t handlerHScrollMax(uiAreaHandler *a, uiArea *area)
|
static uintmax_t handlerHScrollMax(uiAreaHandler *a, uiArea *area)
|
||||||
{
|
{
|
||||||
return gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(nhspinb));
|
return gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(nhspinb));
|
||||||
|
@ -44,6 +49,7 @@ int main(void)
|
||||||
GtkWidget *scroller;
|
GtkWidget *scroller;
|
||||||
GtkWidget *grid;
|
GtkWidget *grid;
|
||||||
|
|
||||||
|
h.ah.Draw = handlerDraw;
|
||||||
h.ah.HScrollMax = handlerHScrollMax;
|
h.ah.HScrollMax = handlerHScrollMax;
|
||||||
h.ah.VScrollMax = handlerVScrollMax;
|
h.ah.VScrollMax = handlerVScrollMax;
|
||||||
|
|
||||||
|
@ -63,8 +69,6 @@ int main(void)
|
||||||
gtk_widget_set_valign(scroller, GTK_ALIGN_FILL);
|
gtk_widget_set_valign(scroller, GTK_ALIGN_FILL);
|
||||||
gtk_container_add(GTK_CONTAINER(box), scroller);
|
gtk_container_add(GTK_CONTAINER(box), scroller);
|
||||||
|
|
||||||
// TODO area
|
|
||||||
|
|
||||||
grid = gtk_grid_new();
|
grid = gtk_grid_new();
|
||||||
gtk_widget_set_halign(grid, GTK_ALIGN_START);
|
gtk_widget_set_halign(grid, GTK_ALIGN_START);
|
||||||
gtk_container_add(GTK_CONTAINER(box), grid);
|
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;
|
typedef struct uiAreaDrawParams uiAreaDrawParams;
|
||||||
|
|
||||||
struct uiAreaHandler {
|
struct uiAreaHandler {
|
||||||
// TODO draw
|
void (*Draw)(uiAreaHandler *, uiArea *, uiAreaDrawParams *);
|
||||||
uintmax_t (*HScrollMax)(uiAreaHandler *, uiArea *);
|
uintmax_t (*HScrollMax)(uiAreaHandler *, uiArea *);
|
||||||
uintmax_t (*VScrollMax)(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