Changed: #947 window title, position, resize. fixed notify sound on key down.

This commit is contained in:
rti 2010-06-01 01:34:19 +02:00
parent 126f0c39b1
commit 84ffbd6c7f
5 changed files with 84 additions and 25 deletions

View file

@ -1770,8 +1770,7 @@ void CDriverGL::setWindowTitle(const ucstring &title)
SetWindowTextW(_hWnd,(WCHAR*)title.c_str());
#elif defined(NL_OS_MAC) && defined(NL_MAC_NATIVE)
# warning "OpenGL Driver: Missing Mac Implementation"
nlwarning("OpenGL Driver: Missing Mac Implementation");
NL3D::MAC::setWindowTitle(title);
#elif defined (NL_OS_UNIX)
XTextProperty text_property;
@ -1790,11 +1789,11 @@ void CDriverGL::setWindowPos(uint32 x, uint32 y)
SetWindowPos(_hWnd, NULL, _WindowX, _WindowY, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
#elif defined(NL_OS_MAC) && defined(NL_MAC_NATIVE)
# warning "OpenGL Driver: Missing Mac Implementation"
nlwarning("OpenGL Driver: Missing Mac Implementation");
NL3D::MAC::setWindowPos(x, y);
#elif defined (NL_OS_UNIX)
XMoveWindow(dpy, win, _WindowX, _WindowY);
#endif // NL_OS_WINDOWS
}
@ -2289,11 +2288,9 @@ void CDriverGL::setupViewport (const class CViewport& viewport)
int clientHeight = _WindowHeight;
#elif defined(NL_OS_MAC) && defined(NL_MAC_NATIVE)
# warning "OpenGL Driver: Temporary Mac Implementation"
// nlwarning("OpenGL Driver: Temporary Mac Implementation");
int clientWidth = 1024;
int clientHeight = 768;
uint32 clientWidth, clientHeight;
NL3D::MAC::getWindowSize(clientWidth, clientHeight);
#elif defined (NL_OS_UNIX)
@ -2544,11 +2541,8 @@ void CDriverGL::getWindowSize(uint32 &width, uint32 &height)
}
}
#elif defined(NL_OS_MAC) && defined(NL_MAC_NATIVE)
# warning "OpenGL Driver: Temporary Mac Implementation"
// nlwarning("OpenGL Driver: Temporary Mac Implementation");
width = 1024;
height = 768;
NL3D::MAC::getWindowSize(width, height);
#elif defined (NL_OS_UNIX)
XWindowAttributes xwa;
@ -2579,8 +2573,8 @@ void CDriverGL::getWindowPos(uint32 &x, uint32 &y)
}
}
#elif defined(NL_OS_MAC) && defined(NL_MAC_NATIVE)
# warning "OpenGL Driver: Missing Mac Implementation"
nlwarning("OpenGL Driver: Missing Mac Implementation");
NL3D::MAC::getWindowPos(x, y);
#elif defined (NL_OS_UNIX)
x = y = 0;

View file

@ -34,26 +34,43 @@
*
* this can as well be seen as a preparation to pull platform specific code
* out of driver_opengl.cpp ;)
*
* btw: we cannot simply use a c++ class here, because then NSWindow* and friends
* would be members, but then we would need to add obj-c code here using an
* include or a forward declaration. this again would break compiling cpp files
* including this one (eg. driver_opengl.cpp)
*/
namespace NL3D { namespace MAC {
/// mac specific stuff todo while calling CDriverGL::CDriverGL()
/// mac specific stuff while calling CDriverGL::CDriverGL()
void ctor();
/// mac specific stuff todo while calling CDriverGL::~CDriverGL()
/// mac specific stuff while calling CDriverGL::~CDriverGL()
void dtor();
/// mac specific stuff todo while calling CDriverGL::init()
/// mac specific stuff while calling CDriverGL::init()
bool init(uint windowIcon = 0, emptyProc exitFunc = 0);
/// mac specific stuff todo while calling CDriverGL::setDisplay()
/// mac specific stuff while calling CDriverGL::setDisplay()
bool setDisplay(nlWindow wnd, const GfxMode& mode, bool show, bool resizeable);
/// mac specific stuff todo while calling CDriverGL::swapBuffers()
/// mac specific stuff while calling CDriverGL::getWindowSize()
void getWindowSize(uint32 &width, uint32 &height);
/// mac specific stuff while calling CDriverGL::getWindowPos()
void getWindowPos(uint32 &x, uint32 &y);
/// mac specific stuff while calling CDriverGL::setWindowPos()
void setWindowPos(uint32 x, uint32 y);
/// mac specific stuff while calling CDriverGL::setWindowTitle()
void setWindowTitle(const ucstring &title);
/// mac specific stuff while calling CDriverGL::swapBuffers()
void swapBuffers();
/// mac specific stuff todo while calling CCocoaEventEmitter::submitEvents()
/// mac specific stuff while calling CCocoaEventEmitter::submitEvents()
void submitEvents(NLMISC::CEventServer& server,
bool allWindows, NLMISC::CCocoaEventEmitter* eventEmitter);

View file

@ -69,7 +69,8 @@ bool setDisplay(nlWindow wnd, const GfxMode& mode, bool show, bool resizeable)
nldebug("mac cpp bridge called with %u %u %u %u", wnd, &mode, show, resizeable);
// create a window
g_window = [[CocoaWindow alloc] initWithContentRect:NSMakeRect(10, 10, 1024, 768)
/* TODO: NSBackingStoreBuffered ??? */
g_window = [[CocoaWindow alloc] initWithContentRect:NSMakeRect(0, 0, 1024, 768)
styleMask:NSTitledWindowMask | NSResizableWindowMask |
NSClosableWindowMask | NSMiniaturizableWindowMask
backing:NSBackingStoreBuffered
@ -100,7 +101,6 @@ bool setDisplay(nlWindow wnd, const GfxMode& mode, bool show, bool resizeable)
g_glctx = [g_glview openGLContext];
// setup some stuff in the window
[g_window setTitle:@"NeL Cocoa Test"];
[g_window setContentView:g_glview];
[g_window makeKeyAndOrderFront:nil];
[g_window setAcceptsMouseMovedEvents:YES];
@ -117,6 +117,39 @@ bool setDisplay(nlWindow wnd, const GfxMode& mode, bool show, bool resizeable)
return true;
}
void getWindowSize(uint32 &width, uint32 &height)
{
NSRect rect = [g_glview bounds];
width = rect.size.width;
height = rect.size.height;
}
void getWindowPos(uint32 &x, uint32 &y)
{
/*
TODO mac os gives bottom left
*/
NSRect rect = [g_window frame];
x = rect.origin.x;
y = rect.origin.y;
nldebug("%d %d", x, y);
}
void setWindowPos(uint32 x, uint32 y)
{
/*
TODO mac os gets bottom left
*/
[g_window setFrameOrigin:NSMakePoint(x, y)];
}
void setWindowTitle(const ucstring &title)
{
[g_window setTitle:[NSString stringWithUTF8String:title.toUtf8().c_str()]];
}
void swapBuffers()
{
[g_glctx flushBuffer];
@ -274,6 +307,7 @@ void submitEvents(NLMISC::CEventServer& server,
g_pool = [[NSAutoreleasePool alloc] init];
// we break if there was no event to handle
/* TODO maximum? */
while(true)
{
// get the next event to handle
@ -285,11 +319,15 @@ void submitEvents(NLMISC::CEventServer& server,
if(!event)
break;
NSLog(@"%@", event);
// NSLog(@"%@", event);
uint32 width, height;
/* TODO cache? */
getWindowSize(width, height);
// get the mouse position in nel style (relative)
float mouseX = event.locationInWindow.x / 1024.0;
float mouseY = event.locationInWindow.y / 768.0;
float mouseX = event.locationInWindow.x / (float)width;
float mouseY = event.locationInWindow.y / (float)height;
// string to store symbols in case of key press
ucstring ucstr;

View file

@ -27,5 +27,6 @@
-(BOOL)acceptsFirstResponder;
-(BOOL)needsPanelToBecomeKey;
-(void)keyDown:(NSEvent*)event;
@end

View file

@ -30,4 +30,13 @@
return NO;
}
-(void)keyDown:(NSEvent*)event
{
// we handle the key here, so os x does not make a sound :)
/*
TODO do it in the event emitter? eg do not forward key down?
does command+q / command+m still work then?
*/
}
@end