Permalink
Browse files

toolbar styles

  • Loading branch information...
1 parent 5bc3a35 commit f5660283122691a604ad798d3c785e4fd78ca83c Todd Ditchendorf committed Apr 18, 2010
@@ -87,7 +87,26 @@ - (void)viewDidLoad {
item = [[[UMEBarButtonItem alloc] initWithBarButtonSystemItem:UMEBarButtonSystemItemCompose target:nil action:nil] autorelease];
[items addObject:item];
-
+
+ item = [[[UMEBarButtonItem alloc] initWithBarButtonSystemItem:UMEBarButtonSystemItemReply target:nil action:nil] autorelease];
+ [items addObject:item];
+
+ item = [[[UMEBarButtonItem alloc] initWithBarButtonSystemItem:UMEBarButtonSystemItemRedo target:nil action:nil] autorelease];
+ [items addObject:item];
+
+ item = [[[UMEBarButtonItem alloc] initWithBarButtonSystemItem:UMEBarButtonSystemItemRewind target:nil action:nil] autorelease];
+ [items addObject:item];
+
+ item = [[[UMEBarButtonItem alloc] initWithBarButtonSystemItem:UMEBarButtonSystemItemRefresh target:nil action:nil] autorelease];
+ [items addObject:item];
+
+ item = [[[UMEBarButtonItem alloc] initWithBarButtonSystemItem:UMEBarButtonSystemItemEdit target:nil action:nil] autorelease];
+ [items addObject:item];
+
+ item = [[[UMEBarButtonItem alloc] initWithBarButtonSystemItem:UMEBarButtonSystemItemDone target:nil action:nil] autorelease];
+ [items addObject:item];
+
+ toolbar.barStyle = UMEBarStyleGray;
toolbar.items = items;
}
@@ -13,6 +13,7 @@
// limitations under the License.
#import <UMEKit/UMEBarItem.h>
+#import <UMEKit/UMEInterface.h>
typedef enum {
UMEBarButtonItemStylePlain, // shows glow when pressed
@@ -53,6 +54,8 @@ typedef enum {
NSButton *button;
UMEBarButtonItemStyle style;
CGFloat width;
+
+ UMEBarStyle barStyle;
}
- (id)initWithBarButtonSystemItem:(UMEBarButtonSystemItem)systemItem target:(id)target action:(SEL)action;
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -24,6 +24,7 @@ @interface UMEBarButtonItem ()
- (void)sizeToFit;
- (void)layout;
@property (nonatomic, retain) NSButton *button;
+@property (nonatomic) UMEBarStyle barStyle; // default is UMEBarStyleDefault
@end
@implementation UMEBarButtonItem
@@ -172,6 +173,7 @@ - (id)initWithTitle:(NSString *)aTitle style:(UMEBarButtonItemStyle)aStyle targe
self.title = aTitle;
self.target = aTarget;
self.action = sel;
+ self.barStyle = UMEBarStyleDefault;
if (CUSTOM_VIEW_FLAG != aStyle) {
self.customView = [[[UMEFlippedView alloc] initWithFrame:NSZeroRect] autorelease];
@@ -279,4 +281,5 @@ - (void)setCustomView:(NSView *)v {
@synthesize button;
@synthesize style;
@synthesize width;
+@synthesize barStyle;
@end
@@ -29,6 +29,7 @@
static NSShadow *sTitleShadow = nil;
+// barStyle default
static NSImage *sDefaultLeftImagePlain = nil;
static NSImage *sDefaultLeftImageDone = nil;
static NSImage *sDefaultLeftImageBack = nil;
@@ -39,6 +40,7 @@
static NSImage *sDefaultRightImageDone = nil;
static NSImage *sDefaultRightImageBack = nil;
+// barStyle default hi
static NSImage *sDefaultLeftImagePlainHi = nil;
static NSImage *sDefaultLeftImageDoneHi = nil;
static NSImage *sDefaultLeftImageBackHi = nil;
@@ -49,6 +51,54 @@
static NSImage *sDefaultRightImageDoneHi = nil;
static NSImage *sDefaultRightImageBackHi = nil;
+// barStyle black
+static NSImage *sBlackLeftImagePlain = nil;
+static NSImage *sBlackLeftImageDone = nil;
+static NSImage *sBlackLeftImageBack = nil;
+static NSImage *sBlackCenterImagePlain = nil;
+static NSImage *sBlackCenterImageDone = nil;
+static NSImage *sBlackCenterImageBack = nil;
+static NSImage *sBlackRightImagePlain = nil;
+static NSImage *sBlackRightImageDone = nil;
+static NSImage *sBlackRightImageBack = nil;
+
+// barStyle black hi
+static NSImage *sBlackLeftImagePlainHi = nil;
+static NSImage *sBlackLeftImageDoneHi = nil;
+static NSImage *sBlackLeftImageBackHi = nil;
+static NSImage *sBlackCenterImagePlainHi = nil;
+static NSImage *sBlackCenterImageDoneHi = nil;
+static NSImage *sBlackCenterImageBackHi = nil;
+static NSImage *sBlackRightImagePlainHi = nil;
+static NSImage *sBlackRightImageDoneHi = nil;
+static NSImage *sBlackRightImageBackHi = nil;
+
+// barStyle gray
+static NSImage *sGrayLeftImagePlain = nil;
+static NSImage *sGrayLeftImageDone = nil;
+static NSImage *sGrayLeftImageBack = nil;
+static NSImage *sGrayCenterImagePlain = nil;
+static NSImage *sGrayCenterImageDone = nil;
+static NSImage *sGrayCenterImageBack = nil;
+static NSImage *sGrayRightImagePlain = nil;
+static NSImage *sGrayRightImageDone = nil;
+static NSImage *sGrayRightImageBack = nil;
+
+// barStyle gray hi
+static NSImage *sGrayLeftImagePlainHi = nil;
+static NSImage *sGrayLeftImageDoneHi = nil;
+static NSImage *sGrayLeftImageBackHi = nil;
+static NSImage *sGrayCenterImagePlainHi = nil;
+static NSImage *sGrayCenterImageDoneHi = nil;
+static NSImage *sGrayCenterImageBackHi = nil;
+static NSImage *sGrayRightImagePlainHi = nil;
+static NSImage *sGrayRightImageDoneHi = nil;
+static NSImage *sGrayRightImageBackHi = nil;
+
+@interface UMEBarButtonItem ()
+@property (nonatomic) UMEBarStyle barStyle; // default is UMEBarStyleDefault
+@end
+
@interface UMEBarButtonItemButtonCell ()
- (void)commonInit;
@end
@@ -66,6 +116,7 @@ + (void)initialize {
NSBundle *b = [NSBundle bundleForClass:[UMEBarButtonItemButtonCell class]];
+ // barStyle default
sDefaultLeftImagePlain = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_default_plain_bg_01"]];
sDefaultLeftImageDone = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_default_done_bg_01"]];
sDefaultLeftImageBack = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_default_back_bg_01"]];
@@ -75,7 +126,8 @@ + (void)initialize {
sDefaultRightImagePlain = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_default_plain_bg_03"]];
sDefaultRightImageDone = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_default_done_bg_03"]];
sDefaultRightImageBack = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_default_back_bg_03"]];
-
+
+ // barStyle default hi
sDefaultLeftImagePlainHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_default_plain_bg_hi_01"]];
sDefaultLeftImageDoneHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_default_done_bg_hi_01"]];
sDefaultLeftImageBackHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_default_back_bg_hi_01"]];
@@ -86,6 +138,50 @@ + (void)initialize {
sDefaultRightImageDoneHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_default_done_bg_hi_03"]];
sDefaultRightImageBackHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_default_back_bg_hi_03"]];
+ // barStyle black
+ sBlackLeftImagePlain = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_black_plain_bg_01"]];
+ sBlackLeftImageDone = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_black_done_bg_01"]];
+ sBlackLeftImageBack = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_black_back_bg_01"]];
+ sBlackCenterImagePlain = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_black_plain_bg_02"]];
+ sBlackCenterImageDone = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_black_done_bg_02"]];
+ sBlackCenterImageBack = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_black_back_bg_02"]];
+ sBlackRightImagePlain = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_black_plain_bg_03"]];
+ sBlackRightImageDone = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_black_done_bg_03"]];
+ sBlackRightImageBack = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_black_back_bg_03"]];
+
+ // barStyle black hi
+ sBlackLeftImagePlainHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_black_plain_bg_hi_01"]];
+ sBlackLeftImageDoneHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_black_done_bg_hi_01"]];
+ sBlackLeftImageBackHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_black_back_bg_hi_01"]];
+ sBlackCenterImagePlainHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_black_plain_bg_hi_02"]];
+ sBlackCenterImageDoneHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_black_done_bg_hi_02"]];
+ sBlackCenterImageBackHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_black_back_bg_hi_02"]];
+ sBlackRightImagePlainHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_black_plain_bg_hi_03"]];
+ sBlackRightImageDoneHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_black_done_bg_hi_03"]];
+ sBlackRightImageBackHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_black_back_bg_hi_03"]];
+
+ // barStyle gray
+ sGrayLeftImagePlain = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_gray_plain_bg_01"]];
+ sGrayLeftImageDone = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_gray_done_bg_01"]];
+ sGrayLeftImageBack = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_gray_back_bg_01"]];
+ sGrayCenterImagePlain = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_gray_plain_bg_02"]];
+ sGrayCenterImageDone = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_gray_done_bg_02"]];
+ sGrayCenterImageBack = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_gray_back_bg_02"]];
+ sGrayRightImagePlain = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_gray_plain_bg_03"]];
+ sGrayRightImageDone = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_gray_done_bg_03"]];
+ sGrayRightImageBack = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_gray_back_bg_03"]];
+
+ // barStyle gray hi
+ sGrayLeftImagePlainHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_gray_plain_bg_hi_01"]];
+ sGrayLeftImageDoneHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_gray_done_bg_hi_01"]];
+ sGrayLeftImageBackHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_gray_back_bg_hi_01"]];
+ sGrayCenterImagePlainHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_gray_plain_bg_hi_02"]];
+ sGrayCenterImageDoneHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_gray_done_bg_hi_02"]];
+ sGrayCenterImageBackHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_gray_back_bg_hi_02"]];
+ sGrayRightImagePlainHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_gray_plain_bg_hi_03"]];
+ sGrayRightImageDoneHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_gray_done_bg_hi_03"]];
+ sGrayRightImageBackHi = [[NSImage alloc] initWithContentsOfFile:[b pathForImageResource:@"barbuttonitem_gray_back_bg_hi_03"]];
+
[pool release];
}
}
@@ -140,36 +236,117 @@ - (void)drawBackgroundWithFrame:(NSRect)r inView:(NSView *)cv {
switch (item.style) {
case UMEBarButtonItemStylePlain:
- if ([self isHighlighted]) {
- leftImage = sDefaultLeftImagePlainHi;
- centerImage = sDefaultCenterImagePlainHi;
- rightImage = sDefaultRightImagePlainHi;
- } else {
- leftImage = sDefaultLeftImagePlain;
- centerImage = sDefaultCenterImagePlain;
- rightImage = sDefaultRightImagePlain;
+ switch (item.barStyle) {
+ case UMEBarStyleDefault:
+ if ([self isHighlighted]) {
+ leftImage = sDefaultLeftImagePlainHi;
+ centerImage = sDefaultCenterImagePlainHi;
+ rightImage = sDefaultRightImagePlainHi;
+ } else {
+ leftImage = sDefaultLeftImagePlain;
+ centerImage = sDefaultCenterImagePlain;
+ rightImage = sDefaultRightImagePlain;
+ }
+ break;
+ case UMEBarStyleBlack:
+ if ([self isHighlighted]) {
+ leftImage = sBlackLeftImagePlainHi;
+ centerImage = sBlackCenterImagePlainHi;
+ rightImage = sBlackRightImagePlainHi;
+ } else {
+ leftImage = sBlackLeftImagePlain;
+ centerImage = sBlackCenterImagePlain;
+ rightImage = sBlackRightImagePlain;
+ }
+ break;
+ case UMEBarStyleGray:
+ if ([self isHighlighted]) {
+ leftImage = sGrayLeftImagePlainHi;
+ centerImage = sGrayCenterImagePlainHi;
+ rightImage = sGrayRightImagePlainHi;
+ } else {
+ leftImage = sGrayLeftImagePlain;
+ centerImage = sGrayCenterImagePlain;
+ rightImage = sGrayRightImagePlain;
+ }
+ break;
+ default:
+ break;
}
break;
case UMEBarButtonItemStyleDone:
- if ([self isHighlighted]) {
- leftImage = sDefaultLeftImageDoneHi;
- centerImage = sDefaultCenterImageDoneHi;
- rightImage = sDefaultRightImageDoneHi;
- } else {
- leftImage = sDefaultLeftImageDone;
- centerImage = sDefaultCenterImageDone;
- rightImage = sDefaultRightImageDone;
+ switch (item.barStyle) {
+ case UMEBarStyleDefault:
+ if ([self isHighlighted]) {
+ leftImage = sDefaultLeftImageDoneHi;
+ centerImage = sDefaultCenterImageDoneHi;
+ rightImage = sDefaultRightImageDoneHi;
+ } else {
+ leftImage = sDefaultLeftImageDone;
+ centerImage = sDefaultCenterImageDone;
+ rightImage = sDefaultRightImageDone;
+ }
+ case UMEBarStyleBlack:
+ if ([self isHighlighted]) {
+ leftImage = sBlackLeftImageDoneHi;
+ centerImage = sBlackCenterImageDoneHi;
+ rightImage = sBlackRightImageDoneHi;
+ } else {
+ leftImage = sBlackLeftImageDone;
+ centerImage = sBlackCenterImageDone;
+ rightImage = sBlackRightImageDone;
+ }
+ case UMEBarStyleGray:
+ if ([self isHighlighted]) {
+ leftImage = sGrayLeftImageDoneHi;
+ centerImage = sGrayCenterImageDoneHi;
+ rightImage = sGrayRightImageDoneHi;
+ } else {
+ leftImage = sGrayLeftImageDone;
+ centerImage = sGrayCenterImageDone;
+ rightImage = sGrayRightImageDone;
+ }
+ default:
+ break;
}
break;
case UMEBarButtonItemStyleBack:
- if ([self isHighlighted]) {
- leftImage = sDefaultLeftImageBackHi;
- centerImage = sDefaultCenterImageBackHi;
- rightImage = sDefaultRightImageBackHi;
- } else {
- leftImage = sDefaultLeftImageBack;
- centerImage = sDefaultCenterImageBack;
- rightImage = sDefaultRightImageBack;
+ switch (item.barStyle) {
+ case UMEBarStyleDefault:
+ if ([self isHighlighted]) {
+ leftImage = sDefaultLeftImageBackHi;
+ centerImage = sDefaultCenterImageBackHi;
+ rightImage = sDefaultRightImageBackHi;
+ } else {
+ leftImage = sDefaultLeftImageBack;
+ centerImage = sDefaultCenterImageBack;
+ rightImage = sDefaultRightImageBack;
+ }
+ break;
+ case UMEBarStyleBlack:
+ if ([self isHighlighted]) {
+ leftImage = sBlackLeftImageBackHi;
+ centerImage = sBlackCenterImageBackHi;
+ rightImage = sBlackRightImageBackHi;
+ } else {
+ leftImage = sBlackLeftImageBack;
+ centerImage = sBlackCenterImageBack;
+ rightImage = sBlackRightImageBack;
+ }
+ break;
+ case UMEBarStyleGray:
+ if ([self isHighlighted]) {
+ leftImage = sGrayLeftImageBackHi;
+ centerImage = sGrayCenterImageBackHi;
+ rightImage = sGrayRightImageBackHi;
+ } else {
+ leftImage = sGrayLeftImageBack;
+ centerImage = sGrayCenterImageBack;
+ rightImage = sGrayRightImageBack;
+ }
+ break;
+ default:
+ break;
}
break;
default:
View
@@ -8,12 +8,16 @@
#import "UMEToolbar.h"
+#define ITEM_X 4.0
+#define ITEM_MARGIN 5.0
+
static NSImage *sDefaultBackgroundImage = nil;
static NSImage *sBlackBackgroundImage = nil;
static NSImage *sGrayBackgroundImage = nil;
@interface UMEBarButtonItem ()
- (void)sizeToFit;
+@property (nonatomic) UMEBarStyle barStyle; // default is UMEBarStyleDefault
@end
@interface UMEToolbar ()
@@ -107,6 +111,10 @@ - (void)setItems:(NSArray *)a {
[items autorelease];
items = [a retain];
+ for (UMEBarButtonItem *item in items) {
+ item.barStyle = barStyle;
+ }
+
[self layoutItems];
}
}
@@ -116,7 +124,7 @@ - (void)setItems:(NSArray *)a {
#pragma mark Private
- (void)layoutItems {
- CGFloat x = 0;
+ CGFloat x = ITEM_X;
CGFloat y = 0;
CGFloat w = 0;
CGFloat h = 0;
@@ -127,7 +135,7 @@ - (void)layoutItems {
w = [item width];
h = NSHeight([item.customView frame]);
[item.customView setFrame:NSMakeRect(x, y, w, h)];
- x += w;
+ x += w + ITEM_MARGIN;
}
[self setNeedsDisplay:YES];

0 comments on commit f566028

Please sign in to comment.