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.MacOS" Version="2025.12.4" />-->
|
||||
<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="Jint" Version="4.4.2" />
|
||||
<PackageVersion Include="Microsoft.Maui.Graphics" Version="10.0.11" />
|
||||
|
||||
@@ -40,28 +40,30 @@ namespace Progrart.Core.JSExecution
|
||||
public ExecutionEngine()
|
||||
{
|
||||
Engine = new Engine();
|
||||
Engine.SetValue("abs", MathFunctions.abs);
|
||||
Engine.SetValue("sin", MathFunctions.sin);
|
||||
Engine.SetValue("cos", MathFunctions.cos);
|
||||
Engine.SetValue("tan", MathFunctions.tan);
|
||||
Engine.SetValue("tanh", MathFunctions.tanh);
|
||||
Engine.SetValue("asin", MathFunctions.asin);
|
||||
Engine.SetValue("acos", MathFunctions.acos);
|
||||
Engine.SetValue("atan", MathFunctions.atan);
|
||||
Engine.SetValue("atan2", MathFunctions.atan2);
|
||||
Engine.SetValue("atanh", MathFunctions.atanh);
|
||||
Engine.SetValue("sqrt", MathFunctions.sqrt);
|
||||
Engine.SetValue("cbrt", MathFunctions.cbrt);
|
||||
Engine.SetValue("pow", MathFunctions.pow);
|
||||
Engine.SetValue("log", MathFunctions.log);
|
||||
Engine.SetValue("log_base", MathFunctions.log_base);
|
||||
Engine.SetValue("log2", MathFunctions.log2);
|
||||
Engine.SetValue("log10", MathFunctions.log10);
|
||||
Engine.SetValue("exp", MathFunctions.exp);
|
||||
Engine.SetValue("ceiling", MathFunctions.ceiling);
|
||||
Engine.SetValue("floor", MathFunctions.floor);
|
||||
Engine.SetValue("sinh", MathFunctions.sinh);
|
||||
Engine.SetValue("cosh", MathFunctions.cosh);
|
||||
JsObject _obj = new JsObject(Engine);
|
||||
Engine.SetValue("math", _obj);
|
||||
_obj.Set("abs", JsObject.FromObject(Engine, (object)MathFunctions.abs));
|
||||
_obj.Set("sin", JsObject.FromObject(Engine, (object)MathFunctions.sin));
|
||||
_obj.Set("cos", JsObject.FromObject(Engine, (object)MathFunctions.cos));
|
||||
_obj.Set("tan", JsObject.FromObject(Engine, (object)MathFunctions.tan));
|
||||
_obj.Set("tanh", JsObject.FromObject(Engine, (object)MathFunctions.tanh));
|
||||
_obj.Set("asin", JsObject.FromObject(Engine, (object)MathFunctions.asin));
|
||||
_obj.Set("acos", JsObject.FromObject(Engine, (object)MathFunctions.acos));
|
||||
_obj.Set("atan", JsObject.FromObject(Engine, (object)MathFunctions.atan));
|
||||
_obj.Set("atan2", JsObject.FromObject(Engine, (object)MathFunctions.atan2));
|
||||
_obj.Set("atanh", JsObject.FromObject(Engine, (object)MathFunctions.atanh));
|
||||
_obj.Set("sqrt", JsObject.FromObject(Engine, (object)MathFunctions.sqrt));
|
||||
_obj.Set("cbrt", JsObject.FromObject(Engine, (object)MathFunctions.cbrt));
|
||||
_obj.Set("pow", JsObject.FromObject(Engine, (object)MathFunctions.pow));
|
||||
_obj.Set("log", JsObject.FromObject(Engine, (object)MathFunctions.log));
|
||||
_obj.Set("log_base", JsObject.FromObject(Engine, (object)MathFunctions.log_base));
|
||||
_obj.Set("log2", JsObject.FromObject(Engine, (object)MathFunctions.log2));
|
||||
_obj.Set("log10", JsObject.FromObject(Engine, (object)MathFunctions.log10));
|
||||
_obj.Set("exp", JsObject.FromObject(Engine, (object)MathFunctions.exp));
|
||||
_obj.Set("ceiling", JsObject.FromObject(Engine, (object)MathFunctions.ceiling));
|
||||
_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)
|
||||
{
|
||||
|
||||
@@ -287,6 +287,7 @@
|
||||
<!--<DevolutionsDevExpressTheme />-->
|
||||
<!--<DevolutionsMacOsTheme/>-->
|
||||
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />
|
||||
<StyleInclude Source="avares://AvaloniaProgressRing/Styles/ProgressRing.xaml"/>
|
||||
<dialoghostavalonia:DialogHostStyles/>
|
||||
<Style Selector="ContextMenu">
|
||||
<!--<Setter Property="FontFamily" Value="{StaticResource SarasaMonoSlabCLFont}"/>-->
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
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"
|
||||
x:Class="Progrart.ProgrartEditorPage">
|
||||
<Grid>
|
||||
@@ -24,6 +25,24 @@
|
||||
<GridSplitter Grid.Column="1" Opacity="0.01"/>
|
||||
<Grid Name="PreviewHolder" Grid.Column="2">
|
||||
<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.Row="1" Margin="0,5,0,5">
|
||||
|
||||
@@ -21,6 +21,7 @@ public partial class ProgrartEditorPage : UserControl, ITabPage, IEditorPage
|
||||
IStorageFile? file = null;
|
||||
TabButton? btn = null;
|
||||
Bitmap? image;
|
||||
string lastSave = "";
|
||||
public ProgrartEditorPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -38,46 +39,57 @@ public partial class ProgrartEditorPage : UserControl, ITabPage, IEditorPage
|
||||
btn.TooltipText = path;
|
||||
}
|
||||
}
|
||||
|
||||
bool isRunning = false;
|
||||
public void Execute(ExecuteArguments? args = null)
|
||||
{
|
||||
AvaloniaStorageProvider provider = new AvaloniaStorageProvider(App.CurrentOpenFolder);
|
||||
using ProgrartExecutor executor = new ProgrartExecutor(provider);
|
||||
try
|
||||
if (isRunning) return;
|
||||
string src = CodeEditor.Text;
|
||||
ProgressRing.IsVisible = true;
|
||||
Task.Run(() =>
|
||||
{
|
||||
int Scale = 1024;
|
||||
if (args is not null)
|
||||
AvaloniaStorageProvider provider = new AvaloniaStorageProvider(App.CurrentOpenFolder);
|
||||
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());
|
||||
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)
|
||||
catch (System.Exception e)
|
||||
{
|
||||
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()
|
||||
{
|
||||
return false;
|
||||
return lastSave == CodeEditor.Text;
|
||||
}
|
||||
|
||||
public bool IsSameFile(IStorageFile file)
|
||||
@@ -105,7 +117,7 @@ public partial class ProgrartEditorPage : UserControl, ITabPage, IEditorPage
|
||||
Dispatcher.UIThread.Invoke(() =>
|
||||
{
|
||||
CodeEditor.Text = text;
|
||||
|
||||
lastSave = text;
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -116,6 +128,7 @@ public partial class ProgrartEditorPage : UserControl, ITabPage, IEditorPage
|
||||
{
|
||||
string content = "";
|
||||
await Dispatcher.UIThread.InvokeAsync(() => { content = CodeEditor.Text; });
|
||||
lastSave = content;
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
using var stream = await file.OpenWriteAsync();
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="AvaloniaEdit.TextMate" />
|
||||
<PackageReference Include="Deadpikle.AvaloniaProgressRing" />
|
||||
<PackageReference Include="DialogHost.Avalonia" />
|
||||
<PackageReference Include="PanAndZoom" />
|
||||
<!--<PackageReference Include="Devolutions.AvaloniaTheme.DevExpress" />
|
||||
|
||||
Reference in New Issue
Block a user