Skip to content

Commit

Permalink
Add text color options to playback buttons
Browse files Browse the repository at this point in the history
- Change color picker default binding mode to two way
  • Loading branch information
dsafa committed May 8, 2019
1 parent 5d5a67f commit 9b995ec
Show file tree
Hide file tree
Showing 10 changed files with 246 additions and 100 deletions.
30 changes: 30 additions & 0 deletions src/AudioBand/Models/PlaybackButtonBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public class PlaybackButtonBase : ModelBase
private ButtonContentType _contentType = ButtonContentType.Image;
private string _textFontFamily = "Segoe MDL2 Assets";
private string _text;
private Color _textColor = Color.White;
private Color _textHoveredColor = Color.White;
private Color _textClickedColor = Color.White;

/// <summary>
/// Gets or sets the path of the button image.
Expand Down Expand Up @@ -147,5 +150,32 @@ public string Text
get => _text;
set => SetProperty(ref _text, value);
}

/// <summary>
/// Gets or sets the text color.
/// </summary>
public Color TextColor
{
get => _textColor;
set => SetProperty(ref _textColor, value);
}

/// <summary>
/// Gets or sets the text color when hovered.
/// </summary>
public Color TextHoveredColor
{
get => _textHoveredColor;
set => SetProperty(ref _textHoveredColor, value);
}

/// <summary>
/// Gets or sets the text color when clicked.
/// </summary>
public Color TextClickedColor
{
get => _textClickedColor;
set => SetProperty(ref _textClickedColor, value);
}
}
}
10 changes: 8 additions & 2 deletions src/AudioBand/Settings/Migrations/V2ToV3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ private MapperConfiguration GetMapConfig()
.ForMember(dest => dest.ClickedBackgroundColor, opt => opt.Ignore())
.ForMember(dest => dest.ContentType, opt => opt.MapFrom(source => ButtonContentType.Image))
.ForMember(dest => dest.TextFontFamily, opt => opt.Ignore())
.ForMember(dest => dest.Text, opt => opt.Ignore());
.ForMember(dest => dest.Text, opt => opt.Ignore())
.ForMember(dest => dest.TextColor, opt => opt.Ignore())
.ForMember(dest => dest.TextHoveredColor, opt => opt.Ignore())
.ForMember(dest => dest.TextClickedColor, opt => opt.Ignore());
cfg.CreateMap<Models.V2.PreviousButtonSettings, PreviousButton>()
.ForMember(dest => dest.HoveredImagePath, opt => opt.MapFrom(source => source.ImagePath))
.ForMember(dest => dest.ClickedImagePath, opt => opt.MapFrom(source => source.ImagePath))
Expand All @@ -46,7 +49,10 @@ private MapperConfiguration GetMapConfig()
.ForMember(dest => dest.ClickedBackgroundColor, opt => opt.Ignore())
.ForMember(dest => dest.ContentType, opt => opt.MapFrom(source => ButtonContentType.Image))
.ForMember(dest => dest.TextFontFamily, opt => opt.Ignore())
.ForMember(dest => dest.Text, opt => opt.Ignore());
.ForMember(dest => dest.Text, opt => opt.Ignore())
.ForMember(dest => dest.TextColor, opt => opt.Ignore())
.ForMember(dest => dest.TextHoveredColor, opt => opt.Ignore())
.ForMember(dest => dest.TextClickedColor, opt => opt.Ignore());
cfg.CreateMap<Models.V2.PlayPauseButtonSettings, PlayPauseButton>()
.ForMember(dest => dest.DefaultBackgroundColor, opt => opt.Ignore())
.ForMember(dest => dest.HoveredBackgroundColor, opt => opt.Ignore())
Expand Down
16 changes: 2 additions & 14 deletions src/AudioBand/ViewModels/NextButtonVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,9 @@ protected override NextButton GetReplacementModel()
}

/// <inheritdoc />
protected override IImage GetDefaultImage()
protected override IImage GetDefaultDrawingImage()
{
return ResourceLoader.TryLoadImageFromPath(ImagePath, ResourceLoader.DefaultNextImage);
}

/// <inheritdoc />
protected override IImage GetHoveredImage()
{
return ResourceLoader.TryLoadImageFromPath(HoveredImagePath, ResourceLoader.DefaultNextImage);
}

