Author: alanmc
Date: 2007-07-12 19:24:40 -0400 (Thu, 12 Jul 2007)
New Revision: 81915

Modified:
   trunk/lunareclipse/ChangeLog
   trunk/lunareclipse/Model/Draw/SelectionDraw.cs
   trunk/lunareclipse/Model/SelectedBorder.cs
   trunk/lunareclipse/Model/SelectionRectangle.cs
Log:
* Model/SelectedBorder.cs, Model/Draw/SelectionDraw.cs,
  Model/SelectionRectangle.cs: Initial support for correct resizing
  when the shapes are rotated

Modified: trunk/lunareclipse/ChangeLog
===================================================================
--- trunk/lunareclipse/ChangeLog        2007-07-12 22:54:41 UTC (rev 81914)
+++ trunk/lunareclipse/ChangeLog        2007-07-12 23:24:40 UTC (rev 81915)
@@ -1,5 +1,11 @@
 2007-07-12  Alan McGovern <[EMAIL PROTECTED]> 
 
+       * Model/SelectedBorder.cs, Model/Draw/SelectionDraw.cs,
+         Model/SelectionRectangle.cs: Initial support for correct resizing
+         when the shapes are rotated
+
+2007-07-12  Alan McGovern <[EMAIL PROTECTED]> 
+
        * Model/Draw/SelectionDraw.cs, Controller/MoonlightController.cs:
          Rewrote some of the selection code to fix some idiosyncrasies.
          Added comments 

Modified: trunk/lunareclipse/Model/Draw/SelectionDraw.cs
===================================================================
--- trunk/lunareclipse/Model/Draw/SelectionDraw.cs      2007-07-12 22:54:41 UTC 
(rev 81914)
+++ trunk/lunareclipse/Model/Draw/SelectionDraw.cs      2007-07-12 23:24:40 UTC 
(rev 81915)
@@ -160,7 +160,7 @@
                 }
                 
                 foreach(KeyValuePair<Visual, SelectedBorder> keypair in 
selectedObjects)
-                    MoveShape(keypair.Key, mousePoint);
+                    MoveShape(keypair.Key, mousePoint, e);
                 
                 Element.Width = 0;
                 Element.Height = 0;
@@ -232,7 +232,10 @@
             // that on the nextMouseDown, a standard move will be performed 
unless
             // the user clicks on one of the handles for 
stretching/skewing/rotating
             foreach(KeyValuePair<Visual, SelectedBorder> keypair in 
selectedObjects)
-                keypair.Value.MoveType = MoveType.Standard;
+            {
+                Console.WriteLine("Setting null");
+                keypair.Value.Handle = null;
+            }
             
             // Reset the clicked on shape = null
             this.clickedOnShape = null;
@@ -266,17 +269,18 @@
             border.MouseLeftButtonDown += new 
MouseEventHandler(ClickedOnVisual);
         }
         
-        private void MoveShape(Visual s, Point offset)
+        private void MoveShape(Visual s, Point offset, MouseEventArgs e)
         {
             SelectedBorder b = selectedObjects[s];
             double oldLeft = (double)b.Child.GetValue(Canvas.LeftProperty);
             double oldTop = (double)b.Child.GetValue(Canvas.TopProperty);
             double oldHeight = (double)b.Child.GetValue(Canvas.HeightProperty);
             double oldWidth = (double)b.Child.GetValue(Canvas.WidthProperty);
-
-            switch(b.MoveType)
+            
+            // Doing a rotation
+            if(b.Handle == b.RotateHandle1 || b.Handle == b.RotateHandle2 ||
+               b.Handle == b.RotateHandle3 || b.Handle == b.RotateHandle4)
             {
-                case MoveType.Rotate:
                 Point center;
                 center = new 
Point((double)b.Child.GetValue(Canvas.WidthProperty) * 0.5 + 
(double)b.Child.GetValue(Canvas.LeftProperty),
                                    
(double)b.Child.GetValue(Canvas.HeightProperty) * 0.5 + 
(double)b.Child.GetValue(Canvas.TopProperty));
@@ -285,44 +289,97 @@
                 double slope1 = (mouseStart.Y - center.Y) / (mouseStart.X - 
center.X);
                 double slope2 = (Position.Y - center.Y) / (Position.X - 
center.X);
                 double difference = Math.Atan((slope2 - slope1) / ( 1 + slope1 
* slope2));
+                
+                // Sometimes the angle will hit infinity, so in those cases
+                // don't apply the change and wait for the next mouse move 
which
+                // will give a proper angle
                 if(!double.IsNaN(difference))
                     b.RotateTransform.Angle += difference * 360 / (2 * 
Math.PI);
-                break;
-                
-                case MoveType.Standard:
-                    b.Child.SetValue<double>(Canvas.LeftProperty, oldLeft + 
offset.X);
-                    b.Child.SetValue<double>(Canvas.TopProperty, oldTop + 
offset.Y);
-                    break;
-                
-                case MoveType.StretchHeight:
-                    if((oldHeight + offset.Y) >= 0)
-                        b.Child.SetValue<double>(Canvas.HeightProperty, 
oldHeight + offset.Y);
-                    break;
-                
-                case MoveType.StretchLeft:
-                    if((oldWidth - offset.X) >= 0)
-                    {
-                        b.Child.SetValue<double>(Canvas.LeftProperty, oldLeft 
+ offset.X);
-                        b.Child.SetValue<double>(Canvas.WidthProperty, 
oldWidth - offset.X);
-                    }
-                    break;
-                
-                case(MoveType.StretchTop):
-                    if((oldHeight - offset.Y) >= 0)
-                    {
-                        b.Child.SetValue<double>(Canvas.TopProperty, oldTop + 
offset.Y);
-                        b.Child.SetValue<double>(Canvas.HeightProperty, 
oldHeight - offset.Y);
-                    }
-                    break;
-                
-                case MoveType.StretchWidth:
-                    if((oldWidth + offset.X) >= 0)
-                        b.Child.SetValue<double>(Canvas.WidthProperty, 
oldWidth + offset.X);
-                    break;
             }
+            
+            if(b.Handle == null)
+            {
+                b.Child.SetValue<double>(Canvas.LeftProperty, oldLeft + 
offset.X);
+                b.Child.SetValue<double>(Canvas.TopProperty, oldTop + 
offset.Y);
+            }
+            
+            // Stretching the height/top
+            if(b.Handle == b.HeightHandle1 || b.Handle == b.HeightHandle2)
+                ResizeHeight(b, offset, e);
+            
+//            if(b.Handle == b.WidthHandle1 || b.Handle == b.WidthHandle2)
+//                ResizeWidth(b, offset, e);
+//            switch(b.Handle)
+//            {
+//                case MoveType.Rotate:
 
+//                
+
+//                
+//                case MoveType.Height:
+//                    ResizeHeight(b, offset);
+//                    break;
+//                
+//                case MoveType.Width:
+//                //left
+//                    if((oldWidth - offset.X) >= 0)
+//                    {
+//                        b.Child.SetValue<double>(Canvas.LeftProperty, 
oldLeft + offset.X);
+//                        b.Child.SetValue<double>(Canvas.WidthProperty, 
oldWidth - offset.X);
+//                    }
+//                
+//                //width
+//                    if((oldWidth + offset.X) >= 0)
+//                        b.Child.SetValue<double>(Canvas.WidthProperty, 
oldWidth + offset.X);
+//                    break;
+//            }
+
             b.ResizeBorder();
             shapeMoved = true;
         }
+        
+        private void ResizeHeight(SelectedBorder b, Point offset, 
MouseEventArgs e)
+        {
+            double oldLeft = (double)b.Child.GetValue(Canvas.LeftProperty);
+            double oldTop = (double)b.Child.GetValue(Canvas.TopProperty);
+            double oldHeight = (double)b.Child.GetValue(Canvas.HeightProperty);
+            double oldWidth = (double)b.Child.GetValue(Canvas.WidthProperty);
+            
+            double top1 = e.GetPosition(b.HeightHandle1).Y;
+            double top2 = e.GetPosition(b.HeightHandle2).Y;
+
+            Console.WriteLine("top1: {0}", top1);
+            Console.WriteLine("top2: {0}", top2);
+            Console.WriteLine("top1 - top2: {0}", top1 - top2);
+
+            // Check to see if we should be changing the 'Top' property
+            
+            if(b.Handle == b.HeightHandle1 && (top1-top2) > 0)
+            {
+                Console.WriteLine("A");
+                if((oldHeight - offset.Y) >= 0)
+                {
+                    b.Child.SetValue<double>(Canvas.TopProperty, oldTop + 
offset.Y);
+                    b.Child.SetValue<double>(Canvas.HeightProperty, oldHeight 
- offset.Y);
+                }
+//                
+//                if((oldHeight + offset.Y) >= 0)
+//                    b.Child.SetValue<double>(Canvas.HeightProperty, 
oldHeight + offset.Y);
+            }
+            else if(b.Handle == b.HeightHandle2 && (top1 - top2) > 0)
+            {
+                Console.WriteLine("B");
+                if((oldHeight + offset.Y) >= 0)
+                    b.Child.SetValue<double>(Canvas.HeightProperty, oldHeight 
+ offset.Y);
+            }
+//            else // Else we change the 'Height' propert
+//            {
+//                if((oldHeight - offset.Y) >= 0)
+//                {
+//                    b.Child.SetValue<double>(Canvas.TopProperty, oldTop + 
offset.Y);
+//                    b.Child.SetValue<double>(Canvas.HeightProperty, 
oldHeight - offset.Y);
+//                }
+//            }
+        }
     }
 }

