Author: alanmc
Date: 2007-06-29 14:22:13 -0400 (Fri, 29 Jun 2007)
New Revision: 81056

Added:
   trunk/lunareclipse/Controller/UndoActions/UndoMoveShape.cs
Modified:
   trunk/lunareclipse/ChangeLog
   trunk/lunareclipse/LunarEclipse.mdp
   trunk/lunareclipse/Model/Draw/SelectionDraw.cs
   trunk/lunareclipse/View/MainWindow.cs
Log:
* Model/Draw/SelectionDraw.cs: You can now undo/redo movements to
  shapes

Modified: trunk/lunareclipse/ChangeLog
===================================================================
--- trunk/lunareclipse/ChangeLog        2007-06-29 18:00:16 UTC (rev 81055)
+++ trunk/lunareclipse/ChangeLog        2007-06-29 18:22:13 UTC (rev 81056)
@@ -1,5 +1,10 @@
 2007-06-29  Alan McGovern <[EMAIL PROTECTED]> 
 
+       * Model/Draw/SelectionDraw.cs: You can now undo/redo movements to
+         shapes
+
+2007-06-29  Alan McGovern <[EMAIL PROTECTED]> 
+
        * Model/Draw/SelectionDraw.cs: Selection code now handles the case
          where you click on an item and drag it without previously selecting
          it

Added: trunk/lunareclipse/Controller/UndoActions/UndoMoveShape.cs
===================================================================
--- trunk/lunareclipse/Controller/UndoActions/UndoMoveShape.cs  2007-06-29 
18:00:16 UTC (rev 81055)
+++ trunk/lunareclipse/Controller/UndoActions/UndoMoveShape.cs  2007-06-29 
18:22:13 UTC (rev 81056)
@@ -0,0 +1,43 @@
+// /home/alan/Projects/LunarEclipse/Controller/UndoActions/UndoMoveShape.cs 
created with MonoDevelop
+// User: alan at 2:20 PMĀ 6/29/2007
+//
+// To change standard headers go to Edit->Preferences->Coding->Standard Headers
+//
+
+using System;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Shapes;
+
+namespace LunarEclipse
+{
+    
+    
+    public class UndoMoveShape : UndoActionBase
+    {
+        private Point offset;
+        private Shape shape;
+        
+        
+        public UndoMoveShape(Shape shape, Point offset)
+        {
+            this.shape = shape;
+            this.offset = offset;
+        }
+        
+        public override void Redo ()
+        {
+            Point location = new 
Point((double)shape.GetValue(Canvas.LeftProperty), 
(double)shape.GetValue(Canvas.TopProperty));
+            shape.SetValue<double>(Canvas.LeftProperty, location.X - offset.X);
+            shape.SetValue<double>(Canvas.TopProperty, location.Y - offset.Y);
+        }
+
+        
+        public override void Undo ()
+        {
+            Point location = new 
Point((double)shape.GetValue(Canvas.LeftProperty), 
(double)shape.GetValue(Canvas.TopProperty));
+            shape.SetValue<double>(Canvas.LeftProperty, location.X + offset.X);
+            shape.SetValue<double>(Canvas.TopProperty, location.Y + offset.Y);
+        }
+    }
+}

Modified: trunk/lunareclipse/LunarEclipse.mdp
===================================================================
--- trunk/lunareclipse/LunarEclipse.mdp 2007-06-29 18:00:16 UTC (rev 81055)
+++ trunk/lunareclipse/LunarEclipse.mdp 2007-06-29 18:22:13 UTC (rev 81056)
@@ -50,6 +50,7 @@
     <File name="./Properties/PropertyGroupAppearance.cs" subtype="Code" 
buildaction="Compile" />
     <File name="./Properties/IPropertyGroup.cs" subtype="Code" 
buildaction="Compile" />
     <File name="./Properties/PropertyGroupLayout.cs" subtype="Code" 
buildaction="Compile" />
+    <File name="./Controller/UndoActions/UndoMoveShape.cs" subtype="Code" 
buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="System, 
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

