Skip to content

Commit

Permalink
Merge pull request #16 from EttienneS/feature/better-border
Browse files Browse the repository at this point in the history
Feature/better border
  • Loading branch information
EttienneS committed Apr 9, 2021
2 parents 5dbbc3f + 8746472 commit 96f8d2c
Show file tree
Hide file tree
Showing 32 changed files with 205 additions and 83 deletions.
59 changes: 45 additions & 14 deletions AnimatedTokenMaker/AnimatedTokenMaker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>2</ApplicationRevision>
<ApplicationVersion>0.1.0.%2a</ApplicationVersion>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>0.2.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
Expand Down Expand Up @@ -181,24 +181,24 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Content Include="Borders\Circle2.png">
<None Include="Assets\Borders\RoundedSquare_mask.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Borders\Circle3.png">
</None>
<None Include="Assets\Borders\Circle_mask.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Borders\Circle4.png">
</None>
<None Include="Assets\Borders\RoundedSquare.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Borders\CircleClear.png">
</None>
<None Include="Assets\Borders\Circle.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Borders\RoundedSquare.png">
</None>
<None Include="Assets\Borders\Sci.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Borders\Circle1.png">
</None>
<None Include="Assets\Borders\Sci_mask.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</None>
<Resource Include="Resources\alpha.png" />
<Resource Include="icon.ico" />
</ItemGroup>
Expand All @@ -214,5 +214,36 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<None Include="Assets\Gradients\Dusk.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Assets\Gradients\Fog.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Assets\Gradients\Forest.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Assets\Gradients\Mango.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Assets\Gradients\T&amp;C.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Include="Assets\Gradients\Ice.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Assets\Gradients\Pride.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Assets\Gradients\Sleek.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Assets\Gradients\Vein.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Binary file added AnimatedTokenMaker/Assets/Borders/Circle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AnimatedTokenMaker/Assets/Borders/Circle_mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AnimatedTokenMaker/Assets/Borders/Sci.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AnimatedTokenMaker/Assets/Borders/Sci_mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AnimatedTokenMaker/Assets/Gradients/Dusk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AnimatedTokenMaker/Assets/Gradients/Fog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AnimatedTokenMaker/Assets/Gradients/Forest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AnimatedTokenMaker/Assets/Gradients/Ice.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AnimatedTokenMaker/Assets/Gradients/Mango.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AnimatedTokenMaker/Assets/Gradients/Pride.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AnimatedTokenMaker/Assets/Gradients/Sleek.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AnimatedTokenMaker/Assets/Gradients/T&C.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added AnimatedTokenMaker/Assets/Gradients/Vein.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions AnimatedTokenMaker/Border/BorderImage.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Drawing;
using System.IO;

namespace AnimatedTokenMaker.Border
{
public class BorderImage : IBorderImage
{
private readonly Bitmap _border;
private readonly Bitmap _mask;

private Color _color;

Expand All @@ -13,6 +15,16 @@ public class BorderImage : IBorderImage
public BorderImage(string borderImageFile)
{
_border = (Bitmap)Image.FromFile(borderImageFile);

var mask = GetMaskName(borderImageFile);
if (File.Exists(mask))
{
_mask = (Bitmap)Image.FromFile(mask);
}
else
{
throw new FileNotFoundException($"Mask not found: {mask}");
}
}

public Size GetBorderSize()
Expand All @@ -29,13 +41,27 @@ public Bitmap GetColoredBorderImage()
return new Bitmap(_coloredBorder);
}

public Bitmap GetMask()
{
return _mask;
}

public void SetBorderColor(Color color)
{
_color = color;

UpdateColoredBorder();
}

private static string GetMaskName(string borderImageFile)
{
var dir = borderImageFile.Replace(Path.GetFileName(borderImageFile), string.Empty);

var file = Path.GetFileNameWithoutExtension(borderImageFile) + "_mask" + Path.GetExtension(borderImageFile);

return Path.Combine(dir, file);
}

private void UpdateColoredBorder()
{
var borderSize = GetBorderSize();
Expand Down
1 change: 1 addition & 0 deletions AnimatedTokenMaker/Border/IBorderImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public interface IBorderImage
Bitmap GetColoredBorderImage();

void SetBorderColor(Color color);
Bitmap GetMask();
}
}
Binary file removed AnimatedTokenMaker/Borders/Circle1.png
Binary file not shown.
Binary file removed AnimatedTokenMaker/Borders/Circle2.png
Binary file not shown.
Binary file removed AnimatedTokenMaker/Borders/Circle3.png
Binary file not shown.
Binary file removed AnimatedTokenMaker/Borders/Circle4.png
Binary file not shown.
Binary file removed AnimatedTokenMaker/Borders/CircleClear.png
Binary file not shown.
Binary file removed AnimatedTokenMaker/Borders/RoundedSquare.png
Binary file not shown.
9 changes: 9 additions & 0 deletions AnimatedTokenMaker/ColorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,14 @@ public static Color Add(this Color color, Color other)
Math.Min(MAX, color.G + other.G),
Math.Min(MAX, color.B + other.B));
}

public static Color Blend(this Color color, Color backColor, double amount)
{
byte r = (byte)((color.R * amount) + backColor.R * (1 - amount));
byte g = (byte)((color.G * amount) + backColor.G * (1 - amount));
byte b = (byte)((color.B * amount) + backColor.B * (1 - amount));
return Color.FromArgb(r, g, b);
}

}
}
10 changes: 8 additions & 2 deletions AnimatedTokenMaker/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
<StackPanel>
<StackPanel Orientation="Horizontal">
<Label Content="Border: " Margin="5" />
<ComboBox Loaded="BorderSelector_Loaded" SelectionChanged="BorderSelector_SelectionChanged" HorizontalAlignment="Left" VerticalAlignment="Top" Width="400" Margin="10" />
<ComboBox Name="BorderSelectorBox"
SelectionChanged="BorderSelector_SelectionChanged"
HorizontalAlignment="Left" VerticalAlignment="Top" Width="284" Margin="10" />
<Label Content="Border Color:" Margin="5"/>
<ColorPickerWPF:ColorPickRow HorizontalAlignment="Left" Margin="5" VerticalAlignment="Top" Options="LoadCustomPalette" OnPick="ColorPicker_Picked" />
</StackPanel>
</StackPanel>
Expand All @@ -27,7 +30,10 @@
<StackPanel>
<Label Content="Layers:" />
<ListView Name="LayerList" Height="475" Margin="5" />
<Button Content="Add Layer" Click="AddStaticLayer_Click" Margin="15" />
<StackPanel Orientation="Horizontal">
<Button Content="Add Layer" Click="AddStaticLayer_Click" Margin="10" Width="375" />
<Button Content="Add Gradient" Click="AddGradient_Click" Margin="10" Width="100" />
</StackPanel>
</StackPanel>
</Border>
<StackPanel Margin="5" Width="300" Height="400">
Expand Down
123 changes: 73 additions & 50 deletions AnimatedTokenMaker/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,9 @@ public MainWindow()
_tokenMaker = new TokenMaker(new VideoExporter(ServiceManager.Instance.FFmpegService, GetDefaultSetting()));
_tokenMaker.OnExportLayerCompleted += OnExportLayerCompleted;

SetBorder(GetBorders()[0]);

InitializeComponent();
}

private static SourceSetting GetDefaultSetting()
{
return new SourceSetting(0, Properties.Settings.Default.Framerate, Properties.Settings.Default.MaxTime);
}

private void OnExportLayerCompleted(int layer, int total)
{
Dispatcher.BeginInvoke((Action)(() =>
{
ExportProgress.Maximum = total;
ExportProgress.Value = layer;
}));
InitMaskAndBorder();
}

public event PropertyChangedEventHandler PropertyChanged;
Expand All @@ -75,15 +61,9 @@ public void Changed(string property)

public string[] GetBorders()
{
return Directory.EnumerateFiles("Borders").ToArray();
}

public void SetBorder(string border)
{
_border = border;
_tokenMaker.LoadBorder(new BorderImage(_border));

UpdatePreview();
return Directory.EnumerateFiles("Assets\\Borders", "*.png", SearchOption.TopDirectoryOnly)
.Where(f => !f.Contains("_mask"))
.ToArray();
}

public void StartPreviewUpdate(int frame)
Expand All @@ -92,6 +72,14 @@ public void StartPreviewUpdate(int frame)
{
return;
}
try
{
_tokenMaker.LoadBorder(new BorderImage(_border));
}
catch (FileNotFoundException ex)
{
MessageBox.Show(ex.Message, "Border mask not found", MessageBoxButton.OK, MessageBoxImage.Error);
}

_previewTask = Task.Run(() =>
{
Expand All @@ -105,18 +93,40 @@ public void StartPreviewUpdate(int frame)
});
}

private static string[] ShowFileDialog()
private static SourceSetting GetDefaultSetting()
{
return new SourceSetting(0, Properties.Settings.Default.Framerate, Properties.Settings.Default.MaxTime);
}

private static string[] ShowFileDialog(string path = "")
{
var ofd = new OpenFileDialog();
ofd.Multiselect = true;
var ofd = new OpenFileDialog
{
Multiselect = true
};

if (!string.IsNullOrEmpty(path) && Directory.Exists(path))
{
ofd.InitialDirectory = path;
}
ofd.ShowDialog();

return ofd.FileNames;
}

private void AddGradient_Click(object sender, RoutedEventArgs e)
{
GetAndAddLayer(Path.Combine(Environment.CurrentDirectory, "Assets\\Gradients"));
}

private void AddStaticLayer_Click(object sender, RoutedEventArgs e)
{
var files = ShowFileDialog();
GetAndAddLayer();
}

private void GetAndAddLayer(string defaultPath = "")
{
var files = ShowFileDialog(defaultPath);
if (files.Length == 0)
{
return;
Expand All @@ -129,17 +139,13 @@ private void AddStaticLayer_Click(object sender, RoutedEventArgs e)
}
}

private void BorderSelector_Loaded(object sender, RoutedEventArgs e)
{
var box = sender as ComboBox;
box.ItemsSource = GetBorders();
box.SelectedIndex = 0;
}

private void BorderSelector_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var box = sender as ComboBox;
SetBorder(box.SelectedValue.ToString());
_border = box.SelectedValue.ToString();

var name = Path.GetFileNameWithoutExtension(_border);
UpdatePreview();
}

private void ColorPicker_Picked(object sender, System.EventArgs e)
Expand All @@ -154,6 +160,28 @@ private void DeleteStaticLayer_Click(object sender, RoutedEventArgs e)
LayerList.Items.Remove(LayerList.SelectedItem);
}

private void FrameSlider_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
{
UpdatePreview();
}

private void InitMaskAndBorder()
{
BorderSelectorBox.ItemsSource = GetBorders();
BorderSelectorBox.SelectedIndex = 0;

_border = BorderSelectorBox.SelectedValue.ToString();
}

private void OnExportLayerCompleted(int layer, int total)
{
Dispatcher.BeginInvoke((Action)(() =>
{
ExportProgress.Maximum = total;
ExportProgress.Value = layer;
}));
}

private void OnLayerChanged(ISourceFile layer)
{
UpdatePreview();
Expand Down Expand Up @@ -201,6 +229,15 @@ private void OnRemoveLayer(ISourceFile layer)
UpdatePreview();
}

private void ResetUi(LoadingControl loadingControl)
{
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
{
LayerList.Items.Remove(loadingControl);
IsEnabled = true;
}));
}

private void Save_Click(object sender, RoutedEventArgs e)
{
var sfd = new SaveFileDialog
Expand Down Expand Up @@ -271,23 +308,9 @@ private void StartAddLayerView(string file)
});
}

private void ResetUi(LoadingControl loadingControl)
{
Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
{
LayerList.Items.Remove(loadingControl);
IsEnabled = true;
}));
}

private void UpdatePreview()
{
StartPreviewUpdate(PreviewFrame);
}

private void FrameSlider_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e)
{
UpdatePreview();
}
}
}
Loading

0 comments on commit 96f8d2c

Please sign in to comment.