Skip to content

Commit

Permalink
Animation방식 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
lukewire129 committed Nov 2, 2023
1 parent 5b268b0 commit 6e1e5e3
Show file tree
Hide file tree
Showing 15 changed files with 391 additions and 60 deletions.
14 changes: 14 additions & 0 deletions src/Jamesnet.Wpf/AnimationTest/AnimationTest.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Jamesnet.Wpf\Jamesnet.Wpf.csproj" />
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions src/Jamesnet.Wpf/AnimationTest/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Application x:Class="AnimationTest.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:AnimationTest"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
17 changes: 17 additions & 0 deletions src/Jamesnet.Wpf/AnimationTest/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace AnimationTest
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
10 changes: 10 additions & 0 deletions src/Jamesnet.Wpf/AnimationTest/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly: ThemeInfo (
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
13 changes: 13 additions & 0 deletions src/Jamesnet.Wpf/AnimationTest/CustomControl1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Windows;
using System.Windows.Controls;

namespace AnimationTest
{
public class CustomControl1 : Control
{
static CustomControl1()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl1), new FrameworkPropertyMetadata(typeof(CustomControl1)));
}
}
}
13 changes: 13 additions & 0 deletions src/Jamesnet.Wpf/AnimationTest/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Window
x:Class="AnimationTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:AnimationTest"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Title="MainWindow"
Width="800"
Height="450"
mc:Ignorable="d">
<local:CustomControl1 />
</Window>
28 changes: 28 additions & 0 deletions src/Jamesnet.Wpf/AnimationTest/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AnimationTest
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent ();
}
}
}
49 changes: 49 additions & 0 deletions src/Jamesnet.Wpf/AnimationTest/Themes/Generic.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:james="https://jamesnet.dev/xaml/presentation"
xmlns:local="clr-namespace:AnimationTest">


<Style TargetType="{x:Type local:CustomControl1}">
<Setter Property="Width" Value="30" />
<Setter Property="Height" Value="30" />
<Setter Property="UseLayoutRounding" Value="True" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:CustomControl1}">
<ControlTemplate.Resources>
<Storyboard x:Key="background">
<james:ColorItem
Mode="PowerEaseIn"
TargetName="border"
Property="(Background).(SolidColorBrush.Color)"
From="#00fe02"
To="#232323"
Duration="0:0:3" />
</Storyboard>
</ControlTemplate.Resources>
<Grid Background="Transparent">
<Border
x:Name="border"
Margin="1"
Background="#232323"
BorderBrush="Transparent" />
<Border
BorderBrush="black"
BorderThickness="1"
Opacity="0.5" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource background}" />
</Trigger.EnterActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
7 changes: 7 additions & 0 deletions src/Jamesnet.Wpf/Jamesnet.Wpf.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DarkWindowTest2.Forms", "Da
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DarkWindowTest3", "DarkWindowTest3\DarkWindowTest3.csproj", "{89A28DCD-5AA7-4478-A12C-137CA9CADEB2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AnimationTest", "AnimationTest\AnimationTest.csproj", "{F0A685CF-7810-46E7-9D2A-B8FF90B30099}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -57,6 +59,10 @@ Global
{89A28DCD-5AA7-4478-A12C-137CA9CADEB2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{89A28DCD-5AA7-4478-A12C-137CA9CADEB2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{89A28DCD-5AA7-4478-A12C-137CA9CADEB2}.Release|Any CPU.Build.0 = Release|Any CPU
{F0A685CF-7810-46E7-9D2A-B8FF90B30099}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F0A685CF-7810-46E7-9D2A-B8FF90B30099}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F0A685CF-7810-46E7-9D2A-B8FF90B30099}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F0A685CF-7810-46E7-9D2A-B8FF90B30099}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -69,6 +75,7 @@ Global
{110A24BA-FFAF-40F6-8162-92D32C5819A3} = {9477ECB7-B9AE-42B3-A6C3-AF258F67215B}
{8B493AF1-919D-4F84-8BC3-3FDE1B0B26B1} = {110A24BA-FFAF-40F6-8162-92D32C5819A3}
{89A28DCD-5AA7-4478-A12C-137CA9CADEB2} = {110A24BA-FFAF-40F6-8162-92D32C5819A3}
{F0A685CF-7810-46E7-9D2A-B8FF90B30099} = {6CBA80F7-FDE2-4CA9-9429-3C60A6258736}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {75B2C820-CED4-4AF0-AC77-978ED865A717}
Expand Down
78 changes: 61 additions & 17 deletions src/Jamesnet.Wpf/Jamesnet.Wpf/Global/Animation/ColorItem.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Jamesnet.Wpf.Animation;
using System.Windows;
using System.Windows.Media.Animation;

Expand Down Expand Up @@ -63,33 +58,82 @@ private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChan

public static readonly DependencyProperty ModeProperty = DependencyProperty.Register(
"Mode",
typeof(EasingMode),
typeof(EasingFunctionBaseMode),
typeof(ColorItem),
new PropertyMetadata(EasingMode.EaseOut, OnEasingModeChanged)
new PropertyMetadata(EasingFunctionBaseMode.CubicEaseIn, OnEasingModeChanged)
);

public EasingMode Mode
public EasingFunctionBaseMode Mode
{
get { return (EasingMode)GetValue(ModeProperty); }
get { return (EasingFunctionBaseMode)GetValue(ModeProperty); }
set { SetValue(ModeProperty, value); }
}
#endregion

private static void OnEasingModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var item = (ColorItem)d;
var easingMode = (EasingMode)e.NewValue;
var easingMode = (EasingFunctionBaseMode)e.NewValue;

if (item.EasingFunction is CubicEase cubicEase)
{
cubicEase.EasingMode = easingMode;
}
else
{
item.EasingFunction = new CubicEase { EasingMode = easingMode };
cubicEase.EasingMode = GetMode (easingMode);
return;
}

item.EasingFunction = GetEasingFunc (easingMode);
}

private static IEasingFunction GetEasingFunc(EasingFunctionBaseMode mode)
{
EasingMode easingMode = GetMode (mode);
EasingFunctionBase easingFunctionBase = GetFunctonBase (mode);

easingFunctionBase.EasingMode = easingMode;

return (IEasingFunction)easingFunctionBase;
}

private static EasingFunctionBase GetFunctonBase(EasingFunctionBaseMode mode)
{
var enumString = mode.ToString ().Replace ("EaseInOut", "").Replace("EaseIn","").Replace ("EaseOut", "");

if (enumString == "Back")
return new BackEase ();
if (enumString == "Bounce")
return new BounceEase ();
if (enumString == "Circle")
return new CircleEase ();
if (enumString == "Cubic")
return new CubicEase ();
if (enumString == "Elastic")
return new ElasticEase ();
if (enumString == "Exponential")
return new ExponentialEase ();
if (enumString == "Power")
return new PowerEase ();
if (enumString == "Quadratic")
return new QuadraticEase ();
if (enumString == "Quartic")
return new QuarticEase ();
if (enumString == "Quintic")
return new QuinticEase ();
if (enumString == "Sine")
return new SineEase ();

return null;
}
}

private static EasingMode GetMode(EasingFunctionBaseMode mode)
{
var enumString = mode.ToString ();

if (enumString.Contains ("EaseInOut"))
return EasingMode.EaseInOut;
else if (enumString.Contains ("EaseIn"))
return EasingMode.EaseIn;

return EasingMode.EaseOut;
}
}
}
Loading

0 comments on commit 6e1e5e3

Please sign in to comment.