when mousing over the icon, show the action button

This commit is contained in:
Mitchell Livingston 2008-01-16 06:48:12 +00:00
parent 4dbbe863f9
commit 4a3d5d7081
4 changed files with 60 additions and 38 deletions

View File

@ -31,7 +31,7 @@
NSMutableDictionary * fTitleAttributes, * fStatusAttributes;
BOOL fTracking, fMouseDownControlButton, fMouseDownRevealButton, fHoverControl, fHoverReveal, fHoverAction;
BOOL fTracking, fMouseDownControlButton, fMouseDownRevealButton, fHoverControl, fHoverReveal, fHoverAction, fHoverActionIcon;
NSColor * fBarOverlayColor;
CTGradient * fWhiteGradient, * fGrayGradient, * fLightGrayGradient, * fBlueGradient, * fDarkBlueGradient,
@ -59,5 +59,6 @@
- (void) setControlHover: (BOOL) hover;
- (void) setRevealHover: (BOOL) hover;
- (void) setActionHover: (BOOL) hover;
- (void) setActionIconHover: (BOOL) hover;
@end

View File

@ -36,8 +36,6 @@
#define IMAGE_SIZE_MIN 16.0
#define NORMAL_BUTTON_WIDTH 14.0
/*#define ACTION_BUTTON_HEIGHT 14.0
#define ACTION_BUTTON_WIDTH 32.0*/
#define ACTION_BUTTON_WIDTH 16.0
//ends up being larger than font height
@ -45,8 +43,6 @@
#define HEIGHT_STATUS 12.0
#define PADDING_HORIZONTAL 3.0
//#define PADDING_ABOVE_IMAGE_REG 9.0
//#define PADDING_BETWEEN_IMAGE_AND_ACTION_BUTTON 3.0
#define PADDING_BETWEEN_IMAGE_AND_TITLE 5.0
#define PADDING_BETWEEN_IMAGE_AND_BAR 7.0
#define PADDING_ABOVE_TITLE 3.0
@ -157,26 +153,13 @@
- (NSRect) iconRectForBounds: (NSRect) bounds
{
NSRect result = bounds;
float imageSize = [fDefaults boolForKey: @"SmallView"] ? IMAGE_SIZE_MIN : IMAGE_SIZE_REG;
NSRect result = bounds;
result.origin.x += PADDING_HORIZONTAL;
result.origin.y += floorf((result.size.height - imageSize) * 0.5);
result.size = NSMakeSize(imageSize, imageSize);
/*float imageSize;
if ([fDefaults boolForKey: @"SmallView"])
{
imageSize = IMAGE_SIZE_MIN;
result.origin.y += (result.size.height - imageSize) * 0.5;
}
else
{
imageSize = IMAGE_SIZE_REG;
result.origin.y += PADDING_ABOVE_IMAGE_REG;
}*/
return result;
}
@ -260,18 +243,12 @@
if ([fDefaults boolForKey: @"SmallView"])
return iconRect;
/*NSRect result = iconRect;
result.origin.x += (iconRect.size.width - ACTION_BUTTON_WIDTH) * 0.5;
result.origin.y += iconRect.size.height + PADDING_BETWEEN_IMAGE_AND_ACTION_BUTTON;
result.size.width = ACTION_BUTTON_WIDTH;
result.size.height = ACTION_BUTTON_HEIGHT;*/
NSRect result = iconRect;
result.origin.x += (iconRect.size.width - ACTION_BUTTON_WIDTH) * 0.5;
result.origin.y += (iconRect.size.height - ACTION_BUTTON_WIDTH) * 0.5;
result.size.width = ACTION_BUTTON_WIDTH;
result.size.height = ACTION_BUTTON_WIDTH;
return result;
}
@ -401,7 +378,7 @@
[revealInfo release];
[area release];
//action button (needed even in minimal mode to display status string)
//action button
NSRect actionButtonRect = [self actionButtonRectForBounds: cellFrame];
NSTrackingAreaOptions actionOptions = options;
if (NSMouseInRect(mouseLocation, actionButtonRect, [controlView isFlipped]))
@ -416,6 +393,26 @@
[controlView addTrackingArea: area];
[actionInfo release];
[area release];
//action button (over icon)
if (![fDefaults boolForKey: @"SmallView"])
{
NSRect actionIconButtonRect = [self iconRectForBounds: cellFrame];
NSTrackingAreaOptions actionIconOptions = options;
if (NSMouseInRect(mouseLocation, actionIconButtonRect, [controlView isFlipped]))
{
actionIconOptions |= NSTrackingAssumeInside;
[(TorrentTableView *)controlView setActionIconButtonHover: [[userInfo objectForKey: @"Row"] intValue]];
}
NSMutableDictionary * actionIconInfo = [userInfo mutableCopy];
[actionIconInfo setObject: @"Icon" forKey: @"Type"];
area = [[NSTrackingArea alloc] initWithRect: actionIconButtonRect options: actionIconOptions owner: controlView
userInfo: actionIconInfo];
[controlView addTrackingArea: area];
[actionIconInfo release];
[area release];
}
}
- (void) setControlHover: (BOOL) hover
@ -433,6 +430,11 @@
fHoverAction = [NSApp isOnLeopardOrBetter] ? hover : NO;
}
- (void) setActionIconHover: (BOOL) hover
{
fHoverActionIcon = [NSApp isOnLeopardOrBetter] ? hover : NO;
}
- (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) controlView
{
[super drawWithFrame: cellFrame inView: controlView];
@ -564,8 +566,9 @@
NSString * actionImageSuffix;
if (!fTracking && fHoverAction)
actionImageSuffix = @"Hover.png";
else if (!fTracking && fHoverActionIcon)
actionImageSuffix = @"Off.png";
else
//actionImageSuffix = @"Off.png";
actionImageSuffix = nil;
if (actionImageSuffix)

View File

@ -37,7 +37,7 @@
IBOutlet NSMenu * fContextRow, * fContextNoRow;
int fMouseControlRow, fMouseRevealRow, fMouseActionRow;
int fMouseControlRow, fMouseRevealRow, fMouseActionRow, fMouseActionIconRow;
NSIndexSet * fSelectedIndexes;
NSMutableArray * fKeyStrokes;
@ -52,6 +52,7 @@
- (void) setControlButtonHover: (int) row;
- (void) setRevealButtonHover: (int) row;
- (void) setActionButtonHover: (int) row;
- (void) setActionIconButtonHover: (int) row;
- (void) toggleControlForTorrent: (Torrent *) torrent;

View File

@ -57,6 +57,7 @@
fMouseControlRow = -1;
fMouseRevealRow = -1;
fMouseActionRow = -1;
fMouseActionIconRow = -1;
[self setDelegate: self];
}
@ -85,6 +86,7 @@
[cell setControlHover: row == fMouseControlRow];
[cell setRevealHover: row == fMouseRevealRow];
[cell setActionHover: row == fMouseActionRow];
[cell setActionIconHover: row == fMouseActionIconRow];
}
- (NSString *) tableView: (NSTableView *) tableView typeSelectStringForTableColumn: (NSTableColumn *) tableColumn row: (int) row
@ -121,6 +123,7 @@
fMouseControlRow = -1;
fMouseRevealRow = -1;
fMouseActionRow = -1;
fMouseActionIconRow = -1;
NSEnumerator * enumerator = [[self trackingAreas] objectEnumerator];
NSTrackingArea * area;
@ -145,7 +148,6 @@
[self setNeedsDisplayInRect: [self rectOfRow: row]];
}
- (void) setActionButtonHover: (int) row
{
fMouseActionRow = row;
@ -153,6 +155,13 @@
[self setNeedsDisplayInRect: [self rectOfRow: row]];
}
- (void) setActionIconButtonHover: (int) row
{
fMouseActionIconRow = row;
if (row >= 0)
[self setNeedsDisplayInRect: [self rectOfRow: row]];
}
- (void) mouseEntered: (NSEvent *) event
{
NSDictionary * dict = (NSDictionary *)[event userData];
@ -161,12 +170,14 @@
if ((row = [dict objectForKey: @"Row"]))
{
int rowVal = [row intValue];
if ([[dict objectForKey: @"Type"] isEqualToString: @"Action"])
fMouseActionRow = rowVal;
else if ([[dict objectForKey: @"Type"] isEqualToString: @"Icon"])
fMouseActionIconRow = rowVal;
if ([[dict objectForKey: @"Type"] isEqualToString: @"Control"])
fMouseControlRow = rowVal;
else if ([[dict objectForKey: @"Type"] isEqualToString: @"Reveal"])
fMouseRevealRow = rowVal;
else
fMouseActionRow = rowVal;
fMouseRevealRow = rowVal;
[self setNeedsDisplayInRect: [self rectOfRow: rowVal]];
}
@ -174,12 +185,20 @@
- (void) mouseExited: (NSEvent *) event
{
NSDictionary * dict = (NSDictionary *)[event userData];
NSNumber * row;
if ((row = [(NSDictionary *)[event userData] objectForKey: @"Row"]))
if ((row = [dict objectForKey: @"Row"]))
{
fMouseControlRow = -1;
fMouseRevealRow = -1;
fMouseActionRow = -1;
int rowVal = [row intValue];
if ([[dict objectForKey: @"Type"] isEqualToString: @"Action"])
fMouseActionRow = -1;
else if ([[dict objectForKey: @"Type"] isEqualToString: @"Icon"])
fMouseActionIconRow = -1;
if ([[dict objectForKey: @"Type"] isEqualToString: @"Control"])
fMouseControlRow = -1;
else
fMouseRevealRow = -1;
[self setNeedsDisplayInRect: [self rectOfRow: [row intValue]]];
}
@ -229,8 +248,6 @@
[fDefaults setBool: ![fDefaults boolForKey: @"DisplayStatusProgressSelected"] forKey: @"DisplayStatusProgressSelected"];
[self reloadData];
}
else if ([self pointInIconRect: point])
[[fTorrents objectAtIndex: [self rowAtPoint: point]] revealData];
else
[fController showInfo: nil];
}