-- PALETTE CHIP -- -- -- © May 2001, James Newton -- -- This behavior is intended for use in conjunction with the -- "Palette.dir" movie. -- PROPERTY DECLARATIONS -- property spriteNum -- author-defined parameters property colorObject property callHandler property callObject -- property mySprite -- SPRITE EVENT -- on beginSprite(me) mySprite = sprite(spriteNum) mySprite.member.pattern = 15 mySprite.lineSize = 1 mySprite.color = rgb(0, 0, 0) -- Convert callObject to a symbol callObjects = me.getLocalizedString(#callObjects, FALSE) callObject = callObjects.getOne(callObject) -- Inform callObject of the initial color me.selectColor(colorObject) end beginSprite -- EVENT HANDLER -- on mouseDown(me) me.openPalette() end mouseDown -- PUBLIC METHODS -- on getReference(me, ID, returnList) ---------------------------------- -- Returns a pointer to this behavior instance or updates returnList -------------------------------------------------------------------- return me.provideData(#instance, ID, returnList) end getReference on getValue(me, ID, returnList) -------------------------------------- -- Returns the value of or updates returnList -------------------------------------------------------------------- return me.provideData(#value, ID, returnList) end getValue on updateColor(me, whichColor) --------------------------------------- -- Sent by updateSelection() handler in Palette.dir movie -- -- ACTION: sets the color of this sprite temporarily when the mouse -- is moved over a new color chip -------------------------------------------------------------------- if ilk(whichColor) = #color then mySprite.bgColor = whichColor end if end updateColor on selectColor(me, whichColor) --------------------------------------- -- Sent by makeSelection() handler in Palette.dir movie -- -- ACTION: sets the color of this sprite permanently when the user -- chooses a color or closes the Palette without making a selection. -------------------------------------------------------------------- if ilk(whichColor) = #color then colorObject = whichColor else -- No new selection was made end if mySprite.bgColor = colorObject -- Call the appropriate handler if symbolP(callHandler) then case callObject of #movie: sendSprite(0, callHandler, colorObject) #sprite: call(callHandler, mySprite.scriptInstanceList, colorObject) #sendAllSprites: sendAllSprites(callHandler, colorObject) #actorList: call(callHandler, the actorList, colorObject) end case end if end selectColor -- PRIVATE METHODS -- on openPalette(me) paletteWindow = window("Palette") paletteWindow.fileName = "Palette.dir" -- Convert to screen coordinates windowRect = paletteWindow.sourceRect stageRect = (the activeWindow).rect adjustH = stageRect.left + mySprite.right adjustV = stageRect.top + mySprite.top - 14 windowRect = windowRect.offset(adjustH, adjustV) paletteWindow.rect = windowRect dataList = [ \ #color: colorObject, \ #update: #updateColor, \ #select: #selectColor, \ #object: me \ ] tell paletteWindow setColorAndCallBack(dataList) end tell open paletteWindow end openPalette -- External calls on provideData(me, dataType, ID, listOrInteger) ---------------------- -- Called by getReference() -- -- PARAMETERS: -- could be #instance | #value -- may be a symbol or a list -- may be a list, an integer value or -- -- RETURNS: a pointer to this behavior instance or the value -- of this slider -------------------------------------------------------------------- case ilk(ID)of #symbol: -- use ID to filter for this behavior if ID <> callHandler then exit end if #list, #propList: listOrInteger = ID end case case dataType of #instance: data = me #value: data = colorObject otherwise: exit end case case ilk(listOrInteger) of #list: listOrInteger.append(data) #propList: listOrInteger.addProp(spriteNum, data) otherwise: listOrInteger = data end case return listOrInteger end provideData -- UTILITY HANDLERS -- on getLocalizedString(me, stringSymbol, asLinearList) ---------------- -- Called by getPropertyDescriptionList() and initialize() -- -- PARAMETERS: -- should be a symbol -- may be TRUE when this handler is called by -- getPropertyDescriptionList() -- -- RETURNS: a localized string defined by -- -- NOTE: Storing all strings in one place makes it easy to -- localize the behavior. -- -- The getPropertyDescriptionList() handler may require a list of -- strings. These may need to be converted to a language-neutral -- #symbol when the behavior is used. In this case, this handler -- can return a property list where the properties are symbols and -- the values are localized strings. The getPD() handler can -- specify that this list be converted to a linear list for display, -- by setting to TRUE. The initialize() handler, -- called on beginSprite, can recuperate the full property list and -- use the following code to convert the appropriate string to a -- symbol: -- -- propertyList = me.getLocalizedString(#propList, FALSE) -- getPDLValue = propertyList.getOne(getPDLValue) -------------------------------------------------------------------- case stringSymbol of #defaultColor: localizedString = "Default color" #callHandler: localizedString = "Handler to call when a selection is made" #defaultHandler: localizedString = #setColor #callObject: localizedString = "This handler is located" #callObjects: localizedString = [ \ #movie: "in a Movie Script", \ #sprite: "in another behavior on this sprite", \ #sendAllSprites: "in behaviors on other sprites", \ #actorList: "in an instance on the actorList" \ ] otherwise: -- Unexpected value localizedString = string(stringSymbol) end case if ilk(localizedString, #propList) then if asLinearList then -- Convert a property list to a linear list for getPDL() temp = localizedString localizedString = [] counter = temp.count repeat with i = 1 to counter localizedString[i] = temp[i] end repeat end if end if return localizedString end getLocalizedString -- BEHAVIOR DESCRIPTION AND PARAMETERS -- on isOKToAttach(me, spriteType, spriteNumber) -- Allow only filled shapes if spriteType = #graphic then theMember = sprite(spriteNumber).member if theMember.type = #shape then if theMember.shapeType <> #line then return theMember.filled end if end if end if return FALSE end isOKToAttach on getPropertyDescriptionList(me) propertiesList = [:] callObjects = me.getLocalizedString(#callObjects, TRUE) propertiesList[ \ #colorObject] = [ \ #comment: me.getLocalizedString(#defaultColor), \ #format: #color, \ #default: rgb(255, 255, 255) \ ] propertiesList[ \ #callHandler] = [ \ #comment: me.getLocalizedString(#callHandler), \ #format: #symbol, \ #default: me.getLocalizedString(#defaultHandler) \ ] propertiesList[ \ #callObject] = [ \ #comment: me.getLocalizedString(#callObject), \ #format: #string, \ #range: callObjects, \ #default: callObjects[3] \ ] return propertiesList end getPropertyDescriptionList on getBehaviorTooltip(me) return \ "Use with a filled shape member."&RETURN&RETURN&\ "Acts as a color chip in conjunction"&RETURN&\ "with the Palette movie in a window." end getBehaviorTooltip on getBehaviorDescription(me) return \ "PALETTE CHIP"&RETURN&RETURN&\ "Use with a filled shape member. Acts as a color chip in conjunction with the Palette movie in a window."&RETURN&RETURN&\ "PARAMETERS:"&RETURN&\ " * Default color"&RETURN&\ " * Handler to call when a color is chosen"&RETURN&\ " * Object where this handler is located" end getBehaviorTooltip