Skip to content

Commit a71baf6

Browse files
committed
• SSYToolbarButton now has a -flashDuration property
• More styles added to SSYVectorImageStyle, parameter name 'diameter' changed to 'length' in imageStyle: length:color:rotateDegrees:
1 parent 5484ac4 commit a71baf6

5 files changed

+607
-170
lines changed

SSYStarRatingView.m

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ - (id)initWithFrame:(NSRect)frame
4444
[self setDisplayMode:SSYStarRatingViewDisplayFull] ;
4545
[self setHalfStarThreshold:SSY_STAR_RATING_VIEW_DEFAULT_HALFSTAR_THRESHOLD] ;
4646
[self setStarImage:[SSYVectorImages imageStyle:SSYVectorImageStyleStar
47-
diameter:starHeight
47+
length:starHeight
4848
color:[NSColor lightGrayColor]
4949
rotateDegrees:0.0]] ;
5050
[self setStarHighlightedImage:[SSYVectorImages imageStyle:SSYVectorImageStyleStar
51-
diameter:starHeight
51+
length:starHeight
5252
color:[NSColor blueColor]
5353
rotateDegrees:0.0]] ;
5454
[self setRemoveXImage:[SSYVectorImages imageStyle:SSYVectorImageStyleRemoveX
55-
diameter:(0.9 * starHeight)
55+
length:(0.9 * starHeight)
5656
color:nil
5757
rotateDegrees:0.0]] ;
5858
[self setEditable:YES] ;

SSYToolbarButton.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
/*!
55
@brief A toolbar item which has a tristate 'value' attribute,
66
and three each additional images, labels and tooltips which
7-
replace super's image, label and tooltip when the value is changed
7+
replace super's image, label and tooltip when the value is changed,
8+
and/or may be configured to flash when clicked.
89
910
@details
1011
*/
@@ -13,6 +14,7 @@
1314
NSImage* m_onImage ;
1415
NSImage* m_offImage ;
1516
NSImage* m_disImage ;
17+
NSImage* m_originalImage ;
1618
NSString* m_onLabel ;
1719
NSString* m_offLabel ;
1820
NSString* m_disLabel ;
@@ -21,6 +23,8 @@
2123
NSString* m_disToolTip ;
2224
id m_externalTarget ;
2325
SEL m_externalAction ;
26+
NSTimeInterval m_flashDuration ;
27+
NSTimer* m_flashTimer ;
2428
}
2529

2630
/*!
@@ -105,4 +109,10 @@
105109
*/
106110
@property (retain) NSString* disToolTip ;
107111

112+
/*!
113+
@brief Duration for which the receiver shall flash when it is clicked
114+
@details The default value is 0 (no flash)
115+
*/
116+
@property (assign) NSTimeInterval flashDuration ;
117+
108118
@end

SSYToolbarButton.m

+34-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
#import "SSYToolbarButton.h"
2+
#import "NSImage+Transform.h"
23

34
static NSString* const constKeyValue = @"value" ;
45
static NSString* const constKeyToolTip = @"toolTip" ;
56

7+
68
@interface SSYToolbarButton ()
79

810
// To avoid retain cycles, it is conventional to not retain
911
// targets. (In this case, I tested [super setTarget:aTarg]
1012
// and it does not increase the retain count of aTarg.)
1113
@property (assign) id externalTarget ;
1214
@property (assign) SEL externalAction ;
15+
@property (retain) NSImage* originalImage ;
16+
@property (assign) NSTimer* flashTimer ; // NSTimer retains itself, so 'assign'
1317

1418
@end
1519

