diff options
Diffstat (limited to 'indra/llwindow')
-rw-r--r-- | indra/llwindow/llopenglview-objc.mm | 54 | ||||
-rw-r--r-- | indra/llwindow/llwindowcallbacks.cpp | 5 | ||||
-rw-r--r-- | indra/llwindow/llwindowcallbacks.h | 1 | ||||
-rw-r--r-- | indra/llwindow/llwindowmacosx-objc.h | 10 | ||||
-rw-r--r-- | indra/llwindow/llwindowmacosx-objc.mm | 24 | ||||
-rw-r--r-- | indra/llwindow/llwindowmacosx.cpp | 46 | ||||
-rw-r--r-- | indra/llwindow/llwindowmacosx.h | 3 |
7 files changed, 107 insertions, 36 deletions
diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index c8c086d705..54a4793b2d 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -28,6 +28,8 @@ #import "llwindowmacosx-objc.h" #import "llappdelegate-objc.h" +extern BOOL gHiDPISupport; + #pragma mark local functions NativeKeyEventData extractKeyDataFromKeyEvent(NSEvent* theEvent) @@ -154,8 +156,8 @@ attributedStringInfo getSegments(NSAttributedString *str) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowResized:) name:NSWindowDidResizeNotification - object:[self window]]; - + object:[self window]]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowWillMiniaturize:) name:NSWindowWillMiniaturizeNotification object:[self window]]; @@ -167,6 +169,17 @@ attributedStringInfo getSegments(NSAttributedString *str) [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(windowDidBecomeKey:) name:NSWindowDidBecomeKeyNotification object:[self window]]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(windowDidChangeScreen:) name:NSWindowDidChangeScreenNotification + object:[self window]]; + + + NSRect wnd_rect = [[self window] frame]; + NSRect dev_rect = [self convertRectToBacking:wnd_rect]; + if (!NSEqualSizes(wnd_rect.size,dev_rect.size)) + { + callResize(dev_rect.size.width, dev_rect.size.height); + } } - (void)setOldResize:(bool)oldresize @@ -178,8 +191,8 @@ attributedStringInfo getSegments(NSAttributedString *str) { if (!mOldResize) //Maint-3288 { - NSSize size = [self frame].size; - callResize(size.width, size.height); + NSSize dev_sz = gHiDPISupport ? [self convertSizeToBacking:[self frame].size] : [self frame].size; + callResize(dev_sz.width, dev_sz.height); } } @@ -198,6 +211,11 @@ attributedStringInfo getSegments(NSAttributedString *str) mModifiers = [NSEvent modifierFlags]; } +-(void)windowDidChangeScreen:(NSNotification *)notification; +{ + callWindowDidChangeScreen(); +} + - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; @@ -258,7 +276,10 @@ attributedStringInfo getSegments(NSAttributedString *str) } [self setPixelFormat:pixelFormat]; - + + //for retina support + [self setWantsBestResolutionOpenGLSurface:gHiDPISupport]; + [self setOpenGLContext:glContext]; [glContext setView:self]; @@ -350,7 +371,7 @@ attributedStringInfo getSegments(NSAttributedString *str) callRightMouseUp(mMousePos, [theEvent modifierFlags]); mSimulatedRightClick = false; } else { - NSPoint mPoint = [theEvent locationInWindow]; + NSPoint mPoint = gHiDPISupport ? [self convertPointToBacking:[theEvent locationInWindow]] : [theEvent locationInWindow]; mMousePos[0] = mPoint.x; mMousePos[1] = mPoint.y; callLeftMouseUp(mMousePos, [theEvent modifierFlags]); @@ -369,14 +390,16 @@ attributedStringInfo getSegments(NSAttributedString *str) - (void)mouseMoved:(NSEvent *)theEvent { - float mouseDeltas[2] = { - float([theEvent deltaX]), - float([theEvent deltaY]) + NSPoint dev_delta = gHiDPISupport ? [self convertPointToBacking:NSMakePoint([theEvent deltaX], [theEvent deltaY])] : NSMakePoint([theEvent deltaX], [theEvent deltaY]); + + float mouseDeltas[] = { + float(dev_delta.x), + float(dev_delta.y) }; callDeltaUpdate(mouseDeltas, 0); - NSPoint mPoint = [theEvent locationInWindow]; + NSPoint mPoint = gHiDPISupport ? [self convertPointToBacking:[theEvent locationInWindow]] : [theEvent locationInWindow]; mMousePos[0] = mPoint.x; mMousePos[1] = mPoint.y; callMouseMoved(mMousePos, 0); @@ -390,14 +413,17 @@ attributedStringInfo getSegments(NSAttributedString *str) // Trust the deltas supplied by NSEvent. // The old CoreGraphics APIs we previously relied on are now flagged as obsolete. // NSEvent isn't obsolete, and provides us with the correct deltas. - float mouseDeltas[2] = { - float([theEvent deltaX]), - float([theEvent deltaY]) + + NSPoint dev_delta = gHiDPISupport ? [self convertPointToBacking:NSMakePoint([theEvent deltaX], [theEvent deltaY])] : NSMakePoint([theEvent deltaX], [theEvent deltaY]); + + float mouseDeltas[] = { + float(dev_delta.x), + float(dev_delta.y) }; callDeltaUpdate(mouseDeltas, 0); - NSPoint mPoint = [theEvent locationInWindow]; + NSPoint mPoint = gHiDPISupport ? [self convertPointToBacking:[theEvent locationInWindow]] : [theEvent locationInWindow]; mMousePos[0] = mPoint.x; mMousePos[1] = mPoint.y; callMouseDragged(mMousePos, 0); diff --git a/indra/llwindow/llwindowcallbacks.cpp b/indra/llwindow/llwindowcallbacks.cpp index 7e90ade423..94c725fc7e 100644 --- a/indra/llwindow/llwindowcallbacks.cpp +++ b/indra/llwindow/llwindowcallbacks.cpp @@ -180,6 +180,11 @@ BOOL LLWindowCallbacks::handleDPIChanged(LLWindow *window, F32 ui_scale_factor, return FALSE; } +BOOL LLWindowCallbacks::handleWindowDidChangeScreen(LLWindow *window) +{ + return FALSE; +} + void LLWindowCallbacks::handlePingWatchdog(LLWindow *window, const char * msg) { diff --git a/indra/llwindow/llwindowcallbacks.h b/indra/llwindow/llwindowcallbacks.h index 47d5a18858..4d753024fe 100644 --- a/indra/llwindow/llwindowcallbacks.h +++ b/indra/llwindow/llwindowcallbacks.h @@ -66,6 +66,7 @@ public: virtual BOOL handleTimerEvent(LLWindow *window); virtual BOOL handleDeviceChange(LLWindow *window); virtual BOOL handleDPIChanged(LLWindow *window, F32 ui_scale_factor, S32 window_width, S32 window_height); + virtual BOOL handleWindowDidChangeScreen(LLWindow *window); enum DragNDropAction { DNDA_START_TRACKING = 0,// Start tracking an incoming drag diff --git a/indra/llwindow/llwindowmacosx-objc.h b/indra/llwindow/llwindowmacosx-objc.h index b06cd2c184..34da99de19 100644 --- a/indra/llwindow/llwindowmacosx-objc.h +++ b/indra/llwindow/llwindowmacosx-objc.h @@ -31,6 +31,9 @@ #include <map> #include <vector> +//fir CGSize +#include <CoreGraphics/CGGeometry.h> + typedef std::vector<std::pair<int, bool> > segment_t; typedef std::vector<int> segment_lengths; @@ -101,11 +104,15 @@ void setResizeMode(bool oldresize, void* glview); NSWindowRef createNSWindow(int x, int y, int width, int height); #include <OpenGL/OpenGL.h> + GLViewRef createOpenGLView(NSWindowRef window, unsigned int samples, bool vsync); void glSwapBuffers(void* context); CGLContextObj getCGLContextObj(GLViewRef view); unsigned long getVramSize(GLViewRef view); -void getContentViewBounds(NSWindowRef window, float* bounds); +float getDeviceUnitSize(GLViewRef view); +const CGPoint & getContentViewBoundsPosition(NSWindowRef window); +const CGSize & getContentViewBoundsSize(NSWindowRef window); +const CGSize & getDeviceContentViewSize(NSWindowRef window, GLViewRef view); void getWindowSize(NSWindowRef window, float* size); void setWindowSize(NSWindowRef window, int width, int height); void getCursorPos(NSWindowRef window, float* pos); @@ -141,6 +148,7 @@ void callWindowFocus(); void callWindowUnfocus(); void callWindowHide(); void callWindowUnhide(); +void callWindowDidChangeScreen(); void callDeltaUpdate(float *delta, unsigned int mask); void callMiddleMouseDown(float *pos, unsigned int mask); void callMiddleMouseUp(float *pos, unsigned int mask); diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index 43ce9a2255..c3eb9b8c8a 100644 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -253,12 +253,24 @@ unsigned long getVramSize(GLViewRef view) return [(LLOpenGLView *)view getVramSize]; } -void getContentViewBounds(NSWindowRef window, float* bounds) +float getDeviceUnitSize(GLViewRef view) { - bounds[0] = [[(LLNSWindow*)window contentView] bounds].origin.x; - bounds[1] = [[(LLNSWindow*)window contentView] bounds].origin.y; - bounds[2] = [[(LLNSWindow*)window contentView] bounds].size.width; - bounds[3] = [[(LLNSWindow*)window contentView] bounds].size.height; + return [(LLOpenGLView*)view convertSizeToBacking:NSMakeSize(1, 1)].width; +} + +const CGPoint & getContentViewBoundsPosition(NSWindowRef window) +{ + return [[(LLNSWindow*)window contentView] bounds].origin; +} + +const CGSize & getContentViewBoundsSize(NSWindowRef window) +{ + return [[(LLNSWindow*)window contentView] bounds].size; +} + +const CGSize & getDeviceContentViewSize(NSWindowRef window, GLViewRef view) +{ + return [(NSOpenGLView*)view convertRectToBacking:[[(LLNSWindow*)window contentView] bounds]].size; } void getWindowSize(NSWindowRef window, float* size) @@ -368,8 +380,8 @@ void closeWindow(NSWindowRef window) void removeGLView(GLViewRef view) { + [(LLOpenGLView*)view clearGLContext]; [(LLOpenGLView*)view removeFromSuperview]; - [(LLOpenGLView*)view release]; } void setupInputWindow(NSWindowRef window, GLViewRef glview) diff --git a/indra/llwindow/llwindowmacosx.cpp b/indra/llwindow/llwindowmacosx.cpp index d4afbb15df..fedea3de08 100644 --- a/indra/llwindow/llwindowmacosx.cpp +++ b/indra/llwindow/llwindowmacosx.cpp @@ -43,6 +43,7 @@ #include <CoreServices/CoreServices.h> extern BOOL gDebugWindowProc; +BOOL gHiDPISupport = TRUE; const S32 BITS_PER_PIXEL = 32; const S32 MAX_NUM_RESOLUTIONS = 32; @@ -400,6 +401,14 @@ void callWindowUnhide() } } +void callWindowDidChangeScreen() +{ + if ( gWindowImplementation && gWindowImplementation->getCallbacks() ) + { + gWindowImplementation->getCallbacks()->handleWindowDidChangeScreen(gWindowImplementation); + } +} + void callDeltaUpdate(float *delta, MASK mask) { gWindowImplementation->updateMouseDeltas(delta); @@ -819,7 +828,6 @@ void LLWindowMacOSX::gatherInput() BOOL LLWindowMacOSX::getPosition(LLCoordScreen *position) { - float rect[4]; S32 err = -1; if(mFullscreen) @@ -830,10 +838,12 @@ BOOL LLWindowMacOSX::getPosition(LLCoordScreen *position) } else if(mWindow) { - getContentViewBounds(mWindow, rect); + const CGPoint & pos = getContentViewBoundsPosition(mWindow); - position->mX = rect[0]; - position->mY = rect[1]; + position->mX = pos.x; + position->mY = pos.y; + + err = noErr; } else { @@ -845,7 +855,6 @@ BOOL LLWindowMacOSX::getPosition(LLCoordScreen *position) BOOL LLWindowMacOSX::getSize(LLCoordScreen *size) { - float rect[4]; S32 err = -1; if(mFullscreen) @@ -856,10 +865,10 @@ BOOL LLWindowMacOSX::getSize(LLCoordScreen *size) } else if(mWindow) { - getContentViewBounds(mWindow, rect); + const CGSize & sz = gHiDPISupport ? getDeviceContentViewSize(mWindow, mGLView) : getContentViewBoundsSize(mWindow); - size->mX = rect[2]; - size->mY = rect[3]; + size->mX = sz.width; + size->mY = sz.height; } else { @@ -871,7 +880,6 @@ BOOL LLWindowMacOSX::getSize(LLCoordScreen *size) BOOL LLWindowMacOSX::getSize(LLCoordWindow *size) { - float rect[4]; S32 err = -1; if(mFullscreen) @@ -882,10 +890,10 @@ BOOL LLWindowMacOSX::getSize(LLCoordWindow *size) } else if(mWindow) { - getContentViewBounds(mWindow, rect); + const CGSize & sz = gHiDPISupport ? getDeviceContentViewSize(mWindow, mGLView) : getContentViewBoundsSize(mWindow); - size->mX = rect[2]; - size->mY = rect[3]; + size->mX = sz.width; + size->mY = sz.height; } else { @@ -1094,6 +1102,9 @@ BOOL LLWindowMacOSX::setCursorPosition(const LLCoordWindow position) // trigger mouse move callback LLCoordGL gl_pos; convertCoords(position, &gl_pos); + float scale = getSystemUISize(); + gl_pos.mX *= scale; + gl_pos.mY *= scale; mCallbacks->handleMouseMove(this, gl_pos, (MASK)0); return result; @@ -1124,8 +1135,9 @@ BOOL LLWindowMacOSX::getCursorPosition(LLCoordWindow *position) cursor_point[1] += mCursorLastEventDeltaY; } - position->mX = cursor_point[0]; - position->mY = cursor_point[1]; + float scale = getSystemUISize(); + position->mX = cursor_point[0] * scale; + position->mY = cursor_point[1] * scale; return TRUE; } @@ -1334,6 +1346,7 @@ BOOL LLWindowMacOSX::convertCoords(LLCoordWindow from, LLCoordScreen *to) mouse_point[0] = from.mX; mouse_point[1] = from.mY; + convertWindowToScreen(mWindow, mouse_point); to->mX = mouse_point[0]; @@ -1889,6 +1902,11 @@ MASK LLWindowMacOSX::modifiersToMask(S16 modifiers) return mask; } +F32 LLWindowMacOSX::getSystemUISize() +{ + return gHiDPISupport ? ::getDeviceUnitSize(mGLView) : LLWindow::getSystemUISize(); +} + #if LL_OS_DRAGDROP_ENABLED /* S16 LLWindowMacOSX::dragTrackingHandler(DragTrackingMessage message, WindowRef theWindow, diff --git a/indra/llwindow/llwindowmacosx.h b/indra/llwindow/llwindowmacosx.h index 9e9bd8ae39..24651027e8 100644 --- a/indra/llwindow/llwindowmacosx.h +++ b/indra/llwindow/llwindowmacosx.h @@ -112,6 +112,7 @@ public: /*virtual*/ void allowLanguageTextInput(LLPreeditor *preeditor, BOOL b); /*virtual*/ void interruptLanguageTextInput(); /*virtual*/ void spawnWebBrowser(const std::string& escaped_url, bool async); + /*virtual*/ F32 getSystemUISize(); static std::vector<std::string> getDynamicFallbackFontList(); @@ -135,7 +136,7 @@ protected: BOOL fullscreen, BOOL clearBg, BOOL disable_vsync, BOOL use_gl, BOOL ignore_pixel_depth, U32 fsaa_samples); - ~LLWindowMacOSX(); + ~LLWindowMacOSX(); void initCursors(); BOOL isValid(); |