home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch9 / TweenEnd.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-05-29  |  23.1 KB  |  748 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Begin VB.Form frmTweenEnd 
  4.    Caption         =   "TweenEnd"
  5.    ClientHeight    =   4590
  6.    ClientLeft      =   2040
  7.    ClientTop       =   1035
  8.    ClientWidth     =   4635
  9.    LinkTopic       =   "Form1"
  10.    PaletteMode     =   1  'UseZOrder
  11.    ScaleHeight     =   306
  12.    ScaleMode       =   3  'Pixel
  13.    ScaleWidth      =   309
  14.    Begin VB.CommandButton cmdTween 
  15.       Caption         =   "Tween"
  16.       Height          =   495
  17.       Left            =   3480
  18.       TabIndex        =   12
  19.       Top             =   480
  20.       Width           =   975
  21.    End
  22.    Begin VB.TextBox txtNumTweens 
  23.       Height          =   285
  24.       Left            =   4200
  25.       TabIndex        =   10
  26.       Text            =   "4"
  27.       Top             =   0
  28.       Width           =   375
  29.    End
  30.    Begin VB.TextBox txtFramesPerSecond 
  31.       Height          =   285
  32.       Left            =   4200
  33.       TabIndex        =   9
  34.       Text            =   "20"
  35.       Top             =   1770
  36.       Width           =   375
  37.    End
  38.    Begin VB.CommandButton cmdPlay 
  39.       Caption         =   "Play"
  40.       Default         =   -1  'True
  41.       Height          =   495
  42.       Left            =   3480
  43.       TabIndex        =   7
  44.       Top             =   3480
  45.       Width           =   975
  46.    End
  47.    Begin VB.OptionButton optPlay 
  48.       Caption         =   "Reversing"
  49.       Height          =   255
  50.       Index           =   2
  51.       Left            =   3360
  52.       TabIndex        =   4
  53.       Top             =   3000
  54.       Width           =   1095
  55.    End
  56.    Begin VB.OptionButton optPlay 
  57.       Caption         =   "Looping"
  58.       Height          =   255
  59.       Index           =   1
  60.       Left            =   3360
  61.       TabIndex        =   3
  62.       Top             =   2640
  63.       Width           =   1095
  64.    End
  65.    Begin VB.OptionButton optPlay 
  66.       Caption         =   "Once"
  67.       Height          =   255
  68.       Index           =   0
  69.       Left            =   3360
  70.       TabIndex        =   2
  71.       Top             =   2280
  72.       Value           =   -1  'True
  73.       Width           =   1095
  74.    End
  75.    Begin VB.HScrollBar sbarFrame 
  76.       Height          =   255
  77.       Left            =   0
  78.       Max             =   1
  79.       Min             =   1
  80.       TabIndex        =   1
  81.       Top             =   3960
  82.       Value           =   1
  83.       Width           =   3255
  84.    End
  85.    Begin VB.PictureBox picCanvas 
  86.       Height          =   3975
  87.       Left            =   0
  88.       ScaleHeight     =   261
  89.       ScaleMode       =   3  'Pixel
  90.       ScaleWidth      =   213
  91.       TabIndex        =   0
  92.       Top             =   0
  93.       Width           =   3255
  94.    End
  95.    Begin MSComDlg.CommonDialog dlgFile 
  96.       Left            =   2640
  97.       Top             =   4200
  98.       _ExtentX        =   847
  99.       _ExtentY        =   847
  100.       _Version        =   393216
  101.       CancelError     =   -1  'True
  102.    End
  103.    Begin VB.Label Label1 
  104.       Caption         =   "Tweens:"
  105.       Height          =   255
  106.       Index           =   2
  107.       Left            =   3360
  108.       TabIndex        =   11
  109.       Top             =   0
  110.       Width           =   615
  111.    End
  112.    Begin VB.Label Label1 
  113.       Alignment       =   2  'Center
  114.       Caption         =   "Frames per Second"
  115.       Height          =   375
  116.       Index           =   1
  117.       Left            =   3360
  118.       TabIndex        =   8
  119.       Top             =   1680
  120.       Width           =   855
  121.    End
  122.    Begin VB.Label lblFrame 
  123.       Alignment       =   2  'Center
  124.       BorderStyle     =   1  'Fixed Single
  125.       Caption         =   "1/1"
  126.       Height          =   255
  127.       Left            =   1680
  128.       TabIndex        =   6
  129.       Top             =   4320
  130.       Width           =   735
  131.    End
  132.    Begin VB.Label Label1 
  133.       Caption         =   "Frame:"
  134.       Height          =   255
  135.       Index           =   0
  136.       Left            =   1080
  137.       TabIndex        =   5
  138.       Top             =   4320
  139.       Width           =   495
  140.    End
  141.    Begin VB.Menu mnuFile 
  142.       Caption         =   "&File"
  143.       Begin VB.Menu mnuFileOpen 
  144.          Caption         =   "&Open..."
  145.          Shortcut        =   ^O
  146.       End
  147.       Begin VB.Menu mnuFileSave 
  148.          Caption         =   "&Save"
  149.          Shortcut        =   ^S
  150.       End
  151.       Begin VB.Menu mnuFileSaveAs 
  152.          Caption         =   "Save &As..."
  153.          Shortcut        =   ^A
  154.       End
  155.       Begin VB.Menu mnuFileSep1 
  156.          Caption         =   "-"
  157.       End
  158.       Begin VB.Menu mnuFileNew 
  159.          Caption         =   "&New"
  160.          Shortcut        =   ^N
  161.       End
  162.       Begin VB.Menu mnuFileSep2 
  163.          Caption         =   "-"
  164.       End
  165.       Begin VB.Menu mnuFileExit 
  166.          Caption         =   "E&xit"
  167.       End
  168.    End
  169.    Begin VB.Menu mnuFrame 
  170.       Caption         =   "Frame"
  171.       Begin VB.Menu mnuFrameAfter 
  172.          Caption         =   "Insert &After"
  173.       End
  174.       Begin VB.Menu mnuFrameBefore 
  175.          Caption         =   "Insert &Before"
  176.       End
  177.       Begin VB.Menu mnuFrameSep 
  178.          Caption         =   "-"
  179.       End
  180.       Begin VB.Menu mnuFrameClear 
  181.          Caption         =   "&Clear"
  182.       End
  183.       Begin VB.Menu mnuFrameDelete 
  184.          Caption         =   "&Delete"
  185.          Enabled         =   0   'False
  186.       End
  187.    End
  188. Attribute VB_Name = "frmTweenEnd"
  189. Attribute VB_GlobalNameSpace = False
  190. Attribute VB_Creatable = False
  191. Attribute VB_PredeclaredId = True
  192. Attribute VB_Exposed = False
  193. Option Explicit
  194. Private NumFrames As Integer
  195. Private Frames() As PolylineFrame
  196. Private FileName As String
  197. Private FileTitle As String
  198. Private DataModified As Boolean
  199. Private Playing As Boolean
  200. Private NumPlayed As Long
  201. Private SelectedFrame As Integer
  202. Private SelectingFrame As Boolean
  203. Private Drawing As Boolean
  204. Private StartX As Integer
  205. Private StartY As Integer
  206. Private LastX As Integer
  207. Private LastY As Integer
  208. Private Type Polyline
  209.     NumPoints As Integer
  210.     X() As Integer
  211.     Y() As Integer
  212. End Type
  213. Private Type PolylineFrame
  214.     NumPolylines As Integer
  215.     Poly() As Polyline
  216. End Type
  217. ' Insert a frame next to the selected one.
  218. Private Sub AddFrame()
  219. Dim i As Integer
  220.     NumFrames = NumFrames + 1
  221.     ReDim Preserve Frames(1 To NumFrames)
  222.     For i = NumFrames - 1 To SelectedFrame Step -1
  223.         CopyFrame i, i + 1
  224.     Next i
  225.     sbarFrame.Max = NumFrames
  226.     mnuFrameDelete.Enabled = (NumFrames > 1)
  227.     DataModified = True
  228.     Caption = "TweenEnd*[" & FileTitle & "]"
  229. End Sub
  230. ' Copy a polyline from frame1 to frame2.
  231. Private Sub CopyFrame(frame1 As Integer, frame2 As Integer)
  232. Dim pline As Integer
  233. Dim point As Integer
  234.     Frames(frame2).NumPolylines = Frames(frame1).NumPolylines
  235.     If Frames(frame2).NumPolylines < 1 Then
  236.         Erase Frames(frame2).Poly
  237.     Else
  238.         ReDim Frames(frame2).Poly(1 To Frames(frame2).NumPolylines)
  239.     End If
  240.     For pline = 1 To Frames(frame2).NumPolylines
  241.         With Frames(frame2).Poly(pline)
  242.             .NumPoints = Frames(frame1).Poly(pline).NumPoints
  243.             If .NumPoints < 1 Then
  244.                 Erase .X
  245.                 Erase .Y
  246.             Else
  247.                 ReDim .X(1 To .NumPoints)
  248.                 ReDim .Y(1 To .NumPoints)
  249.             End If
  250.             For point = 1 To .NumPoints
  251.                 .X(point) = Frames(frame1).Poly(pline).X(point)
  252.                 .Y(point) = Frames(frame1).Poly(pline).Y(point)
  253.             Next point
  254.         End With
  255.     Next pline
  256. End Sub
  257. ' Return true if the data has not been modified,
  258. ' or the user has saved the changes, or the user
  259. ' wants to lose the changes.
  260. Private Function DataSafe() As Boolean
  261. Dim ans As Integer
  262.     Do While DataModified
  263.         ans = MsgBox("The data has been modified." & _
  264.             " Do you want to save the changes?", _
  265.             vbYesNoCancel)
  266.         If ans = vbCancel Then Exit Do
  267.         If ans = vbNo Then
  268.             DataSafe = True
  269.             Exit Function
  270.         End If
  271.             
  272.         ' Otherwise save the data.
  273.         If FileName <> "" Then
  274.             mnuFileSave_Click
  275.         Else
  276.             mnuFileSaveAs_Click
  277.         End If
  278.     Loop
  279.     DataSafe = Not DataModified
  280. End Function
  281. ' Draw the indicated frame.
  282. Private Sub DrawFrame(frame As Integer)
  283. Dim pline As Integer
  284. Dim point As Integer
  285.     picCanvas.Cls
  286.     For pline = 1 To Frames(frame).NumPolylines
  287.         With Frames(frame).Poly(pline)
  288.             If .NumPoints >= 2 Then
  289.                 picCanvas.Line (.X(1), .Y(1))-(.X(2), .Y(2))
  290.                 For point = 3 To .NumPoints
  291.                     picCanvas.Line -(.X(point), .Y(point))
  292.                 Next point
  293.             End If
  294.         End With
  295.     Next pline
  296. End Sub
  297. ' Save the data.
  298. Private Sub SaveData(ByVal file_name As String, ByVal file_title As String)
  299. Dim fnum As Integer
  300. Dim frame As Integer
  301. Dim pline As Integer
  302. Dim point As Integer
  303.     On Error GoTo SaveDataError
  304.     ' Open the file.
  305.     fnum = FreeFile
  306.     Open file_name For Output As fnum
  307.     ' Save the number of frames.
  308.     Write #fnum, NumFrames
  309.     ' Save each frame.
  310.     For frame = 1 To NumFrames
  311.         With Frames(frame)
  312.             ' Save the number of polylines.
  313.             Write #fnum, .NumPolylines
  314.                     
  315.             ' Save each polyline.
  316.             For pline = 1 To .NumPolylines
  317.                 With .Poly(pline)
  318.                     ' Save the number of points.
  319.                     Write #fnum, .NumPoints
  320.                     For point = 1 To .NumPoints
  321.                         Write #fnum, .X(point), .Y(point)
  322.                     Next point
  323.                 End With
  324.             Next pline
  325.         End With
  326.     Next frame
  327.     Close fnum
  328.     FileName = file_name
  329.     FileTitle = file_title
  330.     Caption = "TweenEnd [" & FileTitle & "]"
  331.     DataModified = False
  332.     Exit Sub
  333. SaveDataError:
  334.     Beep
  335.     MsgBox "Error saving file " & file_name & "." & _
  336.         vbCrLf & Format$(Err.Number) & " : " & _
  337.         Err.Description
  338.     Exit Sub
  339. End Sub
  340. ' Load polyline frames from the file.
  341. Private Sub LoadData(ByVal file_name As String, ByVal file_title As String)
  342. Dim fnum As Integer
  343. Dim frame As Integer
  344. Dim pline As Integer
  345. Dim point As Integer
  346.     On Error GoTo SaveDataError
  347.     ' Open the file.
  348.     fnum = FreeFile
  349.     Open file_name For Input As fnum
  350.     ' Read the number of frames.
  351.     Input #fnum, NumFrames
  352.     ReDim Frames(1 To NumFrames)
  353.     sbarFrame.Max = NumFrames
  354.     ' Read each frame.
  355.     For frame = 1 To NumFrames
  356.         With Frames(frame)
  357.             ' Read the number of polylines.
  358.             Input #fnum, .NumPolylines
  359.             ReDim .Poly(1 To .NumPolylines)
  360.                     
  361.             ' Read each polyline.
  362.             For pline = 1 To .NumPolylines
  363.                 With .Poly(pline)
  364.                     ' Read the number of points.
  365.                     Input #fnum, .NumPoints
  366.                     ReDim .X(1 To .NumPoints)
  367.                     ReDim .Y(1 To .NumPoints)
  368.                     For point = 1 To .NumPoints
  369.                         Input #fnum, .X(point), .Y(point)
  370.                     Next point
  371.                 End With
  372.             Next pline
  373.         End With
  374.     Next frame
  375.     Close fnum
  376.     SelectFrame 1
  377.     FileName = file_name
  378.     FileTitle = file_title
  379.     Caption = "TweenEnd [" & FileTitle & "]"
  380.     DataModified = False
  381.     Exit Sub
  382. SaveDataError:
  383.     Beep
  384.     MsgBox "Error loading file " & file_name & "." & _
  385.         vbCrLf & Format$(Err.Number) & " : " & _
  386.         Err.Description
  387.     Exit Sub
  388. End Sub
  389. ' Select and display the indicated frame.
  390. Private Sub SelectFrame(num As Integer)
  391.     SelectedFrame = num
  392.     ' If we're drawing, stop drawing.
  393.     If Drawing Then
  394.         picCanvas.DrawMode = vbCopyPen
  395.         Drawing = False
  396.     End If
  397.     DrawFrame SelectedFrame
  398.     lblFrame.Caption = Format$(SelectedFrame) _
  399.          & "/" & Format$(NumFrames)
  400.     SelectingFrame = True
  401.     sbarFrame.Value = SelectedFrame
  402.     SelectingFrame = False
  403. End Sub
  404. ' Create the tweens between two key frames using
  405. ' endpoint interpolation.
  406. Private Sub MakeTweens(key1 As Integer, key2 As Integer)
  407. Dim frac1 As Single
  408. Dim frac2 As Single
  409. Dim tween As Integer
  410. Dim pline As Integer
  411. Dim point As Integer
  412.     For tween = key1 + 1 To key2 - 1
  413.         frac1 = (key2 - tween) / (key2 - key1)
  414.         frac2 = 1# - frac1
  415.         
  416.         Frames(tween).NumPolylines = Frames(key1).NumPolylines
  417.         ReDim Frames(tween).Poly(1 To Frames(tween).NumPolylines)
  418.         For pline = 1 To Frames(tween).NumPolylines
  419.             With Frames(tween).Poly(pline)
  420.                 .NumPoints = Frames(key1).Poly(pline).NumPoints
  421.                 ReDim .X(1 To .NumPoints)
  422.                 ReDim .Y(1 To .NumPoints)
  423.                 For point = 1 To .NumPoints
  424.                     .X(point) = frac1 * Frames(key1).Poly(pline).X(point) + frac2 * Frames(key2).Poly(pline).X(point)
  425.                     .Y(point) = frac1 * Frames(key1).Poly(pline).Y(point) + frac2 * Frames(key2).Poly(pline).Y(point)
  426.                 Next point
  427.             End With
  428.         Next pline
  429.     Next tween
  430. End Sub
  431. Private Sub picCanvas_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  432.     If Drawing And Button = vbRightButton Then
  433.         ' End the previous polyline.
  434.         picCanvas.Line (StartX, StartY)-(LastX, LastY)
  435.         picCanvas.DrawMode = vbCopyPen
  436.         Drawing = False
  437.         Exit Sub
  438.     End If
  439.     ' See if this is the start of a new polyline.
  440.     If Drawing Then
  441.         ' Nope. Erase the previous line.
  442.         picCanvas.Line (StartX, StartY)-(LastX, LastY)
  443.     Else
  444.         ' Start a new polyline.
  445.         With Frames(SelectedFrame)
  446.             .NumPolylines = .NumPolylines + 1
  447.             ReDim Preserve .Poly(1 To .NumPolylines)
  448.             With .Poly(.NumPolylines)
  449.                 .NumPoints = 1
  450.                 ReDim .X(1 To 1)
  451.                 ReDim .Y(1 To 1)
  452.                 .X(1) = X
  453.                 .Y(1) = Y
  454.             End With
  455.         End With
  456.         picCanvas.DrawMode = vbInvert
  457.         Drawing = True
  458.         DataModified = True
  459.         Caption = "TweenEnd*[" & FileTitle & "]"
  460.         StartX = X
  461.         StartY = Y
  462.     End If
  463.     LastX = X
  464.     LastY = Y
  465.     picCanvas.Line (StartX, StartY)-(LastX, LastY)
  466. End Sub
  467. ' Repaint the current frame.
  468. Private Sub picCanvas_Paint()
  469.     If SelectingFrame Then Exit Sub
  470.     SelectFrame sbarFrame.Value
  471. End Sub
  472. Private Sub picCanvas_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  473.     If Not Drawing Then Exit Sub
  474.     picCanvas.Line (StartX, StartY)-(LastX, LastY)
  475.     LastX = X
  476.     LastY = Y
  477.     picCanvas.Line (StartX, StartY)-(LastX, LastY)
  478. End Sub
  479. Private Sub picCanvas_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  480.     If Not Drawing Then Exit Sub
  481.     picCanvas.Line (StartX, StartY)-(LastX, LastY)
  482.     picCanvas.DrawMode = vbCopyPen
  483.     picCanvas.Line (StartX, StartY)-(X, Y)
  484.     picCanvas.DrawMode = vbInvert
  485.     With Frames(SelectedFrame)
  486.         With .Poly(.NumPolylines)
  487.             .NumPoints = .NumPoints + 1
  488.             ReDim Preserve .X(1 To .NumPoints)
  489.             ReDim Preserve .Y(1 To .NumPoints)
  490.             .X(.NumPoints) = X
  491.             .Y(.NumPoints) = Y
  492.         End With
  493.     End With
  494.     DataModified = True
  495.     Caption = "TweenEnd*[" & FileTitle & "]"
  496.     StartX = X
  497.     StartY = Y
  498. End Sub
  499. ' Play the animation.
  500. Private Sub cmdPlay_Click()
  501.     If Playing Then
  502.         Playing = False
  503.         cmdPlay.Caption = "Stopped"
  504.         cmdPlay.Enabled = False
  505.     Else
  506.         Playing = True
  507.         cmdPlay.Caption = "Stop"
  508.         PlayData
  509.         cmdPlay.Caption = "Play"
  510.         Playing = False
  511.         cmdPlay.Enabled = True
  512.         DrawFrame SelectedFrame
  513.     End If
  514. End Sub
  515. ' Play the animation.
  516. Private Sub PlayData()
  517. Dim ms_per_frame As Long
  518. Dim start_time As Single
  519. Dim stop_time As Single
  520.     ' See how fast we should go.
  521.     If Not IsNumeric(txtFramesPerSecond.Text) Then _
  522.         txtFramesPerSecond.Text = "10"
  523.     ms_per_frame = 1000 \ CLng(txtFramesPerSecond.Text)
  524.     ' See what kind of animation this should be.
  525.     NumPlayed = 0
  526.     start_time = Timer
  527.     If optPlay(0).Value Then
  528.         PlayDataOnce ms_per_frame
  529.     ElseIf optPlay(1).Value Then
  530.         PlayDataLooping ms_per_frame
  531.     ElseIf optPlay(2).Value Then
  532.         PlayDataBackAndForth ms_per_frame
  533.     End If
  534.     stop_time = Timer
  535.     MsgBox "Displayed" & Str$(NumPlayed) & _
  536.         " frames in " & _
  537.         Format$(stop_time - start_time, "0.00") & _
  538.         " seconds (" & _
  539.         Format$(NumPlayed / (stop_time - start_time), "0.00") & _
  540.         " FPS)."
  541. End Sub
  542. ' Play the animation once.
  543. Private Sub PlayDataOnce(ByVal ms_per_frame As Long)
  544. Dim frame As Integer
  545. Dim next_time As Long
  546.     ' Start the animation.
  547.     next_time = GetTickCount()
  548.     For frame = 1 To NumFrames
  549.         If Not Playing Then Exit For
  550.         NumPlayed = NumPlayed + 1
  551.         ' Draw the frame.
  552.         DrawFrame frame
  553.         ' Wait until it's time for the next frame.
  554.         next_time = next_time + ms_per_frame
  555.         WaitTill next_time
  556.     Next frame
  557. End Sub
  558. ' Play the animation backwards.
  559. Private Sub PlayDataBackward(ByVal ms_per_frame As Long)
  560. Dim frame As Integer
  561. Dim next_time As Long
  562.     ' Start the animation.
  563.     next_time = GetTickCount()
  564.     For frame = NumFrames To 1 Step -1
  565.         If Not Playing Then Exit For
  566.         NumPlayed = NumPlayed + 1
  567.         ' Draw the frame.
  568.         DrawFrame frame
  569.         ' Wait until it's time for the next frame.
  570.         next_time = next_time + ms_per_frame
  571.         WaitTill next_time
  572.     Next frame
  573. End Sub
  574. ' Play the animation in a loop.
  575. Private Sub PlayDataLooping(ByVal ms_per_frame As Long)
  576.     Do While Playing
  577.         PlayDataOnce ms_per_frame
  578.     Loop
  579. End Sub
  580. ' Play the animation back and forth.
  581. Private Sub PlayDataBackAndForth(ByVal ms_per_frame As Long)
  582.     Do While Playing
  583.         PlayDataOnce ms_per_frame
  584.         If Not Playing Then Exit Do
  585.         PlayDataBackward ms_per_frame
  586.     Loop
  587. End Sub
  588. ' Make the tweens.
  589. Private Sub cmdTween_Click()
  590. Dim num_tweens As Integer
  591. Dim old_frames As Integer
  592. Dim frame1 As Integer
  593. Dim frame2 As Integer
  594. Dim frame As Integer
  595.     ' See how many tweens to make.
  596.     If Not IsNumeric(txtNumTweens.Text) Then _
  597.         txtNumTweens.Text = "4"
  598.     num_tweens = txtNumTweens.Text
  599.     If num_tweens < 1 Then num_tweens = 1
  600.     ' Make room for the new frames.
  601.     old_frames = NumFrames
  602.     NumFrames = num_tweens * (NumFrames - 1) + NumFrames
  603.     ReDim Preserve Frames(1 To NumFrames)
  604.     ' Spread the original frames out.
  605.     For frame = old_frames To 2 Step -1
  606.         CopyFrame frame, _
  607.             num_tweens * (frame - 1) + frame
  608.     Next frame
  609.     ' Make the tweens.
  610.     For frame = 1 To old_frames - 1
  611.         frame1 = num_tweens * (frame - 1) + frame
  612.         frame2 = frame1 + num_tweens + 1
  613.         MakeTweens frame1, frame2
  614.     Next frame
  615.     sbarFrame.Max = NumFrames
  616.     SelectFrame num_tweens * (SelectedFrame - 1) + _
  617.         SelectedFrame
  618.     DataModified = True
  619.     Caption = "TweenEnd*[" & FileTitle & "]"
  620. End Sub
  621. Private Sub Form_Load()
  622.     ' Position the scroll bar.
  623.     sbarFrame.Top = picCanvas.Top + picCanvas.Height + 1
  624.     ' Create an empty frame.
  625.     mnuFileNew_Click
  626.     dlgFile.InitDir = App.Path
  627.     dlgFile.Filter = _
  628.         "Tween Files (*.twe)|*.twe|" & _
  629.         "All Files (*.*)|*.*"
  630. End Sub
  631. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  632.     Cancel = Not DataSafe()
  633. End Sub
  634. Private Sub Form_Unload(Cancel As Integer)
  635.     End
  636. End Sub
  637. Private Sub mnuFileExit_Click()
  638.     Unload Me
  639. End Sub
  640. ' Load a data file.
  641. Private Sub mnuFileOpen_Click()
  642. Dim file_name As String
  643.     If Not DataSafe() Then Exit Sub
  644.     ' Allow the user to pick a file.
  645.     On Error Resume Next
  646.     dlgFile.Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly
  647.     dlgFile.ShowOpen
  648.     If Err.Number = cdlCancel Then
  649.         Exit Sub
  650.     ElseIf Err.Number <> 0 Then
  651.         Beep
  652.         MsgBox "Error selecting file.", , vbExclamation
  653.         Exit Sub
  654.     End If
  655.     On Error GoTo 0
  656.     file_name = Trim$(dlgFile.FileName)
  657.     dlgFile.InitDir = Left$(file_name, Len(file_name) _
  658.         - Len(dlgFile.FileTitle) - 1)
  659.     ' Load the data file.
  660.     LoadData file_name, dlgFile.FileTitle
  661.     lblFrame.Caption = Format$(SelectedFrame) _
  662.          & "/" & Format$(NumFrames)
  663. End Sub
  664. ' Clear out all the data.
  665. Private Sub mnuFileNew_Click()
  666.     If Not DataSafe() Then Exit Sub
  667.     NumFrames = 1
  668.     ReDim Frames(1 To NumFrames)
  669.     Frames(1).NumPolylines = 0
  670.     sbarFrame.Max = NumFrames
  671.     SelectFrame 1
  672. End Sub
  673. ' Save the data file.
  674. Private Sub mnuFileSave_Click()
  675.     If FileName = "" Then
  676.         mnuFileSaveAs_Click
  677.         Exit Sub
  678.     End If
  679.     SaveData FileName, FileTitle
  680. End Sub
  681. ' Save the data file with a new name.
  682. Private Sub mnuFileSaveAs_Click()
  683. Dim file_name As String
  684.     ' Allow the user to pick a file.
  685.     On Error Resume Next
  686.     dlgFile.Flags = cdlOFNOverwritePrompt + cdlOFNHideReadOnly
  687.     dlgFile.ShowSave
  688.     If Err.Number = cdlCancel Then
  689.         Exit Sub
  690.     ElseIf Err.Number <> 0 Then
  691.         Beep
  692.         MsgBox "Error selecting file.", , vbExclamation
  693.         Exit Sub
  694.     End If
  695.     On Error GoTo 0
  696.     file_name = Trim$(dlgFile.FileName)
  697.     dlgFile.InitDir = Left$(file_name, Len(file_name) _
  698.         - Len(dlgFile.FileTitle) - 1)
  699.     ' Save the script file.
  700.     SaveData file_name, dlgFile.FileTitle
  701. End Sub
  702. ' Insert a frame after the selected one.
  703. Private Sub mnuFrameAfter_Click()
  704.     AddFrame
  705.     SelectFrame SelectedFrame + 1
  706. End Sub
  707. ' Insert a frame before the selected one.
  708. Private Sub mnuFrameBefore_Click()
  709.     AddFrame
  710.     lblFrame.Caption = Format$(SelectedFrame) & "/" & Format$(NumFrames)
  711. End Sub
  712. ' Remove the polylines from the selected frame.
  713. Private Sub mnuFrameClear_Click()
  714. Dim i As Integer
  715.     With Frames(SelectedFrame)
  716.         .NumPolylines = 0
  717.         Erase .Poly
  718.     End With
  719.     SelectFrame SelectedFrame
  720.     DataModified = True
  721.     Caption = "TweenEnd*[" & FileTitle & "]"
  722. End Sub
  723. ' Delete the selected frame.
  724. Private Sub mnuFrameDelete_Click()
  725. Dim i As Integer
  726.     For i = SelectedFrame To NumFrames - 1
  727.         CopyFrame i + 1, i
  728.     Next i
  729.     NumFrames = NumFrames - 1
  730.     ReDim Preserve Frames(1 To NumFrames)
  731.     sbarFrame.Max = NumFrames
  732.     If SelectedFrame > NumFrames Then _
  733.        SelectedFrame = NumFrames
  734.     SelectFrame SelectedFrame
  735.     mnuFrameDelete.Enabled = (NumFrames > 1)
  736.     DataModified = True
  737.     Caption = "TweenEnd*[" & FileTitle & "]"
  738. End Sub
  739. ' Select a new frame.
  740. Private Sub sbarFrame_Change()
  741.     If SelectingFrame Then Exit Sub
  742.     SelectFrame sbarFrame.Value
  743. End Sub
  744. ' Select a new frame.
  745. Private Sub sbarFrame_Scroll()
  746.     sbarFrame_Change
  747. End Sub
  748.