@@ -37,14 +41,16 @@ - (id)initWithItemIdentifier:(NSString*)identifier {
3741
@synthesize onImage = m_onImage ;
3842
@synthesize offImage = m_offImage ;
3943
@synthesize disImage = m_disImage ;
44+
@synthesize originalImage = m_originalImage ;
4045
@synthesize onLabel = m_onLabel ;
4146
@synthesize offLabel = m_offLabel ;
4247
@synthesize disLabel = m_disLabel ;
4348
@synthesize onToolTip = m_onToolTip ;
4449
@synthesize offToolTip = m_offToolTip ;
4550
@synthesize disToolTip = m_disToolTip ;
4651
@synthesize externalTarget = m_externalTarget ;
47-
@synthesize externalAction = m_externalAction ;
52+
@synthesize externalAction = m_externalAction ;
53+
@synthesize flashDuration = m_flashDuration ;
4854

4955
- (void)awakeFromNib {
5056
// The following is to support some other object binding to the
@@ -108,18 +114,44 @@ - (void)setValue:(NSInteger)value {
108114
if (toolTip) {
109115
[self setToolTip:toolTip] ;
110116
}
111-
}
117+
}
118+
119+
- (void)restoreOriginalImage:(NSTimer*)timer {
120+
[self setImage:[self originalImage]] ;
121+
[self setOriginalImage:nil] ;
122+
}
112123

113124
- (IBAction)doDaClick:(id)sender {
125+
if ([self flashDuration] > 0.0) {
126+
NSImage* image = [self image] ;
127+
[self setOriginalImage:image] ;
128+
NSImage* darkerImage = [image copy] ;
129+
[darkerImage darken] ;
130+
[self setImage:darkerImage] ;
131+
[darkerImage release] ;
132+
NSTimer* timer = [NSTimer scheduledTimerWithTimeInterval:[self flashDuration]
133+
target:self
134+
selector:@selector(restoreOriginalImage:)
135+
userInfo:nil
136+
repeats:NO] ;
137+
// Stash the timer so that we can invalidate it during -dealloc, in case
138+
// we are deallocced (window closes, for example) before the timer
139+
// fires. Otherwise there would be a crash.
140+
[self setFlashTimer:timer] ;
141+
}
142+
114143
//[self setValue:([self value] == NSOnState) ? NSOffState : NSOnState] ;
115144
[[self externalTarget] performSelector:[self externalAction]
116145
withObject:self] ;
117146
}
118147

119148
- (void)dealloc {
149+
[m_flashTimer invalidate] ;
150+
120151
[m_onImage release] ;
121152
[m_offImage release] ;
122153
[m_disImage release] ;
154+
[m_originalImage release] ;
123155
[m_onLabel release] ;
124156
[m_offLabel release] ;
125157
[m_disLabel release] ;

SSYVectorImages.h

+19-6
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,32 @@ enum SSYVectorImageStyles_enum
55
{
66
SSYVectorImageStylePlus,
77
SSYVectorImageStyleMinus,
8+
/* Dash is narrower and thinner than Minus */
9+
SSYVectorImageStyleDash,
810
/* Triangle, horizonal baseline, pointing up, with top vertex 90 degrees.
9-
This one is shorter and fatter. */
11+
This one is shorter and fatter than Triangle53. */
1012
SSYVectorImageStyleTriangle90,
1113
/* Triangle, horizonal baseline, pointing up, with top vertex 2*arctan(.5)
12-
= 53.2 degrees. This one is a taller and thinner. */
14+
= 53.2 degrees. This one is a taller and thinner than Triangle90. */
1315
SSYVectorImageStyleTriangle53,
14-
SSYVectorImageStyleInfo,
16+
SSYVectorImageStyleInfoOff,
17+
SSYVectorImageStyleInfoOn,
18+
SSYVectorImageStyleHelp,
1519
/* Five-pointed star used in SSYStarRatingView */
1620
SSYVectorImageStyleStar,
1721
/* White "X" inside a gray circle, used in SSYStarRatingView */
1822
SSYVectorImageStyleRemoveX,
19-
/* "Bookmark", solid color except for a white hole near the top */
20-
SSYVectorImageStyleBookmark
23+
/* "Bookmark", solid black except for a white hole near the top */
24+
SSYVectorImageStyleBookmark,
25+
SSYVectorImageStyleHierarchy,
26+
SSYVectorImageStyleFlat,
27+
SSYVectorImageStyleLineage,
28+
SSYVectorImageStyleTag,
29+
SSYVectorImageStyleCheck1,
30+
SSYVectorImageStyleCheck2,
31+
SSYVectorImageStyleBookmarksInFolder,
32+
SSYVectorImageStyleSettings,
33+
SSYVectorImageStyleReports
2134
} ;
2235
typedef enum SSYVectorImageStyles_enum SSYVectorImageStyle ;
2336

@@ -29,7 +42,7 @@ typedef enum SSYVectorImageStyles_enum SSYVectorImageStyle ;
2942
@param rotateDegrees Measure by which the result should be rotated clockwise
3043
*/
3144
+ (NSImage*)imageStyle:(SSYVectorImageStyle)style
32-
diameter:(CGFloat)diameter
45+
length:(CGFloat)length
3346
color:(NSColor*)color
3447
rotateDegrees:(CGFloat)rotateDegrees ;
3548

0 commit comments

Comments
 (0)