Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
PDF files on the fly
Text Box Xtra
Fast Blur Algorithm
Sharpen Filter - Imaging Lingo
Display an objects properties in Director
Easy Mui
3D Watcher
MP3 Cross Fader
Read a File
Replace embedded fonts in text/field and button members
 

 

 

Behavior Text Pop Up

Added on 4/15/2000

 

Compatibilities:
behavior D7 D8 Mac PC Shockwave

This item has not yet been rated

Author: MarkReijnders

Popup menu behavior that uses Anti-aliased Text members

Download PC Source    Download Mac Source
-- Popup menu behavior that uses Anti-aliased Text members
-- works in Director 7 and 8

--******************************************************************
-- version 1.2   April 2000
-- (c) Mare (Mark Reijnders) mare@peghole.com
-- http://www.peghole.com
-- A demo movie can be found at http://www.peghole.com/lingo/txtpopup2.zip
-- if used please give credit
--******************************************************************

property pNormalSpriteNum , pNormalMember, pPopUpSpriteNum , pPopUpMember, pOutLineSpriteNum
property pOutLineMember,pHiliteSpriteNum, pHilteMember, pSelectedLine, pMouseUpCommand, pExcludedWords
property pLinecount, pLineHeight, pPopUpListOrder

on GetBehaviorDescription
  return "Generic Popupmenu behavior" & RETURN & ¬
"This behavior displays a popup menu (also called dropdown menu) that consists of anti aliased text.¬
The behavior should be attached to a single line text member. In the score there should¬
be three more sprites populated with the following members:¬
An optional outline (Quickdraw shape member), the complete popup text cast member, and the hilite member, a filled quickdraw shape. ¬
The sprite order should be outlinemember, normal (1 line) member, expanded member, hiliteline member" & RETURN & ¬
"Words that should not trigger any change EG 'Select..' can be given as an option."  & RETURN & ¬
"Separators should be made with the underscore character"  & RETURN & ¬
"Optional Lingo handler that will be executed at mouseup with the selected line as a parameter"
  
end GetBehaviorDescription

--********************************************************

