From 4492fa1bccc93616831ddeec76e8c26116d183e4 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Bruyère Date: Sun, 4 Mar 2018 14:46:02 +0100 Subject: docker wip --- src/ExtensionsMethods.cs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/ExtensionsMethods.cs') diff --git a/src/ExtensionsMethods.cs b/src/ExtensionsMethods.cs index 6697be62..dfb90f0e 100644 --- a/src/ExtensionsMethods.cs +++ b/src/ExtensionsMethods.cs @@ -106,6 +106,9 @@ namespace Crow } #endregion + public static Orientation GetOrientation(this Alignment a){ + return (a==Alignment.Left) ||(a==Alignment.Right) ? Orientation.Horizontal : Orientation.Vertical; + } public static void Raise(this EventHandler handler, object sender, EventArgs e) { if(handler != null) -- cgit v1.3.1-4-g156e From 6f303fb67fcc7843ed564c676d12e86b034cfe0a Mon Sep 17 00:00:00 2001 From: Jean-Philippe Bruyère Date: Wed, 7 Mar 2018 15:06:30 +0100 Subject: Height and Width of GO major change for stacking, docker improvement and simplification --- Tests/Interfaces/Experimental/testDock.crow | 24 +- .../TemplatedContainer/testTabView2.crow | 4 +- src/ExtensionsMethods.cs | 21 ++ src/GraphicObjects/DockStack.cs | 285 ++++++++++++--------- src/GraphicObjects/DockWindow.cs | 28 +- src/GraphicObjects/Docker.cs | 33 +-- src/GraphicObjects/GenericStack.cs | 2 +- src/GraphicObjects/GraphicObject.cs | 40 +-- src/GraphicObjects/TabItem.cs | 9 +- src/GraphicObjects/TabView.cs | 4 +- 10 files changed, 255 insertions(+), 195 deletions(-) (limited to 'src/ExtensionsMethods.cs') diff --git a/Tests/Interfaces/Experimental/testDock.crow b/Tests/Interfaces/Experimental/testDock.crow index 3f1aaa3d..742c1e07 100644 --- a/Tests/Interfaces/Experimental/testDock.crow +++ b/Tests/Interfaces/Experimental/testDock.crow @@ -1,14 +1,18 @@  - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/src/ExtensionsMethods.cs b/src/ExtensionsMethods.cs index dfb90f0e..d7448874 100644 --- a/src/ExtensionsMethods.cs +++ b/src/ExtensionsMethods.cs @@ -109,6 +109,27 @@ namespace Crow public static Orientation GetOrientation(this Alignment a){ return (a==Alignment.Left) ||(a==Alignment.Right) ? Orientation.Horizontal : Orientation.Vertical; } + public static Alignment GetOpposite(this Alignment a){ + switch (a) { + case Alignment.Left: + return Alignment.Right; + case Alignment.Right: + return Alignment.Left; + case Alignment.Top: + return Alignment.Bottom; + case Alignment.Bottom: + return Alignment.Top; + case Alignment.TopLeft: + return Alignment.BottomRight; + case Alignment.TopRight: + return Alignment.BottomLeft; + case Alignment.BottomLeft: + return Alignment.TopRight; + case Alignment.BottomRight: + return Alignment.TopLeft; + } + return Alignment.Center; + } public static void Raise(this EventHandler handler, object sender, EventArgs e) { if(handler != null) diff --git a/src/GraphicObjects/DockStack.cs b/src/GraphicObjects/DockStack.cs index c06be42a..bfd3ac9a 100644 --- a/src/GraphicObjects/DockStack.cs +++ b/src/GraphicObjects/DockStack.cs @@ -29,17 +29,9 @@ using Crow.IML; namespace Crow { public class DockStack : GenericStack - { - int dockingDiv = 6; - GraphicObject subStack = null; - + { Docker rootDock { get { return LogicalParent as Docker; }} - public GraphicObject SubStack { - get { return subStack;} - set{ subStack=value; } - } - #region CTor public DockStack () {} public DockStack (Interface iface) : base (iface) {} @@ -77,40 +69,93 @@ namespace Crow } return Slot.ContainsOrIsEqual(m); } + +// public override void OnLayoutChanges (LayoutingType layoutType) +// { +// base.OnLayoutChanges (layoutType); +// +// if ((layoutType & LayoutingType.Sizing) > 0) +// computeRects(); +// } + + Rectangle rIn = default(Rectangle); + double dockThresh = 0.2; + GraphicObject focusedChild; + internal GraphicObject stretchedChild; + + void getFocusedChild (Point lm) { + Rectangle cb = ClientRectangle; + + childrenRWLock.EnterReadLock (); + foreach (GraphicObject c in Children) { + Rectangle bounds = c.Slot + cb.Position; + if (!bounds.ContainsOrIsEqual (lm)) + continue; + rIn = bounds; + focusedChild = c; + break; + } + childrenRWLock.ExitReadLock (); + } + public override void onMouseMove (object sender, MouseMoveEventArgs e) { if (IsDropTarget) { DockWindow dw = IFace.DragAndDropOperation.DragSource as DockWindow; if (dw.IsDocked) { - if (!dw.CheckUndock (e.Position)) { + //if (!dw.CheckUndock (e.Position)) { base.onMouseMove (sender, e); return; - } + //} } - Point lm = ScreenPointToLocal (e.Position); - - Rectangle r = ClientRectangle; - int vTreshold = r.Height / dockingDiv; - int hTreshold = r.Width / dockingDiv; Alignment curDockPos = dw.DockingPosition; + dw.DockingPosition = Alignment.Undefined; + + Rectangle cb = ClientRectangle; + Point lm = ScreenPointToLocal (e.Position); - if (lm.X < hTreshold) - dw.DockingPosition = Alignment.Left; - else if (lm.X > r.Right - hTreshold) - dw.DockingPosition = Alignment.Right; - else if (lm.Y < vTreshold) - dw.DockingPosition = Alignment.Top; - else if (lm.Y > r.Bottom - vTreshold) - dw.DockingPosition = Alignment.Bottom; - else if (this.Children.Contains (rootDock.CenterDockedObj) && !(rootDock.CenterDockedObj is DockWindow)) { - r.Inflate (-r.Width / 3, -r.Height / 3); - if (r.ContainsOrIsEqual (lm)) + if (Children.Count == 0) { + Rectangle r = cb; + r.Inflate (r.Width / -5, r.Height / -5); + if (r.ContainsOrIsEqual(lm)) dw.DockingPosition = Alignment.Center; - else - dw.DockingPosition = Alignment.Undefined; - } else - dw.DockingPosition = Alignment.Undefined; + } else { + rIn = cb; + + if (Orientation == Orientation.Horizontal || Children.Count == 1) { + if (lm.Y > cb.Top + cb.Height / 3 && lm.Y < cb.Bottom - cb.Height / 3) { + if (lm.X < cb.Left + cb.Width / 3) + dw.DockingPosition = Alignment.Left; + else if (lm.X > cb.Right - cb.Width / 3) + dw.DockingPosition = Alignment.Right; + } else { + getFocusedChild (lm); + if (focusedChild != null) { + if (lm.Y < rIn.Top + rIn.Height / 3) + dw.DockingPosition = Alignment.Top; + else if (lm.Y > rIn.Bottom - rIn.Height / 3) + dw.DockingPosition = Alignment.Bottom; + } + } + } + if (Orientation == Orientation.Vertical || Children.Count == 1) { + if (lm.X > cb.Left + cb.Width / 3 && lm.X < cb.Right - cb.Width / 3) { + if (lm.Y < cb.Top + cb.Height / 3) + dw.DockingPosition = Alignment.Top; + else if (lm.Y > cb.Bottom - cb.Height / 3) + dw.DockingPosition = Alignment.Bottom; + } else { + getFocusedChild (lm); + if (focusedChild != null) { + if (lm.X < rIn.Left + rIn.Width / 3) + dw.DockingPosition = Alignment.Left; + else if (lm.X > rIn.Right - rIn.Width / 3) + dw.DockingPosition = Alignment.Right; + } + } + } + } if (curDockPos != dw.DockingPosition) RegisterForGraphicUpdate (); @@ -160,32 +205,28 @@ namespace Crow DockWindow dw = IFace.DragAndDropOperation.DragSource as DockWindow; if (!dw.IsDocked) { - - Rectangle r; - - if ((dw.DockingPosition.GetOrientation () == Orientation || SubStack == null)&&dw.DockingPosition != Alignment.Center) { - r = ClientRectangle; - Console.WriteLine ("Same rect substack=" + SubStack); - }else { - r = subStack.ClientRectangle + subStack.Slot.Position + ClientRectangle.TopLeft; - Console.WriteLine ("sub rect"); - } - + Rectangle cb = ClientRectangle; + double minDim = Math.Min (cb.Width, cb.Height); + + Rectangle r = rIn; + if (Children.Count <= 1 || dw.DockingPosition.GetOrientation()==Orientation ) + r = cb; + switch (dw.DockingPosition) { case Alignment.Top: - gr.Rectangle (r.Left, r.Top, r.Width, r.Height / dockingDiv); + gr.Rectangle (r.Left, r.Top, r.Width, r.Height * dockThresh); break; case Alignment.Bottom: - gr.Rectangle (r.Left, r.Bottom - r.Height / dockingDiv, r.Width, r.Height / dockingDiv); + gr.Rectangle (r.Left, r.Bottom - r.Height * dockThresh, r.Width, r.Height * dockThresh); break; case Alignment.Left: - gr.Rectangle (r.Left, r.Top, r.Width / dockingDiv, r.Height); + gr.Rectangle (r.Left, r.Top, r.Width * dockThresh, r.Height); break; case Alignment.Right: - gr.Rectangle (r.Right - r.Width / dockingDiv, r.Top, r.Width / dockingDiv, r.Height); + gr.Rectangle (r.Right - r.Width * dockThresh, r.Top, r.Width * dockThresh, r.Height); break; case Alignment.Center: - r.Inflate (-Math.Min (r.Width, r.Height) / dockingDiv); + r.Inflate ((int)Math.Ceiling (Math.Min (r.Width, r.Height) * -0.05)); gr.Rectangle (r); break; } @@ -197,77 +238,37 @@ namespace Crow } gr.Restore (); } - - public void Undock (DockWindow dw){ - int idx = Children.IndexOf(dw); - - RemoveChild(dw); - - if (rootDock.CenterDockedObj == dw) { - rootDock.CenterDockedObj = new GraphicObject (IFace) { IsEnabled = false }; - InsertChild (idx, rootDock.CenterDockedObj); - SubStack = rootDock.CenterDockedObj; - }else if (dw.DockingPosition == Alignment.Left || dw.DockingPosition == Alignment.Top) - RemoveChild (idx); - else - RemoveChild (idx - 1); - - if (Children.Count > 1) - return; - - DockStack dsp = Parent as DockStack; - if (dsp == null) - return; - - RemoveChild (0); - idx = dsp.Children.IndexOf (this); - dsp.RemoveChild (this); - dsp.InsertChild (idx, SubStack); - dsp.SubStack = SubStack; - return; - } - public void Dock(DockWindow dw){ - Rectangle r = ClientRectangle; - - int vTreshold = r.Height / dockingDiv; - int hTreshold = r.Width / dockingDiv; - + + public void Dock(DockWindow dw){ DockStack activeStack = this; - Console.WriteLine ("******* Dockingtack {0}", this.Name); + if (Children.Count == 1) { - activeStack = this; Orientation = dw.DockingPosition.GetOrientation (); - }else if (dw.DockingPosition.GetOrientation() != Orientation) { - activeStack = new DockStack (IFace); - int ci = Children.IndexOf (rootDock.CenterDockedObj); - if (ci <0 ){ - DockStack dsp = Parent as DockStack; - if (dsp != null) { - int idx = dsp.Children.IndexOf (this); - dsp.RemoveChild (this); - dsp.SubStack = activeStack; - dsp.InsertChild (idx, activeStack); - activeStack.SubStack = this; - activeStack.AddChild (this); - } else { - Docker dk = Parent as Docker; - dk.RemoveChild (this); - dk.InsertChild (0, activeStack); - dk.SubStack = activeStack; - activeStack.AddChild (this); - activeStack.SubStack = this; - } - }else{ - int i = Children.IndexOf (SubStack); - RemoveChild (SubStack); - activeStack.SubStack = SubStack; - SubStack = activeStack; - InsertChild(i, activeStack); - activeStack.AddChild (activeStack.SubStack); + if (Children [0] is DockWindow) { + (Children [0] as DockWindow).DockingPosition = dw.DockingPosition.GetOpposite (); } + } else if (Children.Count > 0 && dw.DockingPosition.GetOrientation () != Orientation) { + activeStack = new DockStack (IFace); activeStack.Orientation = dw.DockingPosition.GetOrientation (); + activeStack.Width = focusedChild.Width; + activeStack.Height = focusedChild.Height; + int idx = Children.IndexOf (focusedChild); + RemoveChild (focusedChild); + focusedChild.Height = Measure.Stretched; + focusedChild.Width = Measure.Stretched; + InsertChild (idx, activeStack); + activeStack.AddChild (focusedChild); + activeStack.stretchedChild = focusedChild; + if (focusedChild is DockWindow) + (focusedChild as DockWindow).DockingPosition = dw.DockingPosition.GetOpposite (); + focusedChild = null; } - Console.WriteLine ("Docking {0} in {1}", dw.Name, activeStack.Name); + + Rectangle r = ClientRectangle; + int vTreshold = (int)(r.Height * dockThresh); + int hTreshold = (int)(r.Width * dockThresh); + + Console.WriteLine ("Docking {0} as {2} in {1}", dw.Name, activeStack.Name, dw.DockingPosition); switch (dw.DockingPosition) { case Alignment.Top: dw.Height = vTreshold; @@ -294,15 +295,63 @@ namespace Crow activeStack.AddChild (dw); break; case Alignment.Center: - dw.Width = dw.Height = Measure.Stretched; - int i = activeStack.Children.IndexOf (rootDock.CenterDockedObj); - activeStack.DeleteChild (i); - activeStack.InsertChild (i, dw); - activeStack.SubStack = dw; - rootDock.CenterDockedObj= dw; + dw.Width = dw.Height = Measure.Stretched; + AddChild (dw); + stretchedChild = dw; break; } } + public void Undock (DockWindow dw){ + int idx = Children.IndexOf(dw); + + RemoveChild(dw); + + if (Children.Count == 0) + return; + + if (dw.DockingPosition == Alignment.Left || dw.DockingPosition == Alignment.Top) { + RemoveChild (idx); + if (stretchedChild == dw) { + stretchedChild = Children [idx]; + stretchedChild.Width = stretchedChild.Height = Measure.Stretched; + } + } else { + RemoveChild (idx - 1); + if (stretchedChild == dw) { + stretchedChild = Children [idx-2]; + stretchedChild.Width = stretchedChild.Height = Measure.Stretched; + } + } + + if (Children.Count == 1) { + DockStack dsp = Parent as DockStack; + if (dsp == null) { + Children [0].Width = Children [0].Height = Measure.Stretched; + return; + } + //remove level and move remaining obj to level above + GraphicObject g = Children [0]; + RemoveChild (g); + idx = dsp.Children.IndexOf (this); + dsp.RemoveChild (this); + dsp.InsertChild (idx, g); + g.Width = this.Width; + g.Height = this.Height; + if (dsp.stretchedChild == this) + dsp.stretchedChild = g; + dsp.checkAlignments (); + } else + checkAlignments (); + } + + internal void checkAlignments () { + DockWindow dw = Children[0] as DockWindow; + if (dw != null) + dw.DockingPosition = (Orientation == Orientation.Horizontal ? Alignment.Left : Alignment.Top); + dw = Children[Children.Count - 1] as DockWindow; + if (dw != null) + dw.DockingPosition = (Orientation == Orientation.Horizontal ? Alignment.Right : Alignment.Bottom); + } } } diff --git a/src/GraphicObjects/DockWindow.cs b/src/GraphicObjects/DockWindow.cs index f333f6c4..34290a2e 100644 --- a/src/GraphicObjects/DockWindow.cs +++ b/src/GraphicObjects/DockWindow.cs @@ -39,7 +39,6 @@ namespace Crow bool isDocked = false; Alignment docking = Alignment.Undefined; - Point lastMousePos; //last known mouse pos in this control Point undockingMousePosOrig; //mouse pos when docking was donne, use for undocking on mouse move Rectangle savedSlot; //last undocked slot recalled when view is undocked bool wasResizable; @@ -89,13 +88,14 @@ namespace Crow public override void onMouseMove (object sender, MouseMoveEventArgs e) { - lastMousePos = e.Position; +// if (this.HasFocus && e.Mouse.IsButtonDown (MouseButton.Left) && IsDocked) { +// if (Math.Abs (e.Position.X - undockingMousePosOrig.X) > 10 || +// Math.Abs (e.Position.X - undockingMousePosOrig.X) > 10) +// Undock (); +// } - if (this.HasFocus && e.Mouse.IsButtonDown (MouseButton.Left) && IsDocked) { - if (Math.Abs (e.Position.X - undockingMousePosOrig.X) > 10 || - Math.Abs (e.Position.X - undockingMousePosOrig.X) > 10) - Undock (); - } + if (this.HasFocus && e.Mouse.IsButtonDown (MouseButton.Left) && IsDocked) + CheckUndock (e.Position); base.onMouseMove (sender, e); } @@ -107,6 +107,8 @@ namespace Crow undockingMousePosOrig = e.Position; } public bool CheckUndock (Point mousePos) { + if (DockingPosition == Alignment.Center) + return false; if (Math.Abs (mousePos.X - undockingMousePosOrig.X) < undockThreshold || Math.Abs (mousePos.X - undockingMousePosOrig.X) < undockThreshold) return false; @@ -143,10 +145,8 @@ namespace Crow Resizable = wasResizable; } } + void dock (DockStack target){ - if (RootDock.CenterDockedObj is DockWindow && DockingPosition == Alignment.Center) - return; - lock (IFace.UpdateMutex) { IsDocked = true; //undockingMousePosOrig = lastMousePos; @@ -156,17 +156,23 @@ namespace Crow LastSlots = LastPaintedSlot = Slot = default(Rectangle); Left = Top = 0; - RootDock.RemoveChild (this); + Group g = Parent as Group; + g.RemoveChild (this); target.Dock (this); } } + protected override void close () { if (isDocked) Undock (); base.close (); } + + public string ExportWinConfigs () { + return string.Format ("{0};{1};{2}", this.Name, DockingPosition, savedSlot); + } } } diff --git a/src/GraphicObjects/Docker.cs b/src/GraphicObjects/Docker.cs index 6c55e34e..1aa4fa37 100644 --- a/src/GraphicObjects/Docker.cs +++ b/src/GraphicObjects/Docker.cs @@ -44,8 +44,6 @@ namespace Crow int dockingThreshold; - public DockStack SubStack = null; - public GraphicObject CenterDockedObj = null; [XmlAttributeAttribute][DefaultValue(10)] public virtual int DockingThreshold { @@ -58,42 +56,29 @@ namespace Crow } } - protected override void onInitialized (object sender, EventArgs e) - { - base.onInitialized (sender, e); - CenterDockedObj = new GraphicObject (IFace) { IsEnabled = false }; - } - public override void AddChild (GraphicObject g) { base.AddChild (g); g.LogicalParent = this; } - public override void RemoveChild (GraphicObject child) - { -// lock (IFace.UpdateMutex) { -// RegisterClip (ScreenCoordinates (LastPaintedSlot)); -// } - base.RemoveChild (child); - } public override void onMouseMove (object sender, MouseMoveEventArgs e) { if (IFace.DragAndDropOperation?.DragSource as DockWindow != null) { DockWindow dw = IFace.DragAndDropOperation.DragSource as DockWindow; - if (!dw.IsDocked) - dw.MoveAndResize (e.XDelta, e.YDelta); - if (SubStack == null) { - DockStack ds = new DockStack (IFace); - SubStack = ds; - InsertChild (0, SubStack); - ds.LogicalParent = this; - ds.AddChild (CenterDockedObj); - ds.SubStack = CenterDockedObj; + if (!dw.IsDocked) { + Rectangle r = dw.ScreenCoordinates (dw.Slot); + Point p = ScreenPointToLocal (e.Position); + dw.Left = p.X - r.Width / 2; + dw.Top = p.Y - r.Height / 2; } } base.onMouseMove (sender, e); } + + public string ExportWinConfigs () { + return ""; + } } } diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index f23b0bba..587f86dc 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -230,7 +230,7 @@ namespace Crow { base.RemoveChild (child); if (child == stretchedGO) { - stretchedGO.LastSlots = default(Rectangle); + //stretchedGO.LastSlots = default(Rectangle); stretchedGO = null; RegisterForLayouting (LayoutingType.Sizing); return; diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 1e35f5b8..911ea7bd 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -604,23 +604,24 @@ namespace Crow if (value < MinimumSize.Width || (value > MaximumSize.Width && MaximumSize.Width > 0)) return; } - Measure lastWP = WidthPolicy; + Measure old = width; width = value; NotifyValueChanged ("Width", width); - if (WidthPolicy != lastWP) { - NotifyValueChanged ("WidthPolicy", WidthPolicy); + if (width == Measure.Stretched || old == Measure.Stretched) { + //NotifyValueChanged ("WidthPolicy", width.Policy); //contentSize in Stacks are only update on childLayoutChange, and the single stretched //child of the stack is not counted in contentSize, so when changing size policy of a child //we should adapt contentSize //TODO:check case when child become stretched, and another stretched item already exists. - if (parent is GenericStack) {//TODO:check if I should test Group instead - if ((parent as GenericStack).Orientation == Orientation.Horizontal) { - if (lastWP == Measure.Fit) - (parent as GenericStack).contentSize.Width -= this.LastSlots.Width; + GenericStack gs = Parent as GenericStack; + if (gs != null){ //TODO:check if I should test Group instead + if (gs.Orientation == Orientation.Horizontal) { + if (width == Measure.Stretched) + gs.contentSize.Width -= this.LastSlots.Width; else - (parent as GenericStack).contentSize.Width += this.LastSlots.Width; + gs.contentSize.Width += this.LastSlots.Width; } - } + } } this.RegisterForLayouting (LayoutingType.Width); @@ -644,17 +645,18 @@ namespace Crow if (value < MinimumSize.Height || (value > MaximumSize.Height && MaximumSize.Height > 0)) return; } - Measure lastHP = HeightPolicy; + Measure old = height; height = value; NotifyValueChanged ("Height", height); - if (HeightPolicy != lastHP) { - NotifyValueChanged ("HeightPolicy", HeightPolicy); - if (parent is GenericStack) { - if ((parent as GenericStack).Orientation == Orientation.Vertical) { - if (lastHP == Measure.Fit) - (parent as GenericStack).contentSize.Height -= this.LastSlots.Height; + if (height == Measure.Stretched || old == Measure.Stretched) { + //NotifyValueChanged ("HeightPolicy", HeightPolicy); + GenericStack gs = Parent as GenericStack; + if (gs != null){ //TODO:check if I should test Group instead + if (gs.Orientation == Orientation.Vertical) { + if (height == Measure.Stretched) + gs.contentSize.Height -= this.LastSlots.Height; else - (parent as GenericStack).contentSize.Height += this.LastSlots.Height; + gs.contentSize.Height += this.LastSlots.Height; } } } @@ -663,13 +665,13 @@ namespace Crow } } /// - /// Used for binding on dimensions, this property will never hold fixed size, but instead only + /// Was Used for binding on dimensions, this property will never hold fixed size, but instead only /// Fit or Stretched, **with inherited state implementation, it is not longer used in binding** /// [XmlIgnore]public virtual Measure WidthPolicy { get { return Width.IsFit ? Measure.Fit : Measure.Stretched; } } /// - /// Used for binding on dimensions, this property will never hold fixed size, but instead only + /// Was Used for binding on dimensions, this property will never hold fixed size, but instead only /// Fit or Stretched, **with inherited state implementation, it is not longer used in binding** /// [XmlIgnore]public virtual Measure HeightPolicy { get { diff --git a/src/GraphicObjects/TabItem.cs b/src/GraphicObjects/TabItem.cs index b2814393..584c180e 100644 --- a/src/GraphicObjects/TabItem.cs +++ b/src/GraphicObjects/TabItem.cs @@ -227,7 +227,6 @@ namespace Crow tv.AddChild (this); } #region Mouse Handling - public bool HoldCursor = false; public override bool PointIsIn (ref Point m) { if (!base.PointIsIn (ref m)) @@ -238,15 +237,9 @@ namespace Crow else return this.isSelected; } - public override void onMouseDown (object sender, MouseButtonEventArgs e) - { - base.onMouseDown (sender, e); - HoldCursor = true; - } public override void onMouseUp (object sender, MouseButtonEventArgs e) { base.onMouseUp (sender, e); - HoldCursor = false; tview.UpdateLayout (LayoutingType.ArrangeChildren); } public override void onMouseMove (object sender, MouseMoveEventArgs e) @@ -256,7 +249,7 @@ namespace Crow if (Parent == null) return; - if (!(HasFocus && HoldCursor)) + if (!IsDragged) return; TabView tv = Parent as TabView; diff --git a/src/GraphicObjects/TabView.cs b/src/GraphicObjects/TabView.cs index 49d8729d..304e820d 100644 --- a/src/GraphicObjects/TabView.cs +++ b/src/GraphicObjects/TabView.cs @@ -215,7 +215,7 @@ namespace Crow else adjustedTab = -1; - Console.WriteLine ("tabspace: {0} tw:{1}", tabSpace, tabWidth); + //Console.WriteLine ("tabspace: {0} tw:{1}", tabSpace, tabWidth); childrenRWLock.EnterReadLock(); TabItem[] tabItms = Children.Cast().OrderBy (t=>t.ViewIndex).ToArray(); @@ -227,7 +227,7 @@ namespace Crow continue; tabItms [i].NotifyValueChanged ("TabHeight", tabHeight); tabItms [i].NotifyValueChanged ("TabWidth", TabWidth); - if (!tabItms [i].HoldCursor) { + if (!tabItms [i].IsDragged) { tabItms [i].TabOffset = curOffset; //Console.WriteLine ("offset: {0}=>{1}", tabItms [i].Name, tabItms [i].TabOffset); } -- cgit v1.3.1-4-g156e From 523a04de5252ae089e52eeaf9c8d83a5e0676731 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Bruyère Date: Sat, 10 Mar 2018 06:03:25 +0100 Subject: getStremFromPath made instanced for overriding in designiface, crowide wip --- Tests/OpenGL/Shader.cs | 6 ++--- Tests/OpenGL/Texture.cs | 2 +- src/BmpPicture.cs | 9 +++---- src/CompilerServices/CompilerServices.cs | 20 +++++++++++--- src/ExtensionsMethods.cs | 7 ++++- src/GraphicObjects/GraphicObject.cs | 10 +++---- src/GraphicObjects/Group.cs | 22 +++++++-------- src/GraphicObjects/Image.cs | 6 ++--- src/GraphicObjects/TabItem.cs | 4 +-- src/IML/IMLContext.cs | 39 ++++++++++++++++++++++----- src/Instantiator.cs | 4 +-- src/Interface.cs | 46 +++++++++++++++++++++++--------- src/Picture.cs | 16 +++++------ src/SvgPicture.cs | 4 +-- src/XCursor.cs | 4 +-- 15 files changed, 127 insertions(+), 72 deletions(-) (limited to 'src/ExtensionsMethods.cs') diff --git a/Tests/OpenGL/Shader.cs b/Tests/OpenGL/Shader.cs index f91a982c..1253ff72 100644 --- a/Tests/OpenGL/Shader.cs +++ b/Tests/OpenGL/Shader.cs @@ -269,7 +269,7 @@ namespace Crow Stream s; if (!string.IsNullOrEmpty (VertSourcePath)) { - s = Crow.Interface.GetStreamFromPath (VertSourcePath); + s = Crow.Interface.StaticGetStreamFromPath (VertSourcePath); if (s != null) { using (StreamReader sr = new StreamReader (s)) { vertSource = sr.ReadToEnd (); @@ -278,7 +278,7 @@ namespace Crow } if (!string.IsNullOrEmpty (FragSourcePath)) { - s = Crow.Interface.GetStreamFromPath (FragSourcePath); + s = Crow.Interface.StaticGetStreamFromPath (FragSourcePath); if (s != null) { using (StreamReader sr = new StreamReader (s)) { fragSource = sr.ReadToEnd (); @@ -287,7 +287,7 @@ namespace Crow } if (!string.IsNullOrEmpty (GeomSourcePath)) { - s = Crow.Interface.GetStreamFromPath (GeomSourcePath); + s = Crow.Interface.StaticGetStreamFromPath (GeomSourcePath); if (s != null) { using (StreamReader sr = new StreamReader (s)) { geomSource = sr.ReadToEnd (); diff --git a/Tests/OpenGL/Texture.cs b/Tests/OpenGL/Texture.cs index ce24808b..08215ada 100644 --- a/Tests/OpenGL/Texture.cs +++ b/Tests/OpenGL/Texture.cs @@ -37,7 +37,7 @@ namespace Crow public Texture(string _mapPath, bool flipY = true) { - using (Stream s = Interface.GetStreamFromPath (_mapPath)) { + using (Stream s = Interface.StaticGetStreamFromPath (_mapPath)) { try { Map = _mapPath; diff --git a/src/BmpPicture.cs b/src/BmpPicture.cs index b8271615..e3af9c79 100644 --- a/src/BmpPicture.cs +++ b/src/BmpPicture.cs @@ -55,7 +55,7 @@ namespace Crow /// load the image for rendering from the path given as argument /// /// image path, may be embedded - public override void Load (string path) + public override void Load (Interface iface, string path) { Path = path; if (sharedResources.ContainsKey (path)) { @@ -64,11 +64,8 @@ namespace Crow Dimensions = sp.Dims; return; } - using (Stream stream = Interface.GetStreamFromPath (path)) { - using (MemoryStream ms = new MemoryStream ()) { - stream.CopyTo (ms); - loadBitmap (new System.Drawing.Bitmap (ms)); - } + using (Stream stream = iface.GetStreamFromPath (path)) { + loadBitmap (new System.Drawing.Bitmap (stream)); } sharedResources [path] = new sharedPicture (image, Dimensions); } diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index 12a020ff..e315f761 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -276,7 +276,11 @@ namespace Crow.IML #region Reflexion helpers static MemberInfo getMemberInfoWithReflexion(object instance, string member){ - return instance.GetType ().GetMember (member)?.FirstOrDefault(); + Type t = instance.GetType(); + MemberInfo mi = t.GetMember (member)?.FirstOrDefault(); + if (mi == null) + mi = CompilerServices.SearchExtMethod (t, member); + return mi; } static MethodInfo getMethodInfoWithReflexion(object instance, string method){ return instance.GetType ().GetMethod (method, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); @@ -344,12 +348,20 @@ namespace Crow.IML PropertyInfo pi = mi as PropertyInfo; tmp = pi.GetValue (instance); dstType = pi.PropertyType; - } - if (mi.MemberType == MemberTypes.Field) { + }else if (mi.MemberType == MemberTypes.Field) { FieldInfo fi = mi as FieldInfo; tmp = fi.GetValue (instance); dstType = fi.FieldType; + }else if (mi.MemberType == MemberTypes.Method) { + MethodInfo gi = mi as MethodInfo; + if (gi.IsStatic) + tmp = gi.Invoke(null, new object[] {instance}); + else + tmp = gi.Invoke(instance, null); + dstType = gi.ReturnType; } + + if (tmp != null) return tmp; if (dstType == typeof(string) || dstType == CompilerServices.TObject)//TODO:object should be allowed to return null and not "" @@ -693,7 +705,7 @@ namespace Crow.IML /// /// create delegate helper /// - static Delegate createDel(Type eventType, object instance, string method){ + static Delegate createDel(object instance, Type eventType, string method){ Type t = instance.GetType (); MethodInfo mi = t.GetMethod (method, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (mi == null) { diff --git a/src/ExtensionsMethods.cs b/src/ExtensionsMethods.cs index d7448874..cb662c51 100644 --- a/src/ExtensionsMethods.cs +++ b/src/ExtensionsMethods.cs @@ -144,7 +144,12 @@ namespace Crow handler(sender, e); } } - + public static byte[] GetBytes(this string str) + { + byte[] bytes = new byte[str.Length * sizeof(char)]; + System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length); + return bytes; + } public static bool IsWhiteSpaceOrNewLine (this char c) { return c == '\t' || c == '\r' || c == '\n' || char.IsWhiteSpace (c); diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index c7491330..5b6438c2 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -1404,11 +1404,11 @@ namespace Crow IFace.currentLQI.NewSlot = Slot; Debug.WriteLine ("\t\t{0} => {1}",LastSlots,Slot); #endif - #if DESIGN_MODE - if (IFace.GetType().Name == "DesignInterface"){ - Debug.WriteLine ("\t\t{2}: {0} => {1}",LastSlots,Slot,this.name); - } - #endif +// #if DESIGN_MODE +// if (IFace.GetType().Name == "DesignInterface"){ +// Debug.WriteLine ("\t\t{2}: {0} => {1}",LastSlots,Slot,this.name); +// } +// #endif switch (layoutType) { case LayoutingType.Width: diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index 43f08198..9cedec81 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -167,6 +167,17 @@ namespace Crow this.RegisterForLayouting (LayoutingType.Sizing); ChildrenCleared.Raise (this, new EventArgs ()); } + public override void OnDataSourceChanged (object sender, DataSourceChangeEventArgs e) + { + base.OnDataSourceChanged (this, e); + + childrenRWLock.EnterReadLock (); + foreach (GraphicObject g in Children) { + if (g.localDataSourceIsNull & g.localLogicalParentIsNull) + g.OnDataSourceChanged (g, e); + } + childrenRWLock.ExitReadLock (); + } public void putWidgetOnTop(GraphicObject w) { @@ -194,18 +205,7 @@ namespace Crow } #region GraphicObject overrides - public override void OnDataSourceChanged (object sender, DataSourceChangeEventArgs e) - { - base.OnDataSourceChanged (this, e); - childrenRWLock.EnterReadLock (); - - foreach (GraphicObject g in children) - if (g.localDataSourceIsNull & g.localLogicalParentIsNull) - g.OnDataSourceChanged (g, e); - - childrenRWLock.ExitReadLock (); - } public override GraphicObject FindByName (string nameToFind) { if (Name == nameToFind) diff --git a/src/GraphicObjects/Image.cs b/src/GraphicObjects/Image.cs index d6392626..c59abca8 100644 --- a/src/GraphicObjects/Image.cs +++ b/src/GraphicObjects/Image.cs @@ -169,11 +169,11 @@ namespace Crow { Picture pic; if (path.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture)) - pic = new SvgPicture (); + pic = new SvgPicture (path); else - pic = new BmpPicture (); + pic = new BmpPicture (path); - pic.Load (path); + pic.Load (IFace, path); pic.Scaled = scaled; pic.KeepProportions = keepProps; diff --git a/src/GraphicObjects/TabItem.cs b/src/GraphicObjects/TabItem.cs index 584c180e..473fc313 100644 --- a/src/GraphicObjects/TabItem.cs +++ b/src/GraphicObjects/TabItem.cs @@ -90,7 +90,7 @@ namespace Crow } } - [XmlAttributeAttribute][DefaultValue(0)] + [DefaultValue(0)] public int TabOffset { get { return tabOffset; } set { @@ -109,7 +109,7 @@ namespace Crow public Measure TabWidth { get { return tview == null ? Measure.Fit : tview.TabWidth; } } - [XmlAttributeAttribute][DefaultValue(false)] + [DefaultValue(false)] public virtual bool IsSelected { get { return isSelected; } set { diff --git a/src/IML/IMLContext.cs b/src/IML/IMLContext.cs index b11dfa69..aa4dee2f 100644 --- a/src/IML/IMLContext.cs +++ b/src/IML/IMLContext.cs @@ -183,23 +183,48 @@ namespace Crow.IML /// Bd. /// passed as arg to prevent refetching it for the 3rd time public void emitHandlerMethodAddition(EventBinding bd){ + //fetch source instance with address for handler addition (as 1st arg of handler.add) il.Emit (OpCodes.Ldloc_0);//push root CompilerServices.emitGetInstance (il, bd.SourceNA); + il.Emit (OpCodes.Ldloc_0); + CompilerServices.emitGetInstance (il, bd.TargetNA); + + string[] membs = bd.TargetMember.Split ('.'); + for (int i = 0; i < membs.Length - 1; i++) { + il.Emit (OpCodes.Dup); + il.Emit (OpCodes.Ldstr, membs[i]); + il.Emit (OpCodes.Call, CompilerServices.miGetMembIinfoWithRefx); + il.Emit (OpCodes.Call, CompilerServices.miGetValWithRefx); + } + //load handlerType of sourceEvent to create handler delegate (1st arg) il.Emit (OpCodes.Ldtoken, bd.SourceEvent.EventHandlerType); il.Emit (OpCodes.Call, CompilerServices.miGetTypeFromHandle); - //load target the where the method is defined (2nd arg) - il.Emit (OpCodes.Ldloc_0); - CompilerServices.emitGetInstance (il, bd.TargetNA); //load methodInfo (3rd arg) - il.Emit (OpCodes.Ldstr, bd.TargetMember); - + il.Emit (OpCodes.Ldstr, membs[membs.Length-1]); il.Emit (OpCodes.Callvirt, CompilerServices.miCreateDel); - il.Emit (OpCodes.Callvirt, bd.SourceEvent.AddMethod);//call add event } - +// public void emitHandlerMethodAddition(EventBinding bd){ +// //fetch source instance with address for handler addition (as 1st arg of handler.add) +// il.Emit (OpCodes.Ldloc_0);//push root +// CompilerServices.emitGetInstance (il, bd.SourceNA); +// +// //load handlerType of sourceEvent to create handler delegate (1st arg) +// il.Emit (OpCodes.Ldtoken, bd.SourceEvent.EventHandlerType); +// il.Emit (OpCodes.Call, CompilerServices.miGetTypeFromHandle); +// //load target the where the method is defined (2nd arg) +// il.Emit (OpCodes.Ldloc_0); +// CompilerServices.emitGetInstance (il, bd.TargetNA); +// //load methodInfo (3rd arg) +// il.Emit (OpCodes.Ldstr, bd.TargetMember); +// +// il.Emit (OpCodes.Callvirt, CompilerServices.miCreateDel); +// +// il.Emit (OpCodes.Callvirt, bd.SourceEvent.AddMethod);//call add event +// } +// } } \ No newline at end of file diff --git a/src/Instantiator.cs b/src/Instantiator.cs index 49d4f533..3eab819a 100644 --- a/src/Instantiator.cs +++ b/src/Instantiator.cs @@ -85,7 +85,7 @@ namespace Crow.IML /// /// Initializes a new instance of the Instantiator class. /// - public Instantiator (Interface _iface, string path) : this (_iface, Interface.GetStreamFromPath(path), path) { + public Instantiator (Interface _iface, string path) : this (_iface, _iface.GetStreamFromPath(path), path) { } /// @@ -335,7 +335,7 @@ namespace Crow.IML if (iface.Instantiators.ContainsKey (itemTemplatePath)) { itemTemplateIds.Add (new string [] { "default", itemTemplatePath, "" }); } else { - using (Stream stream = Interface.GetStreamFromPath (itemTemplatePath)) { + using (Stream stream = iface.GetStreamFromPath (itemTemplatePath)) { //itemtemplate files may have multiple root nodes XmlReaderSettings itrSettings = new XmlReaderSettings { ConformanceLevel = ConformanceLevel.Fragment }; using (XmlReader itr = XmlReader.Create (stream, itrSettings)) { diff --git a/src/Interface.cs b/src/Interface.cs index f17ac895..00a952b0 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -88,8 +88,6 @@ namespace Crow } } - loadCursors (); - FontRenderingOptions = new FontOptions (); FontRenderingOptions.Antialias = Antialias.Subpixel; FontRenderingOptions.HintMetrics = HintMetrics.On; @@ -103,6 +101,7 @@ namespace Crow public void Init () { CurrentInterface = this; + loadCursors (); loadStyling (); findAvailableTemplates (); initTooltip (); @@ -271,17 +270,17 @@ namespace Crow } } - static void loadCursors(){ + void loadCursors(){ //Load cursors - XCursor.Cross = XCursorFile.Load("#Crow.Images.Icons.Cursors.cross").Cursors[0]; - XCursor.Default = XCursorFile.Load("#Crow.Images.Icons.Cursors.arrow").Cursors[0]; - XCursor.NW = XCursorFile.Load("#Crow.Images.Icons.Cursors.top_left_corner").Cursors[0]; - XCursor.NE = XCursorFile.Load("#Crow.Images.Icons.Cursors.top_right_corner").Cursors[0]; - XCursor.SW = XCursorFile.Load("#Crow.Images.Icons.Cursors.bottom_left_corner").Cursors[0]; - XCursor.SE = XCursorFile.Load("#Crow.Images.Icons.Cursors.bottom_right_corner").Cursors[0]; - XCursor.H = XCursorFile.Load("#Crow.Images.Icons.Cursors.sb_h_double_arrow").Cursors[0]; - XCursor.V = XCursorFile.Load("#Crow.Images.Icons.Cursors.sb_v_double_arrow").Cursors[0]; - XCursor.Text = XCursorFile.Load("#Crow.Images.Icons.Cursors.ibeam").Cursors[0]; + XCursor.Cross = XCursorFile.Load(this, "#Crow.Images.Icons.Cursors.cross").Cursors[0]; + XCursor.Default = XCursorFile.Load(this, "#Crow.Images.Icons.Cursors.arrow").Cursors[0]; + XCursor.NW = XCursorFile.Load(this, "#Crow.Images.Icons.Cursors.top_left_corner").Cursors[0]; + XCursor.NE = XCursorFile.Load(this, "#Crow.Images.Icons.Cursors.top_right_corner").Cursors[0]; + XCursor.SW = XCursorFile.Load(this, "#Crow.Images.Icons.Cursors.bottom_left_corner").Cursors[0]; + XCursor.SE = XCursorFile.Load(this, "#Crow.Images.Icons.Cursors.bottom_right_corner").Cursors[0]; + XCursor.H = XCursorFile.Load(this, "#Crow.Images.Icons.Cursors.sb_h_double_arrow").Cursors[0]; + XCursor.V = XCursorFile.Load(this, "#Crow.Images.Icons.Cursors.sb_v_double_arrow").Cursors[0]; + XCursor.Text = XCursorFile.Load(this, "#Crow.Images.Icons.Cursors.ibeam").Cursors[0]; } #endregion @@ -329,7 +328,28 @@ namespace Crow /// A file or resource stream /// This could be a normal file path, or an embedded ressource ID /// Resource ID's must be prefixed with '#' character - public static Stream GetStreamFromPath (string path) + public virtual Stream GetStreamFromPath (string path) + { + Stream stream = null; + + if (path.StartsWith ("#")) { + string resId = path.Substring (1); + //try/catch added to prevent nunit error + try { + stream = System.Reflection.Assembly.GetEntryAssembly ().GetManifestResourceStream (resId); + } catch{} + if (stream == null)//try to find ressource in Crow assembly + stream = System.Reflection.Assembly.GetExecutingAssembly ().GetManifestResourceStream (resId); + if (stream == null) + throw new Exception ("Resource not found: " + path); + } else { + if (!File.Exists (path)) + throw new FileNotFoundException ("File not found: ", path); + stream = new FileStream (path, FileMode.Open, FileAccess.Read); + } + return stream; + } + public static Stream StaticGetStreamFromPath (string path) { Stream stream = null; diff --git a/src/Picture.cs b/src/Picture.cs index fe7007c7..3784780b 100644 --- a/src/Picture.cs +++ b/src/Picture.cs @@ -87,7 +87,7 @@ namespace Crow /// image path, may be embedded public Picture (string path) { - Load (path); + Path = path; } #endregion @@ -96,7 +96,7 @@ namespace Crow /// load the image for rendering from the stream given as argument /// /// picture stream - public abstract void Load(string path); + public abstract void Load(Interface iface, string path); #endregion /// @@ -117,11 +117,9 @@ namespace Crow Picture _pic = null; if (path.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture)) - _pic = new SvgPicture (); + _pic = new SvgPicture (path); else - _pic = new BmpPicture (); - - _pic.Load (path); + _pic = new BmpPicture (path); return _pic; } @@ -139,11 +137,9 @@ namespace Crow Picture _pic = null; if (path.EndsWith (".svg", true, System.Globalization.CultureInfo.InvariantCulture)) - _pic = new SvgPicture (); + _pic = new SvgPicture (path); else - _pic = new BmpPicture (); - - _pic.Load (path); + _pic = new BmpPicture (path); return _pic; } diff --git a/src/SvgPicture.cs b/src/SvgPicture.cs index ce7fdedf..f676a497 100644 --- a/src/SvgPicture.cs +++ b/src/SvgPicture.cs @@ -51,7 +51,7 @@ namespace Crow {} #endregion - public override void Load (string path) + public override void Load (Interface iface, string path) { Path = path; if (sharedResources.ContainsKey (path)) { @@ -60,7 +60,7 @@ namespace Crow Dimensions = sp.Dims; return; } - using (Stream stream = Interface.GetStreamFromPath (path)) { + using (Stream stream = iface.GetStreamFromPath (path)) { using (MemoryStream ms = new MemoryStream ()) { stream.CopyTo (ms); diff --git a/src/XCursor.cs b/src/XCursor.cs index 627e2afd..1cca510e 100644 --- a/src/XCursor.cs +++ b/src/XCursor.cs @@ -86,9 +86,9 @@ namespace Crow return tmp; } - public static XCursorFile Load(string path) + public static XCursorFile Load(Interface iface, string path) { - return loadFromStream (Interface.GetStreamFromPath (path)); + return loadFromStream (iface.GetStreamFromPath (path)); } static XCursor imageLoad(BinaryReader sr) -- cgit v1.3.1-4-g156e From 2c8ebf731af0a626c5d684efc5c2853edd8c3c2d Mon Sep 17 00:00:00 2001 From: Jean-Philippe Bruyère Date: Wed, 14 Mar 2018 12:33:40 +0100 Subject: dragndrop of GObjs --- Images/screenshot2.png | Bin 0 -> 120135 bytes Tests/BasicTests.cs | 18 ++++----- src/Colors.cs | 2 + src/ExtensionsMethods.cs | 70 +++++++++++++++++++++++++++++---- src/GraphicObjects/GenericStack.cs | 18 ++++----- src/GraphicObjects/GraphicObject.cs | 30 ++++++++++++-- src/GraphicObjects/Group.cs | 2 +- src/GraphicObjects/PrivateContainer.cs | 1 - 8 files changed, 109 insertions(+), 32 deletions(-) create mode 100644 Images/screenshot2.png (limited to 'src/ExtensionsMethods.cs') diff --git a/Images/screenshot2.png b/Images/screenshot2.png new file mode 100644 index 00000000..46a7bec2 Binary files /dev/null and b/Images/screenshot2.png differ diff --git a/Tests/BasicTests.cs b/Tests/BasicTests.cs index e17f1540..09db6231 100644 --- a/Tests/BasicTests.cs +++ b/Tests/BasicTests.cs @@ -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 (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 (); diff --git a/src/Colors.cs b/src/Colors.cs index 6bc380cc..0b1b3ad7 100644 --- a/src/Colors.cs +++ b/src/Colors.cs @@ -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; } diff --git a/src/ExtensionsMethods.cs b/src/ExtensionsMethods.cs index cb662c51..23196404 100644 --- a/src/ExtensionsMethods.cs +++ b/src/ExtensionsMethods.cs @@ -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) { diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index 181c41c2..64841d4b 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -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); } } } diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 9e5e4401..2ca07975 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -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 diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index 9cedec81..a90947a5 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -64,7 +64,7 @@ namespace Crow } #endif - protected ReaderWriterLockSlim childrenRWLock = new ReaderWriterLockSlim(); + protected ReaderWriterLockSlim childrenRWLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); #region CTOR public Group () : base() {} diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs index 668ba452..d6637247 100644 --- a/src/GraphicObjects/PrivateContainer.cs +++ b/src/GraphicObjects/PrivateContainer.cs @@ -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); -- cgit v1.3.1-4-g156e From 3146fb24af208dbe80506885281302438c4402f8 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Bruyère Date: Wed, 14 Mar 2018 19:20:08 +0100 Subject: imledit overlay icon --- src/ExtensionsMethods.cs | 3 +++ src/Rectangle.cs | 8 ++++++++ 2 files changed, 11 insertions(+) (limited to 'src/ExtensionsMethods.cs') diff --git a/src/ExtensionsMethods.cs b/src/ExtensionsMethods.cs index 23196404..340a8ceb 100644 --- a/src/ExtensionsMethods.cs +++ b/src/ExtensionsMethods.cs @@ -58,6 +58,9 @@ namespace Crow public static Cairo.PointD Substract(this Cairo.PointD p1, Cairo.PointD p2){ return new Cairo.PointD(p1.X - p2.X, p1.Y - p2.Y); } + public static Cairo.PointD Divide(this Cairo.PointD p1, double d){ + return new Cairo.PointD(p1.X / d, p1.Y / d); + } public static Cairo.PointD Add(this Cairo.PointD p1, Cairo.PointD p2){ return new Cairo.PointD(p1.X + p2.X, p1.Y + p2.Y); } diff --git a/src/Rectangle.cs b/src/Rectangle.cs index 8f48d06d..56e4148f 100644 --- a/src/Rectangle.cs +++ b/src/Rectangle.cs @@ -124,6 +124,14 @@ namespace Crow { Inflate (delta, delta); } + public Rectangle Inflated (int delta) { + return Inflated (delta,delta); + } + public Rectangle Inflated (int deltaX, int deltaY) { + Rectangle r = this; + r.Inflate (deltaX, deltaY); + return r; + } public bool ContainsOrIsEqual(Point p) { return (p.X >= X && p.X <= X + Width && p.Y >= Y && p.Y <= Y + Height) ? -- cgit v1.3.1-4-g156e