Ionite
1 year ago
8 changed files with 271 additions and 41 deletions
@ -0,0 +1,94 @@
|
||||
using System.Diagnostics.CodeAnalysis; |
||||
using Avalonia; |
||||
using Avalonia.Controls; |
||||
using Avalonia.Media; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Controls; |
||||
|
||||
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] |
||||
public class CheckerboardBorder : Control |
||||
{ |
||||
public static readonly StyledProperty<byte> GridCellSizeProperty = AvaloniaProperty.Register< |
||||
AdvancedImageBox, |
||||
byte |
||||
>(nameof(GridCellSize), 15); |
||||
|
||||
public byte GridCellSize |
||||
{ |
||||
get => GetValue(GridCellSizeProperty); |
||||
set => SetValue(GridCellSizeProperty, value); |
||||
} |
||||
|
||||
public static readonly StyledProperty<ISolidColorBrush> GridColorProperty = |
||||
AvaloniaProperty.Register<AdvancedImageBox, ISolidColorBrush>( |
||||
nameof(GridColor), |
||||
SolidColorBrush.Parse("#181818") |
||||
); |
||||
|
||||
/// <summary> |
||||
/// Gets or sets the color used to create the checkerboard style background |
||||
/// </summary> |
||||
public ISolidColorBrush GridColor |
||||
{ |
||||
get => GetValue(GridColorProperty); |
||||
set => SetValue(GridColorProperty, value); |
||||
} |
||||
|
||||
public static readonly StyledProperty<ISolidColorBrush> GridColorAlternateProperty = |
||||
AvaloniaProperty.Register<AdvancedImageBox, ISolidColorBrush>( |
||||
nameof(GridColorAlternate), |
||||
SolidColorBrush.Parse("#252525") |
||||
); |
||||
|
||||
/// <summary> |
||||
/// Gets or sets the color used to create the checkerboard style background |
||||
/// </summary> |
||||
public ISolidColorBrush GridColorAlternate |
||||
{ |
||||
get => GetValue(GridColorAlternateProperty); |
||||
set => SetValue(GridColorAlternateProperty, value); |
||||
} |
||||
|
||||
static CheckerboardBorder() |
||||
{ |
||||
AffectsRender<CheckerboardBorder>(GridCellSizeProperty); |
||||
AffectsRender<CheckerboardBorder>(GridColorProperty); |
||||
AffectsRender<CheckerboardBorder>(GridColorAlternateProperty); |
||||
} |
||||
|
||||
/// <inheritdoc /> |
||||
public override void Render(DrawingContext context) |
||||
{ |
||||
var size = GridCellSize; |
||||
|
||||
var square1Drawing = new GeometryDrawing |
||||
{ |
||||
Brush = GridColorAlternate, |
||||
Geometry = new RectangleGeometry(new Rect(0.0, 0.0, size, size)) |
||||
}; |
||||
|
||||
var square2Drawing = new GeometryDrawing |
||||
{ |
||||
Brush = GridColorAlternate, |
||||
Geometry = new RectangleGeometry(new Rect(size, size, size, size)) |
||||
}; |
||||
|
||||
var drawingGroup = new DrawingGroup { Children = { square1Drawing, square2Drawing } }; |
||||
|
||||
var tileBrush = new DrawingBrush(drawingGroup) |
||||
{ |
||||
AlignmentX = AlignmentX.Left, |
||||
AlignmentY = AlignmentY.Top, |
||||
DestinationRect = new RelativeRect(new Size(2 * size, 2 * size), RelativeUnit.Absolute), |
||||
Stretch = Stretch.None, |
||||
TileMode = TileMode.Tile, |
||||
}; |
||||
|
||||
context.FillRectangle(GridColor, Bounds); |
||||
// context.DrawRectangle(new Pen(Brushes.Blue), new Rect(0.5, 0.5, Bounds.Width - 1.0, Bounds.Height - 1.0)); |
||||
|
||||
context.FillRectangle(tileBrush, Bounds); |
||||
|
||||
// base.Render(context); |
||||
} |
||||
} |
@ -0,0 +1,20 @@
|
||||
using System; |
||||
using System.Numerics; |
||||
|
||||
namespace StabilityMatrix.Avalonia.Models; |
||||
|
||||
public class DirectionalNavigationEventArgs : EventArgs |
||||
{ |
||||
private Vector2 Direction { get; } |
||||
|
||||
public DirectionalNavigationEventArgs(Vector2 direction) |
||||
{ |
||||
Direction = direction; |
||||
} |
||||
|
||||
public static DirectionalNavigationEventArgs Up => new(new Vector2(0, -1)); |
||||
public static DirectionalNavigationEventArgs Down => new(new Vector2(0, 1)); |
||||
|
||||
public bool IsNext => Direction.X > 0 || Direction.Y > 0; |
||||
public bool IsPrevious => Direction.X < 0 || Direction.Y < 0; |
||||
} |
@ -1,19 +1,60 @@
|
||||
<ResourceDictionary xmlns="https://github.com/avaloniaui" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> |
||||
<!-- Add Resources Here --> |
||||
<ExperimentalAcrylicMaterial |
||||
x:Key="ThemeDarkAcrylicMaterial" |
||||
FallbackColor="{DynamicResource ThemeBackgroundColor}" |
||||
TintColor="Black" |
||||
TintOpacity="0.78" |
||||
MaterialOpacity="0.9" |
||||
BackgroundSource="Digger" /> |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:sty="clr-namespace:FluentAvalonia.Styling;assembly=FluentAvalonia"> |
||||
|
||||
<ExperimentalAcrylicMaterial |
||||
x:Key="ThemeTransparentAcrylicMaterial" |
||||
FallbackColor="{DynamicResource ThemeBackgroundColor}" |
||||
TintColor="Black" |
||||
TintOpacity="0.7" |
||||
MaterialOpacity="0.5" |
||||
BackgroundSource="Digger" /> |
||||
<ResourceDictionary.ThemeDictionaries> |
||||
<ResourceDictionary x:Key="Default"> |
||||
<ExperimentalAcrylicMaterial |
||||
x:Key="ThemeDarkAcrylicMaterial" |
||||
FallbackColor="{DynamicResource ThemeBackgroundColor}" |
||||
TintColor="Black" |
||||
TintOpacity="0.78" |
||||
MaterialOpacity="0.9" |
||||
BackgroundSource="Digger" /> |
||||
|
||||
<ExperimentalAcrylicMaterial |
||||
x:Key="ThemeTransparentAcrylicMaterial" |
||||
FallbackColor="{DynamicResource ThemeBackgroundColor}" |
||||
TintColor="{DynamicResource ThemeBackgroundColor}" |
||||
TintOpacity="0.7" |
||||
MaterialOpacity="0.5" |
||||
BackgroundSource="Digger" /> |
||||
</ResourceDictionary> |
||||
|
||||
<ResourceDictionary x:Key="Dark"> |
||||
<ExperimentalAcrylicMaterial |
||||
x:Key="ThemeDarkAcrylicMaterial" |
||||
FallbackColor="{DynamicResource ThemeBackgroundColor}" |
||||
TintColor="Black" |
||||
TintOpacity="0.78" |
||||
MaterialOpacity="0.9" |
||||
BackgroundSource="Digger" /> |
||||
|
||||
<ExperimentalAcrylicMaterial |
||||
x:Key="ThemeTransparentAcrylicMaterial" |
||||
FallbackColor="{DynamicResource ThemeBackgroundColor}" |
||||
TintColor="Black" |
||||
TintOpacity="0.7" |
||||
MaterialOpacity="0.5" |
||||
BackgroundSource="Digger" /> |
||||
</ResourceDictionary> |
||||
|
||||
<ResourceDictionary x:Key="{x:Static sty:FluentAvaloniaTheme.HighContrastTheme}"> |
||||
<ExperimentalAcrylicMaterial |
||||
x:Key="ThemeDarkAcrylicMaterial" |
||||
FallbackColor="{DynamicResource ThemeBackgroundColor}" |
||||
TintColor="Black" |
||||
TintOpacity="0.78" |
||||
MaterialOpacity="0.9" |
||||
BackgroundSource="Digger" /> |
||||
|
||||
<ExperimentalAcrylicMaterial |
||||
x:Key="ThemeTransparentAcrylicMaterial" |
||||
FallbackColor="{DynamicResource ThemeBackgroundColor}" |
||||
TintColor="Black" |
||||
TintOpacity="0.7" |
||||
MaterialOpacity="0.5" |
||||
BackgroundSource="Digger" /> |
||||
</ResourceDictionary> |
||||
</ResourceDictionary.ThemeDictionaries> |
||||
</ResourceDictionary> |
||||
|
Loading…
Reference in new issue