@@ -83,11 +83,23 @@ CV_IMPL void cvSetTrackbarMin(const char* trackbar_name, const char* window_name
83
83
static bool wasInitialized = false ;
84
84
85
85
@interface CVView : NSView
86
+ {
87
+ NSImage *_image;
88
+ }
86
89
@property (strong ) NSImage *image;
87
90
- (void )setImageData : (CvArr *)arr ;
88
91
@end
89
92
90
93
@interface CVSlider : NSView
94
+ {
95
+ NSSlider *_slider;
96
+ NSTextField *_name;
97
+ int *_value;
98
+ void *_userData;
99
+ CvTrackbarCallback _callback;
100
+ CvTrackbarCallback2 _callback2;
101
+ }
102
+
91
103
@property (strong ) NSSlider *slider;
92
104
@property (strong ) NSTextField *name;
93
105
@property (assign ) int *value;
@@ -97,6 +109,14 @@ @interface CVSlider : NSView
97
109
@end
98
110
99
111
@interface CVWindow : NSWindow
112
+ {
113
+ CvMouseCallback _mouseCallback;
114
+ void *_mouseParam;
115
+ BOOL _autosize;
116
+ BOOL _firstContent;
117
+ NSMutableDictionary *_sliders;
118
+ int _status;
119
+ }
100
120
@property (assign ) CvMouseCallback mouseCallback;
101
121
@property (assign ) void *mouseParam;
102
122
@property (assign ) BOOL autosize;
@@ -681,14 +701,21 @@ void cvSetModeWindow_COCOA( const char* name, double prop_value )
681
701
}
682
702
683
703
@implementation CVWindow
684
-
704
+ # if defined(__LP64__)
685
705
@synthesize mouseCallback;
686
706
@synthesize mouseParam;
687
707
@synthesize autosize;
688
708
@synthesize firstContent;
689
709
@synthesize sliders;
690
710
@synthesize status;
691
-
711
+ #else // 32-bit Obj-C does not have automatic synthesize
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
692
719
- (void )cvSendMouseEvent : (NSEvent *)event type : (int )type flags : (int )flags {
693
720
(void )event;
694
721
// cout << "cvSendMouseEvent" << endl;
@@ -713,12 +740,13 @@ - (void)cvSendMouseEvent:(NSEvent *)event type:(int)type flags:(int)flags {
713
740
mp.y = mp.y * imageSize.height / std::max (viewHeight, 1 .);
714
741
715
742
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 );
717
744
}
718
745
719
746
- (void )cvMouseEvent : (NSEvent *)event {
720
747
// cout << "cvMouseEvent" << endl;
721
- if (!mouseCallback)
748
+
749
+ if ([self mouseCallback ] == nil )
722
750
return ;
723
751
724
752
int flags = 0 ;
@@ -778,13 +806,13 @@ - (void)mouseDown:(NSEvent *)theEvent {
778
806
779
807
- (void )createSliderWithName : (const char *)name maxValue : (int )max value : (int *)value callback : (CvTrackbarCallback)callback {
780
808
// cout << "createSliderWithName" << endl;
781
- if (sliders == nil )
782
- sliders = [[NSMutableDictionary alloc ] init ];
809
+ if (_sliders == nil )
810
+ _sliders = [[NSMutableDictionary alloc ] init ];
783
811
784
812
NSString *cvname = [NSString stringWithFormat: @" %s " , name];
785
813
786
814
// Avoid overwriting slider
787
- if ([sliders valueForKey: cvname]!=nil )
815
+ if ([_sliders valueForKey: cvname]!=nil )
788
816
return ;
789
817
790
818
// Create slider
@@ -803,11 +831,11 @@ - (void)createSliderWithName:(const char *)name maxValue:(int)max value:(int *)v
803
831
[slider setCallback: callback];
804
832
805
833
// Save slider
806
- [sliders setValue: slider forKey: cvname];
834
+ [_sliders setValue: slider forKey: cvname];
807
835
[[self contentView ] addSubview: slider];
808
836
809
837
810
- // update contentView size to contain sliders
838
+ // update contentView size to contain _sliders
811
839
NSSize viewSize=[[self contentView ] frame ].size ,
812
840
sliderSize=[slider frame ].size ;
813
841
viewSize.height += sliderSize.height ;
@@ -817,7 +845,7 @@ - (void)createSliderWithName:(const char *)name maxValue:(int)max value:(int *)v
817
845
[[self contentView ] setFrameSize: viewSize];
818
846
[[self contentView ] setNeedsDisplay: YES ];
819
847
820
- // update window size to contain sliders
848
+ // update window size to contain _sliders
821
849
NSRect rect = [self frame ];
822
850
rect.size .height += [slider frame ].size .height ;
823
851
rect.size .width = std::max<int >(rect.size .width , MIN_SLIDER_WIDTH);
@@ -834,13 +862,16 @@ - (CVView *)contentView {
834
862
@end
835
863
836
864
@implementation CVView
837
-
865
+ # if defined(__LP64__)
838
866
@synthesize image;
867
+ #else // 32-bit Obj-C does not have automatic synthesize
868
+ @synthesize image = _image;
869
+ #endif
839
870
840
871
- (id )init {
841
872
// cout << "CVView init" << endl;
842
873
[super init ];
843
- image = [[NSImage alloc ] init ];
874
+ _image = [[NSImage alloc ] init ];
844
875
return self;
845
876
}
846
877
@@ -895,11 +926,11 @@ - (void)setImageData:(CvArr *)arr {
895
926
dst[i * 4 + 2 ] = src[i * 3 + 2 ];
896
927
}
897
928
898
- if ( image )
899
- [image release ];
929
+ if ( _image )
930
+ [_image release ];
900
931
901
- image = [[NSImage alloc ] init ];
902
- [image addRepresentation: bitmap];
932
+ _image = [[NSImage alloc ] init ];
933
+ [_image addRepresentation: bitmap];
903
934
[bitmap release ];
904
935
905
936
/* CGColorSpaceRelease(colorspace);
@@ -920,7 +951,7 @@ - (void)setFrameSize:(NSSize)size {
920
951
int height = size.height ;
921
952
922
953
CVWindow *cvwindow = (CVWindow *)[self window ];
923
- if ([cvwindow respondsToSelector: @selector (sliders )]) {
954
+ if ([cvwindow respondsToSelector: @selector (_sliders )]) {
924
955
for (NSString *key in [cvwindow sliders ]) {
925
956
NSSlider *slider = [[cvwindow sliders ] valueForKey: key];
926
957
NSRect r = [slider frame ];
@@ -940,17 +971,17 @@ - (void)drawRect:(NSRect)rect {
940
971
NSAutoreleasePool * localpool = [[NSAutoreleasePool alloc ] init ];
941
972
CVWindow *cvwindow = (CVWindow *)[self window ];
942
973
int height = 0 ;
943
- if ([cvwindow respondsToSelector: @selector (sliders )]) {
974
+ if ([cvwindow respondsToSelector: @selector (_sliders )]) {
944
975
for (NSString *key in [cvwindow sliders ]) {
945
976
height += [[[cvwindow sliders ] valueForKey: key] frame ].size .height ;
946
977
}
947
978
}
948
979
949
980
950
- NSRect imageRect = {{0 ,0 }, {[image size ].width , [image size ].height }};
981
+ NSRect imageRect = {{0 ,0 }, {[_image size ].width , [_image size ].height }};
951
982
952
- if (image != nil ) {
953
- [image drawInRect: imageRect
983
+ if (_image != nil ) {
984
+ [_image drawInRect: imageRect
954
985
fromRect: NSZeroRect
955
986
operation: NSCompositeSourceOver
956
987
fraction: 1.0 ];
@@ -962,40 +993,47 @@ - (void)drawRect:(NSRect)rect {
962
993
@end
963
994
964
995
@implementation CVSlider
965
-
996
+ # if defined(__LP64__)
966
997
@synthesize slider;
967
998
@synthesize name;
968
999
@synthesize value;
969
1000
@synthesize userData;
970
1001
@synthesize callback;
971
1002
@synthesize callback2;
972
-
1003
+ #else // 32-bit Obj-C does not have automatic synthesize
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
973
1011
- (id )init {
974
1012
[super init ];
975
1013
976
- callback = NULL ;
977
- value = NULL ;
978
- userData = NULL ;
1014
+ _callback = NULL ;
1015
+ _value = NULL ;
1016
+ _userData = NULL ;
979
1017
980
1018
[self setFrame: NSMakeRect (0 ,0 ,200 ,30 )];
981
1019
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 ];
999
1037
1000
1038
[self setAutoresizingMask: NSViewWidthSizable];
1001
1039
@@ -1006,13 +1044,13 @@ - (id)init {
1006
1044
1007
1045
- (void )sliderChanged : (NSNotification *)notification {
1008
1046
(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 );
1016
1054
}
1017
1055
1018
1056
@end
0 commit comments