Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipad screen size #31

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/KalGridView.h
Expand Up @@ -42,4 +42,5 @@
- (void)slideDown;
- (void)jumpToSelectedMonth; // see comment on KalView

+(CGSize) tileSize;
@end
27 changes: 22 additions & 5 deletions src/KalGridView.m
Expand Up @@ -17,8 +17,6 @@
#define SLIDE_UP 1
#define SLIDE_DOWN 2

const CGSize kTileSize = { 46.f, 44.f };

static NSString *kSlideAnimationId = @"KalSwitchMonths";

@interface KalGridView ()
Expand All @@ -31,6 +29,22 @@ @implementation KalGridView

@synthesize selectedTile, highlightedTile, transitioning;

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
#define KAL_IPAD_VERSION (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#else
#define KAL_IPAD_VERSION (NO)
#endif

+(CGSize) tileSize
{
if (KAL_IPAD_VERSION)
{
return CGSizeMake(110.f, 104.f);
}

return CGSizeMake(46.f, 44.f);
}

- (id)initWithFrame:(CGRect)frame logic:(KalLogic *)theLogic delegate:(id<KalViewDelegate>)theDelegate
{
// MobileCal uses 46px wide tiles, with a 2px inner stroke
Expand All @@ -41,7 +55,9 @@ - (id)initWithFrame:(CGRect)frame logic:(KalLogic *)theLogic delegate:(id<KalVie
// to accomodate all 7 columns. The 7th day's 2px inner stroke
// will be clipped off the screen, but that's fine because
// MobileCal does the same thing.
frame.size.width = 7 * kTileSize.width;
CGSize tileSize = [KalGridView tileSize];
if( frame.size.width < 7 * tileSize.width )
frame.size.width = 7 * tileSize.width;

if (self = [super initWithFrame:frame]) {
self.clipsToBounds = YES;
Expand Down Expand Up @@ -156,16 +172,17 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
- (void)swapMonthsAndSlide:(int)direction keepOneRow:(BOOL)keepOneRow
{
backMonthView.hidden = NO;
CGSize tileSize = [KalGridView tileSize];

// set initial positions before the slide
if (direction == SLIDE_UP) {
backMonthView.top = keepOneRow
? frontMonthView.bottom - kTileSize.height
? frontMonthView.bottom - tileSize.height
: frontMonthView.bottom;
} else if (direction == SLIDE_DOWN) {
NSUInteger numWeeksToKeep = keepOneRow ? 1 : 0;
NSInteger numWeeksToSlide = [backMonthView numWeeks] - numWeeksToKeep;
backMonthView.top = -numWeeksToSlide * kTileSize.height;
backMonthView.top = -numWeeksToSlide * tileSize.height;
} else {
backMonthView.top = 0.f;
}
Expand Down
12 changes: 7 additions & 5 deletions src/KalMonthView.m
Expand Up @@ -6,12 +6,11 @@
#import <CoreGraphics/CoreGraphics.h>
#import "KalMonthView.h"
#import "KalTileView.h"
#import "KalGridView.h"
#import "KalView.h"
#import "KalDate.h"
#import "KalPrivate.h"

extern const CGSize kTileSize;

@implementation KalMonthView

@synthesize numWeeks;
Expand All @@ -21,9 +20,10 @@ - (id)initWithFrame:(CGRect)frame
if ((self = [super initWithFrame:frame])) {
self.opaque = NO;
self.clipsToBounds = YES;
CGSize tileSize = [KalGridView tileSize];
for (int i=0; i<6; i++) {
for (int j=0; j<7; j++) {
CGRect r = CGRectMake(j*kTileSize.width, i*kTileSize.height, kTileSize.width, kTileSize.height);
CGRect r = CGRectMake(j*tileSize.width, i*tileSize.height, tileSize.width, tileSize.height);
[self addSubview:[[[KalTileView alloc] initWithFrame:r] autorelease]];
}
}
Expand Down Expand Up @@ -55,8 +55,9 @@ - (void)showDates:(NSArray *)mainDates leadingAdjacentDates:(NSArray *)leadingAd

- (void)drawRect:(CGRect)rect
{
CGSize tileSize = [KalGridView tileSize];
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextDrawTiledImage(ctx, (CGRect){CGPointZero,kTileSize}, [[UIImage imageNamed:@"Kal.bundle/kal_tile.png"] CGImage]);
CGContextDrawTiledImage(ctx, (CGRect){CGPointZero,tileSize}, [[UIImage imageNamed:@"Kal.bundle/kal_tile.png"] CGImage]);
}

- (KalTileView *)firstTileOfMonth
Expand Down Expand Up @@ -88,7 +89,8 @@ - (KalTileView *)tileForDate:(KalDate *)date

- (void)sizeToFit
{
self.height = 1.f + kTileSize.height * numWeeks;
CGSize tileSize = [KalGridView tileSize];
self.height = 1.f + tileSize.height * numWeeks;
}

- (void)markTilesForDates:(NSArray *)dates
Expand Down
22 changes: 11 additions & 11 deletions src/KalTileView.m
Expand Up @@ -5,10 +5,9 @@

#import "KalTileView.h"
#import "KalDate.h"
#import "KalGridView.h"
#import "KalPrivate.h"

extern const CGSize kTileSize;

@implementation KalTileView

@synthesize date;
Expand All @@ -34,22 +33,23 @@ - (void)drawRect:(CGRect)rect
UIColor *textColor = nil;
UIImage *markerImage = nil;
CGContextSelectFont(ctx, [font.fontName cStringUsingEncoding:NSUTF8StringEncoding], fontSize, kCGEncodingMacRoman);

CGContextTranslateCTM(ctx, 0, kTileSize.height);

CGSize tileSize = [KalGridView tileSize];
CGContextTranslateCTM(ctx, 0, tileSize.height);
CGContextScaleCTM(ctx, 1, -1);

if ([self isToday] && self.selected) {
[[[UIImage imageNamed:@"Kal.bundle/kal_tile_today_selected.png"] stretchableImageWithLeftCapWidth:6 topCapHeight:0] drawInRect:CGRectMake(0, -1, kTileSize.width+1, kTileSize.height+1)];
[[[UIImage imageNamed:@"Kal.bundle/kal_tile_today_selected.png"] stretchableImageWithLeftCapWidth:6 topCapHeight:0] drawInRect:CGRectMake(0, -1, tileSize.width+1, tileSize.height+1)];
textColor = [UIColor whiteColor];
shadowColor = [UIColor blackColor];
markerImage = [UIImage imageNamed:@"Kal.bundle/kal_marker_today.png"];
} else if ([self isToday] && !self.selected) {
[[[UIImage imageNamed:@"Kal.bundle/kal_tile_today.png"] stretchableImageWithLeftCapWidth:6 topCapHeight:0] drawInRect:CGRectMake(0, -1, kTileSize.width+1, kTileSize.height+1)];
[[[UIImage imageNamed:@"Kal.bundle/kal_tile_today.png"] stretchableImageWithLeftCapWidth:6 topCapHeight:0] drawInRect:CGRectMake(0, -1, tileSize.width+1, tileSize.height+1)];
textColor = [UIColor whiteColor];
shadowColor = [UIColor blackColor];
markerImage = [UIImage imageNamed:@"Kal.bundle/kal_marker_today.png"];
} else if (self.selected) {
[[[UIImage imageNamed:@"Kal.bundle/kal_tile_selected.png"] stretchableImageWithLeftCapWidth:1 topCapHeight:0] drawInRect:CGRectMake(0, -1, kTileSize.width+1, kTileSize.height+1)];
[[[UIImage imageNamed:@"Kal.bundle/kal_tile_selected.png"] stretchableImageWithLeftCapWidth:1 topCapHeight:0] drawInRect:CGRectMake(0, -1, tileSize.width+1, tileSize.height+1)];
textColor = [UIColor whiteColor];
shadowColor = [UIColor blackColor];
markerImage = [UIImage imageNamed:@"Kal.bundle/kal_marker_selected.png"];
Expand All @@ -71,8 +71,8 @@ - (void)drawRect:(CGRect)rect
const char *day = [dayText cStringUsingEncoding:NSUTF8StringEncoding];
CGSize textSize = [dayText sizeWithFont:font];
CGFloat textX, textY;
textX = roundf(0.5f * (kTileSize.width - textSize.width));
textY = 6.f + roundf(0.5f * (kTileSize.height - textSize.height));
textX = roundf(0.5f * (tileSize.width - textSize.width));
textY = 6.f + roundf(0.5f * (tileSize.height - textSize.height));
if (shadowColor) {
[shadowColor setFill];
CGContextShowTextAtPoint(ctx, textX, textY, day, n >= 10 ? 2 : 1);
Expand All @@ -83,7 +83,7 @@ - (void)drawRect:(CGRect)rect

if (self.highlighted) {
[[UIColor colorWithWhite:0.25f alpha:0.3f] setFill];
CGContextFillRect(ctx, CGRectMake(0.f, 0.f, kTileSize.width, kTileSize.height));
CGContextFillRect(ctx, CGRectMake(0.f, 0.f, tileSize.width, tileSize.height));
}
}

Expand All @@ -92,7 +92,7 @@ - (void)resetState
// realign to the grid
CGRect frame = self.frame;
frame.origin = origin;
frame.size = kTileSize;
frame.size = [KalGridView tileSize];
self.frame = frame;

[date release];
Expand Down
29 changes: 24 additions & 5 deletions src/KalView.m
Expand Up @@ -14,13 +14,26 @@ - (void)addSubviewsToContentView:(UIView *)contentView;
- (void)setHeaderTitleText:(NSString *)text;
@end

static const CGFloat kHeaderHeight = 44.f;
static const CGFloat kMonthLabelHeight = 17.f;

@implementation KalView

@synthesize delegate, tableView;

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
#define KAL_IPAD_VERSION (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#else
#define KAL_IPAD_VERSION (NO)
#endif

-(CGFloat) headerHeight
{
if(KAL_IPAD_VERSION)
return 80.f;

return 44.f;
}

- (id)initWithFrame:(CGRect)frame delegate:(id<KalViewDelegate>)theDelegate logic:(KalLogic *)theLogic
{
if ((self = [super initWithFrame:frame])) {
Expand All @@ -29,6 +42,8 @@ - (id)initWithFrame:(CGRect)frame delegate:(id<KalViewDelegate>)theDelegate logi
[logic addObserver:self forKeyPath:@"selectedMonthNameAndYear" options:NSKeyValueObservingOptionNew context:NULL];
self.autoresizesSubviews = YES;
self.autoresizingMask = UIViewAutoresizingFlexibleHeight;

const CGFloat kHeaderHeight = [self headerHeight];

UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, frame.size.width, kHeaderHeight)] autorelease];
headerView.backgroundColor = [UIColor grayColor];
Expand Down Expand Up @@ -72,7 +87,7 @@ - (void)addSubviewsToHeaderView:(UIView *)headerView
const CGFloat kChangeMonthButtonWidth = 46.0f;
const CGFloat kChangeMonthButtonHeight = 30.0f;
const CGFloat kMonthLabelWidth = 200.0f;
const CGFloat kHeaderVerticalAdjust = 3.f;
const CGFloat kHeaderVerticalAdjust = KAL_IPAD_VERSION ? 7.f : 3.f;

// Header background gradient
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Kal.bundle/kal_grid_background.png"]];
Expand Down Expand Up @@ -127,11 +142,15 @@ - (void)addSubviewsToHeaderView:(UIView *)headerView
NSArray *weekdayNames = [[[[NSDateFormatter alloc] init] autorelease] shortWeekdaySymbols];
NSUInteger firstWeekday = [[NSCalendar currentCalendar] firstWeekday];
NSUInteger i = firstWeekday - 1;
for (CGFloat xOffset = 0.f; xOffset < headerView.width; xOffset += 46.f, i = (i+1)%7) {
CGRect weekdayFrame = CGRectMake(xOffset, 30.f, 46.f, kHeaderHeight - 29.f);
CGSize tileSize = [KalGridView tileSize];
CGFloat columnWidth = tileSize.width;
CGFloat fontSize = KAL_IPAD_VERSION ? 20.f : 10.f;
const CGFloat kHeaderHeight = [self headerHeight];
for (CGFloat xOffset = 0.f; xOffset < headerView.width; xOffset += columnWidth, i = (i+1)%7) {
CGRect weekdayFrame = CGRectMake(xOffset, 30.f, columnWidth, kHeaderHeight - 29.f);
UILabel *weekdayLabel = [[UILabel alloc] initWithFrame:weekdayFrame];
weekdayLabel.backgroundColor = [UIColor clearColor];
weekdayLabel.font = [UIFont boldSystemFontOfSize:10.f];
weekdayLabel.font = [UIFont boldSystemFontOfSize:fontSize];
weekdayLabel.textAlignment = UITextAlignmentCenter;
weekdayLabel.textColor = [UIColor colorWithRed:0.3f green:0.3f blue:0.3f alpha:1.f];
weekdayLabel.shadowColor = [UIColor whiteColor];
Expand Down