Creates a thread when previewing the image in Progrart Editor.
Moved all math functions to `math` object.
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
<!--<PackageVersion Include="Devolutions.AvaloniaTheme.DevExpress" Version="2025.12.4" />
|
<!--<PackageVersion Include="Devolutions.AvaloniaTheme.DevExpress" Version="2025.12.4" />
|
||||||
<PackageVersion Include="Devolutions.AvaloniaTheme.MacOS" Version="2025.12.4" />-->
|
<PackageVersion Include="Devolutions.AvaloniaTheme.MacOS" Version="2025.12.4" />-->
|
||||||
<PackageVersion Include="AvaloniaEdit.TextMate" Version="11.3.0" />
|
<PackageVersion Include="AvaloniaEdit.TextMate" Version="11.3.0" />
|
||||||
|
<PackageVersion Include="Deadpikle.AvaloniaProgressRing" Version="0.10.11-preview20251127001" />
|
||||||
<PackageVersion Include="DialogHost.Avalonia" Version="0.10.3" />
|
<PackageVersion Include="DialogHost.Avalonia" Version="0.10.3" />
|
||||||
<PackageVersion Include="Jint" Version="4.4.2" />
|
<PackageVersion Include="Jint" Version="4.4.2" />
|
||||||
<PackageVersion Include="Microsoft.Maui.Graphics" Version="10.0.11" />
|
<PackageVersion Include="Microsoft.Maui.Graphics" Version="10.0.11" />
|
||||||
|
|||||||
@@ -40,28 +40,30 @@ namespace Progrart.Core.JSExecution
|
|||||||
public ExecutionEngine()
|
public ExecutionEngine()
|
||||||
{
|
{
|
||||||
Engine = new Engine();
|
Engine = new Engine();
|
||||||
Engine.SetValue("abs", MathFunctions.abs);
|
JsObject _obj = new JsObject(Engine);
|
||||||
Engine.SetValue("sin", MathFunctions.sin);
|
Engine.SetValue("math", _obj);
|
||||||
Engine.SetValue("cos", MathFunctions.cos);
|
_obj.Set("abs", JsObject.FromObject(Engine, (object)MathFunctions.abs));
|
||||||
Engine.SetValue("tan", MathFunctions.tan);
|
_obj.Set("sin", JsObject.FromObject(Engine, (object)MathFunctions.sin));
|
||||||
Engine.SetValue("tanh", MathFunctions.tanh);
|
_obj.Set("cos", JsObject.FromObject(Engine, (object)MathFunctions.cos));
|
||||||
Engine.SetValue("asin", MathFunctions.asin);
|
_obj.Set("tan", JsObject.FromObject(Engine, (object)MathFunctions.tan));
|
||||||
Engine.SetValue("acos", MathFunctions.acos);
|
_obj.Set("tanh", JsObject.FromObject(Engine, (object)MathFunctions.tanh));
|
||||||
Engine.SetValue("atan", MathFunctions.atan);
|
_obj.Set("asin", JsObject.FromObject(Engine, (object)MathFunctions.asin));
|
||||||
Engine.SetValue("atan2", MathFunctions.atan2);
|
_obj.Set("acos", JsObject.FromObject(Engine, (object)MathFunctions.acos));
|
||||||
Engine.SetValue("atanh", MathFunctions.atanh);
|
_obj.Set("atan", JsObject.FromObject(Engine, (object)MathFunctions.atan));
|
||||||
Engine.SetValue("sqrt", MathFunctions.sqrt);
|
_obj.Set("atan2", JsObject.FromObject(Engine, (object)MathFunctions.atan2));
|
||||||
Engine.SetValue("cbrt", MathFunctions.cbrt);
|
_obj.Set("atanh", JsObject.FromObject(Engine, (object)MathFunctions.atanh));
|
||||||
Engine.SetValue("pow", MathFunctions.pow);
|
_obj.Set("sqrt", JsObject.FromObject(Engine, (object)MathFunctions.sqrt));
|
||||||
Engine.SetValue("log", MathFunctions.log);
|
_obj.Set("cbrt", JsObject.FromObject(Engine, (object)MathFunctions.cbrt));
|
||||||
Engine.SetValue("log_base", MathFunctions.log_base);
|
_obj.Set("pow", JsObject.FromObject(Engine, (object)MathFunctions.pow));
|
||||||
Engine.SetValue("log2", MathFunctions.log2);
|
_obj.Set("log", JsObject.FromObject(Engine, (object)MathFunctions.log));
|
||||||
Engine.SetValue("log10", MathFunctions.log10);
|
_obj.Set("log_base", JsObject.FromObject(Engine, (object)MathFunctions.log_base));
|
||||||
Engine.SetValue("exp", MathFunctions.exp);
|
_obj.Set("log2", JsObject.FromObject(Engine, (object)MathFunctions.log2));
|
||||||
Engine.SetValue("ceiling", MathFunctions.ceiling);
|
_obj.Set("log10", JsObject.FromObject(Engine, (object)MathFunctions.log10));
|
||||||
Engine.SetValue("floor", MathFunctions.floor);
|
_obj.Set("exp", JsObject.FromObject(Engine, (object)MathFunctions.exp));
|
||||||
Engine.SetValue("sinh", MathFunctions.sinh);
|
_obj.Set("ceiling", JsObject.FromObject(Engine, (object)MathFunctions.ceiling));
|
||||||
Engine.SetValue("cosh", MathFunctions.cosh);
|
_obj.Set("floor", JsObject.FromObject(Engine, (object)MathFunctions.floor));
|
||||||
|
_obj.Set("sinh", JsObject.FromObject(Engine, (object)MathFunctions.sinh));
|
||||||
|
_obj.Set("cosh", JsObject.FromObject(Engine, (object)MathFunctions.cosh));
|
||||||
}
|
}
|
||||||
string formSymbol(Dictionary<string, string> symbols)
|
string formSymbol(Dictionary<string, string> symbols)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -287,6 +287,7 @@
|
|||||||
<!--<DevolutionsDevExpressTheme />-->
|
<!--<DevolutionsDevExpressTheme />-->
|
||||||
<!--<DevolutionsMacOsTheme/>-->
|
<!--<DevolutionsMacOsTheme/>-->
|
||||||
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />
|
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />
|
||||||
|
<StyleInclude Source="avares://AvaloniaProgressRing/Styles/ProgressRing.xaml"/>
|
||||||
<dialoghostavalonia:DialogHostStyles/>
|
<dialoghostavalonia:DialogHostStyles/>
|
||||||
<Style Selector="ContextMenu">
|
<Style Selector="ContextMenu">
|
||||||
<!--<Setter Property="FontFamily" Value="{StaticResource SarasaMonoSlabCLFont}"/>-->
|
<!--<Setter Property="FontFamily" Value="{StaticResource SarasaMonoSlabCLFont}"/>-->
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:progRing="clr-namespace:AvaloniaProgressRing;assembly=AvaloniaProgressRing"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="Progrart.ProgrartEditorPage">
|
x:Class="Progrart.ProgrartEditorPage">
|
||||||
<Grid>
|
<Grid>
|
||||||
@@ -24,6 +25,24 @@
|
|||||||
<GridSplitter Grid.Column="1" Opacity="0.01"/>
|
<GridSplitter Grid.Column="1" Opacity="0.01"/>
|
||||||
<Grid Name="PreviewHolder" Grid.Column="2">
|
<Grid Name="PreviewHolder" Grid.Column="2">
|
||||||
<controls:ImageViewer Name="PreviewImage"/>
|
<controls:ImageViewer Name="PreviewImage"/>
|
||||||
|
<Grid Name="ProgressRing" IsVisible="False">
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition/>
|
||||||
|
<RowDefinition/>
|
||||||
|
<RowDefinition/>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition/>
|
||||||
|
<ColumnDefinition/>
|
||||||
|
<ColumnDefinition/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<Viewbox Grid.Column="1" Grid.Row="1">
|
||||||
|
<progRing:ProgressRing
|
||||||
|
IsActive="True" Width="100" Height="100"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
VerticalAlignment="Center"/>
|
||||||
|
</Viewbox>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid Grid.Row="1" Margin="0,5,0,5">
|
<Grid Grid.Row="1" Margin="0,5,0,5">
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ public partial class ProgrartEditorPage : UserControl, ITabPage, IEditorPage
|
|||||||
IStorageFile? file = null;
|
IStorageFile? file = null;
|
||||||
TabButton? btn = null;
|
TabButton? btn = null;
|
||||||
Bitmap? image;
|
Bitmap? image;
|
||||||
|
string lastSave = "";
|
||||||
public ProgrartEditorPage()
|
public ProgrartEditorPage()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -38,46 +39,57 @@ public partial class ProgrartEditorPage : UserControl, ITabPage, IEditorPage
|
|||||||
btn.TooltipText = path;
|
btn.TooltipText = path;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
bool isRunning = false;
|
||||||
public void Execute(ExecuteArguments? args = null)
|
public void Execute(ExecuteArguments? args = null)
|
||||||
{
|
{
|
||||||
AvaloniaStorageProvider provider = new AvaloniaStorageProvider(App.CurrentOpenFolder);
|
if (isRunning) return;
|
||||||
using ProgrartExecutor executor = new ProgrartExecutor(provider);
|
string src = CodeEditor.Text;
|
||||||
try
|
ProgressRing.IsVisible = true;
|
||||||
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
int Scale = 1024;
|
AvaloniaStorageProvider provider = new AvaloniaStorageProvider(App.CurrentOpenFolder);
|
||||||
if (args is not null)
|
using ProgrartExecutor executor = new ProgrartExecutor(provider);
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (args.data.TryGetValue("Scale", out var scale))
|
int Scale = 1024;
|
||||||
|
if (args is not null)
|
||||||
{
|
{
|
||||||
if (!int.TryParse(scale, out Scale)) Scale = 1024;
|
if (args.data.TryGetValue("Scale", out var scale))
|
||||||
|
{
|
||||||
|
if (!int.TryParse(scale, out Scale)) Scale = 1024;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
var result = executor.RenderImage(Scale, src, args ?? new ExecuteArguments());
|
||||||
|
var data = result.DrawingCore.ToData();
|
||||||
|
using MemoryStream stream = new MemoryStream();
|
||||||
|
data.SaveTo(stream);
|
||||||
|
stream.Flush();
|
||||||
|
stream.Position = 0;
|
||||||
|
Bitmap image = new Bitmap(stream);
|
||||||
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
|
{
|
||||||
|
ProgressRing.IsVisible = false;
|
||||||
|
PreviewImage.SetImage(image);
|
||||||
|
this.image?.Dispose();
|
||||||
|
this.image = image;
|
||||||
|
isRunning = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
var result = executor.RenderImage(1024, CodeEditor.Text, args ?? new ExecuteArguments());
|
catch (System.Exception e)
|
||||||
var data = result.DrawingCore.ToData();
|
|
||||||
using MemoryStream stream = new MemoryStream();
|
|
||||||
|
|
||||||
data.SaveTo(stream);
|
|
||||||
stream.Flush();
|
|
||||||
|
|
||||||
stream.Position = 0;
|
|
||||||
Bitmap image = new Bitmap(stream);
|
|
||||||
PreviewImage.SetImage(image);
|
|
||||||
if (this.image != null)
|
|
||||||
{
|
{
|
||||||
this.image.Dispose();
|
Trace.WriteLine(e);
|
||||||
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
|
{
|
||||||
|
ProgressRing.IsVisible = false;
|
||||||
|
});
|
||||||
|
isRunning = false;
|
||||||
}
|
}
|
||||||
this.image = image;
|
});
|
||||||
}
|
|
||||||
catch (System.Exception e)
|
|
||||||
{
|
|
||||||
Trace.WriteLine(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsModified()
|
public bool IsModified()
|
||||||
{
|
{
|
||||||
return false;
|
return lastSave == CodeEditor.Text;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsSameFile(IStorageFile file)
|
public bool IsSameFile(IStorageFile file)
|
||||||
@@ -105,7 +117,7 @@ public partial class ProgrartEditorPage : UserControl, ITabPage, IEditorPage
|
|||||||
Dispatcher.UIThread.Invoke(() =>
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
{
|
{
|
||||||
CodeEditor.Text = text;
|
CodeEditor.Text = text;
|
||||||
|
lastSave = text;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -116,6 +128,7 @@ public partial class ProgrartEditorPage : UserControl, ITabPage, IEditorPage
|
|||||||
{
|
{
|
||||||
string content = "";
|
string content = "";
|
||||||
await Dispatcher.UIThread.InvokeAsync(() => { content = CodeEditor.Text; });
|
await Dispatcher.UIThread.InvokeAsync(() => { content = CodeEditor.Text; });
|
||||||
|
lastSave = content;
|
||||||
await Task.Run(async () =>
|
await Task.Run(async () =>
|
||||||
{
|
{
|
||||||
using var stream = await file.OpenWriteAsync();
|
using var stream = await file.OpenWriteAsync();
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="AvaloniaEdit.TextMate" />
|
<PackageReference Include="AvaloniaEdit.TextMate" />
|
||||||
|
<PackageReference Include="Deadpikle.AvaloniaProgressRing" />
|
||||||
<PackageReference Include="DialogHost.Avalonia" />
|
<PackageReference Include="DialogHost.Avalonia" />
|
||||||
<PackageReference Include="PanAndZoom" />
|
<PackageReference Include="PanAndZoom" />
|
||||||
<!--<PackageReference Include="Devolutions.AvaloniaTheme.DevExpress" />
|
<!--<PackageReference Include="Devolutions.AvaloniaTheme.DevExpress" />
|
||||||
|
|||||||
Reference in New Issue
Block a user