[PATCH 6/6] clients: image: add touch handler support for resizing
Tiago Vignatti
vignatti at freedesktop.org
Wed Dec 21 09:34:14 PST 2011
From: Tiago Vignatti <tiago.vignatti at intel.com>
Signed-off-by: Tiago Vignatti <tiago.vignatti at intel.com>
---
clients/image.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 102 insertions(+), 0 deletions(-)
diff --git a/clients/image.c b/clients/image.c
index a1920db..c545e86 100644
--- a/clients/image.c
+++ b/clients/image.c
@@ -46,6 +46,12 @@ struct image {
uint32_t key;
gchar *filename;
cairo_surface_t *c_image;
+
+ struct {
+ double current;
+ double target;
+ double previous;
+ } height, width;
};
static void
@@ -125,6 +131,88 @@ keyboard_focus_handler(struct window *window,
window_schedule_redraw(image->window);
}
+static void
+frame_callback(void *data, struct wl_callback *callback, uint32_t time)
+{
+ static const struct wl_callback_listener listener = {
+ frame_callback
+ };
+ struct image *image = data;
+ double force, width, height;
+ width = image->width.current;
+ force = (image->width.target - width) / 10.0 +
+ (image->width.previous - width);
+
+ image->width.current =
+ width + (width - image->width.previous) + force;
+ image->width.previous = width;
+
+ if (image->width.current >= 1024) {
+ image->width.current = 1024;
+ image->width.previous = image->width.current;
+ goto bail;
+ }
+ if (image->width.current <= 50) {
+ image->width.current = 50;
+ image->width.previous = image->width.current;
+ goto bail;
+ }
+
+ height = image->height.current;
+ force = (image->height.target - height) / 10.0 +
+ (image->height.previous - height);
+
+ image->height.current =
+ height + (height - image->height.previous) + force;
+ image->height.previous = height;
+
+ if (image->height.current >= 640) {
+ image->height.current = 640;
+ image->height.previous = image->height.current;
+ goto bail;
+ }
+ if (image->height.current <= 50) {
+ image->height.current = 50;
+ image->height.previous = image->height.current;
+ goto bail;
+ }
+
+ window_set_child_size(image->window, width + 0.5, height + 0.5);
+
+bail:
+ window_schedule_redraw(image->window);
+
+ if (callback)
+ wl_callback_destroy(callback);
+ else
+ if (fabs(image->height.previous - image->height.target) > 0.1 ||
+ fabs(image->width.previous - image->width.target) > 0.1) {
+ callback = wl_surface_frame(window_get_wl_surface
+ (image->window));
+ wl_callback_add_listener(callback, &listener, image);
+ }
+}
+
+#define RESIZE_FACTOR 50
+static void
+touch_handler(struct window *window, struct input *input, uint32_t time,
+ int resize, void *data)
+{
+ struct image *image = data;
+
+ if (resize > 0) {
+ image->height.target = image->height.current + RESIZE_FACTOR;
+ image->width.target = image->width.current + RESIZE_FACTOR;
+ }
+ else {
+ image->height.target = image->height.current - RESIZE_FACTOR;
+ image->width.target = image->width.current - RESIZE_FACTOR;
+ }
+
+ frame_callback(image, NULL, 0);
+}
+
+
static struct image *
image_create(struct display *display, uint32_t key, const char *filename)
{
@@ -155,6 +243,20 @@ image_create(struct display *display, uint32_t key, const char *filename)
window_set_redraw_handler(image->window, redraw_handler);
window_set_keyboard_focus_handler(image->window,
keyboard_focus_handler);
+
+ window_set_touch_handler(image->window, touch_handler);
+
+ image->width.current = 500;
+ image->width.previous = image->width.current;
+ image->width.target = image->width.current;
+
+ image->height.current = 400;
+ image->height.previous = image->height.current;
+ image->height.target = image->height.current;
+
+ window_set_child_size(image->window, image->width.current + 0.5,
+ image->height.current + 0.5);
+
image_load(image);
image_draw(image);
--
1.7.5.4
More information about the wayland-devel
mailing list