project_files/HedgewarsMobile/Classes/MNEValueTrackingSlider.m
author alfadur
Sun, 02 Jun 2019 23:58:12 +0300
changeset 15102 80ff12edf5e6
parent 13166 ba5c794adae3
permissions -rwxr-xr-x
handle response from IO result handler
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6679
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
     1
//
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
     2
// MNEValueTrackingSlider
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
     3
//
6700
e04da46ee43c the most important commit of the year
koda
parents: 6679
diff changeset
     4
// Copyright 2012 Michael Neuwert
6679
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
     5
// "You can use the code in your own project and modify it as you like."
6700
e04da46ee43c the most important commit of the year
koda
parents: 6679
diff changeset
     6
// http://blog.neuwert-media.com/2012/04/customized-uislider-with-visual-value-tracking/
6679
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
     7
//
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
     8
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
     9
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    10
#import "MNEValueTrackingSlider.h"
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    11
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    12
#pragma mark -
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    13
#pragma mark Private UIView subclass rendering the popup showing slider value
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    14
@interface SliderValuePopupView : UIView
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
    15
@property (nonatomic, strong) UIFont *font;
6679
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    16
@property (nonatomic, copy) NSString *text;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    17
@property (nonatomic) float arrowOffset;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    18
@end
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    19
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    20
@implementation SliderValuePopupView
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    21
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    22
@synthesize font = _font;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    23
@synthesize text = _text;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    24
@synthesize arrowOffset = _arrowOffset;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    25
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
    26
- (id)initWithFrame:(CGRect)frame {
6679
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    27
    self = [super initWithFrame:frame];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    28
    if (self) {
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    29
        self.font = [UIFont boldSystemFontOfSize:18];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    30
    }
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    31
    return self;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    32
}
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    33
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    34
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
    35
- (void)drawRect:(CGRect)rect {
6679
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    36
    // Create the path for the rounded rectangle
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    37
    CGRect roundedRect = CGRectMake(self.bounds.origin.x, self.bounds.origin.y, self.bounds.size.width, floorf(self.bounds.size.height * 0.8));
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    38
    UIBezierPath *roundedRectPath = [UIBezierPath bezierPathWithRoundedRect:roundedRect cornerRadius:6.0];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    39
    roundedRectPath.lineWidth = 2.0f;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    40
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    41
    // Create the arrow path
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    42
    UIBezierPath *arrowPath = [UIBezierPath bezierPath];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    43
    /*
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    44
    // Make sure the arrow offset is nice
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    45
    if (-self.arrowOffset + 1 > CGRectGetMidX(self.bounds) / 2)
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    46
        self.arrowOffset = -CGRectGetMidX(self.bounds) / 2 + 1;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    47
    if (self.arrowOffset > CGRectGetMidX(self.bounds) / 2)
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    48
        self.arrowOffset = CGRectGetMidX(self.bounds) / 2 -1;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    49
     */
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    50
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    51
    CGFloat midX = CGRectGetMidX(self.bounds) + self.arrowOffset;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    52
    CGPoint p0 = CGPointMake(midX, CGRectGetMaxY(self.bounds));
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    53
    [arrowPath moveToPoint:p0];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    54
    [arrowPath addLineToPoint:CGPointMake((midX - 10.0), CGRectGetMaxY(roundedRect))];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    55
    [arrowPath addLineToPoint:CGPointMake((midX + 10.0), CGRectGetMaxY(roundedRect))];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    56
    [arrowPath closePath];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    57
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    58
    // Attach the arrow path to the rounded rect
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    59
    [roundedRectPath appendPath:arrowPath];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    60
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    61
    // Color various sections
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    62
    [[UIColor blackColor] setFill];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    63
    [roundedRectPath fill];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    64
    [[UIColor whiteColor] setStroke];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    65
    [roundedRectPath stroke];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    66
    [[UIColor whiteColor] setFill];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    67
    [arrowPath fill];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    68
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    69
    // Draw the text
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    70
    if (self.text) {
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    71
        [[UIColor lightYellowColor] set];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    72
        CGSize s = [_text sizeWithFont:self.font];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    73
        CGFloat yOffset = (roundedRect.size.height - s.height) / 2;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    74
        CGRect textRect = CGRectMake(roundedRect.origin.x, yOffset, roundedRect.size.width, s.height);
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    75
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    76
        [_text drawInRect:textRect
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    77
                 withFont:self.font
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    78
            lineBreakMode:UILineBreakModeWordWrap
11549
893722a2a1f9 - Some warnings fixed with text alignment on iOS front-end
antonc27 <antonc27@mail.ru>
parents: 6908
diff changeset
    79
                alignment:NSTextAlignmentCenter];
6679
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    80
    }
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    81
}
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    82
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    83
@end
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    84
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    85
#pragma mark -
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    86
#pragma mark MNEValueTrackingSlider implementations
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    87
@implementation MNEValueTrackingSlider
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    88
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    89
@synthesize thumbRect, textValue;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    90
6908
896ed2afcfb8 ios: turn on more warning messages and start correcting them
koda
parents: 6700
diff changeset
    91
