Skip to content

Commit

Permalink
Changed the marker to a square texture
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwulf committed Apr 12, 2018
1 parent 4c760a1 commit 3689bdc
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 3 deletions.
16 changes: 16 additions & 0 deletions JotUI/JotUI/SquareBrushTexture.h
@@ -0,0 +1,16 @@
//
// SquareBrushTexture.h
// JotUI
//
// Created by Adam Wulf on 2/29/16.
// Copyright © 2016 Milestone Made. All rights reserved.
//

#import <JotUI/JotUI.h>


@interface SquareBrushTexture : JotBrushTexture

+ (JotBrushTexture*)sharedInstance;

@end
98 changes: 98 additions & 0 deletions JotUI/JotUI/SquareBrushTexture.m
@@ -0,0 +1,98 @@
//
// SquareBrushTexture.m
// JotUI
//
// Created by Adam Wulf on 2/29/16.
// Copyright © 2016 Milestone Made. All rights reserved.
//

#import "SquareBrushTexture.h"
#import "JotSharedBrushTexture.h"
#import "UIImage+BrushTextures.h"


@implementation SquareBrushTexture

#pragma mark - PlistSaving

- (NSDictionary*)asDictionary {
return [NSDictionary dictionaryWithObject:NSStringFromClass([self class]) forKey:@"class"];
}

- (id)initFromDictionary:(NSDictionary*)dictionary {
NSString* className = [dictionary objectForKey:@"class"];
Class clz = NSClassFromString(className);
return [[clz alloc] init];
}


#pragma mark - Singleton

- (UIImage*)texture {
return [[self brushTexture] texture];
}

- (NSString*)name {
return [[self brushTexture] name];
}

- (BOOL)bind {
return [[self brushTexture] bind];
}

- (void)unbind {
JotGLContext* currContext = (JotGLContext*)[JotGLContext currentContext];
if (!currContext) {
@throw [NSException exceptionWithName:@"NilGLContextException" reason:@"Cannot bind texture to nil gl context" userInfo:nil];
}
if (![currContext isKindOfClass:[JotGLContext class]]) {
@throw [NSException exceptionWithName:@"JotGLContextException" reason:@"Current GL Context must be JotGLContext" userInfo:nil];
}
JotBrushTexture* texture = [currContext.contextProperties objectForKey:@"arrowTexture"];
if (!texture) {
@throw [NSException exceptionWithName:@"JotGLContextException" reason:@"Cannot unbind unbuilt brush texture" userInfo:nil];
}
[texture unbind];
}

#pragma mark - Singleton

static SquareBrushTexture* _instance = nil;

- (id)init {
if (_instance)
return _instance;
if ((_instance = [super init])) {
// noop
}
return _instance;
}

+ (JotBrushTexture*)sharedInstance {
if (!_instance) {
_instance = [[SquareBrushTexture alloc] init];
}
return _instance;
}


#pragma mark - Private

- (JotSharedBrushTexture*)brushTexture {
JotGLContext* currContext = (JotGLContext*)[JotGLContext currentContext];
if (!currContext) {
@throw [NSException exceptionWithName:@"NilGLContextException" reason:@"Cannot bind texture to nil gl context" userInfo:nil];
}
if (![currContext isKindOfClass:[JotGLContext class]]) {
@throw [NSException exceptionWithName:@"JotGLContextException" reason:@"Current GL Context must be JotGLContext" userInfo:nil];
}
JotSharedBrushTexture* texture = [currContext.contextProperties objectForKey:@"arrowTexture"];
if (!texture) {
UIImage* arrow = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Square" ofType:@"png"]];
texture = [[JotSharedBrushTexture alloc] initWithImage:arrow];
[currContext.contextProperties setObject:texture forKey:@"arrowTexture"];
}
return texture;
}

