Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extern methods to customize the visual representations's UI #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions Source-ObjectiveC/SmudgyWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,28 @@
*/
@interface SmudgyWindow : UIWindow

/**
* Customize the way the visual representations are displayed on screen
* @param newRadius Size of the visual representation
* @param newLineWidth Width of the border line of the visual representation
* @param newFillColor Color of the visual representation body
* @param newStrokeColor Color of the border line of the visual representation body
*/
- (void)updateLayerRadius:(CGFloat)newRadius
lineWidth:(CGFloat)newLineWidth
fillColor:(UIColor*)newFillColor
strokeColor:(UIColor*)newStrokeColor;

/**
* Customize the shadow of the visual representations
* @param newShadowColor Color of the visual representation's shadow
* @param newShadowRadius Spread radius of the visual representations's shadow
* @param newShadowOpacity Opacity of the visual representations's shadow
* @param newShadowOffset Offset of the visual representations's shadow
*/
- (void)updateShadowColor:(UIColor*)newShadowColor
shadowRadius:(CGFloat)newShadowRadius
shadowOpacity:(CGFloat)newShadowOpacity
shadowOffset:(CGSize)newShadowOffset;

@end
113 changes: 101 additions & 12 deletions Source-ObjectiveC/SmudgyWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@

#import "SmudgyWindow.h"

static CGFloat layerRadius;
static CGFloat layerLineWidth;
static UIColor* layerFillColor;
static UIColor* layerStrokeColor;

static UIColor* shadowColor;
static CGFloat shadowOpacity;
static CGFloat shadowRadius;
static CGSize shadowOffset;

#pragma mark - Private SmudgeLayer implementation -

@interface SmudgeLayer : CAShapeLayer
Expand Down Expand Up @@ -38,21 +48,34 @@ - (instancetype)init
self.velocity = CGPointZero;
self.contentsScale = [UIScreen mainScreen].scale;

CGFloat radius = 20.0;
self.path = CGPathCreateWithEllipseInRect(CGRectMake(-radius, -radius, radius*2, radius*2), NULL);
self.fillColor = [UIColor colorWithWhite:0.9 alpha:0.9].CGColor;
self.strokeColor = [UIColor colorWithWhite:0.0 alpha:0.35].CGColor;
self.lineWidth = 1;

self.shadowPath = self.path;
self.shadowColor = [UIColor blackColor].CGColor;
self.shadowOpacity = 0.15;
self.shadowRadius = 3.0;
self.shadowOffset = CGSizeMake(0.0, 1.0);
[self refreshLayerLooks];
[self refreshShadowLooks];
}
return self;
}

#pragma mark Customize Looks

- (void)refreshLayerLooks
{
self.fillColor = layerFillColor.CGColor;
self.strokeColor = layerStrokeColor.CGColor;
self.lineWidth = layerLineWidth;

self.path = CGPathCreateWithEllipseInRect(CGRectMake(-layerRadius, -layerRadius, layerRadius*2, layerRadius*2), NULL);
self.shadowPath = self.path;
}

- (void)refreshShadowLooks
{
self.shadowPath = self.path;
self.shadowColor = shadowColor.CGColor;
self.shadowOpacity = shadowOpacity;
self.shadowRadius = shadowRadius;
self.shadowOffset = shadowOffset;
}

#pragma mark Manage Touche
- (void)updateWithTouch:(UITouch *)touch
{
if (touch.phase != UITouchPhaseBegan) {
Expand Down Expand Up @@ -163,6 +186,24 @@ - (void)updateWithEvent:(UIEvent *)event
}
}

#pragma mark Customize Looks

- (void)refreshLayerLooks
{
for (SmudgeLayer* smudgeLayer in self.touchSmudgeTable)
{
[smudgeLayer refreshLayerLooks];
}
}

- (void)refreshShadowLooks
{
for (SmudgeLayer* smudgeLayer in self.touchSmudgeTable)
{
[smudgeLayer refreshShadowLooks];
}
}

@end


Expand All @@ -176,6 +217,19 @@ @interface SmudgyWindow ()

@implementation SmudgyWindow

+ (void)initialize
{
layerRadius = 20.0;
layerFillColor = [UIColor colorWithWhite:0.9 alpha:0.9];
layerStrokeColor = [UIColor colorWithWhite:0.0 alpha:0.35];
layerLineWidth = 1;

shadowColor = [UIColor blackColor];
shadowOpacity = 0.15;
shadowRadius = 3.0;
shadowOffset = CGSizeMake(0.0, 1.0);
}

- (void)sendEvent:(UIEvent *)event
{
[super sendEvent:event];
Expand All @@ -194,6 +248,41 @@ - (void)renderTouchesForEvent:(UIEvent *)event
[self.smudgeContainer updateWithEvent:event];
}

@end
#pragma mark Customize Looks

- (void)updateLayerRadius:(CGFloat)newRadius
lineWidth:(CGFloat)newLineWidth
fillColor:(UIColor*)newFillColor
strokeColor:(UIColor*)newStrokeColor
{
if (newRadius > 0)
layerRadius = newRadius;
if (newLineWidth >= 0)
layerLineWidth = newLineWidth;
if (newFillColor)
layerFillColor = newFillColor;
if (newStrokeColor)
layerStrokeColor = newStrokeColor;

[self.smudgeContainer refreshLayerLooks];
}

- (void)updateShadowColor:(UIColor*)newShadowColor
shadowRadius:(CGFloat)newShadowRadius
shadowOpacity:(CGFloat)newShadowOpacity
shadowOffset:(CGSize)newShadowOffset
{
if (newShadowColor)
shadowColor = newShadowColor;
if (newShadowRadius >= 0)
shadowRadius = newShadowRadius;
if (newShadowOpacity >= 0 && newShadowOpacity <= 1)
shadowOpacity = newShadowOpacity;

shadowOffset = newShadowOffset;


[self.smudgeContainer refreshShadowLooks];
}

@end