1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

Merge pull request #26662 from RoshniUG:4.x

Update window_cocoa.mm #26662

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
- [x ] Added reference to the original bug report (#26661).
- [x]Updated the code as per the reviewer's suggestion to use a ternary operator.
- [x] Verified that the feature is properly documented and can be built with CMake.
This commit is contained in:
RoshniUG
2025-02-08 12:20:53 +05:30
committed by GitHub
parent aeac913203
commit b323780460
+15 -2
View File
@@ -784,6 +784,7 @@ void cvSetPropTopmost_COCOA( const char* name, const bool topmost )
void setWindowTitle_COCOA(const cv::String& winname, const cv::String& title)
{
@autoreleasepool{
CVWindow *window = cvGetWindow(winname.c_str());
@@ -799,6 +800,7 @@ void setWindowTitle_COCOA(const cv::String& winname, const cv::String& title)
NSString *windowTitle = [NSString stringWithFormat:@"%s", title.c_str()];
[window setTitle:windowTitle];
}
}
static NSSize constrainAspectRatio(NSSize base, NSSize constraint) {
@@ -874,8 +876,19 @@ static NSSize constrainAspectRatio(NSSize base, NSSize constraint) {
if([event modifierFlags] & NSControlKeyMask) flags |= CV_EVENT_FLAG_CTRLKEY;
if([event modifierFlags] & NSAlternateKeyMask) flags |= CV_EVENT_FLAG_ALTKEY;
if([event type] == NSLeftMouseDown) {[self cvSendMouseEvent:event type:CV_EVENT_LBUTTONDOWN flags:flags | CV_EVENT_FLAG_LBUTTON];}
if([event type] == NSLeftMouseUp) {[self cvSendMouseEvent:event type:CV_EVENT_LBUTTONUP flags:flags | CV_EVENT_FLAG_LBUTTON];}
//modified code using ternary operator:
if ([event type] == NSLeftMouseDown) {
[self cvSendMouseEvent:event
type:([event modifierFlags] & NSControlKeyMask) ? CV_EVENT_RBUTTONDOWN : CV_EVENT_LBUTTONDOWN
flags:flags | (([event modifierFlags] & NSControlKeyMask) ? CV_EVENT_FLAG_RBUTTON : CV_EVENT_FLAG_LBUTTON)];
}
if ([event type] == NSLeftMouseUp) {
[self cvSendMouseEvent:event
type:([event modifierFlags] & NSControlKeyMask) ? CV_EVENT_RBUTTONUP : CV_EVENT_LBUTTONUP
flags:flags | (([event modifierFlags] & NSControlKeyMask) ? CV_EVENT_FLAG_RBUTTON : CV_EVENT_FLAG_LBUTTON)];
}
if([event type] == NSRightMouseDown){[self cvSendMouseEvent:event type:CV_EVENT_RBUTTONDOWN flags:flags | CV_EVENT_FLAG_RBUTTON];}
if([event type] == NSRightMouseUp) {[self cvSendMouseEvent:event type:CV_EVENT_RBUTTONUP flags:flags | CV_EVENT_FLAG_RBUTTON];}
if([event type] == NSOtherMouseDown){[self cvSendMouseEvent:event type:CV_EVENT_MBUTTONDOWN flags:flags];}