mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-12-03 17:14:46 +00:00
Changed: #947 window title, position, resize. fixed notify sound on key down.
This commit is contained in:
parent
7e3fb9f078
commit
b5c8752872
5 changed files with 84 additions and 25 deletions
|
@ -1770,8 +1770,7 @@ void CDriverGL::setWindowTitle(const ucstring &title)
|
||||||
SetWindowTextW(_hWnd,(WCHAR*)title.c_str());
|
SetWindowTextW(_hWnd,(WCHAR*)title.c_str());
|
||||||
|
|
||||||
#elif defined(NL_OS_MAC) && defined(NL_MAC_NATIVE)
|
#elif defined(NL_OS_MAC) && defined(NL_MAC_NATIVE)
|
||||||
# warning "OpenGL Driver: Missing Mac Implementation"
|
NL3D::MAC::setWindowTitle(title);
|
||||||
nlwarning("OpenGL Driver: Missing Mac Implementation");
|
|
||||||
|
|
||||||
#elif defined (NL_OS_UNIX)
|
#elif defined (NL_OS_UNIX)
|
||||||
XTextProperty text_property;
|
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);
|
SetWindowPos(_hWnd, NULL, _WindowX, _WindowY, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
|
||||||
|
|
||||||
#elif defined(NL_OS_MAC) && defined(NL_MAC_NATIVE)
|
#elif defined(NL_OS_MAC) && defined(NL_MAC_NATIVE)
|
||||||
# warning "OpenGL Driver: Missing Mac Implementation"
|
NL3D::MAC::setWindowPos(x, y);
|
||||||
nlwarning("OpenGL Driver: Missing Mac Implementation");
|
|
||||||
|
|
||||||
#elif defined (NL_OS_UNIX)
|
#elif defined (NL_OS_UNIX)
|
||||||
XMoveWindow(dpy, win, _WindowX, _WindowY);
|
XMoveWindow(dpy, win, _WindowX, _WindowY);
|
||||||
|
|
||||||
#endif // NL_OS_WINDOWS
|
#endif // NL_OS_WINDOWS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2289,11 +2288,9 @@ void CDriverGL::setupViewport (const class CViewport& viewport)
|
||||||
int clientHeight = _WindowHeight;
|
int clientHeight = _WindowHeight;
|
||||||
|
|
||||||
#elif defined(NL_OS_MAC) && defined(NL_MAC_NATIVE)
|
#elif defined(NL_OS_MAC) && defined(NL_MAC_NATIVE)
|
||||||
# warning "OpenGL Driver: Temporary Mac Implementation"
|
|
||||||
// nlwarning("OpenGL Driver: Temporary Mac Implementation");
|
|
||||||
|
|
||||||
int clientWidth = 1024;
|
uint32 clientWidth, clientHeight;
|
||||||
int clientHeight = 768;
|
NL3D::MAC::getWindowSize(clientWidth, clientHeight);
|
||||||
|
|
||||||
#elif defined (NL_OS_UNIX)
|
#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)
|
#elif defined(NL_OS_MAC) && defined(NL_MAC_NATIVE)
|
||||||
# warning "OpenGL Driver: Temporary Mac Implementation"
|
|
||||||
// nlwarning("OpenGL Driver: Temporary Mac Implementation");
|
|
||||||
|
|
||||||
width = 1024;
|
NL3D::MAC::getWindowSize(width, height);
|
||||||
height = 768;
|
|
||||||
|
|
||||||
#elif defined (NL_OS_UNIX)
|
#elif defined (NL_OS_UNIX)
|
||||||
XWindowAttributes xwa;
|
XWindowAttributes xwa;
|
||||||
|
@ -2579,8 +2573,8 @@ void CDriverGL::getWindowPos(uint32 &x, uint32 &y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#elif defined(NL_OS_MAC) && defined(NL_MAC_NATIVE)
|
#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)
|
#elif defined (NL_OS_UNIX)
|
||||||
x = y = 0;
|
x = y = 0;
|
||||||
|
|
|
@ -34,26 +34,43 @@
|
||||||
*
|
*
|
||||||
* this can as well be seen as a preparation to pull platform specific code
|
* this can as well be seen as a preparation to pull platform specific code
|
||||||
* out of driver_opengl.cpp ;)
|
* 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 {
|
namespace NL3D { namespace MAC {
|
||||||
|
|
||||||
/// mac specific stuff todo while calling CDriverGL::CDriverGL()
|
/// mac specific stuff while calling CDriverGL::CDriverGL()
|
||||||
void ctor();
|
void ctor();
|
||||||
|
|
||||||
/// mac specific stuff todo while calling CDriverGL::~CDriverGL()
|
/// mac specific stuff while calling CDriverGL::~CDriverGL()
|
||||||
void dtor();
|
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);
|
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);
|
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();
|
void swapBuffers();
|
||||||
|
|
||||||
/// mac specific stuff todo while calling CCocoaEventEmitter::submitEvents()
|
/// mac specific stuff while calling CCocoaEventEmitter::submitEvents()
|
||||||
void submitEvents(NLMISC::CEventServer& server,
|
void submitEvents(NLMISC::CEventServer& server,
|
||||||
bool allWindows, NLMISC::CCocoaEventEmitter* eventEmitter);
|
bool allWindows, NLMISC::CCocoaEventEmitter* eventEmitter);
|
||||||
|
|
||||||
|
|
|
@ -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);
|
nldebug("mac cpp bridge called with %u %u %u %u", wnd, &mode, show, resizeable);
|
||||||
|
|
||||||
// create a window
|
// 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 |
|
styleMask:NSTitledWindowMask | NSResizableWindowMask |
|
||||||
NSClosableWindowMask | NSMiniaturizableWindowMask
|
NSClosableWindowMask | NSMiniaturizableWindowMask
|
||||||
backing:NSBackingStoreBuffered
|
backing:NSBackingStoreBuffered
|
||||||
|
@ -100,7 +101,6 @@ bool setDisplay(nlWindow wnd, const GfxMode& mode, bool show, bool resizeable)
|
||||||
g_glctx = [g_glview openGLContext];
|
g_glctx = [g_glview openGLContext];
|
||||||
|
|
||||||
// setup some stuff in the window
|
// setup some stuff in the window
|
||||||
[g_window setTitle:@"NeL Cocoa Test"];
|
|
||||||
[g_window setContentView:g_glview];
|
[g_window setContentView:g_glview];
|
||||||
[g_window makeKeyAndOrderFront:nil];
|
[g_window makeKeyAndOrderFront:nil];
|
||||||
[g_window setAcceptsMouseMovedEvents:YES];
|
[g_window setAcceptsMouseMovedEvents:YES];
|
||||||
|
@ -117,6 +117,39 @@ bool setDisplay(nlWindow wnd, const GfxMode& mode, bool show, bool resizeable)
|
||||||
return true;
|
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()
|
void swapBuffers()
|
||||||
{
|
{
|
||||||
[g_glctx flushBuffer];
|
[g_glctx flushBuffer];
|
||||||
|
@ -274,6 +307,7 @@ void submitEvents(NLMISC::CEventServer& server,
|
||||||
g_pool = [[NSAutoreleasePool alloc] init];
|
g_pool = [[NSAutoreleasePool alloc] init];
|
||||||
|
|
||||||
// we break if there was no event to handle
|
// we break if there was no event to handle
|
||||||
|
/* TODO maximum? */
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
// get the next event to handle
|
// get the next event to handle
|
||||||
|
@ -285,11 +319,15 @@ void submitEvents(NLMISC::CEventServer& server,
|
||||||
if(!event)
|
if(!event)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
NSLog(@"%@", event);
|
// NSLog(@"%@", event);
|
||||||
|
|
||||||
|
uint32 width, height;
|
||||||
|
/* TODO cache? */
|
||||||
|
getWindowSize(width, height);
|
||||||
|
|
||||||
// get the mouse position in nel style (relative)
|
// get the mouse position in nel style (relative)
|
||||||
float mouseX = event.locationInWindow.x / 1024.0;
|
float mouseX = event.locationInWindow.x / (float)width;
|
||||||
float mouseY = event.locationInWindow.y / 768.0;
|
float mouseY = event.locationInWindow.y / (float)height;
|
||||||
|
|
||||||
// string to store symbols in case of key press
|
// string to store symbols in case of key press
|
||||||
ucstring ucstr;
|
ucstring ucstr;
|
||||||
|
|
|
@ -27,5 +27,6 @@
|
||||||
|
|
||||||
-(BOOL)acceptsFirstResponder;
|
-(BOOL)acceptsFirstResponder;
|
||||||
-(BOOL)needsPanelToBecomeKey;
|
-(BOOL)needsPanelToBecomeKey;
|
||||||
|
-(void)keyDown:(NSEvent*)event;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -30,4 +30,13 @@
|
||||||
return NO;
|
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
|
@end
|
||||||
|
|
Loading…
Reference in a new issue