Skip to content

Commit

Permalink
Formatted source code with spacecommander in preparation for open sou…
Browse files Browse the repository at this point in the history
…rce. Still some cleanup to do, but it's tidier anyway
  • Loading branch information
adamwulf committed Aug 25, 2016
1 parent 978ab5e commit e5704d1
Show file tree
Hide file tree
Showing 121 changed files with 2,799 additions and 2,825 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Expand Up @@ -49,7 +49,7 @@ PenaltyBreakString: 1000
PenaltyBreakFirstLessLess: 120
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Right
PointerAlignment: Left
SpacesBeforeTrailingComments: 1
Cpp11BracedListStyle: true
Standard: Auto
Expand Down
9 changes: 6 additions & 3 deletions JotUI/JotUI.h
Expand Up @@ -10,7 +10,10 @@
#define JotUI_h


#define CheckMainThread if(![NSThread isMainThread]){ NSAssert(NO, @"needs to be on main thread"); }
#define CheckMainThread \
if (![NSThread isMainThread]) { \
NSAssert(NO, @"needs to be on main thread"); \
}

#define kJotEnableCacheStats NO

Expand Down Expand Up @@ -47,8 +50,8 @@
#import <JotUI/JotHighlighterBrushTexture.h>

typedef struct {
GLfloat x;
GLfloat y;
GLfloat x;
GLfloat y;
} Vertex3D;

typedef Vertex3D Vector3D;
Expand Down
37 changes: 19 additions & 18 deletions JotUI/JotUI/AbstractBezierPathElement-Protected.h
Expand Up @@ -14,39 +14,40 @@
#import "JotGLProgram.h"
#import "JotGLContext.h"


@interface AbstractBezierPathElement ()

@property (nonatomic, assign) CGFloat stepWidth;
@property (nonatomic, strong) UIColor* color;
@property (nonatomic, assign) CGFloat width;
@property (nonatomic, assign) CGFloat rotation;
@property (nonatomic, assign) CGFloat extraLengthWithoutDot;
@property(nonatomic, assign) CGFloat stepWidth;
@property(nonatomic, strong) UIColor* color;
@property(nonatomic, assign) CGFloat width;
@property(nonatomic, assign) CGFloat rotation;
@property(nonatomic, assign) CGFloat extraLengthWithoutDot;

-(id) initWithStart:(CGPoint)point;
- (id)initWithStart:(CGPoint)point;

-(NSInteger) numberOfVerticesPerStep;
- (NSInteger)numberOfVerticesPerStep;

-(NSInteger) numberOfStepsGivenPreviousElement:(AbstractBezierPathElement *)previousElement;
- (NSInteger)numberOfStepsGivenPreviousElement:(AbstractBezierPathElement*)previousElement;

-(NSInteger) numberOfVerticesGivenPreviousElement:(AbstractBezierPathElement *)previousElement;
- (NSInteger)numberOfVerticesGivenPreviousElement:(AbstractBezierPathElement*)previousElement;

-(NSInteger) numberOfBytesGivenPreviousElement:(AbstractBezierPathElement*)previousElement;
- (NSInteger)numberOfBytesGivenPreviousElement:(AbstractBezierPathElement*)previousElement;

-(void) validateDataGivenPreviousElement:(AbstractBezierPathElement*)previousElement;
- (void)validateDataGivenPreviousElement:(AbstractBezierPathElement*)previousElement;

-(struct ColorfulVertex*) generatedVertexArrayWithPreviousElement:(AbstractBezierPathElement*)previousElement forScale:(CGFloat)scale;
- (struct ColorfulVertex*)generatedVertexArrayWithPreviousElement:(AbstractBezierPathElement*)previousElement forScale:(CGFloat)scale;

-(CGFloat) angleBetweenPoint:(CGPoint) point1 andPoint:(CGPoint)point2;
- (CGFloat)angleBetweenPoint:(CGPoint)point1 andPoint:(CGPoint)point2;

-(BOOL) bind;
- (BOOL)bind;

-(void) unbind;
- (void)unbind;

-(JotGLProgram*) glProgramForContext:(JotGLContext*)context;
- (JotGLProgram*)glProgramForContext:(JotGLContext*)context;

-(void) drawGivenPreviousElement:(AbstractBezierPathElement *)previousElement;
- (void)drawGivenPreviousElement:(AbstractBezierPathElement*)previousElement;