on getPropertyDescriptionList me
  
  set p_list = [¬
#pMouseUpCommand:     [#comment:"Lingo for MouseUp:", #format:#string, #default: "handlePopUp"], ¬
#pExcludedWords:  [#comment:"Words in popUp that should not trigger actions:", #format:#string, #default:""]]
  
  return p_list
  
end getPropertyDescriptionList

--********************************************************


on getBehaviorTooltip me
  return¬
  "Use with Text members." & RETURN & RETURN & ¬
  "Displays a popup menu (also called dropdown menu) that consists of anti aliased text."
end getBehaviorTooltip

--********************************************************
--Director 8 handler

on isOKToAttach (me, aSpriteType, aSpriteNum)
  case aSpriteType of
    #graphic:
      return getPos([#text], sprite(aSpriteNum).member.type) <> 0
    #script:
      return FALSE
  end case
end isOKToAttach

--********************************************************

on beginsprite me
  pPopUpListOrder = []
  
  -- set properties
  pNormalSpriteNum = the spriteNum of me
  pNormalMember = sprite(pNormalSpriteNum).member
  pPopUpSpriteNum = pNormalSpriteNum + 1
  pPopUpMember = sprite(pPopUpSpriteNum).member
  pOutLineSpriteNum = pNormalSpriteNum - 1
  pOutLineMember = sprite(pOutLineSpriteNum).member
  pHiliteSpriteNum = pNormalSpriteNum + 2
  pHilteMember = sprite(pHiliteSpriteNum).member
  pSelectedLine = 0
  
  
  sprite(pPopUpSpriteNum).locV = -1000
  updatestage
  scrollTop = pPopUpMember.scrollTop
  spriteHeight = (sprite(pPopUpSpriteNum).rect).height
  memberHeight = (pNormalMember.rect).height
  memberWidth = (pNormalMember.rect).width
  popUpHeight = abs(scrolltop - spriteHeight)
  pLinecount = popUpHeight / max(memberHeight, 1)
  
  reset me
  
  --put number of lines in list so we can keep track of their order
  repeat with i = 1 to pLinecount
    pPopUpListOrder[i] = i
  end repeat
  
  sprite(pHiliteSpriteNum).locV = -1000
  
end beginsprite

--********************************************************
on reset me
  --reset state of normalmember and edge
  
  --synchronise widths
  pNormalMember.rect = rect(pNormalMember.rect[1], pNormalMember.rect[2], pPopUpMember.rect[3], pNormalMember.rect[4])
  
  --set edge
  memberHeight = (pNormalMember.rect).height
  memberWidth = (pNormalMember.rect).width
  
  mylineSize = pOutLineMember.linesize
  outlinewidth = sprite(pOutLineSpriteNum).rect[1] + memberWidth + (mylineSize * 2)
  outlineheight = sprite(pOutLineSpriteNum).rect[2] + memberHeight + (mylineSize * 2)
  
  sprite(pOutLineSpriteNum).rect = rect(sprite(pOutLineSpriteNum).rect[1], sprite(pOutLineSpriteNum).rect[2], outlinewidth, outlineheight)
  sprite(pOutLineSpriteNum).loc = sprite(pNormalSpriteNum).loc - point(mylineSize, mylineSize)
  
  sprite(pHiliteSpriteNum).locV = -1000
  sprite(pPopUpSpriteNum).locV = -1000
  updatestage
  
end reset

on PopupMouseDown me
  -- Do all stuf not in a normal mouseDown handler so it can be called from a button
  -- Eg sendsprite(12, #PopupMouseDown)
  
  myText = pNormalMember.text
  
  --check contents of text
  
  myText = pNormalMember.text
  
  case (true) of
    (pExcludedWords contains myText) : -- don't do anything because popup is 'frozen'
      pSelectedLine = 0
      return
    (myText contains "Don't select") : -- add other words or chunks here to exclude more items
      pSelectedLine = 0
      return
  end case
  
  
  --exchange members
  sprite(pPopUpSpriteNum).loc = sprite(pNormalSpriteNum).loc
  
  memberHeight = (pPopUpMember.rect).height
  memberWidth = (pPopUpMember.rect).width
  
  --set edge
  mylineSize = pOutLineMember.linesize
  outlinewidth = sprite(pOutLineSpriteNum).rect[1] + memberWidth + (mylineSize * 2)
  outlineheight = sprite(pOutLineSpriteNum).rect[2] + memberHeight + (mylineSize * 2)
  
  sprite(pOutLineSpriteNum).rect = rect(sprite(pOutLineSpriteNum).rect[1], sprite(pOutLineSpriteNum).rect[2], outlinewidth, outlineheight)
  sprite(pOutLineSpriteNum).loc = sprite(pPopUpSpriteNum).loc - point(mylineSize, mylineSize)
  
  updatestage
  
  -- get properties of popup; they might be changed
  scrollTop = pPopUpMember.scrollTop
  spriteHeight = (sprite(pPopUpSpriteNum).rect).height
  memberHeight = (pNormalMember.rect).height
  memberWidth = (pPopUpMember.rect).width
  popUpHeight = abs(scrolltop - spriteHeight)
  pLinecount = popUpHeight / max(memberHeight, 1)
  pLineHeight = popUpHeight/pLinecount
  
  -- highlight the right line
  repeat while the mouseDown
    myline = pointToLine(sprite pPopUpSpriteNum, the mouseLoc)
    if myline = -1 then -- no line selected
      sprite(pHiliteSpriteNum).locv = -1000
      updatestage
      next repeat
    end if
    
    myTop = sprite(pPopUpSpriteNum).locV + ((myLine-1) * pLineHeight)
    mybottom = sprite(pPopUpSpriteNum).locV + (myLine * pLineHeight)
    sprite(pHiliteSpriteNum).rect = rect(sprite(pPopUpSpriteNum).rect[1],myTop, sprite(pPopUpSpriteNum).rect[3], myBottom)
    updatestage
  end repeat
  
  -- here we handle what to do on  mouseUp
  pSelectedline = myLine
  
  
  --Exclude words or characters here If the text of the selected line of your popup are one of these words or ¬
phrases you can do special things. Of course you'll have to change these lines.
  
  myText = (pPopUpMember.text).line[pSelectedline]
  --put mytext
  
  case (TRUE) of
      
    (mytext contains "Don't select") : --selected line is excluded popup word
      reset me
      return
      
    (mytext.char[1] = "_") :--selected line is Seperator
      reset me
      return
      
    (mytext = "") : --selected line is EMPTY
      reset me
      return
  end case
  
  if pSelectedline > 0 then
    pNormalMember.text = myText
    pSelectedLine = myText
    
    -- set chosen line as first line of list
    
    if myline > 1 then
      newPopUpText = myText & RETURN & pPopUpMember.text.line[1..(myline - 1)]
    else
      newPopUpText = myText
    end if
    
    
    set curOrderPos = getAt(pPopUpListOrder, myline)
    deleteAt (pPopUpListOrder, myline)
    addAt (pPopUpListOrder, 1, curOrderPos)
    
    mylinecount = (pPopUpMember.text).line.count
    if mylinecount > 2 then
      lastline = mylinecount
      if lastline <> myline then
        newPopUpText = newPopUpText & RETURN & pPopUpMember.text.line[(myline + 1)..lastline]
      end if
    end if
    
    pPopUpMember.text = newPopUpText
    
    
    
    
    if pMouseUpCommand <> "" then
      -- execute chosen handler with two parameters
      do pMouseUpCommand & QUOTE & pSelectedLine & QUOTE && "," && curOrderPos
    end if
  end if
  
  
  reset me
  
end PopupMouseDown


--********************************************************

on mouseDown me
  PopupMouseDown me
  pass
end mouseDown


--********************************************************

on getPopUpActive me
  -- this handler can be called from outside to check which line was selected from the
  -- original order of the popUpmember
  
  return getAt(pPopUpListOrder, 1)
  
end getPopUpActive

--********************************************************

--This is an example of a movie script that works together with this behavior
--copy it to a moviescript

on handlePopUp selectedText, orderInList
  -- selectedText is a string with the currently chosen popup or a 0 if nothing is chosen
  -- orderInList is an integer that tells which line was selected from the original order of the popUpmember
  
  member("feedback").text = "You selected" & RETURN & string(selectedText) & RETURN & "This was line" && orderInList && "of the original popupmember."
  
end handlePopUp

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail