]> O.S.I.I.S - jp/crow.git/commitdiff
proportional size spliter.
authorjpbruyere <jp.bruyere@hotmail.com>
Thu, 1 Sep 2016 02:38:22 +0000 (04:38 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Thu, 1 Sep 2016 10:44:39 +0000 (12:44 +0200)
src/GraphicObjects/Splitter.cs

index 43c1ab08dc37f60e7ec9ef436eaa78a8eb080080..12b9f7d5b7b782141c79bb01432133005326b6d4 100644 (file)
@@ -43,7 +43,26 @@ namespace Crow
                                RegisterForLayouting (LayoutingType.Sizing);
                                RegisterForGraphicUpdate ();
                        }
-               } 
+               }
+
+               Unit u1, u2;
+               int init1 = -1, init2 = -1, delta = 0, min1, min2, max1 , max2;
+               GraphicObject go1 = null, go2 = null;
+
+               void initSplit(Measure m1, int size1, Measure m2, int size2){
+                       if (m1 != Measure.Stretched) {
+                               init1 = size1;
+                               u1 = m1.Units;
+                       }
+                       if (m2 != Measure.Stretched) {
+                               init2 = size2;
+                               u2 = m2.Units;
+                       }
+               }
+               void convertSizeInPix(GraphicObject g1){
+
+               }
+
                #region GraphicObject override
                public override ILayoutable Parent {
                        get { return base.Parent; }
@@ -70,6 +89,43 @@ namespace Crow
                        base.onMouseLeave (sender, e);
                        CurrentInterface.MouseCursor = XCursor.Default;
                }
+               public override void onMouseDown (object sender, MouseButtonEventArgs e)
+               {
+                       base.onMouseDown (sender, e);
+                       go1 = go2 = null;
+                       init1 = init2 = -1;
+                       delta = 0;
+
+                       GenericStack gs = Parent as GenericStack;
+                       int ptrSplit = gs.Children.IndexOf (this);
+                       if (ptrSplit == 0 || ptrSplit == gs.Children.Count - 1)
+                               return;
+
+                       go1 = gs.Children [ptrSplit - 1];
+                       go2 = gs.Children [ptrSplit + 1];
+
+                       if (gs.Orientation == Orientation.Horizontal) {
+                               initSplit (go1.Width, go1.Slot.Width, go2.Width, go2.Slot.Width);
+                               min1 = go1.MinimumSize.Width;
+                               min2 = go2.MinimumSize.Width;
+                               max1 = go1.MaximumSize.Width;
+                               max2 = go2.MaximumSize.Width;
+                               if (init1 >= 0)
+                                       go1.Width = init1;
+                               if (init2 >= 0)
+                                       go2.Width = init2;
+                       } else {
+                               initSplit (go1.Height, go1.Slot.Height, go2.Height, go2.Slot.Height);
+                               min1 = go1.MinimumSize.Height;
+                               min2 = go2.MinimumSize.Height;
+                               max1 = go1.MaximumSize.Height;
+                               max2 = go2.MaximumSize.Height;
+                               if (init1 >= 0)
+                                       go1.Height = init1;
+                               if (init2 >= 0)
+                                       go2.Height = init2;
+                       }
+               }
                public override void onMouseMove (object sender, MouseMoveEventArgs e)
                {
                        base.onMouseMove (sender, e);
@@ -78,40 +134,60 @@ namespace Crow
                                return;
 
                        GenericStack gs = Parent as GenericStack;
-                       int ptrSplit = gs.Children.IndexOf (this);
+                       int newDelta = delta, size1 = init1 , size2 = init2;
+                       if (gs.Orientation == Orientation.Horizontal) {
+                               newDelta -= e.XDelta;
+                               if (size1 < 0)
+                                       size1 = go1.Slot.Width;
+                               if (size2 < 0)
+                                       size2 = go2.Slot.Width;
+                       } else {
+                               newDelta -= e.YDelta;
+                               if (size1 < 0)
+                                       size1 = go1.Slot.Height;
+                               if (size2 < 0)
+                                       size2 = go2.Slot.Height;
+                       }
 
-                       if (ptrSplit == 0 || ptrSplit == gs.Children.Count - 1)
+                       if (size1 - newDelta < min1 || (max1 > 0 && size1 - newDelta > max1) ||
+                               size2 + newDelta < min2 || (max2 > 0 && size2 + newDelta > max2))
                                return;
 
-                       if (gs.Orientation == Orientation.Horizontal) {
-                               if ((gs.Children [ptrSplit - 1].Width + e.XDelta <
-                                       gs.Children [ptrSplit - 1].MinimumSize.Width) ||
-                                       (gs.Children [ptrSplit + 1].Width - e.XDelta <
-                                               gs.Children [ptrSplit + 1].MinimumSize.Width))
-                                       return;
-                               
-                               if (!gs.Children [ptrSplit - 1].Width.IsFixed)
-                                       gs.Children [ptrSplit - 1].Width = gs.Children [ptrSplit - 1].Slot.Width;                                       
-                               if (!gs.Children [ptrSplit + 1].Width.IsFixed)
-                                       gs.Children [ptrSplit + 1].Width = gs.Children [ptrSplit + 1].Slot.Width;
-                               
-                               gs.Children [ptrSplit - 1].Width = gs.Children [ptrSplit - 1].Width + e.XDelta;
-                               gs.Children [ptrSplit + 1].Width = gs.Children [ptrSplit + 1].Width - e.XDelta;
+                       delta = newDelta;
 
+                       if (gs.Orientation == Orientation.Horizontal) {
+                               if (init1 >= 0)
+                                       go1.Width = init1 - delta;
+                               if (init2 >= 0)
+                                       go2.Width = init2 + delta;
                        } else {
-                               if ((gs.Children [ptrSplit - 1].Height + e.YDelta <
-                                       gs.Children [ptrSplit - 1].MinimumSize.Height) ||
-                                       (gs.Children [ptrSplit + 1].Height - e.YDelta <
-                                               gs.Children [ptrSplit + 1].MinimumSize.Height))
-                                       return;
-                               
-                               if (!gs.Children [ptrSplit - 1].Height.IsFixed)
-                                       gs.Children [ptrSplit - 1].Height = gs.Children [ptrSplit - 1].Slot.Height;
-                               if (!gs.Children [ptrSplit + 1].Height.IsFixed)
-                                       gs.Children [ptrSplit + 1].Height = gs.Children [ptrSplit + 1].Slot.Height;
-                               
-                               gs.Children [ptrSplit - 1].Height = gs.Children [ptrSplit - 1].Height + e.YDelta;
-                               gs.Children [ptrSplit + 1].Height = gs.Children [ptrSplit + 1].Height - e.YDelta;
+                               if (init1 >= 0)
+                                       go1.Height = init1 - delta;
+                               if (init2 >= 0)
+                                       go2.Height = init2 + delta;
+                       }
+               }
+               public override void onMouseUp (object sender, MouseButtonEventArgs e)
+               {
+                       base.onMouseUp (sender, e);
+
+                       GenericStack gs = Parent as GenericStack;
+
+                       if (init1 >= 0 && u1 == Unit.Percent) {
+                               if (gs.Orientation == Orientation.Horizontal)
+                                       go1.Width = new Measure ((int)Math.Ceiling (
+                                               go1.Width.Value * 100.0 / (double)gs.Slot.Width), Unit.Percent);
+                               else
+                                       go1.Height = new Measure ((int)Math.Ceiling (
+                                               go1.Height.Value * 100.0 / (double)gs.Slot.Height), Unit.Percent);
+                       }
+                       if (init2 >= 0 && u2 == Unit.Percent) {
+                               if (gs.Orientation == Orientation.Horizontal)
+                                       go2.Width = new Measure ((int)Math.Floor (
+                                               go2.Width.Value * 100.0 / (double)gs.Slot.Width), Unit.Percent);
+                               else
+                                       go2.Height = new Measure ((int)Math.Floor (
+                                               go2.Height.Value * 100.0 / (double)gs.Slot.Height), Unit.Percent);
                        }
                }
                public override bool UpdateLayout (LayoutingType layoutType)