Modified: trunk/lunareclipse/Model/Draw/SelectionDraw.cs
===================================================================
--- trunk/lunareclipse/Model/Draw/SelectionDraw.cs      2007-06-29 18:00:16 UTC 
(rev 81055)
+++ trunk/lunareclipse/Model/Draw/SelectionDraw.cs      2007-06-29 18:22:13 UTC 
(rev 81056)
@@ -11,12 +11,12 @@
 using System.Windows.Media;
 using System.Windows.Input;
 using System.Collections.Generic;
-
-
+using LunarEclipse.Controller;
 namespace LunarEclipse.Model
 {
     public class SelectionDraw : DrawBase
     {
+        private MoonlightController controller;
         private Point mouseStart;
         private bool clickedOnShape;
         private bool prepared;
@@ -32,9 +32,10 @@
             get { return false; }
         }
 
-        public SelectionDraw()
+        public SelectionDraw(MoonlightController controller)
             :base(new SelectionRectangle())
         {
+            this.controller = controller;
             selectedObjects = new List<Shape>();
         }
         
@@ -128,6 +129,7 @@
 
         internal override void Resize (MouseEventArgs e)
         {
+            Shape clickedShape;
             Point mousePoint = e.GetPosition(Panel);
             mousePoint.Offset(-Position.X, -Position.Y);
             
@@ -135,12 +137,12 @@
 
             if(this.clickedOnShape)
             {
+                ClickedOnShape(mouseStart, out clickedShape);
+                if(clickedShape!= null && 
!selectedObjects.Contains(clickedShape))
+                    DeselectAll();
+                
                 if(selectedObjects.Count == 0)
-                {
-                    Shape s;
-                    ClickedOnShape(mouseStart, out s);
-                    selectedObjects.Add(s);
-                }
+                    Select(clickedShape);
                 
                 foreach(Shape s in this.selectedObjects)
                     MoveShape(s, mousePoint);
@@ -181,6 +183,17 @@
                     
             if(!clickedOnShape && mouseDidntMove)
                 DeselectAll();
+            
+            if(!mouseDidntMove)
+            {
+                Point start = mouseStart;
+                start.Offset(-Position.X, -Position.Y);
+                foreach(Shape s in selectedObjects)
+                {
+
+                    controller.UndoEngine.PushUndo(new UndoMoveShape(s, 
start));
+                }
+            }
         }
         
         private void DeselectAll()
@@ -205,8 +218,9 @@
         
         private void MoveShape(Shape s, Point offset)
         {
-            s.SetValue<double>(Canvas.LeftProperty, 
(double)s.GetValue(Canvas.LeftProperty) + offset.X);
-            s.SetValue<double>(Canvas.TopProperty, 
(double)s.GetValue(Canvas.TopProperty) + offset.Y);
+            Point oldPoint = new 
Point((double)s.GetValue(Canvas.LeftProperty), 
(double)s.GetValue(Canvas.TopProperty));
+            s.SetValue<double>(Canvas.LeftProperty, oldPoint.X + offset.X);
+            s.SetValue<double>(Canvas.TopProperty, oldPoint.Y + offset.Y);
         }
     }
 }

Modified: trunk/lunareclipse/View/MainWindow.cs
===================================================================
--- trunk/lunareclipse/View/MainWindow.cs       2007-06-29 18:00:16 UTC (rev 
81055)
+++ trunk/lunareclipse/View/MainWindow.cs       2007-06-29 18:22:13 UTC (rev 
81056)
@@ -67,7 +67,6 @@
                        Add (book);
                        
             controller = new MoonlightController(moonlight);
-            moonlight.Load("~/Desktop/moonlight/moon/test/tester.xaml");
             HookEvents(true);
             Show ();
        }
@@ -113,7 +112,7 @@
             
             b = new Button("Selection");
             b.Clicked += delegate {
-                controller.Current = new SelectionDraw();
+                controller.Current = new SelectionDraw(this.controller);
                 Console.WriteLine("Draw is" + 
controller.Current.GetType().Name.ToString());
             };
             widgets.Add(b);

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to