diff --git a/modules/highgui/src/window_cocoa.mm b/modules/highgui/src/window_cocoa.mm index 97a6831f1a..e9cf5a3c1b 100644 --- a/modules/highgui/src/window_cocoa.mm +++ b/modules/highgui/src/window_cocoa.mm @@ -92,6 +92,7 @@ static bool wasInitialized = false; @interface CVSlider : NSView { NSSlider *slider; NSTextField *name; + NSString *initialName; int *value; void *userData; CvTrackbarCallback callback; @@ -99,6 +100,7 @@ static bool wasInitialized = false; } @property(retain) NSSlider *slider; @property(retain) NSTextField *name; +@property(retain) NSString *initialName; @property(assign) int *value; @property(assign) void *userData; @property(assign) CvTrackbarCallback callback; @@ -107,6 +109,7 @@ static bool wasInitialized = false; @interface CVWindow : NSWindow { NSMutableDictionary *sliders; + NSMutableArray *slidersKeys; CvMouseCallback mouseCallback; void *mouseParam; BOOL autosize; @@ -121,6 +124,7 @@ static bool wasInitialized = false; @property(assign) int x0; @property(assign) int y0; @property(retain) NSMutableDictionary *sliders; +@property(retain) NSMutableArray *slidersKeys; @property(readwrite) int status; - (CVView *)contentView; - (void)cvSendMouseEvent:(NSEvent *)event type:(int)type flags:(int)flags; @@ -842,6 +846,7 @@ static NSSize constrainAspectRatio(NSSize base, NSSize constraint) { @synthesize x0; @synthesize y0; @synthesize sliders; +@synthesize slidersKeys; @synthesize status; - (void)cvSendMouseEvent:(NSEvent *)event type:(int)type flags:(int)flags { @@ -933,6 +938,9 @@ static NSSize constrainAspectRatio(NSSize base, NSSize constraint) { if(sliders == nil) sliders = [[NSMutableDictionary alloc] init]; + if(slidersKeys == nil) + slidersKeys = [[NSMutableArray alloc] init]; + NSString *cvname = [NSString stringWithFormat:@"%s", name]; // Avoid overwriting slider @@ -942,18 +950,23 @@ static NSSize constrainAspectRatio(NSSize base, NSSize constraint) { // Create slider CVSlider *slider = [[CVSlider alloc] init]; [[slider name] setStringValue:cvname]; + slider.initialName = [NSString stringWithFormat:@"%s", name]; [[slider slider] setMaxValue:max]; [[slider slider] setMinValue:0]; if(value) { [[slider slider] setIntValue:*value]; [slider setValue:value]; + NSString *temp = [slider initialName]; + NSString *text = [NSString stringWithFormat:@"%@ %d", temp, *value]; + [[slider name] setStringValue: text]; } if(callback) [slider setCallback:callback]; // Save slider [sliders setValue:slider forKey:cvname]; + [slidersKeys addObject:cvname]; [[self contentView] addSubview:slider]; @@ -1092,7 +1105,7 @@ static NSSize constrainAspectRatio(NSSize base, NSSize constraint) { CVWindow *cvwindow = (CVWindow *)[self window]; if ([cvwindow respondsToSelector:@selector(sliders)]) { - for(NSString *key in [cvwindow sliders]) { + for(NSString *key in [cvwindow slidersKeys]) { CVSlider *slider = [[cvwindow sliders] valueForKey:key]; NSRect r = [slider frame]; r.origin.y = height - r.size.height; @@ -1144,6 +1157,7 @@ static NSSize constrainAspectRatio(NSSize base, NSSize constraint) { @synthesize slider; @synthesize name; +@synthesize initialName; @synthesize value; @synthesize userData; @synthesize callback; @@ -1186,6 +1200,9 @@ static NSSize constrainAspectRatio(NSSize base, NSSize constraint) { - (void)sliderChanged:(NSNotification *)notification { (void)notification; int pos = [slider intValue]; + NSString *temp = [self initialName]; + NSString *text = [NSString stringWithFormat:@"%@ %d", temp, *value]; + [name setStringValue: text]; if(value) *value = pos; if(callback)