|
[code=vb]Private Sub cmdOK_Click()
'计数器
Dim i As Integer
Dim j As Integer
Dim iPoints As Integer
Dim iNodesCount As Integer
Dim shpPointTemp As Shape
Dim bfTemp As FreeformBuilder
Dim shpFreeform As Shape
Dim bBessel As Boolean
Dim effTemp As Effect
Dim bhvTemp As AnimationBehavior
Dim sinX0 As Single
Dim sinY0 As Single
Dim sinX1 As Single
Dim sinY1 As Single
Dim sinX2 As Single
Dim sinY2 As Single
Dim sinX3 As Single
Dim sinY3 As Single
Dim sinSldWidth As Single
Dim sinSldHeight As Single
Dim strVMLPath As String
Set sldTemp = ActivePresentation.Slides(Me.cbbSlide.ListIndex + 1)
With sldTemp
On Error GoTo errHandler
sinSldWidth = .Master.Width
sinSldHeight = .Master.Height
Set shpPointStyle = .Shapes(Me.cbbPointStyle.Text)
If Me.mpReference.Value = 0 Then
'基于用户指定的数据点设置图表动画
bBessel = Me.optBessel.Value
iPoints = Me.lstRefShapes.ListCount
Set shpTemp = .Shapes(Me.lstRefShapes.List(0))
'根据用户提供的数据点,绘制自由曲线或者折线
Set bfTemp = .Shapes.BuildFreeform(msoEditingAuto, _
shpTemp.Left + shpTemp.Width / 2, _
shpTemp.Top + shpTemp.Height / 2)
For i = 1 To iPoints - 1
Set shpTemp = .Shapes(Me.lstRefShapes.List(i))
If Me.optBessel Then
bfTemp.AddNodes msoSegmentCurve, msoEditingAuto, _
shpTemp.Left + shpTemp.Width / 2, _
shpTemp.Top + shpTemp.Height / 2
Else
bfTemp.AddNodes msoSegmentLine, msoEditingAuto, _
shpTemp.Left + shpTemp.Width / 2, _
shpTemp.Top + shpTemp.Height / 2
End If
Next i
Set shpFreeform = bfTemp.ConvertToShape
With shpFreeform.Line
.Visible = msoTrue
.Weight = Me.txtLineWeight
.ForeColor.RGB = RGB(Me.txtR.Text, Me.txtG.Text, Me.txtB.Text)
End With
'将数据标志移动到系列线上面
shpPointStyle.ZOrder msoBringToFront
Else
'基于用户指定的自由曲线设置图表动画
Set shpFreeform = .Shapes(Me.cbbFreeform.Text)
With shpFreeform
'指定图形是否是自由曲线,如果节点数为0则否,报错
If .Nodes(1).SegmentType = msoSegmentCurve Then
bBessel = True
Else
bBessel = False
End If
End With
End If
iNodesCount = shpFreeform.Nodes.Count
If bBessel Then
'贝塞尔曲线轨迹动画
strVMLPath = "M 0 0 C "
If Me.optOnePoint.Value Then
'如果只有一个数据标志
With shpFreeform
shpPointStyle.Left = .Nodes(1).Points(1, 1) - shpPointStyle.Width / 2
shpPointStyle.Top = .Nodes(1).Points(1, 2) - shpPointStyle.Height / 2
sinX0 = .Nodes(1).Points(1, 1)
sinY0 = .Nodes(1).Points(1, 2)
For i = 1 To VBA.Int(iNodesCount / 3)
sinX1 = .Nodes(3 * (i - 1) + 2).Points(1, 1)
sinY1 = .Nodes(3 * (i - 1) + 2).Points(1, 2)
sinX2 = .Nodes(3 * (i - 1) + 3).Points(1, 1)
sinY2 = .Nodes(3 * (i - 1) + 3).Points(1, 2)
sinX3 = .Nodes(3 * (i - 1) + 4).Points(1, 1)
sinY3 = .Nodes(3 * (i - 1) + 4).Points(1, 2)
strVMLPath = strVMLPath & (sinX1 - sinX0) / sinSldWidth & " " & (sinY1 - sinY0) / sinSldHeight & " " _
& (sinX2 - sinX0) / sinSldWidth & " " & (sinY2 - sinY0) / sinSldHeight & " " _
& (sinX3 - sinX0) / sinSldWidth & " " & (sinY3 - sinY0) / sinSldHeight & IIf(i < VBA.Int(iNodesCount / 3), " C ", " E")
Next i
End With
'设置动画
Set effTemp = .TimeLine.MainSequence.AddEffect( _
Shape:=shpPointStyle, _
effectid:=msoAnimEffectCustom, _
trigger:=msoAnimTriggerOnPageClick)
With effTemp
Set bhvTemp = .Behaviors.Add(msoAnimTypeProperty)
With bhvTemp
With .Timing
.Duration = 1
.TriggerDelayTime = 0
End With
With .PropertyEffect
.Property = msoAnimOpacity
.From = 0
.To = 1
End With
End With
Set bhvTemp = .Behaviors.Add(msoAnimTypeMotion)
With bhvTemp
With .Timing
.Duration = 4
.TriggerDelayTime = 1
End With
With .MotionEffect
.Path = strVMLPath
End With
End With
End With
Else
'保留所有数据标志
For j = 1 To VBA.Int(iNodesCount / 3) + 1
strVMLPath = "M 0 0 C "
If j = 1 Then
'复制数据标志,并将其移动到相应位置
Set shpPointTemp = shpPointStyle.Duplicate.Item(1)
With shpPointTemp
.Name = "shpPoint" & j
.Left = shpFreeform.Nodes(1).Points(1, 1) - .Width / 2
.Top = shpFreeform.Nodes(1).Points(1, 2) - .Width / 2
End With
'第一个数据点的动画只是淡入
Set effTemp = .TimeLine.MainSequence.AddEffect( _
Shape:=shpPointTemp, _
effectid:=msoAnimEffectCustom, _
trigger:=msoAnimTriggerOnPageClick)
With effTemp
Set bhvTemp = .Behaviors.Add(msoAnimTypeProperty)
With bhvTemp
With .Timing
.Duration = 1
End With
With .PropertyEffect
.Property = msoAnimOpacity
.From = 0
.To = 1
End With
End With
End With
Else
'复制数据标志,并将其移动到相应位置
Set shpPointTemp = shpPointStyle.Duplicate.Item(1)
With shpPointTemp
.Name = "shpPoint" & j
.Left = shpFreeform.Nodes(3 * (j - 2) + 1).Points(1, 1) - .Width / 2
.Top = shpFreeform.Nodes(3 * (j - 2) + 1).Points(1, 2) - .Width / 2
End With
'第二个以及后面的数据点的动画
'从前面数据点的位置淡入,然后移动到目标位置
Set effTemp = .TimeLine.MainSequence.AddEffect( _
Shape:=shpPointTemp, _
effectid:=msoAnimEffectCustom, _
trigger:=msoAnimTriggerAfterPrevious)
With effTemp
Set bhvTemp = .Behaviors.Add(msoAnimTypeProperty)
With bhvTemp
With .Timing
.Duration = 0.1
End With
With .PropertyEffect
.Property = msoAnimOpacity
.From = 0
.To = 1
End With
End With
With shpFreeform
sinX0 = .Nodes(3 * (j - 2) + 1).Points(1, 1)
sinY0 = .Nodes(3 * (j - 2) + 1).Points(1, 2)
sinX1 = .Nodes(3 * (j - 2) + 2).Points(1, 1)
sinY1 = .Nodes(3 * (j - 2) + 2).Points(1, 2)
sinX2 = .Nodes(3 * (j - 2) + 3).Points(1, 1)
sinY2 = .Nodes(3 * (j - 2) + 3).Points(1, 2)
sinX3 = .Nodes(3 * (j - 2) + 4).Points(1, 1)
sinY3 = .Nodes(3 * (j - 2) + 4).Points(1, 2)
End With
strVMLPath = strVMLPath & (sinX1 - sinX0) / sinSldWidth & " " & (sinY1 - sinY0) / sinSldHeight & " " _
& (sinX2 - sinX0) / sinSldWidth & " " & (sinY2 - sinY0) / sinSldHeight & " " _
& (sinX3 - sinX0) / sinSldWidth & " " & (sinY3 - sinY0) / sinSldHeight & " E"
' Debug.Print j & ": " & strVMLPath
Set bhvTemp = .Behaviors.Add(msoAnimTypeMotion)
With bhvTemp
With .Timing
.Duration = 0.9
.TriggerDelayTime = 0.1
End With
With .MotionEffect
.Path = strVMLPath
End With
End With
End With
End If
Next j
End If
Else[/code] |
|