Author: toshok
Date: 2007-06-09 17:57:56 -0400 (Sat, 09 Jun 2007)
New Revision: 79081
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/animation.cpp
trunk/moon/src/animation.h
trunk/moon/src/runtime.cpp
trunk/moon/src/value.h
Log:
* animation.h, animation.cpp, value.h, runtime.cpp: add
ColorKeyFrame and it's linear/discrete subclasses, as well as
ColorAnimationUsingKeyFrames.
2007-06-09 Chris Toshok <[EMAIL PROTECTED]>
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2007-06-09 21:41:54 UTC (rev 79080)
+++ trunk/moon/src/ChangeLog 2007-06-09 21:57:56 UTC (rev 79081)
@@ -1,5 +1,11 @@
2007-06-09 Chris Toshok <[EMAIL PROTECTED]>
+ * animation.h, animation.cpp, value.h, runtime.cpp: add
+ ColorKeyFrame and it's linear/discrete subclasses, as well as
+ ColorAnimationUsingKeyFrames.
+
+2007-06-09 Chris Toshok <[EMAIL PROTECTED]>
+
* animation.h, animation.cpp, value.h, runtime.cpp: add the
Discrete keyframes for point and double.
Modified: trunk/moon/src/animation.cpp
===================================================================
--- trunk/moon/src/animation.cpp 2007-06-09 21:41:54 UTC (rev 79080)
+++ trunk/moon/src/animation.cpp 2007-06-09 21:57:56 UTC (rev 79081)
@@ -428,6 +428,13 @@
}
+DependencyProperty* ColorKeyFrame::ValueProperty;
+
+ColorKeyFrame::ColorKeyFrame ()
+{
+}
+
+
DependencyProperty* PointKeyFrame::ValueProperty;
PointKeyFrame::PointKeyFrame ()
@@ -456,6 +463,26 @@
Value*
+DiscreteColorKeyFrame::InterpolateValue (Value *baseValue, double
keyFrameProgress)
+{
+ Color *to = GetValue();
+ /* XXX GetValue can return NULL */
+
+ if (keyFrameProgress == 1.0)
+ return new Value(*to);
+ else
+ return new Value (*baseValue->AsColor());
+}
+
+DiscreteColorKeyFrame*
+discrete_color_key_frame_new ()
+{
+ return new DiscreteColorKeyFrame ();
+}
+
+
+
+Value*
DiscretePointKeyFrame::InterpolateValue (Value *baseValue, double
keyFrameProgress)
{
Point *to = GetValue();
@@ -497,7 +524,30 @@
}
+
Value*
+LinearColorKeyFrame::InterpolateValue (Value *baseValue, double
keyFrameProgress)
+{
+ Color *to = GetValue();
+ /* XXX GetValue can return NULL */
+
+ Color start, end;
+
+ start = *baseValue->AsColor();
+ end = *to;
+
+ return new Value (LERP (start, end, keyFrameProgress));
+}
+
+LinearColorKeyFrame*
+linear_color_key_frame_new ()
+{
+ return new LinearColorKeyFrame ();
+}
+
+
+
+Value*
LinearPointKeyFrame::InterpolateValue (Value *baseValue, double
keyFrameProgress)
{
Point *to = GetValue();
@@ -597,7 +647,84 @@
+ColorAnimationUsingKeyFrames::ColorAnimationUsingKeyFrames()
+{
+ key_frames = NULL;
+}
+void
+ColorAnimationUsingKeyFrames::AddKeyFrame (ColorKeyFrame *frame)
+{
+ key_frames = g_list_append (key_frames, frame);
+}
+
+void
+ColorAnimationUsingKeyFrames::RemoveKeyFrame (ColorKeyFrame *frame)
+{
+}
+
+Value*
+ColorAnimationUsingKeyFrames::GetCurrentValue (Value *defaultOriginValue,
Value *defaultDestinationValue,
+ AnimationClock* animationClock)
+{
+
+ /* current segment info */
+ TimeSpan current_time = animationClock->GetCurrentTime();
+ ColorKeyFrame *current_keyframe;
+ ColorKeyFrame *previous_keyframe = NULL;
+ Value *baseValue;
+
+ TimeSpan key_end_time;
+
+ /* figure out what segment to use (this list needs to be sorted) */
+ for (GList *l = key_frames; l; l = l->next) {
+ ColorKeyFrame *keyframe = (ColorKeyFrame*)l->data;
+
+ key_end_time = keyframe->GetKeyTime()->GetTimeSpan();
+
+ if (key_end_time >= current_time) {
+ current_keyframe = keyframe;
+
+ if (l->prev)
+ previous_keyframe =
(ColorKeyFrame*)l->prev->data;
+
+ break;
+ }
+
+ }
+
+ TimeSpan key_start_time;
+
+ if (previous_keyframe == NULL) {
+ /* the first keyframe, start at the animation's base value */
+ baseValue = defaultOriginValue;
+ key_start_time = 0;
+ }
+ else {
+ /* start at the previous keyframe's target value */
+ baseValue = new Value(*previous_keyframe->GetValue ());
+ /* XXX ColorKeyFrame::Value is nullable */
+ key_start_time = previous_keyframe->GetKeyTime()->GetTimeSpan
();
+ }
+
+ TimeSpan key_duration = key_end_time - key_start_time;
+ double progress = (double)(current_time - key_start_time) /
key_duration;
+
+ /* get the current value out of that segment */
+
+ return current_keyframe->InterpolateValue (baseValue, progress);
+}
+
+
+ColorAnimationUsingKeyFrames*
+color_animation_using_key_frames_new ()
+{
+ return new ColorAnimationUsingKeyFrames ();
+}
+
+
+
+
PointAnimationUsingKeyFrames::PointAnimationUsingKeyFrames()
{
key_frames = NULL;
@@ -618,45 +745,52 @@
PointAnimationUsingKeyFrames::GetCurrentValue (Value *defaultOriginValue,
Value *defaultDestinationValue,
AnimationClock* animationClock)
{
- return NULL;
-#if false
+
/* current segment info */
+ TimeSpan current_time = animationClock->GetCurrentTime();
PointKeyFrame *current_keyframe;
- Value *start;
- TimeSpan segment_start_time;
+ PointKeyFrame *previous_keyframe = NULL;
+ Value *baseValue;
+ TimeSpan key_end_time;
+
/* figure out what segment to use (this list needs to be sorted) */
for (GList *l = key_frames; l; l = l->next) {
PointKeyFrame *keyframe = (PointKeyFrame*)l->data;
- if (true/*keyframe is the right one*/) {
- GList *prev = l->prev;
+ key_end_time = keyframe->GetKeyTime()->GetTimeSpan();
+ if (key_end_time >= current_time) {
current_keyframe = keyframe;
- if (prev == NULL) {
- /* the first keyframe, start at the animation's
base value */
- start = defaultOriginValue;
- segment_start_time = 0;
- }
- else {
- PointKeyFrame *prev_frame =
(PointKeyFrame*)l->data;
- /* start at the previous keyframe's target
value */
- start = new Value(*prev_frame->GetValue ()); //
XXX we leak this
- /* XXX PointKeyFrame::Value is nullable */
- segment_start_time =
prev_frame->GetKeyTime()->GetTimeSpan ();
- }
+ if (l->prev)
+ previous_keyframe =
(PointKeyFrame*)l->prev->data;
break;
}
+
}
+ TimeSpan key_start_time;
+
+ if (previous_keyframe == NULL) {
+ /* the first keyframe, start at the animation's base value */
+ baseValue = defaultOriginValue;
+ key_start_time = 0;
+ }
+ else {
+ /* start at the previous keyframe's target value */
+ baseValue = new Value(*previous_keyframe->GetValue ());
+ /* XXX PointKeyFrame::Value is nullable */
+ key_start_time = previous_keyframe->GetKeyTime()->GetTimeSpan
();
+ }
+
+ TimeSpan key_duration = key_end_time - key_start_time;
+ double progress = (double)(current_time - key_start_time) /
key_duration;
+
/* get the current value out of that segment */
-
- return current_keyframe->GetCurrentValue (start, NULL, /* XXX */
- segment_start_time,
- animationClock);
-#endif
+
+ return current_keyframe->InterpolateValue (baseValue, progress);
}
@@ -741,5 +875,6 @@
NULLABLE_GETSET_IMPL (PointAnimation, From, Point, Point)
+NULLABLE_GETSET_IMPL (ColorKeyFrame, Value, Color, Color)
NULLABLE_GETSET_IMPL (PointKeyFrame, Value, Point, Point)
NULLABLE_PRIM_GETSET_IMPL (DoubleKeyFrame, Value, double, Double)
Modified: trunk/moon/src/animation.h
===================================================================
--- trunk/moon/src/animation.h 2007-06-09 21:41:54 UTC (rev 79080)
+++ trunk/moon/src/animation.h 2007-06-09 21:57:56 UTC (rev 79081)
@@ -252,6 +252,18 @@
};
+
+class ColorKeyFrame : public KeyFrame {
+ public:
+ ColorKeyFrame ();
+ Value::Kind GetObjectType () { return Value::COLORKEYFRAME; };
+
+ NULLABLE_GETSET_DECL(Value, Color);
+
+ static DependencyProperty *ValueProperty;
+};
+
+
class PointKeyFrame : public KeyFrame {
public:
PointKeyFrame ();
@@ -263,6 +275,8 @@
};
+
+
class DiscreteDoubleKeyFrame : public DoubleKeyFrame {
public:
DiscreteDoubleKeyFrame () { }
@@ -275,6 +289,18 @@
+class DiscreteColorKeyFrame : public ColorKeyFrame {
+ public:
+ DiscreteColorKeyFrame () { }
+ Value::Kind GetObjectType () { return Value::DISCRETECOLORKEYFRAME; };
+
+ virtual Value *InterpolateValue (Value *baseValue, double
keyFrameProgress);
+};
+
+DiscreteColorKeyFrame* discrete_color_key_frame_new ();
+
+
+
class DiscretePointKeyFrame : public PointKeyFrame {
public:
DiscretePointKeyFrame () { }
@@ -287,6 +313,7 @@
+
class LinearDoubleKeyFrame : public DoubleKeyFrame {
public:
LinearDoubleKeyFrame () { }
@@ -297,6 +324,19 @@
LinearDoubleKeyFrame* linear_double_key_frame_new ();
+class LinearColorKeyFrame : public ColorKeyFrame {
+ public:
+ LinearColorKeyFrame () { }
+ Value::Kind GetObjectType () { return Value::LINEARCOLORKEYFRAME; };
+
+ virtual Value *InterpolateValue (Value *baseValue, double
keyFrameProgress);
+};
+
+LinearColorKeyFrame* linear_color_key_frame_new ();
+
+
+
+
class LinearPointKeyFrame : public PointKeyFrame {
public:
LinearPointKeyFrame () { }
@@ -308,6 +348,7 @@
LinearPointKeyFrame* linear_point_key_frame_new ();
+
class DoubleAnimationUsingKeyFrames : public DoubleAnimation {
public:
DoubleAnimationUsingKeyFrames ();
@@ -327,6 +368,26 @@
DoubleAnimationUsingKeyFrames* double_animation_using_key_frames_new ();
+class ColorAnimationUsingKeyFrames : public ColorAnimation {
+ public:
+ ColorAnimationUsingKeyFrames ();
+ Value::Kind GetObjectType () { return
Value::COLORANIMATIONUSINGKEYFRAMES; };
+
+ void AddKeyFrame (ColorKeyFrame *frame);
+ void RemoveKeyFrame (ColorKeyFrame *frame);
+
+ static DependencyProperty *KeyFramesProperty;
+
+ virtual Value *GetCurrentValue (Value *defaultOriginValue, Value
*defaultDestinationValue,
+ AnimationClock* animationClock);
+
+ private:
+ GList *key_frames;
+};
+
+ColorAnimationUsingKeyFrames* color_animation_using_key_frames_new ();
+
+
class PointAnimationUsingKeyFrames : public PointAnimation {
public:
PointAnimationUsingKeyFrames ();
Modified: trunk/moon/src/runtime.cpp
===================================================================
--- trunk/moon/src/runtime.cpp 2007-06-09 21:41:54 UTC (rev 79080)
+++ trunk/moon/src/runtime.cpp 2007-06-09 21:57:56 UTC (rev 79081)
@@ -1685,12 +1685,16 @@
Type::RegisterType ("EventTrigger", Value::EVENTTRIGGER,
Value::DEPENDENCY_OBJECT);
Type::RegisterType ("KeyFrame", Value::KEYFRAME,
Value::DEPENDENCY_OBJECT);
+ Type::RegisterType ("ColorKeyFrame", Value::COLORKEYFRAME,
Value::KEYFRAME);
Type::RegisterType ("DoubleKeyFrame", Value::DOUBLEKEYFRAME,
Value::KEYFRAME);
Type::RegisterType ("PointKeyFrame", Value::POINTKEYFRAME,
Value::KEYFRAME);
+ Type::RegisterType ("DiscreteColorKeyFrame",
Value::DISCRETECOLORKEYFRAME, Value::DOUBLEKEYFRAME);
Type::RegisterType ("DiscreteDoubleKeyFrame",
Value::DISCRETEDOUBLEKEYFRAME, Value::DOUBLEKEYFRAME);
Type::RegisterType ("DiscretePointKeyFrame",
Value::DISCRETEPOINTKEYFRAME, Value::POINTKEYFRAME);
+ Type::RegisterType ("LinearColorKeyFrame", Value::LINEARCOLORKEYFRAME,
Value::COLORKEYFRAME);
Type::RegisterType ("LinearDoubleKeyFrame",
Value::LINEARDOUBLEKEYFRAME, Value::DOUBLEKEYFRAME);
Type::RegisterType ("LinearPointKeyFrame", Value::LINEARPOINTKEYFRAME,
Value::POINTKEYFRAME);
+ Type::RegisterType ("ColorAnimationUsingKeyFrames",
Value::COLORANIMATIONUSINGKEYFRAMES, Value::COLORANIMATION);
Type::RegisterType ("DoubleAnimationUsingKeyFrames",
Value::DOUBLEANIMATIONUSINGKEYFRAMES, Value::DOUBLEANIMATION);
Type::RegisterType ("PointAnimationUsingKeyFrames",
Value::POINTANIMATIONUSINGKEYFRAMES, Value::POINTANIMATION);
Modified: trunk/moon/src/value.h
===================================================================
--- trunk/moon/src/value.h 2007-06-09 21:41:54 UTC (rev 79080)
+++ trunk/moon/src/value.h 2007-06-09 21:57:56 UTC (rev 79081)
@@ -171,12 +171,16 @@
BEGINSTORYBOARD,
EVENTTRIGGER,
KEYFRAME,
+ COLORKEYFRAME,
DOUBLEKEYFRAME,
POINTKEYFRAME,
+ DISCRETECOLORKEYFRAME,
DISCRETEDOUBLEKEYFRAME,
DISCRETEPOINTKEYFRAME,
+ LINEARCOLORKEYFRAME,
LINEARDOUBLEKEYFRAME,
LINEARPOINTKEYFRAME,
+ COLORANIMATIONUSINGKEYFRAMES,
DOUBLEANIMATIONUSINGKEYFRAMES,
POINTANIMATIONUSINGKEYFRAMES,
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches