PopUp Menus with Fields

Date: Wed, 10 Jul 1996 09:29:34 +0100
From: daetwyler@aum.unibe.ch (Christof Daetwyler)
Subject: PopUp's: Script to shrink the width of fields according to the longest line
Hi there

I had to find a solution for hierarchical PopUps made by lingo only; so ShockWave-able.

Because the content of the popUp's is user-dependent (interactively) generated - I had to find a solution to shrink the with of the PopUp to the length of the longest line.


on PopUpMakeSmall MemberName, SpriteNum, ClickH, ClickV
  ----- By Christof Daetwyler 1996
  ----- daetwyler@aum.unibe.ch
  ----- http://www.iawf.unibe.ch/Mitarbeiter/CDA/index.htm

  -- This script makes a text-Field as width as the longest line
  -- and sets it at the location specified with ClickH, ClickV
  -- The TextField MemberName should have a line and a shadow of 1 Pixel

  set the puppet of sprite SpriteNum to true

  -- First, we have to find out, what line is the longest
  -- And how many characters are there until its end
  -- To use the Director 5 - lingo - Command
  put field memberName into inhalt
  put inhalt & return into inhaltX
  put 0 into X1
  put 0 into X2
  put 0 into X3
  repeat with t = 1 to the number of lines of inhalt
    put offset(numToChar(13),inhaltX) into X1
    delete char 1 to X1 of inhaltX
    put X1 + X2 into X2
    if X1 > X3 then
      put x1 into X3
      put X2 into CharNumLongestLine
      put X1 into CharCountLongestLine
    end if
  end repeat

  put inhalt into field MemberName

  put  ClickV into CV

  -- if the bottom of the PopUp-Field reaches the bottom of the stage, it has to be moved up
  -- probably you find a better solution - let me know
  put (the lineHeight of field MemberName) * (the number of lines of field MemberName) into HS
  set the height of sprite SpriteNum to HS
  if CV + HS > 480 then
    put 480 - HS into CV
  end if
  set the locV of sprite SpriteNum to CV
  set the locH of sprite SpriteNum to ClickH

  put the locH of sprite SpriteNum into x1

  -- first, the PopUp becomes as width as possible -> later we'll shrink it
  -- we use undocomented Lingo, because it's the only way to do it:
  set the rect of member memberName = rect(0,0,640,20)

  put string(charPosToLoc(member memberName,CharNumLongestLine)) into PointString
  put word 1 of PointString into PointString
  delete char 1 to 6 of PointString
  put Value(PointString) + x1 + 4 into x2
  put the locV of sprite SpriteNum - 2 into y1
  put the height of sprite SpriteNum + y1 + 6 into y2

  -- then, when we know how with the longest line is, we shrink to that rects:
  set the rect of member memberName = rect(x1,y1,x2,y2)

end


http://www.iawf.unibe.ch/aum/index.htm
       _?_       Christof Daetwyler MD
      /_ _\      Dept. for Education Media AUM
     [\O-O/]     AUM - IAWF, University of Berne
      \_-_/      Inselspital 38
      _| |_      CH - 3010 Bern
     / \_/ \     Tel: +41 31 632 25 12
 __oOOO___OOOo__ Fax: +41 31 381 93 22
http://www.iawf.unibe.ch/Mitarbeiter/CDA/C_Daetwyler_HomePage.htm