Modified: trunk/lunareclipse/Model/SelectedBorder.cs
===================================================================
--- trunk/lunareclipse/Model/SelectedBorder.cs  2007-07-12 22:54:41 UTC (rev 
81914)
+++ trunk/lunareclipse/Model/SelectedBorder.cs  2007-07-12 23:24:40 UTC (rev 
81915)
@@ -12,36 +12,74 @@
 
 namespace LunarEclipse.Model
 {
-    public enum MoveType
-    {
-        Standard,
-        StretchWidth,
-        StretchHeight,
-        StretchTop,
-        StretchLeft,
-        Rotate
-    }
-    
     public class SelectedBorder : System.Windows.Controls.Canvas
     {
-        private MoveType movetype;
+        private Visual handle;
         private bool updating;
               
         public const double BorderWidth = 20;
         public const double HandleRadius = 5;
         
         private Visual child;
-
+        private Shape height1;
+        private Shape height2;
+        private Shape width1;
+        private Shape width2;
+        private Shape rotate1;
+        private Shape rotate2;
+        private Shape rotate3;
+        private Shape rotate4;
+        private Shape[] lines;
+        
+        public Visual Handle
+        {
+            get { return this.handle; }
+            internal set { this.handle = value; }
+        }
+        
+        public Shape HeightHandle1
+        {
+            get { return this.height1; }
+        }
+        public Shape HeightHandle2
+        {
+            get { return this.height2; }
+        }
+        public Shape WidthHandle1
+        {
+            get { return this.width1; }
+        }
+        public Shape WidthHandle2
+        {
+             get { return this.width2; }
+        }
+        public Shape RotateHandle1
+        {
+            get { return this.rotate1; }
+        }
+        public Shape RotateHandle2
+        {
+            get { return this.rotate2; }
+        }
+        public Shape RotateHandle3
+        {
+            get { return this.rotate3; }
+        }
+        public Shape RotateHandle4
+        {
+            get { return this.rotate4; }
+        }
+        
         public SelectedBorder()
         {
-            this.movetype = MoveType.Standard;
+            
         }
         
         public RotateTransform RotateTransform
         {
             get { return 
(RotateTransform)this.child.GetValue(RenderTransformProperty); }
             set 
-            { 
+            {
                 this.child.SetValue<RotateTransform>(RenderTransformProperty, 
value); 
                 base.SetValue<RotateTransform>(RenderTransformProperty, value);
             }
@@ -65,7 +103,6 @@
                 {
                     updating = true;
                     ResizeBorder();
-                    DrawHandles();
                     updating = false;
                 }
 
@@ -89,17 +126,9 @@
             get { return (double)base.GetValue(TopProperty); }
             set { base.SetValue<double>(TopProperty, value); }
         }
-        
-        public MoveType MoveType
-        {
-            get { return this.movetype; }
-            internal set { this.movetype = value; }
-        }
 
         internal void ResizeBorder()
         {         
-            ((VisualCollection)base.GetValue(ChildrenProperty)).Clear();
-        
             double childTop = (double)child.GetValue(TopProperty);
             double childLeft = (double)child.GetValue(LeftProperty);
             double childWidth = (double)child.GetValue(WidthProperty);
@@ -111,119 +140,149 @@
             base.SetValue<double>(WidthProperty, childWidth + BorderWidth * 2);
             base.SetValue<double>(HeightProperty, childHeight + BorderWidth * 
2);
 
-            DrawHandles();
+            
DrawHandles(((VisualCollection)base.GetValue(ChildrenProperty)).Count == 0);
             //DrawTransform();
         }
         
-        private void DrawHandles()
+        private void DrawHandles(bool firstDraw)
         {
             VisualCollection Children = 
(VisualCollection)base.GetValue(ChildrenProperty);
             Ellipse circle;
             Line line;
             
-            double height = (double)base.GetValue(HeightProperty);
-            double width = (double)base.GetValue(WidthProperty);
-            double midX = width / 2.0;
-            double midY = height / 2.0;
+            double left = 0;
+            double top = 0;
+            double right = (double)GetValue(WidthProperty) - left;
+            double bottom = (double)GetValue(HeightProperty) - top;
+            double midX = (right + left) / 2.0;
+            double midY = (top + bottom) / 2.0;
             
-            // Top side
-            circle = CreateCircle(new Point(0, 0));
-            Children.Add(circle);
-            circle.MouseLeftButtonDown+= delegate {
-                this.movetype = MoveType.Rotate;
-                Console.WriteLine(movetype.ToString());
-            };
+            // Top left rotate handle
+            if(firstDraw)
+            {
+                Console.WriteLine("DRAWING NEW BORDER SHAPES");
+                circle = new Ellipse();
+                Children.Add(circle);
+                rotate1 = circle;
+                circle.MouseLeftButtonDown += delegate { Handle = rotate1; 
Console.WriteLine("Rotate1 {0}", rotate1); };
+                
+                
+                circle = new Ellipse();
+                Children.Add(circle);
+                height1= circle;
+                circle.MouseLeftButtonDown+= delegate { Handle = height1; 
Console.WriteLine("height1 {0}", height1);};
+                
+                
+                circle = new Ellipse();
+                Children.Add(circle);
+                rotate2 = circle;
+                circle.MouseLeftButtonDown+= delegate { Handle = rotate2; };
+                
+                
+                circle = new Ellipse();
+                Children.Add(circle);
+                width1 = circle;
+                circle.MouseLeftButtonDown += delegate { Handle = width1; };
+                
+                
+                circle = new Ellipse();
+                Children.Add(circle);
+                rotate3 = circle;
+                circle.MouseLeftButtonDown += delegate { Handle = rotate3; };
+                
+                
+                circle = new Ellipse();
+                Children.Add(circle);
+                height2 = circle;
+                circle.MouseLeftButtonDown += delegate { Handle = height2; };
+                
+                
+                circle = new Ellipse();
+                Children.Add(circle);
+                rotate4 = circle;
+                circle.MouseLeftButtonDown+= delegate { Handle = rotate4; };
+                
+                
+                circle = new Ellipse();
+                Children.Add(circle);
+                width2 = circle;
+                circle.MouseLeftButtonDown+= delegate { Handle = width2; };
+                
+                lines = new Shape[8];
+                for(int i=0; i < 8; i++)
+                {
+                    lines[i] = new Line();
+                    Children.Add(lines[i]);
+                }
+            }
             
-            Children.Add(CreateLine(new Point(HandleRadius * 2, HandleRadius),
-                                    new Point(midX - HandleRadius, 
HandleRadius)));
+            // Top left rotate handle
+            SetCircle(rotate1, new Point(left, top));
+            // Top centre stretch handle
+            SetCircle(height1, new Point(midX - HandleRadius, top));
+            // Top right rotate handle
+            SetCircle(rotate2, new Point(right - HandleRadius * 2, top));
+            // Middle right stretch handle
+            SetCircle(width1, new Point(right - HandleRadius * 2, midY - 
HandleRadius));
+            // Bottom right rotate handle
+            SetCircle(rotate3, new Point(right - HandleRadius * 2, bottom - 
HandleRadius * 2));
+            // Bottom centre stretch handle
+            SetCircle(height2, new Point(midX - HandleRadius, bottom - 
HandleRadius * 2));
+            // Bottom left rotate handle
+            SetCircle(rotate4, new Point(left, bottom - HandleRadius * 2));
+            // Middle left stretch handle
+            SetCircle(width2, new Point(left, midY - HandleRadius));
             
-            circle = CreateCircle(new Point(midX - HandleRadius, 0));
-            Children.Add(circle);
-            circle.MouseLeftButtonDown+= delegate {
-                movetype = MoveType.StretchTop;
-                Console.WriteLine(movetype.ToString());
-            };
-
-            Children.Add(CreateLine(new Point(midX + HandleRadius, 
HandleRadius),
-                                    new Point(width - HandleRadius * 2, 
HandleRadius)));
+            // Top left line
+            SetLine(lines[0], new Point(left + HandleRadius * 2, top + 
HandleRadius),
+                              new Point(midX - HandleRadius, top + 
HandleRadius));
+           
+           
+            // Top right line
+            SetLine(lines[1], new Point(midX + HandleRadius, top + 
HandleRadius),
+                              new Point(right - HandleRadius * 2, top + 
HandleRadius));
+           
             
-            // Right side            
-            circle = CreateCircle(new Point(width - HandleRadius * 2, 0));
-            Children.Add(circle);
-            circle.MouseLeftButtonDown+= delegate {
-                movetype = MoveType.Rotate;
-                Console.WriteLine(movetype.ToString());
-            };
+            // Right top line
+            SetLine(lines[2], new Point(right - HandleRadius, top + 
HandleRadius * 2),
+                              new Point(right - HandleRadius, midY - 
HandleRadius));
+           
+            // Right bottom line
+            SetLine(lines[3], new Point(right - HandleRadius, midY + 
HandleRadius),
+                              new Point(right - HandleRadius, bottom - 
HandleRadius * 2));
+           
             
-            Children.Add(CreateLine(new Point(width - HandleRadius, 
HandleRadius * 2),
-                                    new Point( width - HandleRadius, midY - 
HandleRadius)));
-            
-            circle = CreateCircle(new Point(width - HandleRadius * 2, midY - 
HandleRadius));
-            Children.Add(circle);
-            circle.MouseLeftButtonDown+= delegate {
-                movetype = MoveType.StretchWidth;
-                Console.WriteLine(movetype.ToString());
-            };
-            
-            Children.Add(CreateLine(new Point(width - HandleRadius, midY + 
HandleRadius),
-                                    new Point(width - HandleRadius, height - 
HandleRadius * 2)));
-            
-            // Bottom side
-            circle = CreateCircle(new Point(width - HandleRadius * 2, height - 
HandleRadius * 2));
-            Children.Add(circle);
-            circle.MouseLeftButtonDown+= delegate {
-                movetype = MoveType.Rotate;
-                Console.WriteLine(movetype.ToString());
-            };
-            
-            Children.Add(CreateLine(new Point(width - HandleRadius * 2, height 
- HandleRadius),
-                                    new Point(midX + HandleRadius, height - 
HandleRadius)));
-            
-            circle = CreateCircle(new Point(midX - HandleRadius, height - 
HandleRadius * 2));
-            Children.Add(circle);
-            circle.MouseLeftButtonDown+= delegate {
-                movetype = MoveType.StretchHeight;
-                Console.WriteLine(movetype.ToString());
-            };
-            Children.Add(CreateLine(new Point(midX - HandleRadius, height - 
HandleRadius),
-                                    new Point(HandleRadius * 2, height - 
HandleRadius)));
-            
-            // Left side
-            circle = CreateCircle(new Point(0, height - HandleRadius * 2));
-            Children.Add(circle);
-            circle.MouseLeftButtonDown+= delegate {
-                movetype = MoveType.Rotate;
-                Console.WriteLine(movetype.ToString());
-            };
-            
-            Children.Add(CreateLine(new Point(HandleRadius, height - 
HandleRadius * 2),
-                                    new Point(HandleRadius, midY + 
HandleRadius)));
-            
-            circle = CreateCircle(new Point(0, midY - HandleRadius));
-            Children.Add(circle);
-            circle.MouseLeftButtonDown+= delegate {
-                movetype = MoveType.StretchLeft;
-                Console.WriteLine(movetype.ToString());
-            };
-            
-            Children.Add(CreateLine(new Point(HandleRadius, midY - 
HandleRadius),
-                                    new Point(HandleRadius, HandleRadius * 
2)));
+            // Bottom right line
+            SetLine(lines[4], new Point(right - HandleRadius * 2, bottom - 
HandleRadius),
+                              new Point(midX + HandleRadius, bottom - 
HandleRadius));
+           
+           
+            // Bottom left line
+            SetLine(lines[5], new Point(midX - HandleRadius, bottom - 
HandleRadius),
+                              new Point(left + HandleRadius * 2, bottom - 
HandleRadius));
+           
+           
+            // Left bottom line
+            SetLine(lines[6], new Point(left + HandleRadius, bottom - 
HandleRadius * 2),
+                              new Point(left + HandleRadius, midY + 
HandleRadius));
+           
+            // Left top line
+            SetLine(lines[7], new Point(left + HandleRadius, midY - 
HandleRadius),
+                              new Point(left + HandleRadius, top + 
HandleRadius * 2));
         }
         
-        private Line CreateLine(Point start, Point end)
+        private void SetLine(Shape shape, Point start, Point end)
         {
-            Line line = new Line();
+            Line line = (Line)shape;
             line.X1 = start.X;  line.Y1 = start.Y;
             line.X2 = end.X;    line.Y2 = end.Y;
             line.StrokeThickness = 2;
             line.Stroke = new SolidColorBrush(Colors.Black);
-                
-            return line;
         }
         
-        private Ellipse CreateCircle(Point start)
+        private void SetCircle(Shape shape, Point start)
         {
-            Ellipse circle = new Ellipse();
+            Ellipse circle = (Ellipse)shape;
             circle.SetValue<double>(TopProperty, start.Y);
             circle.SetValue<double>(LeftProperty, start.X);
             circle.Width = HandleRadius * 2;
@@ -231,7 +290,6 @@
             circle.Fill = new SolidColorBrush(Colors.White);
             circle.Stroke = new SolidColorBrush(Colors.Blue);
             circle.Cursor = System.Windows.Input.Cursors.Hand;
-            return circle;
         }
     }
 }

Modified: trunk/lunareclipse/Model/SelectionRectangle.cs
===================================================================
--- trunk/lunareclipse/Model/SelectionRectangle.cs      2007-07-12 22:54:41 UTC 
(rev 81914)
+++ trunk/lunareclipse/Model/SelectionRectangle.cs      2007-07-12 23:24:40 UTC 
(rev 81915)
@@ -10,7 +10,7 @@
 using System.Windows.Shapes;
 using System.Windows.Media;
 
-namespace LunarEclipse
+namespace LunarEclipse.Model
 {
     public class SelectionRectangle : Rectangle
     {

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

Reply via email to