Codechange: [OSX] Inline some functions that are used in only one place.

This commit is contained in:
Michael Lutz 2021-01-24 13:12:55 +01:00
parent 13134f9d64
commit 8ced72ab10
3 changed files with 23 additions and 50 deletions

View File

@ -22,7 +22,6 @@ private:
int device_width; ///< Width of device in pixel int device_width; ///< Width of device in pixel
int device_height; ///< Height of device in pixel int device_height; ///< Height of device in pixel
int device_depth; ///< Colour depth of device in bit
int window_width; ///< Current window width in pixel int window_width; ///< Current window width in pixel
int window_height; ///< Current window height in pixel int window_height; ///< Current window height in pixel
@ -142,25 +141,11 @@ private:
/** Update the palette */ /** Update the palette */
void UpdatePalette(uint first_color, uint num_colors); void UpdatePalette(uint first_color, uint num_colors);
uint ListModes(OTTD_Point *modes, uint max_modes);
/** Change window resolution
* @param w New window width
* @param h New window height
* @return Whether change was successful
*/
bool ChangeResolution(int w, int h, int bpp);
/** Are we in fullscreen mode /** Are we in fullscreen mode
* @return whether fullscreen mode is currently used * @return whether fullscreen mode is currently used
*/ */
bool IsFullscreen(); bool IsFullscreen();
/** Return the current pixel buffer
* @return pixelbuffer
*/
void *GetPixelBuffer() { return buffer_depth == 8 ? pixel_buffer : window_buffer; }
/** Return the mouse location /** Return the mouse location
* @param event UI event * @param event UI event
* @return mouse location as NSPoint * @return mouse location as NSPoint

View File

@ -141,7 +141,7 @@ const char *VideoDriver_Cocoa::Start(const StringList &parm)
return "The cocoa quartz subdriver only supports 8 and 32 bpp."; return "The cocoa quartz subdriver only supports 8 and 32 bpp.";
} }
if (!this->ChangeResolution(width, height, bpp)) { if (!this->SetVideoMode(width, height, bpp)) {
Stop(); Stop();
return "Could not create subdriver"; return "Could not create subdriver";
} }
@ -195,9 +195,17 @@ void VideoDriver_Cocoa::MainLoop()
*/ */
bool VideoDriver_Cocoa::ChangeResolution(int w, int h) bool VideoDriver_Cocoa::ChangeResolution(int w, int h)
{ {
bool ret = this->ChangeResolution(w, h, BlitterFactory::GetCurrentBlitter()->GetScreenDepth()); int old_width = this->window_width;
this->GameSizeChanged(); int old_height = this->window_height;
return ret; int old_bpp = this->buffer_depth;
if (this->SetVideoMode(w, h, BlitterFactory::GetCurrentBlitter()->GetScreenDepth())) {
this->GameSizeChanged();
return true;
}
if (old_width != 0 && old_height != 0) this->SetVideoMode(old_width, old_height, old_bpp);
return false;
} }
/** /**
@ -257,7 +265,7 @@ void VideoDriver_Cocoa::GameSizeChanged()
_screen.width = this->window_width; _screen.width = this->window_width;
_screen.height = this->window_height; _screen.height = this->window_height;
_screen.pitch = this->window_width; _screen.pitch = this->window_width;
_screen.dst_ptr = this->GetPixelBuffer(); _screen.dst_ptr = this->buffer_depth == 8 ? this->pixel_buffer : this->window_buffer;
/* Store old window size if we entered fullscreen mode. */ /* Store old window size if we entered fullscreen mode. */
bool fullscreen = this->IsFullscreen(); bool fullscreen = this->IsFullscreen();
@ -508,7 +516,7 @@ bool VideoDriver_Cocoa::SetVideoMode(int width, int height, int bpp)
if (this->color_space == nullptr) this->color_space = CGColorSpaceCreateDeviceRGB(); if (this->color_space == nullptr) this->color_space = CGColorSpaceCreateDeviceRGB();
if (this->color_space == nullptr) error("Could not get a valid colour space for drawing."); if (this->color_space == nullptr) error("Could not get a valid colour space for drawing.");
bool ret = WindowResized(); bool ret = this->WindowResized();
this->UpdatePalette(0, 256); this->UpdatePalette(0, 256);
this->setup = false; this->setup = false;
@ -589,18 +597,6 @@ void VideoDriver_Cocoa::UpdatePalette(uint first_color, uint num_colors)
this->num_dirty_rects = lengthof(this->dirty_rects); this->num_dirty_rects = lengthof(this->dirty_rects);
} }
bool VideoDriver_Cocoa::ChangeResolution(int w, int h, int bpp)
{
int old_width = this->window_width;
int old_height = this->window_height;
int old_bpp = this->buffer_depth;
if (this->SetVideoMode(w, h, bpp)) return true;
if (old_width != 0 && old_height != 0) this->SetVideoMode(old_width, old_height, old_bpp);
return false;
}
/* Convert local coordinate to window server (CoreGraphics) coordinate */ /* Convert local coordinate to window server (CoreGraphics) coordinate */
CGPoint VideoDriver_Cocoa::PrivateLocalToCG(NSPoint *p) CGPoint VideoDriver_Cocoa::PrivateLocalToCG(NSPoint *p)
{ {

View File

@ -73,21 +73,6 @@ static uint32 GetTick()
return tim.tv_usec / 1000 + tim.tv_sec * 1000; return tim.tv_usec / 1000 + tim.tv_sec * 1000;
} }
void VideoDriver_Cocoa::WarpCursor(int x, int y)
{
/* Only allow warping when in foreground */
if (![ NSApp isActive ]) return;
NSPoint p = NSMakePoint(x, y);
CGPoint cgp = this->PrivateLocalToCG(&p);
/* Do the actual warp */
CGWarpMouseCursorPosition(cgp);
/* this is the magic call that fixes cursor "freezing" after warp */
CGAssociateMouseAndMouseCursorPosition(true);
}
struct VkMapping { struct VkMapping {
unsigned short vk_from; unsigned short vk_from;
byte map_to; byte map_to;
@ -317,8 +302,15 @@ static void QZ_DoUnsidedModifiers(unsigned int newMods)
void VideoDriver_Cocoa::MouseMovedEvent(int x, int y) void VideoDriver_Cocoa::MouseMovedEvent(int x, int y)
{ {
if (_cursor.UpdateCursorPosition(x, y, false)) { if (_cursor.UpdateCursorPosition(x, y, false) && [ NSApp isActive ]) {
this->WarpCursor(_cursor.pos.x, _cursor.pos.y); /* Warping cursor when in foreground */
NSPoint p = NSMakePoint(_cursor.pos.x, _cursor.pos.y);
CGPoint cgp = this->PrivateLocalToCG(&p);
/* Do the actual warp */
CGWarpMouseCursorPosition(cgp);
/* this is the magic call that fixes cursor "freezing" after warp */
CGAssociateMouseAndMouseCursorPosition(true);
} }
HandleMouseEvents(); HandleMouseEvents();
} }