]> O.S.I.I.S - jp/crow.git/commitdiff
dragndrop of GObjs
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 14 Mar 2018 11:33:40 +0000 (12:33 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 14 Mar 2018 11:33:40 +0000 (12:33 +0100)
Images/screenshot2.png [new file with mode: 0644]
Tests/BasicTests.cs
src/Colors.cs
src/ExtensionsMethods.cs
src/GraphicObjects/GenericStack.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Group.cs
src/GraphicObjects/PrivateContainer.cs

diff --git a/Images/screenshot2.png b/Images/screenshot2.png
new file mode 100644 (file)
index 0000000..46a7bec
Binary files /dev/null and b/Images/screenshot2.png differ
index e17f15401abc445bf903dcccf303a8ab9eae6884..09db62314f8015ebb17d84f51c07f5c1f532c590 100644 (file)
@@ -159,13 +159,13 @@ namespace Tests
                protected override void OnLoad (EventArgs e)
                {
                        base.OnLoad (e);
-
-                       foreach (Color c in Color.ColorDic.Values) {
-                               if (string.IsNullOrEmpty(c.htmlCode))
-                                       Console.WriteLine ("no htmlcode for {0}", c.Name);
-                               else if (c.htmlCode.Substring(1) != c.HtmlCode)
-                                       Console.WriteLine ("{2} orig: {0} comp: {1}",c.htmlCode, c.HtmlCode, c.Name);
-                       }
+//
+//                     foreach (Color c in Color.ColorDic.Values) {
+//                             if (string.IsNullOrEmpty(c.htmlCode))
+//                                     Console.WriteLine ("no htmlcode for {0}", c.Name);
+//                             else if (c.htmlCode.Substring(1) != c.HtmlCode)
+//                                     Console.WriteLine ("{2} orig: {0} comp: {1}",c.htmlCode, c.HtmlCode, c.Name);
+//                     }
 
 
                        Commands = new List<Crow.Command> (new Crow.Command[] {
@@ -177,8 +177,8 @@ namespace Tests
 
                        this.KeyDown += KeyboardKeyDown1;
 
-                       //testFiles = new string [] { @"Interfaces/Divers/welcome.crow" };
-                       testFiles = new string [] { @"Interfaces/Divers/colorPicker.crow" };
+                       testFiles = new string [] { @"Interfaces/Divers/welcome.crow" };
+                       //testFiles = new string [] { @"Interfaces/Divers/colorPicker.crow" };
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/GraphicObject", "*.crow")).ToArray ();
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Container", "*.crow")).ToArray ();
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Group", "*.crow")).ToArray ();
index 6bc380ccc5985ac4e0a97c6da38e75634fe18198..0b1b3ad7383fbcf988cb438a18482da50e0f8675 100644 (file)
@@ -110,6 +110,8 @@ namespace Crow
                                cc.B = int.Parse (s.Substring (5, 2), System.Globalization.NumberStyles.HexNumber) / 255.0;
                                if (s.Length > 7)
                                        cc.A = int.Parse (s.Substring (7, 2), System.Globalization.NumberStyles.HexNumber) / 255.0;
+                               else
+                                       cc.A = 1.0;
                                return cc;
                        }
 
index cb662c51dc2aaebd9f6781896422867c5b28584e..231964049762627083976048ffa776a0100cd843 100644 (file)
@@ -64,11 +64,9 @@ namespace Crow
                public static Cairo.PointD Multiply(this Cairo.PointD p1, double v){
                        return new Cairo.PointD(p1.X * v, p1.Y * v);
                }
-               public static void DrawCote(this Cairo.Context ctx, Cairo.PointD p1, Cairo.PointD p2, double stroke = 1.0)
-               {
-                       const double arrowWidth = 4.0;
-                       const double arrowLength = 10.0;
-
+               public static void DrawCote(this Cairo.Context ctx, Cairo.PointD p1, Cairo.PointD p2,
+                       double stroke = 1.0, bool fill = false, double arrowWidth = 3.0, double arrowLength = 7.0)
+               {                       
                        Cairo.PointD vDir = p2.Substract(p1);
                        vDir = vDir.GetNormalized ();
                        Cairo.PointD vPerp = vDir.GetPerp ();
@@ -80,21 +78,77 @@ namespace Crow
 
                        ctx.MoveTo (p1);
                        ctx.LineTo (pA0.Add (vA));
-                       ctx.LineTo (pA0.Substract (vA));
+                       if (fill)
+                               ctx.LineTo (pA0.Substract (vA));
+                       else
+                               ctx.MoveTo (pA0.Substract (vA));
+                       
                        ctx.LineTo (p1);
 
                        ctx.MoveTo (p2);
                        ctx.LineTo (pA1.Add (vA));
-                       ctx.LineTo (pA1.Substract (vA));
+                       if (fill)
+                               ctx.LineTo (pA1.Substract (vA));
+                       else
+                               ctx.MoveTo (pA1.Substract (vA));
                        ctx.LineTo (p2);
 
-                       ctx.Fill ();
+                       if (fill)
+                               ctx.Fill ();
 
                        ctx.MoveTo (p1);
                        ctx.LineTo (p2);
                        ctx.LineWidth = stroke;
                        ctx.Stroke ();
+               }
+               public static void DrawCoteInverse(this Cairo.Context ctx, Cairo.PointD p1, Cairo.PointD p2,
+                       double stroke = 1.0, bool fill = false, double arrowWidth = 3.0, double arrowLength = 7.0)
+               {                       
+                       Cairo.PointD vDir = p2.Substract(p1);
+                       vDir = vDir.GetNormalized ();
+                       Cairo.PointD vPerp = vDir.GetPerp ();
+
+                       Cairo.PointD pA0 = p1.Add(vDir.Multiply(arrowLength));
+                       Cairo.PointD pA1 = p2.Substract(vDir.Multiply(arrowLength));
+
+                       Cairo.PointD vA = vPerp.Multiply (arrowWidth);
+
+                       ctx.MoveTo (p1.Add (vA));
+                       ctx.LineTo (pA0);
+                       ctx.LineTo (p1.Substract (vA));
+                       if (fill)
+                               ctx.LineTo (p1.Add (vA));
+
+                       ctx.MoveTo (p2.Add (vA));
+                       ctx.LineTo (pA1);
+                       ctx.LineTo (p2.Substract (vA));
+
+                       if (fill) {
+                               ctx.LineTo (p2.Add (vA));
+                               ctx.Fill ();
+                       }
+
+                       ctx.MoveTo (pA0);
+                       ctx.LineTo (pA1);
+                       ctx.LineWidth = stroke;
+                       ctx.Stroke ();
+               }
+               public static void DrawCoteFixed(this Cairo.Context ctx, Cairo.PointD p1, Cairo.PointD p2,
+                       double stroke = 1.0, double coteWidth = 3.0)
+               {                       
+                       Cairo.PointD vDir = p2.Substract(p1);
+                       vDir = vDir.GetNormalized ();
+                       Cairo.PointD vPerp = vDir.GetPerp ();
+                       Cairo.PointD vA = vPerp.Multiply (coteWidth);
 
+                       ctx.MoveTo (p1.Add (vA));
+                       ctx.LineTo (p1.Substract (vA));
+                       ctx.MoveTo (p2.Add (vA));
+                       ctx.LineTo (p2.Substract (vA));
+                       ctx.MoveTo (p1);
+                       ctx.LineTo (p2);
+                       ctx.LineWidth = stroke;
+                       ctx.Stroke ();
                }
                public static void SetSourceColor(this Cairo.Context ctx, Color c)
                {
index 181c41c29e2e1e47c540a24ad8ec7e3d9ec68e2b..64841d4b79415dac9f5f9eff1da73b851390b6a3 100644 (file)
@@ -227,20 +227,20 @@ namespace Crow
 
        public override void RemoveChild (GraphicObject child)
                {
+                       if (child != stretchedGO) {
+                               if (Orientation == Orientation.Horizontal)
+                                       contentSize.Width -= child.LastSlots.Width;
+                               else 
+                                       contentSize.Height -= child.LastSlots.Height;                           
+                       }
                        base.RemoveChild (child);
                        if (child == stretchedGO) {
-                               //stretchedGO.LastSlots = default(Rectangle);
                                stretchedGO = null;
                                RegisterForLayouting (LayoutingType.Sizing);
-                               return;
-                       }
-                       if (Orientation == Orientation.Horizontal) {
-                               contentSize.Width -= child.LastSlots.Width;
+                       }else if (Orientation == Orientation.Horizontal)                                
                                adjustStretchedGo (LayoutingType.Width);
-                       } else {
-                               contentSize.Height -= child.LastSlots.Height;
-                               adjustStretchedGo (LayoutingType.Height);
-                       }
+                       else                            
+                               adjustStretchedGo (LayoutingType.Height);                       
                }
        }
 }
index 9e5e440195c74fbcf67865bff22fbdcfe4ddf765..2ca07975b0c4373dd700c40471c77f0a7b6cc9d2 100644 (file)
@@ -126,7 +126,24 @@ namespace Crow
 
                        parentElem.AppendChild (xe);
                }
-
+               public Surface CreateIcon (int dragIconSize = 32) {
+                       ImageSurface di = new ImageSurface (Format.Argb32, dragIconSize, dragIconSize);
+                       using (Context ctx = new Context (di)) {
+                               double div = Math.Max (LastPaintedSlot.Width, LastPaintedSlot.Height);
+                               double s = (double)dragIconSize / div;
+                               ctx.Scale (s, s);
+                               if (bmp == null)
+                                       this.onDraw (ctx);
+                               else {
+                                       if (LastPaintedSlot.Width>LastPaintedSlot.Height)
+                                               ctx.SetSourceSurface (bmp, 0, (LastPaintedSlot.Width-LastPaintedSlot.Height)/2);
+                                       else
+                                               ctx.SetSourceSurface (bmp, (LastPaintedSlot.Height-LastPaintedSlot.Width)/2, 0);
+                                       ctx.Paint ();
+                               }
+                       }
+                       return di;
+               }                       
                #endif
 
                #region IDisposable implementation
@@ -337,7 +354,7 @@ namespace Crow
 
                                parentRWLock.EnterWriteLock();
                                parent = value;
-                               Slot = default(Rectangle);
+                               Slot = LastSlots = default(Rectangle);
                                parentRWLock.ExitWriteLock();
                                                                        
                                onParentChanged (this, e);
@@ -374,8 +391,13 @@ namespace Crow
                                Parent.ContextCoordinates (r);
                }
                public virtual Rectangle ScreenCoordinates (Rectangle r){
-                       return
-                               Parent.ScreenCoordinates(r) + Parent.getSlot().Position + Parent.ClientRectangle.Position;
+                       try {
+                               return
+                                       Parent.ScreenCoordinates(r) + Parent.getSlot().Position + Parent.ClientRectangle.Position;                              
+                       } catch (Exception ex) {
+                               Debug.WriteLine (ex);
+                               return default(Rectangle);
+                       }
                }
                public virtual Rectangle getSlot () { return Slot;}
                #endregion
index 9cedec81e766d1909bf897186e1573aa01475f53..a90947a56cedcce61bca0d052d24cd39c9fbd7b3 100644 (file)
@@ -64,7 +64,7 @@ namespace Crow
                }
                #endif
 
-               protected ReaderWriterLockSlim childrenRWLock = new ReaderWriterLockSlim();
+               protected ReaderWriterLockSlim childrenRWLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
 
                #region CTOR
                public Group () : base() {}
index 668ba45284d047e8428c46b7d6ebc8e1a87cb3b4..d66372475240fbacfb659e84be0946d95178e8be 100644 (file)
@@ -75,7 +75,6 @@ namespace Crow
                        if (child != null) {
                                child.Parent = this;
                                child.LayoutChanged += OnChildLayoutChanges;
-                               child.Slot = child.LastSlots = default(Rectangle);
                                contentSize = child.Slot.Size;
                                child.RegisteredLayoutings = LayoutingType.None;
                                child.RegisterForLayouting (LayoutingType.Sizing);