Skip to content

Commit

Permalink
Handle touch-events betetr, recompile with latest
Browse files Browse the repository at this point in the history
  • Loading branch information
hansemannn committed Dec 21, 2016
1 parent 5f3da9d commit 52c79f3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 55 deletions.
29 changes: 1 addition & 28 deletions ios/Classes/TiPaintModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,7 @@ -(void)startup
// you *must* call the superclass
[super startup];

NSLog(@"[INFO] %@ loaded",self);
}

-(void)shutdown:(id)sender
{
// this method is called when the module is being unloaded
// typically this is during shutdown. make sure you don't do too
// much processing here or the app will be quit forceably

// you *must* call the superclass
[super shutdown:sender];
}

#pragma mark Cleanup

-(void)dealloc
{
// release any resources that have been retained by the module
[super dealloc];
}

#pragma mark Internal Memory Management

-(void)didReceiveMemoryWarning:(NSNotification*)notification
{
// optionally release any resources that can be dynamically
// reloaded once memory is available - such as caches
[super didReceiveMemoryWarning:notification];
NSLog(@"[DEBUG] %@ loaded",self);
}

@end
32 changes: 13 additions & 19 deletions ios/Classes/TiPaintPaintView.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ - (void)dealloc
[wetPaintView removeFromSuperview];
RELEASE_TO_NIL(wetPaintView);
RELEASE_TO_NIL(drawImage);

[super dealloc];
}

- (void)frameSizeChanged:(CGRect)frame bounds:(CGRect)bounds
{
[super frameSizeChanged:frame bounds:bounds];
[wetPaintView setFrame:bounds];
if (drawImage != nil)
{
if (drawImage != nil) {
[drawImage setFrame:bounds];
}

Expand All @@ -56,8 +56,7 @@ - (void)frameSizeChanged:(CGRect)frame bounds:(CGRect)bounds

- (UIImageView*)imageView
{
if (drawImage == nil)
{
if (drawImage == nil) {
drawImage = [[UIImageView alloc] initWithImage:nil];
drawImage.frame = [self bounds];
[self addSubview:drawImage];
Expand All @@ -70,13 +69,7 @@ - (UIImageView*)imageView

-(void)readyToSavePaint
{
char majorVersion = [[[UIDevice currentDevice] systemVersion] characterAtIndex:0];
if (majorVersion == '2' || majorVersion == '3') {
UIGraphicsBeginImageContext(drawBox.size);
}
else {
UIGraphicsBeginImageContextWithOptions(drawBox.size, NO, 0.0);
}
UIGraphicsBeginImageContextWithOptions(drawBox.size, NO, 0.0);
CGContextRef context = UIGraphicsGetCurrentContext();
[[self imageView].image drawInRect:CGRectMake(0, 0, drawBox.size.width, drawBox.size.height)];
[wetPaintView drawInContext:context andApplyErase:YES];
Expand Down Expand Up @@ -113,7 +106,8 @@ - (void)setImage_:(id)value
{
ENSURE_UI_THREAD(setImage_, value);
RELEASE_TO_NIL(drawImage);
UIImage* image = value == nil ? nil : [TiUtils image:value proxy:self.proxy];
UIImage* image = [TiUtils image:value proxy:self.proxy] ?: nil;

if (image != nil) {
drawImage = [[UIImageView alloc] initWithImage:image];
drawImage.frame = [self bounds];
Expand All @@ -126,30 +120,30 @@ - (void)setImage_:(id)value

- (void)clear:(id)args
{
if (drawImage != nil)
{
if (drawImage != nil) {
drawImage.image = nil;
}
}

#pragma mark Event Handlers
#pragma mark Events

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[self.proxy fireEvent:@"touchend"];
[self processTouchesEnded:touches withEvent:event];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.proxy fireEvent:@"touchstart"];
[self processTouchesBegan:touches withEvent:event];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.proxy fireEvent:@"touchmove"];
[self processTouchesMoved:touches withEvent:event];
}

- (void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.proxy fireEvent:@"touchcancel"];
[self processTouchesCancelled:touches withEvent:event];
}

@end
6 changes: 2 additions & 4 deletions ios/Classes/WetPaintView.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,10 @@ - (void)drawInContext:(CGContextRef)context andApplyErase:(bool)applyErase {
CGContextSetAlpha(context, strokeAlpha);
CGContextSetBlendMode(context, kCGBlendModeNormal);
CFDictionaryApplyFunction(_touchLines, drawPoints, context);
}
else if (applyErase) {
} else if (applyErase) {
CGContextSetBlendMode(context, kCGBlendModeClear);
CFDictionaryApplyFunction(_touchLines, drawPoints, context);
}
else {
} else {
CGContextSetAlpha(context, 1); // Erasing does not respect alpha, unfortunately.
CGContextSetStrokeColorWithColor(context, [[TiUtils colorValue:@"#000"] _color].CGColor);
CFDictionaryApplyFunction(_touchLines, drawPoints, context);
Expand Down
6 changes: 3 additions & 3 deletions ios/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 1.4.1
version: 1.4.2
apiversion: 2
architectures: armv7 i386 x86_64 arm64
description: Provides a paint surface user interface view.
author: Jeff Haynie
license: Appcelerator Commercial License
copyright: Copyright (c) 2010-2014 by Appcelerator, Inc.
copyright: Copyright (c) 2010-Present by Appcelerator, Inc.


# these should not be edited
name: paint
moduleid: ti.paint
guid: 43f13063-d426-4e9c-8a7a-72dc5e4aec57
platform: iphone
minsdk: 3.4.1.GA
minsdk: 5.0.0
2 changes: 1 addition & 1 deletion ios/titanium.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// OF YOUR TITANIUM SDK YOU'RE BUILDING FOR
//
//
TITANIUM_SDK_VERSION = 3.5.0.GA
TITANIUM_SDK_VERSION = 6.0.0.GA


//
Expand Down

0 comments on commit 52c79f3

Please sign in to comment.