summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2021-01-24 13:12:55 +0100
committerMichael Lutz <michi@icosahedron.de>2021-02-13 22:21:17 +0100
commit8ced72ab10b12a33ef5e71f8b346f63a0db0f862 (patch)
treeb17e93ba9c7cd698a0d3bc2a6b6146cc06e612c5
parent13134f9d64fb873ab1ee0cca2cc4c4fa3c64a44a (diff)
downloadopenttd-8ced72ab10b12a33ef5e71f8b346f63a0db0f862.tar.xz
Codechange: [OSX] Inline some functions that are used in only one place.
-rw-r--r--src/video/cocoa/cocoa_v.h15
-rw-r--r--src/video/cocoa/cocoa_v.mm32
-rw-r--r--src/video/cocoa/event.mm26
3 files changed, 23 insertions, 50 deletions
diff --git a/src/video/cocoa/cocoa_v.h b/src/video/cocoa/cocoa_v.h
index 70adb18b5..bae0f5289 100644
--- a/src/video/cocoa/cocoa_v.h
+++ b/src/video/cocoa/cocoa_v.h
@@ -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
diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm
index 9e52cce01..3350e32b8 100644
--- a/src/video/cocoa/cocoa_v.mm
+++ b/src/video/cocoa/cocoa_v.mm
@@ -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)
{
diff --git a/src/video/cocoa/event.mm b/src/video/cocoa/event.mm
index 86ffd9145..858cd51ad 100644
--- a/src/video/cocoa/event.mm
+++ b/src/video/cocoa/event.mm
@@ -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();
}