diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2018-12-04 14:09:07 +0100 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2018-12-04 14:09:07 +0100 |
| commit | 9d381671ec0b1266448eddbf4c4935cdc7d23a9f (patch) | |
| tree | 34e9b4b0296eea8dba03024491934413bcd54083 /src/GraphicObjects | |
| parent | a64627699d4919d389522d92032ce4f05704d313 (diff) | |
docking save/restore; use image surfaces as cache for graphic object instead of backend similar which blink too much
Diffstat (limited to 'src/GraphicObjects')
| -rw-r--r-- | src/GraphicObjects/DockStack.cs | 96 | ||||
| -rw-r--r-- | src/GraphicObjects/DockWindow.cs | 11 | ||||
| -rw-r--r-- | src/GraphicObjects/GenericStack.cs | 6 | ||||
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 36 | ||||
| -rw-r--r-- | src/GraphicObjects/Group.cs | 6 | ||||
| -rw-r--r-- | src/GraphicObjects/Image.cs | 2 | ||||
| -rw-r--r-- | src/GraphicObjects/Menu.cs | 11 | ||||
| -rw-r--r-- | src/GraphicObjects/MenuItem.cs | 12 | ||||
| -rw-r--r-- | src/GraphicObjects/TextBox.cs | 48 |
9 files changed, 177 insertions, 51 deletions
diff --git a/src/GraphicObjects/DockStack.cs b/src/GraphicObjects/DockStack.cs index f2174024..aa7c33da 100644 --- a/src/GraphicObjects/DockStack.cs +++ b/src/GraphicObjects/DockStack.cs @@ -26,6 +26,8 @@ using System; using Crow.IML; using System.Linq; +using System.Text; +using System.IO; namespace Crow { @@ -369,6 +371,100 @@ namespace Crow if (dw != null) dw.DockingPosition = (Orientation == Orientation.Horizontal ? Alignment.Right : Alignment.Bottom); } + + //read next value in config string until next ';' + string getConfAttrib (string conf, ref int i) { + int nextI = conf.Substring (i).IndexOf (';'); + string tmp = conf.Substring (i, nextI); + i += nextI + 1; + return tmp; + } + /// <summary> + /// Imports the config. + /// </summary> + /// <param name="conf">Conf.</param> + /// <param name="dataSource">Data source for the docked windows</param> + public void ImportConfig (string conf, object dataSource = null) { + lock (IFace.UpdateMutex) { + ClearChildren (); + stretchedChild = null; + int i = 0; + Orientation = (Orientation)Enum.Parse (typeof(Orientation), getConfAttrib (conf, ref i)); + importConfig (conf, ref i, dataSource); + } + } + public string ExportConfig () { + return Orientation.ToString() + ";" + exportConfig(); + } + void importConfig (string conf, ref int i, object dataSource) { + if (conf [i++] != '(') + return; + while (i < conf.Length - 4) { + string sc = conf.Substring (i, 4); + i += 4; + switch (sc) { + case "WIN;": + DockWindow dw = null; + string wName = getConfAttrib (conf, ref i); + try { + dw = IFace.Load (wName) as DockWindow; + } catch { + dw = new DockWindow (IFace); + } + + dw.Name = wName; + dw.Width = Measure.Parse (getConfAttrib (conf, ref i)); + dw.Height = Measure.Parse (getConfAttrib (conf, ref i)); + dw.DockingPosition = (Alignment)Enum.Parse (typeof(Alignment), getConfAttrib (conf, ref i)); + dw.IsDocked = true; + dw.DataSource = dataSource; + this.AddChild (dw); + + break; + case "STK;": + DockStack ds = new DockStack (IFace); + ds.Width = Measure.Parse (getConfAttrib (conf, ref i)); + ds.Height = Measure.Parse (getConfAttrib (conf, ref i)); + ds.Orientation = (Orientation)Enum.Parse (typeof(Orientation), getConfAttrib (conf, ref i)); + + this.AddChild (ds); + + ds.importConfig (conf, ref i, dataSource); + break; + case "SPL;": + Splitter sp = new Splitter (IFace); + sp.Width = Measure.Parse (getConfAttrib (conf, ref i)); + sp.Height = Measure.Parse (getConfAttrib (conf, ref i)); + sp.Thickness = int.Parse (getConfAttrib (conf, ref i)); + this.AddChild (sp); + break; + } + char nextC = conf [i++]; + if (nextC == ')') + break; + } + } + string exportConfig () { + StringBuilder tmp = new StringBuilder("("); + + for (int i = 0; i < Children.Count; i++) { + if (Children [i] is DockWindow) { + DockWindow dw = Children [i] as DockWindow; + tmp.Append (string.Format("WIN;{0};{1};{2};{3};",dw.Name, dw.Width, dw.Height, dw.DockingPosition)); + } else if (Children [i] is DockStack) { + DockStack ds = Children [i] as DockStack; + tmp.Append (string.Format("STK;{0};{1};{2};{3}", ds.Width, ds.Height, ds.Orientation, ds.exportConfig())); + } else if (Children [i] is Splitter) { + Splitter sp = Children [i] as Splitter; + tmp.Append (string.Format("SPL;{0};{1};{2};", sp.Width, sp.Height, sp.Thickness)); + } + if (i < Children.Count - 1) + tmp.Append ("|"); + } + + tmp.Append (")"); + return tmp.ToString (); + } } } diff --git a/src/GraphicObjects/DockWindow.cs b/src/GraphicObjects/DockWindow.cs index 1ae3b0b4..d6385057 100644 --- a/src/GraphicObjects/DockWindow.cs +++ b/src/GraphicObjects/DockWindow.cs @@ -31,12 +31,11 @@ namespace Crow public class DockWindow : Window { #region CTOR - public DockWindow () : base () - { - } + public DockWindow () {} + public DockWindow (Interface iface) : base (iface) {} #endregion - int undockThreshold = 4; + int undockThreshold = 10; bool isDocked = false; Alignment docking = Alignment.Undefined; @@ -170,10 +169,6 @@ namespace Crow Undock (); base.close (); } - - public string ExportWinConfigs () { - return string.Format ("{0};{1};{2}", this.Name, DockingPosition, savedSlot); - } } } diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index 64841d4b..f281311c 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -242,5 +242,11 @@ namespace Crow else adjustStretchedGo (LayoutingType.Height); } + + public override void ClearChildren () + { + base.ClearChildren (); + stretchedGO = null; + } } } diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 2bf20f27..747609b0 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -945,11 +945,17 @@ namespace Crow if (value != null) rootDataLevel = true; - + + #if DEBUG_LOG + DbgEvent dbgEvt = DebugLog.AddEvent(DbgEvtType.GOLockLayouting, this); + #endif lock (IFace.LayoutMutex) { OnDataSourceChanged (this, dse); NotifyValueChanged ("DataSource", DataSource); } + #if DEBUG_LOG + dbgEvt.end = DebugLog.chrono.ElapsedTicks; + #endif } get { return rootDataLevel ? dataSource : dataSource == null ? @@ -1358,8 +1364,13 @@ namespace Crow public virtual void RegisterClip(Rectangle clip){ #if DEBUG_LOG DbgEvent dbgEvt = DebugLog.AddEvent(DbgEvtType.GORegisterClip, this); - #endif - Rectangle r = clip + ClientRectangle.Position; + #endif + Rectangle cb = ClientRectangle; + Rectangle r = clip + cb.Position; + if (r.Right > cb.Right) + r.Width -= r.Right - cb.Right; + if (r.Bottom > cb.Bottom) + r.Height -= r.Bottom - cb.Bottom; if (CacheEnabled && !IsDirty) Clipping.UnionRectangle (r); if (Parent == null) @@ -1372,7 +1383,7 @@ namespace Crow dbgEvt.end = DebugLog.chrono.ElapsedTicks; #endif } - /// <summary> Full update, taking care of sizing policy </summary> + /// <summary> Full update, content and layouting, taking care of sizing policy </summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RegisterForGraphicUpdate () { @@ -1382,7 +1393,7 @@ namespace Crow else if (RegisteredLayoutings == LayoutingType.None) IFace.EnqueueForRepaint (this); } - /// <summary> query an update of the content, a redraw </summary> + /// <summary> query an update of the content without layouting changes</summary> [MethodImpl(MethodImplOptions.AggressiveInlining)] public void RegisterForRedraw () { @@ -1641,14 +1652,21 @@ namespace Crow #if DEBUG_LOG DbgEvent dbgEvt = DebugLog.AddEvent(DbgEvtType.GORecreateCache, this); #endif - IsDirty = false; + + /*if (bmp == null) + bmp = IFace.surf.CreateSimilar (Content.ColorAlpha, Slot.Width, Slot.Height); + else if (LastPaintedSlot.Width != Slot.Width || LastPaintedSlot.Height != Slot.Height) + bmp.SetSize (Slot.Width, Slot.Height);*/ bmp?.Dispose (); - bmp = IFace.surf.CreateSimilar(Content.ColorAlpha, Slot.Width, Slot.Height); + bmp = new ImageSurface(Format.Argb32, Slot.Width, Slot.Height); + using (Context gr = new Context (bmp)) { gr.Antialias = Interface.Antialias; onDraw (gr); } - bmp.Flush (); + + IsDirty = false; + #if DEBUG_LOG dbgEvt.end = DebugLog.chrono.ElapsedTicks; #endif @@ -1657,6 +1675,7 @@ namespace Crow #if DEBUG_LOG DbgEvent dbgEvt = DebugLog.AddEvent(DbgEvtType.GOUpdateCacheAndPaintOnCTX, this); #endif + Rectangle rb = Slot + Parent.ClientRectangle.Position; if (clearBackground) { ctx.Save (); @@ -1665,6 +1684,7 @@ namespace Crow ctx.Fill (); ctx.Restore (); } + ctx.SetSourceSurface (bmp, rb.X, rb.Y); ctx.Paint (); Clipping.Dispose (); diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index a90947a5..ece1f090 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -340,7 +340,11 @@ namespace Crow childrenRWLock.ExitReadLock (); #if DEBUG_CLIP_RECTANGLE - Clipping.stroke (gr, Color.Amaranth.AdjustAlpha (0.8)); + /*gr.LineWidth = 1; + gr.SetSourceColor(Color.DarkMagenta.AdjustAlpha (0.8)); + for (int i = 0; i < Clipping.NumRectangles; i++) + gr.Rectangle(Clipping.GetRectangle(i)); + gr.Stroke ();*/ #endif } gr.Dispose (); diff --git a/src/GraphicObjects/Image.cs b/src/GraphicObjects/Image.cs index e83183c0..5960101a 100644 --- a/src/GraphicObjects/Image.cs +++ b/src/GraphicObjects/Image.cs @@ -173,7 +173,7 @@ namespace Crow else pic = new BmpPicture (path); - pic.Load (IFace, path); + pic.Scaled = scaled; pic.KeepProportions = keepProps; diff --git a/src/GraphicObjects/Menu.cs b/src/GraphicObjects/Menu.cs index dbc1d636..0ddb8eae 100644 --- a/src/GraphicObjects/Menu.cs +++ b/src/GraphicObjects/Menu.cs @@ -51,10 +51,15 @@ namespace Crow NotifyValueChanged ("Orientation", orientation); } } - [XmlIgnore]public bool AutomaticOpenning + [XmlIgnore]public bool AutomaticOpening { get { return autoOpen; } - set { autoOpen = value; } + set { + if (autoOpen == value) + return; + autoOpen = value; + NotifyValueChanged ("AutomaticOpening", autoOpen); + } } #endregion @@ -70,7 +75,7 @@ namespace Crow public override void onMouseLeave (object sender, MouseMoveEventArgs e) { base.onMouseLeave (sender, e); - AutomaticOpenning = false; + AutomaticOpening = false; } } } diff --git a/src/GraphicObjects/MenuItem.cs b/src/GraphicObjects/MenuItem.cs index 47bd978f..3b25a9fe 100644 --- a/src/GraphicObjects/MenuItem.cs +++ b/src/GraphicObjects/MenuItem.cs @@ -46,7 +46,7 @@ namespace Crow Measure popWidth, popHeight; #region Public properties - [XmlAttributeAttribute][DefaultValue(false)] + [DefaultValue(false)] public bool IsOpened { get { return isOpened; } set { @@ -58,12 +58,12 @@ namespace Crow if (isOpened) { onOpen (this, null); if (LogicalParent is Menu) - (LogicalParent as Menu).AutomaticOpenning = true; + (LogicalParent as Menu).AutomaticOpening = true; }else onClose (this, null); } } - [XmlAttributeAttribute][DefaultValue(null)] + [DefaultValue(null)] public virtual Command Command { get { return command; } set { @@ -148,7 +148,7 @@ namespace Crow closeMenu (); } if(!IsOpened) - (LogicalParent as Menu).AutomaticOpenning = false; + (LogicalParent as Menu).AutomaticOpening = false; } protected virtual void onOpen (object sender, EventArgs e){ Open.Raise (this, null); @@ -167,7 +167,7 @@ namespace Crow Menu menu = LogicalParent as Menu; if (menu == null) return; - if (menu.AutomaticOpenning && items.Children.Count>0) + if (menu.AutomaticOpening && items.Children.Count>0) IsOpened = true; } public override void onMouseLeave (object sender, MouseMoveEventArgs e) @@ -181,6 +181,8 @@ namespace Crow MenuItem tmp = LogicalParent as MenuItem; while (tmp != null) { tmp.IsOpened = false; + tmp.Background = Color.Transparent; + tmp.AutomaticOpening = false; tmp = tmp.LogicalParent as MenuItem; } } diff --git a/src/GraphicObjects/TextBox.cs b/src/GraphicObjects/TextBox.cs index 7d14f800..5da67e31 100644 --- a/src/GraphicObjects/TextBox.cs +++ b/src/GraphicObjects/TextBox.cs @@ -69,7 +69,7 @@ namespace Crow public override void onKeyDown (object sender, KeyEventArgs e) { base.onKeyDown (sender, e); - /* + Key key = e.Key; switch (key) @@ -85,12 +85,12 @@ namespace Crow if (selectionIsEmpty) { if (!MoveRight ()) return; - }else if (e.Shift) + }else if (IFace.Keyboard.Shift) IFace.Clipboard = this.SelectedText; this.DeleteChar (); break; - case Key.ISO_Enter: case Key.KP_Enter: + case Key.Return: if (!selectionIsEmpty) this.DeleteChar (); if (Multiline) @@ -104,46 +104,46 @@ namespace Crow SelRelease = -1; break; case Key.Home: - if (e.Shift) { + if (IFace.Keyboard.Shift) { if (selectionIsEmpty) SelBegin = new Point (CurrentColumn, CurrentLine); - if (e.Control) + if (IFace.Keyboard.Ctrl) CurrentLine = 0; CurrentColumn = 0; SelRelease = new Point (CurrentColumn, CurrentLine); break; } SelRelease = -1; - if (e.Control) + if (IFace.Keyboard.Ctrl) CurrentLine = 0; CurrentColumn = 0; break; case Key.End: - if (e.Shift) { + if (IFace.Keyboard.Shift) { if (selectionIsEmpty) SelBegin = CurrentPosition; - if (e.Control) + if (IFace.Keyboard.Ctrl) CurrentLine = int.MaxValue; CurrentColumn = int.MaxValue; SelRelease = CurrentPosition; break; } SelRelease = -1; - if (e.Control) + if (IFace.Keyboard.Ctrl) CurrentLine = int.MaxValue; CurrentColumn = int.MaxValue; break; case Key.Insert: - if (e.Shift) + if (IFace.Keyboard.Shift) this.Insert (IFace.Clipboard); - else if (e.Control && !selectionIsEmpty) + else if (IFace.Keyboard.Ctrl && !selectionIsEmpty) IFace.Clipboard = this.SelectedText; break; case Key.Left: - if (e.Shift) { + if (IFace.Keyboard.Shift) { if (selectionIsEmpty) SelBegin = new Point(CurrentColumn, CurrentLine); - if (e.Control) + if (IFace.Keyboard.Ctrl) GotoWordStart (); else if (!MoveLeft ()) return; @@ -151,16 +151,16 @@ namespace Crow break; } SelRelease = -1; - if (e.Control) + if (IFace.Keyboard.Ctrl) GotoWordStart (); else MoveLeft(); break; case Key.Right: - if (e.Shift) { + if (IFace.Keyboard.Shift) { if (selectionIsEmpty) SelBegin = CurrentPosition; - if (e.Control) + if (IFace.Keyboard.Ctrl) GotoWordEnd (); else if (!MoveRight ()) return; @@ -168,13 +168,13 @@ namespace Crow break; } SelRelease = -1; - if (e.Control) + if (IFace.Keyboard.Ctrl) GotoWordEnd (); else MoveRight (); break; case Key.Up: - if (e.Shift) { + if (IFace.Keyboard.Shift) { if (selectionIsEmpty) SelBegin = CurrentPosition; CurrentLine--; @@ -185,7 +185,7 @@ namespace Crow CurrentLine--; break; case Key.Down: - if (e.Shift) { + if (IFace.Keyboard.Shift) { if (selectionIsEmpty) SelBegin = CurrentPosition; CurrentLine++; @@ -197,13 +197,11 @@ namespace Crow break; case Key.Menu: break; - case Key.NumLock: - break; - case Key.PageDown: + case Key.Num_Lock: break; - case Key.PageUp: + case Key.Page_Down: break; - case Key.RWin: + case Key.Page_Up: break; case Key.Tab: this.Insert ("\t"); @@ -211,7 +209,7 @@ namespace Crow default: break; } - */ + RegisterForGraphicUpdate(); } public override void onKeyPress (object sender, KeyPressEventArgs e) |