-- LAYOUT MANAGER -- -- Parent Script -- -- © April 2004 - April 2006, OpenSpark Interactive Ltd -- -- ---------------------------------------------------------------------- -- On startUp, a global instance of this script determines the -- dimensions of the user's largest monitor and resizes the movie to -- fit. The movie is played in a window, so if there are additional -- monitors, parts of the window frame may be visible in those -- monitors. -- -- As the user navigates to different markers, the behaviors at those -- markers ask this instance for information on how to place -- themselves correctly. -- -- A maximum movie size of 1280 x 1024 pixels is assumed. If the -- monitor is bigger than this, then the movie will be centered on the -- screen. ---------------------------------------------------------------------- -- PROPERTY DECLARATIONS -- property pSourceRect -- property pDrawRect -- -- CONSTRUCTOR METHOD -- on new(me) ----------------------------------------------------------- -- ACTION: Determines the source and target rects to use for this -- movie in order to display it at the best scale for the -- current monitor. -------------------------------------------------------------------- me.mInitialize() return me end new -- PUBLIC METHODS -- on GetScaledRect(me, aSprite) ---------------------------------------- -- SOURCE: Called by the beginSprite() handler of the Map To Monitor -- behavior on sprites with a fixed size and position -- INPUT: may be a sprite reference or the rect of the -- sprite -- OUTPUT: Returns the rect of the sprite relative to the current -- movie size -------------------------------------------------------------------- case ilk(aSprite) of #sprite: vRect = aSprite.rect #rect: vRect = aSprite otherwise: exit end case vRect = vRect.map(pSourceRect, pDrawRect) return vRect end GetScaledRect -- "PRIVATE" METHODS -- on mInitialize(me) --------------------------------------------------- -- ACTION: Determines the source and target rects to use for this -- movie in order to display it at the best scale for the -- current monitor. -------------------------------------------------------------------- vScreenRect = (the stage).sourceRect pDrawRect = me.mSetScreenRect(vScreenRect) pSourceRect = vScreenRect.offset(-vScreenRect.left, -vScreenRect.top) end mInitialize on mSetScreenRect(me, aSourceRect) ----------------------------------- -- SOURCE: Called by mInitialize() -- INPUT: is the initial rect of the stage: -- rect(0, 0, 1280, 1024) -- ACTION: Calculates the largest rect with a width less than or -- equal to the default windowWidth, and centers it on the -- largest available monitor. -- EFFECT: Sets pPreferences[#windowSize] and [#imageRect] -- OUTPUT: Returns the width of the application window -------------------------------------------------------------------- vMaxWidth = aSourceRect.width vMaxHeight = aSourceRect.height vRatio = vMaxHeight / float(vMaxWidth) tScreen = 0 tScale = 0 tBestWidth = 0 tBestHeight = 0 tScreenRects = the deskTopRectList tCount = tScreenRects.count repeat with i = 1 to tCount tScreenRect = tScreenRects[i] tWidth = tScreenRect.width tHeight = tScreenRect.height if the runMode = "Author" then if i = 1 then -- Allow space at the top of the screen for menu and title bars tHeight = tHeight - 61 -- 75 -- end if end if -- Find the biggest integer rect of the given ratio that can fit tScaleHeight = tWidth * vRatio if tHeight < tScaleHeight then tWidth = bitXor(tHeight / vRatio, 0) else tHeight = bitXor(tScaleHeight, 0) end if if tWidth < vMaxWidth then -- This screen is not wide enough, but it might be the biggest if tBestWidth < tWidth then -- This screen is wider than any previous one. Remember it. tBestWidth = tWidth tBestHeight = tHeight tScreen = i end if next repeat else if tHeight < vMaxHeight then -- This screen is too low to give a bigger rect than earlier next repeat end if -- We've found a monitor that the maximum size can fit on exit repeat end repeat if i > tCount then -- None of the monitors is big enough. Use the best. tScreenRect = tScreenRects[tScreen] tWidth = tBestWidth tHeight = tBestHeight else -- tScreenRect, tWidth and tHeight are already correctly set tWidth = min(tWidth, vMaxWidth) tHeight = min(tHeight, vMaxHeight) end if -- Determine the drawRect of the application window vStageRect = rect(0, 0, tWidth, tHeight) -- Set the screen rect of the application window, so it is centred tLeft = tScreenRect.left + (tScreenRect.width - tWidth) / 2 tTop = tScreenRect.top + (tScreenRect.height - tHeight) / 2 tWindowRect = vStageRect.offset(tLeft, tTop) (the activeWindow).rect = tWindowRect return vStageRect end mSetScreenRect