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
Check valid date
BorderPatch
cXtraWebBrowser
Back Button
Show Me the Movie
dmmMDB
cXtraPrinter
Using ActiveX
Sprite Blender - Time
3D Model
 

 

 

Behavior Slider behaviour v2.2

Added on 6/10/1999

 

Compatibilities:
behavior D6_5 Mac PC

This item has not yet been rated

Author: MarkHagers

Slider behavior

property backSprite, direction, Update , minimum, maximum, margin, cursorMember
property lowBorder, highBorder, scale, range, currentValue, start, lok, numberFormat, handlerName, backList

on getBehaviorDescription  
  return "Slider behaviour, by Mark Hagers." & return & "Version 2.2, december 10, 1997." & return & "© 1997 Mediaeval Multimedia" & return & "email: mark@mediaeval.nl" & return & "Additions: 12/10/97: fixed cursorlist to allow unnamed cursor members." & return & "12/10/97: bug fix, non-zero minimum values now work properly." & return & "Behaviour for a slider sprite. Does it all !!" & return & "This behaviour must be assigned to the moving part of the slider. The behaviour also needs a background sprite, the 'scale' of the slider." & return & "Parameters for this behaviour:" & return & " - Orientation: you can have a horizontal or a vertical slider." & return & " - Back sprite: Sprite number of the slider's background (scale)." & return & " - Margin: constrain movement to within this number of pixels away from the background borders" & return & "   just experiment and see what happens." & return & " - Numberformat: let the value controlled by the slider be an integer or a floating point value." & return & "   With numberFormat 'integer' the slider will snap to an integer value when it is updated." & return & " - Minimum and maximum slider values, these values display as floats in the parameter dialog," & return & "   regardless of the numberFormat setting." & return & "   The Minimum value can be higher than the Maximum value for a 'reversed' slider." & return & "   This feature should now work correctly as of version 2." & return & " - Callback handler: you can put any valid Lingo command or handler here," & return & "   it will be executed whenever the slider is updated (see 'Updating' below)," & return & "   the slider value will be passed as a parameter to the command," & return & "   try 'put' and look at the message box to experiment." & return & " - Updating: update slider value on mouseup only (when the slider is released) or continuous (while dragging the slider)." & return & "   Combining 'Continuous' with the numberFormat 'integer' will cause the slider to 'snap' to integer values."
end getBehaviorDescription

on getPropertyDescriptionList
  set description = [:]
  
  set directionDef = #Horizontal
  
  if the currentspritenum = 1 then
    alert "this behavior will not work on sprite channels below 2"
    exit
  else
    set backDef = max(1,the currentspritenum - 1)
    set backList = []
    repeat with i = 1 to backDef
      if the memberNum of sprite i > 0 then add backList,i
    end repeat
    if count(backList) > 0 then
      set backDef = getLast(backList)
    else set backList = [1]
    set cursorList = [#none]
    repeat with i = 1 to the number of members
      if the type of member i = #bitmap then
        if the depth of member i = 1 then
          if the name of member i <> "" then
            add cursorList, the name of member i
          else add cursorList, member i
        end if
      end if
    end repeat
    set cursDef = #none
  end if
  
  addProp description, #direction, ¬
            [#default:directionDef,#format:#symbol,#comment:"Orientation:",#range:[#Horizontal,#Vertical]]
  
  addProp description, #backSprite, ¬
            [#default:backDef,#format:#integer,#comment:"Back Sprite:",#range:backList]
  
  addProp description, #margin, ¬
            [#default:0,#format:#integer,#comment:"Margin:", #range:[#max:40,#min:-40]]
  
  addprop description, #cursorMember,  ¬
            [#default:cursDef,#format:#bitmap,#comment:"Cursor image:", #range:cursorList]
  
  addProp description, #numberFormat, ¬
            [#default:#integer,#format:#symbol,#comment:"Number format:",#range:[#integer,#float]]
  
  addprop description, #minimum,  ¬
            [#default:0,#format:#float,#comment:"Minimum Value:"]
  
  addprop description, #maximum,  ¬
            [#default:1,#format:#float,#comment:"Maximum Value:"]
  
  addprop description, #handlerName,  ¬
            [#default:"",#format:#string,#comment:"Callback handler:"]
  
  addprop description, #Update,  ¬
            [#default:#MouseUp,#format:#symbol,#comment:"Updating:",#range:[#Mouseup,#Continuous]]
  
  return description
end getPropertyDescriptionList

--------

on beginSprite me
  if the memberNum of sprite backSprite = 0 then
    alert "Behaviour 'Marks Slider' on sprite" && the spriteNum of me & ":" & return & return & "You need a background sprite in a lower channel number for this behaviour to work properly."
    exit
  end if
  case direction of
    #horizontal:
      set tempMargin = (the width of sprite (the spriteNum of me)) / 2  
      set tempMargin2 = (the width of sprite (the spriteNum of me)) - tempMargin
      set lowBorder = tempMargin2 + margin + the left of sprite backSprite
      set highBorder = - tempMargin - margin + the right of sprite backSprite
    #vertical:
      set tempMargin = (the height of sprite (the spriteNum of me)) / 2
      set tempMargin2 = (the height of sprite (the spriteNum of me)) - tempMargin
      set lowBorder = tempMargin + margin + the top of sprite backSprite
      set highBorder = - tempMargin2 - margin + the bottom of sprite backSprite
  end case
  set range = highBorder - lowBorder
  set scale = float(abs(maximum - minimum)) / float(range)  
  set lok = 0
  set start = 0
  set currentValue = minimum
  if numberFormat = #integer then
    showValue me, integer(currentValue)
  else
    showValue me, currentValue
  end if
  if not voidP(cursorMember) and cursorMember <> #none then setCursor me, true
  return me
end

on mouseDown me
  case direction of
    #horizontal:
      set lok = the locH of sprite (the SpriteNum of me)
      set start = the mouseH
    #vertical:
      set lok = the locV of sprite (the SpriteNum of me)
      set start = the mouseV
  end case
end mouseDown

on prepareFrame me
  if lok > 0 then
    case direction of
      #horizontal:
        set hor = the mouseH
        set screenVal = max(lowBorder,min(lok + hor - start,highBorder))  
        set the locH of sprite (the spriteNum of me) to screenVal
        if Update = #continuous then doUpdate me, screenVal - lowBorder
      #vertical:
        set ver = the mouseV
        set screenVal = max(lowBorder,min(lok + ver - start,highBorder))  
        set the locV of sprite (the spriteNum of me) to screenVal
        if Update = #continuous then doUpdate me, highBorder - screenVal
    end case
  end if
end exitFrame

on mouseUpOutside me
  endUpdate me
end mouseUpOutside

on mouseup me
  endUpdate me
end mouseup

on endUpdate me
  set lok = 0
  set start = 0
  case direction of
    #horizontal:
      doUpdate me, the locH of sprite (the spriteNum of me) - lowBorder
    #vertical:
      doUpdate me, highBorder - the locV of sprite (the spriteNum of me)
  end case
end endUpdate

on doUpdate me, scrvalue
  if minimum < maximum then
    set currentValue = minimum + scrvalue * scale
  else set currentValue = minimum - scrValue * scale
  if numberFormat = #integer then set currentValue = integer(currentValue)
  showValue me, currentValue
  if handlerName <> "" then do handlerName && currentValue
end

on showValue me, theVal
  if minimum < maximum then
    set scrValue = (theVal - minimum) / scale  
    case direction of
      #horizontal:
        set the locH of sprite (the SpriteNum of me) to lowBorder + scrValue
      #vertical:
        set the locV of sprite (the SpriteNum of me) to highBorder - scrValue  
    end case
  else
    set scrValue = (theVal - maximum) / scale
    case direction of
      #horizontal:
        set the locH of sprite (the SpriteNum of me) to highBorder - scrValue
      #vertical:
        set the locV of sprite (the SpriteNum of me) to lowBorder + scrValue
    end case
  end if
end showValue

on setCursor me, theVal
  if theVal then
    set theCurs = the number of member cursorMember
    set theMask = the number of member(the name of member cursorMember & ".mask")
    if theMask > 0 then
      set the cursor of sprite (the spriteNum of me) = list(theCurs, theMask)
    else set the cursor of sprite (the spriteNum of me) = list(theCurs)
  else set the cursor of sprite (the spriteNum of me) = 0
end

 


Contact

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

Send e-mail