home *** CD-ROM | disk | FTP | other *** search
/ New Grand Theft Auto 2003 Classic Collection / PHOTOSHOP.iso / contents / sample.dxr / 00029_Tooltip.ls < prev    next >
Encoding:
Text File  |  2002-04-19  |  10.1 KB  |  206 lines

  1. property mySprite, getPDLError, myString, myDelay, myPosition, myDisplaySprite, myHideFlag, myDisplayList, myStartTicks, myDisplayFlag
  2.  
  3. on getBehaviorDescription me
  4.   return "TOOLTIP" & RETURN & RETURN & "Generates a tool tip when the user rolls over the sprite." & RETURN & RETURN & "NOTE: This behavior calls the 'Display Text' behavior to actually show the message. " & "The 'Display Text' behavior must be attached to a different sprite which contains either a Field or a Text member." & RETURN & RETURN & "If such a sprite exists, it will automatically be selected in the Behavior Parameters dialog." & RETURN & RETURN & "If you wish the Tooltip to appear in a given position relative to the current sprite, choose the appropriate position in the Behavior Parameters dialog, and ensure that the associated 'Display Text' behavior is set to act as a Tooltip. " & "(If the 'Display Text' behavior is set to act as a Status Bar, then it will ignore any position data and appear in a fixed position)." & RETURN & RETURN & "You can choose to have the tooltip appear immediately on rollover, or to appear only if the mouse remains over the sprite for a given period. " & "You can also choose to have the tooltip disappear if the user clicks on the sprite." & RETURN & RETURN & "The Behavior Parameters dialog has limited space for entering a tool tip message. " & "In particular, it will not accept a string which contains the RETURN character. " & "If you need to display a long Tooltip which consists of several lines of text, and which must appear at the position of this sprite, then you must use send a message to this behavior containing the requiresd string. " & "For example:" & RETURN & RETURN & "  SendSprite (1, #Tooltip_SetMessage, " & QUOTE & "This message consists" & QUOTE & "&RETURN&" & QUOTE & "of two lines of text" & QUOTE & ")" & RETURN & RETURN & "This would produce the following message when the mouse rolls over sprite 1:" & RETURN & RETURN & "     This message consists" & RETURN & "     of two lines of text" & RETURN & RETURN & "If the tooltip generated by this behavior is to be diplayed in a Status bar then this step may be needed. " & " The 'Display Text' behavior will ensure that a long line of text is wrapped in the Status bar, and that scroll bars appear if necessary." & RETURN & RETURN & "PERMITTED MEMBER TYPES:" & RETURN & "All" & RETURN & RETURN & "PARAMETERS:" & RETURN & "* Tool tip to display (single-line string)" & RETURN & "* Delay before displaying tool tip (0 - 2 seconds)" & RETURN & "* Hide tool tip if sprite is clicked? (TRUE | FALSE)" & RETURN & "* Position of tool tip relative to the sprite" & RETURN & "  (This will be ignored if the 'Display Text' behavior is set to act as a status bar)." & RETURN & "* Number of the sprite where tool tip is to be displayed." & RETURN & "  (This sprite should have the 'Display Text' behavior attached to it. " & " If the given sprite is moved an authortime alert will invite you to update the Behavior Parameters)." & RETURN & RETURN & "PUBLIC METHODS:" & RETURN & "=> Set the tooltip message (allows the RETURN character)" & RETURN & "=> Obtain behavior reference" & RETURN & RETURN & "ASSOCIATED BEHAVIORS:" & RETURN & "+ Display Text - ESSENTIAL - must be attached to a Field or Text sprite which covers the same span of frames." & RETURN & RETURN & "You can find the 'Display Text' behavior in the Library Palette, under Controls > Display Text."
  5. end
  6.  
  7. on getBehaviorTooltip me
  8.   return "Use with any type of member." & RETURN & RETURN & "Generates a tool tip message when the mouse is over the sprite." & RETURN & RETURN & "This behavior requires that the 'Display Text' behavior be available on a Field or Text sprite to display the messages that it generates. " & "If no such sprite is available an alert will appear (authortime only)." & RETURN & RETURN & "The parameter set for the associated 'Display Text' behavior determines whether the tool tip message appears in a Status Bar or as a temporary Tooltip display over or near this sprite."
  9. end
  10.  
  11. on beginSprite me
  12.   initialize(me)
  13. end
  14.  
  15. on prepareFrame me
  16.   CheckStatus(me)
  17. end
  18.  
  19. on mouseEnter me
  20.   myStartTicks = the ticks + myDelay
  21. end
  22.  
  23. on mouseLeave me
  24.   myStartTicks = the maxinteger
  25. end
  26.  
  27. on initialize me
  28.   mySprite = sprite(me.spriteNum)
  29.   myMember = mySprite.member
  30.   myDisplayList = []
  31.   myStartTicks = the maxinteger
  32. end
  33.  
  34. on CheckStatus me
  35.   if myStartTicks < the ticks then
  36.     if myHideFlag then
  37.       if the mouseDown then
  38.         if myDisplayFlag then
  39.           HideTip(me)
  40.         end if
  41.         exit
  42.       end if
  43.     end if
  44.     if myDisplayFlag then
  45.       exit
  46.     end if
  47.     ShowTip(me)
  48.   else
  49.     if myDisplayFlag then
  50.       HideTip(me)
  51.     end if
  52.   end if
  53. end
  54.  
  55. on ShowTip me
  56.   myDisplayFlag = 1
  57.   case myPosition of
  58.     "centered above":
  59.       theAlignment = #bottomcenter
  60.       displayLoc = point((mySprite.left + mySprite.right) / 2, mySprite.top)
  61.     "centered below":
  62.       displayLoc = point((mySprite.left + mySprite.right) / 2, mySprite.bottom)
  63.       theAlignment = #topcenter
  64.     "at topLeft":
  65.       displayLoc = point(mySprite.left, mySprite.top)
  66.       theAlignment = #topleft
  67.     "at topRight":
  68.       displayLoc = point(mySprite.right, mySprite.top)
  69.       theAlignment = #topright
  70.     "centered":
  71.       centerh = (mySprite.left + mySprite.right) / 2
  72.       centerv = (mySprite.top + mySprite.bottom) / 2
  73.       displayLoc = point(centerh, centerv)
  74.       theAlignment = #center
  75.     "at bottomLeft":
  76.       displayLoc = point(mySprite.left, mySprite.bottom)
  77.       theAlignment = #bottomleft
  78.     "at bottomRight":
  79.       displayLoc = point(mySprite.right, mySprite.bottom)
  80.       theAlignment = #bottomright
  81.     "at regPoint":
  82.       displayLoc = mySprite.loc
  83.       theAlignment = #center
  84.     "under the mouse":
  85.       displayLoc = the mouseLoc
  86.       theAlignment = #center
  87.     "New Point":
  88.       displayLoc = point((mySprite.left + mySprite.right) / 2, mySprite.bottom)
  89.       theAlignment = #center
  90.   end case
  91.   if not myDisplayList.count() then
  92.     EnrollDisplaySprite(me)
  93.   end if
  94.   call(#DisplayText_SetText, myDisplayList, myString, displayLoc, theAlignment)
  95. end
  96.  
  97. on HideTip me
  98.   myDisplayFlag = 0
  99.   if not myDisplayList.count() then
  100.     EnrollDisplaySprite(me)
  101.   end if
  102.   call(#DisplayText_SetText, myDisplayList, EMPTY)
  103. end
  104.  
  105. on EnrollDisplaySprite me
  106.   sendSprite(myDisplaySprite, #DisplayText_Enroll, myDisplayList)
  107.   if not myDisplayList.count() then
  108.     sendAllSprites(#DisplayText_Enroll, myDisplayList)
  109.     if not myDisplayList.count() then
  110.       ErrorAlert(me, #noValidSprites, myDisplaySprite)
  111.     else
  112.       ErrorAlert(me, #invalidSpriteNumber, myDisplaySprite)
  113.     end if
  114.   end if
  115. end
  116.  
  117. on GetDisplaySprite me
  118.   displayScriptMember = the number of member "Display Text"
  119.   if displayScriptMember > 0 then
  120.     displayScriptMember = member(displayScriptMember)
  121.     repeat with theSprite = 1 to the lastChannel
  122.       theScripts = sprite(theSprite).scriptList
  123.       scriptCount = theScripts.count()
  124.       repeat while scriptCount
  125.         if theScripts[scriptCount][1] = displayScriptMember then
  126.           return theSprite
  127.         end if
  128.         scriptCount = scriptCount - 1
  129.       end repeat
  130.     end repeat
  131.   end if
  132.   return the currentSpriteNum + 1
  133. end
  134.  
  135. on Tooltip_SetMessage me, thestring
  136.   case ilk(thestring) of
  137.     #string:
  138.     otherwise:
  139.       return #invalidTypeError
  140.   end case
  141.   myString = thestring
  142. end
  143.  
  144. on Tooltip_GetReference me
  145.   return me
  146. end
  147.  
  148. on ErrorAlert me, theError, data
  149.   behaviorName = string(me)
  150.   delete word 1 of behaviorName
  151.   delete char -30001 of behaviorName
  152.   delete char -30001 of behaviorName
  153.   case data.ilk of
  154.     #void:
  155.       data = "<void>"
  156.     #symbol:
  157.       data = "#" & data
  158.   end case
  159.   case theError of
  160.     #invalidSpriteNumber:
  161.       if the runMode = "Author" then
  162.         message = substituteStrings(me, "Sprite ^3 did not respond to a #DisplayText call. " & " Another sprite will be used. " & " Please open the Behavior Parameters dialog to choose the correct sprite for displaying the Tooltip message.", ["^0": the frame, "^1": me.spriteNum, "^2": behaviorName, "^3": data])
  163.       end if
  164.       alert(message)
  165.     #noValidSprites:
  166.       if the runMode = "Author" then
  167.         message = substituteStrings(me, "BEHAVIOR ERROR: Frame ^0, Sprite ^1 " & RETURN & "Behavior ^2" & RETURN & RETURN & "No sprites responded to a #DisplayText call." & RETURN & RETURN & "Please ensure that the '^3' behavior is attached to a Field or Text Sprite in the same frames as Sprite ^1.", ["^0": the frame, "^1": me.spriteNum, "^2": behaviorName, "^3": "Display Text"])
  168.       end if
  169.       alert(message)
  170.   end case
  171. end
  172.  
  173. on substituteStrings me, parentString, childStringList
  174.   i = childStringList.count()
  175.   repeat while i
  176.     tempString = EMPTY
  177.     dummyString = childStringList.getPropAt(i)
  178.     replacement = childStringList[i]
  179.     lengthAdjust = dummyString.char.count - 1
  180.     repeat while 1
  181.       position = offset(dummyString, parentString)
  182.       if not position then
  183.         parentString = tempString & parentString
  184.         exit repeat
  185.         next repeat
  186.       end if
  187.       if position <> 1 then
  188.         tempString = tempString & parentString.char[1..position - 1]
  189.       end if
  190.       tempString = tempString & replacement
  191.       delete parentString.char[1..position + lengthAdjust]
  192.     end repeat
  193.     i = i - 1
  194.   end repeat
  195.   return parentString
  196. end
  197.  
  198. on isOKToAttach me, aSpriteType
  199.   return aSpriteType = #graphic
  200. end
  201.  
  202. on getPropertyDescriptionList me
  203.   displaySprite = GetDisplaySprite(me)
  204.   return [#myString: [#comment: "Text of tool tip", #format: #string, #default: "Insert your single-line tool tip here"], #myDelay: [#comment: "Pause before showing tool tip (ticks)", #format: #integer, #range: [#min: 0, #max: 120], #default: 30], #myHideFlag: [#comment: "Hide tool tip if user clicks on sprite?", #format: #boolean, #default: 1], #myPosition: [#comment: "Tool tip position relative to sprite (see notes)", #format: #string, #range: ["centered above", "New Point", "at topLeft", "at topRight", "centered", "at bottomLeft", "at bottomRight", "centered below", "at regPoint", "under the mouse"], #default: "New Point"], #myDisplaySprite: [#comment: "Use which sprite to display tooltip?", #format: #integer, #range: [#min: 1, #max: the lastChannel], #default: displaySprite]]
  205. end
  206.