From 1bcaff76b2d964fd425287a17beba0dbe4103187 Mon Sep 17 00:00:00 2001 From: Creeper Lv Date: Sun, 11 Jan 2026 03:54:14 +1100 Subject: [PATCH] Working on the project editor. Implemented a very basic version of command line tool. --- .dockerignore | 30 +++++++++ Directory.Packages.props | 1 + Progrart.Cmd/Dockerfile | 47 +++++++++++++ Progrart.Cmd/Program.cs | 67 +++++++++++++++++++ Progrart.Cmd/Progrart.Cmd.csproj | 21 ++++++ Progrart.Cmd/Properties/launchSettings.json | 10 +++ Progrart.Core/Graphics/Path.cs | 4 +- Progrart.Core/Graphics/PathCmd.cs | 17 ++++- Progrart.Core/Graphics/PathElement.cs | 2 - Progrart.sln | 8 ++- Progrart/App.axaml.cs | 2 + Progrart/Controls/ConfigEditor.axaml | 37 ++++++++++ Progrart/Controls/ConfigEditor.axaml.cs | 11 +++ Progrart/Controls/ExecuteArgumentItem.axaml | 30 +++++++++ .../Controls/ExecuteArgumentItem.axaml.cs | 31 +++++++++ .../Controls/ExecuteArgumentsEditor.axaml | 22 ++++++ .../Controls/ExecuteArgumentsEditor.axaml.cs | 25 +++++++ Progrart/Pages/ProjectEditor.axaml | 37 ++++++++++ Progrart/Pages/ProjectEditor.axaml.cs | 55 +++++++++++++++ 19 files changed, 452 insertions(+), 5 deletions(-) create mode 100644 .dockerignore create mode 100644 Progrart.Cmd/Dockerfile create mode 100644 Progrart.Cmd/Program.cs create mode 100644 Progrart.Cmd/Progrart.Cmd.csproj create mode 100644 Progrart.Cmd/Properties/launchSettings.json create mode 100644 Progrart/Controls/ConfigEditor.axaml create mode 100644 Progrart/Controls/ConfigEditor.axaml.cs create mode 100644 Progrart/Controls/ExecuteArgumentItem.axaml create mode 100644 Progrart/Controls/ExecuteArgumentItem.axaml.cs create mode 100644 Progrart/Controls/ExecuteArgumentsEditor.axaml create mode 100644 Progrart/Controls/ExecuteArgumentsEditor.axaml.cs create mode 100644 Progrart/Pages/ProjectEditor.axaml create mode 100644 Progrart/Pages/ProjectEditor.axaml.cs diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..fe1152b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,30 @@ +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md +!**/.gitignore +!.git/HEAD +!.git/config +!.git/packed-refs +!.git/refs/heads/** \ No newline at end of file diff --git a/Directory.Packages.props b/Directory.Packages.props index d1a548e..6328d7f 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -23,6 +23,7 @@ + diff --git a/Progrart.Cmd/Dockerfile b/Progrart.Cmd/Dockerfile new file mode 100644 index 0000000..41ce7c9 --- /dev/null +++ b/Progrart.Cmd/Dockerfile @@ -0,0 +1,47 @@ +# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. + +# These ARGs allow for swapping out the base used to make the final image when debugging from VS +ARG LAUNCHING_FROM_VS +# This sets the base image for final, but only if LAUNCHING_FROM_VS has been defined +ARG FINAL_BASE_IMAGE=${LAUNCHING_FROM_VS:+aotdebug} + +# This stage is used when running from VS in fast mode (Default for Debug configuration) +FROM mcr.microsoft.com/dotnet/runtime:10.0 AS base +USER $APP_UID +WORKDIR /app + + +# This stage is used to build the service project +FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build +# Install clang/zlib1g-dev dependencies for publishing to native +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + clang zlib1g-dev +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["Directory.Packages.props", "."] +COPY ["Progrart.Cmd/Progrart.Cmd.csproj", "Progrart.Cmd/"] +RUN dotnet restore "./Progrart.Cmd/Progrart.Cmd.csproj" +COPY . . +WORKDIR "/src/Progrart.Cmd" +RUN dotnet build "./Progrart.Cmd.csproj" -c $BUILD_CONFIGURATION -o /app/build + +# This stage is used to publish the service project to be copied to the final stage +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "./Progrart.Cmd.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=true + +# This stage is used as the base for the final stage when launching from VS to support debugging in regular mode (Default when not using the Debug configuration) +FROM base AS aotdebug +USER root +# Install GDB to support native debugging +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + gdb +USER app + +# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration) +FROM ${FINAL_BASE_IMAGE:-mcr.microsoft.com/dotnet/runtime-deps:10.0} AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["./Progrart.Cmd"] \ No newline at end of file diff --git a/Progrart.Cmd/Program.cs b/Progrart.Cmd/Program.cs new file mode 100644 index 0000000..fa9dc93 --- /dev/null +++ b/Progrart.Cmd/Program.cs @@ -0,0 +1,67 @@ +using Progrart.Core.ProjectSystem; +using Progrart.Core.Storage; + +namespace Progrart.Cmd +{ + internal class Program + { + static void Main(string[] args) + { + string? project_file = null; + string? configuration = null; + for (int i = 0; i < args.Length; i++) + { + string? item = args[i]; + switch (item) + { + case "-c": + case "--config": + case "--configuration": + { + i++; + item = args[i]; + configuration = item; + } + break; + default: + { + + if (File.Exists(item)) + { + project_file = item; + } + } + break; + } + } + if (project_file != null) + if (configuration != null) + { + FileInfo fi = new FileInfo(project_file); + if (fi.Directory is DirectoryInfo di) + { + using var fs = fi.OpenRead(); + using var sr = new StreamReader(fs); + ClassicStorageProvider provider = new ClassicStorageProvider(di); + Builder builder = new Builder(sr, provider); + builder.OnProgressUpdate = (v, m) => + { + Console.WriteLine($"{v}/{m}"); + }; + builder.OnCompleted = () => + { + Environment.Exit(0); + }; + Task.Run(async () => + { + await builder.Build(configuration); + }); + while (true) + { + Thread.Sleep(1000); + } + } + } + } + } +} diff --git a/Progrart.Cmd/Progrart.Cmd.csproj b/Progrart.Cmd/Progrart.Cmd.csproj new file mode 100644 index 0000000..c003786 --- /dev/null +++ b/Progrart.Cmd/Progrart.Cmd.csproj @@ -0,0 +1,21 @@ + + + + Exe + net10.0 + enable + enable + true + true + Linux + + + + + + + + + + + diff --git a/Progrart.Cmd/Properties/launchSettings.json b/Progrart.Cmd/Properties/launchSettings.json new file mode 100644 index 0000000..7c41f1a --- /dev/null +++ b/Progrart.Cmd/Properties/launchSettings.json @@ -0,0 +1,10 @@ +{ + "profiles": { + "Progrart.Cmd": { + "commandName": "Project" + }, + "Container (Dockerfile)": { + "commandName": "Docker" + } + } +} \ No newline at end of file diff --git a/Progrart.Core/Graphics/Path.cs b/Progrart.Core/Graphics/Path.cs index e21dd8c..6a24f09 100644 --- a/Progrart.Core/Graphics/Path.cs +++ b/Progrart.Core/Graphics/Path.cs @@ -4,7 +4,7 @@ using SkiaSharp; namespace Progrart.Core.Graphics { - public class Path : BaseElement + public class Path : BaseElement { SKPath path = new SKPath(); public SKPath RealPath => path; @@ -16,10 +16,12 @@ namespace Progrart.Core.Graphics { __object.Set("line_to", JsValue.FromObject(engine, (object)line_to)); __object.Set("move_to", JsValue.FromObject(engine, (object)move_to)); + __object.Set("quad_to", JsValue.FromObject(engine, (object)quad_to)); } } void line_to(float x, float y) => Commands.Add(new LineToCmd(x, y)); void move_to(float x, float y) => Commands.Add(new MoveToCmd(x, y)); + void quad_to(float x0, float y0, float x1, float y1) => Commands.Add(new QuadToCmd(x0, y0, x1, y1)); public override void Render(RenderContext context) { diff --git a/Progrart.Core/Graphics/PathCmd.cs b/Progrart.Core/Graphics/PathCmd.cs index f163d0a..646f98e 100644 --- a/Progrart.Core/Graphics/PathCmd.cs +++ b/Progrart.Core/Graphics/PathCmd.cs @@ -2,7 +2,7 @@ namespace Progrart.Core.Graphics { - public class PathCmd + public class PathCmd { public virtual void ApplyCommand(RenderContext context, SKPath path) { } } @@ -17,6 +17,21 @@ namespace Progrart.Core.Graphics path.LineTo(pos); } } + public class QuadToCmd(float x1, float y1, float x2, float y2) : PathCmd + { + public readonly float x1 = x1; + public readonly float y1 = y1; + private readonly float x2 = x2; + private readonly float y2 = y2; + + public override void ApplyCommand(RenderContext context, SKPath path) + { + base.ApplyCommand(context, path); + var pos = context.TranslatePoint(x1, y1); + var pos2 = context.TranslatePoint(x2, y2); + path.QuadTo(pos, pos2); + } + } public class MoveToCmd(float x, float y) : PathCmd { public readonly float x = x; diff --git a/Progrart.Core/Graphics/PathElement.cs b/Progrart.Core/Graphics/PathElement.cs index b358234..e0c90bd 100644 --- a/Progrart.Core/Graphics/PathElement.cs +++ b/Progrart.Core/Graphics/PathElement.cs @@ -9,8 +9,6 @@ namespace Progrart.Core.Graphics public class PathElement : BaseElement { float StrokeWidth; - SKPoint Start; - SKPoint End; SKColorF Color; SKShader? shader = null; public override void SetupProperties(Engine engine) diff --git a/Progrart.sln b/Progrart.sln index d53e088..c85863f 100644 --- a/Progrart.sln +++ b/Progrart.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 18 -VisualStudioVersion = 18.3.11222.16 d18.3 +VisualStudioVersion = 18.3.11222.16 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Progrart", "Progrart\Progrart.csproj", "{EBFA8512-1EA5-4D8C-B4AC-AB5B48A6D568}" EndProject @@ -20,6 +20,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Progrart.Core", "Progrart.Core\Progrart.Core.csproj", "{A691B4C5-777C-4AAA-B402-237372B34F15}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Progrart.Cmd", "Progrart.Cmd\Progrart.Cmd.csproj", "{81803E2B-2EBC-4B11-8B3B-E9278166921B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -52,6 +54,10 @@ Global {A691B4C5-777C-4AAA-B402-237372B34F15}.Debug|Any CPU.Build.0 = Debug|Any CPU {A691B4C5-777C-4AAA-B402-237372B34F15}.Release|Any CPU.ActiveCfg = Release|Any CPU {A691B4C5-777C-4AAA-B402-237372B34F15}.Release|Any CPU.Build.0 = Release|Any CPU + {81803E2B-2EBC-4B11-8B3B-E9278166921B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {81803E2B-2EBC-4B11-8B3B-E9278166921B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {81803E2B-2EBC-4B11-8B3B-E9278166921B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {81803E2B-2EBC-4B11-8B3B-E9278166921B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Progrart/App.axaml.cs b/Progrart/App.axaml.cs index 616bd32..23e44e4 100644 --- a/Progrart/App.axaml.cs +++ b/Progrart/App.axaml.cs @@ -26,6 +26,7 @@ public partial class App : Application EditorProvider.Register("text", "Default Text Editor", typeof(EditorPage)); EditorProvider.Register("image", "Default Image Viewer", typeof(ImageViewPage)); EditorProvider.Register("progrart", "Default Progrart Editor", typeof(ProgrartEditorPage)); + EditorProvider.Register("project", "Progrart Project Editor", typeof(ProjectEditor)); EditorProvider.Register("console", "Console", typeof(Console)); EditorProvider.BindFileType("cs", "text"); EditorProvider.BindFileType("c", "text"); @@ -42,6 +43,7 @@ public partial class App : Application EditorProvider.BindFileType("png", "image"); EditorProvider.BindFileType("bmp", "image"); EditorProvider.BindFileType("jpg", "image"); + EditorProvider.BindFileType("progrart-project", "project"); EditorProvider.BindFileType("wd", "console"); if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { diff --git a/Progrart/Controls/ConfigEditor.axaml b/Progrart/Controls/ConfigEditor.axaml new file mode 100644 index 0000000..a25aa2b --- /dev/null +++ b/Progrart/Controls/ConfigEditor.axaml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + Name + + Output + + + + + + + + + Targets + + + + + + diff --git a/Progrart/Controls/ConfigEditor.axaml.cs b/Progrart/Controls/ConfigEditor.axaml.cs new file mode 100644 index 0000000..863b173 --- /dev/null +++ b/Progrart/Controls/ConfigEditor.axaml.cs @@ -0,0 +1,11 @@ +using Avalonia.Controls; + +namespace Progrart.Controls; + +public partial class ConfigEditor : UserControl +{ + public ConfigEditor() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/Progrart/Controls/ExecuteArgumentItem.axaml b/Progrart/Controls/ExecuteArgumentItem.axaml new file mode 100644 index 0000000..873c3ba --- /dev/null +++ b/Progrart/Controls/ExecuteArgumentItem.axaml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + Key + Value + + + + + + + diff --git a/Progrart/Controls/ExecuteArgumentsEditor.axaml.cs b/Progrart/Controls/ExecuteArgumentsEditor.axaml.cs new file mode 100644 index 0000000..9c5b98d --- /dev/null +++ b/Progrart/Controls/ExecuteArgumentsEditor.axaml.cs @@ -0,0 +1,25 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; +using Progrart.Core; + +namespace Progrart.Controls; + +public partial class ExecuteArgumentsEditor : UserControl +{ + public ExecuteArgumentsEditor() + { + InitializeComponent(); + AddButton.Click += (_, _) => + { + ItemHolder.Children.Add(new ExecuteArgumentItem()); + }; + } + public void LoadArguments(ExecuteArguments args) + { + foreach (var item in args.data) + { + ItemHolder.Children.Add(new ExecuteArgumentItem(item.Key, item.Value)); + } + } +} \ No newline at end of file diff --git a/Progrart/Pages/ProjectEditor.axaml b/Progrart/Pages/ProjectEditor.axaml new file mode 100644 index 0000000..6330496 --- /dev/null +++ b/Progrart/Pages/ProjectEditor.axaml @@ -0,0 +1,37 @@ + + + + + + + + + + + + Output + + + + + + + + + Configurations + + + + + + + diff --git a/Progrart/Pages/ProjectEditor.axaml.cs b/Progrart/Pages/ProjectEditor.axaml.cs new file mode 100644 index 0000000..019f580 --- /dev/null +++ b/Progrart/Pages/ProjectEditor.axaml.cs @@ -0,0 +1,55 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; +using Avalonia.Platform.Storage; +using Progrart.Controls; +using Progrart.Controls.TabSystem; +using Progrart.Core; +using System; +using System.Threading.Tasks; + +namespace Progrart.Pages; + +public partial class ProjectEditor : UserControl, ITabPage, IEditorPage +{ + public ProjectEditor() + { + InitializeComponent(); + AddButton.Click += (_, _) => + { + ConfigurationHolder.Children.Add(new ConfigEditor()); + }; + } + + public void Execute(ExecuteArguments? args = null) + { + } + + public bool IsSameFile(IStorageFile file) + { + return (this.file?.Path == file.Path); + } + IStorageFile? file = null; + public void LoadDocument(IStorageFile file) + { + this.file = file; + } + + public async Task Save() + { + } + + public void SetHost(TabHost host) + { + } + + public void BindButton(TabButton button) + { + button.Title = "Project"; + } + + public bool IsModified() + { + return true; + } +} \ No newline at end of file