some changes to the way text is drawn to the table

This commit is contained in:
Mitchell Livingston 2007-01-19 02:06:12 +00:00
parent 3e6d071e0d
commit 2944a10d60
3 changed files with 37 additions and 51 deletions

View File

@ -43,16 +43,14 @@
[NSFont messageFontOfSize: 12.0], NSFontAttributeName,
paragraphStyle, NSParagraphStyleAttributeName, nil];
float textHeight = [(NSTableView *)controlView rowHeight];
NSRect textRect = NSMakeRect(NSMaxX(imageRect) + SPACE, cellFrame.origin.y + 1.0,
NSMaxX(cellFrame) - NSMaxX(imageRect) - 2.0 * SPACE, textHeight);
NSString * nameString = [item objectForKey: @"Name"];
NSRect nameTextRect = NSMakeRect(NSMaxX(imageRect) + SPACE, cellFrame.origin.y + 1.0,
NSMaxX(cellFrame) - NSMaxX(imageRect) - 2.0 * SPACE, [nameString sizeWithAttributes: nameAttributes].height);
NSAttributedString * text = [[NSAttributedString alloc] initWithString: [item objectForKey: @"Name"]
attributes: nameAttributes];
[text drawInRect: textRect];
[text release];
[nameString drawInRect: nameTextRect withAttributes: nameAttributes];
[nameAttributes release];
//bottomText
//status text
if (![[item objectForKey: @"IsFolder"] boolValue])
{
NSDictionary * statusAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:
@ -60,22 +58,17 @@
[NSFont messageFontOfSize: 9.0], NSFontAttributeName,
paragraphStyle, NSParagraphStyleAttributeName, nil];
NSRect bottomTextRect = textRect;
bottomTextRect.origin.y += textHeight;
bottomTextRect.size.height = cellFrame.size.height - textHeight;
NSString * statusString = [NSString stringForFileSize: [[item objectForKey: @"Size"] unsignedLongLongValue]];
NSMutableAttributedString * bottomText = [[NSMutableAttributedString alloc] initWithString:
[NSString stringForFileSize: [[item objectForKey: @"Size"] unsignedLongLongValue]]
attributes: statusAttributes];
[bottomText drawInRect: bottomTextRect];
[bottomText release];
NSRect statusTextRect = nameTextRect;
statusTextRect.size.height = [statusString sizeWithAttributes: statusAttributes].height;
statusTextRect.origin.y += (cellFrame.size.height + nameTextRect.size.height - statusTextRect.size.height) * 0.5 - 1.0;
[statusString drawInRect: statusTextRect withAttributes: statusAttributes];
[statusAttributes release];
}
[paragraphStyle release];
[nameAttributes release];
}
@end

View File