#pragma mark Private methods
6679
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    92
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
    93
- (void)_constructSlider {
6679
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    94
    valuePopupView = [[SliderValuePopupView alloc] initWithFrame:CGRectZero];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    95
    valuePopupView.backgroundColor = [UIColor clearColor];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    96
    valuePopupView.alpha = 0.0;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    97
    [self addSubview:valuePopupView];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    98
}
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
    99
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
   100
- (void)_fadePopupViewInAndOut:(BOOL)aFadeIn {
6679
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   101
    [UIView beginAnimations:nil context:NULL];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   102
    [UIView setAnimationDuration:0.25];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   103
    if (aFadeIn) {
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   104
        valuePopupView.alpha = 1.0;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   105
    } else {
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   106
        valuePopupView.alpha = 0.0;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   107
    }
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   108
    [UIView commitAnimations];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   109
}
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   110
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
   111
- (void)_positionAndUpdatePopupView {
6679
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   112
    CGRect _thumbRect = self.thumbRect;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   113
    CGRect popupRect = CGRectOffset(_thumbRect, 0, -floorf(_thumbRect.size.height * 1.5));
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   114
    // (-100, -15) determines the size of the the rect
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   115
    popupRect = CGRectInset(popupRect, -100, -15);
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   116
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   117
    // this prevents drawing the popup outside the slider view
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   118
    if (popupRect.origin.x < -self.frame.origin.x+5)
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   119
        popupRect.origin.x = -self.frame.origin.x+5;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   120
    else if (popupRect.origin.x > self.superview.frame.size.width - popupRect.size.width - self.frame.origin.x - 5)
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   121
        popupRect.origin.x = self.superview.frame.size.width - popupRect.size.width - self.frame.origin.x - 5;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   122
    //else if (CGRectGetMaxX(popupRect) > CGRectGetMaxX(self.superview.bounds))
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   123
    //    popupRect.origin.x = CGRectGetMaxX(self.superview.bounds) - CGRectGetWidth(popupRect) - 1.0;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   124
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   125
    valuePopupView.arrowOffset = CGRectGetMidX(_thumbRect) - CGRectGetMidX(popupRect);
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   126
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   127
    valuePopupView.frame = popupRect;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   128
    valuePopupView.text = self.textValue;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   129
    [valuePopupView setNeedsDisplay];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   130
}
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   131
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   132
#pragma mark Memory management
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   133
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
   134
- (id)initWithFrame:(CGRect)frame {
6679
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   135
    self = [super initWithFrame:frame];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   136
    if (self) {
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   137
        [self _constructSlider];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   138
    }
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   139
    return self;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   140
}
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   141
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
   142
- (id)initWithCoder:(NSCoder *)aDecoder {
6679
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   143
    self = [super initWithCoder:aDecoder];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   144
    if (self) {
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   145
        [self _constructSlider];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   146
    }
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   147
    return self;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   148
}
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   149
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   150
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   151
#pragma mark -
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   152
#pragma mark UIControl touch event tracking
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
   153
- (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
6679
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   154
    // Fade in and update the popup view
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   155
    CGPoint touchPoint = [touch locationInView:self];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   156
    // Check if the knob is touched. Only in this case show the popup-view
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   157
    if(CGRectContainsPoint(CGRectInset(self.thumbRect, -14.0, -12.0), touchPoint)) {
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   158
        [self _positionAndUpdatePopupView];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   159
        [self _fadePopupViewInAndOut:YES];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   160
    }
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   161
    return [super beginTrackingWithTouch:touch withEvent:event];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   162
}
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   163
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
   164
- (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
6679
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   165
    // Update the popup view as slider knob is being moved
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   166
    [self _positionAndUpdatePopupView];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   167
    return [super continueTrackingWithTouch:touch withEvent:event];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   168
}
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   169
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
   170
- (void)cancelTrackingWithEvent:(UIEvent *)event {
6679
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   171
    [super cancelTrackingWithEvent:event];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   172
}
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   173
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11549
diff changeset
   174
- (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event {
6679
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   175
    // Fade out the popoup view
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   176
    [self _fadePopupViewInAndOut:NO];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   177
    [super endTrackingWithTouch:touch withEvent:event];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   178
}
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   179
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   180
#pragma mark -
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   181
#pragma mark Custom property accessors
13166
ba5c794adae3 - Some not-so-important pretty formatting
antonc27 <antonc27@mail.ru>
parents: 12872
diff changeset
   182
- (CGRect)thumbRect {
6679
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   183
    CGRect trackRect = [self trackRectForBounds:self.bounds];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   184
    CGRect thumbR = [self thumbRectForBounds:self.bounds
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   185
                                         trackRect:trackRect
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   186
                                             value:self.value];
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   187
    return thumbR;
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   188
}
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   189
d8b98aa486a6 tweaks to the value tracking slider (doesn't draw outside the superview bounds) and assign proper copyright notice to it
koda
parents:
diff changeset
   190
@end