From 4b80bdeb898a851011b6284b5e91be5750e4591f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Sun, 17 Jul 2022 20:24:27 +0200 Subject: [PATCH] update to Crow 1 with Backends --- CrowEditBase/CrowEditBase.csproj | 8 ++-- CrowEditBase/src/Compiler/SourceDocument.cs | 3 +- CrowEditBase/src/CrowEditBase.cs | 21 +++++++++- CrowEditBase/src/Editor.cs | 34 +++++++++------- CrowEditBase/src/LogViewerWidget.cs | 17 +++----- CrowEditBase/src/Plugin.cs | 11 +++++- CrowEditBase/src/SourceEditor.cs | 19 +++++---- CrowEditBase/ui/slider.tmp | 11 ++++++ plugins/CECrowPlugin/default.conf | 1 + plugins/CECrowPlugin/src/CrowService.cs | 35 ++++++++++------- plugins/CECrowPlugin/src/DbgEventWidget.cs | 6 +-- plugins/CECrowPlugin/src/DbgLogViewer.cs | 29 +++++++------- plugins/CECrowPlugin/src/DebugInterface.cs | 39 +++++++++---------- .../CECrowPlugin/src/DebugInterfaceWidget.cs | 20 +++++----- plugins/CECrowPlugin/src/ImlDocument.cs | 1 + plugins/CECrowPlugin/src/StyleDocument.cs | 1 + plugins/CERoslynPlugin/default.conf | 1 + plugins/CERoslynPlugin/src/CSTokenizer.cs | 10 ++--- plugins/CERoslynPlugin/src/RoslynService.cs | 16 +++++--- .../CEXmlPlugin/src/Parsing/XmlDocument.cs | 9 +---- src/CrowEdit.cs | 5 ++- ui/EditorOptions.crow | 6 +++ 22 files changed, 183 insertions(+), 120 deletions(-) create mode 100644 CrowEditBase/ui/slider.tmp diff --git a/CrowEditBase/CrowEditBase.csproj b/CrowEditBase/CrowEditBase.csproj index 26dd958..d388caf 100644 --- a/CrowEditBase/CrowEditBase.csproj +++ b/CrowEditBase/CrowEditBase.csproj @@ -7,15 +7,17 @@ - + ui.%(Filename)%(Extension) - + icons.%(Filename)%(Extension) - + + diff --git a/CrowEditBase/src/Compiler/SourceDocument.cs b/CrowEditBase/src/Compiler/SourceDocument.cs index 2f092b6..40b0773 100644 --- a/CrowEditBase/src/Compiler/SourceDocument.cs +++ b/CrowEditBase/src/Compiler/SourceDocument.cs @@ -8,6 +8,7 @@ using Crow.Text; using System.Diagnostics; using System.Collections; using System.Collections.Generic; +using Drawing2D; namespace CrowEditBase { @@ -143,7 +144,7 @@ namespace CrowEditBase } } - public virtual Crow.Color GetColorForToken (TokenType tokType) { + public virtual Color GetColorForToken (TokenType tokType) { if (tokType.HasFlag (TokenType.Punctuation)) return Colors.DarkGrey; if (tokType.HasFlag (TokenType.Trivia)) diff --git a/CrowEditBase/src/CrowEditBase.cs b/CrowEditBase/src/CrowEditBase.cs index a8caa2b..d18e5a5 100644 --- a/CrowEditBase/src/CrowEditBase.cs +++ b/CrowEditBase/src/CrowEditBase.cs @@ -10,6 +10,7 @@ using System.Runtime.CompilerServices; using System.Collections.Generic; using System.Runtime.Loader; using System.Text; +using Drawing2D; namespace CrowEditBase { @@ -58,7 +59,7 @@ namespace CrowEditBase public static CrowEditBase App; - public CrowEditBase (int width, int height) : base (width, height) { + public CrowEditBase (int width, int height) : base (width, height, true) { App = this; } @@ -352,6 +353,24 @@ namespace CrowEditBase #region main options + public int CrowUpdateInterval { + get => Crow.Interface.UPDATE_INTERVAL; + set { + if (Crow.Interface.UPDATE_INTERVAL == value) + return; + Crow.Interface.UPDATE_INTERVAL = value; + NotifyValueChanged (Crow.Interface.UPDATE_INTERVAL); + } + } + public int CrowPollingInterval { + get => Crow.Interface.POLLING_INTERVAL; + set { + if (Crow.Interface.POLLING_INTERVAL == value) + return; + Crow.Interface.POLLING_INTERVAL = value; + NotifyValueChanged (Crow.Interface.POLLING_INTERVAL); + } + } public virtual Color MarginBackground { get => Configuration.Global.Get ("MarginBackground", Colors.Onyx); set { diff --git a/CrowEditBase/src/Editor.cs b/CrowEditBase/src/Editor.cs index b1ca568..f00adfb 100644 --- a/CrowEditBase/src/Editor.cs +++ b/CrowEditBase/src/Editor.cs @@ -6,7 +6,7 @@ using System; using Glfw; using Crow.Text; using System.Collections.Generic; -using Crow.Drawing; +using Drawing2D; using System.Linq; using CrowEditBase; using System.Threading; @@ -268,7 +268,7 @@ namespace Crow /// protected virtual int visualLineCount => document.LinesCount; - protected virtual void measureTextBounds (Context gr) { + protected virtual void measureTextBounds (IContext gr) { fe = gr.FontExtents; te = new TextExtents (); @@ -301,7 +301,7 @@ namespace Crow document.ExitReadLock (); } } - protected virtual void drawContent (Context gr) { + protected virtual void drawContent (IContext gr) { gr.Translate (-ScrollX, -ScrollY); Rectangle cb = ClientRectangle; @@ -358,7 +358,7 @@ namespace Crow if (bytes.Length < size) bytes = size > 512 ? new byte[size] : stackalloc byte[size]; - encodedBytes = Crow.Text.Encoding.ToUtf8 (document.GetText (l), bytes); + encodedBytes = document.GetText (l).ToUtf8 (bytes); bytes[encodedBytes++] = 0; if (l.LengthInPixel < 0) { @@ -442,21 +442,23 @@ namespace Crow NotifyValueChanged("VisibleLines", visibleLines); NotifyValueChanged("HoverLine", hoverLine); hoverLoc = new CharLocation (hoverLine, -1, mouseLocalPos.X + ScrollX); - using (Context gr = new Context (IFace.surf)) { - setFontForContext (gr); + using (IContext gr = IFace.Backend.CreateContext (IFace.MainSurface)) { + gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); + gr.SetFontSize (Font.Size); updateLocation (gr, ClientRectangle.Width, ref hoverLoc); } } protected virtual bool cancelLinePrint (double lineHeght, double y, int clientHeight) => false; RectangleD? textCursor = null; - public virtual bool DrawCursor (Context ctx, out Rectangle rect) { + public virtual bool DrawCursor (IContext ctx, out Rectangle rect) { if (CurrentLoc == null) { rect = default; return false; } if (!CurrentLoc.Value.HasVisualX) { - setFontForContext (ctx); + ctx.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); + ctx.SetFontSize (Font.Size); if (currentLoc?.Column < 0) { updateLocation (ctx, ClientRectangle.Width, ref currentLoc); @@ -486,7 +488,7 @@ namespace Crow return true; } - protected void updateLocation (Context gr, int clientWidth, ref CharLocation? location) { + protected void updateLocation (IContext gr, int clientWidth, ref CharLocation? location) { if (location == null) return; CharLocation loc = location.Value; @@ -512,7 +514,7 @@ namespace Crow Span bytes = stackalloc byte[5];//utf8 single char buffer + '\0' for (int i = 0; i < ls.Length; i++) { - int encodedBytes = Crow.Text.Encoding.ToUtf8 (curLine.Slice (i, 1), bytes); + int encodedBytes = curLine.Slice (i, 1).ToUtf8 (bytes); bytes[encodedBytes] = 0; gr.TextExtents (bytes, out te); @@ -563,8 +565,9 @@ namespace Crow DbgLogger.StartEvent(DbgEvtType.GOMeasure, this, lt); try { if (!textMeasureIsUpToDate) { - using (Context gr = new Context (IFace.surf)) { - setFontForContext (gr); + using (IContext gr = IFace.Backend.CreateContext (IFace.MainSurface)) { + gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); + gr.SetFontSize (Font.Size); measureTextBounds (gr); } } @@ -573,15 +576,16 @@ namespace Crow DbgLogger.EndEvent(DbgEvtType.GOMeasure); } } - public override void Paint (Context ctx) { + public override void Paint (IContext ctx) { base.Paint (ctx); IFace.forceTextCursor = true; } - protected override void onDraw (Context gr) + protected override void onDraw (IContext gr) { //base.onDraw (gr); - setFontForContext (gr); + gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); + gr.SetFontSize (Font.Size); if (!textMeasureIsUpToDate) { measureTextBounds (gr); diff --git a/CrowEditBase/src/LogViewerWidget.cs b/CrowEditBase/src/LogViewerWidget.cs index e7d1d74..c63d67e 100644 --- a/CrowEditBase/src/LogViewerWidget.cs +++ b/CrowEditBase/src/LogViewerWidget.cs @@ -6,7 +6,7 @@ using System; using System.Xml.Serialization; using System.ComponentModel; using System.Collections; -using Crow.Drawing; +using Drawing2D; using System.Threading.Tasks; using System.Linq; @@ -254,15 +254,10 @@ namespace Crow base.OnLayoutChanges (layoutType); if (layoutType == LayoutingType.Height) { - using (ImageSurface img = new ImageSurface (Format.Argb32, 10, 10)) { - using (Context gr = new Context (img)) { - //Cairo.FontFace cf = gr.GetContextFontFace (); - - gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); - gr.SetFontSize (Font.Size); - - fe = gr.FontExtents; - } + using (IContext gr = IFace.Backend.CreateContext (IFace.MainSurface)) { + gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); + gr.SetFontSize (Font.Size); + fe = gr.FontExtents; } if (updateFilteredLinesRequest) updateFilteredLines (); @@ -270,7 +265,7 @@ namespace Crow MaxScrollY = filteredLines == null ? 0 : filteredLines.Length - visibleLines; } } - protected override void onDraw (Context gr) + protected override void onDraw (IContext gr) { base.onDraw (gr); diff --git a/CrowEditBase/src/Plugin.cs b/CrowEditBase/src/Plugin.cs index e681c80..55950bd 100644 --- a/CrowEditBase/src/Plugin.cs +++ b/CrowEditBase/src/Plugin.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2021-2021 Jean-Philippe Bruyère +// Copyright (c) 2021-2022 Jean-Philippe Bruyère // // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) @@ -18,6 +18,7 @@ namespace CrowEditBase string FullPath; bool isLoaded; PluginsLoadContext loadContext; + Type serviceClass; public Assembly Load (AssemblyName assemblyName) => loadContext.LoadFromAssemblyName (assemblyName); @@ -68,6 +69,11 @@ namespace CrowEditBase string defaultConfigName = loadContext.MainAssembly.GetManifestResourceNames ().FirstOrDefault(c=>c.EndsWith ("default.conf")); if (!string.IsNullOrEmpty (defaultConfigName)) { Configuration config = new Configuration (loadContext.MainAssembly.GetManifestResourceStream (defaultConfigName)); + string mainService = config.Get ("MainService"); + if (!string.IsNullOrEmpty (mainService)) { + serviceClass = loadContext.MainAssembly.GetType (mainService); + App.GetService (serviceClass)?.Start(); + } string fileAssociations = config.Get ("FileAssociations"); if (!string.IsNullOrEmpty (fileAssociations)) { try @@ -95,6 +101,9 @@ namespace CrowEditBase if (!isLoaded) return; + if (serviceClass != null) + App.GetService (serviceClass)?.Stop(); + App.RemoveCrowAssembly (loadContext.MainAssembly); IsLoaded = false; diff --git a/CrowEditBase/src/SourceEditor.cs b/CrowEditBase/src/SourceEditor.cs index 281a7cd..94b200b 100644 --- a/CrowEditBase/src/SourceEditor.cs +++ b/CrowEditBase/src/SourceEditor.cs @@ -5,7 +5,7 @@ using System; using Glfw; using Crow.Text; -using Crow.Drawing; +using Drawing2D; using System.Collections; using CrowEditBase; using static CrowEditBase.CrowEditBase; @@ -186,8 +186,10 @@ namespace Crow updateMargin (); if (!textMeasureIsUpToDate) { - using (Context gr = new Context (IFace.surf)) { - setFontForContext (gr); + using (IContext gr = IFace.Backend.CreateContext (IFace.MainSurface)) { + gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); + gr.SetFontSize (Font.Size); + measureTextBounds (gr); } } @@ -258,8 +260,9 @@ namespace Crow return; } hoverLoc = new CharLocation (hoverLine, -1, mouseLocalPos.X + ScrollX - leftMargin); - using (Context gr = new Context (IFace.surf)) { - setFontForContext (gr); + using (IContext gr = IFace.Backend.CreateContext (IFace.MainSurface)) { + gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); + gr.SetFontSize (Font.Size); updateLocation (gr, ClientRectangle.Width, ref hoverLoc); } #if DEBUG_NODES @@ -473,7 +476,7 @@ namespace Crow } - protected virtual void fillHighlight (Context gr, int l, CharLocation selStart, CharLocation selEnd, RectangleD selRect, Color color) { + protected virtual void fillHighlight (IContext gr, int l, CharLocation selStart, CharLocation selEnd, RectangleD selRect, Color color) { if (selStart.Line == selEnd.Line) { selRect.X += selStart.VisualCharXPosition; selRect.Width = selEnd.VisualCharXPosition - selStart.VisualCharXPosition; @@ -495,7 +498,7 @@ namespace Crow gr.Operator = Operator.Over; } - protected override void drawContent (Context gr) { + protected override void drawContent (IContext gr) { if (!(Document is SourceDocument doc)) { base.drawContent (gr); return; @@ -642,7 +645,7 @@ namespace Crow if (bytes.Length < size) bytes = size > 512 ? new byte[size] : stackalloc byte[size]; - int encodedBytes = Crow.Text.Encoding.ToUtf8 (buff, bytes); + int encodedBytes = buff.ToUtf8 (bytes); if (encodedBytes > 0) { bytes[encodedBytes++] = 0; diff --git a/CrowEditBase/ui/slider.tmp b/CrowEditBase/ui/slider.tmp new file mode 100644 index 0000000..d60e66c --- /dev/null +++ b/CrowEditBase/ui/slider.tmp @@ -0,0 +1,11 @@ + + diff --git a/plugins/CECrowPlugin/default.conf b/plugins/CECrowPlugin/default.conf index 87b623e..8a67d52 100644 --- a/plugins/CECrowPlugin/default.conf +++ b/plugins/CECrowPlugin/default.conf @@ -1 +1,2 @@ +MainService=Crow.CrowService FileAssociations = CECrowPlugin.ImlDocument:.crow,.iml,.itmp,.template,.tmp:#ui.sourceEditor.itmp;CECrowPlugin.Style.StyleDocument:.style:#ui.sourceEditor.itmp diff --git a/plugins/CECrowPlugin/src/CrowService.cs b/plugins/CECrowPlugin/src/CrowService.cs index 3d93ee3..62b2753 100644 --- a/plugins/CECrowPlugin/src/CrowService.cs +++ b/plugins/CECrowPlugin/src/CrowService.cs @@ -7,7 +7,6 @@ using Glfw; using System.Reflection; using System.Runtime.Loader; using System.IO; -using Crow.Drawing; using System.Diagnostics; using System.Collections.Generic; using Crow.DebugLogger; @@ -18,6 +17,7 @@ using Crow.Text; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using static CrowEditBase.CrowEditBase; +using Drawing2D; namespace Crow { @@ -93,10 +93,12 @@ namespace Crow } ); + public ActionCommand CMDViewPreview; + void initCommands () { - App.ViewCommands.Add ( - new ActionCommand("Crow Preview", () => App.LoadWindow ("#CECrowPlugin.ui.winCrowPreview.crow", App))); + CMDViewPreview = new ActionCommand("Crow Preview", () => App.LoadWindow ("#CECrowPlugin.ui.winCrowPreview.crow", App)); + CMDRefresh = new ActionCommand ("Refresh", refresh, "#icons.refresh.svg", IsRunning); CMDStartRecording = new ActionCommand ("Start Recording", () => Recording = true, "#icons.circle.svg", false); CMDStopRecording = new ActionCommand ("Stop Recording", stopRecording, "#icons.circle-red.svg", false); @@ -129,14 +131,14 @@ namespace Crow FieldInfo fiDbgIFace_IsDirty; Action delResetDebugger; Action delSaveDebugLog; - Func delGetSurfacePointer; + Func delGetMainSurface; Action delSetSource; Action delReloadIml; Func delGetZoomFactor; Action delSetZoomFactor; - FieldInfo fiDbg_IncludeEvents, fiDbg_DiscardEvents, fiDbg_ConsoleOutput, fiDbgIFace_MaxLayoutingTries, fiDbgIFace_MaxDiscardCount; + FieldInfo fiDbg_IncludeEvents, fiDbg_DiscardEvents, fiDbg_ConsoleOutput, fiDbgIFace_MaxLayoutingTries, fiDbgIFace_MaxDiscardCount, fiDbgIFace_Terminate; #endregion bool recording, debugLogIsEnabled; @@ -293,7 +295,7 @@ namespace Crow foreach (string assemblyPath in crowAssemblies) additionalResolvePath.Add (System.IO.Path.GetDirectoryName(assemblyPath)); - crowLoadCtx?.Unload(); + //crowLoadCtx?.Unload(); crowLoadCtx = new AssemblyLoadContext("CrowDebuggerLoadContext"); crowLoadCtx.Resolving += (context, assemblyName) => { foreach (string path in additionalResolvePath) { @@ -343,17 +345,18 @@ namespace Crow dbgIFace, dbgIfaceType.GetMethod("OnKeyPress")); - delGetSurfacePointer = (Func)Delegate.CreateDelegate(typeof(Func), - dbgIFace, dbgIfaceType.GetProperty("SurfacePointer").GetGetMethod()); + delGetMainSurface = (Func)Delegate.CreateDelegate(typeof(Func), + dbgIFace, dbgIfaceType.GetProperty("MainSurface").GetGetMethod()); delSetSource = (Action)Delegate.CreateDelegate(typeof(Action), dbgIFace, dbgIfaceType.GetProperty("Source").GetSetMethod()); delReloadIml = (Action)Delegate.CreateDelegate(typeof(Action), dbgIFace, dbgIfaceType.GetMethod("ReloadIml")); - delGetZoomFactor = (Func)Delegate.CreateDelegate(typeof(Func), + /*delGetZoomFactor = (Func)Delegate.CreateDelegate(typeof(Func), dbgIFace, dbgIfaceType.GetProperty("ZoomFactor").GetGetMethod()); delSetZoomFactor = (Action)Delegate.CreateDelegate(typeof(Action), - dbgIFace, dbgIfaceType.GetProperty("ZoomFactor").GetSetMethod()); + dbgIFace, dbgIfaceType.GetProperty("ZoomFactor").GetSetMethod());*/ + fiDbgIFace_Terminate = dbgIfaceType.GetField("Terminate"); fiDbgIFace_IsDirty = dbgIfaceType.GetField("IsDirty"); fiDbgIFace_MaxLayoutingTries = dbgIfaceType.GetField("MaxLayoutingTries", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy); fiDbgIFace_MaxDiscardCount = dbgIfaceType.GetField("MaxDiscardCount", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy); @@ -364,7 +367,7 @@ namespace Crow delResetDebugger = (Action)Delegate.CreateDelegate(typeof(Action), null, debuggerType.GetMethod("Reset")); /*delSaveDebugLog = (Action)Delegate.CreateDelegate(typeof(Action), null, debuggerType.GetMethod("Save", new Type[] {dbgIfaceType, typeof(string)}));*/ - HasVkvgBackend = (bool)dbgIfaceType.GetField ("HaveVkvgBackend", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy).GetValue (null); + //HasVkvgBackend = (bool)dbgIfaceType.GetField ("HaveVkvgBackend", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy).GetValue (null); dbgIfaceType.GetMethod("RegisterDebugInterfaceCallback").Invoke (dbgIFace, new object[] {this} ); dbgIfaceType.GetMethod("Run").Invoke (dbgIFace, null); @@ -373,12 +376,18 @@ namespace Crow CurrentState = Status.Running; + App.ViewCommands.Add (CMDViewPreview); + updateCrowDebuggerState(); - delSetZoomFactor (ZoomFactor); + //delSetZoomFactor (ZoomFactor); } public override void Stop() { + if (CurrentState == Status.Running) + fiDbgIFace_Terminate.SetValue (dbgIFace, true); + App.ViewCommands.Remove (CMDViewPreview); + Recording = false; DebugLogIsEnabled = false; crowLoadCtx = null; @@ -540,7 +549,7 @@ namespace Crow } } #endregion - public IntPtr SurfacePointer => IsRunning ? delGetSurfacePointer() : IntPtr.Zero; + public ISurface MainSurface => IsRunning ? delGetMainSurface() : null; public void Resize (int width, int height) { if (IsRunning) delResize (width, height); diff --git a/plugins/CECrowPlugin/src/DbgEventWidget.cs b/plugins/CECrowPlugin/src/DbgEventWidget.cs index 5960a8c..c29edfe 100644 --- a/plugins/CECrowPlugin/src/DbgEventWidget.cs +++ b/plugins/CECrowPlugin/src/DbgEventWidget.cs @@ -4,7 +4,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using Crow.Drawing; +using Drawing2D; using Crow.DebugLogger; namespace Crow @@ -85,7 +85,7 @@ namespace Crow base.OnLayoutChanges (layoutType); } - protected override void onDraw (Context gr) + protected override void onDraw (IContext gr) { lock (dataMutex) { @@ -109,7 +109,7 @@ namespace Crow drawEvent (gr, cb.Height, Event); } } - void drawEvent (Context ctx, int h, DbgEvent dbge) + void drawEvent (IContext ctx, int h, DbgEvent dbge) { double w = Math.Max(dbge.Duration * pixelPerTick, 2.0); double x = (dbge.begin - Event.begin) * pixelPerTick; diff --git a/plugins/CECrowPlugin/src/DbgLogViewer.cs b/plugins/CECrowPlugin/src/DbgLogViewer.cs index fd0f18e..5df0be2 100644 --- a/plugins/CECrowPlugin/src/DbgLogViewer.cs +++ b/plugins/CECrowPlugin/src/DbgLogViewer.cs @@ -8,7 +8,7 @@ using System.ComponentModel; using System.IO; using System.Linq; using System.Threading.Tasks; -using Crow.Drawing; +using Drawing2D; using Crow.DebugLogger; using System.Diagnostics; @@ -176,7 +176,7 @@ namespace Crow get { return base.Font; } set { base.Font = value; - using (Context gr = new Context (IFace.surf)) { + using (IContext gr = IFace.Backend.CreateContext (IFace.MainSurface)) { gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); gr.SetFontSize (Font.Size); @@ -198,7 +198,7 @@ namespace Crow w -= rightDiff; return new RectangleD(x, penY, w, fe.Height); } - void drawEvents (Context ctx, IList evts) + void drawEvents (IContext ctx, IList evts) { if (evts == null || evts.Count == 0) return; @@ -245,11 +245,12 @@ namespace Crow } DbgEvtType currentFilter; - protected override void onDraw (Context gr) + protected override void onDraw (IContext gr) { base.onDraw (gr); - setFontForContext (gr); + gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); + gr.SetFontSize (Font.Size); if (widgets == null) return; @@ -268,7 +269,7 @@ namespace Crow penY += fe.Height; - gr.SetSource (Crow.Colors.Jet); + gr.SetSource (Colors.Jet); gr.MoveTo (cb.X, penY - 0.5); gr.LineTo (cb.Right, penY - 0.5); gr.Stroke (); @@ -276,7 +277,7 @@ namespace Crow double penX = 5.0 * g.xLevel + cb.Left; if (g.xLevel == 0) - gr.SetSource (Crow.Colors.LightSalmon); + gr.SetSource (Colors.LightSalmon); else if (currentLine == g.listIndex) gr.SetSource(Colors.RoyalBlue); else @@ -294,7 +295,7 @@ namespace Crow gr.MoveTo (leftMargin + cb.Left, cb.Top); gr.LineTo (leftMargin + cb.Left, cb.Bottom); - gr.SetSource (Crow.Colors.Grey); + gr.SetSource (Colors.Grey); penY = topMargin + ClientRectangle.Top; @@ -329,7 +330,7 @@ namespace Crow } string ticksToMS(long ticks) => Math.Round ((double)ticks / Stopwatch.Frequency * 1000.0, 2).ToString(); - public override void Paint (Context ctx) + public override void Paint (IContext ctx) { base.Paint (ctx); @@ -362,7 +363,8 @@ namespace Crow } } - setFontForContext (ctx); + ctx.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); + ctx.SetFontSize (Font.Size); string str = ticksToMS(hoverTick); @@ -586,11 +588,12 @@ namespace Crow if (widgets == null) return; - using (Context gr = new Context (IFace.surf)) { + using (IContext gr = IFace.Backend.CreateContext (IFace.MainSurface)) { + gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); + gr.SetFontSize (Font.Size); + double maxNameWidth = 0.0; - setFontForContext (gr); - foreach (DbgWidgetRecord o in widgets) { double nameWidth = gr.TextExtents (o.name).Width + 5.0 * o.xLevel; if (nameWidth > maxNameWidth) diff --git a/plugins/CECrowPlugin/src/DebugInterface.cs b/plugins/CECrowPlugin/src/DebugInterface.cs index b5c78f4..8f5d8d3 100644 --- a/plugins/CECrowPlugin/src/DebugInterface.cs +++ b/plugins/CECrowPlugin/src/DebugInterface.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2021 Bruyère Jean-Philippe +// Copyright (c) 2021-2022 Bruyère Jean-Philippe // // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) @@ -9,7 +9,7 @@ using System.Reflection; using System.Threading; using System.Linq; using Crow; -using Crow.Drawing; +using Drawing2D; using IML = Crow.IML; namespace CECrowPlugin @@ -20,21 +20,28 @@ namespace CECrowPlugin } public DebugInterface (IntPtr hWin) : base (100, 100, hWin) { - SolidBackground = false; - initBackend (true); - clientRectangle = new Rectangle (0, 0, 100, 100); - CreateMainSurface (ref clientRectangle); } - + protected override void initBackend() + { + if (!tryFindBackendType (out Type backendType)) + throw new Exception ("No backend found."); + backend = (CrowBackend)Activator.CreateInstance (backendType, new object[] {clientRectangle.Width, clientRectangle.Height}); + //hWin = backend.hWin; + ownWindow = false; + clipping = Backend.CreateRegion (); + } public override void Run() { - Init(); + initBackend (); Thread t = new Thread (interfaceThread) { IsBackground = true }; t.Start (); + + Init(); + } public bool Terminate; string source; @@ -66,8 +73,6 @@ namespace CECrowPlugin Console.WriteLine ($"[DebugIFace] trying to exit ClippingMutex on error"); Monitor.Exit (ClippingMutex); } - - /*while (Monitor.IsEntered(LayoutMutex)) Monitor.Exit (LayoutMutex); while (Monitor.IsEntered(UpdateMutex)) @@ -85,12 +90,7 @@ namespace CECrowPlugin Thread.Sleep (UPDATE_INTERVAL); } - } - public new IntPtr SurfacePointer { - get { - lock(UpdateMutex) - return surf.Handle; - } + Dispose(); } public void RegisterDebugInterfaceCallback (object crowService){ Type t = crowService.GetType(); @@ -152,10 +152,9 @@ namespace CECrowPlugin Source = src; } public void Resize (int width, int height) { - if (!HaveVkvgBackend) - ProcessResize (new Rectangle(0,0,width, height)); + ProcessResize (new Rectangle(0, 0, width, height)); } - public override void ProcessResize(Rectangle bounds) { + /*public override void ProcessResize(Rectangle bounds) { lock (UpdateMutex) { clientRectangle = bounds.Size; @@ -166,7 +165,7 @@ namespace CECrowPlugin RegisterClip (clientRectangle); } - } + }*/ public override void ForceMousePosition() { delCrowServiceGetScreenCoordinate(out int x, out int y); diff --git a/plugins/CECrowPlugin/src/DebugInterfaceWidget.cs b/plugins/CECrowPlugin/src/DebugInterfaceWidget.cs index 13a5dcf..849f72e 100644 --- a/plugins/CECrowPlugin/src/DebugInterfaceWidget.cs +++ b/plugins/CECrowPlugin/src/DebugInterfaceWidget.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2019 Bruyère Jean-Philippe +// Copyright (c) 2013-2022 Bruyère Jean-Philippe // // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) @@ -7,7 +7,7 @@ using Glfw; using System.Reflection; using System.Runtime.Loader; using System.IO; -using Crow.Drawing; +using Drawing2D; using System.Diagnostics; using System.Collections.Generic; using Crow.DebugLogger; @@ -137,7 +137,7 @@ namespace Crow (Parent.LogicalParent as DockWindow).CMDClose ); - protected override void onDraw(Context gr) + protected override void onDraw(IContext gr) { Console.WriteLine("onDraw"); gr.SetSource(Colors.RoyalBlue); @@ -156,23 +156,23 @@ namespace Crow public override void onMouseUp(object sender, MouseButtonEventArgs e) => crowIFaceService?.onMouseUp(e); public override void onMouseWheel(object sender, MouseWheelEventArgs e) => crowIFaceService?.onMouseWheel(e); + public override void Paint(IContext ctx) + { + base.Paint(ctx); + } protected override void RecreateCache() { - bmp?.Dispose (); + //bmp?.Dispose (); if (crowIFaceService != null && crowIFaceService.IsRunning) { crowIFaceService.Resize (Slot.Width, Slot.Height); - if (crowIFaceService.HasVkvgBackend) - bmp = IFace.CreateSurfaceForData (crowIFaceService.SurfacePointer, Slot.Width, Slot.Height); - else - bmp = IFace.CreateSurface (crowIFaceService.SurfacePointer); - bmp = Crow.Drawing.Surface.Lookup (crowIFaceService.SurfacePointer, false); + bmp = crowIFaceService.MainSurface; } else base.RecreateCache (); IsDirty = false; } - protected override void UpdateCache(Context ctx) + protected override void UpdateCache(IContext ctx) { if (bmp != null) { paintCache (ctx, Slot + Parent.ClientRectangle.Position); diff --git a/plugins/CECrowPlugin/src/ImlDocument.cs b/plugins/CECrowPlugin/src/ImlDocument.cs index 49a4f99..a5d30f6 100644 --- a/plugins/CECrowPlugin/src/ImlDocument.cs +++ b/plugins/CECrowPlugin/src/ImlDocument.cs @@ -17,6 +17,7 @@ using static CrowEditBase.CrowEditBase; using CrowEdit.Xml; using AttributeSyntax = CrowEdit.Xml.AttributeSyntax; +using Drawing2D; namespace CECrowPlugin { diff --git a/plugins/CECrowPlugin/src/StyleDocument.cs b/plugins/CECrowPlugin/src/StyleDocument.cs index d6e751a..215d764 100644 --- a/plugins/CECrowPlugin/src/StyleDocument.cs +++ b/plugins/CECrowPlugin/src/StyleDocument.cs @@ -7,6 +7,7 @@ using Crow; using System.Collections; using CrowEditBase; using static CrowEditBase.CrowEditBase; +using Drawing2D; namespace CECrowPlugin.Style { diff --git a/plugins/CERoslynPlugin/default.conf b/plugins/CERoslynPlugin/default.conf index 8fb7123..cd4b1a1 100644 --- a/plugins/CERoslynPlugin/default.conf +++ b/plugins/CERoslynPlugin/default.conf @@ -1 +1,2 @@ +MainService=CERoslynPlugin.RoslynService FileAssociations=CERoslynPlugin.CSDocument:.cs;CERoslynPlugin.SolutionProject:.sln \ No newline at end of file diff --git a/plugins/CERoslynPlugin/src/CSTokenizer.cs b/plugins/CERoslynPlugin/src/CSTokenizer.cs index e34f23e..68b386d 100644 --- a/plugins/CERoslynPlugin/src/CSTokenizer.cs +++ b/plugins/CERoslynPlugin/src/CSTokenizer.cs @@ -37,11 +37,11 @@ namespace CERoslynPlugin reader.Read(); if (reader.IsNextCharIn ('\xA', '\x85')) reader.Read(); - addTok (ref reader, TokenType.LineBreak); + addTok (ref reader, TokenType.LineBreak); break; case '\x20': case '\x9': - char c = reader.Read(); + char c = reader.Read(); while (reader.TryPeak (c)) reader.Read(); addTok (ref reader, c == '\x20' ? TokenType.WhiteSpace : TokenType.Tabulation); @@ -56,7 +56,7 @@ namespace CERoslynPlugin switch (reader.Peak) { case '\x20': case '\x9': - char c = reader.Read(); + char c = reader.Read(); while (reader.TryPeak (c)) reader.Read(); addTok (ref reader, c == '\x20' ? TokenType.WhiteSpace : TokenType.Tabulation); @@ -70,7 +70,7 @@ namespace CERoslynPlugin public override Token[] Tokenize(string source) { SpanCharReader reader = new SpanCharReader(source); - + startOfTok = 0; //curState = States.Init; Toks = new List(100); @@ -101,7 +101,7 @@ namespace CERoslynPlugin Toks = new List(100); } public override void Visit (SyntaxNode node) - { + { base.Visit (node); } public override void VisitToken (SyntaxToken token) diff --git a/plugins/CERoslynPlugin/src/RoslynService.cs b/plugins/CERoslynPlugin/src/RoslynService.cs index f2a6728..4a74b08 100644 --- a/plugins/CERoslynPlugin/src/RoslynService.cs +++ b/plugins/CERoslynPlugin/src/RoslynService.cs @@ -61,15 +61,19 @@ namespace CERoslynPlugin AssemblyLoadContext pluginCtx = AssemblyLoadContext.GetLoadContext (Assembly.GetExecutingAssembly()); pluginCtx.Resolving += msbuildResolve; - foreach (string dll in Directory.GetFiles (MSBuildRoot, "*.dll")) - pluginCtx.LoadFromAssemblyPath (dll); + foreach (string dll in Directory.GetFiles (MSBuildRoot, "*.dll")) { + try { + pluginCtx.LoadFromAssemblyPath (dll); + } catch (Exception ex) { + App.Log(LogType.Error, $"[RoslynService]{ex}"); + } + } string capath = Path.Combine (MSBuildRoot, "Roslyn", "bincore"); foreach (string dll in Directory.GetFiles (capath, "*.dll")) { try { pluginCtx.LoadFromAssemblyPath (dll); - } - catch (Exception ex) { - Console.WriteLine ($"[RoslynService]{ex}"); + } catch (Exception ex) { + App.Log(LogType.Error, $"[RoslynService]{ex}"); } } @@ -80,7 +84,7 @@ namespace CERoslynPlugin if (!File.Exists (assemblyPath)) return null; Assembly a = context.LoadFromAssemblyPath (assemblyPath); - Console.WriteLine ($"[MSBuildResolve]{a},{a.CodeBase}"); + App.Log (LogType.Message, $"[MSBuildResolve]{a},{a.CodeBase}"); return a; } diff --git a/plugins/CEXmlPlugin/src/Parsing/XmlDocument.cs b/plugins/CEXmlPlugin/src/Parsing/XmlDocument.cs index edb10d3..7918136 100644 --- a/plugins/CEXmlPlugin/src/Parsing/XmlDocument.cs +++ b/plugins/CEXmlPlugin/src/Parsing/XmlDocument.cs @@ -2,17 +2,10 @@ // // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) -using System; -using System.Linq; using Crow.Text; -using System.Collections.Generic; -using System.Diagnostics; -using Crow; -using IML = Crow.IML; using System.Collections; -using System.Reflection; using CrowEditBase; -using static CrowEditBase.CrowEditBase; +using Drawing2D; namespace CrowEdit.Xml { diff --git a/src/CrowEdit.cs b/src/CrowEdit.cs index 17556c7..19c133c 100644 --- a/src/CrowEdit.cs +++ b/src/CrowEdit.cs @@ -12,6 +12,7 @@ using System.Runtime.InteropServices; using CrowEditBase; using System.Linq; using System.Text; +using Drawing2D; namespace CrowEdit { @@ -62,6 +63,8 @@ namespace CrowEdit protected override void OnInitialized () { base.OnInitialized (); + initCommands (); + loadPlugins (); SetWindowIcon ("#Crow.Icons.crow.png"); @@ -69,8 +72,6 @@ namespace CrowEdit if (CurrentDir == null) CurrentDir = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments); - initCommands (); - Widget w = Load ("#CrowEdit.ui.main.crow"); w.DataSource = this; diff --git a/ui/EditorOptions.crow b/ui/EditorOptions.crow index dc0183c..b2e4096 100644 --- a/ui/EditorOptions.crow +++ b/ui/EditorOptions.crow @@ -5,5 +5,11 @@ + + \ No newline at end of file -- 2.47.3