Skip to content

Commit

Permalink
要素の色を変更できるようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
yuto-trd committed Aug 21, 2023
1 parent 603b8a7 commit 8a35534
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Beutl.Language/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Beutl.Language/Strings.ja.resx
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,9 @@ b-editorがダウンロードURLを管理します。</value>
<data name="Number_of_Layers" xml:space="preserve">
<value>レイヤーの数</value>
</data>
<data name="ChangeColor" xml:space="preserve">
<value>色を変更</value>
</data>
<data name="EditAnimationInInlineView" xml:space="preserve">
<value>インライン表示でアニメーションを編集</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions src/Beutl.Language/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,9 @@ and b-editor maintains the download URL.</value>
<data name="Number_of_Layers" xml:space="preserve">
<value>Number of Layers</value>
</data>
<data name="ChangeColor" xml:space="preserve">
<value>Change color</value>
</data>
<data name="EditAnimationInInlineView" xml:space="preserve">
<value>Edit animation in inline view</value>
</data>
Expand Down
1 change: 1 addition & 0 deletions src/Beutl/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<KeyGesture x:Key="StartKeyGesture">Home</KeyGesture>
<KeyGesture x:Key="EndKeyGesture">End</KeyGesture>
<KeyGesture x:Key="LayerDeleteKeyGesture">Ctrl+Delete</KeyGesture>
<KeyGesture x:Key="RenameKeyGesture">F2</KeyGesture>
</ResourceDictionary>
</Application.Resources>
<Application.Styles>
Expand Down
8 changes: 8 additions & 0 deletions src/Beutl/Views/ElementView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@
<icons:SymbolIconSource Symbol="Delete" />
</ui:MenuFlyoutItem.IconSource>
</ui:MenuFlyoutItem>
<ui:MenuFlyoutItem Click="Rename_Click"
InputGesture="{DynamicResource RenameKeyGesture}"
Text="{x:Static lang:Strings.Rename}">
<ui:MenuFlyoutItem.IconSource>
<icons:SymbolIconSource Symbol="Rename" />
</ui:MenuFlyoutItem.IconSource>
</ui:MenuFlyoutItem>
<ui:MenuFlyoutItem Click="ChangeColor_Click" Text="{x:Static lang:Strings.ChangeColor}" />
<ui:MenuFlyoutSeparator />
<ui:MenuFlyoutSubItem Text="{x:Static lang:Strings.Animation}">
<ui:MenuFlyoutItem Command="{Binding FinishEditingAnimation}" Text="{x:Static lang:Strings.FinishEditing}" />
Expand Down
52 changes: 52 additions & 0 deletions src/Beutl/Views/ElementView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
using Beutl.ViewModels;
using Beutl.ViewModels.NodeTree;

using FluentAvalonia.UI.Controls;

using Setter = Avalonia.Styling.Setter;

namespace Beutl.Views;
Expand All @@ -30,6 +32,7 @@ public sealed partial class ElementView : UserControl
private Timeline? _timeline;
private TimeSpan _pointerPosition;
private IDisposable? _disposable1;
private static ColorPickerFlyout? s_colorPickerFlyout;

public ElementView()
{
Expand Down Expand Up @@ -164,6 +167,54 @@ private void OnTextBoxLostFocus(object? sender, RoutedEventArgs e)
textBox.IsVisible = false;
}

private void Rename_Click(object? sender, RoutedEventArgs e)
{
textBlock.IsVisible = false;
textBox.IsVisible = true;
textBox.SelectAll();
textBox.Focus();
}

private void ChangeColor_Click(object? sender, RoutedEventArgs e)
{
if (DataContext is ElementViewModel viewModel)
{
// ContextMenuから開いているので、閉じるのを待つ
s_colorPickerFlyout ??= new ColorPickerFlyout();
s_colorPickerFlyout.ColorPicker.Color = viewModel.Color.Value;
s_colorPickerFlyout.ColorPicker.IsAlphaEnabled = false;
s_colorPickerFlyout.ColorPicker.UseColorPalette = true;
s_colorPickerFlyout.ColorPicker.IsCompact = true;
s_colorPickerFlyout.ColorPicker.IsMoreButtonVisible = true;
s_colorPickerFlyout.Placement = PlacementMode.Top;

if (this.TryFindResource("PaletteColors", out object? colors)
&& colors is IEnumerable<Color> tcolors)
{
s_colorPickerFlyout.ColorPicker.CustomPaletteColors = tcolors;
}

s_colorPickerFlyout.Confirmed += OnColorPickerFlyoutConfirmed;
s_colorPickerFlyout.Closed += OnColorPickerFlyoutClosed;

s_colorPickerFlyout.ShowAt(border);
}
}

private void OnColorPickerFlyoutClosed(object? sender, EventArgs e)
{
s_colorPickerFlyout!.Confirmed -= OnColorPickerFlyoutConfirmed;
s_colorPickerFlyout!.Closed -= OnColorPickerFlyoutClosed;
}

private void OnColorPickerFlyoutConfirmed(ColorPickerFlyout sender, EventArgs args)
{
if (DataContext is ElementViewModel viewModel)
{
viewModel.Color.Value = sender.ColorPicker.Color;
}
}

private void OpenNodeTree_Click(object? sender, RoutedEventArgs e)
{
Element model = ViewModel.Model;
Expand Down Expand Up @@ -523,6 +574,7 @@ private void OnBorderPointerPressed(object? sender, PointerPressedEventArgs e)
obj.textBlock.IsVisible = false;
obj.textBox.IsVisible = true;
obj.textBox.SelectAll();
obj.textBox.Focus();
}
else
{
Expand Down

0 comments on commit 8a35534

Please sign in to comment.