Skip to content

Commit

Permalink
Fixes all around.
Browse files Browse the repository at this point in the history
  • Loading branch information
ccgus committed Jul 23, 2012
1 parent 69c71b5 commit fa7f876
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 91 deletions.
4 changes: 2 additions & 2 deletions jstalk.xcodeproj/project.pbxproj
Expand Up @@ -210,7 +210,7 @@
CCEC36F515BA5E44008D8460 /* MOInstanceVariableDescription.h in Headers */ = {isa = PBXBuildFile; fileRef = CCEC36B915BA5E44008D8460 /* MOInstanceVariableDescription.h */; }; CCEC36F515BA5E44008D8460 /* MOInstanceVariableDescription.h in Headers */ = {isa = PBXBuildFile; fileRef = CCEC36B915BA5E44008D8460 /* MOInstanceVariableDescription.h */; };
CCEC36F615BA5E44008D8460 /* MOInstanceVariableDescription.m in Sources */ = {isa = PBXBuildFile; fileRef = CCEC36BA15BA5E44008D8460 /* MOInstanceVariableDescription.m */; }; CCEC36F615BA5E44008D8460 /* MOInstanceVariableDescription.m in Sources */ = {isa = PBXBuildFile; fileRef = CCEC36BA15BA5E44008D8460 /* MOInstanceVariableDescription.m */; };
CCEC36F715BA5E44008D8460 /* MOInstanceVariableDescription_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = CCEC36BB15BA5E44008D8460 /* MOInstanceVariableDescription_Private.h */; }; CCEC36F715BA5E44008D8460 /* MOInstanceVariableDescription_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = CCEC36BB15BA5E44008D8460 /* MOInstanceVariableDescription_Private.h */; };
CCEC36F815BA5E44008D8460 /* MOJavaScriptObject.h in Headers */ = {isa = PBXBuildFile; fileRef = CCEC36BC15BA5E44008D8460 /* MOJavaScriptObject.h */; }; CCEC36F815BA5E44008D8460 /* MOJavaScriptObject.h in Headers */ = {isa = PBXBuildFile; fileRef = CCEC36BC15BA5E44008D8460 /* MOJavaScriptObject.h */; settings = {ATTRIBUTES = (Public, ); }; };
CCEC36F915BA5E44008D8460 /* MOJavaScriptObject.m in Sources */ = {isa = PBXBuildFile; fileRef = CCEC36BD15BA5E44008D8460 /* MOJavaScriptObject.m */; }; CCEC36F915BA5E44008D8460 /* MOJavaScriptObject.m in Sources */ = {isa = PBXBuildFile; fileRef = CCEC36BD15BA5E44008D8460 /* MOJavaScriptObject.m */; };
CCEC36FA15BA5E44008D8460 /* MOMethod.h in Headers */ = {isa = PBXBuildFile; fileRef = CCEC36BE15BA5E44008D8460 /* MOMethod.h */; }; CCEC36FA15BA5E44008D8460 /* MOMethod.h in Headers */ = {isa = PBXBuildFile; fileRef = CCEC36BE15BA5E44008D8460 /* MOMethod.h */; };
CCEC36FB15BA5E44008D8460 /* MOMethod.m in Sources */ = {isa = PBXBuildFile; fileRef = CCEC36BF15BA5E44008D8460 /* MOMethod.m */; }; CCEC36FB15BA5E44008D8460 /* MOMethod.m in Sources */ = {isa = PBXBuildFile; fileRef = CCEC36BF15BA5E44008D8460 /* MOMethod.m */; };
Expand Down Expand Up @@ -887,6 +887,7 @@
CC41433B0F25259400E46669 /* JSTalk.h in Headers */, CC41433B0F25259400E46669 /* JSTalk.h in Headers */,
CC41433D0F25259500E46669 /* JSTListener.h in Headers */, CC41433D0F25259500E46669 /* JSTListener.h in Headers */,
CC4143C30F2529F200E46669 /* JSTExtras.h in Headers */, CC4143C30F2529F200E46669 /* JSTExtras.h in Headers */,
CCEC36F815BA5E44008D8460 /* MOJavaScriptObject.h in Headers */,
CC975BC80F47E5BD00097108 /* JSTPreprocessor.h in Headers */, CC975BC80F47E5BD00097108 /* JSTPreprocessor.h in Headers */,
CC0FEEE21086740F008FF7DD /* JSTTextView.h in Headers */, CC0FEEE21086740F008FF7DD /* JSTTextView.h in Headers */,
CC0FEEE410867410008FF7DD /* MarkerLineNumberView.h in Headers */, CC0FEEE410867410008FF7DD /* MarkerLineNumberView.h in Headers */,
Expand All @@ -911,7 +912,6 @@
CCEC36F415BA5E44008D8460 /* MOClosure_Private.h in Headers */, CCEC36F415BA5E44008D8460 /* MOClosure_Private.h in Headers */,
CCEC36F515BA5E44008D8460 /* MOInstanceVariableDescription.h in Headers */, CCEC36F515BA5E44008D8460 /* MOInstanceVariableDescription.h in Headers */,
CCEC36F715BA5E44008D8460 /* MOInstanceVariableDescription_Private.h in Headers */, CCEC36F715BA5E44008D8460 /* MOInstanceVariableDescription_Private.h in Headers */,
CCEC36F815BA5E44008D8460 /* MOJavaScriptObject.h in Headers */,
CCEC36FA15BA5E44008D8460 /* MOMethod.h in Headers */, CCEC36FA15BA5E44008D8460 /* MOMethod.h in Headers */,
CCEC36FC15BA5E44008D8460 /* MOMethod_Private.h in Headers */, CCEC36FC15BA5E44008D8460 /* MOMethod_Private.h in Headers */,
CCEC36FD15BA5E44008D8460 /* MOMethodDescription.h in Headers */, CCEC36FD15BA5E44008D8460 /* MOMethodDescription.h in Headers */,
Expand Down
3 changes: 2 additions & 1 deletion mocha/Utilities/MOFunctionArgument.m
Expand Up @@ -863,7 +863,8 @@ + (BOOL)toJSValue:(JSValueRef *)value inContext:(JSContextRef)ctx typeEncoding:(
*value = [runtime JSValueForObject:[NSNull null]]; *value = [runtime JSValueForObject:[NSNull null]];
} }
else { else {
NSValue *object = [NSValue valueWithPointer:ptr]; void* pointer = *(void**)ptr;
NSValue *object = [NSValue valueWithPointer:pointer];
*value = [runtime JSValueForObject:object]; *value = [runtime JSValueForObject:object];
} }
return YES; return YES;
Expand Down
1 change: 0 additions & 1 deletion mocha/Utilities/MOUtilities.m
Expand Up @@ -449,7 +449,6 @@ JSValueRef MOFunctionInvoke(id function, JSContextRef ctx, size_t argumentCount,
#else #else
typeEncoding = [argument type]; typeEncoding = [argument type];
#endif #endif

MOFunctionArgument *arg = MOFunctionArgumentForTypeEncoding(typeEncoding); MOFunctionArgument *arg = MOFunctionArgumentForTypeEncoding(typeEncoding);
[args addObject:arg]; [args addObject:arg];
} }
Expand Down
29 changes: 15 additions & 14 deletions plugins/imagetools/JSTCodeSketcher.h
Expand Up @@ -8,17 +8,18 @@


