I needed to write some code to convert a bunch of cards down from Retina size to Non-Retina. There was a lot of trial and error and I thought I'd save everyone else the time. I tend to create a separate card for my backup & dev scripts for each app. So I create a button on it that runs this code. It will ask what card and what scale and a suffix to add to the card name. I default to 3GS as the suffix.
Code: Select all
on duplicateCardScaled
// I've not bothered to code in any scalers for gradients
// Also can't affect the Geometry Object Limits
-- Ask questions
ask "Which Card?"
if the result is "Cancel" or it is "" then
exit to top
end if
if not exists(card it) then
exit to top
end if
put it into tCardToCopy
ask "New Name:" with tCardToCopy & "3GS"
if the result is "Cancel" or it is "" then
exit to top
end if
if exists(card it) then
answer "That name already exists"
exit to top
end if
put it into tCardNewName
ask "Scale Factor (%)" with 50
if the result is "Cancel" or it is "" then
exit to top
end if
put it /100 into tCardScaleFactor
-- Make a dupe of the card
copy card tCardToCopy to this stack
set the name of it to tCardNewName
-- Adjust the Cards Settings
set the textSize of it to round(the textSize of it * tCardScaleFactor)
if the showBorder of it is true then
set the borderWidth of it to round(the borderWidth of it /tCardScaleFactor)
end if
-- Find any BackgroundBehavior groups (that will need unlinking)
repeat with tCtrlNum = 1 to the number of controls in card tCardNewName
if word 1 of the name of control tCtrlNum of card tCardNewName is "group" then
if the backgroundBehavior of control tCtrlNum of card tCardNewName is true then
put the long id of control tCtrlNum of card tCardNewName & cr into tBGobjects
copy control tCtrlNum of card tCardNewName to card tCardNewName
set the backgroundBehavior of it to false
end if
end if
end repeat
-- remove the BGBehavior Groups from the copied card
repeat for each line tBGBobject in tBGobjects
if tBGBobject is not empty then
remove tBGBobject from card tCardNewName
end if
end repeat
-- Find the long ids of each object in the new card
repeat with tCtrlNum = 1 to the number of controls in card tCardNewName
put the long id of control tCtrlNum of card tCardNewName &tab& the loc of control tCtrlNum of card tCardNewName into line tCtrlNum of tObjects
end repeat
-- Scale them all down
set the itemDel to tab
repeat for each line tObjectAndLoc in tObjects
scaleObject (item 1 of tObjectAndLoc),(item 2 of tObjectAndLoc), tCardScaleFactor
end repeat
end duplicateCardScaled
on scaleObject pObject pOrigLoc pScaleFactor -- pObject MUST be the long name of the control
-- SIZE
set the width of pObject to round(the width of pObject * pScaleFactor)
set the height of pObject to round(the height of pObject * pScaleFactor)
-- SHADOW
if the dropShadow of pObject is true then
set the dropShadow["spread"] of pObject to round(the dropShadow["spread"] of pObject * pScaleFactor)
set the dropShadow["size"] of pObject to round(the dropShadow["size"] of pObject * pScaleFactor)
set the dropShadow["distance"] of pObject to round(the dropShadow["distance"] of pObject * pScaleFactor)
end if
if the innerShadow of pObject is true then
set the innerShadow["spread"] of pObject to round(the innerShadow["spread"] of pObject * pScaleFactor)
set the innerShadow["size"] of pObject to round(the innerShadow["size"] of pObject * pScaleFactor)
set the innerShadow["distance"] of pObject to round(the innerShadow["distance"] of pObject * pScaleFactor)
end if
-- GLOW
if the innerGlow of pObject is true then
set the innerGlow["spread"] of pObject to round(the innerGlow["spread"] of pObject * pScaleFactor)
set the innerGlow["size"] of pObject to round(the innerGlow["size"] of pObject * pScaleFactor)
end if
if the outerGlow of pObject is true then
set the outerGlow["spread"] of pObject to round(the outerGlow["spread"] of pObject * pScaleFactor)
set the outerGlow["size"] of pObject to round(the outerGlow["size"] of pObject * pScaleFactor)
end if
-- GROUP
if (word 1 of the name of pObject) is "group" then
set the borderWidth of pObject to round(the borderWidth of pObject * pScaleFactor)
set the scrollbarWidth of pObject to round(the scrollbarWidth of pObject * pScaleFactor)
-- FIELD
else if (word 1 of the name of pObject) is "field" then
-- set the margins of pObject to round(the margins of pObject * pScaleFactor)
set the textSize of pObject to round(the textSize of pObject * pScaleFactor)
set the textHeight of pObject to round(the textHeight of pObject * pScaleFactor)
if the borderWidth of pObject > 1 then
set the borderWidth of pObject to round(the borderWidth of pObject * pScaleFactor)
end if
-- IMAGE
else if (word 1 of the name of pObject) is "image" then
set the borderWidth of pObject to round(the borderWidth of pObject * pScaleFactor)
-- GRAPHIC
else if (word 1 of the name of pObject) is "graphic" then
set the lineSize of pObject to round(the lineSize of pObject * pScaleFactor)
try
set the roundRadius of pObject to round(the roundRadius of pObject * pScaleFactor)
end try
-- BUTTON
else if (word 1 of the name of pObject) is "button" then
if the borderWidth of pObject > 1 then
set the borderWidth of pObject to round(the borderWidth of pObject * pScaleFactor)
end if
if the shadowOffset of pObject > 1 then
set the shadowOffset of pObject to round(the shadowOffset of pObject * pScaleFactor)
end if
-- SCROLLBAR
else if (word 1 of the name of pObject) is "scrollbar" then
-- Nothing
-- PLAYER
else if (word 1 of the name of pObject) is "player" then
-- Nothing
end if
set the loc of pObject to (round(item 1 of pOrigLoc * pScaleFactor)), (round(item 2 of pOrigLoc * pScaleFactor))
end scaleObject
All the best
Sean (Mr Pi)
Pi Digital