[ease] Support zoom properly when selecting and dragging Actors.



commit 5bf809eacca418589f745e69a4ab9dac35933380
Author: Nate Stedman <natesm gmail com>
Date:   Tue May 18 22:15:55 2010 -0400

    Support zoom properly when selecting and dragging Actors.

 src/libease/EditorEmbed.vala |   34 ++++++++++++++++++++++++++--------
 1 files changed, 26 insertions(+), 8 deletions(-)
---
diff --git a/src/libease/EditorEmbed.vala b/src/libease/EditorEmbed.vala
index 1a1672f..c370322 100644
--- a/src/libease/EditorEmbed.vala
+++ b/src/libease/EditorEmbed.vala
@@ -201,6 +201,25 @@ namespace Ease
 			slide_actor.y = h < height
 			              ? height / 2 - h / 2
 			              : 0;
+			              
+			if (selection_rectangle != null)
+			{
+				position_selection();
+			}
+		}
+		
+		/**
+		 * Repositions the EditorEmbed's selection rectangle
+		 * 
+		 * Call this function after changing the zoom level, document size, or
+		 * any other properties that could place the slide off center. 
+		 */
+		private void position_selection()
+		{
+			selection_rectangle.set_position(zoom * selected.x + slide_actor.x,
+				                             zoom * selected.y + slide_actor.y);
+			selection_rectangle.set_size(zoom * selected.width,
+			                             zoom * selected.height);
 		}
 		
 		public bool actor_clicked(Clutter.Actor sender, Clutter.Event event)
@@ -229,9 +248,7 @@ namespace Ease
 			selection_rectangle.border_color = {0, 0, 0, 255};
 			selection_rectangle.color = {0, 0, 0, 0};
 			selection_rectangle.set_border_width(2);
-			selection_rectangle.set_position(selected.x + slide_actor.x,
-			                                 selected.y + slide_actor.y);
-			selection_rectangle.set_size(selected.width, selected.height);
+			position_selection();
 			contents.add_actor(selection_rectangle);
 			
 			return true;
@@ -259,15 +276,16 @@ namespace Ease
 					mouse_y = event.motion.y;
 					return true;
 				}
-				actor.translate(event.motion.x - mouse_x,
-				                event.motion.y - mouse_y);
+				
+				float factor = 1 / zoom;
+				
+				actor.translate(factor * (event.motion.x - mouse_x),
+				                factor * (event.motion.y - mouse_y));
 				
 				mouse_x = event.motion.x;
 				mouse_y = event.motion.y;
 				
-				selection_rectangle.set_position(selected.x + slide_actor.x,
-				                                 selected.y + slide_actor.y);
-				selection_rectangle.set_size(selected.width, selected.height);
+				position_selection();
 			}
 			return true;
 		}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]