Merge pull request #16588 from vpisarev:fix_macos_move_window

fixed cv::moveWindow() on mac

* fixed cv::moveWindow() on mac (issue #16343). Thanks to cwreynolds and saskatchewancatch for the help!

* fixed warnings about _x0 and _y0

* fixed warnings about _x0 and _y0
This commit is contained in:
Vadim Pisarevsky 2020-02-17 14:54:36 +03:00 committed by GitHub
parent d84360e7f3
commit d67a6c1be4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -111,11 +111,14 @@ static bool wasInitialized = false;
BOOL autosize; BOOL autosize;
BOOL firstContent; BOOL firstContent;
int status; int status;
int x0, y0;
} }
@property(assign) CvMouseCallback mouseCallback; @property(assign) CvMouseCallback mouseCallback;
@property(assign) void *mouseParam; @property(assign) void *mouseParam;
@property(assign) BOOL autosize; @property(assign) BOOL autosize;
@property(assign) BOOL firstContent; @property(assign) BOOL firstContent;
@property(assign) int x0;
@property(assign) int y0;
@property(retain) NSMutableDictionary *sliders; @property(retain) NSMutableDictionary *sliders;
@property(readwrite) int status; @property(readwrite) int status;
- (CVView *)contentView; - (CVView *)contentView;
@ -251,6 +254,16 @@ CV_IMPL void cvShowImage( const char* name, const CvArr* arr)
contentSize.height = scaledImageSize.height + [window contentView].sliderHeight; contentSize.height = scaledImageSize.height + [window contentView].sliderHeight;
contentSize.width = std::max<int>(scaledImageSize.width, MIN_SLIDER_WIDTH); contentSize.width = std::max<int>(scaledImageSize.width, MIN_SLIDER_WIDTH);
[window setContentSize:contentSize]; //adjust sliders to fit new window size [window setContentSize:contentSize]; //adjust sliders to fit new window size
if([window firstContent])
{
int x = [window x0];
int y = [window y0];
if(x >= 0 && y >= 0)
{
y = [[window screen] visibleFrame].size.height - y;
[window setFrameTopLeftPoint:NSMakePoint(x, y)];
}
}
} }
} }
[window setFirstContent:NO]; [window setFirstContent:NO];
@ -274,7 +287,6 @@ CV_IMPL void cvResizeWindow( const char* name, int width, int height)
CV_IMPL void cvMoveWindow( const char* name, int x, int y) CV_IMPL void cvMoveWindow( const char* name, int x, int y)
{ {
CV_FUNCNAME("cvMoveWindow"); CV_FUNCNAME("cvMoveWindow");
__BEGIN__; __BEGIN__;
@ -286,8 +298,14 @@ CV_IMPL void cvMoveWindow( const char* name, int x, int y)
//cout << "cvMoveWindow"<< endl; //cout << "cvMoveWindow"<< endl;
window = cvGetWindow(name); window = cvGetWindow(name);
if(window) { if(window) {
y = [[window screen] frame].size.height - y; if([window firstContent]) {
[window setFrameTopLeftPoint:NSMakePoint(x, y)]; [window setX0:x];
[window setY0:y];
}
else {
y = [[window screen] visibleFrame].size.height - y;
[window setFrameTopLeftPoint:NSMakePoint(x, y)];
}
} }
[localpool1 drain]; [localpool1 drain];
@ -556,6 +574,8 @@ CV_IMPL int cvNamedWindow( const char* name, int flags )
[window setFrameTopLeftPoint:initContentRect.origin]; [window setFrameTopLeftPoint:initContentRect.origin];
[window setFirstContent:YES]; [window setFirstContent:YES];
[window setX0:-1];
[window setY0:-1];
[window setContentView:[[CVView alloc] init]]; [window setContentView:[[CVView alloc] init]];
@ -818,6 +838,8 @@ static NSSize constrainAspectRatio(NSSize base, NSSize constraint) {
@synthesize mouseParam; @synthesize mouseParam;
@synthesize autosize; @synthesize autosize;
@synthesize firstContent; @synthesize firstContent;
@synthesize x0;
@synthesize y0;
@synthesize sliders; @synthesize sliders;
@synthesize status; @synthesize status;