-- HILITE AND SELECT (FIELD) -- -- -- © August 2000, James Newton -- PROPERTY DECLARATIONS -- property spriteNum -- author-defined parameters property action -- #mouseUp | #doubleClick property handler -- #handlerName to call in ... property location -- movie | behaviors | sendAllSprites | actorList -- internal properties property mySprite -- sprite(me.spriteNum) property myMember -- mySprite.member property myTextTop -- locV of top of text (adjusted for sprite.loc, -- border and margin) property myMouseLine -- line currently under the mouse property myMouseOver -- TRUE if rollover(spriteNum) on last exitFrame -- SPRITE EVENTS -- on beginSprite(me) me.initialize() end beginSprite on endSprite(me) end endSprite -- EVENT HANDLERS -- on mouseUp(me) if the doubleClick = (action = #doubleClick) then me.selectLine() end if end mouseUp on exitFrame(me) if myMouseOver then if not rollover(spriteNum) then -- The mouse has just left the sprite myMouseOver = FALSE end if else if rollover(spriteNum) then -- The mouse has just rolled onto the sprite myMouseOver = TRUE else -- The mouse is still elsewhere exit end if me.updateHilite(myMouseOver) end exitFrame -- PRIVATE METHODS -- on initialize(me) ---------------------------------------------------- -- Sent by beginSprite() -- -- * -------------------------------------------------------------------- mySprite = sprite(me.spriteNum) myMember = mySprite.member edgeWidth = myMember.border + (myMember.margin / 2) myTextTop = mySprite.top + edgeWidth end initialize on updateHilite(me, mouseOver) --------------------------------------- -- Sent by exitFrame() -- -- * Hilites the line under the mouse, or removes the hilite if the -- mouse is not directly over a line. -------------------------------------------------------------------- if mouseOver then currentLine = the mouseLine theText = myMember.text -- The mouse may be before the first line or after the last line, -- in which case the last line should not appear selected if currentLine = 1 then if the mouseV < myTextTop then -- The mouse is above the first line currentLine = 0 end if else if currentLine = theText.line.count then charCount = theText.char.count -- Where is the bottom (-left corner) of the last character? vLoc = (charPosToLoc(myMember, charCount)).locV + myTextTop vLoc = vLoc - myMember.scrollTop if the mouseV > vLoc then -- The mouse is below the last character currentLine = 0 end if end if else -- The mouse is no longer over the field currentLine = 0 end if if myMouseLine = currentLine then -- Status quo exit end if -- The mouse has just moved over a new line myMouseLine = currentLine if myMouseLine then -- Hilite the current line if myMouseLine = 1 then firstChar = 1 else firstChar = (theText.line[1..myMouseLine - 1]).char.count + 2 end if finalChar = firstChar + theText.line[myMouseLine].char.count hilite char firstChar to finalChar of field myMember else -- Remove the hilite hilite char the maxInteger of field myMember end if end updateHilite on selectLine(me) ---------------------------------------------------- -- Sent by mouseUp() -- -- * Sends the chosen handler to the chosen scripts/instances, with -- the parameters , . -------------------------------------------------------------------- if myMouseLine < 1 then exit end if selectedText = myMember.line[myMouseLine] case location of "a movie script": sendSprite(0, handler, selectedText, myMouseLine) "a behavior on the same sprite": behaviors = mySprite.scriptInstanceList call(handler, behaviors, selectedText, myMouseLine) "behaviors on other sprites": sendAllSprites(handler, selectedText, myMouseLine) "an instance on the actorList": call(handler, the actorList, selectedText, myMouseLine) end case end selectLine -- BEHAVIOR DESCRIPTION AND PARAMETERS -- on isOKToAttach(me, spriteType, spriteNumber) if spriteType = #graphic then return sprite(spriteNumber).member.type = #field else return FALSE end if end isOKToAttach on getPropertyDescriptionList(me) propertiesList = [:] propertiesList[ \ #action] = [ \ #comment: "on", \ #format: #symbol, \ #range: [ \ #mouseUp, \ #doubleClick \ ], \ #default: #mouseUp \ ] propertiesList[ \ #handler] = [ \ #comment: "call the handler", \ #format: #symbol, \ #default: #selectFromField \ ] propertiesList[ \ #location] = [ \ #comment: "which appears in", \ #format: #string, \ #range: [ \ "a movie script", \ "a behavior on the same sprite", \ "behaviors on other sprites", \ "an instance on the actorList" \ ], \ #default: "a movie script" \ ] return propertiesList end getPropertyDescriptionList on getBehaviorTooltip(me) return \ "Use with #field members"&RETURN&RETURN&\ "Hilites the line under the mouse on rollover"&RETURN&\ "and sends a customizable call when a line is"&RETURN&\ "clicked or double-clicked." end getBehaviorTooltip on getBehaviorDescription(me) return \ "HILITE AND SELECT (FIELD)"&RETURN&RETURN&\ "Use with field members only."&RETURN&RETURN&\ "Hilites the line of text under the mouse. (A line terminates with a hard RETURN character: a section of softwrapped text counts as one line). When the user clicks on the field, this behavior sends a customizable message to a Movie Script handler, to other behaviors or to the actorList. You can choose between a single- and a double-click. "&RETURN&RETURN&\ "Example call:"&RETURN&RETURN&\ " sendAllSprites(#lineSelected, selectedText, selectedLine)"&\ RETURN&RETURN&\ "This behavior will work with non-scrolling fields but will not scroll automatically. You can change the text of the member on the fly without taking any special precautions."&RETURN&RETURN&\ "PARAMETERS:"&RETURN&\ " * React to a single- or to a double-click"&RETURN&\ " * Handler to call"&RETURN&\ " * Location of handler to call" end getBehaviorDescription