--- a/src/video/cocoa_v.mm Wed Jun 27 01:01:16 2007 +0000
+++ b/src/video/cocoa_v.mm Sat Jul 07 09:20:52 2007 +0000
@@ -65,10 +65,12 @@
#include "../stdafx.h"
+#include "../openttd.h"
#include "../debug.h"
#include "../macros.h"
#include "../os/macosx/splash.h"
#include "../variables.h"
+#include "../gfx.h"
#include "cocoa_v.h"
#include "cocoa_keys.h"
#include "../blitter/factory.hpp"
@@ -131,7 +133,6 @@
static void QZ_WarpCursor(int x, int y);
static void QZ_ShowMouse();
static void QZ_HideMouse();
-static void CocoaVideoFullScreen(bool full_screen);
static NSAutoreleasePool *_ottd_autorelease_pool;
@@ -366,7 +367,7 @@
case QZ_RETURN:
case QZ_f:
if (down && (_cocoa_video_data.current_mods & NSCommandKeyMask)) {
- CocoaVideoFullScreen(!_fullscreen);
+ _video_driver->ToggleFullscreen(!_fullscreen);
}
break;
}
@@ -1184,10 +1185,17 @@
/* We already have a window, just change its size */
if (!isCustom) {
[ _cocoa_video_data.window setContentSize:contentRect.size ];
+ // Ensure frame height - title bar height >= view height
+ contentRect.size.height = clamp(height, 0, [ _cocoa_video_data.window frame ].size.height - 22 /* 22 is the height of title bar of window*/);
+ height = contentRect.size.height;
[ _cocoa_video_data.qdview setFrameSize:contentRect.size ];
}
}
+ // Update again
+ _cocoa_video_data.width = width;
+ _cocoa_video_data.height = height;
+
[ _cocoa_video_data.window center ];
/* Only recreate the view if it doesn't already exist */
@@ -1963,7 +1971,9 @@
* Video driver interface *
******************************************************************************/
-static void CocoaVideoStop()
+static FVideoDriver_Cocoa iFVideoDriver_Cocoa;
+
+void VideoDriver_Cocoa::Stop()
{
if (!_cocoa_video_started) return;
@@ -1974,7 +1984,7 @@
_cocoa_video_started = false;
}
-static const char *CocoaVideoStart(const char * const *parm)
+const char *VideoDriver_Cocoa::Start(const char * const *parm)
{
const char *ret;
@@ -1991,12 +2001,12 @@
QZ_VideoInit();
ret = QZ_SetVideoMode(_cur_resolution[0], _cur_resolution[1], _fullscreen);
- if (ret != NULL) CocoaVideoStop();
+ if (ret != NULL) _video_driver->Stop();
return ret;
}
-static void CocoaVideoMakeDirty(int left, int top, int width, int height)
+void VideoDriver_Cocoa::MakeDirty(int left, int top, int width, int height)
{
if (_cocoa_video_data.num_dirty_rects < MAX_DIRTY_RECTS) {
_cocoa_video_data.dirty_rects[_cocoa_video_data.num_dirty_rects].left = left;
@@ -2007,41 +2017,32 @@
_cocoa_video_data.num_dirty_rects++;
}
-static void CocoaVideoMainLoop()
+void VideoDriver_Cocoa::MainLoop()
{
/* Start the main event loop */
[NSApp run];
}
-static bool CocoaVideoChangeRes(int w, int h)
+bool VideoDriver_Cocoa::ChangeResolution(int w, int h)
{
const char *ret = QZ_SetVideoModeAndRestoreOnFailure((uint)w, (uint)h, _cocoa_video_data.fullscreen);
if (ret != NULL) {
- DEBUG(driver, 0, "cocoa_v: CocoaVideoChangeRes failed with message: %s", ret);
+ DEBUG(driver, 0, "cocoa_v: VideoDriver_Cocoa::ChangeResolution failed with message: %s", ret);
}
return ret == NULL;
}
-static void CocoaVideoFullScreen(bool full_screen)
+void VideoDriver_Cocoa::ToggleFullscreen(bool full_screen)
{
const char *ret = QZ_SetVideoModeAndRestoreOnFailure(_cocoa_video_data.width, _cocoa_video_data.height, full_screen);
if (ret != NULL) {
- DEBUG(driver, 0, "cocoa_v: CocoaVideoFullScreen failed with message: %s", ret);
+ DEBUG(driver, 0, "cocoa_v: VideoDriver_Cocoa::ToggleFullscreen failed with message: %s", ret);
}
_fullscreen = _cocoa_video_data.fullscreen;
}
-const HalVideoDriver _cocoa_video_driver = {
- CocoaVideoStart,
- CocoaVideoStop,
- CocoaVideoMakeDirty,
- CocoaVideoMainLoop,
- CocoaVideoChangeRes,
- CocoaVideoFullScreen,
-};
-
/* This is needed since sometimes assert is called before the videodriver is initialized */
void CocoaDialog(const char* title, const char* message, const char* buttonLabel)
@@ -2051,14 +2052,14 @@
_cocoa_video_dialog = true;
wasstarted = _cocoa_video_started;
- if (!_cocoa_video_started && CocoaVideoStart(NULL) != NULL) {
+ if (!_cocoa_video_started && _video_driver->Start(NULL) != NULL) {
fprintf(stderr, "%s: %s\n", title, message);
return;
}
NSRunAlertPanel([NSString stringWithCString: title], [NSString stringWithCString: message], [NSString stringWithCString: buttonLabel], nil, nil);
- if (!wasstarted) CocoaVideoStop();
+ if (!wasstarted) _video_driver->Stop();
_cocoa_video_dialog = false;
}