diff --git a/desmume/src/frontend/cocoa/ClientDisplayView.cpp b/desmume/src/frontend/cocoa/ClientDisplayView.cpp index f22409100..92c6589a8 100644 --- a/desmume/src/frontend/cocoa/ClientDisplayView.cpp +++ b/desmume/src/frontend/cocoa/ClientDisplayView.cpp @@ -155,7 +155,7 @@ void ClientDisplayView::GetNDSPoint(const int inputID, const bool isInitialTouch ClientDisplayView::ConvertClientToNormalPoint(this->_property.normalWidth, this->_property.normalHeight, this->_property.clientWidth, this->_property.clientHeight, s, - 360.0 - this->_property.rotation, + this->_property.rotation, x, y); // Normalize the touch location to the DS. diff --git a/desmume/src/frontend/cocoa/OGLDisplayOutput.cpp b/desmume/src/frontend/cocoa/OGLDisplayOutput.cpp index 814d8dd58..672758313 100644 --- a/desmume/src/frontend/cocoa/OGLDisplayOutput.cpp +++ b/desmume/src/frontend/cocoa/OGLDisplayOutput.cpp @@ -71,8 +71,8 @@ static const char *Sample1x1OutputVertShader_100 = {"\ mat2 projection = mat2( vec2(2.0/viewSize.x, 0.0), \n\ vec2( 0.0, 2.0/viewSize.y)); \n\ \n\ - mat2 rotation = mat2( vec2(cos(angleRadians), -sin(angleRadians)), \n\ - vec2(sin(angleRadians), cos(angleRadians))); \n\ + mat2 rotation = mat2( vec2( cos(angleRadians), sin(angleRadians)), \n\ + vec2(-sin(angleRadians), cos(angleRadians))); \n\ \n\ mat2 scale = mat2( vec2(scalar, 0.0), \n\ vec2( 0.0, scalar)); \n\ @@ -105,8 +105,8 @@ static const char *BicubicSample4x4Output_VertShader_110 = {"\ mat2 projection = mat2( vec2(2.0/viewSize.x, 0.0), \n\ vec2( 0.0, 2.0/viewSize.y)); \n\ \n\ - mat2 rotation = mat2( vec2(cos(angleRadians), -sin(angleRadians)), \n\ - vec2(sin(angleRadians), cos(angleRadians))); \n\ + mat2 rotation = mat2( vec2( cos(angleRadians), sin(angleRadians)), \n\ + vec2(-sin(angleRadians), cos(angleRadians))); \n\ \n\ mat2 scale = mat2( vec2(scalar, 0.0), \n\ vec2( 0.0, scalar)); \n\ @@ -161,8 +161,8 @@ static const char *BicubicSample5x5Output_VertShader_110 = {"\ mat2 projection = mat2( vec2(2.0/viewSize.x, 0.0), \n\ vec2( 0.0, 2.0/viewSize.y)); \n\ \n\ - mat2 rotation = mat2( vec2(cos(angleRadians), -sin(angleRadians)), \n\ - vec2(sin(angleRadians), cos(angleRadians))); \n\ + mat2 rotation = mat2( vec2( cos(angleRadians), sin(angleRadians)), \n\ + vec2(-sin(angleRadians), cos(angleRadians))); \n\ \n\ mat2 scale = mat2( vec2(scalar, 0.0), \n\ vec2( 0.0, scalar)); \n\ @@ -228,8 +228,8 @@ static const char *BicubicSample6x6Output_VertShader_110 = {"\ mat2 projection = mat2( vec2(2.0/viewSize.x, 0.0), \n\ vec2( 0.0, 2.0/viewSize.y)); \n\ \n\ - mat2 rotation = mat2( vec2(cos(angleRadians), -sin(angleRadians)), \n\ - vec2(sin(angleRadians), cos(angleRadians))); \n\ + mat2 rotation = mat2( vec2( cos(angleRadians), sin(angleRadians)), \n\ + vec2(-sin(angleRadians), cos(angleRadians))); \n\ \n\ mat2 scale = mat2( vec2(scalar, 0.0), \n\ vec2( 0.0, scalar)); \n\ diff --git a/desmume/src/frontend/cocoa/cocoa_globals.h b/desmume/src/frontend/cocoa/cocoa_globals.h index a52db5e73..363b3daba 100644 --- a/desmume/src/frontend/cocoa/cocoa_globals.h +++ b/desmume/src/frontend/cocoa/cocoa_globals.h @@ -209,8 +209,6 @@ #define SPU_SAMPLE_SIZE ((SPU_SAMPLE_RESOLUTION / 8) * SPU_NUMBER_CHANNELS) // Bytes per sample, multiplied by the number of channels #define SPU_BUFFER_BYTES ((SPU_SAMPLE_RATE / DS_FRAMES_PER_SECOND) * SPU_SAMPLE_SIZE) // Note that this value may be returned as floating point -#define CLOCKWISE_DEGREES(x) (360.0 - x) // Converts an angle in degrees from normal-direction to clockwise-direction. - #define VOLUME_THRESHOLD_LOW 35.0f #define VOLUME_THRESHOLD_HIGH 75.0f diff --git a/desmume/src/frontend/cocoa/userinterface/DisplayWindowController.h b/desmume/src/frontend/cocoa/userinterface/DisplayWindowController.h index bac2c87e8..4629d2aee 100644 --- a/desmume/src/frontend/cocoa/userinterface/DisplayWindowController.h +++ b/desmume/src/frontend/cocoa/userinterface/DisplayWindowController.h @@ -112,6 +112,7 @@ class OGLVideoOutput; BOOL _masterStatusBarState; NSRect _masterWindowFrame; double _masterWindowScale; + double _localRotation; OSSpinLock spinlockScale; OSSpinLock spinlockRotation; diff --git a/desmume/src/frontend/cocoa/userinterface/DisplayWindowController.mm b/desmume/src/frontend/cocoa/userinterface/DisplayWindowController.mm index eb437bc76..39d157a95 100644 --- a/desmume/src/frontend/cocoa/userinterface/DisplayWindowController.mm +++ b/desmume/src/frontend/cocoa/userinterface/DisplayWindowController.mm @@ -117,6 +117,7 @@ static std::unordered_map _screenMap; // _localViewProps.layout = ClientDisplayLayout_Vertical; _localViewProps.order = ClientDisplayOrder_MainFirst; + _localRotation = 0.0; _minDisplayViewSize = NSMakeSize(_localViewProps.clientWidth, _localViewProps.clientHeight + _localViewProps.gapDistance); _isMinSizeNormal = YES; _statusBarHeight = WINDOW_STATUS_BAR_HEIGHT; @@ -192,15 +193,18 @@ static std::unordered_map _screenMap; // } OSSpinLockLock(&spinlockRotation); - _localViewProps.rotation = newAngleDegrees; + _localRotation = newAngleDegrees; OSSpinLockUnlock(&spinlockRotation); + // Convert angle to clockwise-direction degrees (left-handed Cartesian coordinate system). + _localViewProps.rotation = 360.0 - newAngleDegrees; + NSWindow *theWindow = [self window]; // Set the minimum content size for the window, since this will change based on rotation. double contentMinWidth = _minDisplayViewSize.width; double contentMinHeight = _minDisplayViewSize.height; - ClientDisplayView::ConvertNormalToTransformedBounds(1.0, CLOCKWISE_DEGREES(newAngleDegrees), contentMinWidth, contentMinHeight); + ClientDisplayView::ConvertNormalToTransformedBounds(1.0, _localViewProps.rotation, contentMinWidth, contentMinHeight); contentMinHeight += _statusBarHeight; [theWindow setContentMinSize:NSMakeSize(contentMinWidth, contentMinHeight)]; @@ -218,7 +222,7 @@ static std::unordered_map _screenMap; // } DisplayOutputTransformData transformData = { _localViewProps.viewScale, - newAngleDegrees, + _localViewProps.rotation, 0.0, 0.0, 0.0 }; @@ -231,7 +235,7 @@ static std::unordered_map _screenMap; // - (double) displayRotation { OSSpinLockLock(&spinlockRotation); - const double angleDegrees = _localViewProps.rotation; + const double angleDegrees = _localRotation; OSSpinLockUnlock(&spinlockRotation); return angleDegrees; @@ -408,7 +412,7 @@ static std::unordered_map _screenMap; // // Set the minimum content size, keeping the display rotation in mind. double transformedMinWidth = _minDisplayViewSize.width; double transformedMinHeight = _minDisplayViewSize.height; - ClientDisplayView::ConvertNormalToTransformedBounds(1.0, CLOCKWISE_DEGREES([self displayRotation]), transformedMinWidth, transformedMinHeight); + ClientDisplayView::ConvertNormalToTransformedBounds(1.0, _localViewProps.rotation, transformedMinWidth, transformedMinHeight); [[self window] setContentMinSize:NSMakeSize(transformedMinWidth, transformedMinHeight + _statusBarHeight)]; } @@ -510,13 +514,10 @@ static std::unordered_map _screenMap; // return; } - // Convert angle to clockwise-direction degrees. - const double angleDegrees = CLOCKWISE_DEGREES(_localViewProps.rotation); - // Get the maximum scalar size within drawBounds. Constrain scalar to maxScalar if necessary. double checkWidth = _localViewProps.normalWidth; double checkHeight = _localViewProps.normalHeight; - ClientDisplayView::ConvertNormalToTransformedBounds(1.0, angleDegrees, checkWidth, checkHeight); + ClientDisplayView::ConvertNormalToTransformedBounds(1.0, _localViewProps.rotation, checkWidth, checkHeight); const double constrainedScale = [self maxScalarForContentBoundsWidth:checkWidth height:checkHeight]; if (_localViewProps.viewScale > constrainedScale) @@ -529,7 +530,7 @@ static std::unordered_map _screenMap; // // Get the new bounds for the window's content view based on the transformed draw bounds. double transformedWidth = _localViewProps.normalWidth; double transformedHeight = _localViewProps.normalHeight; - ClientDisplayView::ConvertNormalToTransformedBounds(_localViewProps.viewScale, angleDegrees, transformedWidth, transformedHeight); + ClientDisplayView::ConvertNormalToTransformedBounds(_localViewProps.viewScale, _localViewProps.rotation, transformedWidth, transformedHeight); // Get the center of the content view in screen coordinates. const NSRect windowContentRect = [[masterWindow contentView] bounds]; @@ -759,7 +760,7 @@ static std::unordered_map _screenMap; // // Set the minimum content size, keeping the display rotation in mind. double transformedMinWidth = _minDisplayViewSize.width; double transformedMinHeight = _minDisplayViewSize.height; - ClientDisplayView::ConvertNormalToTransformedBounds(1.0, CLOCKWISE_DEGREES([self displayRotation]), transformedMinWidth, transformedMinHeight); + ClientDisplayView::ConvertNormalToTransformedBounds(1.0, _localViewProps.rotation, transformedMinWidth, transformedMinHeight); transformedMinHeight += _statusBarHeight; // Resize the window if it's smaller than the minimum content size. @@ -1275,7 +1276,7 @@ static std::unordered_map _screenMap; // // content Rect. double checkWidth = _localViewProps.normalWidth; double checkHeight = _localViewProps.normalHeight; - ClientDisplayView::ConvertNormalToTransformedBounds(1.0, [self displayRotation], checkWidth, checkHeight); + ClientDisplayView::ConvertNormalToTransformedBounds(1.0, _localViewProps.rotation, checkWidth, checkHeight); const NSSize contentBounds = NSMakeSize(contentRect.size.width, contentRect.size.height - _statusBarHeight); const double constrainedScale = ClientDisplayView::GetMaxScalarWithinBounds(checkWidth, checkHeight, contentBounds.width, contentBounds.height); @@ -1297,7 +1298,7 @@ static std::unordered_map _screenMap; // // Get the max scalar within the window's current content bounds. double checkWidth = _localViewProps.normalWidth; double checkHeight = _localViewProps.normalHeight; - ClientDisplayView::ConvertNormalToTransformedBounds(1.0, [self displayRotation], checkWidth, checkHeight); + ClientDisplayView::ConvertNormalToTransformedBounds(1.0, _localViewProps.rotation, checkWidth, checkHeight); NSSize contentBounds = [[[self window] contentView] bounds].size; contentBounds.height -= _statusBarHeight; @@ -1346,7 +1347,7 @@ static std::unordered_map _screenMap; // // content Rect. double checkWidth = _localViewProps.normalWidth; double checkHeight = _localViewProps.normalHeight; - ClientDisplayView::ConvertNormalToTransformedBounds(1.0, [self displayRotation], checkWidth, checkHeight); + ClientDisplayView::ConvertNormalToTransformedBounds(1.0, _localViewProps.rotation, checkWidth, checkHeight); const NSSize contentBounds = NSMakeSize(contentRect.size.width, contentRect.size.height - _statusBarHeight); const double maxS = ClientDisplayView::GetMaxScalarWithinBounds(checkWidth, checkHeight, contentBounds.width, contentBounds.height);