Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // GraphicView.m
- // W24X
- //
- // Created by Carey Richardson on 1/31/15.
- // Copyright (c) 2015 Edge of the Atlas. All rights reserved.
- //
- #import "GraphicView.h"
- #define DEGREES_TO_RADIANS(degrees)((M_PI * degrees)/180)
- @implementation GraphicView
- @synthesize myDelegate = _myDelegate;
- @synthesize thisStation, graphicBackgroundColor, baseRadius, metarObject, tfrObject, tafObject, airmetObject;
- -(id)init{
- //
- self = [super init];
- if(self){
- // set vars
- //NSLog(@"init");
- // set app delegate
- appDelegate = [[UIApplication sharedApplication] delegate];
- // init vars
- baseRadius = 58;
- metarObject = [MetarObject new];
- tfrObject = [TFRObject new];
- tafObject = [TAFObject new];
- airmetObject = [AirmetObject new];
- }
- return self;
- }
- -(void)metarSingleTap:(UITapGestureRecognizer*)gesture {
- // callback
- [_myDelegate metarDataToggleTouched];
- }
- -(void)metarDoubleTap:(UITapGestureRecognizer*)gesture {
- // callback
- [_myDelegate metarTouchedWithMetar:metarObject];
- }
- -(void)tafSingleTap:(UITapGestureRecognizer*)gesture {
- // check
- NSLog(@"single");
- }
- -(void)tafDoubleTap:(UITapGestureRecognizer*)gesture {
- // callback
- [_myDelegate tafTouchedWithTAF:tafObject];
- }
- -(void)updateView{
- //NSLog(@"updating");
- [self setNeedsDisplay];
- }
- -(void)drawRect:(CGRect)rect {
- // Drawing code
- //NSLog(@"drawing");
- // check
- if([self subviews].count > 0){
- // clear
- for(UIView *tempView in [self subviews]){
- // remove
- [tempView removeFromSuperview];
- }
- }
- // vars
- CGPoint center = CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2);
- float metarRadius = baseRadius;
- float tfrRadius = metarRadius + 8;
- float tafRadius = tfrRadius + 48;
- float tafOuterPadding = 1;
- float airmetIFRRadius = tafRadius + tafOuterPadding + 8;
- float airmetIFROuterPadding = 1;
- float airmetICERadius = airmetIFRRadius + airmetIFROuterPadding + 8;
- float airmetICEOuterPadding = 1;
- float airmetTURBRadius = airmetICERadius + airmetICEOuterPadding + 8;
- float airmetTURBOuterPadding = 1;
- float airmetMTNRadius = airmetTURBRadius + airmetTURBOuterPadding + 8;
- float airmetMTNOuterPadding = 1;
- float airmetCONVRadius = airmetMTNRadius + airmetMTNOuterPadding + 8;
- // offset
- NSDate *nowDate = [NSDate date];
- NSTimeInterval timeZoneSeconds = [[NSTimeZone localTimeZone] secondsFromGMT];
- NSDate *utcDate = [nowDate dateByAddingTimeInterval:(timeZoneSeconds * -1)];
- NSDate *metarDate = metarObject.dateUTC;
- NSTimeInterval distanceBetweenDates = [utcDate timeIntervalSinceDate:metarDate];
- double minutesInAnHour = 60;
- double secondsInAnHour = 3600;
- NSInteger minutesBetweenDates = distanceBetweenDates / minutesInAnHour;
- NSInteger hoursBetweenDates = distanceBetweenDates / secondsInAnHour;
- NSInteger timeOffset = hoursBetweenDates;
- /*NSLog(@"now utc %@", utcDate);
- NSLog(@"metar utc %@", metarDate);
- NSLog(@"minutes between dates %ld", (long)minutesBetweenDates);
- NSLog(@"hours between dates %ld", (long)hoursBetweenDates);
- NSLog(@"time offset %ld", (long)timeOffset);
- NSLog(@"global time offset %ld", (long)[appDelegate.myGlobals timeOffset]);*/
- // check
- if([appDelegate.myGlobals airmetOn]){
- /* ==================== */
- // airmet conv bkg
- /* ====================*/
- UIBezierPath *airmetCONVBkg = [UIBezierPath bezierPathWithArcCenter:center radius:airmetCONVRadius startAngle:DEGREES_TO_RADIANS(0) endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
- [graphicBackgroundColor setFill];
- [airmetCONVBkg fill];
- /* ==================== */
- // airmet conv
- /* ====================*/
- for(AirmetSegmentObject *convObject in airmetObject.convSegments){
- // vars
- UIColor *convFill = [appDelegate.myGlobals getColorWithName:convObject.color];
- NSTimeInterval metarTimeInterval = [metarObject.dateUTC timeIntervalSince1970];
- NSTimeInterval tafStartTimeInterval = [convObject.startDateUTC timeIntervalSince1970];
- NSTimeInterval tafEndTimeInterval = [convObject.endDateUTC timeIntervalSince1970];
- NSInteger startTimeBetweenDates = tafStartTimeInterval - metarTimeInterval;
- NSInteger endTimeBetweenDates = tafEndTimeInterval - metarTimeInterval;
- float startTime = (startTimeBetweenDates/3600) - timeOffset;
- float endTime = (endTimeBetweenDates/3600) - timeOffset;
- // check
- if(startTime < 0){
- // set
- startTime = 0;
- }
- // check
- if(endTime < 0){
- // set
- endTime = 0;
- }
- float startDegrees = DEGREES_TO_RADIANS((startTime - 6) * 15);
- float endDegrees = DEGREES_TO_RADIANS((endTime - 6) * 15);
- // conv segment
- UIBezierPath *convSegment = [UIBezierPath bezierPath];
- [convSegment moveToPoint:center];
- [convSegment addArcWithCenter:center radius:airmetCONVRadius startAngle:startDegrees endAngle:endDegrees clockwise:YES];
- [convSegment addLineToPoint:center];
- [convFill setFill];
- [convSegment fill];
- }
- /* ==================== */
- // airmet mtn spacer
- /* ====================*/
- UIBezierPath *airmetMTNSpacer = [UIBezierPath bezierPathWithArcCenter:center radius:(airmetMTNRadius + airmetMTNOuterPadding) startAngle:DEGREES_TO_RADIANS(0) endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
- [graphicBackgroundColor setFill];
- [airmetMTNSpacer fill];
- /* ==================== */
- // airmet mtn bkg
- /* ====================*/
- UIBezierPath *airmetMTNBkg = [UIBezierPath bezierPathWithArcCenter:center radius:airmetMTNRadius startAngle:DEGREES_TO_RADIANS(0) endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
- [graphicBackgroundColor setFill];
- [airmetMTNBkg fill];
- /* ==================== */
- // airmet mtn
- /* ====================*/
- for(AirmetSegmentObject *mtnObject in airmetObject.mtnSegments){
- // vars
- UIColor *mtnFill = [appDelegate.myGlobals getColorWithName:mtnObject.color];
- NSTimeInterval metarTimeInterval = [metarObject.dateUTC timeIntervalSince1970];
- NSTimeInterval tafStartTimeInterval = [mtnObject.startDateUTC timeIntervalSince1970];
- NSTimeInterval tafEndTimeInterval = [mtnObject.endDateUTC timeIntervalSince1970];
- NSInteger startTimeBetweenDates = tafStartTimeInterval - metarTimeInterval;
- NSInteger endTimeBetweenDates = tafEndTimeInterval - metarTimeInterval;
- float startTime = (startTimeBetweenDates/3600) - timeOffset;
- float endTime = (endTimeBetweenDates/3600) - timeOffset;
- // check
- if(startTime < 0){
- // set
- startTime = 0;
- }
- // check
- if(endTime < 0){
- // set
- endTime = 0;
- }
- float startDegrees = DEGREES_TO_RADIANS((startTime - 6) * 15);
- float endDegrees = DEGREES_TO_RADIANS((endTime - 6) * 15);
- // mtn segment
- UIBezierPath *mtnSegment = [UIBezierPath bezierPath];
- [mtnSegment moveToPoint:center];
- [mtnSegment addArcWithCenter:center radius:airmetMTNRadius startAngle:startDegrees endAngle:endDegrees clockwise:YES];
- [mtnSegment addLineToPoint:center];
- [mtnFill setFill];
- [mtnSegment fill];
- }
- /* ==================== */
- // airmet turb spacer
- /* ====================*/
- UIBezierPath *airmetTURBSpacer = [UIBezierPath bezierPathWithArcCenter:center radius:(airmetTURBRadius + airmetTURBOuterPadding) startAngle:DEGREES_TO_RADIANS(0) endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
- [graphicBackgroundColor setFill];
- [airmetTURBSpacer fill];
- /* ==================== */
- // airmet turb bkg
- /* ====================*/
- UIBezierPath *airmetTURBBkg = [UIBezierPath bezierPathWithArcCenter:center radius:airmetTURBRadius startAngle:DEGREES_TO_RADIANS(0) endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
- [graphicBackgroundColor setFill];
- [airmetTURBBkg fill];
- /* ==================== */
- // airmet turb
- /* ====================*/
- for(AirmetSegmentObject *turbObject in airmetObject.turbSegments){
- // vars
- UIColor *turbFill = [appDelegate.myGlobals getColorWithName:turbObject.color];
- NSTimeInterval metarTimeInterval = [metarObject.dateUTC timeIntervalSince1970];
- NSTimeInterval tafStartTimeInterval = [turbObject.startDateUTC timeIntervalSince1970];
- NSTimeInterval tafEndTimeInterval = [turbObject.endDateUTC timeIntervalSince1970];
- NSInteger startTimeBetweenDates = tafStartTimeInterval - metarTimeInterval;
- NSInteger endTimeBetweenDates = tafEndTimeInterval - metarTimeInterval;
- float startTime = (startTimeBetweenDates/3600) - timeOffset;
- float endTime = (endTimeBetweenDates/3600) - timeOffset;
- // check
- if(startTime < 0){
- // set
- startTime = 0;
- }
- // check
- if(endTime < 0){
- // set
- endTime = 0;
- }
- float startDegrees = DEGREES_TO_RADIANS((startTime - 6) * 15);
- float endDegrees = DEGREES_TO_RADIANS((endTime - 6) * 15);
- /*NSLog(@"this station %@", thisStation.stationId);
- NSLog(@"metar time interval %f", metarTimeInterval);
- NSLog(@"taf start interval %f", tafStartTimeInterval);
- NSLog(@"taf end interval %f", tafEndTimeInterval);
- NSLog(@"start time %0.2f", startTime);
- NSLog(@"end time %0.2f\n\n", endTime);*/
- // turb segment
- UIBezierPath *turbSegment = [UIBezierPath bezierPath];
- [turbSegment moveToPoint:center];
- [turbSegment addArcWithCenter:center radius:airmetTURBRadius startAngle:startDegrees endAngle:endDegrees clockwise:YES];
- [turbSegment addLineToPoint:center];
- [turbFill setFill];
- [turbSegment fill];
- }
- /* ==================== */
- // airmet ice spacer
- /* ====================*/
- UIBezierPath *airmetICESpacer = [UIBezierPath bezierPathWithArcCenter:center radius:(airmetICERadius + airmetICEOuterPadding) startAngle:DEGREES_TO_RADIANS(0) endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
- [graphicBackgroundColor setFill];
- [airmetICESpacer fill];
- /* ==================== */
- // airmet ice bkg
- /* ====================*/
- UIBezierPath *airmetICEBkg = [UIBezierPath bezierPathWithArcCenter:center radius:airmetICERadius startAngle:DEGREES_TO_RADIANS(0) endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
- [graphicBackgroundColor setFill];
- [airmetICEBkg fill];
- /* ==================== */
- // airmet ice
- /* ====================*/
- for(AirmetSegmentObject *iceObject in airmetObject.iceSegments){
- // vars
- UIColor *iceFill = [appDelegate.myGlobals getColorWithName:iceObject.color];
- NSTimeInterval metarTimeInterval = [metarObject.dateUTC timeIntervalSince1970];
- NSTimeInterval tafStartTimeInterval = [iceObject.startDateUTC timeIntervalSince1970];
- NSTimeInterval tafEndTimeInterval = [iceObject.endDateUTC timeIntervalSince1970];
- NSInteger startTimeBetweenDates = tafStartTimeInterval - metarTimeInterval;
- NSInteger endTimeBetweenDates = tafEndTimeInterval - metarTimeInterval;
- float startTime = (startTimeBetweenDates/3600) - timeOffset;
- float endTime = (endTimeBetweenDates/3600) - timeOffset;
- // check
- if(startTime < 0){
- // set
- startTime = 0;
- }
- // check
- if(endTime < 0){
- // set
- endTime = 0;
- }
- float startDegrees = DEGREES_TO_RADIANS((startTime - 6) * 15);
- float endDegrees = DEGREES_TO_RADIANS((endTime - 6) * 15);
- // ice segment
- UIBezierPath *iceSegment = [UIBezierPath bezierPath];
- [iceSegment moveToPoint:center];
- [iceSegment addArcWithCenter:center radius:airmetICERadius startAngle:startDegrees endAngle:endDegrees clockwise:YES];
- [iceSegment addLineToPoint:center];
- [iceFill setFill];
- [iceSegment fill];
- }
- /* ==================== */
- // airmet ifr spacer
- /* ====================*/
- UIBezierPath *airmetIFRSpacer = [UIBezierPath bezierPathWithArcCenter:center radius:(airmetIFRRadius + airmetIFROuterPadding) startAngle:DEGREES_TO_RADIANS(0) endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
- [graphicBackgroundColor setFill];
- [airmetIFRSpacer fill];
- /* ==================== */
- // airmet ifr bkg
- /* ====================*/
- UIBezierPath *airmetIFRBkg = [UIBezierPath bezierPathWithArcCenter:center radius:airmetIFRRadius startAngle:DEGREES_TO_RADIANS(0) endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
- [graphicBackgroundColor setFill];
- [airmetIFRBkg fill];
- /* ==================== */
- // airmet ifr
- /* ====================*/
- for(AirmetSegmentObject *ifrObject in airmetObject.ifrSegments){
- // vars
- UIColor *ifrFill = [appDelegate.myGlobals getColorWithName:ifrObject.color];
- NSTimeInterval metarTimeInterval = [metarObject.dateUTC timeIntervalSince1970];
- NSTimeInterval tafStartTimeInterval = [ifrObject.startDateUTC timeIntervalSince1970];
- NSTimeInterval tafEndTimeInterval = [ifrObject.endDateUTC timeIntervalSince1970];
- NSInteger startTimeBetweenDates = tafStartTimeInterval - metarTimeInterval;
- NSInteger endTimeBetweenDates = tafEndTimeInterval - metarTimeInterval;
- float startTime = (startTimeBetweenDates/3600) - timeOffset;
- float endTime = (endTimeBetweenDates/3600) - timeOffset;
- // check
- if(startTime < 0){
- // set
- startTime = 0;
- }
- // check
- if(endTime < 0){
- // set
- endTime = 0;
- }
- float startDegrees = DEGREES_TO_RADIANS((startTime - 6) * 15);
- float endDegrees = DEGREES_TO_RADIANS((endTime - 6) * 15);
- // ifr segment
- UIBezierPath *ifrSegment = [UIBezierPath bezierPath];
- [ifrSegment moveToPoint:center];
- [ifrSegment addArcWithCenter:center radius:airmetIFRRadius startAngle:startDegrees endAngle:endDegrees clockwise:YES];
- [ifrSegment addLineToPoint:center];
- [ifrFill setFill];
- [ifrSegment fill];
- }
- }
- /* ==================== */
- // airmet spacer
- /* ====================*/
- UIBezierPath *airmetSpacer = [UIBezierPath bezierPathWithArcCenter:center radius:(tafRadius + tafOuterPadding) startAngle:DEGREES_TO_RADIANS(0) endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
- [graphicBackgroundColor setFill];
- [airmetSpacer fill];
- //NSLog(@"station reporting %@", thisStation.reporting);
- // check
- if([thisStation.reporting isEqualToString:@"M"]){
- /* ==================== */
- // taf background
- /* ====================*/
- UIBezierPath *tafBkg = [UIBezierPath bezierPathWithArcCenter:center radius:tafRadius startAngle:DEGREES_TO_RADIANS(0) endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
- [[UIColor colorWithRed:70/255.0 green:70/255.0 blue:70/255.0 alpha:1] setFill];
- [tafBkg fill];
- }
- else{
- /* ==================== */
- // taf background
- /* ====================*/
- UIBezierPath *tafBkg = [UIBezierPath bezierPathWithArcCenter:center radius:tafRadius startAngle:DEGREES_TO_RADIANS(0) endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
- [[UIColor colorWithRed:210/255.0 green:210/255.0 blue:210/255.0 alpha:1] setFill];
- [tafBkg fill];
- //NSLog(@"taf segments %d", tafObject.segments.count);
- /* ==================== */
- // taf segments
- /* ====================*/
- for(TAFSegmentObject *tafSegmentObject in [tafObject segments]){
- // vars
- UIColor *tafFill = [appDelegate.myGlobals getColorWithName:tafSegmentObject.color];
- // NSUInteger thisWidth = (tafRadius * 2) - 0;
- BOOL willCreateSegment = YES;
- NSTimeInterval metarTimeInterval = [metarObject.dateUTC timeIntervalSince1970];
- NSTimeInterval tafStartTimeInterval = [tafSegmentObject.startDateUTC timeIntervalSince1970];
- NSTimeInterval tafEndTimeInterval = [tafSegmentObject.endDateUTC timeIntervalSince1970];
- NSInteger startTimeBetweenDates = tafStartTimeInterval - metarTimeInterval;
- NSInteger endTimeBetweenDates = tafEndTimeInterval - metarTimeInterval;
- float startTime = (startTimeBetweenDates/3600) - timeOffset;
- float endTime = (endTimeBetweenDates/3600) - timeOffset;
- /*NSLog(@"metar time interval %f", metarTimeInterval);
- NSLog(@"taf start interval %f", tafStartTimeInterval);
- NSLog(@"taf end interval %f", tafEndTimeInterval);
- NSLog(@"start time %0.2f", startTime);
- NSLog(@"end time %0.2f\n\n", endTime);*/
- // check
- if(startTime < 0){
- // check
- if(endTime <= 0){
- // set
- willCreateSegment = NO;
- }
- else{
- // set
- startTime = 0;
- }
- }
- // check
- if(willCreateSegment){
- // circle 2
- UIBezierPath *tafSegment = [UIBezierPath bezierPath];
- [tafSegment moveToPoint:center];
- [tafSegment addArcWithCenter:center radius:tafRadius startAngle:DEGREES_TO_RADIANS(((startTime - 6) * 15) + 1) endAngle:DEGREES_TO_RADIANS(((endTime - 6) * 15) - 1) clockwise:YES];
- [tafSegment addLineToPoint:center];
- [tafFill setFill];
- [tafSegment fill];
- // check
- if(tafSegmentObject.icons.count == 1){
- // vars
- /*NSDictionary *firstIconDict = [tafSegmentObject.icons objectAtIndex:0];
- // create view
- UIView *iconView = [[UIView alloc] initWithFrame:CGRectMake((center.x - (thisWidth/2)), (center.y - (thisWidth/2)), thisWidth, thisWidth)];
- [iconView setBackgroundColor:[UIColor clearColor]];
- [self addSubview:iconView];
- // image
- UIImage *iconImage = [UIImage imageNamed:[firstIconDict objectForKey:@"i"]];
- UIImageView *iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake((thisWidth/2) - 12, 12, 24, 24)];
- [iconImageView setImage:iconImage];
- [iconView addSubview:iconImageView];
- // halfway
- float halfwayAngle = ((endTime - startTime)/2) + startTime;
- // rotate
- iconView.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(halfwayAngle * 15));*/
- }
- else if(tafSegmentObject.icons.count == 2){
- // vars
- /*NSDictionary *firstIconDict = [tafSegmentObject.icons objectAtIndex:0];
- NSDictionary *secondIconDict = [tafSegmentObject.icons objectAtIndex:1];
- // create view
- UIView *iconViewLeft = [[UIView alloc] initWithFrame:CGRectMake((center.x - (thisWidth/2)), (center.y - (thisWidth/2)), thisWidth, thisWidth)];
- [iconViewLeft setBackgroundColor:[UIColor clearColor]];
- [self addSubview:iconViewLeft];
- // create view
- UIView *iconViewRight = [[UIView alloc] initWithFrame:CGRectMake((center.x - (thisWidth/2)), (center.y - (thisWidth/2)), thisWidth, thisWidth)];
- [iconViewRight setBackgroundColor:[UIColor clearColor]];
- [self addSubview:iconViewRight];
- // image
- UIImage *iconImageLeft = [UIImage imageNamed:[firstIconDict objectForKey:@"i"]];
- UIImageView *iconImageViewLeft = [[UIImageView alloc] initWithFrame:CGRectMake((thisWidth/2) - 12, 12, 24, 24)];
- [iconImageViewLeft setImage:iconImageLeft];
- [iconViewLeft addSubview:iconImageViewLeft];
- // image
- UIImage *iconImageRight = [UIImage imageNamed:[secondIconDict objectForKey:@"i"]];
- UIImageView *iconImageViewRight = [[UIImageView alloc] initWithFrame:CGRectMake((thisWidth/2) - 12, 12, 24, 24)];
- [iconImageViewRight setImage:iconImageRight];
- [iconViewRight addSubview:iconImageViewRight];
- // halfway
- float thirdAngle = ((endTime - startTime)/3) + startTime;
- // rotate
- iconViewLeft.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(thirdAngle * 15));
- iconViewRight.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS((thirdAngle * 2) * 15));*/
- }
- }
- }
- /* ==================== */
- // taf arrows
- /* ====================*/
- if([appDelegate.myGlobals dataLevel] > 0){
- for(TAFSegmentObject *tafSegmentObject in [tafObject segments]){
- // vars
- BOOL willCreateArrow = YES;
- NSTimeInterval metarTimeInterval = [metarObject.dateUTC timeIntervalSince1970];
- NSTimeInterval tafStartTimeInterval = [tafSegmentObject.startDateUTC timeIntervalSince1970];
- NSInteger startTimeBetweenDates = tafStartTimeInterval - metarTimeInterval;
- float startTime = (startTimeBetweenDates/3600) - timeOffset;
- NSString *displayTime = [NSString stringWithFormat:@"%0.0f", startTime];
- NSCalendar *calendar = [NSCalendar currentCalendar];
- NSDateComponents *components = [calendar components:(NSHourCalendarUnit) fromDate:tafSegmentObject.startDateUTC];
- NSInteger hour = [components hour];
- // check
- if([appDelegate.myGlobals timeOffset] == 0){
- // set
- displayTime = [NSString stringWithFormat:@"%ld", (long)hour];
- }
- else if([appDelegate.myGlobals timeOffset] == 2){
- // vars
- NSInteger localHourDifference = (timeZoneSeconds * -1) / secondsInAnHour;
- NSInteger offsetHour = hour - localHourDifference;
- // check
- if(offsetHour < 0){
- // set
- offsetHour = offsetHour * -1;
- }
- // set
- displayTime = [NSString stringWithFormat:@"%ld", (long)offsetHour];
- }
- // check
- if(startTime <= 0){
- // set
- willCreateArrow = NO;
- }
- // check
- if(willCreateArrow){
- // vars
- NSUInteger thisWidth = (tafRadius * 2) - 58;
- // create view
- UIView *arrowView = [[UIView alloc] initWithFrame:CGRectMake((center.x - (thisWidth/2)), (center.y - (thisWidth/2)), thisWidth, thisWidth)];
- [arrowView setBackgroundColor:[UIColor clearColor]];
- [self addSubview:arrowView];
- // arrow image
- UIImage *timeStartImage = [UIImage imageNamed:@"TimeArrow.png"];
- UIImageView *timeStartImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, thisWidth, thisWidth)];
- [timeStartImageView setImage:timeStartImage];
- [arrowView addSubview:timeStartImageView];
- // label
- UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake((thisWidth/2) - 14, 3, 28, 20)];
- [timeLabel setBackgroundColor:[UIColor clearColor]];
- [timeLabel setText:displayTime];
- [timeLabel setTextColor:[UIColor blackColor]];
- [timeLabel setTextAlignment:NSTextAlignmentCenter];
- [timeLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Medium" size:9]];
- [arrowView addSubview:timeLabel];
- // rotate
- arrowView.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(startTime * 15));
- timeLabel.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(-startTime * 15));
- }
- }
- }
- /* ==================== */
- // taf rect
- /* ====================*/
- UIBezierPath *tafStartRect = [UIBezierPath bezierPathWithRect:CGRectMake((center.x - 2), (center.y - tafRadius), 4, (tafRadius - tfrRadius))];
- [graphicBackgroundColor setFill];
- [tafStartRect fill];
- }
- // check
- if([appDelegate.myGlobals dataLevel] > 1){
- // check
- if(thisStation.midnightUTC){
- /* ==================== */
- // sunset sunrise
- /* ====================*/
- NSTimeInterval metarTimeInterval = [metarObject.dateUTC timeIntervalSince1970];
- NSTimeInterval midnightTimeInterval = [thisStation.midnightUTC timeIntervalSince1970];
- NSTimeInterval sunsetTimeInterval = [thisStation.sunsetUTC timeIntervalSince1970];
- NSTimeInterval sunriseTimeInterval = [thisStation.sunriseUTC timeIntervalSince1970];
- NSTimeInterval timeZoneSeconds = [[NSTimeZone localTimeZone] secondsFromGMT];
- NSInteger midnightTimeBetweenDates = midnightTimeInterval - metarTimeInterval;
- NSInteger startTimeBetweenDates = sunsetTimeInterval - metarTimeInterval;
- NSInteger endTimeBetweenDates = sunriseTimeInterval - metarTimeInterval;
- float midnightTime = (midnightTimeBetweenDates/3600) + timeZoneSeconds;
- float sunsetTime = roundf((startTimeBetweenDates - timeZoneSeconds)/3600);
- float sunriseTime = roundf((endTimeBetweenDates - timeZoneSeconds)/3600);
- UIBezierPath *sunCircle = [UIBezierPath bezierPathWithArcCenter:center radius:airmetCONVRadius startAngle:DEGREES_TO_RADIANS((sunsetTime - 6) * 15) endAngle:DEGREES_TO_RADIANS((sunriseTime - 6) * 15) clockwise:YES];
- [[UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:.25] setFill];
- [sunCircle fill];
- /* ==================== */
- // midnight rect
- /* ====================*/
- UIBezierPath *midnightBkgCircle = [UIBezierPath bezierPath];
- [midnightBkgCircle moveToPoint:center];
- [midnightBkgCircle addArcWithCenter:center radius:airmetCONVRadius startAngle:DEGREES_TO_RADIANS(((midnightTime - 6) * 15)- 2) endAngle:DEGREES_TO_RADIANS(((midnightTime - 6) * 15) + 2) clockwise:YES];
- [midnightBkgCircle addLineToPoint:center];
- [[UIColor blackColor] setFill];
- [midnightBkgCircle fill];
- UIBezierPath *midnightCircle = [UIBezierPath bezierPath];
- [midnightCircle moveToPoint:center];
- [midnightCircle addArcWithCenter:center radius:airmetCONVRadius startAngle:DEGREES_TO_RADIANS(((midnightTime - 6) * 15) - 1) endAngle:DEGREES_TO_RADIANS(((midnightTime - 6) * 15) + 1) clockwise:YES];
- [midnightCircle addLineToPoint:center];
- [[UIColor whiteColor] setFill];
- [midnightCircle fill];
- //NSLog(@"start angle %0.f", DEGREES_TO_RADIANS(((midnightTime - 6) * 15)- 2) );
- //NSLog(@"end angle %0.f", DEGREES_TO_RADIANS(((midnightTime - 6) * 15) + 2) );
- }
- }
- /* ==================== */
- // tfr background
- /* ====================*/
- UIBezierPath *tfrBkg = [UIBezierPath bezierPathWithArcCenter:center radius:tfrRadius startAngle:DEGREES_TO_RADIANS(0) endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
- [[UIColor colorWithRed:210/255.0 green:210/255.0 blue:210/255.0 alpha:1] setFill];
- [tfrBkg fill];
- /* ==================== */
- // tfr
- /* ====================*/
- // check
- if([appDelegate.myGlobals tfrOn]){
- // vars
- UIColor *tfrFill = [appDelegate.myGlobals getColorWithName:tfrObject.color];
- // circle 2
- UIBezierPath *tfrCircle = [UIBezierPath bezierPath];
- [tfrCircle moveToPoint:center];
- [tfrCircle addArcWithCenter:center radius:tfrRadius startAngle:DEGREES_TO_RADIANS(((tfrObject.timeStart - timeOffset) - 6) * 15) endAngle:DEGREES_TO_RADIANS(((tfrObject.timeEnd - timeOffset) - 6) * 15) clockwise:YES];
- [tfrCircle addLineToPoint:center];
- [tfrFill setFill];
- [tfrCircle fill];
- }
- /* ==================== */
- // metar
- /* ====================*/
- UIColor *metarFill = [appDelegate.myGlobals getColorWithName:metarObject.color];
- // circle 1
- UIBezierPath *metarCircle = [UIBezierPath bezierPathWithArcCenter:center radius:metarRadius startAngle:DEGREES_TO_RADIANS(0) endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
- [metarFill setFill];
- [metarCircle fill];
- /* ==================== */
- // time circle
- /* ==================== */
- // check
- if([appDelegate.myGlobals metarTimeOn]){
- // vars
- float endAngle = 360;
- // check
- if(minutesBetweenDates < 60){
- // set
- endAngle = (minutesBetweenDates - 15) * 6;
- }
- // vars
- UIColor *timeCircleFill = [appDelegate.myGlobals getColorWithName:@"dark green"];
- // time circle
- UIBezierPath *timeCircle = [UIBezierPath bezierPath];
- [timeCircle moveToPoint:center];
- [timeCircle addArcWithCenter:center radius:metarRadius startAngle:DEGREES_TO_RADIANS((-6 * 15)) endAngle:DEGREES_TO_RADIANS(endAngle) clockwise:YES];
- [timeCircle addLineToPoint:center];
- [timeCircleFill setFill];
- [timeCircle fill];
- // metar
- UIBezierPath *metarCover = [UIBezierPath bezierPathWithArcCenter:center radius:(metarRadius - 8) startAngle:DEGREES_TO_RADIANS(0) endAngle:DEGREES_TO_RADIANS(360) clockwise:YES];
- [metarFill setFill];
- [metarCover fill];
- }
- // check
- if([appDelegate.myGlobals dataLevel] > 0){
- // check
- if([appDelegate.myGlobals metarData] == 1){
- // wind speed label
- NSUInteger wsLabelWidth = 50;
- UILabel *windSpeedLabel = [[UILabel alloc] initWithFrame:CGRectMake((center.x - round(wsLabelWidth/2)), (center.y - round(wsLabelWidth/2)), 50, 50)];
- [windSpeedLabel setBackgroundColor:[UIColor clearColor]];
- [windSpeedLabel setText:[NSString stringWithFormat:@"%ld", (long)metarObject.windSpeed]];
- [windSpeedLabel setTextColor:[UIColor whiteColor]];
- [windSpeedLabel setTextAlignment:NSTextAlignmentCenter];
- [windSpeedLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Medium" size:24]];
- [self addSubview:windSpeedLabel];
- // check
- if([appDelegate.myGlobals windArrowOn]){
- // wind speed direction
- UIImage *windDirectionImage = [UIImage imageNamed:@"Arrow.png"];
- UIImageView *windDirectionImageView = [[UIImageView alloc] initWithFrame:CGRectMake((center.x - metarRadius), (center.y - metarRadius), metarRadius*2, metarRadius*2)];
- [windDirectionImageView setImage:windDirectionImage];
- windDirectionImageView.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(metarObject.windDirection));
- [self addSubview:windDirectionImageView];
- }
- }
- else if([appDelegate.myGlobals metarData] == 2){
- // bar label
- NSUInteger barLabelWidth = 100;
- NSUInteger barLabelHeight = 50;
- UILabel *barLabel = [[UILabel alloc] initWithFrame:CGRectMake((center.x - round(barLabelWidth/2)), (center.y - round(barLabelHeight/2)), barLabelWidth, barLabelHeight)];
- [barLabel setBackgroundColor:[UIColor clearColor]];
- [barLabel setText:[NSString stringWithFormat:@"%00.02f", metarObject.barometerPressure]];
- [barLabel setTextColor:[UIColor whiteColor]];
- [barLabel setTextAlignment:NSTextAlignmentCenter];
- [barLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Medium" size:24]];
- [self addSubview:barLabel];
- }
- else if([appDelegate.myGlobals metarData] == 3){
- // bar label
- NSUInteger tempLabelWidth = 100;
- NSUInteger tempLabelHeight = 50;
- UILabel *tempLabel = [[UILabel alloc] initWithFrame:CGRectMake((center.x - round(tempLabelWidth/2)), (center.y - round(tempLabelHeight/2)), tempLabelWidth, tempLabelHeight)];
- [tempLabel setBackgroundColor:[UIColor clearColor]];
- [tempLabel setText:[NSString stringWithFormat:@"%0.1f°", metarObject.temperature]];
- [tempLabel setTextColor:[UIColor whiteColor]];
- [tempLabel setTextAlignment:NSTextAlignmentCenter];
- [tempLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Medium" size:24]];
- [self addSubview:tempLabel];
- }
- }
- /* ==================== */
- // taf button
- /* ====================*/
- UIButton *tafButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [tafButton setFrame:CGRectMake(0, 0, tafRadius * 2, tafRadius * 2)];
- [tafButton setCenter:center];
- [tafButton setBackgroundColor:[UIColor clearColor]];
- [tafButton.layer setCornerRadius:(tafRadius)];
- //[tafButton addTarget:self action:@selector(tafTouched:) forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:tafButton];
- UITapGestureRecognizer *tafSingleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tafSingleTap:)];
- UITapGestureRecognizer *tafDoubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tafDoubleTap:)];
- [tafSingleTap setNumberOfTapsRequired:1];
- [tafDoubleTap setNumberOfTapsRequired:2];
- [tafSingleTap requireGestureRecognizerToFail:tafDoubleTap];
- [tafButton addGestureRecognizer:tafSingleTap];
- [tafButton addGestureRecognizer:tafDoubleTap];
- /* ==================== */
- // metar button
- /* ====================*/
- UIButton *metarButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [metarButton setFrame:CGRectMake(0, 0, metarRadius * 2, metarRadius * 2)];
- [metarButton setCenter:center];
- [metarButton setBackgroundColor:[UIColor clearColor]];
- [metarButton.layer setCornerRadius:(metarRadius)];
- //[metarButton addTarget:self action:@selector(metarTouched:) forControlEvents:UIControlEventTouchUpInside];
- [self addSubview:metarButton];
- UITapGestureRecognizer *metarSingleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(metarSingleTap:)];
- UITapGestureRecognizer *metarDoubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(metarDoubleTap:)];
- [metarSingleTap setNumberOfTapsRequired:1];
- [metarDoubleTap setNumberOfTapsRequired:2];
- [metarSingleTap requireGestureRecognizerToFail:metarDoubleTap];
- [metarButton addGestureRecognizer:metarSingleTap];
- [metarButton addGestureRecognizer:metarDoubleTap];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment