diff options
author | sung-su.kim <sung-su.kim@samsung.com> | 2017-06-19 20:37:11 +0900 |
---|---|---|
committer | sung-su.kim <sung-su.kim@samsung.com> | 2017-06-23 15:36:55 +0900 |
commit | 698f1e1ddc73f43b0c49ccea464deaa501b73a29 (patch) | |
tree | 6dce52683c366fd9b224cbc928c334073ba0caec /ElmSharp/ElmSharp | |
parent | 3b6b2ce393fbedbc240acf62f8dc2bf7e69627c9 (diff) | |
download | elm-sharp-698f1e1ddc73f43b0c49ccea464deaa501b73a29.tar.gz elm-sharp-698f1e1ddc73f43b0c49ccea464deaa501b73a29.tar.bz2 elm-sharp-698f1e1ddc73f43b0c49ccea464deaa501b73a29.zip |
Add Transit
Change-Id: I84f82a4fa1940214286219bf9a7940ad8fdb5469
Diffstat (limited to 'ElmSharp/ElmSharp')
-rwxr-xr-x | ElmSharp/ElmSharp/EffectBase.cs | 38 | ||||
-rwxr-xr-x | ElmSharp/ElmSharp/Transit.cs | 381 | ||||
-rwxr-xr-x | ElmSharp/ElmSharp/TransitEffect.cs | 461 |
3 files changed, 880 insertions, 0 deletions
diff --git a/ElmSharp/ElmSharp/EffectBase.cs b/ElmSharp/ElmSharp/EffectBase.cs new file mode 100755 index 0000000..19eddb0 --- /dev/null +++ b/ElmSharp/ElmSharp/EffectBase.cs @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; + +namespace ElmSharp +{ + /// <summary> + /// EffectBase class for the TransitEffect + /// </summary> + public abstract class EffectBase + { + /// <summary> + /// EffectEneded event will be triggered when be effect ended. + /// </summary> + public event EventHandler EffectEnded; + + internal abstract IntPtr CreateEffect(IntPtr transit); + + internal void SendEffectEnd() + { + EffectEnded?.Invoke(this, EventArgs.Empty); + } + } +}
\ No newline at end of file diff --git a/ElmSharp/ElmSharp/Transit.cs b/ElmSharp/ElmSharp/Transit.cs new file mode 100755 index 0000000..2b2dc00 --- /dev/null +++ b/ElmSharp/ElmSharp/Transit.cs @@ -0,0 +1,381 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Collections.Specialized; +using static Interop.Elementary; + +namespace ElmSharp +{ + /// <summary> + /// Transit is designed to apply various animated transition effects, such like translation, rotation, etc. + /// For using these effects, create an Transit and add the desired transition effects. + /// </summary> + /// <remarks>Transit is not reusable. If the effect ends, the transit is destroyed automatically.</remarks> + public class Transit : IDisposable + { + IntPtr _handle = IntPtr.Zero; + bool _isDisposed = false; + ObservableCollection<EvasObject> _objects = new ObservableCollection<EvasObject>(); + ObservableCollection<Transit> _chains = new ObservableCollection<Transit>(); + HashSet<object> _checker = new HashSet<object>(); + Elm_Transit_Del_Cb DeletedCallback; + Elm_Transit_Effect_End_Cb EffectEndCallback; + + /// <summary> + /// A callback called when the transit is deleted. + /// </summary> + public event EventHandler Deleted; + + /// <summary> + /// Creates and initializes a new instance of Transit class. + /// </summary> + public Transit() + { + _handle = Interop.Elementary.elm_transit_add(); + DeletedCallback = (ptr1, ptr2) => { + Deleted?.Invoke(this, EventArgs.Empty); + Dispose(true); + }; + Interop.Elementary.elm_transit_del_cb_set(_handle, DeletedCallback, IntPtr.Zero); + ((INotifyCollectionChanged)_objects).CollectionChanged += OnObjectCollectionChanged; + ((INotifyCollectionChanged)_chains).CollectionChanged += OnChaninCollectionChanged; + } + + ~Transit() + { + Dispose(false); + } + + /// <summary> + /// Gets or sets the transit animation time + /// </summary> + public double Duration + { + get + { + return Interop.Elementary.elm_transit_duration_get(_handle); + } + set + { + Interop.Elementary.elm_transit_duration_set(_handle, value); + } + } + + /// <summary> + /// Gets or sets a value whether the objects states will be keep or not. + /// If it is not kept, the objects states will be reset when transition ends. + /// </summary> + public bool ObjectStateKeep + { + get + { + return Interop.Elementary.elm_transit_objects_final_state_keep_get(_handle); + } + set + { + Interop.Elementary.elm_transit_objects_final_state_keep_set(_handle, value); + } + } + + /// <summary> + /// Gets or sets the transit animation acceleration type. + /// </summary> + public TweenMode TweenMode + { + get + { + return (TweenMode)Interop.Elementary.elm_transit_tween_mode_get(_handle); + } + set + { + Interop.Elementary.elm_transit_tween_mode_set(_handle, (int)value); + } + } + + /// <summary> + /// Gets or sets the transit repeat count. + /// If the repeat is a negative number, it will repeat infinite times. + /// </summary> + public int Repeat + { + get + { + return Interop.Elementary.elm_transit_repeat_times_get(_handle); + } + set + { + Interop.Elementary.elm_transit_repeat_times_set(_handle, value); + } + } + + /// <summary> + /// Gets or sets if the auto reverse is on. + /// </summary> + public bool AutoReverse + { + get + { + return Interop.Elementary.elm_transit_auto_reverse_get(_handle); + } + set + { + Interop.Elementary.elm_transit_auto_reverse_set(_handle, value); + } + } + + /// <summary> + /// Gets or sets the event enabled when transit is operating. + /// </summary> + public bool EventEnabled + { + get + { + return Interop.Elementary.elm_transit_event_enabled_get(_handle); + } + set + { + Interop.Elementary.elm_transit_event_enabled_set(_handle, value); + } + } + + /// <summary> + /// Gets or sets the smooth scaling for transit map rendering + /// This gets smooth scaling for transit map rendering. + /// </summary> + public bool Smooth + { + get + { + return Interop.Elementary.elm_transit_smooth_get(_handle); + } + set + { + Interop.Elementary.elm_transit_smooth_set(_handle, value); + } + } + + /// <summary> + /// Pause/Resume the transition. + /// </summary> + public bool Pause + { + get + { + return Interop.Elementary.elm_transit_paused_get(_handle); + } + set + { + Interop.Elementary.elm_transit_paused_set(_handle, value); + } + } + + /// <summary> + /// Get the time progression of the animation (a double value between 0.0 and 1.0). + /// The value returned is a fraction(current time / total time). + /// It represents the progression position relative to the total. + /// </summary> + public double Progress + { + get + { + return Interop.Elementary.elm_transit_progress_value_get(_handle); + } + } + + /// <summary> + /// Gets or sets the transit animation tween mode acceleration factor. + /// </summary> + /// <returns>A factor value from 0.0 to 1.0.</returns> + public double BeginAccelerationFactor + { + get + { + double begin = 1.0, end = 0.0; + Interop.Elementary.elm_transit_tween_mode_factor_get(_handle, out begin, out end); + return begin; + } + set + { + Interop.Elementary.elm_transit_tween_mode_factor_set(_handle, value, EndAccelerationFactor); + } + } + + /// <summary> + /// Gets or sets the transit animation tween mode acceleration factor. + /// </summary> + /// <returns>A factor value from 0.0 to 1.0.</returns> + public double EndAccelerationFactor + { + get + { + double begin = 1.0, end = 0.0; + Interop.Elementary.elm_transit_tween_mode_factor_get(_handle, out begin, out end); + return end; + } + set + { + Interop.Elementary.elm_transit_tween_mode_factor_set(_handle, BeginAccelerationFactor, value); + } + } + + /// <summary> + /// Starts the transition in given seconds. + /// Once this API is called, the transit begins to measure the time. + /// </summary> + /// <param name="interval">The interval value in seconds</param> + public void Go(double interval = 0) + { + Interop.Elementary.elm_transit_go_in(_handle, interval); + } + + /// <summary> + /// Get the current chained transit list. + /// </summary> + /// <remarks>Cannot add the duplicate transit.</remarks> + public IList<Transit> Chains + { + get { return _chains; } + } + + /// <summary> + /// Get the objects list of the transit. + /// </summary> + /// <remarks>Cannot add the duplicate object.</remarks> + public IList<EvasObject> Objects + { + get { return _objects; } + } + + /// <summary> + /// Add the effect. + /// </summary> + /// <param name="effect">EffectBase object.</param> + public void AddEffect(EffectBase effect) + { + IntPtr _effect = effect.CreateEffect(_handle); + EffectEndCallback = (ptr1, ptr2) => { effect.SendEffectEnd(); }; + Interop.Elementary.elm_transit_effect_add(_handle, null, _effect, EffectEndCallback); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool isDisposing) + { + if (_isDisposed) + return; + + if (isDisposing) + { + ((INotifyCollectionChanged)_chains).CollectionChanged -= OnChaninCollectionChanged; + _chains.Clear(); + ((INotifyCollectionChanged)_objects).CollectionChanged -= OnObjectCollectionChanged; + _objects.Clear(); + _checker.Clear(); + } + + _isDisposed = true; + } + + void OnObjectCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + if (e.Action == NotifyCollectionChangedAction.Add) + { + foreach (EvasObject item in e.NewItems) + AddObject(item); + } + else if (e.Action == NotifyCollectionChangedAction.Remove) + { + foreach (EvasObject item in e.OldItems) + RemoveObject(item); + } + } + + void OnChaninCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + if (e.Action == NotifyCollectionChangedAction.Add) + { + foreach (Transit item in e.NewItems) + AddChainedTransit(item); + } + else if (e.Action == NotifyCollectionChangedAction.Remove) + { + foreach (Transit item in e.OldItems) + DeleteChainedTransit(item); + } + } + + /// <summary> + /// Add new object to apply the effects. + /// After the first addition of an object to transit, if its object list become empty again, the transit will be killed. + /// If the obj belongs to another transit, the obj will be removed from it and it will only belong to the other transit. + /// </summary> + /// <remarks>It is not allowed to add a new object after transit begins.</remarks> + /// <param name="obj">Object to be animated.</param> + void AddObject(EvasObject obj) + { + if (_checker.Contains(obj)) + throw new Exception("Cannot add the duplicate object."); + + _checker.Add(obj); + Interop.Elementary.elm_transit_object_add(_handle, obj); + } + + /// <summary> + /// Removes an added object from the transit. + /// </summary> + /// <param name="obj">Object to be removed from transit.</param> + void RemoveObject(EvasObject obj) + { + if (_checker.Contains(obj)) + _checker.Remove(obj); + + Interop.Elementary.elm_transit_object_remove(_handle, obj); + } + + /// <summary> + /// Makes the chain relationship between two transits. + /// </summary> + /// <param name="transit">The chain transit object. This transit will be operated after transit is done.</param> + void AddChainedTransit(Transit transit) + { + if (_checker.Contains(transit)) + throw new Exception("Cannot add the duplicate transit."); + + _checker.Add(transit); + Interop.Elementary.elm_transit_chain_transit_add(_handle, transit._handle); + } + + /// <summary> + /// Cut off the chain relationship between two transits. + /// </summary> + /// <param name="transit">The chain transit object.</param> + void DeleteChainedTransit(Transit transit) + { + if (_checker.Contains(transit)) + _checker.Remove(transit); + + Interop.Elementary.elm_transit_chain_transit_del(_handle, transit._handle); + } + } +}
\ No newline at end of file diff --git a/ElmSharp/ElmSharp/TransitEffect.cs b/ElmSharp/ElmSharp/TransitEffect.cs new file mode 100755 index 0000000..fd29499 --- /dev/null +++ b/ElmSharp/ElmSharp/TransitEffect.cs @@ -0,0 +1,461 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Collections.Generic; + +namespace ElmSharp +{ + /// <summary> + /// The axis along which flip effect should be applied. + /// </summary> + public enum FlipAxis + { + /// <summary> + /// Flip on X axis + /// </summary> + X, + + /// <summary> + /// Flip on Y axis + /// </summary> + Y, + } + + /// <summary> + /// The direction in which the wipe effect should occur. + /// </summary> + public enum WipeDirection + { + /// <summary> + /// Wipe to the left + /// </summary> + Left, + + /// <summary> + /// Wipe to the right + /// </summary> + Right, + + /// <summary> + /// Wipe to the up + /// </summary> + Up, + + /// <summary> + /// Wipe to the down + /// </summary> + Down, + } + + /// <summary> + /// Whether the wipe effect should show or hide the object. + /// </summary> + public enum WipeType + { + /// <summary> + /// Hide the object during the animation + /// </summary> + Hide, + + /// <summary> + /// Show the object during the animation + /// </summary> + Show, + } + + /// <summary> + /// The type of acceleration used in the transition. + /// </summary> + public enum TweenMode + { + /// <summary> + /// Constant speed + /// </summary> + Linear, + + /// <summary> + /// Starts slow, increase speed over time, then decrease again and stop slowly, v1 being a power factor + /// </summary> + Sinusoidal, + + /// <summary> + /// Starts fast and decrease speed over time, v1 being a power factor + /// </summary> + Decelerate, + + /// <summary> + /// Starts slow and increase speed over time, v1 being a power factor + /// </summary> + Accelerate, + + /// <summary> + /// Start at gradient v1, interpolated via power of v2 curve + /// </summary> + DivisorInterpolate, + + /// <summary> + /// Start at 0.0 then "drop" like a ball bouncing to the ground at 1.0, and bounce v2 times, with decay factor of v1 + /// </summary> + Bounce, + + /// <summary> + /// Start at 0.0 then "wobble" like a spring rest position 1.0, and wobble v2 times, with decay factor of v1 + /// </summary> + Spring, + + /// <summary> + /// Follow the cubic-bezier curve calculated with the control points (x1, y1), (x2, y2) + /// </summary> + BezierCurve, + } + + /// <summary> + /// Blend effect class. + /// </summary> + public class BlendEffect : EffectBase + { + /// <summary> + /// Creates and initializes a new instance of BlendEffect class. + /// </summary> + public BlendEffect() + { + } + + internal override IntPtr CreateEffect(IntPtr transit) + { + return Interop.Elementary.elm_transit_effect_blend_add(transit); + } + } + + /// <summary> + /// Color effect class. + /// </summary> + public class ColorEffect : EffectBase + { + Color _begin; + Color _end; + + /// <summary> + /// Creates and initializes a new instance of ColorEffect class. + /// </summary> + /// <param name="beginColor">The begin color of the effect</param> + /// <param name="endColor">The end color of the effect</param> + public ColorEffect(Color beginColor, Color endColor) + { + _begin = beginColor; + _end = endColor; + } + + /// <summary> + /// The begin color of the effect + /// </summary> + public Color BeginColor + { + get { return _begin; } + } + + /// <summary> + /// The end color of the effect + /// </summary> + public Color EndColor + { + get { return _end; } + } + + internal override IntPtr CreateEffect(IntPtr transit) + { + return Interop.Elementary.elm_transit_effect_color_add(transit, _begin.R, _begin.G, _begin.B, _begin.A, _end.R, _end.G, _end.B, _end.A); + } + } + + /// <summary> + /// Fade effect class. + /// </summary> + public class FadeEffect : EffectBase + { + /// <summary> + /// Creates and initializes a new instance of FadeEffect class. + /// </summary> + public FadeEffect() + { + } + + internal override IntPtr CreateEffect(IntPtr transit) + { + return Interop.Elementary.elm_transit_effect_fade_add(transit); + } + } + + /// <summary> + /// Flip effect class. + /// </summary> + public class FlipEffect : EffectBase + { + FlipAxis _axis; + bool _clockWise; + bool _resizable; + + /// <summary> + /// Creates and initializes a new instance of FlipEffect class. + /// </summary> + /// <param name="axis">Flipping Axis(X or Y).</param> + /// <param name="clockWise">Flipping Direction. True is clock-wise.</param> + /// <param name="resizable">Resizable effect with FlipEffect</param> + public FlipEffect(FlipAxis axis, bool clockWise, bool resizable = false) + { + _axis = axis; + _clockWise = clockWise; + _resizable = resizable; + } + + /// <summary> + /// Flipping Axis(X or Y). + /// </summary> + public FlipAxis Axis + { + get { return _axis; } + } + + /// <summary> + /// Flipping Direction. True is clock-wise. + /// </summary> + public bool ClockWise + { + get { return _clockWise; } + } + + /// <summary> + /// Resizable FlipEffect. + /// </summary> + public bool Resizable + { + get { return _resizable; } + } + + internal override IntPtr CreateEffect(IntPtr transit) + { + if (_resizable) + return Interop.Elementary.elm_transit_effect_resizable_flip_add(transit, (int)_axis, _clockWise); + return Interop.Elementary.elm_transit_effect_flip_add(transit, (int)_axis, _clockWise); + } + } + + /// <summary> + /// Resizing effect class. + /// </summary> + public class ResizingEffect : EffectBase + { + Size _begin; + Size _end; + + /// <summary> + /// Creates and initializes a new instance of FlipEffect class. + /// </summary> + /// <param name="beginSize">The begin Size of the effect</param> + /// <param name="endSize">The end Size of the effect</param> + public ResizingEffect(Size beginSize, Size endSize) + { + _begin = beginSize; + _end = endSize; + } + + /// <summary> + /// The begin Size of the effect + /// </summary> + public Size BeginSize + { + get { return _begin; } + } + + /// <summary> + /// The end Size of the effect + /// </summary> + public Size EndSize + { + get { return _end; } + } + + internal override IntPtr CreateEffect(IntPtr transit) + { + return Interop.Elementary.elm_transit_effect_resizing_add(transit, _begin.Width, _begin.Height, _end.Width, _end.Height); + } + } + + /// <summary> + /// Rotation effect class. + /// </summary> + public class RotationEffect : EffectBase + { + float _begin; + float _end; + + /// <summary> + /// Creates and initializes a new instance of RotationEffect class. + /// </summary> + /// <param name="beginDegree">The begin degree of the effect</param> + /// <param name="endDegree">The end degree of the effect</param> + public RotationEffect(float beginDegree, float endDegree) + { + _begin = beginDegree; + _end = endDegree; + } + + /// <summary> + /// The begin degree of the effect + /// </summary> + public float BeginDegree + { + get { return _begin; } + } + + /// <summary> + /// The end degree of the effect + /// </summary> + public float EndDegree + { + get { return _end; } + } + + internal override IntPtr CreateEffect(IntPtr transit) + { + return Interop.Elementary.elm_transit_effect_rotation_add(transit, _begin, _end); + } + } + + /// <summary> + /// Translation effect class. + /// </summary> + public class TranslationEffect : EffectBase + { + Point _begin; + Point _end; + + /// <summary> + /// Creates and initializes a new instance of FlipEffect class. + /// </summary> + /// <param name="beginPoint">The begin Point of the effect</param> + /// <param name="endPoint">The end Point of the effect</param> + public TranslationEffect(Point beginPoint, Point endPoint) + { + _begin = beginPoint; + _end = endPoint; + } + + /// <summary> + /// The begin Point of the effect + /// </summary> + public Point BeginPoint + { + get { return _begin; } + } + + /// <summary> + /// The end Point of the effect + /// </summary> + public Point EndPoint + { + get { return _end; } + } + + internal override IntPtr CreateEffect(IntPtr transit) + { + return Interop.Elementary.elm_transit_effect_translation_add(transit, _begin.X, _begin.Y, _end.X, _end.Y); + } + } + + /// <summary> + /// Wipe effect class. + /// </summary> + public class WipeEffect : EffectBase + { + WipeType _type; + WipeDirection _direction; + + /// <summary> + /// Creates and initializes a new instance of WipeEffect class. + /// </summary> + /// <param name="type">Wipe type. Hide or show.</param> + /// <param name="direction">Wipe Direction.</param> + public WipeEffect(WipeType type, WipeDirection direction) + { + _type = type; + _direction = direction; + } + + /// <summary> + /// Wipe type. Hide or show. + /// </summary> + public WipeType Type + { + get { return _type; } + } + + /// <summary> + /// Wipe Direction. + /// </summary> + public WipeDirection Direction + { + get { return _direction; } + } + + internal override IntPtr CreateEffect(IntPtr transit) + { + return Interop.Elementary.elm_transit_effect_wipe_add(transit, (int)_type, (int)_direction); + } + } + + /// <summary> + /// Zoom effect class. + /// </summary> + public class ZoomEffect : EffectBase + { + float _begin; + float _end; + + /// <summary> + /// Creates and initializes a new instance of ZoomEffect class. + /// </summary> + /// <param name="beginRate">The begin rate of the effect</param> + /// <param name="endRate">The end rate of the effect</param> + public ZoomEffect(float beginRate, float endRate) + { + _begin = beginRate; + _end = endRate; + } + + /// <summary> + /// The begin rate of the effect + /// </summary> + public float BeginRate + { + get { return _begin; } + } + + /// <summary> + /// The end rate of the effect + /// </summary> + public float EndRate + { + get { return _end; } + } + + internal override IntPtr CreateEffect(IntPtr transit) + { + return Interop.Elementary.elm_transit_effect_zoom_add(transit, _begin, _end); + } + } +}
\ No newline at end of file |