Skip to content

Commit 2d20aa4

Browse files
author
Jaime O. Rios
committed
Modified code to work with universal build.
1 parent 8e8da3f commit 2d20aa4

File tree

1 file changed

+88
-50
lines changed

1 file changed

+88
-50
lines changed

modules/highgui/src/window_cocoa.mm

Lines changed: 88 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,23 @@ CV_IMPL void cvSetTrackbarMin(const char* trackbar_name, const char* window_name
8383
static bool wasInitialized = false;
8484

8585
@interface CVView : NSView
86+
{
87+
NSImage *_image;
88+
}
8689
@property(strong) NSImage *image;
8790
- (void)setImageData:(CvArr *)arr;
8891
@end
8992

9093
@interface CVSlider : NSView
94+
{
95+
NSSlider *_slider;
96+
NSTextField *_name;
97+
int *_value;
98+
void *_userData;
99+
CvTrackbarCallback _callback;
100+
CvTrackbarCallback2 _callback2;
101+
}
102+
91103
@property(strong) NSSlider *slider;
92104
@property(strong) NSTextField *name;
93105
@property(assign) int *value;
@@ -97,6 +109,14 @@ @interface CVSlider : NSView
97109
@end
98110

99111
@interface CVWindow : NSWindow
112+
{
113+
CvMouseCallback _mouseCallback;
114+
void *_mouseParam;
115+
BOOL _autosize;
116+
BOOL _firstContent;
117+
NSMutableDictionary *_sliders;
118+
int _status;
119+
}
100120
@property(assign) CvMouseCallback mouseCallback;
101121
@property(assign) void *mouseParam;
102122
@property(assign) BOOL autosize;
@@ -681,14 +701,21 @@ void cvSetModeWindow_COCOA( const char* name, double prop_value )
681701
}
682702

