home *** CD-ROM | disk | FTP | other *** search
/ Comic Book Maker: The Smurfs / COMIC.iso / mac / data_m / dialog / 00032_balloonFieldBhvr.ls < prev    next >
Encoding:
Text File  |  1999-07-07  |  6.1 KB  |  166 lines

  1. property myMemb, mySprite, initialLocV, hOffset, lneHite, offsetLoc, lineMax, platformOffset
  2. global gObj3, gPlatForm
  3.  
  4. on beginSprite me
  5.   set myMemb to the memberNum of sprite the currentSpriteNum
  6.   set mySprite to the currentSpriteNum
  7.   if voidp(initialLocV) then
  8.     set initialLocV to the locV of sprite mySprite
  9.   end if
  10.   set the locV of sprite mySprite to initialLocV - the vLocOffset of gObj3
  11.   set offsetLoc to the loc of sprite the currentSpriteNum
  12.   set lneHite to the textHeight of member myMemb
  13.   set hOffset to lneHite / 3
  14. end
  15.  
  16. on mouseEnter me
  17.   cursor(1)
  18. end
  19.  
  20. on mouseLeave me
  21.   cursor(0)
  22. end
  23.  
  24. on mouseDown me
  25.   clearSelection(me, 0)
  26.   set theTxt to the text of member myMemb
  27.   set platformOffset to lneHite * not gPlatForm
  28.   set dragDist to 0
  29.   set lineMax to the number of lines in the text of member myMemb
  30.   set startLine to min(lineMax, ((the locV of the clickLoc - the locV of sprite mySprite) / lneHite) + 1)
  31.   if startLine = 1 then
  32.     set charMin to 1
  33.   else
  34.     set charMin to length(line 1 to startLine - 1 of theTxt) + 2
  35.   end if
  36.   set startChar to max(charMin, locToCharPos(member myMemb, the clickLoc - offsetLoc + [hOffset, 0]))
  37.   set oldLine to startLine
  38.   set oldLoc to startChar
  39.   set xtraOffset to platformOffset + the lineHiteDiff of gObj3
  40.   set theRect to rect(charPosToLoc(member myMemb, startChar) + offsetLoc - [0, lneHite], charPosToLoc(member myMemb, startChar) + offsetLoc)
  41.   if the width of theRect < 2 then
  42.     setAt(theRect, 3, getAt(theRect, 1) - 1)
  43.   end if
  44.   set the rect of sprite (startLine + 20) to theRect + [0, xtraOffset, 0, xtraOffset]
  45.   set selectionRange to [startChar, startChar]
  46.   updateStage()
  47.   repeat while the mouseDown
  48.     set newLoc to point(the mouseH, the mouseV)
  49.     if not (newLoc = oldLoc) then
  50.       if dragDist < hOffset then
  51.         set dragDist to max(max(the clickLoc - newLoc), max(newLoc - the clickLoc))
  52.         next repeat
  53.       end if
  54.       set cChar to locToCharPos(member myMemb, newLoc - offsetLoc + [hOffset, 0])
  55.       set newLine to min(lineMax, ((the locV of newLoc - the locV of sprite mySprite) / lneHite) + 1)
  56.       set lineRange to [startLine, newLine]
  57.       sort(lineRange)
  58.       set selectBack to cChar < startChar
  59.       set dOffset to 0
  60.       set selectionRange to [3333, 0]
  61.       if newLine = 1 then
  62.         set charMin to 1
  63.       else
  64.         set charMin to length(line 1 to newLine - 1 of theTxt) + 2
  65.       end if
  66.       repeat with i = 1 to lineMax
  67.         if (i < getAt(lineRange, 1)) or (i > getAt(lineRange, 2)) then
  68.           set the locH of sprite (i + 20) to 9000
  69.           next repeat
  70.         end if
  71.         set xtraOffset to platformOffset + the lineHiteDiff of gObj3
  72.         if i = newLine then
  73.           if i = startLine then
  74.             set charTotal1 to startChar
  75.           else
  76.             if not selectBack then
  77.               set charTotal1 to length(line 1 to i - 1 of theTxt) + 2
  78.             else
  79.               set charTotal1 to length(line 1 to i of theTxt) + 1
  80.             end if
  81.           end if
  82.           set charTotal2 to max(cChar, charMin)
  83.         else
  84.           if i = startLine then
  85.             set charTotal1 to startChar
  86.             if selectBack then
  87.               set dOffset to 1
  88.             end if
  89.           else
  90.             if i = 1 then
  91.               set charTotal1 to 1
  92.             else
  93.               set charTotal1 to length(line 1 to i - 1 of theTxt) + 2
  94.             end if
  95.           end if
  96.           set charTotal2 to length(line 1 to i - dOffset of theTxt) + 1 + dOffset
  97.         end if
  98.         setAt(selectionRange, 1, min(getAt(selectionRange, 1), charTotal1, charTotal2))
  99.         setAt(selectionRange, 2, max(getAt(selectionRange, 2), charTotal2, charTotal1))
  100.         set theRect to rect(charPosToLoc(member myMemb, charTotal1) + offsetLoc - [0, lneHite], charPosToLoc(member myMemb, charTotal2) + offsetLoc)
  101.         if the width of theRect < 2 then
  102.           setAt(theRect, 3, getAt(theRect, 1) - 1)
  103.         end if
  104.         set the rect of sprite (i + 20) to theRect + [0, xtraOffset, 0, xtraOffset]
  105.       end repeat
  106.       updateStage()
  107.       set oldLoc to newLoc
  108.     end if
  109.   end repeat
  110.   sort(selectionRange)
  111.   if getAt(selectionRange, 1) = getAt(selectionRange, 2) then
  112.     set singleSelection to 1
  113.     set the theSelection of gObj3 to [getAt(selectionRange, 1) - 1]
  114.     set the rect of sprite 20 to theRect + [0, xtraOffset, 0, xtraOffset]
  115.     clearSelection(me, 1)
  116.   else
  117.     set the theSelection of gObj3 to [getAt(selectionRange, 1), getAt(selectionRange, 2) - 1]
  118.   end if
  119.   set lineRange to [the number of lines in char 1 to getAt(the theSelection of gObj3, 1) of theTxt]
  120.   if not singleSelection then
  121.     add(lineRange, getAt(lineRange, 1) - 1 + the number of lines in char getAt(the theSelection of gObj3, 1) to getAt(the theSelection of gObj3, 2) of theTxt)
  122.   end if
  123.   repeat with i in the softReturnsList of gObj3
  124.     if i < getAt(lineRange, 1) then
  125.       setAt(the theSelection of gObj3, 1, getAt(the theSelection of gObj3, 1) - 1)
  126.     end if
  127.     if not singleSelection then
  128.       if i < getAt(lineRange, 2) then
  129.         setAt(the theSelection of gObj3, 2, getAt(the theSelection of gObj3, 2) - 1)
  130.       end if
  131.     end if
  132.   end repeat
  133. end
  134.  
  135. on clearSelection me, startFrom
  136.   repeat with i = startFrom to 7
  137.     set the locH of sprite (20 + i) to 9000
  138.   end repeat
  139.   updateStage()
  140. end
  141.  
  142. on updateInsertion me
  143.   set theTxt to the text of member myMemb
  144.   set charTotal1 to getAt(the theSelection of gObj3, 1)
  145.   set charTotal1 to charTotal1 + addAll(the softReturnsList of gObj3, charTotal1) + 1
  146.   set i to the number of lines in char 1 to charTotal1 - 1 of theTxt
  147.   set xtraOffset to 0
  148.   set hLoc to the locH of charPosToLoc(member myMemb, charTotal1) + the locH of offsetLoc
  149.   set vLoc to ((i - 1) * lneHite) + the locV of offsetLoc
  150.   if char charTotal1 - 1 of the cBalloonString of gObj3 = RETURN then
  151.     beep()
  152.   end if
  153.   set theRect to rect(hLoc, vLoc, hLoc - 1, vLoc + lneHite)
  154.   set the rect of sprite 20 to theRect + [0, xtraOffset, 0, xtraOffset]
  155.   updateStage()
  156. end
  157.  
  158. on addAll theList, max
  159.   repeat with i = 1 to count(theList)
  160.     if getPropAt(theList, i) < max then
  161.       set theValue to theValue + 1
  162.     end if
  163.   end repeat
  164.   return theValue
  165. end
  166.