home *** CD-ROM | disk | FTP | other *** search
/ Knitting Made Easy / Knitting.iso / App / Patterns.dxr / behaviors_161_scrollbar.ls < prev    next >
Encoding:
Text File  |  2002-04-18  |  3.2 KB  |  116 lines

  1. property extentSprite, thumbheight, travelrange, position, offset, tracking, dynamic, proportional, fieldNum, totalHeight, fieldHeight, fieldMem
  2.  
  3. on getPropertyDescriptionList
  4.   description = [:]
  5.   addProp(description, #dynamic, [#default: 1, #format: #boolean, #comment: "Dynamic:"])
  6.   addProp(description, #fieldNum, [#default: the currentSpriteNum - 3, #format: #integer, #comment: "Scroll which sprite:"])
  7.   addProp(description, #extentSprite, [#default: the currentSpriteNum - 2, #format: #integer, #comment: "Slider Constraint Sprite:"])
  8.   return description
  9. end
  10.  
  11. on getBehaviorDescription
  12.   return "Vertical Multiline Textfield Scrollbar"
  13. end
  14.  
  15. on beginSprite me
  16.   fnum = me.fieldNum
  17.   fmember = the memberNum of sprite 8
  18.   me.fieldMem = fmember
  19.   viewable = 1.0
  20.   me.totalHeight = float(member(fmember).rect.bottom)
  21.   me.fieldHeight = float(the bottom of sprite fnum - the top of sprite fnum)
  22.   viewable = me.fieldHeight / me.totalHeight
  23.   puppetSprite(me.spriteNum, 1)
  24.   barheight = the bottom of sprite me.extentSprite - the top of sprite me.extentSprite
  25.   me.thumbheight = the height of sprite me.spriteNum
  26.   me.travelrange = barheight - thumbheight
  27.   me.tracking = 0
  28.   me.position = 0.0
  29.   positionThumb(me)
  30. end
  31.  
  32. on getAssocMembers
  33.   myPropList = []
  34.   return myPropList
  35. end
  36.  
  37. on endSprite me
  38.   puppetSprite(me.spriteNum, 0)
  39. end
  40.  
  41. on positionThumb me
  42.   topT = (me.position * me.travelrange) + the top of sprite me.extentSprite
  43.   snum = me.spriteNum
  44.   Trect = rect(the left of sprite snum, topT, the right of sprite snum, topT + me.thumbheight)
  45.   set the rect of sprite snum to Trect
  46. end
  47.  
  48. on scrollText me
  49.   member(me.fieldMem).scrollTop = me.position * (me.totalHeight - (me.fieldHeight / 16))
  50. end
  51.  
  52. on prepareFrame me
  53.   if me.tracking then
  54.     thumb = me.spriteNum
  55.     extent = me.extentSprite
  56.     v = the mouseV - me.offset
  57.     if v < the top of sprite extent then
  58.       v = the top of sprite extent
  59.     end if
  60.     if v > (the bottom of sprite extent - me.thumbheight) then
  61.       v = the bottom of sprite extent - me.thumbheight
  62.     end if
  63.     me.position = float(v - the top of sprite extent) / float(me.travelrange)
  64.     positionThumb(me)
  65.     if me.dynamic then
  66.       scrollText(me)
  67.     end if
  68.   end if
  69. end
  70.  
  71. on mouseDown me
  72.   me.tracking = 1
  73.   me.offset = the mouseV - the top of sprite me.spriteNum
  74. end
  75.  
  76. on mouseUp me
  77.   if me.dynamic = 0 then
  78.     scrollText(me)
  79.   end if
  80.   me.tracking = 0
  81. end
  82.  
  83. on mouseUpOutSide me
  84.   if me.dynamic = 0 then
  85.     scrollText(me)
  86.   end if
  87.   me.tracking = 0
  88. end
  89.  
  90. on scroll_a_line me, amount
  91.   member(me.fieldMem).scrollTop = me.position * me.totalHeight
  92.   change_amount = float(amount) * (float(the textHeight of member the fieldMem of me) / float(me.totalHeight - me.fieldHeight))
  93.   me.position = me.position + change_amount
  94.   if me.position < 0.0 then
  95.     me.position = 0.0
  96.   end if
  97.   if me.position > 1.0 then
  98.     me.position = 1.0
  99.   end if
  100.   positionThumb(me)
  101. end
  102.  
  103. on scroll_a_Top me, amount
  104.   extent = me.extentSprite
  105.   (the member of sprite 2).scrollTop = amount
  106.   change_amount = float(amount * travelrange) / float(me.totalHeight)
  107.   me.position = float(change_amount) / float(me.travelrange)
  108.   if me.position < 0.0 then
  109.     me.position = 0.0
  110.   end if
  111.   if me.position > 1.0 then
  112.     me.position = 1.0
  113.   end if
  114.   positionThumb(me)
  115. end
  116.