@ -218,20 +218,20 @@
pen.x += iconSize.width + PADDING + EXTRA_NAME_SHIFT;
pen.y = cellFrame.origin.y + PADDING;
NSAttributedString * nameString = [[NSAttributedString alloc] initWithString: [info objectForKey: @"Name"]
attributes: nameAttributes];
[nameString drawInRect: NSMakeRect(pen.x, pen.y, mainWidth, [nameString size].height)];
NSString * nameString = [info objectForKey: @"Name"];
NSSize nameSize = [nameString sizeWithAttributes: nameAttributes];
[nameString drawInRect: NSMakeRect(pen.x, pen.y, mainWidth, nameSize.height) withAttributes: nameAttributes];
//progress string
pen.y += [nameString size].height + LINE_PADDING - 1.0;
pen.y += nameSize.height + LINE_PADDING - 1.0;
NSAttributedString * progressString = [[NSAttributedString alloc] initWithString:
[info objectForKey: @"ProgressString"] attributes: statusAttributes];
[progressString drawInRect: NSMakeRect(pen.x, pen.y, mainWidth, [progressString size].height)];
NSString * progressString = [info objectForKey: @"ProgressString"];
NSSize progressSize = [progressString sizeWithAttributes: statusAttributes];
[progressString drawInRect: NSMakeRect(pen.x, pen.y, mainWidth, progressSize.height) withAttributes: statusAttributes];
//progress bar
pen.x -= EXTRA_NAME_SHIFT;
pen.y += [progressString size].height + LINE_PADDING + BAR_HEIGHT;
pen.y += progressSize.height + LINE_PADDING + BAR_HEIGHT;
float barWidth = mainWidth + EXTRA_NAME_SHIFT - BUTTONS_TOTAL_WIDTH + PADDING;
@ -244,13 +244,9 @@
pen.x += EXTRA_NAME_SHIFT;
pen.y += LINE_PADDING;
NSAttributedString * statusString = [[NSAttributedString alloc] initWithString:
[info objectForKey: @"StatusString"] attributes: statusAttributes];
[statusString drawInRect: NSMakeRect(pen.x, pen.y, mainWidth, [statusString size].height)];
[nameString release];
[progressString release];
[statusString release];
NSString * statusString = [info objectForKey: @"StatusString"];
NSSize statusSize = [statusString sizeWithAttributes: statusAttributes];
[statusString drawInRect: NSMakeRect(pen.x, pen.y, mainWidth, statusSize.height) withAttributes: statusAttributes];
}
else //small size
{
@ -267,31 +263,31 @@
//name and status string
float mainWidth = cellFrame.size.width - iconSize.width - 3.0 * PADDING - EXTRA_NAME_SHIFT;
NSString * realStatusString = !fStatusRegular && [[info objectForKey: @"Active"] boolValue]
? [info objectForKey: @"RemainingTimeString"]
: [info objectForKey: @"ShortStatusString"];
NSAttributedString * statusString = [[NSAttributedString alloc] initWithString: realStatusString
attributes: statusAttributes];
NSAttributedString * nameString = [[NSAttributedString alloc] initWithString:
[info objectForKey: @"Name"] attributes: nameAttributes];
//place name string
pen.x += iconSize.width + PADDING + EXTRA_NAME_SHIFT;
pen.y = cellFrame.origin.y + LINE_PADDING;
[nameString drawInRect: NSMakeRect(pen.x, pen.y, mainWidth - [statusString size].width - LINE_PADDING,
[nameString size].height)];
NSString * nameString = [info objectForKey: @"Name"];
NSSize nameSize = [nameString sizeWithAttributes: nameAttributes];
NSString * statusString = !fStatusRegular && [[info objectForKey: @"Active"] boolValue]
? [info objectForKey: @"RemainingTimeString"]
: [info objectForKey: @"ShortStatusString"];
NSSize statusSize = [statusString sizeWithAttributes: statusAttributes];
[nameString drawInRect: NSMakeRect(pen.x, pen.y, mainWidth - statusSize.width - 2.0 * LINE_PADDING, nameSize.height)
withAttributes: nameAttributes];
//place status string
pen.x = NSMaxX(cellFrame) - PADDING - [statusString size].width;
pen.y += ([nameString size].height - [statusString size].height) * 0.5;
pen.x = NSMaxX(cellFrame) - PADDING - statusSize.width;
pen.y += (nameSize.height - statusSize.height) * 0.5;
[statusString drawAtPoint: pen];
[statusString drawInRect: NSMakeRect(pen.x, pen.y, statusSize.width, statusSize.height)
withAttributes: statusAttributes];
//progress bar
pen.x = cellFrame.origin.x + iconSize.width + 2.0 * PADDING;
pen.y = cellFrame.origin.y + [nameString size].height + LINE_PADDING + PADDING + BAR_HEIGHT;
pen.y = cellFrame.origin.y + nameSize.height + LINE_PADDING + PADDING + BAR_HEIGHT;
float barWidth = mainWidth + EXTRA_NAME_SHIFT - BUTTONS_TOTAL_WIDTH + PADDING;
@ -299,9 +295,6 @@
[self buildAdvancedBar: barWidth point: pen];
else
[self buildSimpleBar: barWidth point: pen];
[nameString release];
[statusString release];
}
[nameAttributes release];