Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 12 additions & 49 deletions Pod/Classes/ALDTimer.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,21 @@

#import "ALDTimer.h"




typedef struct{
double x;
double y;
double z;
} ALDVector3D;



@interface ALDTimer ()

@property (nonatomic, assign) CGFloat totalRotation;
@property (nonatomic, assign) CGFloat radius;


- (void)moveHandFromPoint:(CGPoint)fromPoint toPoint:(CGPoint)toPoint;
- (void)updateDisplayAndListeners;


/*this limits angle and interval in interval limits set by user*/
- (void)updateIntervalInBoundsWithAngleDelta:(float)angleDelta;

Expand All @@ -44,9 +38,6 @@ - (void)drawCirclesWithNumber:(int)cirlce context:(CGContextRef)context;

@implementation ALDTimer




- (instancetype)initWithCoder:(NSCoder *)aDecoder {

self = [super initWithCoder:aDecoder];
Expand All @@ -67,20 +58,16 @@ - (instancetype)initWithFrame:(CGRect)frame {

- (void)awakeFromNib{
[self commonInit];

}

- (void)commonInit {
[super setBackgroundColor:[UIColor clearColor]];


//zero interval
_totalRotation = 0;


// How wide should the clock be?
[self updateRadius];

}

- (void)updateRadius {
Expand All @@ -94,11 +81,6 @@ - (void)setFrame:(CGRect)frame {
[self updateRadius];
}






#pragma mark - Tracking Methods

-(BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
Expand All @@ -113,7 +95,6 @@ -(BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
-(BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event{
[super continueTrackingWithTouch:touch withEvent:event];


//Get touch location
CGPoint currentPoint = [touch locationInView:self];
CGPoint previousPoint = [touch previousLocationInView:self];
Expand All @@ -132,8 +113,6 @@ - (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
#pragma mark -
#pragma mark - Handle Tracking



-(void)moveHandFromPoint:(CGPoint)fromPoint toPoint:(CGPoint)toPoint {

CGPoint center = CGPointMake(CGRectGetWidth(self.frame)/2.0, CGRectGetHeight(self.frame)/2.0);
Expand All @@ -151,11 +130,9 @@ -(void)moveHandFromPoint:(CGPoint)fromPoint toPoint:(CGPoint)toPoint {
[self updateIntervalInBoundsWithAngleDelta:directedDeltaAngle];
}


/*this limits angle and interval in interval limits set by user*/
- (void)updateIntervalInBoundsWithAngleDelta:(float)angleDelta{


//flip the angle , because we increase timer based on right rotation
angleDelta= -1*angleDelta;

Expand Down Expand Up @@ -183,21 +160,14 @@ - (void)updateIntervalInBoundsWithAngleDelta:(float)angleDelta{

//Redraw
[self updateDisplayAndListeners];

}



- (void)updateDisplayAndListeners {

[self sendActionsForControlEvents:UIControlEventValueChanged];
[self setNeedsDisplay];
}





#pragma mark -


Expand Down Expand Up @@ -242,7 +212,6 @@ - (BOOL)isMovingCounterClockwise:(ALDVector3D)v1 vector:(ALDVector3D)v2 {
return isCounterClockwise;
}


#pragma mark -

/*returns the inclosing rect for clock*/
Expand All @@ -264,41 +233,40 @@ - (CGRect)clockRect{
return rectForClockFace;
}


- (void)drawRect:(CGRect)rect {


CGContextRef context = UIGraphicsGetCurrentContext();


// Draw the clock background
CGContextSetFillColorWithColor(context, self.backgroundColor.CGColor);
CGContextFillEllipseInRect(context, [self clockRect]);


//draw the cicles depends on how much cirlces we need
int numberOfCirlces = self.maximumInterval/3600;
if((self.maximumInterval- numberOfCirlces*3600)>0)
numberOfCirlces++;
int numberOfCircles = 0;

double tempInterval = _interval;

for(int circle = 1 ; circle<=numberOfCirlces; circle++){
[self drawCirclesWithNumber:circle context:context];

while (tempInterval >= 0) {
numberOfCircles = numberOfCircles + 1;
tempInterval = tempInterval - 3600;
}

if (_interval == self.maximumInterval) {
numberOfCircles = numberOfCircles - 1;
}

for(int circle = 1 ; circle<=numberOfCircles; circle++){
[self drawCirclesWithNumber:circle context:context];
}
}


/*draws the dots in circles*/
- (void)drawCirclesWithNumber:(int)cirlce context:(CGContextRef)context{

CGPoint center = CGPointMake(self.frame.size.width/2.0f, self.frame.size.height/2.0f);
float dotradius = self.dotRadius - (self.dotRadius*self.decreaseSizeBy/100)*cirlce;
float offset = self.circleDistance*cirlce;



for(NSInteger i = 0; i < 60; i ++) {

//if we dont do it , it starts at x= 0 ;
Expand All @@ -310,22 +278,17 @@ - (void)drawCirclesWithNumber:(int)cirlce context:(CGContextRef)context{
CGFloat markingX1 = center.x + markingDistanceFromCenter * cos((M_PI/180)* (i+ angleOffset) * 6 + M_PI);
CGFloat markingY1 = center.y + - 1 * markingDistanceFromCenter * sin((M_PI/180)* (i+ angleOffset) * 6);


if(self.interval>(i*60+ ((cirlce-1) * 3600)))
CGContextSetFillColorWithColor(context, self.selectedDotColor.CGColor);
else
CGContextSetFillColorWithColor(context, self.unSelectedDotColor.CGColor);

CGContextFillEllipseInRect(context, CGRectMake(markingX1-3,
markingY1-3,dotradius*2,dotradius*2));


}

// Draw minor markings.
CGContextDrawPath(context, kCGPathStroke);


}


Expand Down