/// <inheritdoc />
protected override IImage GetClickedImage()
{
return ResourceLoader.TryLoadImageFromPath(ClickedImagePath, ResourceLoader.DefaultNextImage);
return ResourceLoader.DefaultNextImage;
}
}
}
137 changes: 109 additions & 28 deletions src/AudioBand/ViewModels/PlaybackButtonVMBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime;
using AudioBand.Models;
using AudioBand.Resources;
Expand All @@ -15,6 +17,7 @@ namespace AudioBand.ViewModels
public abstract class PlaybackButtonVMBase<TButton> : ViewModelBase<TButton>
where TButton : PlaybackButtonBase, new()
{
private static readonly List<ButtonContentType> ContentTypes = Enum.GetValues(typeof(ButtonContentType)).Cast<ButtonContentType>().ToList();
private IImage _image;
private IImage _hoveredImage;
private IImage _clickedImage;
Expand All @@ -34,9 +37,7 @@ protected PlaybackButtonVMBase(IAppSettings appSettings, IResourceLoader resourc
ResourceLoader = resourceLoader;

AppSettings.ProfileChanged += AppsSettingsOnProfileChanged;
Image = GetDefaultImage(); // Abstract method but everything should be initialized already
HoveredImage = GetHoveredImage();
ClickedImage = GetClickedImage();
UpdateImages();
}

/// <summary>
Expand Down Expand Up @@ -75,9 +76,9 @@ public string ImagePath
get => Model.ImagePath;
set
{
if (SetProperty(nameof(Model.ImagePath), value))
if (SetProperty(nameof(Model.ImagePath), value) && ContentType == ButtonContentType.Image)
{
Image = GetDefaultImage();
Image = LoadDrawingImage(value);
}
}
}
Expand All @@ -91,9 +92,9 @@ public string HoveredImagePath
get => Model.HoveredImagePath;
set
{
if (SetProperty(nameof(Model.HoveredImagePath), value))
if (SetProperty(nameof(Model.HoveredImagePath), value) && ContentType == ButtonContentType.Image)
{
HoveredImage = GetHoveredImage();
HoveredImage = LoadDrawingImage(value);
}
}
}
Expand All @@ -107,9 +108,9 @@ public string ClickedImagePath
get => Model.ClickedImagePath;
set
{
if (SetProperty(nameof(Model.ClickedImagePath), value))
if (SetProperty(nameof(Model.ClickedImagePath), value) && ContentType == ButtonContentType.Image)
{
ClickedImage = GetClickedImage();
ClickedImage = LoadDrawingImage(value);
}
}
}
Expand Down Expand Up @@ -198,14 +199,25 @@ public Color ClickedBackgroundColor
set => SetProperty(nameof(Model.ClickedBackgroundColor), value);
}

/// <summary>
/// Gets the button content types.
/// </summary>
public IEnumerable<ButtonContentType> ButtonContentTypes => ContentTypes;

/// <summary>
/// Gets or sets the content type for the button.
/// </summary>
[PropertyChangeBinding(nameof(PlaybackButtonBase.ContentType))]
public ButtonContentType ContentType
{
get => Model.ContentType;
set => SetProperty(nameof(Model.ContentType), value);
set
{
if (SetProperty(nameof(Model.ContentType), value))
{
UpdateImages();
}
}
}

/// <summary>
Expand All @@ -215,7 +227,13 @@ public ButtonContentType ContentType
public string TextFontFamily
{
get => Model.TextFontFamily;
set => SetProperty(nameof(Model.TextFontFamily), value);
set
{
if (SetProperty(nameof(Model.TextFontFamily), value) && ContentType == ButtonContentType.Text)
{
UpdateImages();
}
}
}

/// <summary>
Expand All @@ -225,7 +243,61 @@ public string TextFontFamily
public string Text
{
get => Model.Text;
set => SetProperty(nameof(Model.Text), value);
set
{
if (SetProperty(nameof(Model.Text), value) && ContentType == ButtonContentType.Text)
{
UpdateImages();
}
}
}

/// <summary>
/// Gets or sets the text color.
/// </summary>
[PropertyChangeBinding(nameof(PlaybackButtonBase.TextColor))]
public Color TextColor
{
get => Model.TextColor;
set
{
if (SetProperty(nameof(Model.TextColor), value) && ContentType == ButtonContentType.Text)
{
Image = new TextImage(Text, TextFontFamily, value);
}
}
}

