From 881b57d359150acb59fce00d2f2133d267d5ac90 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Mon, 15 Aug 2016 20:54:15 +0200 Subject: [PATCH] iml source handling, mouse hover in imlVE --- CrowIDE/CrowIDE.csproj | 3 + CrowIDE/images/save.svg | 3421 +++++++++++++++++++++++++++ CrowIDE/src/CrowIDE.cs | 5 +- CrowIDE/src/ImlVisualEditor.cs | 129 +- CrowIDE/ui/IDE.style | 9 + CrowIDE/ui/imlEditor.crow | 10 +- src/GraphicObjects/GraphicObject.cs | 2 +- src/IMLReader.cs | 6 - 8 files changed, 3551 insertions(+), 34 deletions(-) create mode 100644 CrowIDE/images/save.svg create mode 100644 CrowIDE/ui/IDE.style diff --git a/CrowIDE/CrowIDE.csproj b/CrowIDE/CrowIDE.csproj index ce7149d6..6a3a9139 100644 --- a/CrowIDE/CrowIDE.csproj +++ b/CrowIDE/CrowIDE.csproj @@ -79,9 +79,12 @@ + + + diff --git a/CrowIDE/images/save.svg b/CrowIDE/images/save.svg new file mode 100644 index 00000000..7bdc5518 --- /dev/null +++ b/CrowIDE/images/save.svg @@ -0,0 +1,3421 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CrowIDE/src/CrowIDE.cs b/CrowIDE/src/CrowIDE.cs index 221de0e5..72ad48ad 100644 --- a/CrowIDE/src/CrowIDE.cs +++ b/CrowIDE/src/CrowIDE.cs @@ -36,7 +36,7 @@ namespace CrowIDE } public CrowIDE () - : base(800, 600,"UIEditor") + : base(1024, 800,"UIEditor") { } @@ -49,5 +49,8 @@ namespace CrowIDE GraphicObject go = this.CrowInterface.LoadInterface (@"#CrowIDE.ui.imlEditor.crow"); go.DataSource = this; } + protected void onCommandSave(object sender, MouseButtonEventArgs e){ + System.Diagnostics.Debug.WriteLine("save"); + } } } \ No newline at end of file diff --git a/CrowIDE/src/ImlVisualEditor.cs b/CrowIDE/src/ImlVisualEditor.cs index 80d325a1..6bcdb754 100644 --- a/CrowIDE/src/ImlVisualEditor.cs +++ b/CrowIDE/src/ImlVisualEditor.cs @@ -29,26 +29,92 @@ namespace CrowIDE { public class ImlVisualEditor : GraphicObject { + #region CTOR + public ImlVisualEditor () : base() + { + imlVE = new Interface (); + Thread t = new Thread (interfaceThread); + t.IsBackground = true; + t.Start (); + } + #endregion + string imlPath; Interface imlVE; + Instantiator itor; + string imlSource; + + bool drawGrid; + int gridSpacing; + + [XmlIgnore]public string ImlSource { + get { return imlSource; } + set { + if (imlSource == value) + return; + imlSource = value; + + NotifyValueChanged ("ImlSource", ImlSource); + + reloadFromSource (); + } + } [XmlAttributeAttribute][DefaultValue("")] - public virtual string ImlPath { + public string ImlPath { get { return imlPath; } set { if (imlPath == value) return; - if (!File.Exists (value)) - return; + imlPath = value; + NotifyValueChanged ("ImlPath", imlPath); - imlVE.ClearInterface (); - imlVE.LoadInterface (imlPath); + + reloadFromPath (); + } + } + void reloadFromSource(){ + if (string.IsNullOrEmpty (imlSource)) { + reload_iTor (null); + return; + } + + Instantiator iTmp; + try { + iTmp = Instantiator.CreateFromImlFragment (imlSource); + } catch (Exception ex) { + System.Diagnostics.Debug.WriteLine (ex.ToString()); + return; + } + + reload_iTor (iTmp); + } + void reloadFromPath(){ + if (!File.Exists (imlPath)){ + System.Diagnostics.Debug.WriteLine ("Path not found: " + imlPath); + reload_iTor (null); + return; + } + using (StreamReader sr = new StreamReader (imlPath)) { + ImlSource = sr.ReadToEnd (); + } + } + void reload_iTor(Instantiator new_iTot){ + itor = new_iTot; + lock (imlVE.UpdateMutex) { + try { + imlVE.ClearInterface (); + if (itor != null) + imlVE.AddWidget(itor.CreateInstance(imlVE)); + + } catch (Exception ex) { + System.Diagnostics.Debug.WriteLine (ex.ToString()); + } } } - bool drawGrid; [XmlAttributeAttribute()][DefaultValue(true)] - public virtual bool DrawGrid { + public bool DrawGrid { get { return drawGrid; } set { if (drawGrid == value) @@ -58,9 +124,8 @@ namespace CrowIDE RegisterForRedraw (); } } - int gridSpacing; [XmlAttributeAttribute()][DefaultValue(10)] - public virtual int GridSpacing { + public int GridSpacing { get { return gridSpacing; } set { if (gridSpacing == value) @@ -81,14 +146,21 @@ namespace CrowIDE void interfaceThread() { while (true) { - imlVE.Update (); + try { + imlVE.Update (); + } catch (Exception ex) { + System.Diagnostics.Debug.WriteLine (ex.ToString ()); + if (Monitor.IsEntered(imlVE.UpdateMutex)) + Monitor.Exit (imlVE.UpdateMutex); + } + bool isDirty = false; lock (imlVE.RenderMutex) isDirty = imlVE.IsDirty; - if (imlVE.IsDirty) { + if (isDirty) { lock (CurrentInterface.UpdateMutex) RegisterForRedraw (); } @@ -96,6 +168,8 @@ namespace CrowIDE Thread.Sleep (5); } } + + #region GraphicObject overrides public override void OnLayoutChanges (LayoutingType layoutType) { base.OnLayoutChanges (layoutType); @@ -106,11 +180,14 @@ namespace CrowIDE break; } } - public override void RegisterForRedraw () + public override void onMouseMove (object sender, MouseMoveEventArgs e) { - base.RegisterForRedraw (); - lock(imlVE.UpdateMutex) - imlVE.clipping.AddRectangle (imlVE.ClientRectangle); + base.onMouseMove (sender, e); + GraphicObject oldHW = imlVE.HoverWidget; + Rectangle scr = this.ScreenCoordinates (this.getSlot ()); + imlVE.ProcessMouseMove (e.X - scr.X, e.Y - scr.Y); + if (oldHW != imlVE.HoverWidget) + RegisterForRedraw (); } protected override void onDraw (Cairo.Context gr) { @@ -141,15 +218,23 @@ namespace CrowIDE gr.Stroke (); lock (imlVE.RenderMutex) { - if (imlVE.IsDirty) { - using (Cairo.Surface surf = new Cairo.ImageSurface (imlVE.dirtyBmp, Cairo.Format.Argb32, - imlVE.DirtyRect.Width, imlVE.DirtyRect.Height, imlVE.DirtyRect.Width * 4)) { - gr.SetSourceSurface (surf, imlVE.DirtyRect.Left, imlVE.DirtyRect.Top); - gr.Paint (); - } - imlVE.IsDirty = false; + using (Cairo.Surface surf = new Cairo.ImageSurface (imlVE.bmp, Cairo.Format.Argb32, + imlVE.ClientRectangle.Width, imlVE.ClientRectangle.Height, imlVE.ClientRectangle.Width * 4)) { + gr.SetSourceSurface (surf, cb.Left, cb.Top); + gr.Paint (); } + imlVE.IsDirty = false; } + + if (imlVE.HoverWidget == null) + return; + + Rectangle hr = imlVE.HoverWidget.ScreenCoordinates(imlVE.HoverWidget.getSlot ()); + hr.Inflate (2); + gr.SetSourceColor (Color.LightGray); + gr.SetDash (new double[]{ 3.0, 3.0 },0.0); + gr.Rectangle (hr, 1.0); } + #endregion } } diff --git a/CrowIDE/ui/IDE.style b/CrowIDE/ui/IDE.style new file mode 100644 index 00000000..5d39b25f --- /dev/null +++ b/CrowIDE/ui/IDE.style @@ -0,0 +1,9 @@ +icon { + Focusable=true; + Width=32; + Height=32; + Margin=2; + CornerRadius=5; + MouseEnter = {Background=UnitedNationsBlue;} + MouseLeave = {Background=Transparent;} +} diff --git a/CrowIDE/ui/imlEditor.crow b/CrowIDE/ui/imlEditor.crow index 3a8e5204..e08c2efe 100644 --- a/CrowIDE/ui/imlEditor.crow +++ b/CrowIDE/ui/imlEditor.crow @@ -1,6 +1,9 @@  - + + + + @@ -8,7 +11,7 @@ - + @@ -20,8 +23,7 @@ + Text="{²../../../crowContainer.ImlSource}" Multiline="true"/> query an update of the content, a redraw [MethodImpl(MethodImplOptions.AggressiveInlining)] - public virtual void RegisterForRedraw () + public void RegisterForRedraw () { bmp = null; if (RegisteredLayoutings == LayoutingType.None) diff --git a/src/IMLReader.cs b/src/IMLReader.cs index 922a48d7..7d87a66d 100644 --- a/src/IMLReader.cs +++ b/src/IMLReader.cs @@ -31,10 +31,6 @@ namespace Crow public class IMLReader : XmlTextReader { InstanciatorInvoker loader = null; - - string ImlPath; - Stream ImlStream; - DynamicMethod dm = null; public ILGenerator il = null; @@ -55,12 +51,10 @@ namespace Crow #region CTOR public IMLReader (string path) : this(Interface.GetStreamFromPath (path)){ - ImlPath = path; } public IMLReader (Stream stream) : base(stream) { - ImlStream = stream; createInstantiator (); } /// -- 2.47.3