home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 January / Chip_1997-01_cd.bin / dirwin / data.z / ANIMWIZ.DIR / 00008_Script_Banners < prev    next >
Text File  |  1996-03-15  |  10KB  |  337 lines

  1. -- Banners script
  2.  
  3. property ioFieldList
  4. property iFieldFocus
  5. property ioFieldFocus
  6. property iCurrentMotionStyleIndex
  7. property iCurrentVisualStyleIndex
  8.  
  9. -- The motion styles are:
  10. property ikMotionRightToLeft  -- 1
  11. property ikMotionLeftToRight  -- 2
  12. property ikMotionUp                 -- 3
  13. property ikMotionDown             --4
  14.  
  15. property iFirstTIme
  16. property iSaveSeconds
  17. property iSaveFPS
  18. property iSaveBaseline
  19. property iSaveDelayEnter
  20. property iSaveMark
  21. property iSaveCycles
  22.  
  23.  
  24. on birth me
  25.   global goBannersText
  26.   global goSeconds
  27.   global goFPS
  28.   global goBaseLine
  29.   global goDelayEnter
  30.   global goCycles
  31.   
  32.   set ioFieldList = [goBannersText, goSeconds, goFPS, goBaseLine, goDelayEnter, goCycles]
  33.   set ikMotionRightToLeft = 1
  34.   set ikMotionLeftToRight = 2
  35.   set ikMotionUp = 3
  36.   set ikMotionDown = 4
  37.   
  38.   set iCurrentMotionStyleIndex = ikMotionRightToLeft
  39.   set iCurrentVisualStyleIndex = 1
  40.   set iFieldFocus = 1
  41.   set iFirstTime = TRUE
  42.   
  43.   return me
  44. end birth
  45.  
  46. on mInit me
  47.   global goSeconds
  48.   global goFPS
  49.   global goBaseLine
  50.   global goDelayEnter
  51.   global goCycles
  52.   global goBanners
  53.   global goMarkFrame
  54.   global goVisualStyles
  55.   global goMotionStyles
  56.   global goScoreMgr
  57.   
  58.   -- CheckMark parameter: channel
  59.   mInit(goMarkFrame, 4)  -- channel
  60.   
  61.   if iFirstTime then  -- use intellegent defaults
  62.     mSetValue(goSeconds, 5)
  63.     mSetValue(goFPS, 5)
  64.     set defaultBaseLine = integer(mGetStageHeight(goScoreMgr) / 2)
  65.     mSetValue(goBaseLine, defaultBaseLine)
  66.     mSetValue(goDelayEnter, 0)
  67.     mSetValue(goCycles, 1)
  68.     mSetValue(goMarkFrame, TRUE)
  69.     set iFirstTime = FALSE
  70.     
  71.   else  -- use values saved from when we last left
  72.     mSetValue(goSeconds, iSaveSeconds)
  73.     mSetValue(goFPS, iSaveFPS)
  74.     mSetValue(goBaseLine, iSaveBaseline)
  75.     mSetValue(goDelayEnter, iSaveDelayEnter)
  76.     mSetValue(goCycles, iSaveCycles)
  77.     mSetValue(goMarkFrame, iSaveMark)
  78.   end if
  79.   
  80.   set ioFieldFocus = GetAt(ioFieldList, iFieldFocus)
  81.   
  82.   -- RadioButtons parameters: channel, nChannels, rightAnswer, default
  83.   set goMotionStyles = 0
  84.   set goMotionStyles = birth(script "RadioButton",  26, 4, 0, iCurrentMotionStyleIndex)
  85.   
  86.   
  87.   -- VisualStyles Params: castNum, default, nItems, channel
  88.   if the machineType < 256 then
  89.     mInit(goVisualStyles, the number of cast "BannersVisualStylesMac", ¼
  90.                iCurrentVisualStyleIndex, 8, 19)
  91.   else
  92.     mInit(goVisualStyles, the number of cast "BannersVisualStylesPC", ¼
  93.                iCurrentVisualStyleIndex, 8, 19)
  94.   end if
  95.   
  96.   
  97.   -- For keystroke validity checking
  98.   set the keydownscript =  "mCheckKey(goBanners)"
  99.   
  100. end mInit 
  101.  
  102. on mSetFieldFocus me, oWhom
  103.   set where = getOne(ioFieldList, oWhom)
  104.   if where = 0 then
  105.     alert("Internal error - mSetFieldFocus could not find object")
  106.     return
  107.   end if
  108.   
  109.   set iFieldFocus = where  
  110.   set ioFieldFocus = GetAt(ioFieldList, iFieldFocus)
  111.   
  112. end mSetFieldFocus
  113.  
  114.  
  115. on mCheckKey me
  116.   if the Key = TAB then -- change focus to the next field
  117.     set iFieldFocus = IncrMod(iFieldFocus, count(ioFieldList))
  118.     set ioFieldFocus = GetAt(ioFieldList, iFieldFocus)
  119.     pass  -- pass the event so the hilight goes to the next field  
  120.   else
  121.     if iFieldFocus = 1 then -- the text entry field, allow anything
  122.       pass
  123.     else  -- numeric fields, only allow digits
  124.       if (offset(the key, "0123456789") > 0) or (the key = BACKSPACE)  then
  125.         pass
  126.       else
  127.         dontPassEvent -- restrict only to digits.
  128.       end if
  129.     end if
  130.   end if
  131. end mCheckKey
  132.  
  133. on mSetNewMotionStyle me, theNewStyleIndex
  134.   set iCurrentMotionStyleIndex = theNewStyleIndex
  135. end mSetNewMotionStyle
  136.  
  137. on mSetNewVisualStyle me, theNewStyleIndex
  138.   set iCurrentVisualStyleIndex = theNewStyleIndex
  139. end mSetNewVisualStyle
  140.  
  141.  
  142.  
  143. on mValidate me
  144.   -- Attempt to validate the last field of focus
  145.   set lastFieldOKFlag = mValidate(ioFIeldFocus)
  146.   return lastFieldOKFlag
  147. end mValidate
  148.  
  149.  
  150. on mCreate me
  151.   global goMarkFrame
  152.   global goMotionStyles
  153.   global goVisualStyles
  154.   global goScoreMgr
  155.   global goCastMgr
  156.   global gDevelopmentFlag
  157.   global gCastNumTextAsBitmap
  158.   
  159.   if not(mValidate(me)) then
  160.     return
  161.   end if
  162.   if field("BannersText") = EMPTY then
  163.     alert("Please enter some text for the banner.")
  164.     return
  165.   end if
  166.   
  167.   tell the stage
  168.     set theStageFrame = the frame
  169.   end tell
  170.   
  171.   set castNumVisualStyle = mGetCastNum(goVisualStyles, iCurrentVisualStyleIndex)
  172.   set theVisualStyleName = the name of cast castNumVisualStyle
  173.   set theFont = word 2 of theVisualStyleName
  174.   set theSize = word 3 of theVisualStyleName
  175.   set theSeconds = integer(field "Seconds")
  176.   
  177.   set fps = integer(field "FPS")
  178.   set nFrames = integer(theSeconds * fps)
  179.   set baseLine = integer(field "BaseLine")
  180.   set delayEnter = integer(field "DelayEnter")
  181.   set nCycles = integer(field "Cycles")
  182.   set markFirst = mGetValue(goMarkFrame)
  183.   
  184.   
  185.   -- Call the ScoreMgr to set up the score, # of frames, and 1 channel
  186.   --  set nTotalFrames = (delayEnter + nFrames) * nCycles 
  187.   set nTotalFrames = nFrames * nCycles 
  188.   if not(mInit(goScoreMgr, nTotalFrames, 1)) then
  189.     return
  190.   end if
  191.   
  192.   set theCh = mGetNextSelectedChannel(goScoreMgr)
  193.   set theFrameNum = mGetStartFrame(goScoreMgr)
  194.   
  195.   set castNumSource = mModifyRichTextCM(goCastMgr, ¼
  196.                 the text of field "BannersText", theFont, theSize)
  197.   if castNumSource = 0 then  -- error
  198.     return
  199.   end if
  200.   
  201.   -- The following does an effective "Convert to bitmap" into a 
  202.   -- known bitmap cast member.
  203.   set the picture of member gCastNumTextAsBitmap = ¼
  204.         the picture of member castNumSource
  205.   set widthOfTextAsBitmap = the width of member gCastNumTextAsBitmap
  206.   set heightOfTextAsBitmap = the height of member castNumSource / ¼
  207.                                                 the number of lines in (the text of member castNumSource)
  208.   
  209.   
  210.   -- Do specific calculations depending on motion style  
  211.   
  212.   if (iCurrentMotionStyleIndex = ikMotionRightToLeft) or ¼
  213.       (iCurrentMotionStyleIndex = ikMotionLeftToRight) then    
  214.     set yStart = baseline
  215.     set yEnd = baseLine
  216.     set yInc = 0
  217.     
  218.     if (iCurrentMotionStyleIndex = ikMotionRightToLeft)  then   
  219.       set xStart = mGetStageRight(goScoreMgr)  + 10
  220.       set xEnd = 0 - widthOfTextAsBitmap - 10  
  221.       set xInc = float( xEnd - xStart ) / float(nFrames)  
  222.       
  223.     else  -- Left to right
  224.       set xStart = 0 - widthOfTextAsBitmap - 10  
  225.       set xEnd = mGetStageRight(goScoreMgr) + 10       
  226.       set xInc = float( xEnd - xStart ) / float(nFrames)     
  227.     end if
  228.     
  229.   else  -- up or down
  230.     set xStart = (mGetStageWidth(goScoreMgr) / 2) - (widthOfTextAsBitmap / 2)
  231.     set xEnd = xStart
  232.     set xInc = 0
  233.     if (iCurrentMotionStyleIndex = ikMotionUp)  then   
  234.       set yStart = mGetStageHeight(goScoreMgr) + heightOfTextAsBitmap + 1
  235.       set yEnd = 0 - heightOfTextAsBitmap - 10 
  236.       set yInc = float( yEnd - yStart ) / float(nFrames)  
  237.       
  238.     else  -- Down
  239.       set yStart = 0 - heightOfTextAsBitmap - 10  
  240.       set yEnd = mGetStageHeight(goScoreMgr) + heightOfTextAsBitmap + 10       
  241.       set yInc = float( yEnd - yStart ) / float(nFrames)  
  242.       
  243.     end if
  244.   end if
  245.   
  246.   set theForeColor  = 255
  247.   set theBackColor  = 0
  248.   
  249.   --  Copy the cast member into the source movie's cast
  250.   
  251.   set castNumTarget = mFindFreeCastRun(goCastMgr, 1, 1)
  252.   copyToClipBoard member castNumSource
  253.   tell the stage
  254.     pasteClipboardInto member castNumTarget
  255.     set the name of member castNumTarget  = "RichText" && string(the ticks)
  256.   end tell
  257.   
  258.   --  Finally we are ready to generate frames
  259.   
  260.   -- Mark first frame upon request
  261.   if markFirst  then
  262.     set theLabel  = "AW.Banner." & word 1 of the text of field "BannersText" & " " & ¼
  263.               mGetGeneratedScoreSelection(goScoreMgr)
  264.     mWriteFrameLabel(goScoreMgr, theFrameNum, theLabel)
  265.   end if
  266.   
  267.   -- Generate the score fragment
  268.   repeat with thisCycle = 1 to nCycles
  269.     -- Insert delay at entry upon request  
  270.     --    if  delayEnter > 0  then 
  271.     --      mWriteFrameDelay(goScoreMgr, theFrameNum, delayEnter)
  272.     --     set theFrameNum = theFrameNum + delayEnter
  273.     --    end if
  274.     if delayEnter > 0 then
  275.       mWriteFrameDelay(goScoreMgr, theFrameNum, delayEnter)
  276.       mWriteFrameTempo(goScoreMgr, (theFrameNum + 1), fps)
  277.     else 
  278.       mWriteFrameTempo(goScoreMgr, theFrameNum , fps)
  279.       mWriteFrameTempo(goScoreMgr, (theFrameNum + 1), 0)
  280.     end if
  281.     --      mWriteFrameTempo(goScoreMgr, theFrameNum , fps)
  282.     set xLoc = xStart
  283.     set yLoc = yStart
  284.     tell the stage
  285.       beginRecording
  286.         repeat with thisFrame = 1 to nFrames
  287.           put theFrameNum && theCh  && castNumTarget  && xLoc && yLoc     
  288.           --      mWriteSprite(goScoreMgr, theFrameNum, theCh, castNumTarget, ¼
  289. --                         theForeColor, theBackColor, round(xLoc), round(yLoc), 0, 0)
  290.           set xLoc = integer(xLoc + .49)
  291.           set yLoc = integer(yLoc  + .49)
  292.           mWriteSpriteRange(goScoreMgr, theFrameNum, theCh, castNumTarget, ¼
  293.                          theForeColor, theBackColor, xLoc, yLoc, 0, 0)    
  294.           set theFrameNum = theFrameNum + 1
  295.           set xLoc = xLoc + xInc
  296.           set yLoc = yLoc + yInc
  297.         end repeat
  298.       endRecording
  299.     end tell
  300.   end repeat  
  301.   
  302.   go  label("Banners") + 2  -- to display reselect button
  303.   
  304.   if not(gDevelopmentFlag) then
  305.     tell the stage
  306.       go frame theStageFrame
  307.     end tell
  308.   end if 
  309.   
  310.   mClean(goScoreMgr)
  311.   
  312. end mCreate
  313.  
  314.  
  315.  
  316. on mCleanup me
  317.   global goMotionStyles
  318.   global goSeconds
  319.   global goFPS
  320.   global goBaseLine
  321.   global goDelayEnter
  322.   global goCycles
  323.   global goMarkFrame
  324.   
  325.   mCleanup(goMotionStyles)
  326.   
  327.   set iSaveSeconds =  mGetValue(goSeconds)
  328.   set iSaveFPS = mGetValue(goFPS)
  329.   set iSaveBaseLine = mGetValue(goBaseLine)
  330.   set iSaveDelayEnter = mGetValue(goDelayEnter)
  331.   set iSaveCycles = mGetValue(goCycles)  
  332.   set iSaveMark = mGetValue(goMarkFrame)  
  333.   mCleanup(goMarkFrame)
  334. end mCleanup
  335.  
  336.  
  337.