mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-09 15:41:15 +00:00
Codechange: [OSX] Inline some functions that are used in only one place.
This commit is contained in:
parent
13134f9d64
commit
8ced72ab10
@ -22,7 +22,6 @@ private:
|
||||
|
||||
int device_width; ///< Width 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_height; ///< Current window height in pixel
|
||||
@ -142,25 +141,11 @@ private:
|
||||
/** Update the palette */
|
||||
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
|
||||
* @return whether fullscreen mode is currently used
|
||||
*/
|
||||
bool IsFullscreen();
|
||||
|
||||
/** Return the current pixel buffer
|
||||
* @return pixelbuffer
|
||||
*/
|
||||
void *GetPixelBuffer() { return buffer_depth == 8 ? pixel_buffer : window_buffer; }
|
||||
|
||||
/** Return the mouse location
|
||||
* @param event UI event
|
||||
* @return mouse location as NSPoint
|
||||
|
@ -141,7 +141,7 @@ const char *VideoDriver_Cocoa::Start(const StringList &parm)
|
||||
return "The cocoa quartz subdriver only supports 8 and 32 bpp.";
|
||||
}
|
||||
|
||||
if (!this->ChangeResolution(width, height, bpp)) {
|
||||
if (!this->SetVideoMode(width, height, bpp)) {
|
||||
Stop();
|
||||
return "Could not create subdriver";
|
||||
}
|
||||
@ -195,9 +195,17 @@ void VideoDriver_Cocoa::MainLoop()
|
||||
*/
|
||||
bool VideoDriver_Cocoa::ChangeResolution(int w, int h)
|
||||
{
|
||||
bool ret = this->ChangeResolution(w, h, BlitterFactory::GetCurrentBlitter()->GetScreenDepth());
|
||||
this->GameSizeChanged();
|
||||
return ret;
|
||||
int old_width = this->window_width;
|
||||
int old_height = this->window_height;
|
||||
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.height = this->window_height;
|
||||
_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. */
|
||||
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) error("Could not get a valid colour space for drawing.");
|
||||
|
||||
bool ret = WindowResized();
|
||||
bool ret = this->WindowResized();
|
||||
this->UpdatePalette(0, 256);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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 */
|
||||
CGPoint VideoDriver_Cocoa::PrivateLocalToCG(NSPoint *p)
|
||||
{
|
||||
|
@ -73,21 +73,6 @@ static uint32 GetTick()
|
||||
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 {
|
||||
unsigned short vk_from;
|
||||
byte map_to;
|
||||
@ -317,8 +302,15 @@ static void QZ_DoUnsidedModifiers(unsigned int newMods)
|
||||
|
||||
void VideoDriver_Cocoa::MouseMovedEvent(int x, int y)
|
||||
{
|
||||
if (_cursor.UpdateCursorPosition(x, y, false)) {
|
||||
this->WarpCursor(_cursor.pos.x, _cursor.pos.y);
|
||||
if (_cursor.UpdateCursorPosition(x, y, false) && [ NSApp isActive ]) {
|
||||
/* 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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user