home *** CD-ROM | disk | FTP | other *** search
/ Boot Disc 2 / boot-disc-1996-10.iso / Demo.dir / 00048_Script_scrollClass < prev    next >
Text File  |  1996-08-09  |  11KB  |  348 lines

  1. property revSprite,advSprite,revBtnUp,revBtnDn,advBtnUp,advBtnDn
  2. property thumbSprite,thumbOrient,thumbpos,thumbmin,thumbmax
  3. property textmember,textsprite,numLines,texttop,textHeight
  4. property totalTextHeight,curLine,textRate,textDefaultRate
  5. property RevActive,AdvActive,ThumbActive,IDName,thumbRefresh
  6. property textdelta,basepos,acceleratemode,hand,handmask
  7. property findinstance,findtext
  8.  
  9. on new me,myIDName,textMemberName,revMemberName,advMemberName,thumbName,tOrient,tMin,tMax,handmember,handmaskmember
  10.   set IDName=myIDName
  11.   do ("global "&IDName)
  12.   do ("set "&IDName&" to me")
  13.   set revSprite=castsprite(me,revMemberName)
  14.   set advSprite=castsprite(me,advMemberName)
  15.   set revBtnUp=the number of member revMemberName
  16.   set revBtnDn=the number of member (revMemberName&"Down")
  17.   set advBtnUp=the number of member advMemberName
  18.   set advBtnDn=the number of member (advMemberName&"Down")
  19.   preload advBtnDn
  20.   preload revBtnDn
  21.   set findtext=""
  22.   set textDefaultRate=5
  23.   set textRate=textDefaultRate
  24.   set thumbSprite=castsprite(me,thumbName)
  25.   set thumbOrient=tOrient
  26.   set thumbMin=tMin
  27.   set thumbMax=tMax
  28.   puppetsprite thumbSprite,true
  29.   puppetsprite revsprite,true
  30.   puppetsprite advsprite,true
  31.   set textMember=the number of member textMemberName
  32.   set textsprite=castsprite(me,textMemberName)
  33.   setTextCursor me,hand,handmask
  34.   set textdelta=0
  35.   set numLines=the linecount of member textmember
  36.   if the number of member "SystemInfoList">0 then
  37.     set syslist=value(the text of member "SystemInfoList")
  38.     if not listP(syslist) then
  39.       set totalTextHeight=getTextHeight(me,numLines)
  40.     else
  41.       set obj=getaprop(syslist,IDName)
  42.       if not voidP(obj) then
  43.         set totalTextHeight=the totalTextHeight of obj
  44.       else
  45.         set totalTextHeight=getTextHeight(me,numLines)
  46.       end if
  47.     end if
  48.   else
  49.     set totalTextHeight=getTextHeight(me,numLines)
  50.   end if
  51.   set textTop=the locV of sprite textsprite
  52.   set textHeight=the height of sprite textsprite
  53.   set curline=1
  54.   set thumbrefresh=false
  55.   set the scrolltop of member textMember to 0
  56.   set acceleratemode=false
  57.   updateThumb me
  58.   clearOldInstancesOf me
  59.   add the actorlist,me
  60.   updateSystemInfoList me
  61.   return me
  62. end
  63.  
  64. on clearOldInstancesOf me
  65.   set clearlist=[]
  66.   set oldDelimiter=the itemDelimiter
  67.   set the itemDelimiter=quote
  68.   repeat with obj in the actorlist
  69.     if item 2 of string(obj)="scrollClass" then
  70.       if the textmember of obj=textmember then
  71.         add clearlist,getpos(the actorlist,obj)
  72.       end if
  73.     end if
  74.   end repeat
  75.   repeat with index=count(clearlist) down to 1
  76.     set curpos=getat(clearlist,index)
  77.     deleteat the actorlist,curpos
  78.   end repeat
  79.   set the itemDelimiter=oldDelimiter
  80. end
  81.  
  82. on getTextHeight me,numlines
  83.   if voidP(numlines) then set numlines=the linecount of member textmember
  84.   set pos=0
  85.   repeat with index=1 to numlines
  86.     set pos=pos+the lineheight of line index of member textmember
  87.   end repeat
  88.   return pos
  89. end
  90.  
  91. on castsprite me,castname
  92.   set spritenum=0
  93.   repeat with index=1 to 48
  94.     if the membernum of sprite index>0 then
  95.       if the name of member the membernum of sprite index=castname then
  96.         set spritenum=index
  97.         exit repeat
  98.       end if
  99.     end if
  100.   end repeat
  101.   return spritenum
  102. end castsprite
  103.  
  104. on stepframe me
  105.   set refreshmode=true
  106.   if the mouseDown then
  107.     if rollover(thumbSprite) or (thumbrefresh) then
  108.       if thumbOrient=#vert then
  109.         set the locV of sprite thumbsprite to min(max(the mouseV,thumbmin),thumbmax)
  110.       else
  111.         set the locH of sprite thumbsprite to min(max(the mouseH,thumbmin),thumbmax)
  112.       end if
  113.       updateStage
  114.       set thumbrefresh=true
  115.       setTextFromThumb me
  116.     end if
  117.   end if
  118.   if the mousedown then
  119.     if rollover(textsprite) then
  120.       if textdelta=0 then
  121.         set textdelta=the mouseV
  122.         set basepos=the scrolltop of member textmember
  123.       end if
  124.       if the rightmousedown then
  125.         set basepos=the scrolltop of member textmember
  126.       end if
  127.       set the scrolltop of member textmember to min(max(basepos+textdelta-the mouseV,0),totaltextheight-textheight)
  128.       updateThumb me
  129.     end if  
  130.   else
  131.     if textdelta<>0 then
  132.       set textdelta=0
  133.       --      updateThumb me
  134.     end if
  135.   end if
  136.   if the mouseUp and thumbrefresh=true then
  137.     set thumbrefresh=false
  138.     setTextFromThumb me
  139.   end if
  140.   if rollover(advSprite) then
  141.     if the mousedown then
  142.       if the membernum of sprite advSprite=advbtnup then
  143.         set the membernum of sprite advSprite to advbtndn
  144.         updateStage
  145.       end if
  146.       set refreshmode=false
  147.       advance me
  148.     end if
  149.   end if
  150.   if rollover(revSprite) then
  151.     if the mousedown then
  152.       if the membernum of sprite revSprite=revbtnup then
  153.         set the membernum of sprite revSprite to revbtndn
  154.         updateStage
  155.       end if
  156.       set refreshmode=false
  157.       reverse me
  158.     end if
  159.   end if
  160.   if refreshmode then
  161.     set textrate=textdefaultrate
  162.     if the membernum of sprite revsprite=revbtndn then
  163.       set the membernum of sprite revsprite to revbtnup
  164.       updateStage
  165.     end if
  166.     if the membernum of sprite advsprite=advbtndn then
  167.       set the membernum of sprite advsprite to advbtnup
  168.       updateStage
  169.     end if
  170.   end if
  171. end
  172.  
  173. on setTextFromThumb me
  174.   -- cursor 4
  175.   if thumborient=#vert then
  176.     set ratio=1.0*(the locV of sprite thumbsprite-thumbmin)/(thumbmax-thumbmin)
  177.     set the scrollTop of member textmember to  integer((totaltextheight-textheight)*ratio)
  178.   else
  179.     set ratio=1.0*(the locH of sprite thumbsprite-thumbmin)/(thumbmax-thumbmin)
  180.     set the scrollTop of member textmember to  integer((totaltextheight-textheight)*ratio)
  181.     --    set curline=locVtolinepos(member textmember,texttop)
  182.     --    set newpos=gettextheight(me,curline-1)
  183.     --    set the scrollTop of member textmember to newpos
  184.   end if
  185.   -- cursor -1
  186. end
  187.  
  188. on advance me
  189.   set textrate=the lineheight of line (locVtolinepos(member textmember,texttop)) of member textmember
  190.   if the scrollTop of member textmember+textheight+textrate<=totaltextheight then
  191.     set the scrollTop of member textmember to the scrollTop of member textmember+textrate
  192.     -- set textrate=textrate+0.2
  193.     updateThumb me
  194.   end if
  195. end
  196.  
  197. on reverse me
  198.   set textrate=the lineheight of line (locVtolinepos(member textmember,texttop)) of member textmember
  199.   if the scrolltop of member textmember - textrate>=0 then
  200.     set the scrollTop of member textmember to the scrollTop of member textmember-textrate
  201.     --set textrate=textrate+0.2
  202.     updateThumb me
  203.   end if
  204. end
  205.  
  206. on reset me
  207.   set totalTextHeight=gettextheight(me)
  208. --  if totalTextHeight<textheight then
  209. --    set the visible of sprite thumbsprite to false
  210. --  else
  211. --    set the visible of sprite thumbsprite to true
  212. --  end if
  213.   updateSystemInfoList me
  214. end
  215.  
  216. on updateThumb me
  217. --  set totalTextHeight=gettextheight(me)
  218. --  if totalTextHeight<textheight then
  219. --    set the visible of sprite thumbsprite to false
  220. --  else
  221. --    set the visible of sprite thumbsprite to true
  222. --  end if
  223.   set ratio=1.0*(the scrolltop of member textmember)/(totaltextheight-textheight)
  224.   if thumborient=#vert then
  225.     set the locV of sprite thumbsprite to thumbmin+ratio*(thumbmax-thumbmin)
  226.   else
  227.     set the locH of sprite thumbsprite to thumbmin+ratio*(thumbmax-thumbmin)
  228.   end if
  229.   updateStage
  230. end
  231.  
  232. on settextcursor me,hand,handmask
  233.   if voidP(hand) then
  234.     if the number of member "hand">0 then
  235.       if the number of member "handmask">0 then
  236.         set the cursor of sprite textsprite to [the number of member "hand",the number of member "handmask"]
  237.       end if
  238.     end if
  239.   else
  240.     if the number of member hand>0 then
  241.       if the number of member handmask>0 then
  242.         set the cursor of sprite textsprite to [the number of member hand,the number of member handmask]
  243.       else
  244.         set the cursor of sprite textsprite to [the number of member hand,the number of member hand]
  245.       end if
  246.     else
  247.       alert ("The castmember "&hand&" was not found.")
  248.       halt
  249.     end if
  250.   end if
  251. end
  252.  
  253. on dispose me
  254.   updateSystemInfoList me
  255.   clearOldInstancesOf me
  256.   puppetsprite thumbsprite,0
  257.   puppetsprite advsprite,0
  258.   puppetsprite revsprite,0
  259.   set the cursor of sprite textsprite to -1
  260.   return 0
  261. end
  262.  
  263. on updateSystemInfoList me
  264.   set systemlist=[:]
  265.   if the number of member "SystemInfoList"<1 then
  266.     set systemlist=[:]
  267.     set sysmember=findEmpty(member 1)
  268.     repeat with index=1 to the maxInteger
  269.       if the type of member index=#field then
  270.         duplicate member index, sysmember
  271.         exit repeat
  272.       end if
  273.     end repeat
  274.     set the name of member sysmember to "SystemInfoList"
  275.     set the text of member sysmember to  "[:]"
  276.   else
  277.     set sysmember=the number of member ("SystemInfoList")
  278.     set systemlist=value(the text of member sysmember)
  279.     if systemlist=0 then
  280.       set systemlist=[:]
  281.     end if
  282.   end if
  283.   set proplist=[:]
  284.   repeat with index=1 to count(me)
  285.     set prop=getpropat(me,index)
  286.     set entry=getprop(me,prop)
  287.     if voidP(entry) then set entry=0
  288.     addprop proplist,prop,entry
  289.   end repeat
  290.   if voidP(getaprop(systemlist,IDName)) then
  291.     addprop systemlist,IDName,proplist
  292.   else
  293.     setprop systemlist,IDName,proplist
  294.   end if
  295.   set the text of member sysmember to string(systemlist)  
  296. end
  297.  
  298. on find me,phrase,whichincidence
  299.   if voidP(phrase) then
  300.     if findtext="" then
  301.       alert("A search phrase must be specified")
  302.       exit
  303.     else
  304.       set phrase=findtext
  305.     end if
  306.   else
  307.     if findtext<>phrase then
  308.       set findinstance=0
  309.     end if
  310.   end if
  311.   set lastpos=0
  312.   set findtext=phrase
  313.   set curtext=the text of member TextMember
  314.   if voidP(whichincidence) then 
  315.     set whichincidence=findinstance+1
  316.     set findinstance=whichincidence
  317.   else
  318.     set findinstance=whichincidence
  319.   end if
  320.   set the forecolor of member TextMember to 255
  321.   repeat with index=1 to whichincidence
  322.     set pos=offset(phrase,curtext)
  323.     if pos=0 then
  324.       if index=1 then
  325.         alert(quote&phrase"e&" was not found.")
  326.         exit
  327.       else
  328.         alert("No more instances of ""e&phrase"e&" were found.")
  329.         exit  
  330.       end if
  331.     else
  332.       set curchar=pos+lastpos
  333.       set linepos=linePosToLocV(member textmember,locVToLinePos(member textmember,getat(charpostoloc(member textmember,curchar),2)+texttop)-1)-texttop
  334.       if index=whichincidence then
  335.         set the forecolor of char curchar to curchar+length(phrase)-1 of member textmember to 6
  336.         set the scrolltop of member textmember to linepos
  337.         updateThumb me
  338.       end if
  339.       set lastpos=lastpos+pos+length(phrase)-1
  340.       delete char 1 to pos+length(phrase)-1 of curtext
  341.     end if
  342.   end repeat
  343. end
  344.  
  345.  
  346.  
  347.  
  348.