From 62ea7c94a5ee8d5e17e8bb3b1ff4315253c61f82 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Sun, 20 Jan 2013 06:44:25 +0000 Subject: [PATCH] Convert to GtkAllocation --- src/grits-opengl.c | 18 +++++++++++------- src/objects/grits-marker.c | 5 +++-- src/plugins/env.c | 14 +++++++------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/grits-opengl.c b/src/grits-opengl.c index 6a5ea32..c4c7dac 100644 --- a/src/grits-opengl.c +++ b/src/grits-opengl.c @@ -68,8 +68,10 @@ static void _set_projection(GritsOpenGL *opengl) glMatrixMode(GL_PROJECTION); glLoadIdentity(); - double width = GTK_WIDGET(opengl)->allocation.width; - double height = GTK_WIDGET(opengl)->allocation.height; + GtkAllocation alloc; + gtk_widget_get_allocation(GTK_WIDGET(opengl), &alloc); + double width = alloc.width; + double height = alloc.height; double ang = atan((height/2)/FOV_DIST)*2; double atmos = 100000; double near = MAX(elev*0.75 - atmos, 50); // View 100km of atmosphere @@ -219,9 +221,11 @@ static gint run_picking(GritsOpenGL *opengl, GdkEvent *event, static gboolean run_mouse_move(GritsOpenGL *opengl, GdkEventMotion *event) { - gdouble height = GTK_WIDGET(opengl)->allocation.height; + GtkAllocation alloc; + gtk_widget_get_allocation(GTK_WIDGET(opengl), &alloc); + gdouble gl_x = event->x; - gdouble gl_y = height - event->y; + gdouble gl_y = alloc.height - event->y; gdouble delta = opengl->pickmode ? 200 : 2; if (opengl->pickmode) { @@ -322,11 +326,11 @@ static void _draw_level(gpointer _level, gpointer _opengl) /* Start ortho */ if (level->num >= GRITS_LEVEL_HUD) { + GtkAllocation alloc; + gtk_widget_get_allocation(GTK_WIDGET(opengl), &alloc); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); - gint win_width = GTK_WIDGET(opengl)->allocation.width; - gint win_height = GTK_WIDGET(opengl)->allocation.height; - glOrtho(0, win_width, win_height, 0, 1000, -1000); + glOrtho(0, alloc.width, alloc.height, 0, 1000, -1000); } /* Draw unsorted objects without depth testing, diff --git a/src/objects/grits-marker.c b/src/objects/grits-marker.c index 3510353..40d45f4 100644 --- a/src/objects/grits-marker.c +++ b/src/objects/grits-marker.c @@ -256,11 +256,12 @@ static void grits_marker_draw(GritsObject *_marker, GritsOpenGL *opengl) point->lat, point->lon, point->elev, &px, &py, &pz); - gint win_height = GTK_WIDGET(opengl)->allocation.height; if (pz > 1) return; - glTranslated(px, win_height-py, 0); + GtkAllocation alloc; + gtk_widget_get_allocation(GTK_WIDGET(opengl), &alloc); + glTranslated(px, alloc.height-py, 0); glRotatef(marker->angle, 0, 0, -1); glTranslated(-marker->xoff, -marker->yoff, 0); } else { diff --git a/src/plugins/env.c b/src/plugins/env.c index 4b6ed79..658881d 100644 --- a/src/plugins/env.c +++ b/src/plugins/env.c @@ -195,11 +195,11 @@ static void compass_expose(GritsCallback *compass, GritsOpenGL *opengl, gpointer grits_viewer_get_rotation(env->viewer, &x, &y, &z); /* Setup projection */ - gint win_width = GTK_WIDGET(opengl)->allocation.width; - gint win_height = GTK_WIDGET(opengl)->allocation.height; - float scale = CLAMP(MIN(win_width,win_height)/2.0 * 0.1, 40, 100); + GtkAllocation alloc; + gtk_widget_get_allocation(GTK_WIDGET(opengl), &alloc); + float scale = CLAMP(MIN(alloc.width,alloc.height)/2.0 * 0.1, 40, 100); float offset = scale + 20; - glTranslatef(win_width - offset, offset, 0); + glTranslatef(alloc.width - offset, offset, 0); /* Setup state */ glClear(GL_DEPTH_BUFFER_BIT); @@ -226,8 +226,8 @@ static gboolean compass_click(GritsCallback *compass, GdkEvent *evnet, GritsView /* Info */ static void info_expose(GritsCallback *compass, GritsOpenGL *opengl, gpointer _env) { - gint win_width = GTK_WIDGET(opengl)->allocation.width; - gint win_height = GTK_WIDGET(opengl)->allocation.height; + GtkAllocation alloc; + gtk_widget_get_allocation(GTK_WIDGET(opengl), &alloc); /* Create cairo surface */ guint tex = 0; @@ -292,7 +292,7 @@ static void info_expose(GritsCallback *compass, GritsOpenGL *opengl, gpointer _e glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, tex); glDisable(GL_CULL_FACE); - glTranslatef(win_width - width, win_height - height, 0); + glTranslatef(alloc.width - width, alloc.height - height, 0); glBegin(GL_QUADS); glTexCoord2f(1, 0); glVertex3f(width, 0 , 0); // 0 - 3 0 glTexCoord2f(1, 1); glVertex3f(width, height, 0); // 1 - | | -- 2.43.2