Skip to content

Commit adf89bb

Browse files
authored
Merge pull request opencv#22047 from jlopezr:trackbar-ordered-in-mac
* In Mac highgui now shows trackbars in creation order * In Mac highgui trackbars show current value * Remove trailing spaces in objectivec code
1 parent 583bd1a commit adf89bb

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

modules/highgui/src/window_cocoa.mm

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,15 @@ - (void)setImageData:(CvArr *)arr;
9292
@interface CVSlider : NSView {
9393
NSSlider *slider;
9494
NSTextField *name;
95+
NSString *initialName;
9596
int *value;
9697
void *userData;
9798
CvTrackbarCallback callback;
9899
CvTrackbarCallback2 callback2;
99100
}
100101
@property(retain) NSSlider *slider;
101102
@property(retain) NSTextField *name;
103+
@property(retain) NSString *initialName;
102104
@property(assign) int *value;
103105
@property(assign) void *userData;
104106
@property(assign) CvTrackbarCallback callback;
@@ -107,6 +109,7 @@ @interface CVSlider : NSView {
107109

108110
@interface CVWindow : NSWindow {
109111
NSMutableDictionary *sliders;
112+
NSMutableArray *slidersKeys;
110113
CvMouseCallback mouseCallback;
111114
void *mouseParam;
112115
BOOL autosize;
@@ -121,6 +124,7 @@ @interface CVWindow : NSWindow {
121124
@property(assign) int x0;
122125
@property(assign) int y0;
123126
@property(retain) NSMutableDictionary *sliders;
127+
@property(retain) NSMutableArray *slidersKeys;
124128
@property(readwrite) int status;
125129
- (CVView *)contentView;
126130
- (void)cvSendMouseEvent:(NSEvent *)event type:(int)type flags:(int)flags;
@@ -842,6 +846,7 @@ @implementation CVWindow
842846
@synthesize x0;
843847
@synthesize y0;
844848
@synthesize sliders;
849+
@synthesize slidersKeys;
845850
@synthesize status;
846851

847852
- (void)cvSendMouseEvent:(NSEvent *)event type:(int)type flags:(int)flags {
@@ -933,6 +938,9 @@ - (void)createSliderWithName:(const char *)name maxValue:(int)max value:(int *)v
933938
if(sliders == nil)
934939
sliders = [[NSMutableDictionary alloc] init];
935940

941+
if(slidersKeys == nil)
942+
slidersKeys = [[NSMutableArray alloc] init];
943+
936944
NSString *cvname = [NSString stringWithFormat:@"%s", name];
937945

938946
// Avoid overwriting slider
@@ -942,18 +950,23 @@ - (void)createSliderWithName:(const char *)name maxValue:(int)max value:(int *)v
942950
// Create slider
943951
CVSlider *slider = [[CVSlider alloc] init];
944952
[[slider name] setStringValue:cvname];
953+
slider.initialName = [NSString stringWithFormat:@"%s", name];
945954
[[slider slider] setMaxValue:max];
946955
[[slider slider] setMinValue:0];
947956
if(value)
948957
{
949958
[[slider slider] setIntValue:*value];
950959
[slider setValue:value];
960+
NSString *temp = [slider initialName];
961+
NSString *text = [NSString stringWithFormat:@"%@ %d", temp, *value];
962+
[[slider name] setStringValue: text];
951963
}
952964
if(callback)
953965
[slider setCallback:callback];
954966

955967
// Save slider
956968
[sliders setValue:slider forKey:cvname];
969+
[slidersKeys addObject:cvname];
957970
[[self contentView] addSubview:slider];
958971

959972

@@ -1092,7 +1105,7 @@ - (void)setFrameSize:(NSSize)size {
10921105

10931106
CVWindow *cvwindow = (CVWindow *)[self window];
10941107
if ([cvwindow respondsToSelector:@selector(sliders)]) {
1095-
for(NSString *key in [cvwindow sliders]) {
1108+
for(NSString *key in [cvwindow slidersKeys]) {
10961109
CVSlider *slider = [[cvwindow sliders] valueForKey:key];
10971110
NSRect r = [slider frame];
10981111
r.origin.y = height - r.size.height;
@@ -1144,6 +1157,7 @@ @implementation CVSlider
11441157

11451158
@synthesize slider;
11461159
@synthesize name;
1160+
@synthesize initialName;
11471161
@synthesize value;
11481162
@synthesize userData;
11491163
@synthesize callback;
@@ -1186,6 +1200,9 @@ - (id)init {
11861200
- (void)sliderChanged:(NSNotification *)notification {
11871201
(void)notification;
11881202
int pos = [slider intValue];
1203+
NSString *temp = [self initialName];
1204+
NSString *text = [NSString stringWithFormat:@"%@ %d", temp, *value];
1205+
[name setStringValue: text];
11891206
if(value)
11901207
*value = pos;
11911208
if(callback)

0 commit comments

Comments
 (0)