summaryrefslogtreecommitdiff
path: root/indra/llwindow
diff options
context:
space:
mode:
authorGeenz <geenz@geenzo.com>2012-12-29 06:59:43 -0500
committerGeenz <geenz@geenzo.com>2012-12-29 06:59:43 -0500
commitbd152c1fb75c4a8d4b9271896c44243ca8759e58 (patch)
treece85602e2ca58b894524e1a3fc426a0d138f41b4 /indra/llwindow
parentc8aa1fb7c8ed44886599ea4e04eed403392e2e34 (diff)
Huge amount of refactoring to use Cocoa here:
- Updated to .xib format. To produce a new nib (which is required after changing the xib file), use "ibtool SecondLife.xib --compile SecondLife.nib" within the newview directory. - xib file now defines the viewer's window. VIews are still being pragmatically added to the main window. This may change in the future. - LLAppViewer's main loop has been slightly refactored to be executed on a timer for OS X. This probably needs a bit more work. - Event handling still needs more work to work within a timer based event loop. It works fairly sporadically at the moment, as if events are being dropped between timer executions, at least for the mouse. - Carbon has been purged from the viewer's startup, and from LLWindow entirely. There's likely still a few odds and ends fragmented throughout the viewer and its dependencies. Need to track these down. - LLAppViewerMacOSX now uses NSApplicationMain, and also implements the NSApplicationDelegate protocol in LLAppDelegate. - Fullscreen support has been implemented for OS X 10.7+ This is still a work in progress, however at this stage everything needed for a functional viewer is (mostly) complete. From here, it's mostly just bug hunting and fixing.
Diffstat (limited to 'indra/llwindow')
-rw-r--r--indra/llwindow/llopenglview-objc.h7
-rw-r--r--indra/llwindow/llopenglview-objc.mm140
-rw-r--r--indra/llwindow/llwindowmacosx-objc.h4
-rw-r--r--indra/llwindow/llwindowmacosx-objc.mm19
-rw-r--r--indra/llwindow/llwindowmacosx.cpp133
-rw-r--r--indra/llwindow/llwindowmacosx.h2
6 files changed, 120 insertions, 185 deletions
diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h
index 8abe81ce9e..6b055bc665 100644
--- a/indra/llwindow/llopenglview-objc.h
+++ b/indra/llwindow/llopenglview-objc.h
@@ -69,4 +69,9 @@
- (void) registerMouseExitCallback:(VoidCallback)callback;
- (void) registerDeltaUpdateCallback:(MouseCallback)callback;
-@end \ No newline at end of file
+@end
+
+void setLLNSWindowRef(LLNSWindow* window);
+void setLLOpenGLViewRef(LLOpenGLView* view);
+LLNSWindow* winRef;
+LLOpenGLView* glviewRef;
diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm
index a96c4cf82c..7c148f4acd 100644
--- a/indra/llwindow/llopenglview-objc.mm
+++ b/indra/llwindow/llopenglview-objc.mm
@@ -19,9 +19,12 @@
- (void)windowResized:(NSNotification *)notification;
{
- NSSize size = [[self window] frame].size;
-
- mResizeCallback(size.width, size.height);
+ if (mResizeCallback != nil)
+ {
+ NSSize size = [[self window] frame].size;
+
+ mResizeCallback(size.width, size.height);
+ }
}
- (void)dealloc
@@ -194,23 +197,29 @@
}
- (void) keyDown:(NSEvent *)theEvent {
- mKeyDownCallback([theEvent keyCode], [theEvent modifierFlags]);
-
- NSString *chars = [theEvent charactersIgnoringModifiers];
- for (uint i = 0; i < [chars length]; i++)
+ if (mKeyDownCallback != nil && mUnicodeCallback != nil)
{
- mUnicodeCallback([chars characterAtIndex:i], [theEvent modifierFlags]);
- }
-
- // The viewer expects return to be submitted separately as a unicode character.
- if ([theEvent keyCode] == 3 || [theEvent keyCode] == 13)
- {
- mUnicodeCallback([theEvent keyCode], [theEvent modifierFlags]);
+ mKeyDownCallback([theEvent keyCode], [theEvent modifierFlags]);
+
+ NSString *chars = [theEvent charactersIgnoringModifiers];
+ for (uint i = 0; i < [chars length]; i++)
+ {
+ mUnicodeCallback([chars characterAtIndex:i], [theEvent modifierFlags]);
+ }
+
+ // The viewer expects return to be submitted separately as a unicode character.
+ if ([theEvent keyCode] == 3 || [theEvent keyCode] == 13)
+ {
+ mUnicodeCallback([theEvent keyCode], [theEvent modifierFlags]);
+ }
}
}
- (void) keyUp:(NSEvent *)theEvent {
- mKeyUpCallback([theEvent keyCode], [theEvent modifierFlags]);
+ if (mKeyUpCallback != nil)
+ {
+ mKeyUpCallback([theEvent keyCode], [theEvent modifierFlags]);
+ }
}
- (void)flagsChanged:(NSEvent *)theEvent {
@@ -219,41 +228,59 @@
- (void) mouseDown:(NSEvent *)theEvent
{
- if ([theEvent clickCount] == 2)
+ if (mMouseDoubleClickCallback != nil && mMouseDownCallback != nil)
{
- mMouseDoubleClickCallback(mMousePos, [theEvent modifierFlags]);
- } else if ([theEvent clickCount] == 1) {
- mMouseDownCallback(mMousePos, [theEvent modifierFlags]);
+ if ([theEvent clickCount] == 2)
+ {
+ mMouseDoubleClickCallback(mMousePos, [theEvent modifierFlags]);
+ } else if ([theEvent clickCount] == 1) {
+ mMouseDownCallback(mMousePos, [theEvent modifierFlags]);
+ }
}
}
- (void) mouseUp:(NSEvent *)theEvent
{
- mMouseUpCallback(mMousePos, [theEvent modifierFlags]);
+ if (mMouseUpCallback != nil)
+ {
+ mMouseUpCallback(mMousePos, [theEvent modifierFlags]);
+ }
}
- (void) rightMouseDown:(NSEvent *)theEvent
{
- mRightMouseDownCallback(mMousePos, [theEvent modifierFlags]);
+ if (mRightMouseDownCallback != nil)
+ {
+ mRightMouseDownCallback(mMousePos, [theEvent modifierFlags]);
+ }
}
- (void) rightMouseUp:(NSEvent *)theEvent
{
- mRightMouseUpCallback(mMousePos, [theEvent modifierFlags]);
+ if (mRightMouseUpCallback != nil)
+ {
+ mRightMouseUpCallback(mMousePos, [theEvent modifierFlags]);
+ }
}
- (void)mouseMoved:(NSEvent *)theEvent {
- float mouseDeltas[2] = {
- [theEvent deltaX],
- [theEvent deltaZ]
- };
-
- mDeltaUpdateCallback(mouseDeltas, 0);
-
- NSPoint mPoint = [theEvent locationInWindow];
- mMousePos[0] = mPoint.x;
- mMousePos[1] = mPoint.y;
- mMouseMovedCallback(mMousePos, 0);
+ if (mDeltaUpdateCallback != nil && mMouseMovedCallback != nil)
+ {
+ float mouseDeltas[2] = {
+ [theEvent deltaX],
+ [theEvent deltaZ]
+ };
+
+ mDeltaUpdateCallback(mouseDeltas, 0);
+
+ NSPoint mPoint = [theEvent locationInWindow];
+ mMousePos[0] = mPoint.x;
+ mMousePos[1] = mPoint.y;
+ if (mMouseMovedCallback != nil)
+ {
+ mMouseMovedCallback(mMousePos, 0);
+ }
+ }
}
// NSWindow doesn't trigger mouseMoved when the mouse is being clicked and dragged.
@@ -261,27 +288,36 @@
- (void) mouseDragged:(NSEvent *)theEvent
{
- float mouseDeltas[2] = {
- [theEvent deltaX],
- [theEvent deltaZ]
- };
-
- mDeltaUpdateCallback(mouseDeltas, 0);
-
- NSPoint mPoint = [theEvent locationInWindow];
- mMousePos[0] = mPoint.x;
- mMousePos[1] = mPoint.y;
- mMouseMovedCallback(mMousePos, 0);
+ if (mDeltaUpdateCallback != nil && mMouseMovedCallback != nil)
+ {
+ float mouseDeltas[2] = {
+ [theEvent deltaX],
+ [theEvent deltaZ]
+ };
+
+ mDeltaUpdateCallback(mouseDeltas, 0);
+
+ NSPoint mPoint = [theEvent locationInWindow];
+ mMousePos[0] = mPoint.x;
+ mMousePos[1] = mPoint.y;
+ mMouseMovedCallback(mMousePos, 0);
+ }
}
- (void) scrollWheel:(NSEvent *)theEvent
{
- mScrollWhellCallback(-[theEvent deltaY]);
+ if (mScrollWhellCallback != nil)
+ {
+ mScrollWhellCallback(-[theEvent deltaY]);
+ }
}
- (void) mouseExited:(NSEvent *)theEvent
{
- mMouseExitCallback();
+ if (mMouseExitCallback != nil)
+ {
+ mMouseExitCallback();
+ }
}
- (void) registerKeyDownCallback:(KeyCallback)callback
@@ -349,4 +385,14 @@
mDeltaUpdateCallback = callback;
}
-@end \ No newline at end of file
+@end
+
+void setLLNSWindowRef(LLNSWindow* window)
+{
+ winRef = window;
+}
+
+void setLLOpenGLViewRef(LLOpenGLView* view)
+{
+ glviewRef = view;
+}
diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h
index 47ae13cb25..abaeda1f91 100644
--- a/indra/llwindow/llwindowmacosx-objc.h
+++ b/indra/llwindow/llwindowmacosx-objc.h
@@ -57,7 +57,7 @@ NSWindowRef createNSWindow(int x, int y, int width, int height);
#include <OpenGL/OpenGL.h>
GLViewRef createOpenGLView(NSWindowRef window);
void glSwapBuffers(void* context);
-CGLContextObj getCGLContextObj(NSWindowRef window);
+CGLContextObj getCGLContextObj(GLViewRef view);
void getContentViewBounds(NSWindowRef window, float* bounds);
void getWindowSize(NSWindowRef window, float* size);
void setWindowSize(NSWindowRef window, int width, int height);
@@ -80,5 +80,7 @@ void registerMouseMovedCallback(NSWindowRef window, MouseCallback callback);
void registerScrollCallback(NSWindowRef window, ScrollWheelCallback callback);
void registerMouseExitCallback(NSWindowRef window, VoidCallback callback);
void registerDeltaUpdateCallback(NSWindowRef window, MouseCallback callback);
+NSWindowRef getMainAppWindow();
+GLViewRef getGLView(NSWindowRef window);
unsigned int getModifiers();
diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm
index 03c0f55883..07efc25ea6 100644
--- a/indra/llwindow/llwindowmacosx-objc.mm
+++ b/indra/llwindow/llwindowmacosx-objc.mm
@@ -54,10 +54,10 @@ void setupCocoa()
// http://developer.apple.com/samplecode/CarbonCocoa_PictureCursor/index.html
// Needed for Carbon based applications which call into Cocoa
- NSApplicationLoad();
+ // NSApplicationLoad();
// Must first call [[[NSWindow alloc] init] release] to get the NSWindow machinery set up so that NSCursor can use a window to cache the cursor image
- [[[NSWindow alloc] init] release];
+ //[[[NSWindow alloc] init] release];
[pool release];
@@ -188,10 +188,9 @@ void glSwapBuffers(void* context)
[(NSOpenGLContext*)context flushBuffer];
}
-CGLContextObj getCGLContextObj(NSWindowRef window)
+CGLContextObj getCGLContextObj(GLViewRef view)
{
- LLOpenGLView *glview = [(LLNSWindow*)window contentView];
- return [glview getCGLContextObj];
+ return [(LLOpenGLView *)view getCGLContextObj];
}
CGLPixelFormatObj* getCGLPixelFormatObj(NSWindowRef window)
@@ -331,6 +330,16 @@ void registerDeltaUpdateCallback(NSWindowRef window, MouseCallback callback)
[(LLNSWindow*)window registerDeltaUpdateCallback:callback];
}
+NSWindowRef getMainAppWindow()
+{
+ return winRef;
+}
+
+GLViewRef getGLView(NSWindowRef window)
+{
+ return glviewRef;
+}
+
unsigned int getModifiers()
{
return [NSEvent modifierFlags];
diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp
index 1fb8bea802..a616b2df2d 100644
--- a/indra/llwindow/llwindowmacosx.cpp
+++ b/indra/llwindow/llwindowmacosx.cpp
@@ -38,7 +38,6 @@
#include "lldir.h"
#include "indra_constants.h"
-#include <Carbon/Carbon.h>
#include <OpenGL/OpenGL.h>
extern BOOL gDebugWindowProc;
@@ -342,7 +341,7 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits
if (mWindow == NULL)
{
LL_INFOS("Window") << "Creating window..." << LL_ENDL;
- mWindow = createNSWindow(x, y, width, height);
+ mWindow = getMainAppWindow();
LL_INFOS("Window") << "Registering key callbacks..." << LL_ENDL;
registerKeyDownCallback(mWindow, callKeyDown);
registerKeyUpCallback(mWindow, callKeyUp);
@@ -361,9 +360,11 @@ BOOL LLWindowMacOSX::createContext(int x, int y, int width, int height, int bits
if(mContext == NULL)
{
LL_INFOS("Window") << "Creating GL view..." << LL_ENDL;
+ // Our OpenGL view is already defined within SecondLife.xib.
+ // Get the view instead.
mGLView = createOpenGLView(mWindow);
registerResizeEventCallback(mGLView, callResize);
- mContext = getCGLContextObj(mWindow);
+ mContext = getCGLContextObj(mGLView);
// Since we just created the context, it needs to be set up.
glNeedsInit = TRUE;
}
@@ -577,132 +578,6 @@ void LLWindowMacOSX::gatherInput()
stopDockTileBounce();
}
- EventRecord evt;
- while(WaitNextEvent(everyEvent, &evt, 0, NULL))
- {
- // printf("WaitNextEvent returned true, event is %d.\n", evt.what);
- switch(evt.what)
- {
- case mouseDown:
- {
- short part;
- WindowRef window;
- long selectResult;
- part = FindWindow(evt.where, &window);
- switch ( part )
- {
- case inMenuBar:
- selectResult = MenuSelect(evt.where);
-
- HiliteMenu(0);
- break;
- }
- }
- break;
-
- case kHighLevelEvent:
- AEProcessAppleEvent (&evt);
- break;
-
- case updateEvt:
- // We shouldn't be getting these regularly (since our window will be buffered), but we need to handle them correctly...
- BeginUpdate((WindowRef)evt.message);
- EndUpdate((WindowRef)evt.message);
- break;
-
- }
- }
- /*
- U32 event = getLatestEvent(mWindow);
- switch (event) {
- case 0:
- // Nothing's happened since our last handled event.
- break;
-
- case 1:
- {
- gKeyboard->handleKeyDown(getKeyDown(mWindow), getModifiers(mWindow));
- mCallbacks->handleUnicodeChar(getLastCharacter(mWindow), gKeyboard->currentMask(FALSE)); // currentMask has the appropriately translated modifiers.
- mLastModifiers = gKeyboard->currentMask(FALSE);
- }
- break;
-
- case 2:
- gKeyboard->handleKeyUp(getKeyUp(mWindow), getModifiers(mWindow));
- mLastModifiers = gKeyboard->currentMask(FALSE);
- break;
-
- case 3:
- break;
-
- case 4:
- {
- LLCoordScreen inCoords;
- LLCoordGL outCoords;
- float* mouseCoords = getMouseDown(mWindow);
- inCoords.mX = llround(mouseCoords[0]);
- inCoords.mY = llround(mouseCoords[1]);
- convertCoords(inCoords, &outCoords);
- mCallbacks->handleMouseDown(this, outCoords, getModifiers(mWindow));
- mLastModifiers = gKeyboard->currentMask(FALSE);
- }
- break;
- case 5:
- {
- LLCoordScreen inCoords;
- LLCoordGL outCoords;
- float* mouseCoords = getMouseUp(mWindow);
- inCoords.mX = llround(mouseCoords[0]);
- inCoords.mY = llround(mouseCoords[1]);
- convertCoords(inCoords, &outCoords);
- mCallbacks->handleMouseUp(this, outCoords, getModifiers(mWindow));
- mLastModifiers = gKeyboard->currentMask(FALSE);
- }
- break;
- case 6:
- {
- LLCoordScreen inCoords;
- LLCoordGL outCoords;
- float* mouseCoords = getRightMouseDown(mWindow);
- inCoords.mX = llround(mouseCoords[0]);
- inCoords.mY = llround(mouseCoords[1]);
- convertCoords(inCoords, &outCoords);
- mCallbacks->handleRightMouseDown(this, outCoords, getModifiers(mWindow));
- mLastModifiers = gKeyboard->currentMask(FALSE);
- }
- break;
- case 7:
- {
- LLCoordScreen inCoords;
- LLCoordGL outCoords;
- float* mouseCoords = getRightMouseDown(mWindow);
- inCoords.mX = llround(mouseCoords[0]);
- inCoords.mY = llround(mouseCoords[1]);
- convertCoords(inCoords, &outCoords);
- mCallbacks->handleRightMouseDown(this, outCoords, getModifiers(mWindow));
- mLastModifiers = gKeyboard->currentMask(FALSE);
- }
- break;
- case 8: // Double click
- {
- LLCoordScreen inCoords;
- LLCoordGL outCoords;
- float* mouseCoords = getRightMouseDown(mWindow);
- inCoords.mX = llround(mouseCoords[0]);
- inCoords.mY = llround(mouseCoords[1]);
- convertCoords(inCoords, &outCoords);
- mCallbacks->handleDoubleClick(this, outCoords, getModifiers(mWindow));
- mLastModifiers = gKeyboard->currentMask(FALSE);
- }
- break;
- case 10: // Text input (for IMEs)
-
- break;
- default:
- break;
-
- }*/
-
updateCursor();
}
diff --git a/indra/llwindow/llwindowmacosx.h b/indra/llwindow/llwindowmacosx.h
index a821dcabd8..487af7658f 100644
--- a/indra/llwindow/llwindowmacosx.h
+++ b/indra/llwindow/llwindowmacosx.h
@@ -33,8 +33,6 @@
#include "lltimer.h"
-//#include <Carbon/Carbon.h>
-//#include <AGL/agl.h>
#include <ApplicationServices/ApplicationServices.h>
#include <OpenGL/OpenGL.h>