mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-01 16:16:00 +00:00
merge
This commit is contained in:
commit
d74cc77637
5 changed files with 250 additions and 185 deletions
|
@ -872,8 +872,11 @@ bool CDriverGL::swapBuffers()
|
||||||
#elif defined(NL_OS_MAC)
|
#elif defined(NL_OS_MAC)
|
||||||
|
|
||||||
// TODO: maybe do this somewhere else?
|
// TODO: maybe do this somewhere else?
|
||||||
|
if(_DestroyWindow)
|
||||||
|
{
|
||||||
[_autoreleasePool release];
|
[_autoreleasePool release];
|
||||||
_autoreleasePool = [[NSAutoreleasePool alloc] init];
|
_autoreleasePool = [[NSAutoreleasePool alloc] init];
|
||||||
|
}
|
||||||
|
|
||||||
[_ctx flushBuffer];
|
[_ctx flushBuffer];
|
||||||
[containerView() display];
|
[containerView() display];
|
||||||
|
|
|
@ -116,8 +116,7 @@ bool GlWndProc(CDriverGL *driver, HWND hWnd, UINT message, WPARAM wParam, LPARAM
|
||||||
|
|
||||||
#elif defined (NL_OS_MAC)
|
#elif defined (NL_OS_MAC)
|
||||||
|
|
||||||
// TODO: change that
|
bool GlWndProc(CDriverGL *driver, NSEvent* e);
|
||||||
bool GlWndProc(CDriverGL *driver);
|
|
||||||
|
|
||||||
#elif defined (NL_OS_UNIX)
|
#elif defined (NL_OS_UNIX)
|
||||||
|
|
||||||
|
@ -706,9 +705,11 @@ private:
|
||||||
|
|
||||||
#elif defined(NL_OS_MAC)
|
#elif defined(NL_OS_MAC)
|
||||||
|
|
||||||
|
friend bool GlWndProc(CDriverGL* driver, NSEvent* e);
|
||||||
|
|
||||||
NLMISC::CCocoaEventEmitter _EventEmitter;
|
NLMISC::CCocoaEventEmitter _EventEmitter;
|
||||||
NSOpenGLContext* _ctx;
|
NSOpenGLContext* _ctx;
|
||||||
NSOpenGLView* _glView;
|
CocoaOpenGLView* _glView;
|
||||||
NSAutoreleasePool* _autoreleasePool;
|
NSAutoreleasePool* _autoreleasePool;
|
||||||
uint16 _backBufferHeight;
|
uint16 _backBufferHeight;
|
||||||
uint16 _backBufferWidth;
|
uint16 _backBufferWidth;
|
||||||
|
|
|
@ -164,8 +164,22 @@ 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)
|
bool GlWndProc(CDriverGL *driver, NSEvent* e)
|
||||||
{
|
{
|
||||||
|
H_AUTO_OGL(GlWndProc)
|
||||||
|
|
||||||
|
if(!driver)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// NSLog(@"NSEvent in GlWndProc %@", e);
|
||||||
|
|
||||||
|
switch([e type])
|
||||||
|
{
|
||||||
|
/* TODO handle window move, resize, activate, close, etc. */
|
||||||
|
default:
|
||||||
|
return driver->_EventEmitter.processMessage(e);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -951,6 +965,8 @@ bool CDriverGL::setDisplay(nlWindow wnd, const GfxMode &mode, bool show, bool re
|
||||||
[_ctx flushBuffer];
|
[_ctx flushBuffer];
|
||||||
[containerView() display];
|
[containerView() display];
|
||||||
|
|
||||||
|
_EventEmitter.init(this, _glView);
|
||||||
|
|
||||||
#elif defined(NL_OS_UNIX)
|
#elif defined(NL_OS_UNIX)
|
||||||
|
|
||||||
static int sAttribList16bpp[] =
|
static int sAttribList16bpp[] =
|
||||||
|
@ -2164,7 +2180,7 @@ void CDriverGL::showWindow(bool show)
|
||||||
|
|
||||||
#elif defined(NL_OS_MAC)
|
#elif defined(NL_OS_MAC)
|
||||||
|
|
||||||
// TODO implement me
|
# warning "OpenGL Driver: Missing Mac Implementation for showWindow"
|
||||||
|
|
||||||
#elif defined (NL_OS_UNIX)
|
#elif defined (NL_OS_UNIX)
|
||||||
|
|
||||||
|
@ -2601,7 +2617,7 @@ bool CDriverGL::isActive()
|
||||||
res = (IsWindow(_win) != FALSE);
|
res = (IsWindow(_win) != FALSE);
|
||||||
|
|
||||||
#elif defined(NL_OS_MAC)
|
#elif defined(NL_OS_MAC)
|
||||||
# warning "OpenGL Driver: Missing Mac Implementation for isActive"
|
# warning "OpenGL Driver: Missing Mac Implementation for isActive (always true if a window is set)"
|
||||||
#elif defined (NL_OS_UNIX)
|
#elif defined (NL_OS_UNIX)
|
||||||
|
|
||||||
#endif // NL_OS_UNIX
|
#endif // NL_OS_UNIX
|
||||||
|
|
|
@ -16,13 +16,6 @@
|
||||||
|
|
||||||
#include "cocoa_event_emitter.h"
|
#include "cocoa_event_emitter.h"
|
||||||
|
|
||||||
#include "nel/misc/event_server.h"
|
|
||||||
#include "nel/misc/events.h"
|
|
||||||
#include "nel/misc/game_device_events.h"
|
|
||||||
|
|
||||||
#include <Carbon/Carbon.h>
|
|
||||||
#import <Cocoa/Cocoa.h>
|
|
||||||
|
|
||||||
namespace NLMISC
|
namespace NLMISC
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -227,22 +220,21 @@ static bool isTextKeyEvent(NSEvent* event)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCocoaEventEmitter::submitEvents(CEventServer& server, bool /* allWins */)
|
void CCocoaEventEmitter::init(NL3D::IDriver* driver, CocoaOpenGLView* glView)
|
||||||
{
|
{
|
||||||
// break if there was no event to handle
|
_driver = driver;
|
||||||
while(true)
|
_glView = glView;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CCocoaEventEmitter::processMessage(NSEvent* event, CEventServer* server)
|
||||||
{
|
{
|
||||||
// get the next event to handle
|
if(!server && !_server)
|
||||||
NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask
|
nlerror("no server to post events to");
|
||||||
untilDate:nil /*[NSDate distantFuture]*/
|
|
||||||
inMode:NSDefaultRunLoopMode dequeue:YES];
|
|
||||||
|
|
||||||
// stop, if there was no event
|
if(!server)
|
||||||
if(!event)
|
server = _server;
|
||||||
break;
|
|
||||||
|
|
||||||
NSView* glView = [[[[event window] contentView] subviews] lastObject];
|
NSRect viewRect = [_glView frame];
|
||||||
NSRect viewRect = [glView frame];
|
|
||||||
|
|
||||||
// TODO this code assumes, that the view fills the window
|
// TODO this code assumes, that the view fills the window
|
||||||
// convert the mouse position to NeL style (relative)
|
// convert the mouse position to NeL style (relative)
|
||||||
|
@ -254,7 +246,7 @@ void CCocoaEventEmitter::submitEvents(CEventServer& server, bool /* allWins */)
|
||||||
event.type != NSKeyDown && event.type != NSKeyUp)
|
event.type != NSKeyDown && event.type != NSKeyUp)
|
||||||
{
|
{
|
||||||
[NSApp sendEvent:event];
|
[NSApp sendEvent:event];
|
||||||
continue;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert the modifiers for nel to pass them with the events
|
// convert the modifiers for nel to pass them with the events
|
||||||
|
@ -265,28 +257,28 @@ void CCocoaEventEmitter::submitEvents(CEventServer& server, bool /* allWins */)
|
||||||
{
|
{
|
||||||
case NSLeftMouseDown:
|
case NSLeftMouseDown:
|
||||||
{
|
{
|
||||||
server.postEvent(new NLMISC::CEventMouseDown(
|
server->postEvent(new NLMISC::CEventMouseDown(
|
||||||
mouseX, mouseY,
|
mouseX, mouseY,
|
||||||
(NLMISC::TMouseButton)(NLMISC::leftButton | modifiers), this));
|
(NLMISC::TMouseButton)(NLMISC::leftButton | modifiers), this));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NSLeftMouseUp:
|
case NSLeftMouseUp:
|
||||||
{
|
{
|
||||||
server.postEvent(new NLMISC::CEventMouseUp(
|
server->postEvent(new NLMISC::CEventMouseUp(
|
||||||
mouseX, mouseY,
|
mouseX, mouseY,
|
||||||
(NLMISC::TMouseButton)(NLMISC::leftButton | modifiers), this));
|
(NLMISC::TMouseButton)(NLMISC::leftButton | modifiers), this));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NSRightMouseDown:
|
case NSRightMouseDown:
|
||||||
{
|
{
|
||||||
server.postEvent(new NLMISC::CEventMouseDown(
|
server->postEvent(new NLMISC::CEventMouseDown(
|
||||||
mouseX, mouseY,
|
mouseX, mouseY,
|
||||||
(NLMISC::TMouseButton)(NLMISC::rightButton | modifiers), this));
|
(NLMISC::TMouseButton)(NLMISC::rightButton | modifiers), this));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NSRightMouseUp:
|
case NSRightMouseUp:
|
||||||
{
|
{
|
||||||
server.postEvent(new NLMISC::CEventMouseUp(
|
server->postEvent(new NLMISC::CEventMouseUp(
|
||||||
mouseX, mouseY,
|
mouseX, mouseY,
|
||||||
(NLMISC::TMouseButton)(NLMISC::rightButton | modifiers), this));
|
(NLMISC::TMouseButton)(NLMISC::rightButton | modifiers), this));
|
||||||
break;
|
break;
|
||||||
|
@ -305,7 +297,7 @@ void CCocoaEventEmitter::submitEvents(CEventServer& server, bool /* allWins */)
|
||||||
nelEvent = new NLMISC::CEventMouseMove(
|
nelEvent = new NLMISC::CEventMouseMove(
|
||||||
mouseX, mouseY, (NLMISC::TMouseButton)modifiers, this);
|
mouseX, mouseY, (NLMISC::TMouseButton)modifiers, this);
|
||||||
|
|
||||||
server.postEvent(nelEvent);
|
server->postEvent(nelEvent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NSLeftMouseDragged:
|
case NSLeftMouseDragged:
|
||||||
|
@ -322,7 +314,7 @@ void CCocoaEventEmitter::submitEvents(CEventServer& server, bool /* allWins */)
|
||||||
nelEvent = new NLMISC::CEventMouseMove(mouseX, mouseY,
|
nelEvent = new NLMISC::CEventMouseMove(mouseX, mouseY,
|
||||||
(NLMISC::TMouseButton)(NLMISC::leftButton | modifiers), this);
|
(NLMISC::TMouseButton)(NLMISC::leftButton | modifiers), this);
|
||||||
|
|
||||||
server.postEvent(nelEvent);
|
server->postEvent(nelEvent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NSRightMouseDragged:
|
case NSRightMouseDragged:
|
||||||
|
@ -339,7 +331,7 @@ void CCocoaEventEmitter::submitEvents(CEventServer& server, bool /* allWins */)
|
||||||
nelEvent = new NLMISC::CEventMouseMove(mouseX, mouseY,
|
nelEvent = new NLMISC::CEventMouseMove(mouseX, mouseY,
|
||||||
(NLMISC::TMouseButton)(NLMISC::rightButton | modifiers), this);
|
(NLMISC::TMouseButton)(NLMISC::rightButton | modifiers), this);
|
||||||
|
|
||||||
server.postEvent(nelEvent);
|
server->postEvent(nelEvent);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NSMouseEntered:break;
|
case NSMouseEntered:break;
|
||||||
|
@ -347,7 +339,7 @@ void CCocoaEventEmitter::submitEvents(CEventServer& server, bool /* allWins */)
|
||||||
case NSKeyDown:
|
case NSKeyDown:
|
||||||
{
|
{
|
||||||
// push the key press event to the event server
|
// push the key press event to the event server
|
||||||
server.postEvent(new NLMISC::CEventKeyDown(
|
server->postEvent(new NLMISC::CEventKeyDown(
|
||||||
virtualKeycodeToNelKey([event keyCode]),
|
virtualKeycodeToNelKey([event keyCode]),
|
||||||
modifierFlagsToNelKeyButton([event modifierFlags]),
|
modifierFlagsToNelKeyButton([event modifierFlags]),
|
||||||
[event isARepeat] == NO, this));
|
[event isARepeat] == NO, this));
|
||||||
|
@ -361,7 +353,7 @@ void CCocoaEventEmitter::submitEvents(CEventServer& server, bool /* allWins */)
|
||||||
ucstr.fromUtf8([[event characters] UTF8String]);
|
ucstr.fromUtf8([[event characters] UTF8String]);
|
||||||
|
|
||||||
// push the text event to event server as well
|
// push the text event to event server as well
|
||||||
server.postEvent(new NLMISC::CEventChar(
|
server->postEvent(new NLMISC::CEventChar(
|
||||||
ucstr[0], NLMISC::noKeyButton, this));
|
ucstr[0], NLMISC::noKeyButton, this));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -369,7 +361,7 @@ void CCocoaEventEmitter::submitEvents(CEventServer& server, bool /* allWins */)
|
||||||
case NSKeyUp:
|
case NSKeyUp:
|
||||||
{
|
{
|
||||||
// push the key release event to the event server
|
// push the key release event to the event server
|
||||||
server.postEvent(new NLMISC::CEventKeyUp(
|
server->postEvent(new NLMISC::CEventKeyUp(
|
||||||
virtualKeycodeToNelKey([event keyCode]),
|
virtualKeycodeToNelKey([event keyCode]),
|
||||||
modifierFlagsToNelKeyButton([event modifierFlags]), this));
|
modifierFlagsToNelKeyButton([event modifierFlags]), this));
|
||||||
break;
|
break;
|
||||||
|
@ -383,7 +375,7 @@ void CCocoaEventEmitter::submitEvents(CEventServer& server, bool /* allWins */)
|
||||||
case NSScrollWheel:
|
case NSScrollWheel:
|
||||||
{
|
{
|
||||||
if(fabs(event.deltaY) > 0.1)
|
if(fabs(event.deltaY) > 0.1)
|
||||||
server.postEvent(new NLMISC::CEventMouseWheel(
|
server->postEvent(new NLMISC::CEventMouseWheel(
|
||||||
mouseX, mouseY, (NLMISC::TMouseButton)modifiers,
|
mouseX, mouseY, (NLMISC::TMouseButton)modifiers,
|
||||||
(event.deltaY > 0), this));
|
(event.deltaY > 0), this));
|
||||||
|
|
||||||
|
@ -411,7 +403,41 @@ void CCocoaEventEmitter::submitEvents(CEventServer& server, bool /* allWins */)
|
||||||
}
|
}
|
||||||
|
|
||||||
[NSApp sendEvent:event];
|
[NSApp sendEvent:event];
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef bool (*cocoaProc)(NL3D::IDriver*, void* e);
|
||||||
|
|
||||||
|
void CCocoaEventEmitter::submitEvents(CEventServer& server, bool /* allWins */)
|
||||||
|
{
|
||||||
|
// break if there was no event to handle
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
// get the next event to handle
|
||||||
|
NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask
|
||||||
|
untilDate:nil /*[NSDate distantFuture]*/
|
||||||
|
inMode:NSDefaultRunLoopMode dequeue:YES];
|
||||||
|
|
||||||
|
// stop, if there was no event
|
||||||
|
if(!event)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if(_driver)
|
||||||
|
{
|
||||||
|
cocoaProc proc = (cocoaProc)_driver->getWindowProc();
|
||||||
|
|
||||||
|
if(proc)
|
||||||
|
proc(_driver, event);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
processMessage(event, &server);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO like internal server in unix event emitter... review!
|
||||||
|
_server = &server;
|
||||||
|
// _server->pump();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCocoaEventEmitter::emulateMouseRawMode(bool enable)
|
void CCocoaEventEmitter::emulateMouseRawMode(bool enable)
|
||||||
|
|
|
@ -17,7 +17,15 @@
|
||||||
#ifndef NL_COCOA_EVENT_EMITTER_H
|
#ifndef NL_COCOA_EVENT_EMITTER_H
|
||||||
#define NL_COCOA_EVENT_EMITTER_H
|
#define NL_COCOA_EVENT_EMITTER_H
|
||||||
|
|
||||||
#include <nel/misc/event_emitter.h>
|
#include "nel/misc/event_emitter.h"
|
||||||
|
#include "nel/misc/event_server.h"
|
||||||
|
#include "nel/misc/events.h"
|
||||||
|
#include "nel/misc/game_device_events.h"
|
||||||
|
#include "nel/3d/driver.h"
|
||||||
|
#import "cocoa_opengl_view.h"
|
||||||
|
|
||||||
|
#include <Carbon/Carbon.h>
|
||||||
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
namespace NLMISC
|
namespace NLMISC
|
||||||
{
|
{
|
||||||
|
@ -25,10 +33,21 @@ namespace NLMISC
|
||||||
class CCocoaEventEmitter : public IEventEmitter
|
class CCocoaEventEmitter : public IEventEmitter
|
||||||
{
|
{
|
||||||
bool _emulateRawMode;
|
bool _emulateRawMode;
|
||||||
|
NL3D::IDriver* _driver;
|
||||||
|
CocoaOpenGLView* _glView;
|
||||||
|
|
||||||
|
// TODO like internal server in unix event emitter... review!
|
||||||
|
CEventServer* _server;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CCocoaEventEmitter() : _emulateRawMode(false) { }
|
CCocoaEventEmitter() :
|
||||||
|
_emulateRawMode(false),
|
||||||
|
_driver(NULL),
|
||||||
|
_glView(nil),
|
||||||
|
_server(NULL) { }
|
||||||
|
|
||||||
|
void init(NL3D::IDriver* driver, CocoaOpenGLView* glView);
|
||||||
|
bool processMessage(NSEvent* event, CEventServer* server = NULL);
|
||||||
virtual void submitEvents(CEventServer& server, bool allWindows);
|
virtual void submitEvents(CEventServer& server, bool allWindows);
|
||||||
virtual void emulateMouseRawMode(bool enable);
|
virtual void emulateMouseRawMode(bool enable);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue