[weston,v2,04/20] zoom: Use pixels instead of GL coordinates

Submitted by Derek Foreman on Oct. 16, 2014, 3:55 p.m.

Details

Message ID 1413474938-2407-5-git-send-email-derekf@osg.samsung.com
State Superseded
Delegated to: Pekka Paalanen
Headers show

Not browsing as part of any series.

Commit Message

Derek Foreman Oct. 16, 2014, 3:55 p.m.
From: Jason Ekstrand <jason@jlekstrand.net>

Previously, the zoom functions used GL coordinates natively which doesn't
work with the new output matrix calculations.  This changes zoom to work in
pixel coordinates to match the new output matrix format.  This also cleans
up the math in the zoom code substantially.
---
 src/zoom.c | 38 ++++++++++++++------------------------
 1 file changed, 14 insertions(+), 24 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/zoom.c b/src/zoom.c
index 7553849..cbff2f3 100644
--- a/src/zoom.c
+++ b/src/zoom.c
@@ -106,8 +106,8 @@  zoom_area_center_from_pointer(struct weston_output *output,
 	wl_fixed_t w = wl_fixed_from_int(output->width);
 	wl_fixed_t h = wl_fixed_from_int(output->height);
 
-	*x -= ((((*x - offset_x) / (float) w) - 0.5) * (w * (1.0 - level)));
-	*y -= ((((*y - offset_y) / (float) h) - 0.5) * (h * (1.0 - level)));
+	*x = (*x - offset_x) * level + w / 2;
+	*y = (*y - offset_y) * level + h / 2;
 }
 
 static void
@@ -116,11 +116,9 @@  weston_output_update_zoom_transform(struct weston_output *output)
 	float global_x, global_y;
 	wl_fixed_t x = output->zoom.current.x;
 	wl_fixed_t y = output->zoom.current.y;
-	float trans_min, trans_max;
-	float ratio, level;
+	float level;
 
 	level = output->zoom.spring_z.current;
-	ratio = 1 / level;
 
 	if (!output->zoom.active || level > output->zoom.max_level ||
 	    level == 0.0f)
@@ -132,25 +130,17 @@  weston_output_update_zoom_transform(struct weston_output *output)
 	global_x = wl_fixed_to_double(x);
 	global_y = wl_fixed_to_double(y);
 
-	output->zoom.trans_x =
-		((((global_x - output->x) / output->width) *
-		(level * 2)) - level) * ratio;
-	output->zoom.trans_y =
-		((((global_y - output->y) / output->height) *
-		(level * 2)) - level) * ratio;
-
-	trans_max = level * 2 - level;
-	trans_min = -trans_max;
-
-	/* Clip zoom area to output */
-	if (output->zoom.trans_x > trans_max)
-		output->zoom.trans_x = trans_max;
-	else if (output->zoom.trans_x < trans_min)
-		output->zoom.trans_x = trans_min;
-	if (output->zoom.trans_y > trans_max)
-		output->zoom.trans_y = trans_max;
-	else if (output->zoom.trans_y < trans_min)
-		output->zoom.trans_y = trans_min;
+	output->zoom.trans_x = global_x - (output->x + output->width / 2);
+	output->zoom.trans_y = global_y - (output->y + output->height / 2);
+
+	if (output->zoom.trans_x < 0)
+		output->zoom.trans_x = 0;
+	if (output->zoom.trans_y < 0)
+		output->zoom.trans_y = 0;
+	if (output->zoom.trans_x > level * output->width)
+		output->zoom.trans_x = level * output->width;
+	if (output->zoom.trans_y > level * output->height)
+		output->zoom.trans_y = level * output->height;
 }
 
 static void