Display capture questions

Posts: 177
Joined: 2002.08
Post: #1
I'm just starting on resolution switching, and I've run into a few issues...
  • Cocoa graphics coordinates are measured from the lower left of rectangles, while CG seems to use the upper left. Therefore, I'm having trouble converting mouse locations obtained from NSEvents to locations on captured displays (it doesn't help that using CG appears to render NSScreen useless). Is there a way to get the absolute mouse position without having to take into account every display attached to the system, or am I limited to CG's mouse delta function?
  • How do I stop resolution switching from resizing windows in background apps on that monitor? I capture the display during the entire time the monitor is in an altered state, but this still happens.
Quote this message in a reply
Post: #2
I think you're stuck with mouse deltas, although you can do it by getting the deltaX and deltaY of NSMouseMoved events instead. That said, it would surprise me greatly if the one did anything more than wrap the other.

Um, I dunno. My windows etc. stay fine, even when I unexpectedly terminate without changing back or releasing the display. How are you going about it? You do switch back to the original settings before you quit, I presume... Wink
Quote this message in a reply
Posts: 469
Joined: 2002.10
Post: #3
1) When I set my app to draw fullscreen I define a frame to draw in. CoreGraphics will pick the best size resolution, and I clip to my frame. Here's the code I use to get the mouseLoc:
[sourcecode]- (NSPoint)mouseLocInFrame {
NSPoint mouseLoc = [NSEvent mouseLocation];
CGRect screenBounds = CGDisplayBounds(kCGDirectMainDisplay);
mouseLoc.y += screenBounds.size.height;
mouseLoc.y -= ([[NSScreen mainScreen] frame].size.height + 1);
mouseLoc.y -= frame.origin.y;
mouseLoc.x -= frame.origin.x;
if ( mouseLoc.x < 0 ) mouseLoc.x = 0;
if ( mouseLoc.x > [self frame].size.width-1 ) mouseLoc.x = [self frame].size.width-1;
if ( mouseLoc.y < 0 ) mouseLoc.y = 0;
if ( mouseLoc.y > [self frame].size.height-1 ) mouseLoc.y = [self frame].size.height-1;
return mouseLoc;

2)As long as you change the screen res only while the screen is captured, not before, not after, then your windows shouldn't move. Course you're gonna have to keep it captured the whole while.

15.4" MacBook Pro revA
Quote this message in a reply
Posts: 177
Joined: 2002.08
Post: #4
foo = CGGetActiveDisplayList(32, list, &count);
        foo = CGDisplayCapture(list[monitorChoice]);
        originalMode = CGDisplayCurrentMode(list[monitorChoice]);
        modes = CGDisplayAvailableModes(list[monitorChoice]);
        selectedMode = CFArrayGetValueAtIndex(modes, resChoice);
        CGDisplaySwitchToMode(list[monitorChoice], selectedMode);

monitorChoice and resChoice are, naturally, integers. They are generated earlier based on the active display list, and I'm sure that part is correct.

Then the game runs, and then:

bar = CGLClearDrawable(coreContext);
        bar = CGLDestroyContext(coreContext);
        foo = CGGetActiveDisplayList(32, list, &count);
        CGDisplaySwitchToMode(list[monitorChoice], originalMode);

Kelvin: I'm trying to stay general by not explicitly using the main display, just the one selected by the user. Guess I'll just use mouse deltas for that part.
Quote this message in a reply
Posts: 834
Joined: 2002.09
Post: #5
Gravedigging warning, but: thanks a lot, Kelvin.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Capture Piece Help Coin 8 5,682 Jan 12, 2005 03:49 PM
Last Post: Coin