Skip to content

Commit

Permalink
Добавлены изображения
Browse files Browse the repository at this point in the history
  • Loading branch information
ComradeAkei committed Nov 11, 2023
1 parent 1040862 commit 64b7d6e
Show file tree
Hide file tree
Showing 130 changed files with 158 additions and 1,497 deletions.
11 changes: 11 additions & 0 deletions ElementGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Avalonia.Media;
using Avalonia.Styling;
using Avalonia.Controls.Primitives;
using Avalonia.Media.Imaging;

namespace Xamlade;

Expand Down Expand Up @@ -70,6 +71,16 @@ public static void SetDefaultValues(JControl element)
((jTextBlock)element).Foreground = Brushes.White;
}
break;
case ControlType.Image:
{

((jImage)element).Source = new Bitmap("assets/Xamlade.png");
((jImage)element).Width = 400;
((jImage)element).Height = 400;
((jImage)element).jImageSource = @"assets/Xamlade.png";
((jImage)element).Background = Brushes.Blue;
}
break;
case ControlType.ToggleButton:
{
// ((jTextBlock)element).Background = Brushes.Blue;
Expand Down
4 changes: 4 additions & 0 deletions MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
PropertyChanged="StrictModeEnabled_OnPropertyChanged" VerticalAlignment="Center" HorizontalAlignment="Center"
VerticalContentAlignment="Center"/>


</StackPanel>

<!-- Левая панель с иерархией проекта -->
Expand Down Expand Up @@ -55,6 +56,8 @@
Margin="10,0,10,10" />
<Button Name="GenerateToggleButton" Content="ToggleButton" Click="GenerateElement"
Margin="10,0,10,10" />
<Button Name="GenerateImage" Background="Chartreuse" Content="Image" Click="GenerateElement"
Margin="10,0,10,10" />
</StackPanel>
</TabItem>

Expand All @@ -79,6 +82,7 @@
<xamlade:jCanvas.Styles>
<FluentTheme/>
</xamlade:jCanvas.Styles>
<!-- <Image Source="assets/Xamlade.png" Width="500" Height="500"/> -->
<!-- Здесь наступает власть объектов JControl -->
</xamlade:jCanvas>

Expand Down
57 changes: 53 additions & 4 deletions MainWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Avalonia.Controls.Primitives;
using Avalonia.Layout;
using Avalonia.Gif;
using Avalonia.Media.Imaging;
using AvaloniaColorPicker;

namespace Xamlade;
Expand Down Expand Up @@ -194,7 +195,7 @@ private void XAMLIZE(object? sender, RoutedEventArgs? e)
"OpacityMask", "Bounds", "Cursor", "Tag", "ContextFlyout", "ContextMenu", "FocusAdorner", "IsItemsHost",
"Children", "jChildren", "FontFamily", "TextDecoration", "ContentTemplate", "FlowDirection", "Inlines",
"TextLayout",
"XAMLRating", "XAMLPiece", "CanPaste", "CanUndo"
"XAMLRating", "XAMLPiece", "CanPaste", "CanUndo","jImageSource"
};

private void ShowProperties()
Expand Down Expand Up @@ -297,7 +298,35 @@ private void OnjControlReleased(object? sender, PointerReleasedEventArgs e)
element.IsPressed = false;
}