683703
@implementation CVWindow
684-
704+
#if defined(__LP64__)
685705
@synthesize mouseCallback;
686706
@synthesize mouseParam;
687707
@synthesize autosize;
688708
@synthesize firstContent;
689709
@synthesize sliders;
690710
@synthesize status;
691-
711+
#else
712+
@synthesize mouseCallback = _mouseCallback;
713+
@synthesize mouseParam = _mouseParam;
714+
@synthesize autosize = _autosize;
715+
@synthesize firstContent = _firstContent;
716+
@synthesize sliders = _sliders;
717+
@synthesize status = _status;
718+
#endif
692719
- (void)cvSendMouseEvent:(NSEvent *)event type:(int)type flags:(int)flags {
693720
(void)event;
694721
//cout << "cvSendMouseEvent" << endl;
@@ -713,12 +740,13 @@ - (void)cvSendMouseEvent:(NSEvent *)event type:(int)type flags:(int)flags {
713740
mp.y = mp.y * imageSize.height / std::max(viewHeight, 1.);
714741

715742
if( mp.x >= 0 && mp.y >= 0 && mp.x < imageSize.width && mp.y < imageSize.height )
716-
mouseCallback(type, mp.x, mp.y, flags, mouseParam);
743+
_mouseCallback(type, mp.x, mp.y, flags, _mouseParam);
717744
}
718745

719746
- (void)cvMouseEvent:(NSEvent *)event {
720747
//cout << "cvMouseEvent" << endl;
721-
if(!mouseCallback)
748+
749+
if([self mouseCallback] == nil)
722750
return;
723751

724752
int flags = 0;
@@ -778,13 +806,13 @@ - (void)mouseDown:(NSEvent *)theEvent {
778806

779807
- (void)createSliderWithName:(const char *)name maxValue:(int)max value:(int *)value callback:(CvTrackbarCallback)callback {
780808
//cout << "createSliderWithName" << endl;
781-
if(sliders == nil)
782-
sliders = [[NSMutableDictionary alloc] init];
809+
if(_sliders == nil)
810+
_sliders = [[NSMutableDictionary alloc] init];
783811

784812
NSString *cvname = [NSString stringWithFormat:@"%s", name];
785813

786814
// Avoid overwriting slider
787-
if([sliders valueForKey:cvname]!=nil)
815+
if([_sliders valueForKey:cvname]!=nil)
788816
return;
789817

790818
// Create slider
@@ -803,11 +831,11 @@ - (void)createSliderWithName:(const char *)name maxValue:(int)max value:(int *)v
803831
[slider setCallback:callback];
804832

805833
// Save slider
806-
[sliders setValue:slider forKey:cvname];
834+
[_sliders setValue:slider forKey:cvname];
807835
[[self contentView] addSubview:slider];
808836

809837

810-
//update contentView size to contain sliders
838+
//update contentView size to contain _sliders
811839
NSSize viewSize=[[self contentView] frame].size,
812840
sliderSize=[slider frame].size;
813841
viewSize.height += sliderSize.height;
@@ -817,7 +845,7 @@ - (void)createSliderWithName:(const char *)name maxValue:(int)max value:(int *)v
817845
[[self contentView] setFrameSize:viewSize];
818846
[[self contentView] setNeedsDisplay:YES];
819847

820-
//update window size to contain sliders
848+
//update window size to contain _sliders
821849
NSRect rect = [self frame];
822850
rect.size.height += [slider frame].size.height;
823851
rect.size.width = std::max<int>(rect.size.width, MIN_SLIDER_WIDTH);
@@ -834,13 +862,16 @@ - (CVView *)contentView {
834862
@end
835863

836864
@implementation CVView
837-
865+
#if defined(__LP64__)
838866
@synthesize image;
867+
#else
868+
@synthesize image = _image;
869+
#endif
839870

840871
- (id)init {
841872
//cout << "CVView init" << endl;
842873
[super init];
843-
image = [[NSImage alloc] init];
874+
_image = [[NSImage alloc] init];
844875
return self;
845876
}
846877

@@ -895,11 +926,11 @@ - (void)setImageData:(CvArr *)arr {
895926
dst[i * 4 + 2] = src[i * 3 + 2];
896927
}
897928

898-
if( image )
899-
[image release];
929+
if( _image )
930+
[_image release];
900931

901-
image = [[NSImage alloc] init];
902-
[image addRepresentation:bitmap];
932+
_image = [[NSImage alloc] init];
933+
[_image addRepresentation:bitmap];
903934
[bitmap release];
904935

905936
/*CGColorSpaceRelease(colorspace);
@@ -920,7 +951,7 @@ - (void)setFrameSize:(NSSize)size {
920951
int height = size.height;
921952

922953
CVWindow *cvwindow = (CVWindow *)[self window];
923-
if ([cvwindow respondsToSelector:@selector(sliders)]) {
954+
if ([cvwindow respondsToSelector:@selector(_sliders)]) {
924955
for(NSString *key in [cvwindow sliders]) {
925956
NSSlider *slider = [[cvwindow sliders] valueForKey:key];
926957
NSRect r = [slider frame];
@@ -940,17 +971,17 @@ - (void)drawRect:(NSRect)rect {
940971
NSAutoreleasePool* localpool = [[NSAutoreleasePool alloc] init];
941972
CVWindow *cvwindow = (CVWindow *)[self window];
942973
int height = 0;
943-
if ([cvwindow respondsToSelector:@selector(sliders)]) {
974+
if ([cvwindow respondsToSelector:@selector(_sliders)]) {
944975
for(NSString *key in [cvwindow sliders]) {
945976
height += [[[cvwindow sliders] valueForKey:key] frame].size.height;
946977
}
947978
}
948979

949980

950-
NSRect imageRect = {{0,0}, {[image size].width, [image size].height}};
981+
NSRect imageRect = {{0,0}, {[_image size].width, [_image size].height}};
951982

952-
if(image != nil) {
953-
[image drawInRect: imageRect
983+
if(_image != nil) {
984+
[_image drawInRect: imageRect
954985
fromRect: NSZeroRect
955986
operation: NSCompositeSourceOver
956987
fraction: 1.0];
@@ -962,40 +993,47 @@ - (void)drawRect:(NSRect)rect {
962993
@end
963994

964995
@implementation CVSlider
965-
996+
#if defined(__LP64__)
966997
@synthesize slider;
967998
@synthesize name;
968999
@synthesize value;
9691000
@synthesize userData;
9701001
@synthesize callback;
9711002
@synthesize callback2;
972-
1003+
#else
1004+
@synthesize slider = _slider;
1005+
@synthesize name = _name;
1006+
@synthesize value = _value;
1007+
@synthesize userData = _userData;
1008+
@synthesize callback = _callback;
1009+
@synthesize callback2 = _callback2;
1010+
#endif
9731011
- (id)init {
9741012
[super init];
9751013

976-
callback = NULL;
977-
value = NULL;
978-
userData = NULL;
1014+
_callback = NULL;
1015+
_value = NULL;
1016+
_userData = NULL;
9791017

9801018
[self setFrame:NSMakeRect(0,0,200,30)];
9811019

982-
name = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 0,110, 25)];
983-
[name setEditable:NO];
984-
[name setSelectable:NO];
985-
[name setBezeled:NO];
986-
[name setBordered:NO];
987-
[name setDrawsBackground:NO];
988-
[[name cell] setLineBreakMode:NSLineBreakByTruncatingTail];
989-
[self addSubview:name];
990-
991-
slider = [[NSSlider alloc] initWithFrame:NSMakeRect(120, 0, 70, 25)];
992-
[slider setAutoresizingMask:NSViewWidthSizable];
993-
[slider setMinValue:0];
994-
[slider setMaxValue:100];
995-
[slider setContinuous:YES];
996-
[slider setTarget:self];
997-
[slider setAction:@selector(sliderChanged:)];
998-
[self addSubview:slider];
1020+
_name = [[NSTextField alloc] initWithFrame:NSMakeRect(10, 0,110, 25)];
1021+
[_name setEditable:NO];
1022+
[_name setSelectable:NO];
1023+
[_name setBezeled:NO];
1024+
[_name setBordered:NO];
1025+
[_name setDrawsBackground:NO];
1026+
[[_name cell] setLineBreakMode:NSLineBreakByTruncatingTail];
1027+
[self addSubview:_name];
1028+
1029+
_slider = [[NSSlider alloc] initWithFrame:NSMakeRect(120, 0, 70, 25)];
1030+
[_slider setAutoresizingMask:NSViewWidthSizable];
1031+
[_slider setMinValue:0];
1032+
[_slider setMaxValue:100];
1033+
[_slider setContinuous:YES];
1034+
[_slider setTarget:self];
1035+
[_slider setAction:@selector(sliderChanged:)];
1036+
[self addSubview:_slider];
9991037

10001038
[self setAutoresizingMask:NSViewWidthSizable];
10011039

@@ -1006,13 +1044,13 @@ - (id)init {
10061044

10071045
- (void)sliderChanged:(NSNotification *)notification {
10081046
(void)notification;
1009-
int pos = [slider intValue];
1010-
if(value)
1011-
*value = pos;
1012-
if(callback)
1013-
callback(pos);
1014-
if(callback2)
1015-
callback2(pos, userData);
1047+
int pos = [_slider intValue];
1048+
if(_value)
1049+
*_value = pos;
1050+
if(_callback)
1051+
_callback(pos);
1052+
if(_callback2)
1053+
_callback2(pos, _userData);
10161054
}
10171055

10181056
@end

0 commit comments

Comments
 (0)