Re: ScreenSaverView with multiple displays
Re: ScreenSaverView with multiple displays
- Subject: Re: ScreenSaverView with multiple displays
- From: "John C. Randolph" <email@hidden>
- Date: Thu, 27 Jan 2005 16:41:20 -0800
On Jan 27, 2005, at 9:06 AM, Douglas A. Welton wrote:
Patrick,
Are you comparing the NSRect passed to -initWithFrame: with your known
list
of screen frames? I haven't tried this myself, but it would make
sense that
the -initWithFrame: argument would match up.
This only helps if the screens are of different sizes.
Also, since all of the screen share the same Cartesian coordinates
system,
would it not be correct to assume that if your drawing coordinates are
not
found on the main screen (i.e., NSPointInRect() )that you must be
drawing on
one of the secondary screens?
Remember that a view (and a window, for that matter) has its own
coordinate space.
Patrick,
I think your best bet is to use [[self window] screen] to find out what
screen your view is drawing to.
-jcr
curiously,
douglas
on 1/26/05 11:46 PM, patrick at email@hidden wrote:
To follow up on the problem of screen savers and multiple screens, I'm
wondering if you or someone can help me wrap my head around something:
My screen saver is written such that I maintain state information
about where I am on the screen for the next iteration of
animateOneFrame(). I currently am only drawing to the main screen
(using the isMenuBarScreen() method you so kindly helped me with)
because I haven't figured out a good way to reliably tell to which
monitor I am drawing. Well, the current way with isMenuBarScreen works
great for two monitors, but not three or more. While it probably is
pretty uncommon for someone to have three or monitors, it bothers me
that I can't solve this problem for n number of monitors.
I would like to create a struct of some sort to store the state
information for each screen to be put into an array, indexed one for
each screen. While I can get an array of screens using [NSScreen
screens], and I [think] I can get the NSScreen by doing [[self window]
screen], should it work if I were to test for the current screen by
doing:
NSScreen *currentScreen = [[self window] screen];
NSArray *screens = [NSScreen screens];
int i;
int size = [screens size];
int currentScreenIndex = -1;
for (i = 0; i < size; i++)
{
if ((NSWindow)[screens objectAtIndex:i] == currentScreen))
{
currentScreenIndex = i;
}
}
// go on to get my state struct out of a array indexed one-for-one
with the [NSScreen screens] array...
Patrick
On Wed, 29 Dec 2004 16:19:02 -0800, Steve Christensen
<email@hidden> wrote:
How about something like this?
1. Add a BOOL _isMenuBarDisplay to your screensaver view class.
2. Override -initWithFrame: and -initWithFrame:isPreview:.
In each, call the super's method, then
if -isPreview, set _isMenuBarDisplay to true, else check if
frameRect has
the same bounds as the main screen and set _isMenuBarDisplay
accordingly.
3. Override -animateOneFrame (and -drawRect: ?), check
_isMenuBarDisplay and
do the appropriate thing.
This assumes that the view bounds are in global coordinates and are
aligned with individual screens, but this is just a guess since I
haven't yet written a screensaver. :-) If it works, it should get you
away from messy issues like the order in which the views are
initialized.
As for counting the number of screens, how about:
unsigned int screenCount = [[NSScreen screens] count];
And finding the menu bar screen:
- (BOOL) isMenuBarScreen
{
NSArray* listOfScreens = [NSScreen screens];
if ((listOfScreens != nil) && ([listOfScreens count] > 0))
return NSEqualRects([self frame], [listOfScreens
objectAtIndex:0]);
return false;
}
steve
On Dec 29, 2004, at 3:09 PM, patrick wrote:
I'm creating a screensaver, and I would like to be able to draw
something different on displays other than the primary. Through
trial
and error, I've learned that initWithFrame() gets called for each
display, although it doesn't seem like any useful information is
passed into initWithFrame() or animateOneFrame() to help the
developer
know which display is being used.
By using a counter in my ScreenSaverView and incrementing it each
time
initWithFrame() is called (where isPreview is false) I am able to
count how many displays there are, and it seems like
animateOneFrame()
is called in order of display: animateOneFrame() for display 1,
animateOneFrame() for display 2, and then back to 1 again, etc. So
by
using another counter, I can [sort of] keep track of to which
display
I'm drawing, though it doesn't seem like that great a way of doing
this, nor does it seem that foolproof.
Does anyone have any suggestions as to a better way of knowing a)
how
many displays there are to begin with, and b) a good way in
animateOneFrame() to tell which display is being used?
Many thanks,
Patrick
John C. Randolph <email@hidden> (408) 974-8819
Sr. Cocoa Software Engineer,
Apple Worldwide Developer Relations
http://developer.apple.com/cocoa/index.html
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden