Skip to content

Commit

Permalink
Merge branch 'main' of [email protected]:b-editor/beutl.git into main
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Aug 15, 2023
2 parents b33eb38 + b62fbde commit 4277ea8
Show file tree
Hide file tree
Showing 35 changed files with 1,310 additions and 464 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dotnet.defaultSolution": "Beutl.sln"
}
2 changes: 2 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<PackageVersion Include="FluentAvaloniaUI" Version="2.0.1" />
<PackageVersion Include="FluentIcons.FluentAvalonia" Version="1.1.209" />
<PackageVersion Include="FluentTextTable" Version="1.0.0" />
<PackageVersion Include="ILGPU" Version="1.4.0" />
<PackageVersion Include="Kokuban" Version="0.2.0" />
<PackageVersion Include="Kurukuru" Version="1.4.2" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
Expand All @@ -29,6 +30,7 @@
<PackageVersion Include="Microsoft.Extensions.FileSystemGlobbing" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.ObjectPool" Version="7.0.10" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
<PackageVersion Include="Nito.AsyncEx" Version="5.1.2" />
<PackageVersion Include="NuGet.ProjectModel" Version="6.7.0" />
Expand Down
44 changes: 39 additions & 5 deletions src/Beutl.Controls/PropertyEditors/ColorEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public class ColorEditor : PropertyEditor
(o, v) => o.Value = v,
defaultBindingMode: BindingMode.TwoWay);

public static readonly StyledProperty<bool> IsLivePreviewEnabledProperty =
AvaloniaProperty.Register<ColorEditor, bool>(nameof(IsLivePreviewEnabled));

private Color _oldValue;
private Color _value;

public Color Value
Expand All @@ -25,24 +29,54 @@ public Color Value
set => SetAndRaise(ValueProperty, ref _value, value);
}

public bool IsLivePreviewEnabled
{
get => GetValue(IsLivePreviewEnabledProperty);
set => SetValue(IsLivePreviewEnabledProperty, value);
}

protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
ColorPickerButton button = e.NameScope.Get<ColorPickerButton>("PART_ColorPickerButton");
button.ColorChanged += OnColorChanged;
button.FlyoutOpened += OnFlyoutOpened;
button.FlyoutClosed += OnFlyoutClosed;
button.FlyoutConfirmed += OnFlyoutConfirmed;
}

private void OnFlyoutOpened(ColorPickerButton sender, EventArgs args)
{
if (IsLivePreviewEnabled)
_oldValue = _value;
}

private void OnFlyoutClosed(ColorPickerButton sender, EventArgs args)
{
if (IsLivePreviewEnabled)
{
RaiseEvent(new PropertyEditorValueChangedEventArgs<Color>(
Value, _oldValue, ValueChangedEvent));
}
}

private void OnFlyoutConfirmed(ColorPickerButton sender, ColorButtonColorChangedEventArgs args)
{
Value = args.NewColor.GetValueOrDefault();
RaiseEvent(new PropertyEditorValueChangedEventArgs<Color>(
Value, args.OldColor.GetValueOrDefault(), ValueChangedEvent));
if (!IsLivePreviewEnabled)
{
Value = args.NewColor.GetValueOrDefault();
RaiseEvent(new PropertyEditorValueChangedEventArgs<Color>(
Value, args.OldColor.GetValueOrDefault(), ValueChangedEvent));
}
}

private void OnColorChanged(ColorPickerButton sender, ColorButtonColorChangedEventArgs args)
{
RaiseEvent(new PropertyEditorValueChangedEventArgs<Color>(
args.NewColor.GetValueOrDefault(), args.OldColor.GetValueOrDefault(), ValueChangingEvent));
if (IsLivePreviewEnabled)
{
Value = args.NewColor.GetValueOrDefault();
RaiseEvent(new PropertyEditorValueChangedEventArgs<Color>(
args.NewColor.GetValueOrDefault(), args.OldColor.GetValueOrDefault(), ValueChangingEvent));
}
}
}
4 changes: 4 additions & 0 deletions src/Beutl.Controls/Styling/PropertyEditors/ColorEditor.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
Grid.Column="1"
Margin="4,2"
HorizontalAlignment="Right"
CustomPaletteColors="{DynamicResource PaletteColors}"
IsEnabled="{TemplateBinding IsReadOnly, Converter={x:Static BoolConverters.Not}}"
ShowAcceptDismissButtons="{TemplateBinding IsLivePreviewEnabled, Converter={x:Static BoolConverters.Not}}"
UseColorPalette="True"
Color="{Binding Value, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />

Expand Down Expand Up @@ -73,7 +75,9 @@
Grid.Column="1"
Margin="4,2"
HorizontalAlignment="Right"
CustomPaletteColors="{DynamicResource PaletteColors}"
IsEnabled="{TemplateBinding IsReadOnly, Converter={x:Static BoolConverters.Not}}"
ShowAcceptDismissButtons="{TemplateBinding IsLivePreviewEnabled, Converter={x:Static BoolConverters.Not}}"
UseColorPalette="True"
Color="{Binding Value, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="{StaticResource TextBoxIconFontSize}"
Foreground="{StaticResource TextControlButtonForeground}"
Foreground="{DynamicResource TextControlButtonForeground}"
Symbol="Open" />
</Border>
</ControlTemplate>
Expand Down
5 changes: 2 additions & 3 deletions src/Beutl.Engine/Beutl.Engine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
</PropertyGroup>
<ItemGroup>
<Compile Remove="Graphics\VertexMode.cs" />
<Compile Remove="Media\Cmyk.cs" />
<Compile Remove="Media\Hsv.cs" />
<Compile Remove="Media\YCbCr.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Beutl.Core\Beutl.Core.csproj" />
Expand All @@ -18,6 +15,8 @@
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ILGPU" />
<PackageReference Include="Microsoft.Extensions.ObjectPool" />
<PackageReference Include="OpenCvSharp4" />
<PackageReference Include="OpenCvSharp4.runtime.centos7-x64" />
<PackageReference Include="OpenCvSharp4.runtime.osx.10.15-x64" />
Expand Down
49 changes: 41 additions & 8 deletions src/Beutl.Engine/Graphics/ColorMatrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ public static ColorMatrix CreateLuminanceToAlpha()
return CreateFromSpan(span);
}

public static ColorMatrix CreateBrightness(float amount)
{
Span<float> span = stackalloc float[20];
CreateBrightness(amount, span);

return CreateFromSpan(span);
}

public float[] ToArray()
{
return new float[]
Expand All @@ -146,15 +154,34 @@ public float[] ToArray()
};
}

internal float[] ToArrayForSkia()
internal void ToArrayForSkia(float[] array)
{
return new float[]
{
M11, M12, M13, M14, M15 * 255,
M21, M22, M23, M24, M25 * 255,
M31, M32, M33, M34, M35 * 255,
M41, M42, M43, M44, M45 * 255,
};
if (array.Length != 20)
throw new ArgumentException("配列の長さが無効です。");

array[0] = M11;
array[1] = M12;
array[2] = M13;
array[3] = M14;
array[4] = M15 * 255;

array[5] = M21;
array[6] = M22;
array[7] = M23;
array[8] = M24;
array[9] = M25 * 255;

array[10] = M31;
array[11] = M32;
array[12] = M33;
array[13] = M34;
array[14] = M35 * 255;

array[15] = M41;
array[16] = M42;
array[17] = M43;
array[18] = M44;
array[19] = M45 * 255;
}

public static bool operator ==(in ColorMatrix value1, in ColorMatrix value2) => value1.Equals(value2);
Expand Down Expand Up @@ -300,6 +327,12 @@ internal static void CreateLuminanceToAlphaMatrix(Span<float> span)
span[17] = 0.0721F;
}

internal static void CreateBrightness(float amount, Span<float> span)
{
span[0] = span[6] = span[12] = amount;
span[18] = 1;
}

internal static void ToSkiaColorMatrix(Span<float> array)
{
array[4] *= 255;
Expand Down
Loading

0 comments on commit 4277ea8

Please sign in to comment.