Created
November 27, 2011 21:58
-
-
Save Nub/1398232 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (void)drawRect:(CGRect)rect | |
| { | |
| //Some variables | |
| CGSize size = self.bounds.size; | |
| CGContextRef context = UIGraphicsGetCurrentContext(); | |
| UIGraphicsPushContext(context); | |
| CGContextClearRect(context, self.bounds); | |
| //Snap grid for sharp pixels | |
| //CGContextTranslateCTM (context, 0.5f,0.5f); | |
| //Draw screen in current context | |
| [backgroundImage drawInRect:self.bounds]; | |
| CGContextSetFillColorWithColor(context, [[UIColor blackColor] CGColor]); | |
| CGContextSetAlpha(context, 0.5f); | |
| // Finite Freq bar | |
| [finiteBar stroke]; | |
| //Detail finite bar | |
| [finiteBar applyTransform:CGAffineTransformMakeTranslation(0, kYRFiniteBarDetailTranslate - 0.5f)]; | |
| [finiteBar setLineWidth:kYRFiniteBarDetailThickness]; | |
| [finiteBar stroke]; | |
| //Move Back intoplace | |
| [finiteBar applyTransform:CGAffineTransformIdentity]; | |
| // Frequency bar | |
| [freqBar stroke]; | |
| //Detail Freq bar | |
| [freqBar applyTransform:CGAffineTransformMakeTranslation(0, kYRFreqBarDetailTranslate + 0.5f)]; | |
| [freqBar setLineWidth:kYRFreqBarDetailThickness]; | |
| [freqBar stroke]; | |
| CGFloat finiteWidth = (size.width - (kYRFiniteBarXPadding) - (kYRFramePadding)) - (kYRFramePadding + kYRFiniteBarXPadding); | |
| [largeBlock applyTransform:CGAffineTransformMakeTranslation(0,kYRFiniteBarYPadding + kYRlargeYOffset)]; | |
| for (int i = 0; i < 11; i ++) { | |
| NSString *number = [NSString stringWithFormat:@"%i", i]; | |
| CGFloat x = kYRFramePadding + kYRFiniteBarXPadding + (finiteWidth/10.f * i); | |
| x = floorf(x); | |
| CGSize numberSize = [number sizeWithFont:finiteFont]; | |
| [number drawAtPoint:CGPointMake(x - (numberSize.width * 0.35f), kYRFiniteBarYTextPadding) withFont:finiteFont]; | |
| CGContextTranslateCTM(context, (i == 9)?x-kYRlargeBlockWidth:x, 0.f); | |
| //[largeBlock applyTransform:CGAffineTransformMakeTranslation(x,0)]; | |
| [largeBlock stroke]; | |
| CGContextTranslateCTM(context, -x, 0); | |
| } | |
| [largeBlock applyTransform:CGAffineTransformMakeTranslation(0,(kYRFiniteBarYPadding + kYRlargeYOffset) * -1.f)]; | |
| NSString *x = @"106"; | |
| CGSize xs = [x sizeWithFont:[UIFont fontWithName:@"Futura-CondensedMedium" size:8.f]]; | |
| CGFloat freqWidth = (size.width - (kYRFreqBarXTextPadding * 2) - (kYRFramePadding*2.f)) - (xs.width * 0.5f); | |
| [largeBlock applyTransform:CGAffineTransformMakeTranslation(0,kYRFreqBarYPadding - kYRlargeYOffset)]; | |
| for (int i = 0; i < YRFrequenciesCount; i ++) { | |
| NSString *number = [NSString stringWithFormat:@"%i", YRFrequencies[i]]; | |
| CGSize numberSize = [number sizeWithFont:freqFont]; | |
| CGFloat x = kYRFramePadding + kYRFreqBarXTextPadding + (freqWidth * (((float)YRFrequencies[i] - YRFrequencies[0])/(float)YRFreqSpread)); | |
| x = floorf(x); | |
| [number drawAtPoint:CGPointMake((x - (numberSize.width * 0.35f)), kYRFreqBarYTextPadding) withFont:freqFont]; | |
| CGContextTranslateCTM(context, x, 0); | |
| //[largeBlock applyTransform:CGAffineTransformMakeTranslation(x,0)]; | |
| [largeBlock stroke]; | |
| CGContextTranslateCTM(context, -x, 0); | |
| } | |
| [largeBlock applyTransform:CGAffineTransformMakeTranslation(0,(kYRFreqBarYPadding - kYRlargeYOffset) * -1.f)]; | |
| CGContextSetAlpha(context, 1.f); | |
| CGContextSetFillColorWithColor(context, [[UIColor colorWithRed:0.7f green:0 blue:0 alpha:1.f] CGColor]); | |
| CGRect overlayRect = self.bounds; | |
| overlayRect.size.width -= 3.f; | |
| overlayRect.size.height -= 2.f; | |
| overlayRect.origin.x += 3.5f; | |
| overlayRect.origin.y += 1.f; | |
| [overlayImage drawInRect:overlayRect]; | |
| [finiteNeedle applyTransform:CGAffineTransformMakeTranslation(finiteNeedleX, kYRFramePadding-0.5f)]; | |
| [finiteNeedle stroke]; | |
| [finiteNeedle fill]; | |
| [finiteNeedle applyTransform:CGAffineTransformMakeTranslation(-1.f * finiteNeedleX,-1.f * kYRFramePadding-0.5f)]; | |
| [freqNeedle applyTransform:CGAffineTransformMakeTranslation(freqNeedleX,size.height - (kYRFramePadding-0.5f))]; | |
| [freqNeedle stroke]; | |
| [freqNeedle fill]; | |
| [freqNeedle applyTransform:CGAffineTransformMakeTranslation(-1.f * freqNeedleX,-1.f * size.height - (kYRFramePadding-0.5f))]; | |
| // Render a glossy gradient on top! | |
| CGGradientRef glossGradient; | |
| CGColorSpaceRef rgbColorSpace; | |
| size_t num_locations = 2; | |
| CGFloat locations[2] = { | |
| 0.25, 1.0 | |
| }; | |
| CGFloat components[8] = { | |
| 1.0, 1.0, 1.0, 0.00f, // Start color | |
| 1.0, 1.0, 1.0, 0.50f // End color | |
| }; | |
| rgbColorSpace = CGColorSpaceCreateDeviceRGB(); | |
| glossGradient = CGGradientCreateWithColorComponents(rgbColorSpace, components, locations, num_locations); | |
| CGPoint topCenter = CGPointMake(finiteNeedleX, 0.0); | |
| CGPoint topQuarterBoundary = CGPointMake(finiteNeedleX+2.f,0.0); | |
| //CGContextSetBlendMode(context, kCGBlendModeOverlay); | |
| CGContextAddPath(context, [finiteNeedle CGPath]); | |
| CGContextAddPath(context, [freqNeedle CGPath]); | |
| CGContextClip(context); | |
| CGContextDrawLinearGradient(context, glossGradient, topCenter, topQuarterBoundary, 0); | |
| CGPoint topCenter2 = CGPointMake(freqNeedleX, 0.0); | |
| CGPoint topQuarterBoundary2 = CGPointMake(freqNeedleX+2.f,0.0); | |
| CGContextDrawLinearGradient(context, glossGradient, topCenter2, topQuarterBoundary2, 0); | |
| // CGContextSetBlendMode(context, kCGBlendModeNormal); | |
| CGContextClipToRect(context, rect); | |
| CGGradientRelease(glossGradient); | |
| UIGraphicsPopContext(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment