Economy-x-Talk - Sample Scripts
Center Window to Screen 2
This function uses the window ID to avoid problems with duplicate window names and window names that are a number. I modified Uli's script to center the window, not center the topLeft of the window. (Mine adjusts the loc by half the height and width of the window.)
[It appears that the script doesn't work - MS]
-- Karl Peterson
function centerWindowOnScreenLoc winID
if winID is empty then put id of window (short name of this stack) into winID
-- Returns new loc of window centered on screen,
-- expressed in the local coordinates of the current
-- stack. Handles multiple monitors.
-- First we calculate a global loc (uses screen coordinates)
-- that centers the window on screen. Note the topLeft
-- of the window isn't centered, the entire window is centered.
-- collect info about screen...
put the screenRect into sRect
put (item 3 of sRect - item 1 of sRect) into sWidth
put (item 4 of sRect - item 2 of sRect) into sHeight
-- collect info about window...
put width of window id winID into wWidth
put height of window id winID into wHeight
-- calculate centerpoint of screen adjusted by
-- window's width and height
put (sWidth div 2) - (wWidth div 2) into X
put (sHeight div 2) - (wHeight div 2) into Y
-- To center the window as the movie XCMD does,
-- we must adjust our calculation slightly to account
-- for height of menubar
add (height of menubar div 2) to Y
-- Next convert global loc to the local coordinates
-- of the current stack.
add item 1 of sRect - item 1 of rect of cd window to X
add item 2 of sRect - item 2 of rect of cd window to Y
-- Finally, return the new loc
return X & "," & Y
end centerWindowOnScreenLoc
on centerWindowNow
set the loc of window (short name of this stack) to ¬
centerWindowOnScreenLoc()
end centerWindowNow
Keep this extensive resource of tutorials and samples on-line! Support RunRev.info!
| Yes, this script is useful. I make a donation and choose freely how much I want to donate on-line (PayPal). Click here if you want to make a donation in dollars. | This script has not (completely) solved my problem and I want Economy-x-Talk to take care of it. Let me contact you. |
Copyright©2002-2008 by Mark Schonewille, Nijmegen, the Netherlands. This web site is in no way affiliated with Runtime Revolution Ltd., but we do recommend the Revolution development platform.