#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <JSTalk/JSTalk.h> #import <JSTalk/JSTalk.h>
#import <JSTalk/MOJavaScriptObject.h>


@interface JSTCodeSketcher : NSView { @interface JSTCodeSketcher : NSView {


JSTalk *_jstalk; JSTalk *_jstalk;


JSValueRef _drawFunction; MOJavaScriptObject *_drawRect;
JSValueRef _setupFunction; MOJavaScriptObject *_setup;
JSValueRef _mouseMoveFunction; MOJavaScriptObject *_mouseMoved;
JSValueRef _mouseUpFunction; MOJavaScriptObject *_mouseUp;
JSValueRef _mouseDownFunction; MOJavaScriptObject *_mouseDown;
JSValueRef _mouseDragFunction; MOJavaScriptObject *_mouseDragged;


CGFloat _frameRate; CGFloat _frameRate;


Expand Down Expand Up @@ -50,17 +51,17 @@
@property (retain) NSString *lookupName; @property (retain) NSString *lookupName;
@property (retain) NSGraphicsContext *nsContext; @property (retain) NSGraphicsContext *nsContext;
@property (assign) NSSize size; @property (assign) NSSize size;

@property (strong) MOJavaScriptObject *drawRect;
@property (strong) MOJavaScriptObject *setup;
@property (strong) MOJavaScriptObject *mouseMoved;
@property (strong) MOJavaScriptObject *mouseUp;
@property (strong) MOJavaScriptObject *mouseDown;
@property (strong) MOJavaScriptObject *mouseDragged;

- (void)stop; - (void)stop;
- (void)start; - (void)start;


/*
- (void)setDraw:(JSValueRefAndContextRef)ref;
- (void)setMouseMove:(JSValueRefAndContextRef)ref;
- (void)setMouseUp:(JSValueRefAndContextRef)ref;
- (void)setMouseDown:(JSValueRefAndContextRef)ref;
- (void)setMouseDrag:(JSValueRefAndContextRef)ref;
*/

@end @end




Expand Down
117 changes: 51 additions & 66 deletions plugins/imagetools/JSTCodeSketcher.m
Expand Up @@ -8,6 +8,10 @@


#import "JSTCodeSketcher.h" #import "JSTCodeSketcher.h"


@interface JSTalk (Private)

@end

@interface JSTCodeSketcher() @interface JSTCodeSketcher()
- (void)setupWindow; - (void)setupWindow;
- (void)resizeContext; - (void)resizeContext;
Expand All @@ -24,9 +28,18 @@ @implementation JSTCodeSketcher
@synthesize nsContext = _nsContext; @synthesize nsContext = _nsContext;
@synthesize size = _size; @synthesize size = _size;


@synthesize drawRect = _drawRect;
@synthesize setup = _setup;
@synthesize mouseMoved = _mouseMoved;
@synthesize mouseUp = _mouseUp;
@synthesize mouseDown = _mouseDown;
@synthesize mouseDragged = _mouseDragged;



+ (id)codeSketcherWithName:(NSString*)name { + (id)codeSketcherWithName:(NSString*)name {


static NSMutableDictionary *JSTSketchers = 0x00; static NSMutableDictionary *JSTSketchers = nil;


if (!JSTSketchers) { if (!JSTSketchers) {
JSTSketchers = [[NSMutableDictionary dictionary] retain]; JSTSketchers = [[NSMutableDictionary dictionary] retain];
Expand Down Expand Up @@ -90,7 +103,9 @@ - (void)resizeContext {


CGColorSpaceRef cs = [[[NSScreen mainScreen] colorSpace] CGColorSpace]; CGColorSpaceRef cs = [[[NSScreen mainScreen] colorSpace] CGColorSpace];
// using float components because it helps with premultiplication. // using float components because it helps with premultiplication.
_context = CGBitmapContextCreate(0x00, mySize.width, mySize.height, 32, 0, cs, kCGBitmapFloatComponents | kCGImageAlphaPremultipliedLast); _context = CGBitmapContextCreate(nil, mySize.width, mySize.height, 32, 0, cs, kCGBitmapFloatComponents | kCGImageAlphaPremultipliedLast);

debug(@"made new context: %p / %@", _context, _context);


[self setNsContext:[NSGraphicsContext graphicsContextWithGraphicsPort:_context flipped:_flipped]]; [self setNsContext:[NSGraphicsContext graphicsContextWithGraphicsPort:_context flipped:_flipped]];


Expand All @@ -100,38 +115,34 @@ - (void)stop {


[_redrawTimer invalidate]; [_redrawTimer invalidate];
[_redrawTimer release]; [_redrawTimer release];
_redrawTimer = 0x00; _redrawTimer = nil;


if (_setupFunction) { [_drawRect release];
JSValueUnprotect([_jstalk context], _drawFunction); _drawRect = nil;
}


if (_drawFunction) { [_setup release];
JSValueUnprotect([_jstalk context], _drawFunction); _setup = nil;
}


if (_mouseUpFunction) { [_mouseMoved release];
JSValueUnprotect([_jstalk context], _mouseUpFunction); _mouseMoved = nil;
}
[_mouseUp release];
_mouseUp = nil;

[_mouseDown release];
_mouseDown = nil;

[_mouseDragged release];
_mouseDragged = nil;


if (_mouseDownFunction) {
JSValueUnprotect([_jstalk context], _mouseDownFunction);
}


if (_mouseMoveFunction) {
JSValueUnprotect([_jstalk context], _mouseMoveFunction);
}


if (_mouseDragFunction) {
JSValueUnprotect([_jstalk context], _mouseDragFunction);
}
} }


- (void)start { - (void)start {


if (_setupFunction) { if (_setup) {
#pragma message "FIXME: add this back in with the Mocha transition" [_jstalk callJSFunction:[_setup JSObject] withArgumentsInArray:nil];
//[[_jstalk jsController] callJSFunction:_setupFunction withArguments:0x00];
} }


[self setupWindow]; [self setupWindow];
Expand All @@ -153,7 +164,7 @@ - (void)start {
} }


if (_frameRate > 0) { if (_frameRate > 0) {
_redrawTimer = [[NSTimer scheduledTimerWithTimeInterval:(1.0 / _frameRate) target:self selector:@selector(fpsTimerHit:) userInfo:0x00 repeats:YES] retain]; _redrawTimer = [[NSTimer scheduledTimerWithTimeInterval:(1.0 / _frameRate) target:self selector:@selector(fpsTimerHit:) userInfo:nil repeats:YES] retain];
} }
} }


Expand Down Expand Up @@ -229,11 +240,10 @@ - (void)drawRect:(NSRect)dirtyRect {
[self resizeContext]; [self resizeContext];
} }


if (_drawFunction) { if (_drawRect) {
[self pushContext]; [self pushContext];


#pragma message "FIXME: add back in w/ Mocha transition" [_jstalk callJSFunction:[_drawRect JSObject] withArgumentsInArray:nil];
//[[_jstalk jsController] callJSFunction:_drawFunction withArguments:0x00];
[self popContext]; [self popContext];
} }


Expand All @@ -247,46 +257,20 @@ - (void)drawRect:(NSRect)dirtyRect {
- (void)viewDidEndLiveResize { - (void)viewDidEndLiveResize {
[self resizeContext]; [self resizeContext];
} }
/*
- (void)setSetup:(JSValueRefAndContextRef)ref {
_setupFunction = ref.value;
JSValueProtect([[_jstalk jsController] ctx], _setupFunction);
}
- (void)setDraw:(JSValueRefAndContextRef)ref {
_drawFunction = ref.value;
JSValueProtect([[_jstalk jsController] ctx], _drawFunction);
}
- (void)setMouseMove:(JSValueRefAndContextRef)ref {
_mouseMoveFunction = ref.value;
JSValueProtect([[_jstalk jsController] ctx], _mouseMoveFunction);
}


- (void)setMouseUp:(JSValueRefAndContextRef)ref {
_mouseUpFunction = ref.value;
JSValueProtect([[_jstalk jsController] ctx], _mouseUpFunction);
}
- (void)setMouseDown:(JSValueRefAndContextRef)ref {
_mouseDownFunction = ref.value;
JSValueProtect([[_jstalk jsController] ctx], _mouseDownFunction);
}


- (void)setMouseDrag:(JSValueRefAndContextRef)ref {
_mouseDragFunction = ref.value;
JSValueProtect([[_jstalk jsController] ctx], _mouseDragFunction);
}


- (void)mouseDown:(NSEvent *)event { - (void)mouseDown:(NSEvent *)event {
debug(@"%s:%d", __FUNCTION__, __LINE__);
_mousePressed = YES; _mousePressed = YES;


_pmouseLocation = _mouseLocation; _pmouseLocation = _mouseLocation;
_mouseLocation = [self convertPoint:[event locationInWindow] fromView:nil];; _mouseLocation = [self convertPoint:[event locationInWindow] fromView:nil];;


if (_mouseDownFunction) { debug(@"_mouseDown:%@", _mouseDown);
if (_mouseDown) {
[self pushContext]; [self pushContext];
[[_jstalk jsController] callJSFunction:_mouseDownFunction withArguments:[NSArray arrayWithObject:event]]; [_jstalk callJSFunction:[_mouseDown JSObject] withArgumentsInArray:[NSArray arrayWithObject:event]];
[self popContext]; [self popContext];
[self setNeedsDisplay:YES]; [self setNeedsDisplay:YES];
} }
Expand All @@ -297,9 +281,9 @@ - (void)mouseUp:(NSEvent *)event {
_pmouseLocation = _mouseLocation; _pmouseLocation = _mouseLocation;
_mouseLocation = [self convertPoint:[event locationInWindow] fromView:nil]; _mouseLocation = [self convertPoint:[event locationInWindow] fromView:nil];


if (_mouseUpFunction) { if (_mouseUp) {
[self pushContext]; [self pushContext];
[[_jstalk jsController] callJSFunction:_mouseUpFunction withArguments:[NSArray arrayWithObject:event]]; [_jstalk callJSFunction:[_mouseUp JSObject] withArgumentsInArray:[NSArray arrayWithObject:event]];
[self popContext]; [self popContext];
[self setNeedsDisplay:YES]; [self setNeedsDisplay:YES];
} }
Expand All @@ -310,9 +294,9 @@ - (void)mouseDragged:(NSEvent *)event {
_pmouseLocation = _mouseLocation; _pmouseLocation = _mouseLocation;
_mouseLocation = [self convertPoint:[event locationInWindow] fromView:nil]; _mouseLocation = [self convertPoint:[event locationInWindow] fromView:nil];


if (_mouseDragFunction) { if (_mouseDragged) {
[self pushContext]; [self pushContext];
[[_jstalk jsController] callJSFunction:_mouseDragFunction withArguments:[NSArray arrayWithObject:event]]; [_jstalk callJSFunction:[_mouseDragged JSObject] withArgumentsInArray:[NSArray arrayWithObject:event]];
[self popContext]; [self popContext];
[self setNeedsDisplay:YES]; [self setNeedsDisplay:YES];
} }
Expand All @@ -323,15 +307,14 @@ - (void)mouseMoved:(NSEvent *)event {
_pmouseLocation = _mouseLocation; _pmouseLocation = _mouseLocation;
_mouseLocation = [self convertPoint:[event locationInWindow] fromView:nil]; _mouseLocation = [self convertPoint:[event locationInWindow] fromView:nil];


if (_mouseMoveFunction) { if (_mouseMoved) {
[self pushContext]; [self pushContext];
[[_jstalk jsController] callJSFunction:_mouseMoveFunction withArguments:[NSArray arrayWithObject:event]]; [_jstalk callJSFunction:[_mouseMoved JSObject] withArgumentsInArray:[NSArray arrayWithObject:event]];
[self popContext]; [self popContext];
[self setNeedsDisplay:YES]; [self setNeedsDisplay:YES];
} }


} }
*/


- (BOOL)isFlipped { - (BOOL)isFlipped {
return _flipped; return _flipped;
Expand Down Expand Up @@ -400,7 +383,9 @@ - (void)update {
[self setNeedsDisplay:YES]; [self setNeedsDisplay:YES];
} }



- (void)sketcherWhatever:(id)ctx {
debug(@"ctx: %@", ctx);
}


@end @end


Expand Down
24 changes: 20 additions & 4 deletions plugins/imagetools/samples/codesketcher-draw.jstalk
@@ -1,17 +1,19 @@
var sketcher = [JSTCodeSketcher codeSketcherWithName:"Draw"]; var sketcher = [JSTCodeSketcher codeSketcherWithName:"Draw"];


sketcher.setup = function() { var setup = function() {
print("setup!")
[sketcher setSize:NSMakeSize(600, 300)]; [sketcher setSize:NSMakeSize(600, 300)];
[sketcher clear]; [sketcher clear];
}; };


sketcher.mouseDown = function() { var mouseDown = function() {
// reset our points // reset our points
m1 = m2 = m3 = m4 = null; m1 = m2 = m3 = m4 = null;
print("mouseDown!")
}; };


sketcher.mouseDrag = function() { var mouseDragged = function() {

print("mouseDragged!")
var m0 = [sketcher mouseLocation]; var m0 = [sketcher mouseLocation];


if (m4) { if (m4) {
Expand All @@ -29,3 +31,17 @@ sketcher.mouseDrag = function() {
m1 = m0; m1 = m0;
}; };


var mouseMoved = function() {
var p = [sketcher mouseLocation];

[[[NSColor redColor] colorWithAlphaComponent:.2] set];

var path = [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(p.x-5, p.y-5, 10, 10)];
[path stroke];
};


[sketcher setSetup:setup];
[sketcher setMouseDown:mouseDown];
[sketcher setMouseDragged:mouseDragged];
//[sketcher setMouseMoved:mouseMoved];
17 changes: 14 additions & 3 deletions plugins/imagetools/samples/codesketcher.jstalk
@@ -1,7 +1,9 @@
var sketcher = [JSTCodeSketcher codeSketcherWithName:"Code Sketcher - New Time"]; var sketcher = [JSTCodeSketcher codeSketcherWithName:"Code Sketcher - New Time"];
[sketcher setFrameRate:30]; [sketcher setFrameRate:60];


sketcher.draw = function() { var drawFunction = function() {




var date = [NSDate date] var date = [NSDate date]
var c = [[NSCalendar currentCalendar] components:(NSDayCalendarUnit | NSWeekOfYearCalendarUnit | NSMonthCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit | NSWeekdayCalendarUnit) fromDate:date]; var c = [[NSCalendar currentCalendar] components:(NSDayCalendarUnit | NSWeekOfYearCalendarUnit | NSMonthCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit | NSWeekdayCalendarUnit) fromDate:date];
Expand Down Expand Up @@ -55,8 +57,13 @@ sketcher.draw = function() {
*/ */


// hour // hour

var context = [sketcher context]; var context = [sketcher context];

CGContextSetLineWidth(context, 2.0); CGContextSetLineWidth(context, 2.0);



CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 0.5); CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 0.5);
var offset = (h_width*tm_hour) + (tm_min * (h_width/60)); var offset = (h_width*tm_hour) + (tm_min * (h_width/60));


Expand Down Expand Up @@ -127,6 +134,10 @@ sketcher.draw = function() {
CGContextAddArc(context, offset ,base-12, 5, 0, 2*Math.PI, 0); CGContextAddArc(context, offset ,base-12, 5, 0, 2*Math.PI, 0);
CGContextClosePath(context); CGContextClosePath(context);
CGContextStrokePath(context); CGContextStrokePath(context);

}; };



[sketcher setDrawRect:drawFunction];



0 comments on commit fa7f876

Please sign in to comment.