@end
6 changes: 6 additions & 0 deletions jotuiexample/jotuiexample.xcodeproj/project.pbxproj
Expand Up @@ -43,6 +43,7 @@
C56201D21DDE74C200FF508E /* stencil.fsh in Resources */ = {isa = PBXBuildFile; fileRef = C56201CC1DDE74C200FF508E /* stencil.fsh */; };
C56201D31DDE74C200FF508E /* point.fsh in Resources */ = {isa = PBXBuildFile; fileRef = C56201CD1DDE74C200FF508E /* point.fsh */; };
C584F8351C37C4AB00413840 /* Particle.png in Resources */ = {isa = PBXBuildFile; fileRef = C584F8341C37C4AB00413840 /* Particle.png */; };
C59C7D95207F00210030634A /* SquareBrushTexture.m in Sources */ = {isa = PBXBuildFile; fileRef = C59C7D93207F00210030634A /* SquareBrushTexture.m */; };
C5C459EA1DBF155900C50EA7 /* JotUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C5C459E91DBF155900C50EA7 /* JotUI.framework */; };
C5E0C8131E04A95900D8E301 /* ViewController~iphone.xib in Resources */ = {isa = PBXBuildFile; fileRef = C5E0C8121E04A95900D8E301 /* ViewController~iphone.xib */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -93,6 +94,8 @@
C56201CD1DDE74C200FF508E /* point.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = point.fsh; path = ../JotUI/JotUI/point.fsh; sourceTree = "<group>"; };
C584F8301C37C14C00413840 /* point.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = point.vsh; sourceTree = "<group>"; };
C584F8341C37C4AB00413840 /* Particle.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Particle.png; sourceTree = "<group>"; };
C59C7D93207F00210030634A /* SquareBrushTexture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SquareBrushTexture.m; path = ../../JotUI/JotUI/SquareBrushTexture.m; sourceTree = "<group>"; };
C59C7D94207F00210030634A /* SquareBrushTexture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SquareBrushTexture.h; path = ../../JotUI/JotUI/SquareBrushTexture.h; sourceTree = "<group>"; };
C5C459E91DBF155900C50EA7 /* JotUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JotUI.framework; path = "../../../../Library/Developer/Xcode/DerivedData/JotUI-gwtuddnpdsuqegaloczvhymgkvbq/Build/Products/Debug-iphoneos/JotUI.framework"; sourceTree = "<group>"; };
C5E0C8121E04A95900D8E301 /* ViewController~iphone.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = "ViewController~iphone.xib"; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -129,6 +132,8 @@
66910E8516803FA50046EE12 /* Pen Styles */ = {
isa = PBXGroup;
children = (
C59C7D94207F00210030634A /* SquareBrushTexture.h */,
C59C7D93207F00210030634A /* SquareBrushTexture.m */,
66910E8716803FCF0046EE12 /* Pen.h */,
66910E8816803FCF0046EE12 /* Pen.m */,
66910E92168043400046EE12 /* Marker.h */,
Expand Down Expand Up @@ -341,6 +346,7 @@
buildActionMask = 2147483647;
files = (
66F9215416734FF000B1F868 /* main.m in Sources */,
C59C7D95207F00210030634A /* SquareBrushTexture.m in Sources */,
66F9215816734FF000B1F868 /* AppDelegate.m in Sources */,
66F9216116734FF000B1F868 /* ViewController.m in Sources */,
66910E8916803FCF0046EE12 /* Pen.m in Sources */,
Expand Down
7 changes: 4 additions & 3 deletions jotuiexample/jotuiexample/Marker.m
Expand Up @@ -7,6 +7,7 @@
//

#import "Marker.h"
#import "SquareBrushTexture.h"


@implementation Marker
Expand All @@ -19,11 +20,11 @@ - (id)initWithMinSize:(CGFloat)_minSize andMaxSize:(CGFloat)_maxSize andMinAlpha
}

- (id)init {
return [self initWithMinSize:22.0 andMaxSize:30.0 andMinAlpha:.3 andMaxAlpha:.5];
return [self initWithMinSize:40.0 andMaxSize:60.0 andMinAlpha:.3 andMaxAlpha:.5];
}

- (JotBrushTexture*)texture {
return [JotDefaultBrushTexture sharedInstance];
- (JotBrushTexture*)textureForStroke {
return [SquareBrushTexture sharedInstance];
}

@end

0 comments on commit 3689bdc

Please sign in to comment.