Skip to content

Commit

Permalink
Added comments and thumbTintColor property
Browse files Browse the repository at this point in the history
  • Loading branch information
Zedenem committed Mar 12, 2012
1 parent 2bd46b2 commit 5f45a0a
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 43 deletions.
24 changes: 20 additions & 4 deletions UICircularSlider/UICircularSlider.h
Expand Up @@ -3,10 +3,10 @@
/// UICircularSlider
//
// Created by Zouhair Mahieddine on 02/03/12.
/// Copyright (c) 2012 Zouhair Mahieddine.
// Copyright (c) 2012 Zouhair Mahieddine.
// http://www.zedenem.com
//
// This file is part of the UICircularProgressView Library.
// This file is part of the UICircularSlider Library.
//
// UICircularProgressView is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand All @@ -19,7 +19,7 @@
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with UICircularProgressView. If not, see <http://www.gnu.org/licenses/>.
// along with UICircularSlider. If not, see <http://www.gnu.org/licenses/>.
//

#import <UIKit/UIKit.h>
Expand Down Expand Up @@ -71,12 +71,19 @@ typedef enum {
*/
@property(nonatomic, retain) UIColor *maximumTrackTintColor;

/**
* The color used to tint the standard thumb.
*/
@property(nonatomic, retain) UIColor *thumbTintColor;

/**
* Contains a Boolean value indicating whether changes in the sliders value generate continuous update events.
*
* If YES, the slider sends update events continuously to the associated target’s action method.
* If NO, the slider only sends an action event when the user releases the slider’s thumb control to set the final value.
* The default value of this property is YES.
*
* @warning Not implemented Yet.
*/
@property(nonatomic, getter=isContinuous) BOOL continuous;

Expand Down Expand Up @@ -108,4 +115,13 @@ typedef enum {
* b = dMax - a*sMax = dMin - a*sMin
*/
float translateValueFromSourceIntervalToDestinationInterval(float sourceValue, float sourceIntervalMinimum, float sourceIntervalMaximum, float destinationIntervalMinimum, float destinationIntervalMaximum);
CGFloat clockwiseAngleBetweenThreePoints(CGPoint centerPoint, CGPoint p1, CGPoint p2);
/**
* Returns the smallest angle between three points, one of them clearly indicated as the "junction point" or "center point".
* @param centerPoint The "center point" or "junction point"
* @param p1 The first point, member of the [centerPoint p1] segment
* @param p2 The second point, member of the [centerPoint p2] segment
* @return The angle between those two segments
* This function uses the properties of the triangle and arctan (atan2f) function to calculate the angle.
*/
CGFloat angleBetweenThreePoints(CGPoint centerPoint, CGPoint p1, CGPoint p2);
40 changes: 24 additions & 16 deletions UICircularSlider/UICircularSlider.m
Expand Up @@ -6,7 +6,7 @@
// Copyright (c) 2012 Zouhair Mahieddine.
// http://www.zedenem.com
//
// This file is part of the UICircularProgressView Library.
// This file is part of the UICircularSlider Library.
//
// UICircularProgressView is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand All @@ -19,7 +19,7 @@
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with UICircularProgressView. If not, see <http://www.gnu.org/licenses/>.
// along with UICircularSlider. If not, see <http://www.gnu.org/licenses/>.
//

#import "UICircularSlider.h"
Expand Down Expand Up @@ -88,6 +88,14 @@ - (void)setMaximumTrackTintColor:(UIColor *)maximumTrackTintColor {
}
}

@synthesize thumbTintColor = _thumbTintColor;
- (void)setThumbTintColor:(UIColor *)thumbTintColor {
if (![thumbTintColor isEqual:_thumbTintColor]) {
_thumbTintColor = thumbTintColor;
[self setNeedsDisplay];
}
}

@synthesize continuous = _continuous;

@synthesize sliderStyle = _sliderStyle;
Expand Down Expand Up @@ -119,6 +127,7 @@ - (void)setup {
self.maximumValue = 1.0;
self.minimumTrackTintColor = [UIColor blueColor];
self.maximumTrackTintColor = [UIColor whiteColor];
self.thumbTintColor = [UIColor darkGrayColor];
self.continuous = YES;
self.thumbCenterPoint = CGPointZero;

Expand All @@ -133,20 +142,20 @@ - (void)setup {
/** @name Drawing methods */
#pragma mark - Drawing methods
#define kLineWidth 5.0
#define kThumbRadius 12.0
- (CGFloat)sliderRadius {
CGFloat radius = MIN(self.bounds.size.width/2, self.bounds.size.height/2);
radius -= kLineWidth*2;
radius -= MAX(kLineWidth, kThumbRadius);
return radius;
}
#define kThumbRadius 10.0
- (void)drawThumbAtPoint:(CGPoint)sliderButtonCenterPoint inContext:(CGContextRef)context {
UIGraphicsPushContext(context);
CGContextBeginPath(context);

CGContextMoveToPoint(context, sliderButtonCenterPoint.x, sliderButtonCenterPoint.y);
CGContextAddArc(context, sliderButtonCenterPoint.x, sliderButtonCenterPoint.y, kThumbRadius, 0.0, 2*M_PI, NO);

CGContextFillPath(context);
CGContextStrokePath(context);
UIGraphicsPopContext();
}

Expand Down Expand Up @@ -215,8 +224,7 @@ - (void)drawRect:(CGRect)rect {
break;
}

[self.minimumTrackTintColor setFill];
[self.minimumTrackTintColor setStroke];
[self.thumbTintColor setFill];
[self drawThumbAtPoint:self.thumbCenterPoint inContext:context];
}

Expand All @@ -236,7 +244,14 @@ - (void)panGestureHappened:(UIPanGestureRecognizer *)panGestureRecognizer {
CGFloat radius = [self sliderRadius];
CGPoint sliderCenter = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2);
CGPoint sliderStartPoint = CGPointMake(sliderCenter.x, sliderCenter.y - radius);
CGFloat angle = clockwiseAngleBetweenThreePoints(sliderCenter, sliderStartPoint, tapLocation);
CGFloat angle = angleBetweenThreePoints(sliderCenter, sliderStartPoint, tapLocation);

if (angle < 0) {
angle = -angle;
}
else {
angle = 2*M_PI - angle;
}

self.value = translateValueFromSourceIntervalToDestinationInterval(angle, 0, 2*M_PI, self.minimumValue, self.maximumValue);
break;
Expand Down Expand Up @@ -270,18 +285,11 @@ float translateValueFromSourceIntervalToDestinationInterval(float sourceValue, f
return destinationValue;
}

CGFloat clockwiseAngleBetweenThreePoints(CGPoint centerPoint, CGPoint p1, CGPoint p2) {
CGFloat angleBetweenThreePoints(CGPoint centerPoint, CGPoint p1, CGPoint p2) {
CGPoint v1 = CGPointMake(p1.x - centerPoint.x, p1.y - centerPoint.y);
CGPoint v2 = CGPointMake(p2.x - centerPoint.x, p2.y - centerPoint.y);

CGFloat angle = atan2f(v2.x*v1.y - v1.x*v2.y, v1.x*v2.x + v1.y*v2.y);

if (angle < 0) {
angle = -angle;
}
else {
angle = 2*M_PI - angle;
}

return angle;
}
4 changes: 4 additions & 0 deletions test_project/UICircularSlider.xcodeproj/project.pbxproj
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
5F7A1DA4150E3C4E00284473 /* circularSliderThumbImage.png in Resources */ = {isa = PBXBuildFile; fileRef = 5F7A1DA3150E3C4E00284473 /* circularSliderThumbImage.png */; };
5FF75D1D1500E8B200CFC305 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5FF75D1C1500E8B200CFC305 /* UIKit.framework */; };
5FF75D1F1500E8B200CFC305 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5FF75D1E1500E8B200CFC305 /* Foundation.framework */; };
5FF75D211500E8B200CFC305 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5FF75D201500E8B200CFC305 /* CoreGraphics.framework */; };
Expand All @@ -18,6 +19,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
5F7A1DA3150E3C4E00284473 /* circularSliderThumbImage.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = circularSliderThumbImage.png; sourceTree = "<group>"; };
5FF75D181500E8B200CFC305 /* UICircularSlider.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = UICircularSlider.app; sourceTree = BUILT_PRODUCTS_DIR; };
5FF75D1C1500E8B200CFC305 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
5FF75D1E1500E8B200CFC305 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -79,6 +81,7 @@
5FF75D221500E8B200CFC305 /* test_project */ = {
isa = PBXGroup;
children = (
5F7A1DA3150E3C4E00284473 /* circularSliderThumbImage.png */,
5FF75D2B1500E8B200CFC305 /* UICircularSliderAppDelegate.h */,
5FF75D2C1500E8B200CFC305 /* UICircularSliderAppDelegate.m */,
5FF75D2E1500E8B200CFC305 /* UICircularSliderViewController.h */,
Expand Down Expand Up @@ -163,6 +166,7 @@
buildActionMask = 2147483647;
files = (
5FF75D421500E8F100CFC305 /* UICircularSliderViewController.xib in Resources */,
5F7A1DA4150E3C4E00284473 /* circularSliderThumbImage.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
18 changes: 17 additions & 1 deletion test_project/UICircularSlider/UICircularSliderAppDelegate.h
Expand Up @@ -3,7 +3,23 @@
// UICircularSlider
//
// Created by Zouhair Mahieddine on 02/03/12.
// Copyright (c) 2012 Zouhair Mahieddine. All rights reserved.
// Copyright (c) 2012 Zouhair Mahieddine.
// http://www.zedenem.com
//
// This file is part of the UICircularSlider Library.
//
// UICircularProgressView is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// UICircularProgressView is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with UICircularSlider. If not, see <http://www.gnu.org/licenses/>.
//

#import <UIKit/UIKit.h>
Expand Down
18 changes: 17 additions & 1 deletion test_project/UICircularSlider/UICircularSliderAppDelegate.m
Expand Up @@ -3,7 +3,23 @@
// UICircularSlider
//
// Created by Zouhair Mahieddine on 02/03/12.
// Copyright (c) 2012 Zouhair Mahieddine. All rights reserved.
// Copyright (c) 2012 Zouhair Mahieddine.
// http://www.zedenem.com
//
// This file is part of the UICircularSlider Library.
//
// UICircularProgressView is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// UICircularProgressView is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with UICircularSlider. If not, see <http://www.gnu.org/licenses/>.
//

#import "UICircularSliderAppDelegate.h"
Expand Down
18 changes: 17 additions & 1 deletion test_project/UICircularSlider/UICircularSliderViewController.h
Expand Up @@ -3,7 +3,23 @@
// UICircularSlider
//
// Created by Zouhair Mahieddine on 02/03/12.
// Copyright (c) 2012 Zouhair Mahieddine. All rights reserved.
// Copyright (c) 2012 Zouhair Mahieddine.
// http://www.zedenem.com
//
// This file is part of the UICircularSlider Library.
//
// UICircularProgressView is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// UICircularProgressView is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with UICircularSlider. If not, see <http://www.gnu.org/licenses/>.
//

#import <UIKit/UIKit.h>
Expand Down
18 changes: 17 additions & 1 deletion test_project/UICircularSlider/UICircularSliderViewController.m
Expand Up @@ -3,7 +3,23 @@
// UICircularSlider
//
// Created by Zouhair Mahieddine on 02/03/12.
// Copyright (c) 2012 Zouhair Mahieddine. All rights reserved.
// Copyright (c) 2012 Zouhair Mahieddine.
// http://www.zedenem.com
//
// This file is part of the UICircularSlider Library.
//
// UICircularProgressView is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// UICircularProgressView is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with UICircularSlider. If not, see <http://www.gnu.org/licenses/>.
//

#import "UICircularSliderViewController.h"
Expand Down
29 changes: 10 additions & 19 deletions test_project/UICircularSlider/UICircularSliderViewController.xib
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
<data>
<int key="IBDocument.SystemTarget">1280</int>
<int key="IBDocument.SystemTarget">1296</int>
<string key="IBDocument.SystemVersion">11D50</string>
<string key="IBDocument.InterfaceBuilderVersion">2177</string>
<string key="IBDocument.InterfaceBuilderVersion">2182</string>
<string key="IBDocument.AppKitVersion">1138.32</string>
<string key="IBDocument.HIToolboxVersion">568.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<string key="NS.object.0">1173</string>
<string key="NS.object.0">1179</string>
</object>
<array key="IBDocument.IntegratedClassDependencies">
<string>IBUISlider</string>
Expand Down Expand Up @@ -48,21 +48,9 @@
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<int key="IBUIContentHorizontalAlignment">0</int>
<int key="IBUIContentVerticalAlignment">0</int>
<float key="IBUIValue">10</float>
<float key="IBUIValue">12</float>
<float key="IBUIMinValue">10</float>
<float key="IBUIMaxValue">25</float>
<object class="NSColor" key="IBUIMinimumTrackTintColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MCAxIDAAA</bytes>
</object>
<object class="NSColor" key="IBUIMaximumTrackTintColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MC4yOTgwMzkyMjc3IDAuMjk4MDM5MjI3NyAwLjI5ODAzOTIyNzcAA</bytes>
</object>
<object class="NSColor" key="IBUIThumbTintColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MSAwIDAAA</bytes>
</object>
</object>
<object class="IBUIProgressView" id="980353563">
<reference key="NSNextResponder" ref="774585933"/>
Expand All @@ -82,7 +70,6 @@
<string key="NSFrame">{{60, 240}, {200, 200}}</string>
<reference key="NSSuperview" ref="774585933"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<bool key="IBUIOpaque">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
Expand Down Expand Up @@ -215,7 +202,7 @@
<array class="NSMutableArray" key="referencedPartialClassDescriptions">
<object class="IBPartialClassDescription">
<string key="className">UICircularSlider</string>
<string key="superclassName">UIView</string>
<string key="superclassName">UIControl</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">./Classes/UICircularSlider.h</string>
Expand Down Expand Up @@ -252,8 +239,12 @@
</object>
<int key="IBDocument.localizationMode">0</int>
<string key="IBDocument.TargetRuntimeIdentifier">IBCocoaTouchFramework</string>
<object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDependencyDefaults">
<string key="NS.key.0">com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS</string>
<real value="1296" key="NS.object.0"/>
</object>
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
<string key="IBCocoaTouchPluginVersion">1173</string>
<string key="IBCocoaTouchPluginVersion">1179</string>
</data>
</archive>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5f45a0a

Please sign in to comment.