summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorRobert Bragg <robert@linux.intel.com>2012-06-20 16:22:36 +0100
committerRobert Bragg <robert@linux.intel.com>2012-08-06 18:51:32 +0100
commitdf515741161f7390570d3b110a272d1b6664c050 (patch)
tree24cda696dfe24ee2bda8dca5b9175940bf57bf0e /examples
parent72f992effe6cbc9f2b9a2052279a52aade2a037c (diff)
downloadcogl-df515741161f7390570d3b110a272d1b6664c050.tar.gz
onscreen: Adds support for resizable windows
This adds api to be able to request that the window system allows a given onscreen framebuffer to be resizable, and api to add and remove resize handlers to be called whenever the framebuffer does actually change size. The new functions are: cogl_onscreen_{get,set}_resizable() cogl_onscreen_{add,remove}_resize_handler() The examples cogl-hello and cogl-x11-foreign have been updated to use the new api. To smoke test how Cogl updates the viewport automatically in response to window resizes the cogl-hello test doesn't explicitly respond to resize events by setting the viewport and cogl-x11-foreign responds by setting a viewport that is offset by a quarter of the window's width/height and half the width and height of the window. Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit a1a8cc00bfa2cecaf1007aec5f3dd95dc07b1786)
Diffstat (limited to 'examples')
-rw-r--r--examples/cogl-hello.c2
-rw-r--r--examples/cogl-x11-foreign.c24
2 files changed, 23 insertions, 3 deletions
diff --git a/examples/cogl-hello.c b/examples/cogl-hello.c
index a0b002d1..cf0e8f6d 100644
--- a/examples/cogl-hello.c
+++ b/examples/cogl-hello.c
@@ -59,6 +59,8 @@ main (int argc, char **argv)
cogl_onscreen_show (onscreen);
data.fb = COGL_FRAMEBUFFER (onscreen);
+ cogl_onscreen_set_resizable (onscreen, TRUE);
+
data.triangle = cogl_primitive_new_p2c4 (data.ctx,
COGL_VERTICES_MODE_TRIANGLES,
3, triangle_vertices);
diff --git a/examples/cogl-x11-foreign.c b/examples/cogl-x11-foreign.c
index 70049f2f..9397f4d4 100644
--- a/examples/cogl-x11-foreign.c
+++ b/examples/cogl-x11-foreign.c
@@ -31,6 +31,16 @@ update_cogl_x11_event_mask (CoglOnscreen *onscreen,
&attrs);
}
+static void
+resize_handler (CoglOnscreen *onscreen,
+ int width,
+ int height,
+ void *user_data)
+{
+ CoglFramebuffer *fb = user_data;
+ cogl_framebuffer_set_viewport (fb, width / 4, height / 4, width / 2, height / 2);
+}
+
int
main (int argc, char **argv)
{
@@ -149,6 +159,9 @@ main (int argc, char **argv)
fb = COGL_FRAMEBUFFER (onscreen);
+ cogl_onscreen_set_resizable (onscreen, TRUE);
+ cogl_onscreen_add_resize_handler (onscreen, resize_handler, onscreen);
+
triangle = cogl_primitive_new_p2c4 (ctx, COGL_VERTICES_MODE_TRIANGLES,
3, triangle_vertices);
pipeline = cogl_pipeline_new (ctx);
@@ -170,13 +183,18 @@ main (int argc, char **argv)
}
cogl_xlib_renderer_handle_event (renderer, &event);
}
- cogl_framebuffer_clear4f (fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);
- cogl_framebuffer_draw_primitive (fb, pipeline, triangle);
- cogl_onscreen_swap_buffers (onscreen);
+ /* After forwarding native events directly to Cogl you should
+ * then allow Cogl to dispatch any corresponding event
+ * callbacks, such as resize notification callbacks...
+ */
cogl_poll_get_info (ctx, &poll_fds, &n_poll_fds, &timeout);
g_poll ((GPollFD *) poll_fds, n_poll_fds, 0);
cogl_poll_dispatch (ctx, poll_fds, n_poll_fds);
+
+ cogl_framebuffer_clear4f (fb, COGL_BUFFER_BIT_COLOR, 0, 0, 0, 1);
+ cogl_framebuffer_draw_primitive (fb, pipeline, triangle);
+ cogl_onscreen_swap_buffers (onscreen);
}
return 0;