Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
b2addc35
E
engine
项目概览
sxychenjing
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b2addc35
编写于
8月 04, 2015
作者:
M
mpcomplete
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #446 from mpcomplete/curves
When animating, use the same curve until it completes.
上级
7b0856d8
d3817ff4
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
112 addition
and
89 deletion
+112
-89
sky/packages/sky/lib/animation/animated_value.dart
sky/packages/sky/lib/animation/animated_value.dart
+49
-37
sky/packages/sky/lib/animation/animation_performance.dart
sky/packages/sky/lib/animation/animation_performance.dart
+21
-2
sky/packages/sky/lib/animation/curves.dart
sky/packages/sky/lib/animation/curves.dart
+16
-0
sky/packages/sky/lib/animation/direction.dart
sky/packages/sky/lib/animation/direction.dart
+8
-0
sky/packages/sky/lib/animation/forces.dart
sky/packages/sky/lib/animation/forces.dart
+1
-6
sky/packages/sky/lib/rendering/toggleable.dart
sky/packages/sky/lib/rendering/toggleable.dart
+2
-10
sky/packages/sky/lib/widgets/animated_container.dart
sky/packages/sky/lib/widgets/animated_container.dart
+7
-23
sky/packages/sky/lib/widgets/navigator.dart
sky/packages/sky/lib/widgets/navigator.dart
+0
-1
sky/packages/sky/lib/widgets/popup_menu.dart
sky/packages/sky/lib/widgets/popup_menu.dart
+3
-5
sky/packages/sky/lib/widgets/transitions.dart
sky/packages/sky/lib/widgets/transitions.dart
+5
-5
未找到文件。
sky/packages/sky/lib/animation/animated_value.dart
浏览文件 @
b2addc35
...
...
@@ -5,84 +5,96 @@
import
"dart:sky"
;
import
'package:sky/animation/curves.dart'
;
import
'package:sky/animation/direction.dart'
;
import
'package:sky/base/lerp.dart'
;
export
'package:sky/animation/curves.dart'
show
Interval
;
abstract
class
AnimatedVariable
{
void
setProgress
(
double
t
);
void
setProgress
(
double
t
,
Direction
direction
);
String
toString
();
}
class
Interval
{
final
double
start
;
final
double
end
;
abstract
class
CurvedVariable
implements
AnimatedVariable
{
CurvedVariable
({
this
.
interval
,
this
.
reverseInterval
,
this
.
curve
,
this
.
reverseCurve
});
Interval
interval
;
Interval
reverseInterval
;
Curve
curve
;
Curve
reverseCurve
;
double
_transform
(
double
t
,
Direction
direction
)
{
Interval
interval
=
_getInterval
(
direction
);
if
(
interval
!=
null
)
t
=
interval
.
transform
(
t
);
if
(
t
==
1.0
)
// Or should we support inverse curves?
return
t
;
Curve
curve
=
_getCurve
(
direction
);
if
(
curve
!=
null
)
t
=
curve
.
transform
(
t
);
return
t
;
}
double
adjustTime
(
double
t
)
{
return
((
t
-
start
)
/
(
end
-
start
)).
clamp
(
0.0
,
1.0
);
Interval
_getInterval
(
Direction
direction
)
{
if
(
direction
==
Direction
.
forward
||
reverseInterval
==
null
)
return
interval
;
return
reverseInterval
;
}
Interval
(
this
.
start
,
this
.
end
)
{
assert
(
start
>=
0.0
);
assert
(
start
<=
1.0
);
assert
(
end
>=
0.0
);
assert
(
end
<=
1.0
);
Curve
_getCurve
(
Direction
direction
)
{
if
(
direction
==
Direction
.
forward
||
reverseCurve
==
null
)
return
curve
;
return
reverseCurve
;
}
}
class
AnimatedValue
<
T
extends
dynamic
>
extends
AnimatedVariable
{
AnimatedValue
(
this
.
begin
,
{
this
.
end
,
this
.
interval
,
this
.
curve
:
linear
})
{
class
AnimatedValue
<
T
extends
dynamic
>
extends
CurvedVariable
{
AnimatedValue
(
this
.
begin
,
{
this
.
end
,
Interval
interval
,
Curve
curve
,
Curve
reverseCurve
})
:
super
(
interval:
interval
,
curve:
curve
,
reverseCurve:
reverseCurve
)
{
value
=
begin
;
}
T
value
;
T
begin
;
T
end
;
Interval
interval
;
Curve
curve
;
void
setProgress
(
double
t
)
{
T
lerp
(
double
t
)
=>
begin
+
(
end
-
begin
)
*
t
;
void
setProgress
(
double
t
,
Direction
direction
)
{
if
(
end
!=
null
)
{
double
adjustedTime
=
interval
==
null
?
t
:
interval
.
adjustTime
(
t
);
if
(
adjustedTime
==
1.0
)
{
value
=
end
;
}
else
{
// TODO(mpcomplete): Reverse the timeline and curve.
value
=
begin
+
(
end
-
begin
)
*
curve
.
transform
(
adjustedTime
);
}
t
=
_transform
(
t
,
direction
);
value
=
(
t
==
1.0
)
?
end
:
lerp
(
t
);
}
}
String
toString
()
=>
'AnimatedValue(begin=
$begin
, end=
$end
, value=
$value
)'
;
}
class
AnimatedList
extends
Animat
edVariable
{
class
AnimatedList
extends
Curv
edVariable
{
List
<
AnimatedVariable
>
variables
;
Interval
interval
;
AnimatedList
(
this
.
variables
,
{
this
.
interval
});
AnimatedList
(
this
.
variables
,
{
Interval
interval
,
Curve
curve
,
Curve
reverseCurve
})
:
super
(
interval:
interval
,
curve:
curve
,
reverseCurve:
reverseCurve
);
void
setProgress
(
double
t
)
{
double
adjustedTime
=
interval
==
null
?
t
:
interval
.
adjustTime
(
t
);
void
setProgress
(
double
t
,
Direction
direction
)
{
double
adjustedTime
=
_transform
(
t
,
direction
);
for
(
AnimatedVariable
variable
in
variables
)
variable
.
setProgress
(
adjustedTime
);
variable
.
setProgress
(
adjustedTime
,
direction
);
}
String
toString
()
=>
'AnimatedList([
$variables
])'
;
}
class
AnimatedColorValue
extends
AnimatedValue
<
Color
>
{
AnimatedColorValue
(
Color
begin
,
{
Color
end
,
Curve
curve
:
linear
})
AnimatedColorValue
(
Color
begin
,
{
Color
end
,
Curve
curve
})
:
super
(
begin
,
end:
end
,
curve:
curve
);
void
setProgress
(
double
t
)
{
value
=
lerpColor
(
begin
,
end
,
t
);
}
Color
lerp
(
double
t
)
=>
lerpColor
(
begin
,
end
,
t
);
}
class
AnimatedRect
extends
AnimatedValue
<
Rect
>
{
AnimatedRect
(
Rect
begin
,
{
Rect
end
,
Curve
curve
:
linear
})
AnimatedRect
(
Rect
begin
,
{
Rect
end
,
Curve
curve
})
:
super
(
begin
,
end:
end
,
curve:
curve
);
void
setProgress
(
double
t
)
{
value
=
lerpRect
(
begin
,
end
,
t
);
}
Rect
lerp
(
double
t
)
=>
lerpRect
(
begin
,
end
,
t
);
}
sky/packages/sky/lib/animation/animation_performance.dart
浏览文件 @
b2addc35
...
...
@@ -5,10 +5,11 @@
import
'dart:async'
;
import
'package:sky/animation/animated_value.dart'
;
import
'package:sky/animation/direction.dart'
;
import
'package:sky/animation/forces.dart'
;
import
'package:sky/animation/timeline.dart'
;
export
'package:sky/animation/
forces
.dart'
show
Direction
;
export
'package:sky/animation/
direction
.dart'
show
Direction
;
enum
AnimationStatus
{
dismissed
,
// stoped at 0
...
...
@@ -39,6 +40,12 @@ class AnimationPerformance {
Direction
_direction
;
Direction
get
direction
=>
_direction
;
// This controls which curve we use for variables with different curves in
// the forward/reverse directions. Curve direction is only reset when we hit
// 0 or 1, to avoid discontinuities.
Direction
_curveDirection
;
Direction
get
curveDirection
=>
_curveDirection
;
// If non-null, animate with this force instead of a tween animation.
Force
attachedForce
;
...
...
@@ -74,6 +81,10 @@ class AnimationPerformance {
AnimationStatus
.
reverse
;
}
void
updateVariable
(
AnimatedVariable
variable
)
{
variable
.
setProgress
(
progress
,
curveDirection
);
}
Future
play
([
Direction
direction
=
Direction
.
forward
])
{
_direction
=
direction
;
return
resume
();
...
...
@@ -136,6 +147,13 @@ class AnimationPerformance {
_lastStatus
=
currentStatus
;
}
void
_updateCurveDirection
()
{
if
(
status
!=
_lastStatus
)
{
if
(
_lastStatus
==
AnimationStatus
.
dismissed
||
_lastStatus
==
AnimationStatus
.
completed
)
_curveDirection
=
direction
;
}
}
Future
_animateTo
(
double
target
)
{
Duration
remainingDuration
=
duration
*
(
target
-
timeline
.
value
).
abs
();
timeline
.
stop
();
...
...
@@ -145,8 +163,9 @@ class AnimationPerformance {
}
void
_tick
(
double
t
)
{
_updateCurveDirection
();
if
(
variable
!=
null
)
variable
.
setProgress
(
t
);
variable
.
setProgress
(
t
,
curveDirection
);
_notifyListeners
();
_checkStatusChanged
();
}
...
...
sky/packages/sky/lib/animation/curves.dart
浏览文件 @
b2addc35
...
...
@@ -21,6 +21,22 @@ class Linear implements Curve {
}
}
class
Interval
implements
Curve
{
final
double
start
;
final
double
end
;
Interval
(
this
.
start
,
this
.
end
)
{
assert
(
start
>=
0.0
);
assert
(
start
<=
1.0
);
assert
(
end
>=
0.0
);
assert
(
end
<=
1.0
);
}
double
transform
(
double
t
)
{
return
((
t
-
start
)
/
(
end
-
start
)).
clamp
(
0.0
,
1.0
);
}
}
class
ParabolicFall
implements
Curve
{
const
ParabolicFall
();
...
...
sky/packages/sky/lib/animation/direction.dart
0 → 100644
浏览文件 @
b2addc35
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
enum
Direction
{
forward
,
reverse
}
sky/packages/sky/lib/animation/forces.dart
浏览文件 @
b2addc35
...
...
@@ -3,12 +3,7 @@
// found in the LICENSE file.
import
'package:newton/newton.dart'
;
// TODO(mpcomplete): This doesn't belong here.
enum
Direction
{
forward
,
reverse
}
import
'package:sky/animation/direction.dart'
;
// Base class for creating Simulations for the animation Timeline.
abstract
class
Force
{
...
...
sky/packages/sky/lib/rendering/toggleable.dart
浏览文件 @
b2addc35
...
...
@@ -44,15 +44,7 @@ abstract class RenderToggleable extends RenderConstrainedBox {
void
set
value
(
bool
value
)
{
if
(
value
==
_value
)
return
;
_value
=
value
;
// TODO(abarth): Setting the curve on the position means there's a
// discontinuity when we reverse the timeline.
if
(
value
)
{
_position
.
curve
=
easeIn
;
_performance
.
play
();
}
else
{
_position
.
curve
=
easeOut
;
_performance
.
reverse
();
}
performance
.
play
(
value
?
Direction
.
forward
:
Direction
.
reverse
);
}
ValueChanged
_onChanged
;
...
...
@@ -63,7 +55,7 @@ abstract class RenderToggleable extends RenderConstrainedBox {
}
final
AnimatedValue
<
double
>
_position
=
new
AnimatedValue
<
double
>(
0.0
,
end:
1.0
);
new
AnimatedValue
<
double
>(
0.0
,
end:
1.0
,
curve:
easeIn
,
reverseCurve:
easeOut
);
AnimatedValue
<
double
>
get
position
=>
_position
;
AnimationPerformance
_performance
;
...
...
sky/packages/sky/lib/widgets/animated_container.dart
浏览文件 @
b2addc35
...
...
@@ -16,35 +16,23 @@ class AnimatedBoxConstraintsValue extends AnimatedValue<BoxConstraints> {
AnimatedBoxConstraintsValue
(
BoxConstraints
begin
,
{
BoxConstraints
end
,
Curve
curve:
linear
})
:
super
(
begin
,
end:
end
,
curve:
curve
);
void
setProgress
(
double
t
)
{
// TODO(abarth): We should lerp the BoxConstraints.
value
=
end
;
}
// TODO(abarth): We should lerp the BoxConstraints.
BoxConstraints
lerp
(
double
t
)
=>
end
;
}
class
AnimatedBoxDecorationValue
extends
AnimatedValue
<
BoxDecoration
>
{
AnimatedBoxDecorationValue
(
BoxDecoration
begin
,
{
BoxDecoration
end
,
Curve
curve:
linear
})
:
super
(
begin
,
end:
end
,
curve:
curve
);
void
setProgress
(
double
t
)
{
if
(
t
==
1.0
)
{
value
=
end
;
return
;
}
value
=
lerpBoxDecoration
(
begin
,
end
,
t
);
}
BoxDecoration
lerp
(
double
t
)
=>
lerpBoxDecoration
(
begin
,
end
,
t
);
}
class
AnimatedEdgeDimsValue
extends
AnimatedValue
<
EdgeDims
>
{
AnimatedEdgeDimsValue
(
EdgeDims
begin
,
{
EdgeDims
end
,
Curve
curve:
linear
})
:
super
(
begin
,
end:
end
,
curve:
curve
);
void
setProgress
(
double
t
)
{
if
(
t
==
1.0
)
{
value
=
end
;
return
;
}
value
=
new
EdgeDims
(
EdgeDims
lerp
(
double
t
)
{
return
new
EdgeDims
(
lerpNum
(
begin
.
top
,
end
.
top
,
t
),
lerpNum
(
begin
.
right
,
end
.
right
,
t
),
lerpNum
(
begin
.
bottom
,
end
.
bottom
,
t
),
...
...
@@ -57,17 +45,13 @@ class AnimatedMatrix4Value extends AnimatedValue<Matrix4> {
AnimatedMatrix4Value
(
Matrix4
begin
,
{
Matrix4
end
,
Curve
curve:
linear
})
:
super
(
begin
,
end:
end
,
curve:
curve
);
void
setProgress
(
double
t
)
{
if
(
t
==
1.0
)
{
value
=
end
;
return
;
}
Matrix4
lerp
(
double
t
)
{
// TODO(mpcomplete): Animate the full matrix. Will animating the cells
// separately work?
Vector3
beginT
=
begin
.
getTranslation
();
Vector3
endT
=
end
.
getTranslation
();
Vector3
lerpT
=
beginT
*(
1.0
-
t
)
+
endT
*
t
;
value
=
new
Matrix4
.
identity
()..
translate
(
lerpT
);
return
new
Matrix4
.
identity
()..
translate
(
lerpT
);
}
}
...
...
sky/packages/sky/lib/widgets/navigator.dart
浏览文件 @
b2addc35
...
...
@@ -7,7 +7,6 @@ import 'dart:async';
import
'package:sky/animation/animated_value.dart'
;
import
'package:sky/animation/animation_performance.dart'
;
import
'package:sky/animation/curves.dart'
;
import
'package:sky/animation/forces.dart'
;
import
'package:sky/widgets/basic.dart'
;
import
'package:sky/widgets/focus.dart'
;
import
'package:sky/widgets/transitions.dart'
;
...
...
sky/packages/sky/lib/widgets/popup_menu.dart
浏览文件 @
b2addc35
...
...
@@ -50,7 +50,6 @@ class PopupMenu extends AnimatedComponent {
AnimatedValue
<
double
>
_width
;
AnimatedValue
<
double
>
_height
;
List
<
AnimatedValue
<
double
>>
_itemOpacities
;
AnimatedList
_animationList
;
AnimationPerformance
_performance
;
void
initState
()
{
...
...
@@ -101,8 +100,9 @@ class PopupMenu extends AnimatedComponent {
..
add
(
_width
)
..
add
(
_height
)
..
addAll
(
_itemOpacities
);
_animationList
=
new
AnimatedList
(
variables
);
_performance
.
variable
=
_animationList
;
AnimatedList
list
=
new
AnimatedList
(
variables
)
..
reverseInterval
=
new
Interval
(
0.0
,
_kMenuCloseIntervalEnd
);
_performance
.
variable
=
list
;
}
void
_updateBoxPainter
()
{
...
...
@@ -124,14 +124,12 @@ class PopupMenu extends AnimatedComponent {
void
_open
()
{
_animationList
.
interval
=
null
;
_performance
.
play
();
if
(
navigator
!=
null
)
navigator
.
pushState
(
this
,
(
_
)
=>
_close
());
}
void
_close
()
{
_animationList
.
interval
=
new
Interval
(
0.0
,
_kMenuCloseIntervalEnd
);
_performance
.
reverse
();
}
...
...
sky/packages/sky/lib/widgets/transitions.dart
浏览文件 @
b2addc35
...
...
@@ -98,7 +98,7 @@ class SlideTransition extends TransitionBase {
}
Widget
build
()
{
p
osition
.
setProgress
(
performance
.
progress
);
p
erformance
.
updateVariable
(
position
);
Matrix4
transform
=
new
Matrix4
.
identity
()
..
translate
(
position
.
value
.
x
,
position
.
value
.
y
);
return
new
Transform
(
transform:
transform
,
child:
child
);
...
...
@@ -131,7 +131,7 @@ class FadeTransition extends TransitionBase {
}
Widget
build
()
{
opacity
.
setProgress
(
performance
.
progress
);
performance
.
updateVariable
(
opacity
);
return
new
Opacity
(
opacity:
opacity
.
value
,
child:
child
);
}
}
...
...
@@ -162,7 +162,7 @@ class ColorTransition extends TransitionBase {
}
Widget
build
()
{
color
.
setProgress
(
performance
.
progress
);
performance
.
updateVariable
(
color
);
return
new
DecoratedBox
(
decoration:
new
BoxDecoration
(
backgroundColor:
color
.
value
),
child:
child
...
...
@@ -200,9 +200,9 @@ class SquashTransition extends TransitionBase {
Widget
build
()
{
if
(
width
!=
null
)
width
.
setProgress
(
performance
.
progress
);
performance
.
updateVariable
(
width
);
if
(
height
!=
null
)
height
.
setProgress
(
performance
.
progress
);
performance
.
updateVariable
(
height
);
return
new
SizedBox
(
width:
_maybe
(
width
),
height:
_maybe
(
height
),
child:
child
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录