/// <summary>
/// Gets or sets the text hovered color.
/// </summary>
[PropertyChangeBinding(nameof(PlaybackButtonBase.TextHoveredColor))]
public Color TextHoveredColor
{
get => Model.TextHoveredColor;
set
{
if (SetProperty(nameof(Model.TextHoveredColor), value) && ContentType == ButtonContentType.Text)
{
HoveredImage = new TextImage(Text, TextFontFamily, value);
}
}
}

/// <summary>
/// Gets or sets the text clicked color.
/// </summary>
[PropertyChangeBinding(nameof(PlaybackButtonBase.TextClickedColor))]
public Color TextClickedColor
{
get => Model.TextClickedColor;
set
{
if (SetProperty(nameof(Model.TextClickedColor), value) && ContentType == ButtonContentType.Text)
{
ClickedImage = new TextImage(Text, TextFontFamily, value);
}
}
}

/// <summary>
Expand Down Expand Up @@ -259,14 +331,14 @@ public string Text
protected override void OnReset()
{
base.OnReset();
Image = GetDefaultImage();
UpdateImages();
}

/// <inheritdoc/>
protected override void OnCancelEdit()
{
base.OnCancelEdit();
Image = GetDefaultImage();
UpdateImages();
}

/// <summary>
Expand All @@ -276,27 +348,36 @@ protected override void OnCancelEdit()
protected abstract TButton GetReplacementModel();

/// <summary>
/// Gets the default image.
/// Gets the default drawing image.
/// </summary>
/// <returns>The default image.</returns>
protected abstract IImage GetDefaultImage();

/// <summary>
/// Gets the hovered image.
/// </summary>
/// <returns>The hovered image.</returns>
protected abstract IImage GetHoveredImage();

/// <summary>
/// Gets the clicked image.
/// </summary>
/// <returns>The clicked image.</returns>
protected abstract IImage GetClickedImage();
protected abstract IImage GetDefaultDrawingImage();

private void AppsSettingsOnProfileChanged(object sender, EventArgs e)
{
Debug.Assert(IsEditing == false, "Should not be editing");
ReplaceModel(GetReplacementModel());
}

private IImage LoadDrawingImage(string path)
{
return ResourceLoader.TryLoadImageFromPath(path, GetDefaultDrawingImage());
}

private void UpdateImages()
{
if (ContentType == ButtonContentType.Image)
{
Image = LoadDrawingImage(ImagePath);
HoveredImage = LoadDrawingImage(HoveredImagePath);
ClickedImage = LoadDrawingImage(ClickedImagePath);
}
else
{
Image = new TextImage(Text, TextFontFamily, TextColor);
HoveredImage = new TextImage(Text, TextFontFamily, TextHoveredColor);
ClickedImage = new TextImage(Text, TextFontFamily, TextClickedColor);
}
}
}
}
16 changes: 2 additions & 14 deletions src/AudioBand/ViewModels/PreviousButtonVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,9 @@ protected override PreviousButton GetReplacementModel()
}

/// <inheritdoc />
protected override IImage GetDefaultImage()
protected override IImage GetDefaultDrawingImage()
{
return ResourceLoader.TryLoadImageFromPath(ImagePath, ResourceLoader.DefaultPreviousImage);
}

/// <inheritdoc />
protected override IImage GetHoveredImage()
{
return ResourceLoader.TryLoadImageFromPath(HoveredImagePath, ResourceLoader.DefaultPreviousImage);
}

/// <inheritdoc />
protected override IImage GetClickedImage()
{
return ResourceLoader.TryLoadImageFromPath(ClickedImagePath, ResourceLoader.DefaultPreviousImage);
return ResourceLoader.DefaultPreviousImage;
}
}
}
2 changes: 1 addition & 1 deletion src/AudioBand/Views/Wpf/ColorPicker.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class ColorPicker : UserControl
/// <summary>
/// Dependency property for <see cref="Color"/>.
/// </summary>
public static readonly DependencyProperty ColorProperty = DependencyProperty.Register(nameof(Color), typeof(Color), typeof(ColorPicker));
public static readonly DependencyProperty ColorProperty = DependencyProperty.Register(nameof(Color), typeof(Color), typeof(ColorPicker), new FrameworkPropertyMetadata(Colors.White, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));

/// <summary>
/// Dependency property for <see cref="DialogService"/>.
Expand Down
Loading

0 comments on commit 9b995ec

Please sign in to comment.