private async void OnChooseImageClick(object? sender, RoutedEventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Title = "Выберите изображение";
dialog.AllowMultiple = false;
dialog.Filters.Add(new FileDialogFilter
{
Name = "Изображения",
Extensions = { "png", "jpg", "jpeg", "gif", "bmp" }
});
Task<string[]> task = dialog.ShowAsync(this);

// Дожидаемся завершения задачи (await)
string[] result = await task;

// Обрабатываем результат
if (result != null && result.Length > 0)
{
string fileName = Path.GetFileName(result[0]);
string targetFilePath = Path.Combine("assets", fileName);
File.Copy(result[0], targetFilePath, true);
((jImage)selectedTreeItem.element).jImageSource = @"assets/" + fileName;
((jImage)selectedTreeItem.element).Source = new Bitmap(((jImage)selectedTreeItem.element).jImageSource);
}
else
{
return;
}
}
private void OnEnumPropertyChanged(object? sender, SelectionChangedEventArgs e)
{
var comboBox = sender as ComboBox;
Expand Down Expand Up @@ -413,12 +442,30 @@ private void OnPropertyChanged(object? sender, KeyEventArgs e)

private async void RUN_WINDOW(object? sender, RoutedEventArgs e)
{
CopyAssets();
LoadingGif.IsVisible = true;
await ExecuteLinuxCommandAsync("XamladeDemo/BUILD.sh");

await ExecuteLinuxCommandAsync(@"XamladeDemo/BUILD.sh");
LoadingGif.IsVisible = false;
await ExecuteLinuxCommandAsync("XamladeDemo/RUN.sh");
await ExecuteLinuxCommandAsync(@"XamladeDemo/RUN.sh");
}


public static void CopyAssets()
{
string[] files = Directory.GetFiles(@"assets");
string targetDirectory = @"XamladeDemo/assets";
if (!Directory.Exists(targetDirectory))
{
Directory.CreateDirectory(targetDirectory);
}
foreach (string file in files)
{
string fileName = Path.GetFileName(file);
string destFile = Path.Combine(targetDirectory, fileName);
File.Copy(file, destFile, true);
}
}
public static async Task<string> ExecuteLinuxCommandAsync(string command)
{
using (Process process = new Process())
Expand Down Expand Up @@ -448,4 +495,6 @@ public static async Task<string> ExecuteLinuxCommandAsync(string command)
private void DEBUG(object? sender, RoutedEventArgs e)
{
}


}
17 changes: 17 additions & 0 deletions Miscellaneous.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Avalonia.Data;
using Avalonia.Layout;
using Avalonia.Media;
using Avalonia.Media.Imaging;
using AvaloniaColorPicker;

namespace Xamlade;
Expand Down Expand Up @@ -134,6 +135,22 @@ public void AddPropItem(string name, object? value,Type type)
DockPanel.SetDock(_propElement, Dock.Right);
dockPanel.Children.Add(_propElement);

}
else if ( type == typeof(IImage))
{
var _propElement = new Button();
_propElement.Content = "Выбрать";
_propElement.HorizontalAlignment = HorizontalAlignment.Right;
_propElement.Foreground = GetColor("#88F1FF");
_propElement.FontWeight = FontWeight.DemiBold;
_propElement.HorizontalContentAlignment = HorizontalAlignment.Right;
_propElement.VerticalAlignment = VerticalAlignment.Center;
_propElement.VerticalContentAlignment = VerticalAlignment.Bottom;
_propElement.Margin = new Thickness(5, 0, 0, 0);
_propElement.Click += OnChooseImageClick;
DockPanel.SetDock(_propElement, Dock.Right);
dockPanel.Children.Add(_propElement);

}
else
{
Expand Down
13 changes: 9 additions & 4 deletions XAMLGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ public static string GetProperties(JControl element)
foreach (var prop in props)
{
if((element.Name == "MainCanvas") && prop.Name is "Width" or "Height") continue;
if(!MainWindow.ExcludedWords.Contains(prop.Name))
if(prop.GetValue(element)?.ToString() != prop.GetValue(DefaultObject)?.ToString()
&& prop.GetValue(element)!=null)
getProperties+=($"{prop.Name}=\"{prop.GetValue(element)}\" ");
if (!MainWindow.ExcludedWords.Contains(prop.Name))
{
if (prop.Name == "Source")
getProperties += ($"{prop.Name}=\"{((jImage)element).jImageSource}\" ");
else if (prop.Name == "Background" && element is jImage) continue;
else if (prop.GetValue(element)?.ToString() != prop.GetValue(DefaultObject)?.ToString()
&& prop.GetValue(element) != null)
getProperties += ($"{prop.Name}=\"{prop.GetValue(element)}\" ");
}
}

if (element.Name == "MainCanvas")
Expand Down
15 changes: 15 additions & 0 deletions Xamlade.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@
<HintPath>Avalonia.GIF\Avalonia.Gif.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<!-- Добавление всех файлов из папки assets в ресурсы -->
<AvaloniaResource Include="assets\**\*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</AvaloniaResource>
</ItemGroup>

<ItemGroup>
<MySourceFiles Include="assets\**\*.*"/>
</ItemGroup>

<Target Name="CopyAssets" BeforeTargets="Build">
<MakeDir Directories="$(OutputPath)\assets" />
<Copy SourceFiles="@(MySourceFiles)" DestinationFolder="$(OutputPath)\assets" SkipUnchangedFiles="true" />
</Target>

</Project>
Binary file removed bin/Debug/net7.0/Avalonia.Base.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Avalonia.Controls.ColorPicker.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Avalonia.Controls.DataGrid.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Avalonia.Controls.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Avalonia.DesignerSupport.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Avalonia.Desktop.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Avalonia.Diagnostics.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Avalonia.Dialogs.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Avalonia.Fonts.Inter.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Avalonia.FreeDesktop.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Avalonia.Markup.Xaml.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Avalonia.Markup.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Avalonia.Metal.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Avalonia.MicroCom.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Avalonia.Native.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Avalonia.OpenGL.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Avalonia.Remote.Protocol.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Avalonia.Skia.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Avalonia.Themes.Fluent.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Avalonia.Themes.Simple.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Avalonia.Win32.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Avalonia.X11.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Avalonia.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/HarfBuzzSharp.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Material.Avalonia.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Material.Colors.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Material.Ripple.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Material.Styles.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/MicroCom.Runtime.dll
Binary file not shown.
Binary file not shown.
Binary file removed bin/Debug/net7.0/Microsoft.CodeAnalysis.CSharp.dll
Binary file not shown.
Binary file not shown.
Binary file removed bin/Debug/net7.0/Microsoft.CodeAnalysis.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Microsoft.Win32.SystemEvents.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/SkiaSharp.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/System.Drawing.Common.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/System.IO.Pipelines.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/System.Reactive.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Tmds.DBus.Protocol.dll
Binary file not shown.
Binary file removed bin/Debug/net7.0/Xamlade
Binary file not shown.
Loading

0 comments on commit 64b7d6e

Please sign in to comment.