From cb1a1e9a5131614bce46463faa2aa95dbeddb80b Mon Sep 17 00:00:00 2001 From: Christine Poerschke <6458642+cpoerschke@users.noreply.github.com> Date: Sun, 11 Sep 2022 16:40:27 +0100 Subject: [PATCH] add explicit onChange callback in cocoa cvSetTrackbarPos --- modules/highgui/src/window_cocoa.mm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/highgui/src/window_cocoa.mm b/modules/highgui/src/window_cocoa.mm index ef3f828cf8..3f46d47de7 100644 --- a/modules/highgui/src/window_cocoa.mm +++ b/modules/highgui/src/window_cocoa.mm @@ -451,6 +451,9 @@ CV_IMPL void cvSetTrackbarPos(const char* trackbar_name, const char* window_name slider = [[window sliders] valueForKey:[NSString stringWithFormat:@"%s", trackbar_name]]; if(slider) { [[slider slider] setIntValue:pos]; + if([slider respondsToSelector:@selector(handleSlider)]) { + [slider performSelector:@selector(handleSlider)]; + } } } [localpool5 drain]; @@ -1187,7 +1190,7 @@ static NSSize constrainAspectRatio(NSSize base, NSSize constraint) { [slider setMaxValue:100]; [slider setContinuous:YES]; [slider setTarget:self]; - [slider setAction:@selector(sliderChanged:)]; + [slider setAction:@selector(handleSliderNotification:)]; [self addSubview:slider]; [self setAutoresizingMask:NSViewWidthSizable]; @@ -1197,8 +1200,12 @@ static NSSize constrainAspectRatio(NSSize base, NSSize constraint) { return self; } -- (void)sliderChanged:(NSNotification *)notification { +- (void)handleSliderNotification:(NSNotification *)notification { (void)notification; + [self handleSlider]; +} + +- (void)handleSlider { int pos = [slider intValue]; NSString *temp = [self initialName]; NSString *text = [NSString stringWithFormat:@"%@ %d", temp, pos];