Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
}
26 changes: 18 additions & 8 deletions App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,27 @@
*
*/

using LunaDraw.Logic.Utils;

namespace LunaDraw;

public partial class App : Application
{
public App()
{
InitializeComponent();
}
public App(IPreferencesFacade preferencesFacade)
{
InitializeComponent();

var theme = preferencesFacade.Get(AppPreference.AppTheme);
UserAppTheme = theme switch
{
"Light" => AppTheme.Light,
"Dark" => AppTheme.Dark,
_ => AppTheme.Unspecified
};
}

protected override Window CreateWindow(IActivationState? activationState)
{
return new Window(new AppShell());
}
protected override Window CreateWindow(IActivationState? activationState)
{
return new Window(new AppShell());
}
}
3 changes: 2 additions & 1 deletion AppShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:pages="clr-namespace:LunaDraw.Pages"
Title="LunaDraw">
Title="LunaDraw"
Shell.BackgroundColor="Transparent">

<ShellContent
ContentTemplate="{DataTemplate pages:MainPage}"
Expand Down
50 changes: 50 additions & 0 deletions Components/AdvancedSettingsPopup.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8" ?>
<toolkit:Popup xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:toolkit="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
xmlns:viewModels="clr-namespace:LunaDraw.Logic.ViewModels"
xmlns:strings="clr-namespace:LunaDraw.Resources.Strings"
x:Class="LunaDraw.Components.AdvancedSettingsPopup"
x:DataType="viewModels:MainViewModel"
CanBeDismissedByTappingOutsideOfPopup="True"
BackgroundColor="{AppThemeBinding Light={StaticResource White}, Dark={StaticResource Gray900}}">
<VerticalStackLayout Spacing="15">
<Grid ColumnDefinitions="*, Auto"
RowDefinitions="Auto, Auto, Auto"
RowSpacing="15">
<Label Grid.Row="0"
TextColor="{AppThemeBinding Light={StaticResource Gray900}, Dark={StaticResource White}}"
Grid.Column="0"
Text="{x:Static strings:AppResources.Label_ShowLayersPanel}"
VerticalOptions="Center"/>
<Switch Grid.Row="0"
Grid.Column="1"
IsToggled="{Binding ShowLayersPanel}"/>

<Label Grid.Row="1"
TextColor="{AppThemeBinding Light={StaticResource Gray900}, Dark={StaticResource White}}"
Grid.Column="0"
Text="{x:Static strings:AppResources.Label_ShowButtonLabels}"
VerticalOptions="Center"/>
<Switch Grid.Row="1"
Grid.Column="1"
IsToggled="{Binding ShowButtonLabels}"/>

<Label Grid.Row="2"
TextColor="{AppThemeBinding Light={StaticResource Gray900}, Dark={StaticResource White}}"
Grid.Column="0"
Text="Theme"
VerticalOptions="Center"/>
<Picker Grid.Row="2"
Grid.Column="1"
ItemsSource="{Binding AvailableThemes}"
SelectedItem="{Binding SelectedTheme}"
TextColor="{AppThemeBinding Light={StaticResource Gray900}, Dark={StaticResource White}}"
Title="Select Theme"/>
</Grid>

<Button Text="{x:Static strings:AppResources.Label_Close}"
Clicked="OnCloseClicked"
Margin="0,10,0,0"/>
</VerticalStackLayout>
</toolkit:Popup>
41 changes: 41 additions & 0 deletions Components/AdvancedSettingsPopup.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2025 CodeSoupCafe LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
*/

using CommunityToolkit.Maui.Views;
using LunaDraw.Logic.ViewModels;

namespace LunaDraw.Components;

public partial class AdvancedSettingsPopup : Popup
{
public AdvancedSettingsPopup(MainViewModel viewModel)
{
InitializeComponent();
BindingContext = viewModel;
}

private void OnCloseClicked(object sender, EventArgs e)
{
this.CloseAsync();
}
}
207 changes: 103 additions & 104 deletions Components/BrushPreviewControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,136 +27,135 @@
using SkiaSharp.Views.Maui;
using SkiaSharp.Views.Maui.Controls;

namespace LunaDraw.Components
namespace LunaDraw.Components;

public class BrushPreviewControl : SKCanvasView
{
public class BrushPreviewControl : SKCanvasView
{
public static readonly BindableProperty BrushShapeProperty =
BindableProperty.Create(nameof(BrushShape), typeof(BrushShape), typeof(BrushPreviewControl), null, propertyChanged: OnPropertyChanged);
public static readonly BindableProperty BrushShapeProperty =
BindableProperty.Create(nameof(BrushShape), typeof(BrushShape), typeof(BrushPreviewControl), null, propertyChanged: OnPropertyChanged);

public BrushShape BrushShape
{
get => (BrushShape)GetValue(BrushShapeProperty);
set => SetValue(BrushShapeProperty, value);
}
public BrushShape BrushShape
{
get => (BrushShape)GetValue(BrushShapeProperty);
set => SetValue(BrushShapeProperty, value);
}

public static readonly BindableProperty ColorProperty =
BindableProperty.Create(nameof(Color), typeof(Color), typeof(BrushPreviewControl), Colors.Black, propertyChanged: OnPropertyChanged);
public static readonly BindableProperty ColorProperty =
BindableProperty.Create(nameof(Color), typeof(Color), typeof(BrushPreviewControl), Colors.Black, propertyChanged: OnPropertyChanged);

public Color Color
{
get => (Color)GetValue(ColorProperty);
set => SetValue(ColorProperty, value);
}
public Color Color
{
get => (Color)GetValue(ColorProperty);
set => SetValue(ColorProperty, value);
}

public static readonly BindableProperty StrokeColorProperty =
BindableProperty.Create(nameof(StrokeColor), typeof(SKColor), typeof(BrushPreviewControl), SKColors.Empty, propertyChanged: OnPropertyChanged);
public static readonly BindableProperty StrokeColorProperty =
BindableProperty.Create(nameof(StrokeColor), typeof(SKColor), typeof(BrushPreviewControl), SKColors.Empty, propertyChanged: OnPropertyChanged);

public SKColor StrokeColor
{
get => (SKColor)GetValue(StrokeColorProperty);
set => SetValue(StrokeColorProperty, value);
}
public SKColor StrokeColor
{
get => (SKColor)GetValue(StrokeColorProperty);
set => SetValue(StrokeColorProperty, value);
}

public static readonly BindableProperty FillColorProperty =
BindableProperty.Create(nameof(FillColor), typeof(SKColor?), typeof(BrushPreviewControl), null, propertyChanged: OnPropertyChanged);
public static readonly BindableProperty FillColorProperty =
BindableProperty.Create(nameof(FillColor), typeof(SKColor?), typeof(BrushPreviewControl), null, propertyChanged: OnPropertyChanged);

public SKColor? FillColor
{
get => (SKColor?)GetValue(FillColorProperty);
set => SetValue(FillColorProperty, value);
}
public SKColor? FillColor
{
get => (SKColor?)GetValue(FillColorProperty);
set => SetValue(FillColorProperty, value);
}

public static readonly BindableProperty IsGlowEnabledProperty =
BindableProperty.Create(nameof(IsGlowEnabled), typeof(bool), typeof(BrushPreviewControl), false, propertyChanged: OnPropertyChanged);
public static readonly BindableProperty IsGlowEnabledProperty =
BindableProperty.Create(nameof(IsGlowEnabled), typeof(bool), typeof(BrushPreviewControl), false, propertyChanged: OnPropertyChanged);

public bool IsGlowEnabled
{
get => (bool)GetValue(IsGlowEnabledProperty);
set => SetValue(IsGlowEnabledProperty, value);
}
public bool IsGlowEnabled
{
get => (bool)GetValue(IsGlowEnabledProperty);
set => SetValue(IsGlowEnabledProperty, value);
}

public static readonly BindableProperty GlowColorProperty =
BindableProperty.Create(nameof(GlowColor), typeof(SKColor), typeof(BrushPreviewControl), SKColors.Yellow, propertyChanged: OnPropertyChanged);
public static readonly BindableProperty GlowColorProperty =
BindableProperty.Create(nameof(GlowColor), typeof(SKColor), typeof(BrushPreviewControl), SKColors.Yellow, propertyChanged: OnPropertyChanged);

public SKColor GlowColor
{
get => (SKColor)GetValue(GlowColorProperty);
set => SetValue(GlowColorProperty, value);
}
public SKColor GlowColor
{
get => (SKColor)GetValue(GlowColorProperty);
set => SetValue(GlowColorProperty, value);
}

public static readonly BindableProperty GlowRadiusProperty =
BindableProperty.Create(nameof(GlowRadius), typeof(float), typeof(BrushPreviewControl), 10f, propertyChanged: OnPropertyChanged);
public static readonly BindableProperty GlowRadiusProperty =
BindableProperty.Create(nameof(GlowRadius), typeof(float), typeof(BrushPreviewControl), 10f, propertyChanged: OnPropertyChanged);

public float GlowRadius
{
get => (float)GetValue(GlowRadiusProperty);
set => SetValue(GlowRadiusProperty, value);
}
public float GlowRadius
{
get => (float)GetValue(GlowRadiusProperty);
set => SetValue(GlowRadiusProperty, value);
}

private static void OnPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
((BrushPreviewControl)bindable).InvalidateSurface();
}
private static void OnPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
((BrushPreviewControl)bindable).InvalidateSurface();
}

protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
{
base.OnPaintSurface(e);
protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
{
base.OnPaintSurface(e);

var canvas = e.Surface.Canvas;
canvas.Clear();
var canvas = e.Surface.Canvas;
canvas.Clear();

if (BrushShape?.Path == null) return;
if (BrushShape?.Path == null) return;

var info = e.Info;
var center = new SKPoint(info.Width / 2, info.Height / 2);
var info = e.Info;
var center = new SKPoint(info.Width / 2, info.Height / 2);

// Calculate scale to fit in the view (with padding)
var bounds = BrushShape.Path.TightBounds;
float maxDim = Math.Max(bounds.Width, bounds.Height);
if (maxDim <= 0) maxDim = 1;
// Calculate scale to fit in the view (with padding)
var bounds = BrushShape.Path.TightBounds;
float maxDim = Math.Max(bounds.Width, bounds.Height);
if (maxDim <= 0) maxDim = 1;

float availableSize = Math.Min(info.Width, info.Height) * 0.6f; // 60% padding
float scale = availableSize / maxDim;
float availableSize = Math.Min(info.Width, info.Height) * 0.6f; // 60% padding
float scale = availableSize / maxDim;

SKColor drawColor;
if (StrokeColor != SKColors.Empty)
{
drawColor = StrokeColor;
}
else
{
drawColor = new SKColor((byte)(Color.Red * 255), (byte)(Color.Green * 255), (byte)(Color.Blue * 255), (byte)(Color.Alpha * 255));
}
SKColor drawColor;
if (StrokeColor != SKColors.Empty)
{
drawColor = StrokeColor;
}
else
{
drawColor = new SKColor((byte)(Color.Red * 255), (byte)(Color.Green * 255), (byte)(Color.Blue * 255), (byte)(Color.Alpha * 255));
}

canvas.Save();
canvas.Translate(center.X, center.Y);
canvas.Scale(scale);
// Center the shape itself (if not centered at 0,0)
canvas.Translate(-bounds.MidX, -bounds.MidY);
canvas.Save();
canvas.Translate(center.X, center.Y);
canvas.Scale(scale);
// Center the shape itself (if not centered at 0,0)
canvas.Translate(-bounds.MidX, -bounds.MidY);

// Draw Glow if enabled
if (IsGlowEnabled)
{
using var glowPaint = new SKPaint
{
Style = SKPaintStyle.StrokeAndFill,
Color = GlowColor,
IsAntialias = true,
MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, GlowRadius)
};
canvas.DrawPath(BrushShape.Path, glowPaint);
}

using var paint = new SKPaint
// Draw Glow if enabled
if (IsGlowEnabled)
{
using var glowPaint = new SKPaint
{
Style = SKPaintStyle.Fill,
Color = drawColor,
IsAntialias = true
Style = SKPaintStyle.StrokeAndFill,
Color = GlowColor,
IsAntialias = true,
MaskFilter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, GlowRadius)
};

canvas.DrawPath(BrushShape.Path, paint);
canvas.Restore();
canvas.DrawPath(BrushShape.Path, glowPaint);
}

using var paint = new SKPaint
{
Style = SKPaintStyle.Fill,
Color = drawColor,
IsAntialias = true
};

canvas.DrawPath(BrushShape.Path, paint);
canvas.Restore();
}
}
Loading