Mercurial > hg > openttd
changeset 16476:62857190c379 draft
(svn r21200) -Fix: [OSX] Don't let the mouse cursor jump when switching to full screen mode
author | planetmaker <planetmaker@openttd.org> |
---|---|
date | Mon, 15 Nov 2010 19:53:15 +0000 |
parents | cc40724e03da |
children | 51073f01788c |
files | src/video/cocoa/fullscreen.mm |
diffstat | 1 files changed, 21 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/src/video/cocoa/fullscreen.mm +++ b/src/video/cocoa/fullscreen.mm @@ -266,7 +266,6 @@ /* Define this variables at the top (against coding style) because * otherwise GCC barfs at the goto's jumping over variable initialization. */ NSRect screen_rect; - NSPoint pt; int gamma_error; /* Destroy any previous mode */ @@ -296,6 +295,14 @@ CFNumberGetValue(number, kCFNumberSInt32Type, &h); } + /* Capture the main screen */ + CGDisplayCapture(this->display_id); + + /* Store the mouse coordinates relative to the total screen */ + NSPoint mouseLocation = [ NSEvent mouseLocation ]; + mouseLocation.x /= this->display_width; + mouseLocation.y /= this->display_height; + /* Hide mouse in order to avoid glitch in 8bpp */ QZ_HideMouse(); @@ -348,11 +355,14 @@ screen_rect = NSMakeRect(0, 0, this->display_width, this->display_height); [ [ NSScreen mainScreen ] setFrame:screen_rect ]; - pt = [ NSEvent mouseLocation ]; - pt.y = this->display_height - pt.y; - if (this->MouseIsInsideView(&pt)) QZ_HideMouse(); + this->UpdatePalette(0, 256); - this->UpdatePalette(0, 256); + /* Move the mouse cursor to approx the same location */ + CGPoint display_mouseLocation; + display_mouseLocation.x = mouseLocation.x * this->display_width; + display_mouseLocation.y = this->display_height - (mouseLocation.y * this->display_height); + + CGDisplayMoveCursorToPoint(this->display_id, display_mouseLocation); return true; @@ -381,7 +391,9 @@ /* Restore original screen resolution/bpp */ CGDisplaySwitchToMode(this->display_id, this->save_mode); + CGReleaseAllDisplays(); + ShowMenuBar(); /* Reset the main screen's rectangle @@ -399,8 +411,8 @@ if (!gamma_error) this->FadeGammaIn(&gamma_table); - this->display_width = 0; - this->display_height = 0; + this->display_width = CGDisplayPixelsWide(this->display_id); + this->display_height = CGDisplayPixelsHigh(this->display_id); } public: @@ -416,8 +428,8 @@ if (bpp == 8) this->palette = CGPaletteCreateDefaultColorPalette(); - this->display_width = 0; - this->display_height = 0; + this->display_width = CGDisplayPixelsWide(this->display_id); + this->display_height = CGDisplayPixelsHigh(this->display_id); this->display_depth = bpp; this->pixel_buffer = NULL;