mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-01-01 10:13:30 +00:00
Clean up tweening
This commit is contained in:
parent
201e65b3b5
commit
039593c6fe
@ -1,135 +1,126 @@
|
|||||||
using System;
|
using System;
|
||||||
using Betwixt;
|
using Betwixt;
|
||||||
|
|
||||||
namespace Artemis.Profiles.Layers.Models
|
namespace Artemis.Profiles.Layers.Models
|
||||||
{
|
{
|
||||||
public class TweenModel
|
public class TweenModel
|
||||||
{
|
{
|
||||||
private readonly LayerModel _layerModel;
|
private readonly LayerModel _layerModel;
|
||||||
private Tweener<float> _xTweener;
|
private Tweener<float> _xTweener;
|
||||||
private Tweener<float> _yTweener;
|
private Tweener<float> _yTweener;
|
||||||
private float _width;
|
private float _width;
|
||||||
private Tweener<float> _widthTweener;
|
private Tweener<float> _widthTweener;
|
||||||
private float _height;
|
private float _height;
|
||||||
private Tweener<float> _heightTweener;
|
private Tweener<float> _heightTweener;
|
||||||
private float _opacity;
|
private float _opacity;
|
||||||
private Tweener<float> _opacityTweener;
|
private Tweener<float> _opacityTweener;
|
||||||
private float _x;
|
private float _x;
|
||||||
private float _y;
|
private float _y;
|
||||||
|
|
||||||
public TweenModel(LayerModel layerModel)
|
public TweenModel(LayerModel layerModel)
|
||||||
{
|
{
|
||||||
_layerModel = layerModel;
|
_layerModel = layerModel;
|
||||||
_xTweener = new Tweener<float>((float) layerModel.X, (float) layerModel.X, 0);
|
_xTweener = new Tweener<float>((float) layerModel.X, (float) layerModel.X, 0);
|
||||||
_yTweener = new Tweener<float>((float) layerModel.Y, (float) layerModel.Y, 0);
|
_yTweener = new Tweener<float>((float) layerModel.Y, (float) layerModel.Y, 0);
|
||||||
_widthTweener = new Tweener<float>((float) layerModel.Width, (float) layerModel.Width, 0);
|
_widthTweener = new Tweener<float>((float) layerModel.Width, (float) layerModel.Width, 0);
|
||||||
_heightTweener = new Tweener<float>((float) layerModel.Height, (float) layerModel.Height, 0);
|
_heightTweener = new Tweener<float>((float) layerModel.Height, (float) layerModel.Height, 0);
|
||||||
_opacityTweener = new Tweener<float>((float) layerModel.Opacity, (float) layerModel.Opacity, 0);
|
_opacityTweener = new Tweener<float>((float) layerModel.Opacity, (float) layerModel.Opacity, 0);
|
||||||
|
|
||||||
_x = (float)_layerModel.X;
|
_x = (float)_layerModel.X;
|
||||||
_y = (float)_layerModel.Y;
|
_y = (float)_layerModel.Y;
|
||||||
_width = (float)_layerModel.Width;
|
_width = (float)_layerModel.Width;
|
||||||
_height = (float)_layerModel.Height;
|
_height = (float)_layerModel.Height;
|
||||||
_opacity = (float)_layerModel.Opacity;
|
_opacity = (float)_layerModel.Opacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
|
||||||
UpdateWidth();
|
|
||||||
UpdateHeight();
|
|
||||||
UpdateOpacity();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateWidth()
|
|
||||||
{
|
{
|
||||||
if (Math.Abs(_layerModel.Properties.WidthEaseTime) < 0.001)
|
UpdateWidth();
|
||||||
|
UpdateHeight();
|
||||||
|
UpdateOpacity();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateWidth()
|
||||||
|
{
|
||||||
|
if (_layerModel.Properties.WidthEaseTime < 0.001)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Width
|
// Width
|
||||||
if (Math.Abs(_layerModel.Width - _width) > 0.001)
|
if (Math.Abs(_layerModel.Width - _width) > 0.001)
|
||||||
{
|
{
|
||||||
var widthFunc = GetEaseFunction(_layerModel.Properties.WidthEase);
|
var widthFunc = GetEaseFunction(_layerModel.Properties.WidthEase);
|
||||||
var widthSpeed = _layerModel.Properties.WidthEaseTime;
|
var widthSpeed = _layerModel.Properties.WidthEaseTime;
|
||||||
|
|
||||||
_xTweener = new Tweener<float>(_xTweener.Value, (float)_layerModel.X, widthSpeed, widthFunc);
|
_xTweener = new Tweener<float>(_xTweener.Value, (float)_layerModel.X, widthSpeed, widthFunc);
|
||||||
_widthTweener = new Tweener<float>(_widthTweener.Value, (float)_layerModel.Width, widthSpeed, widthFunc);
|
_widthTweener = new Tweener<float>(_widthTweener.Value, (float)_layerModel.Width, widthSpeed, widthFunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
_xTweener.Update(40);
|
_xTweener.Update(40);
|
||||||
_widthTweener.Update(40);
|
_widthTweener.Update(40);
|
||||||
|
|
||||||
_x = (float) _layerModel.X;
|
_x = (float) _layerModel.X;
|
||||||
_width = (float)_layerModel.Width;
|
_width = (float)_layerModel.Width;
|
||||||
|
|
||||||
_layerModel.X = _xTweener.Value;
|
_layerModel.X = _xTweener.Value;
|
||||||
_layerModel.Width = _widthTweener.Value;
|
_layerModel.Width = _widthTweener.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateHeight()
|
private void UpdateHeight()
|
||||||
{
|
{
|
||||||
if (Math.Abs(_layerModel.Properties.HeightEaseTime) < 0.001)
|
if (_layerModel.Properties.HeightEaseTime < 0.001)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Height
|
// Height
|
||||||
if (Math.Abs(_layerModel.Height - _height) > 0.001)
|
if (Math.Abs(_layerModel.Height - _height) > 0.001)
|
||||||
{
|
{
|
||||||
var heightFunc = GetEaseFunction(_layerModel.Properties.HeightEase);
|
var heightFunc = GetEaseFunction(_layerModel.Properties.HeightEase);
|
||||||
var heightSpeed = _layerModel.Properties.HeightEaseTime;
|
var heightSpeed = _layerModel.Properties.HeightEaseTime;
|
||||||
_yTweener = new Tweener<float>(_y, (float)_layerModel.Y, heightSpeed, heightFunc);
|
_yTweener = new Tweener<float>(_y, (float)_layerModel.Y, heightSpeed, heightFunc);
|
||||||
_heightTweener = new Tweener<float>(_height, (float)_layerModel.Height, heightSpeed, heightFunc);
|
_heightTweener = new Tweener<float>(_height, (float)_layerModel.Height, heightSpeed, heightFunc);
|
||||||
}
|
}
|
||||||
|
|
||||||
_yTweener.Update(40);
|
_yTweener.Update(40);
|
||||||
_heightTweener.Update(40);
|
_heightTweener.Update(40);
|
||||||
|
|
||||||
_y = (float)_layerModel.Y;
|
_y = (float)_layerModel.Y;
|
||||||
_height = (float)_layerModel.Height;
|
_height = (float)_layerModel.Height;
|
||||||
|
|
||||||
_layerModel.Y = _yTweener.Value;
|
_layerModel.Y = _yTweener.Value;
|
||||||
_layerModel.Height = _heightTweener.Value;
|
_layerModel.Height = _heightTweener.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateOpacity()
|
private void UpdateOpacity()
|
||||||
{
|
{
|
||||||
if (Math.Abs(_layerModel.Properties.OpacityEaseTime) < 0.001)
|
if (_layerModel.Properties.OpacityEaseTime < 0.001)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Opacity
|
// Opacity
|
||||||
if (Math.Abs(_layerModel.Opacity - _opacity) > 0.001)
|
if (Math.Abs(_layerModel.Opacity - _opacity) > 0.001)
|
||||||
{
|
{
|
||||||
_opacityTweener = new Tweener<float>(_opacity, (float)_layerModel.Opacity,
|
_opacityTweener = new Tweener<float>(_opacity, (float)_layerModel.Opacity,
|
||||||
_layerModel.Properties.OpacityEaseTime, GetEaseFunction(_layerModel.Properties.OpacityEase));
|
_layerModel.Properties.OpacityEaseTime, GetEaseFunction(_layerModel.Properties.OpacityEase));
|
||||||
}
|
}
|
||||||
|
|
||||||
_opacityTweener.Update(40);
|
_opacityTweener.Update(40);
|
||||||
|
|
||||||
_opacity = (float)_layerModel.Opacity;
|
_opacity = (float)_layerModel.Opacity;
|
||||||
|
|
||||||
_layerModel.Opacity = _opacityTweener.Value;
|
_layerModel.Opacity = _opacityTweener.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StoreCurrentValues()
|
private static EaseFunc GetEaseFunction(string functionName)
|
||||||
{
|
{
|
||||||
_x = (float) _layerModel.X;
|
switch (functionName)
|
||||||
_y = (float) _layerModel.Y;
|
{
|
||||||
_width = (float) _layerModel.Width;
|
case "In":
|
||||||
_height = (float) _layerModel.Height;
|
return Ease.Quint.In;
|
||||||
_opacity = (float) _layerModel.Opacity;
|
case "Out":
|
||||||
}
|
return Ease.Quint.Out;
|
||||||
|
case "In/out":
|
||||||
private static EaseFunc GetEaseFunction(string functionName)
|
return Ease.Quint.InOut;
|
||||||
{
|
default:
|
||||||
switch (functionName)
|
return Ease.Linear;
|
||||||
{
|
}
|
||||||
case "In":
|
}
|
||||||
return Ease.Quint.In;
|
}
|
||||||
case "Out":
|
|
||||||
return Ease.Quint.Out;
|
|
||||||
case "In/out":
|
|
||||||
return Ease.Quint.InOut;
|
|
||||||
default:
|
|
||||||
return Ease.Linear;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user