-- PLATFORM TWEAK -- -- -- © June 2001, James Newton -- -- -- 056010 JN: Correct mGetPlatform() for Director 8.5 -- ---------------------------------------------------------------------- -- Attach this behavior to any graphic sprite to optimize the position -- and display of the on both platforms. ---------------------------------------------------------------------- -- PROPERTY DECLARATIONS -- property spriteNum -- number of current sprite -- author-defined parameters property tweakPlatform property left property right property top property bottom property font property fontSize -- private properties property pSprite -- sprite(spriteNum) property pMember -- the member of the current sprite property pType -- the type of pMember property pRect -- original rect of the sprite -- SPRITE EVENT -- on beginSprite(me) if me.mGetPlatform() = tweakPlatform then me.mInitialize() end if end beginSprite on endSprite(me) if me.mGetPlatform() = tweakPlatform then me.mResetRect() end if end endSprite -- PRIVATE METHODS -- on mInitialize(me) --------------------------------------------------- -- SENT BY beginSprite() -- ACTION: sets the rect, font and fontSize of the sprite -------------------------------------------------------------------- pSprite = sprite(me.spriteNum) pMember = pSprite.member pType = pMember.type pRect = pSprite.rect tRect = pRect + [left, top, right, bottom] -- For field and text members, the rect of the member itself needs -- to be changed case pType of #text: pMember.width = tRect.width pMember.height = tRect.height pSprite.loc = point(tRect.left, tRect.top) #field: pMember.rect = tRect pSprite.loc = point(tRect.left, tRect.top) otherwise pSprite.rect = tRect end case if not voidP(font) then case pType of #button, #field, #text: -- Change the font of the member pMember.font = font pMember.fontSize = fontSize otherwise: -- Change the font of the OSControl sprite pSprite.font = font case font of "SystemLarge", "SystemSmall": -- use default font size otherwise pSprite.fontSize = fontSize end case end case end if end mInitialize on mResetRect(me) ---------------------------------------------------- -- SENT BY endSprite() -- ACTION: resets the rect of field or text members -------------------------------------------------------------------- case pType of #text: pMember.width = pRect.width pMember.height = pRect.height #field: pMember.rect = pRect end case end mInitialize -- UTILITIES -- on mGetCurrentSpriteData(me, aSprite, aPropertyName) ------------------ -- Called by getPropertyDescriptionList() -- -- RETURNS: the value of for this behavior in the -- scriptList for -------------------------------------------------------------------- -- Determine the name of this behavior scriptName = string(me) delete scriptName.word[1] scriptName = value(scriptName) -- Identify the behavior initialisers for this behavior behaviorList = aSprite.scriptList i = behaviorList.count() repeat while i behaviorData = behaviorList[i] behaviorMember = behaviorData[1] if behaviorMember.name = scriptName then -- This is the current behavior behaviorData = value(behaviorData[2]) if ilk(behaviorData) = #propList then return behaviorData[aPropertyName] end if end if i = i - 1 end repeat end mGetCurrentSpriteData on mGetFontList(me, aPlatform) --------------------------------------- -- -- -- RETURNS: a list of fonts which should be installed on all -- computers on the chosen platform. -------------------------------------------------------------------- case aPlatform of "Macintosh": -- Show Macintosh fonts first tPlatformFonts = [ \ "Charcoal", \ "Chicago", \ "Courier", \ "Geneva", \ "Helvetica", \ "Monaco", \ "New York", \ "Symbol", \ "Times", \ "Palatino", \ "Arial", \ "Courier New", \ "MS Serif", \ "MS Sans Serif", \ "System", \ "Terminal", \ "Times New Roman" \ ] "Windows": -- Show Windows fonts first tPlatformFonts = [ \ "Arial", \ "Courier", \ "Courier New", \ "MS Serif", \ "MS Sans Serif", \ "Symbol", \ "System", \ "Terminal", \ "Times New Roman",\ "Charcoal", \ "Chicago", \ "Geneva", \ "Helvetica", \ "Monaco", \ "New York", \ "Times", \ "Palatino" \ ] otherwise: tPlatformFonts = [""] end case return tPlatformFonts end mGetFontList on mGetPlatform(me) if the platform starts "Windows" then return "Windows" else tVersion = the environment[#osVersion] if voidP(tVersion) then -- Running in Director 8.0 or earlier, so must be Classic return "Mac Classic" else -- Check for Mac OS X or greater tVersion = char 1 to 3 of word 3 of tVersion tVersion = value(tVersion) if tVersion < 10 then return "Mac Classic" else return "Mac OS X" end if end if end if end mGetPlatform -- BEHAVIOR DESCRIPTION AND PARAMETERS -- on isOKToAttach(me, aSpriteType, aSpriteNumber) return aSpriteType = #graphic end isOKToAttach on getPropertyDescriptionList(me) tProperties = [:] tProperties[ \ #tweakPlatform] = [ \ #comment: "Adjust display on", \ #format: #string, \ #range: ["Mac Classic", "Mac OS X", "Windows"], \ #default: me.mGetPlatform() \ ] tProperties[ \ #left] = [ \ #comment: "Adjust left edge:", \ #format: # integer, \ #range: [#min: -32, #max: 32], \ #default: 0 \ ] tProperties[ \ #right] = [ \ #comment: "Adjust right edge:", \ #format: #integer, \ #range: [#min: -32, #max: 32], \ #default: 0 \ ] tProperties[ \ #top] = [ \ #comment: "Adjust top edge:", \ #format: #integer, \ #range: [#min: -32, #max: 32], \ #default: 0 \ ] tProperties[ \ #bottom] = [ \ #comment: "Adjust bottom edge:", \ #format: #integer, \ #range: [#min: -32, #max: 32], \ #default: 0 \ ] if the currentSpriteNum then tSprite = sprite(the currentSpriteNum) tMember = tSprite.member tType = tMember.type case tType of -- The following member types support text #field, #button, #text, \ #OSBox, #OSStaticText, \ #OSMenu, #OSPopupMenu, \ #OSBevelButton, #OSCheckbutton, #OSPushButton, #OSRadioButton: -- Get list of safe fonts tPlatform = me.mGetCurrentSpriteData(tSprite, #tweakPlatform) tFontList = me.mGetFontList(tPlatform) tCurrentFont = mGetCurrentSpriteData(me, tSprite, #fontName) if not voidP(tCurrentFont) then tFontList.deleteOne(tCurrentFont) tFontList.addAt(1, tCurrentFont) end if case tType of #field, #button, #text: --members can't use "SystemXxxx" otherwise: -- Show "System" fonts at or near the top of the list tFontList.addAt(1, "SystemSmall") tFontList.addAt(1, "SystemLarge") end case tDefaultSize = tMember.fontSize tProperties[ \ #font] = [ \ #comment: "Font to use:", \ #format: #string, \ #range: tFontList, \ #default: tFontList[1] \ ] tProperties[ \ #fontSize] = [ \ #comment: "Font size:", \ #format: #integer, \ #range: [#min: 0, #max: 128], \ #default: tDefaultSize \ ] end case end if return tProperties end getPropertyDescriptionList on getBehaviorTooltip me return \ "Attach this behavior to any graphic sprite"&RETURN&\ "to optimize the position and display of the"&RETURN&\ "on both platforms." end getBehaviorTooltip on getBehaviorDescription me return \ "PLATFORM TWEAK"&RETURN&RETURN&\ "Attach this behavior to any graphic sprite to optimize the position and display of the on both platforms."&RETURN&RETURN&\ "NOTE: Use a font size of zero with systemLarge and systemSmall fonts."&RETURN&RETURN&\ "PARAMETERS:"&RETURN&\ " * Adjust display on which platform? (Macintosh | Windows)"&RETURN&\ " * Adjust left, right, top and bottom of sprite"&RETURN&\ " * Adjust font and fontSize (certain member types only)" end getBehaviorDescription