Commit 8c2246bd authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

fixed slider rendering in highgui windows on MacOSX (ticket #608; thanks to tingfan for the patch)

parent f6bc96c4
...@@ -795,6 +795,7 @@ double CvCaptureFile::getProperty(int property_id){ ...@@ -795,6 +795,7 @@ double CvCaptureFile::getProperty(int property_id){
double retval; double retval;
QTTime t; QTTime t;
//cerr << "get_prop"<<endl;
switch (property_id) { switch (property_id) {
case CV_CAP_PROP_POS_MSEC: case CV_CAP_PROP_POS_MSEC:
[[mCaptureSession attributeForKey:QTMovieCurrentTimeAttribute] getValue:&t]; [[mCaptureSession attributeForKey:QTMovieCurrentTimeAttribute] getValue:&t];
...@@ -815,6 +816,9 @@ double CvCaptureFile::getProperty(int property_id){ ...@@ -815,6 +816,9 @@ double CvCaptureFile::getProperty(int property_id){
case CV_CAP_PROP_FPS: case CV_CAP_PROP_FPS:
retval = currentFPS; retval = currentFPS;
break; break;
case CV_CAP_PROP_FRAME_COUNT:
retval = movieDuration*movieFPS/1000;
break;
case CV_CAP_PROP_FOURCC: case CV_CAP_PROP_FOURCC:
default: default:
retval = 0; retval = 0;
......
...@@ -74,6 +74,7 @@ CV_IMPL int cvWaitKey (int maxWait) {return 0;} ...@@ -74,6 +74,7 @@ CV_IMPL int cvWaitKey (int maxWait) {return 0;}
using namespace std; using namespace std;
const int TOP_BORDER = 7; const int TOP_BORDER = 7;
const int MIN_SLIDER_WIDTH=200;
static NSApplication *application = nil; static NSApplication *application = nil;
static NSAutoreleasePool *pool = nil; static NSAutoreleasePool *pool = nil;
...@@ -221,8 +222,16 @@ CV_IMPL void cvShowImage( const char* name, const CvArr* arr) ...@@ -221,8 +222,16 @@ CV_IMPL void cvShowImage( const char* name, const CvArr* arr)
[[window contentView] setImageData:(CvArr *)arr]; [[window contentView] setImageData:(CvArr *)arr];
if([window autosize] || [window firstContent] || empty) if([window autosize] || [window firstContent] || empty)
{ {
//Set new view size considering sliders (reserve height and min width)
NSRect vrectNew = vrectOld; NSRect vrectNew = vrectOld;
vrectNew.size = [[[window contentView] image] size]; int slider_height = 0;
for(NSString *key in [window sliders]) {
slider_height += [[[window sliders] valueForKey:key] frame].size.height;
}
vrectNew.size.height = [[[window contentView] image] size].height + slider_height;
vrectNew.size.width = std::max<int>([[[window contentView] image] size].width, MIN_SLIDER_WIDTH);
[[window contentView] setFrameSize:vrectNew.size]; //adjust sliders to fit new window size
rect.size.width += vrectNew.size.width - vrectOld.size.width; rect.size.width += vrectNew.size.width - vrectOld.size.width;
rect.size.height += vrectNew.size.height - vrectOld.size.height; rect.size.height += vrectNew.size.height - vrectOld.size.height;
rect.origin.y -= vrectNew.size.height - vrectOld.size.height; rect.origin.y -= vrectNew.size.height - vrectOld.size.height;
...@@ -645,17 +654,26 @@ CV_IMPL int cvWaitKey (int maxWait) ...@@ -645,17 +654,26 @@ CV_IMPL int cvWaitKey (int maxWait)
// Save slider // Save slider
[sliders setValue:slider forKey:cvname]; [sliders setValue:slider forKey:cvname];
[[self contentView] addSubview:slider]; [[self contentView] addSubview:slider];
//update contentView size to contain sliders
NSSize viewSize=[[self contentView] frame].size,
sliderSize=[slider frame].size;
viewSize.height += sliderSize.height;
viewSize.width = std::max<int>(viewSize.width, MIN_SLIDER_WIDTH);
// Update slider sizes // Update slider sizes
[[self contentView] setFrameSize:[[self contentView] frame].size]; [[self contentView] setFrameSize:viewSize];
[[self contentView] setNeedsDisplay:YES]; [[self contentView] setNeedsDisplay:YES];
//update window size to contain sliders
NSRect rect = [self frame];
rect.size.height += [slider frame].size.height;
rect.size.width = std::max<int>(rect.size.width, MIN_SLIDER_WIDTH);
[self setFrame:rect display:YES];
int height = 0;
for(NSString *key in sliders) {
height += [[sliders valueForKey:key] frame].size.height;
}
[self setContentMinSize:NSMakeSize(0, height)];
} }
- (CVView *)contentView { - (CVView *)contentView {
...@@ -755,6 +773,7 @@ CV_IMPL int cvWaitKey (int maxWait) ...@@ -755,6 +773,7 @@ CV_IMPL int cvWaitKey (int maxWait)
NSSlider *slider = [[cvwindow sliders] valueForKey:key]; NSSlider *slider = [[cvwindow sliders] valueForKey:key];
NSRect r = [slider frame]; NSRect r = [slider frame];
r.origin.y = height - r.size.height; r.origin.y = height - r.size.height;
r.size.width = [[cvwindow contentView] frame].size.width;
[slider setFrame:r]; [slider setFrame:r];
height -= r.size.height; height -= r.size.height;
} }
...@@ -773,7 +792,7 @@ CV_IMPL int cvWaitKey (int maxWait) ...@@ -773,7 +792,7 @@ CV_IMPL int cvWaitKey (int maxWait)
} }
NSRect imageRect = {{0,0}, {self.frame.size.width, self.frame.size.height-height-6}}; NSRect imageRect = {{0,0}, {[image size].width, [image size].height}};
if(image != nil) { if(image != nil) {
[image drawInRect: imageRect [image drawInRect: imageRect
...@@ -803,9 +822,9 @@ CV_IMPL int cvWaitKey (int maxWait) ...@@ -803,9 +822,9 @@ CV_IMPL int cvWaitKey (int maxWait)
value = NULL; value = NULL;
userData = NULL; userData = NULL;
[self setFrame:NSMakeRect(0,0,200,25)]; [self setFrame:NSMakeRect(0,0,200,30)];
name = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0,120, 20)]; name = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 0,110, 25)];
[name setEditable:NO]; [name setEditable:NO];
[name setSelectable:NO]; [name setSelectable:NO];
[name setBezeled:NO]; [name setBezeled:NO];
...@@ -814,7 +833,7 @@ CV_IMPL int cvWaitKey (int maxWait) ...@@ -814,7 +833,7 @@ CV_IMPL int cvWaitKey (int maxWait)
[[name cell] setLineBreakMode:NSLineBreakByTruncatingTail]; [[name cell] setLineBreakMode:NSLineBreakByTruncatingTail];
[self addSubview:name]; [self addSubview:name];
slider = [[NSSlider alloc] initWithFrame:NSMakeRect(120, 0, 76, 20)]; slider = [[NSSlider alloc] initWithFrame:NSMakeRect(120, 0, 70, 25)];
[slider setAutoresizingMask:NSViewWidthSizable]; [slider setAutoresizingMask:NSViewWidthSizable];
[slider setMinValue:0]; [slider setMinValue:0];
[slider setMaxValue:100]; [slider setMaxValue:100];
...@@ -825,7 +844,7 @@ CV_IMPL int cvWaitKey (int maxWait) ...@@ -825,7 +844,7 @@ CV_IMPL int cvWaitKey (int maxWait)
[self setAutoresizingMask:NSViewWidthSizable]; [self setAutoresizingMask:NSViewWidthSizable];
[self setFrame:NSMakeRect(12, 0, 182, 30)]; //[self setFrame:NSMakeRect(12, 0, 100, 30)];
return self; return self;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment