Fixed: #1147 Make OVQT work on MacOS

This commit is contained in:
rti 2010-10-31 16:50:56 +01:00
parent 9a9ea61516
commit 012e2cc886
7 changed files with 53 additions and 26 deletions

View file

@ -879,7 +879,6 @@ bool CDriverGL::swapBuffers()
} }
[_ctx flushBuffer]; [_ctx flushBuffer];
[containerView() display];
#elif defined (NL_OS_UNIX) #elif defined (NL_OS_UNIX)

View file

@ -116,7 +116,7 @@ bool GlWndProc(CDriverGL *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM
#elif defined (NL_OS_MAC) #elif defined (NL_OS_MAC)
bool GlWndProc(CDriverGL *driver, NSEvent* e); bool GlWndProc(CDriverGL *driver, const void* e);
#elif defined (NL_OS_UNIX) #elif defined (NL_OS_UNIX)
@ -705,7 +705,7 @@ private:
#elif defined(NL_OS_MAC) #elif defined(NL_OS_MAC)
friend bool GlWndProc(CDriverGL*, NSEvent*); friend bool GlWndProc(CDriverGL*, const void*);
friend void windowDidMove(NSWindow*, CDriverGL*); friend void windowDidMove(NSWindow*, CDriverGL*);
friend void viewDidResize(NSView*, CDriverGL*); friend void viewDidResize(NSView*, CDriverGL*);

View file

@ -165,20 +165,21 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM l
#elif defined (NL_OS_MAC) #elif defined (NL_OS_MAC)
bool GlWndProc(CDriverGL *driver, NSEvent* e) bool GlWndProc(CDriverGL *driver, const void* e)
{ {
H_AUTO_OGL(GlWndProc) H_AUTO_OGL(GlWndProc)
// NSLog(@"NSEvent in GlWndProc %@", e);
if(!driver) if(!driver)
return false; return false;
switch([e type]) NSEvent* event = [NSEvent eventWithEventRef:e];
// NSLog(@"NSEvent in GlWndProc %@", event);
switch([event type])
{ {
/* TODO handle window activate, close, etc. */ /* TODO handle window activate, close, etc. */
default: default:
return driver->_EventEmitter.processMessage(e); return driver->_EventEmitter.processMessage(event);
} }
return false; return false;
@ -967,7 +968,6 @@ bool CDriverGL::setDisplay(nlWindow wnd, const GfxMode &mode, bool show, bool re
[[containerView() window] makeFirstResponder:_glView]; [[containerView() window] makeFirstResponder:_glView];
[_ctx flushBuffer]; [_ctx flushBuffer];
[containerView() display];
_EventEmitter.init(this, _glView); _EventEmitter.init(this, _glView);

View file

@ -233,6 +233,7 @@ bool CCocoaEventEmitter::processMessage(NSEvent* event, CEventServer* server)
if(!server && !_server) if(!server && !_server)
nlerror("no server to post events to"); nlerror("no server to post events to");
// TODO like internal server in unix event emitter... review!
if(!server) if(!server)
server = _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) && if((mouseX < 0.0 || mouseX > 1.0 || mouseY < 0.0 || mouseY > 1.0) &&
event.type != NSKeyDown && event.type != NSKeyUp) event.type != NSKeyDown && event.type != NSKeyUp)
{ {
[NSApp sendEvent:event];
return false; return false;
} }
@ -399,16 +399,15 @@ bool CCocoaEventEmitter::processMessage(NSEvent* event, CEventServer* server)
default: default:
{ {
nlwarning("Unknown event type. dropping."); nlwarning("Unknown event type. dropping.");
// NSLog(@"%@", event); NSLog(@"%@", event);
break; break;
} }
} }
[NSApp sendEvent:event];
return true; return true;
} }
typedef bool (*cocoaProc)(NL3D::IDriver*, NSEvent* e); typedef bool (*cocoaProc)(NL3D::IDriver*, const void* e);
void CCocoaEventEmitter::submitEvents(CEventServer& server, bool /* allWins */) void CCocoaEventEmitter::submitEvents(CEventServer& server, bool /* allWins */)
{ {
@ -429,17 +428,18 @@ void CCocoaEventEmitter::submitEvents(CEventServer& server, bool /* allWins */)
cocoaProc proc = (cocoaProc)_driver->getWindowProc(); cocoaProc proc = (cocoaProc)_driver->getWindowProc();
if(proc) if(proc)
proc(_driver, event); proc(_driver, [event eventRef]);
} }
else else
{ {
processMessage(event, &server); processMessage(event, &server);
} }
[NSApp sendEvent:event];
} }
// TODO like internal server in unix event emitter... review! // TODO like internal server in unix event emitter... review!
_server = &server; _server = &server;
// _server->pump();
} }
void CCocoaEventEmitter::emulateMouseRawMode(bool enable) void CCocoaEventEmitter::emulateMouseRawMode(bool enable)

View file

@ -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_CPP( OBJECT_VIEWER_MOC_SRCS ${OBJECT_VIEWER_HDR} )
QT4_WRAP_UI( OBJECT_VIEWER_UI_HDRS ${OBJECT_VIEWER_UIS} ) 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 TARGET_LINK_LIBRARIES(object_viewer_qt
nelmisc 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) ADD_NATIVE_PRECOMPILED_HEADER(object_viewer_qt ${CMAKE_CURRENT_SOURCE_DIR}/stdpch.h ${CMAKE_CURRENT_SOURCE_DIR}/stdpch.cpp)
ENDIF(WITH_PCH) 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)

View file

@ -60,11 +60,11 @@ void CGraphicsViewport::init()
//H_AUTO2 //H_AUTO2
nldebug("CGraphicsViewport::init"); nldebug("CGraphicsViewport::init");
#ifdef NL_OS_UNIX #if defined(NL_OS_UNIX) && !defined(NL_OS_MAC)
makeCurrent(); 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(); Modules::psEdit().init();
setMouseTracking(true); setMouseTracking(true);
@ -115,7 +115,7 @@ void CGraphicsViewport::resizeEvent(QResizeEvent *resizeEvent)
Modules::objView().setSizeViewport(resizeEvent->size().width(), resizeEvent->size().height()); 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); 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; 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<NL3D::CDriverUser*>(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); typedef bool (*x11Proc)(NL3D::IDriver *drv, XEvent *e);

View file

@ -33,9 +33,12 @@
// Project includes // Project includes
#ifdef NL_OS_WINDOWS /* TODO every platform should use QWidget */
#if defined(NL_OS_WINDOWS)
typedef QWidget QNLWidget; typedef QWidget QNLWidget;
#else // NL_OS_UNIX #elif defined(NL_OS_MAC)
typedef QWidget QNLWidget;
#elif defined(NL_OS_UNIX)
typedef QGLWidget QNLWidget; typedef QGLWidget QNLWidget;
#endif // NL_OS_UNIX #endif // NL_OS_UNIX
@ -73,9 +76,11 @@ private Q_SLOTS:
protected: protected:
virtual void resizeEvent(QResizeEvent *resizeEvent); virtual void resizeEvent(QResizeEvent *resizeEvent);
#ifdef NL_OS_WINDOWS #if defined(NL_OS_WINDOWS)
virtual bool winEvent(MSG * message, long * result); 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); virtual bool x11Event(XEvent *event);
#endif #endif