From bcbde9df16b8377ad17696ad0d60b3be5254a69e Mon Sep 17 00:00:00 2001 From: rti Date: Sun, 31 Oct 2010 16:50:56 +0100 Subject: [PATCH] Fixed: #1147 Make OVQT work on MacOS --- .../src/3d/driver/opengl/driver_opengl.cpp | 1 - code/nel/src/3d/driver/opengl/driver_opengl.h | 4 +-- .../3d/driver/opengl/driver_opengl_window.cpp | 12 +++---- .../driver/opengl/mac/cocoa_event_emitter.cpp | 12 +++---- .../3d/object_viewer_qt/src/CMakeLists.txt | 4 +-- .../src/graphics_viewport.cpp | 33 ++++++++++++++++--- .../object_viewer_qt/src/graphics_viewport.h | 13 +++++--- 7 files changed, 53 insertions(+), 26 deletions(-) diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.cpp b/code/nel/src/3d/driver/opengl/driver_opengl.cpp index 147420545..3b7a2a1d3 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl.cpp @@ -879,7 +879,6 @@ bool CDriverGL::swapBuffers() } [_ctx flushBuffer]; - [containerView() display]; #elif defined (NL_OS_UNIX) diff --git a/code/nel/src/3d/driver/opengl/driver_opengl.h b/code/nel/src/3d/driver/opengl/driver_opengl.h index 3af14a1d5..3143249c9 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl.h +++ b/code/nel/src/3d/driver/opengl/driver_opengl.h @@ -116,7 +116,7 @@ bool GlWndProc(CDriverGL *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM #elif defined (NL_OS_MAC) -bool GlWndProc(CDriverGL *driver, NSEvent* e); +bool GlWndProc(CDriverGL *driver, const void* e); #elif defined (NL_OS_UNIX) @@ -705,7 +705,7 @@ private: #elif defined(NL_OS_MAC) - friend bool GlWndProc(CDriverGL*, NSEvent*); + friend bool GlWndProc(CDriverGL*, const void*); friend void windowDidMove(NSWindow*, CDriverGL*); friend void viewDidResize(NSView*, CDriverGL*); diff --git a/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp b/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp index f65979873..8ba37c2df 100644 --- a/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp +++ b/code/nel/src/3d/driver/opengl/driver_opengl_window.cpp @@ -165,20 +165,21 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l #elif defined (NL_OS_MAC) -bool GlWndProc(CDriverGL *driver, NSEvent* e) +bool GlWndProc(CDriverGL *driver, const void* e) { H_AUTO_OGL(GlWndProc) - // NSLog(@"NSEvent in GlWndProc %@", e); - if(!driver) return false; - switch([e type]) + NSEvent* event = [NSEvent eventWithEventRef:e]; + // NSLog(@"NSEvent in GlWndProc %@", event); + + switch([event type]) { /* TODO handle window activate, close, etc. */ default: - return driver->_EventEmitter.processMessage(e); + return driver->_EventEmitter.processMessage(event); } return false; @@ -967,7 +968,6 @@ bool CDriverGL::setDisplay(nlWindow wnd, const GfxMode &mode, bool show, bool re [[containerView() window] makeFirstResponder:_glView]; [_ctx flushBuffer]; - [containerView() display]; _EventEmitter.init(this, _glView); diff --git a/code/nel/src/3d/driver/opengl/mac/cocoa_event_emitter.cpp b/code/nel/src/3d/driver/opengl/mac/cocoa_event_emitter.cpp index f1c5e2ad9..3ed9a4fc6 100644 --- a/code/nel/src/3d/driver/opengl/mac/cocoa_event_emitter.cpp +++ b/code/nel/src/3d/driver/opengl/mac/cocoa_event_emitter.cpp @@ -233,6 +233,7 @@ bool CCocoaEventEmitter::processMessage(NSEvent* event, CEventServer* server) if(!server && !_server) nlerror("no server to post events to"); + // TODO like internal server in unix event emitter... review! if(!server) server = _server; @@ -247,7 +248,6 @@ bool CCocoaEventEmitter::processMessage(NSEvent* event, CEventServer* server) if((mouseX < 0.0 || mouseX > 1.0 || mouseY < 0.0 || mouseY > 1.0) && event.type != NSKeyDown && event.type != NSKeyUp) { - [NSApp sendEvent:event]; return false; } @@ -399,16 +399,15 @@ bool CCocoaEventEmitter::processMessage(NSEvent* event, CEventServer* server) default: { nlwarning("Unknown event type. dropping."); - // NSLog(@"%@", event); + NSLog(@"%@", event); break; } } - [NSApp sendEvent:event]; return true; } -typedef bool (*cocoaProc)(NL3D::IDriver*, NSEvent* e); +typedef bool (*cocoaProc)(NL3D::IDriver*, const void* e); void CCocoaEventEmitter::submitEvents(CEventServer& server, bool /* allWins */) { @@ -429,17 +428,18 @@ void CCocoaEventEmitter::submitEvents(CEventServer& server, bool /* allWins */) cocoaProc proc = (cocoaProc)_driver->getWindowProc(); if(proc) - proc(_driver, event); + proc(_driver, [event eventRef]); } else { processMessage(event, &server); } + + [NSApp sendEvent:event]; } // TODO like internal server in unix event emitter... review! _server = &server; - // _server->pump(); } void CCocoaEventEmitter::emulateMouseRawMode(bool enable) diff --git a/code/nel/tools/3d/object_viewer_qt/src/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/CMakeLists.txt index 107f52775..3cf65baa0 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/CMakeLists.txt @@ -40,7 +40,7 @@ QT4_ADD_RESOURCES( OBJECT_VIEWER_RC_SRCS ${OBJECT_VIEWER_RCS} ) QT4_WRAP_CPP( OBJECT_VIEWER_MOC_SRCS ${OBJECT_VIEWER_HDR} ) QT4_WRAP_UI( OBJECT_VIEWER_UI_HDRS ${OBJECT_VIEWER_UIS} ) -ADD_EXECUTABLE(object_viewer_qt WIN32 ${OBJECT_VIEWER_SRC} ${OBJECT_VIEWER_MOC_SRCS} ${OBJECT_VIEWER_RC_SRCS} ${OBJECT_VIEWER_UI_HDRS}) +ADD_EXECUTABLE(object_viewer_qt WIN32 MACOSX_BUNDLE ${OBJECT_VIEWER_SRC} ${OBJECT_VIEWER_MOC_SRCS} ${OBJECT_VIEWER_RC_SRCS} ${OBJECT_VIEWER_UI_HDRS}) TARGET_LINK_LIBRARIES(object_viewer_qt nelmisc @@ -60,4 +60,4 @@ IF(WITH_PCH) ADD_NATIVE_PRECOMPILED_HEADER(object_viewer_qt ${CMAKE_CURRENT_SOURCE_DIR}/stdpch.h ${CMAKE_CURRENT_SOURCE_DIR}/stdpch.cpp) ENDIF(WITH_PCH) -INSTALL(TARGETS object_viewer_qt RUNTIME DESTINATION bin COMPONENT runtime) +INSTALL(TARGETS object_viewer_qt RUNTIME DESTINATION bin COMPONENT runtime BUNDLE DESTINATION /Applications) diff --git a/code/nel/tools/3d/object_viewer_qt/src/graphics_viewport.cpp b/code/nel/tools/3d/object_viewer_qt/src/graphics_viewport.cpp index daccaa876..99807cef4 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/graphics_viewport.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/graphics_viewport.cpp @@ -60,11 +60,11 @@ void CGraphicsViewport::init() //H_AUTO2 nldebug("CGraphicsViewport::init"); -#ifdef NL_OS_UNIX +#if defined(NL_OS_UNIX) && !defined(NL_OS_MAC) makeCurrent(); -#endif // NL_OS_UNIX +#endif // defined(NL_OS_UNIX) && !defined(NL_OS_MAC) - Modules::objView().init(winId(), width(), height()); + Modules::objView().init((nlWindow)winId(), width(), height()); Modules::psEdit().init(); setMouseTracking(true); @@ -115,7 +115,7 @@ void CGraphicsViewport::resizeEvent(QResizeEvent *resizeEvent) Modules::objView().setSizeViewport(resizeEvent->size().width(), resizeEvent->size().height()); } -#ifdef NL_OS_WINDOWS +#if defined(NL_OS_WINDOWS) typedef bool (*winProc)(NL3D::IDriver *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); @@ -133,7 +133,30 @@ bool CGraphicsViewport::winEvent(MSG * message, long * result) return false; } -#else // NL_OS_UNIX + +#elif defined(NL_OS_MAC) + +typedef bool (*cocoaProc)(NL3D::IDriver*, const void* e); + +bool CGraphicsViewport::macEvent(EventHandlerCallRef caller, EventRef event) +{ + if(caller) + nlerror("You are using QtCarbon! Only QtCocoa supported, please upgrade Qt"); + + if (Modules::objView().getDriver() && Modules::objView().getDriver()->isActive()) + { + NL3D::IDriver *driver = dynamic_cast(Modules::objView().getDriver())->getDriver(); + if (driver) + { + cocoaProc proc = (cocoaProc)driver->getWindowProc(); + return proc(driver, event); + } + } + + return false; +} + +#elif defined(NL_OS_UNIX) typedef bool (*x11Proc)(NL3D::IDriver *drv, XEvent *e); diff --git a/code/nel/tools/3d/object_viewer_qt/src/graphics_viewport.h b/code/nel/tools/3d/object_viewer_qt/src/graphics_viewport.h index 1c30012ed..9a6fefd3e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/graphics_viewport.h +++ b/code/nel/tools/3d/object_viewer_qt/src/graphics_viewport.h @@ -33,9 +33,12 @@ // Project includes -#ifdef NL_OS_WINDOWS +/* TODO every platform should use QWidget */ +#if defined(NL_OS_WINDOWS) typedef QWidget QNLWidget; -#else // NL_OS_UNIX +#elif defined(NL_OS_MAC) +typedef QWidget QNLWidget; +#elif defined(NL_OS_UNIX) typedef QGLWidget QNLWidget; #endif // NL_OS_UNIX @@ -73,9 +76,11 @@ private Q_SLOTS: protected: virtual void resizeEvent(QResizeEvent *resizeEvent); -#ifdef NL_OS_WINDOWS +#if defined(NL_OS_WINDOWS) virtual bool winEvent(MSG * message, long * result); -#else // NL_OS_UNIX +#elif defined(NL_OS_MAC) + virtual bool macEvent(EventHandlerCallRef caller, EventRef event); +#elif defined(NL_OS_UNIX) virtual bool x11Event(XEvent *event); #endif