-(void) loadDataIntoVBOIfNeeded;
- (void)loadDataIntoVBOIfNeeded;

@end

Expand Down
53 changes: 27 additions & 26 deletions JotUI/JotUI/AbstractBezierPathElement.h
Expand Up @@ -13,15 +13,15 @@
#ifndef AbstractBezierPathElement_H
#define AbstractBezierPathElement_H

struct ColorfulVertex{
GLfloat Position[2]; // x,y position // 8
GLfloat Color [4]; // rgba color // 16
GLfloat Size; // pixel size // 4
struct ColorfulVertex {
GLfloat Position[2]; // x,y position // 8
GLfloat Color[4]; // rgba color // 16
GLfloat Size; // pixel size // 4
};

struct ColorlessVertex{
GLfloat Position[2]; // x,y position // 8
GLfloat Size; // pixel size // 4
struct ColorlessVertex {
GLfloat Position[2]; // x,y position // 8
GLfloat Size; // pixel size // 4
};

#endif
Expand All @@ -37,34 +37,35 @@ struct ColorlessVertex{
* small values will also give a smoother line, but will
* cost more in CPU
*/
#define kBrushStepSize 1
#define kBrushStepSize 1

@interface AbstractBezierPathElement : NSObject<PlistSaving>{

@interface AbstractBezierPathElement : NSObject <PlistSaving> {
CGPoint startPoint;
CGFloat width;
UIColor* color;

NSData* dataVertexBuffer;
CGFloat scaleOfVertexBuffer;
}

@property (nonatomic, readonly) CGFloat stepWidth;
@property (nonatomic, readonly) UIColor* color;
@property (nonatomic, readonly) CGFloat width;
@property (nonatomic, readonly) CGFloat rotation;
@property (nonatomic, readonly) CGPoint startPoint;
@property (nonatomic, readonly) CGPoint endPoint;
@property (nonatomic, readonly) CGRect bounds;
@property (nonatomic, strong) JotBufferManager* bufferManager;
@property (nonatomic, readonly) int fullByteSize;
@property (nonatomic, readonly) CGFloat extraLengthWithoutDot;
@property(nonatomic, readonly) CGFloat stepWidth;
@property(nonatomic, readonly) UIColor* color;
@property(nonatomic, readonly) CGFloat width;
@property(nonatomic, readonly) CGFloat rotation;
@property(nonatomic, readonly) CGPoint startPoint;
@property(nonatomic, readonly) CGPoint endPoint;
@property(nonatomic, readonly) CGRect bounds;
@property(nonatomic, strong) JotBufferManager* bufferManager;
@property(nonatomic, readonly) int fullByteSize;
@property(nonatomic, readonly) CGFloat extraLengthWithoutDot;

-(CGFloat) lengthOfElement;
-(CGFloat) angleOfStart;
-(CGFloat) angleOfEnd;
-(void) adjustStartBy:(CGPoint)adjustment;
-(UIBezierPath*) bezierPathSegment;
- (CGFloat)lengthOfElement;
- (CGFloat)angleOfStart;
- (CGFloat)angleOfEnd;
- (void)adjustStartBy:(CGPoint)adjustment;
- (UIBezierPath*)bezierPathSegment;

-(void) scaleForWidth:(CGFloat)widthRatio andHeight:(CGFloat)heightRatio NS_REQUIRES_SUPER;
- (void)scaleForWidth:(CGFloat)widthRatio andHeight:(CGFloat)heightRatio NS_REQUIRES_SUPER;

@end
81 changes: 41 additions & 40 deletions JotUI/JotUI/AbstractBezierPathElement.m
Expand Up @@ -12,7 +12,8 @@
#import "JotUI.h"
#import "JotGLColorlessPointProgram.h"

@implementation AbstractBezierPathElement{

@implementation AbstractBezierPathElement {
JotBufferManager* bufferManager;
}

Expand All @@ -24,14 +25,14 @@ @implementation AbstractBezierPathElement{
@synthesize bufferManager;
@synthesize extraLengthWithoutDot;

-(id) initWithStart:(CGPoint)point{
if(self = [super init]){
- (id)initWithStart:(CGPoint)point {
if (self = [super init]) {
startPoint = point;
}
return self;
}

-(int) fullByteSize{
- (int)fullByteSize {
@throw kAbstractMethodException;
}

Expand All @@ -41,27 +42,27 @@ -(int) fullByteSize{
* the curve, not the linear distance between start
* and end points
*/
-(CGFloat) lengthOfElement{
- (CGFloat)lengthOfElement {
@throw kAbstractMethodException;
}

-(CGFloat) angleOfStart{
- (CGFloat)angleOfStart {
@throw kAbstractMethodException;
}

-(CGFloat) angleOfEnd{
- (CGFloat)angleOfEnd {
@throw kAbstractMethodException;
}

-(CGRect) bounds{
- (CGRect)bounds {
@throw kAbstractMethodException;
}

-(CGPoint) endPoint{
- (CGPoint)endPoint {
@throw kAbstractMethodException;
}

-(void) adjustStartBy:(CGPoint)adjustment{
- (void)adjustStartBy:(CGPoint)adjustment {
@throw kAbstractMethodException;
}

Expand All @@ -70,20 +71,20 @@ -(void) adjustStartBy:(CGPoint)adjustment{
* step. this should be a multiple of 3,
* since rendering is using GL_TRIANGLES
*/
-(NSInteger) numberOfVerticesPerStep{
- (NSInteger)numberOfVerticesPerStep {
return 1;
}

/**
* the ideal number of steps we should take along
* this line to render it with vertex points
*/
-(NSInteger) numberOfStepsGivenPreviousElement:(AbstractBezierPathElement *)previousElement{
- (NSInteger)numberOfStepsGivenPreviousElement:(AbstractBezierPathElement*)previousElement {
NSInteger ret = MAX(floorf(([self lengthOfElement] + previousElement.extraLengthWithoutDot) / kBrushStepSize), 0);
// if we are beginning the stroke, then we have 1 more
// dot to begin the stroke. otherwise we skip the first dot
// and pick up after kBrushStepSize
if([previousElement isKindOfClass:[MoveToPathElement class]]){
if ([previousElement isKindOfClass:[MoveToPathElement class]]) {
ret += 1;
}
return ret;
Expand All @@ -92,15 +93,15 @@ -(NSInteger) numberOfStepsGivenPreviousElement:(AbstractBezierPathElement *)prev
/**
* returns the total number of vertices for this element
*/
-(NSInteger) numberOfVerticesGivenPreviousElement:(AbstractBezierPathElement *)previousElement{
- (NSInteger)numberOfVerticesGivenPreviousElement:(AbstractBezierPathElement*)previousElement {
return [self numberOfStepsGivenPreviousElement:previousElement] * [self numberOfVerticesPerStep];
}

-(NSInteger) numberOfBytesGivenPreviousElement:(AbstractBezierPathElement *)previousElement{
- (NSInteger)numberOfBytesGivenPreviousElement:(AbstractBezierPathElement*)previousElement {
@throw kAbstractMethodException;
}

-(void) validateDataGivenPreviousElement:(AbstractBezierPathElement*)previousElement{
- (void)validateDataGivenPreviousElement:(AbstractBezierPathElement*)previousElement {
@throw kAbstractMethodException;
}

Expand All @@ -113,44 +114,44 @@ -(void) validateDataGivenPreviousElement:(AbstractBezierPathElement*)previousEle
* the generated vertex array should be stored in
* vertexBuffer ivar
*/
-(struct ColorfulVertex*) generatedVertexArrayWithPreviousElement:(AbstractBezierPathElement*)previousElement forScale:(CGFloat)scale{
- (struct ColorfulVertex*)generatedVertexArrayWithPreviousElement:(AbstractBezierPathElement*)previousElement forScale:(CGFloat)scale {
@throw kAbstractMethodException;
}

-(UIBezierPath*) bezierPathSegment{
- (UIBezierPath*)bezierPathSegment {
@throw kAbstractMethodException;
}


-(CGFloat) angleBetweenPoint:(CGPoint) point1 andPoint:(CGPoint)point2 {
- (CGFloat)angleBetweenPoint:(CGPoint)point1 andPoint:(CGPoint)point2 {
// Provides a directional bearing from point2 to the given point.
// standard cartesian plain coords: Y goes up, X goes right
// result returns radians, -180 to 180 ish: 0 degrees = up, -90 = left, 90 = right
return atan2f(point1.y - point2.y, point1.x - point2.x) + M_PI_2;
}

-(void) loadDataIntoVBOIfNeeded{
// noop
- (void)loadDataIntoVBOIfNeeded {
// noop
}

-(BOOL) bind{
- (BOOL)bind {
return NO;
}

-(void) unbind{
- (void)unbind {
@throw kAbstractMethodException;
}

-(JotGLProgram*) glProgramForContext:(JotGLContext*)context{
- (JotGLProgram*)glProgramForContext:(JotGLContext*)context {
return [context colorlessPointProgram];
}

-(void) drawGivenPreviousElement:(AbstractBezierPathElement *)previousElement{
if([self bind]){
- (void)drawGivenPreviousElement:(AbstractBezierPathElement*)previousElement {
if ([self bind]) {
// VBO
[JotGLContext runBlock:^(JotGLContext* context){
if([self numberOfStepsGivenPreviousElement:previousElement]){
[context drawPointCount:(int) ([self numberOfStepsGivenPreviousElement:previousElement] * [self numberOfVerticesPerStep])
[JotGLContext runBlock:^(JotGLContext* context) {
if ([self numberOfStepsGivenPreviousElement:previousElement]) {
[context drawPointCount:(int)([self numberOfStepsGivenPreviousElement:previousElement] * [self numberOfVerticesPerStep])
withProgram:[self glProgramForContext:context]];
}
}];
Expand All @@ -161,19 +162,19 @@ -(void) drawGivenPreviousElement:(AbstractBezierPathElement *)previousElement{

#pragma mark - PlistSaving

-(NSDictionary*) asDictionary{
- (NSDictionary*)asDictionary {
return [NSDictionary dictionaryWithObjectsAndKeys:NSStringFromClass([self class]), @"class",
[NSNumber numberWithFloat:startPoint.x], @"startPoint.x",
[NSNumber numberWithFloat:startPoint.y], @"startPoint.y",
[NSNumber numberWithFloat:rotation], @"rotation",
[NSNumber numberWithFloat:width], @"width",
[NSNumber numberWithFloat:stepWidth], @"stepWidth",
[NSNumber numberWithFloat:extraLengthWithoutDot], @"extraLengthWithoutDot",
(color ? [color asDictionary] : [NSDictionary dictionary]), @"color",
[NSNumber numberWithFloat:scaleOfVertexBuffer], @"scaleOfVertexBuffer", nil];
[NSNumber numberWithFloat:startPoint.x], @"startPoint.x",
[NSNumber numberWithFloat:startPoint.y], @"startPoint.y",
[NSNumber numberWithFloat:rotation], @"rotation",
[NSNumber numberWithFloat:width], @"width",
[NSNumber numberWithFloat:stepWidth], @"stepWidth",
[NSNumber numberWithFloat:extraLengthWithoutDot], @"extraLengthWithoutDot",
(color ? [color asDictionary] : [NSDictionary dictionary]), @"color",
[NSNumber numberWithFloat:scaleOfVertexBuffer], @"scaleOfVertexBuffer", nil];
}

-(id) initFromDictionary:(NSDictionary*)dictionary{
- (id)initFromDictionary:(NSDictionary*)dictionary {
self = [super init];
if (self) {
startPoint = CGPointMake([[dictionary objectForKey:@"startPoint.x"] floatValue], [[dictionary objectForKey:@"startPoint.y"] floatValue]);
Expand All @@ -189,7 +190,7 @@ -(id) initFromDictionary:(NSDictionary*)dictionary{

#pragma mark - Scaling

-(void) scaleForWidth:(CGFloat)widthRatio andHeight:(CGFloat)heightRatio{
- (void)scaleForWidth:(CGFloat)widthRatio andHeight:(CGFloat)heightRatio {
startPoint.x = startPoint.x * widthRatio;
startPoint.y = startPoint.y * heightRatio;
}
Expand Down
7 changes: 4 additions & 3 deletions JotUI/JotUI/AbstractJotGLFrameBuffer.h
Expand Up @@ -9,14 +9,15 @@
#import <Foundation/Foundation.h>
#import "JotGLContext.h"

@interface AbstractJotGLFrameBuffer : NSObject{

@interface AbstractJotGLFrameBuffer : NSObject {
GLuint framebufferID;
}

//@property (readonly) GLuint framebufferID;

-(void) bind;
- (void)bind;

-(void) unbind;
- (void)unbind;

@end

0 comments on commit e5704d1

Please sign in to comment.