Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Wow this is some sketchy (no pun intended) code.

  • Loading branch information...
commit ea3d4f18f655c848d8e1f9149d70092a577e35f7 1 parent 5a4a96b
August "Gus" Mueller authored
24 plugins/imagetools/ImageTools.xcodeproj/project.pbxproj
View
@@ -9,6 +9,9 @@
/* Begin PBXBuildFile section */
8D5B49B0048680CD000E48DA /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C167DFE841241C02AAC07 /* InfoPlist.strings */; };
8D5B49B4048680CD000E48DA /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */; };
+ CC03335C146DF15C00CDE6FD /* JSTalk.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CC03335B146DF15C00CDE6FD /* JSTalk.framework */; };
+ CC03335E146DF17600CDE6FD /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CC03335D146DF17600CDE6FD /* JavaScriptCore.framework */; };
+ CC033365146DF31800CDE6FD /* JSTCodeSketcher.m in Sources */ = {isa = PBXBuildFile; fileRef = CC033364146DF31800CDE6FD /* JSTCodeSketcher.m */; };
CC32EF6412034B230090827E /* JSTImageTools.m in Sources */ = {isa = PBXBuildFile; fileRef = CC32EF6312034B230090827E /* JSTImageTools.m */; };
CC32EFCF12034F170090827E /* JSTOpenCLContext.m in Sources */ = {isa = PBXBuildFile; fileRef = CC32EFCE12034F170090827E /* JSTOpenCLContext.m */; };
CC32EFD212034FDF0090827E /* OpenCL.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CC32EFD112034FDF0090827E /* OpenCL.framework */; };
@@ -35,6 +38,10 @@
1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
8D5B49B6048680CD000E48DA /* ImageTools.jstplugin */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ImageTools.jstplugin; sourceTree = BUILT_PRODUCTS_DIR; };
8D5B49B7048680CD000E48DA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
+ CC03335B146DF15C00CDE6FD /* JSTalk.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = JSTalk.framework; sourceTree = "<group>"; };
+ CC03335D146DF17600CDE6FD /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
+ CC033363146DF31800CDE6FD /* JSTCodeSketcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTCodeSketcher.h; sourceTree = "<group>"; };
+ CC033364146DF31800CDE6FD /* JSTCodeSketcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSTCodeSketcher.m; sourceTree = "<group>"; };
CC32EF6112034B230090827E /* JSTOpenCL_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTOpenCL_Prefix.pch; sourceTree = "<group>"; };
CC32EF6212034B230090827E /* JSTImageTools.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTImageTools.h; sourceTree = "<group>"; };
CC32EF6312034B230090827E /* JSTImageTools.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JSTImageTools.m; sourceTree = "<group>"; };
@@ -69,6 +76,8 @@
8D5B49B4048680CD000E48DA /* Cocoa.framework in Frameworks */,
CC32EFD212034FDF0090827E /* OpenCL.framework in Frameworks */,
CCC9CABB1209F1F5007EED57 /* QuartzCore.framework in Frameworks */,
+ CC03335C146DF15C00CDE6FD /* JSTalk.framework in Frameworks */,
+ CC03335E146DF17600CDE6FD /* JavaScriptCore.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -128,6 +137,8 @@
CCC9CAB81209F1C6007EED57 /* JSTQuickCIFilter.m */,
CCCFCCBD13494AAA00752BB0 /* JSTCIImageAdditions.h */,
CCCFCCBE13494AAA00752BB0 /* JSTCIImageAdditions.m */,
+ CC033363146DF31800CDE6FD /* JSTCodeSketcher.h */,
+ CC033364146DF31800CDE6FD /* JSTCodeSketcher.m */,
);
name = Classes;
sourceTree = "<group>";
@@ -135,6 +146,8 @@
1058C7ACFEA557BF11CA2CBB /* Linked Frameworks */ = {
isa = PBXGroup;
children = (
+ CC03335D146DF17600CDE6FD /* JavaScriptCore.framework */,
+ CC03335B146DF15C00CDE6FD /* JSTalk.framework */,
CCC9CABA1209F1F5007EED57 /* QuartzCore.framework */,
1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */,
CC32EFD112034FDF0090827E /* OpenCL.framework */,
@@ -244,6 +257,7 @@
CC32EFD5120350040090827E /* JSTOpenCLProgram.m in Sources */,
CCC9CAB91209F1C6007EED57 /* JSTQuickCIFilter.m in Sources */,
CCCFCCBF13494AAA00752BB0 /* JSTCIImageAdditions.m in Sources */,
+ CC033365146DF31800CDE6FD /* JSTCodeSketcher.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -267,6 +281,11 @@
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_64_BIT)";
COPY_PHASE_STRIP = NO;
+ FRAMEWORK_SEARCH_PATHS = (
+ "$(inherited)",
+ "\"/builds/jstalk-dphbftdevinaiygrzonxxbjasmzc/Build/Products/Debug\"",
+ "\"$(SRCROOT)\"",
+ );
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_OPTIMIZATION_LEVEL = 0;
@@ -289,6 +308,11 @@
i386,
);
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ FRAMEWORK_SEARCH_PATHS = (
+ "$(inherited)",
+ "\"/builds/jstalk-dphbftdevinaiygrzonxxbjasmzc/Build/Products/Debug\"",
+ "\"$(SRCROOT)\"",
+ );
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = JSTOpenCL_Prefix.pch;
INFOPLIST_FILE = Info.plist;
87 plugins/imagetools/JSTCodeSketcher.h
View
@@ -0,0 +1,87 @@
+//
+// JSTCodeSketcher.h
+// ImageTools
+//
+// Created by August Mueller on 11/11/11.
+// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import <JSTalk/JSTalk.h>
+
+@class JSTCodeSketcherView;
+
+@interface JSTCodeSketcher : NSObject {
+
+ JSTalk *_jstalk;
+
+ JSValueRef _drawFunction;
+ JSValueRef _setupFunction;
+ JSValueRef _mouseMovedFunction;
+
+ CGFloat _fps;
+
+ NSWindow *_window;
+
+
+ JSTCodeSketcherView *_unretainedSketcherView;
+
+ BOOL _flipped;
+
+ NSTimer *_redrawTimer;
+
+ CGContextRef _context;
+}
+
+@property (retain) JSTalk *jstalk;
+@property (assign, getter=isFlipped) BOOL flipped;
+
+- (void)stop;
+- (void)start;
+
+- (void)setFramesPerSecond:(CGFloat)f;
+
+- (void)setDraw:(JSValueRefAndContextRef)ref;
+- (void)setMouseMove:(JSValueRefAndContextRef)ref;
+- (void)callDrawWithRect:(NSRect)r;
+
+@end
+
+
+
+@interface JSTCodeSketcherView : NSView {
+ JSTCodeSketcher *_sketcher;
+}
+
+@property (retain) JSTCodeSketcher *sketcher;
+
+@end
+
+
+
+
+@interface JSTFakePoint : NSObject {
+ CGFloat _x;
+ CGFloat _y;
+}
+@property (assign) CGFloat x;
+@property (assign) CGFloat y;
+@end
+
+@interface JSTFakeSize : NSObject {
+ CGFloat _width;
+ CGFloat _height;
+}
+@property (assign) CGFloat width;
+@property (assign) CGFloat height;
+@end
+
+
+@interface JSTFakeRect : NSObject {
+ JSTFakePoint *_origin;
+ JSTFakeSize *_size;
+}
+@property (retain) JSTFakePoint *origin;
+@property (retain) JSTFakeSize *size;
++ (id)rectWithRect:(NSRect)rect;
+@end
275 plugins/imagetools/JSTCodeSketcher.m
View
@@ -0,0 +1,275 @@
+//
+// JSTCodeSketcher.m
+// ImageTools
+//
+// Created by August Mueller on 11/11/11.
+// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import "JSTCodeSketcher.h"
+
+@interface JSTCodeSketcher()
+- (void)setupWindow;
+@end
+
+@implementation JSTCodeSketcher
+
+@synthesize jstalk = _jstalk;
+@synthesize flipped = _flipped;
+
+static NSMutableDictionary *JSTSketchers = 0x00;
+
++ (id)codeSketcherWithName:(NSString*)name {
+ if (!JSTSketchers) {
+ JSTSketchers = [[NSMutableDictionary dictionary] retain];
+ }
+
+ JSTCodeSketcher *cs = [JSTSketchers objectForKey:name];
+
+ if (!cs) {
+ cs = [[JSTCodeSketcher new] autorelease];
+ [JSTSketchers setObject:cs forKey:name];
+ }
+
+ [cs stop];
+
+ [cs setJstalk:[JSTalk currentJSTalk]];
+
+ dispatch_async(dispatch_get_main_queue(),^ {
+ [cs start];
+ });
+
+ return cs;
+}
+
+
+- (id)init {
+ self = [super init];
+ if (self) {
+ _flipped = YES;
+ }
+ return self;
+}
+
+- (void)dealloc {
+
+ _unretainedSketcherView = 0x00;
+
+ [super dealloc];
+}
+
+- (void)stop {
+
+ [_redrawTimer invalidate];
+ [_redrawTimer release];
+ _redrawTimer = 0x00;
+
+ if (_drawFunction) {
+ JSValueUnprotect([[_jstalk jsController] ctx], _drawFunction);
+ }
+}
+
+- (void)start {
+
+ [self setupWindow];
+
+ [_unretainedSketcherView setNeedsDisplay:YES];
+
+ if (_fps > 0) {
+ _redrawTimer = [[NSTimer scheduledTimerWithTimeInterval:(1.0 / _fps) target:self selector:@selector(fpsTimerHit:) userInfo:0x00 repeats:YES] retain];
+ }
+}
+
+- (void)fpsTimerHit:(NSTimer*)timer {
+ [_unretainedSketcherView setNeedsDisplay:YES];
+}
+
+- (void)setFramesPerSecond:(CGFloat)f {
+
+ if (_fps > 60) {
+ _fps = 60;
+ NSLog(@"FPS set too high, limiting to 60");
+ }
+
+ _fps = f;
+}
+
+- (void)setDraw:(JSValueRefAndContextRef)ref {
+
+ _drawFunction = ref.value;
+ JSValueProtect([[_jstalk jsController] ctx], _drawFunction);
+}
+
+- (void)setMouseMove:(JSValueRefAndContextRef)ref {
+ _mouseMovedFunction = ref.value;
+ JSValueProtect([[_jstalk jsController] ctx], _mouseMovedFunction);
+}
+
+- (NSRect)viewBounds {
+ return [_unretainedSketcherView bounds];
+}
+
+- (void)callMouseMovedWithEvent:(NSEvent*)event {
+ if (_mouseMovedFunction) {
+ [[_jstalk jsController] callJSFunction:_mouseMovedFunction withArguments:[NSArray arrayWithObject:event]];
+ }
+}
+
+- (void)callDrawWithRect:(NSRect)r {
+ if (_drawFunction) {
+
+ [[NSGraphicsContext currentContext] saveGraphicsState];
+
+ [[_jstalk jsController] callJSFunction:_drawFunction withArguments:[NSArray arrayWithObject:[JSTFakeRect rectWithRect:r]]];
+
+ [[NSGraphicsContext currentContext] restoreGraphicsState];
+ }
+}
+
+- (void)setupWindow {
+ if (!_window) {
+
+ CGFloat bottomBorderHeight = 20;
+
+ NSRect winRect = NSMakeRect(0, 0, 800, 400);
+ NSRect extent = winRect;
+
+ winRect.size.height += bottomBorderHeight;
+
+
+ _window = [[NSWindow alloc] initWithContentRect:winRect
+ styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask
+ backing:NSBackingStoreBuffered
+ defer:NO];
+
+ [_window center];
+ [_window setShowsResizeIndicator:YES];
+ [_window makeKeyAndOrderFront:self];
+ [_window setReleasedWhenClosed:YES]; // we retain it in the dictionary.
+ [_window setContentBorderThickness:bottomBorderHeight forEdge:NSMinYEdge];
+ [_window setPreferredBackingLocation:NSWindowBackingLocationMainMemory];
+
+
+ [_window setAcceptsMouseMovedEvents:YES];
+
+ extent.origin.y += bottomBorderHeight;
+
+ JSTCodeSketcherView *iv = [[[JSTCodeSketcherView alloc] initWithFrame:extent] autorelease];
+ [iv setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable];
+ [[_window contentView] addSubview:iv];
+ [_window setTitle:@"Code Sketcher!"];
+
+ [_window makeFirstResponder:iv];
+
+ [iv setSketcher:self];
+
+ _unretainedSketcherView = iv;
+
+ [[NSNotificationCenter defaultCenter] addObserverForName:NSWindowWillCloseNotification object:_window queue:nil usingBlock:^(NSNotification *arg1) {
+
+ dispatch_async(dispatch_get_main_queue(),^ {
+
+ [_unretainedSketcherView setSketcher:0x00];
+
+ _unretainedSketcherView = 0x00;
+
+ debug(@"Wow, we're just leaking here.");
+ });
+ }];
+ }
+}
+
+- (CGFloat)mouseX {
+
+ NSPoint p = [NSEvent mouseLocation];
+
+ p = [_window convertScreenToBase:p];
+ p = [_unretainedSketcherView convertPoint:p fromView:nil];
+
+ return p.x;
+}
+
+- (CGFloat)mouseY {
+ NSPoint p = [NSEvent mouseLocation];
+
+ p = [_window convertScreenToBase:p];
+ p = [_unretainedSketcherView convertPoint:p fromView:nil];
+
+ return p.y;
+}
+
+@end
+
+
+@implementation JSTCodeSketcherView
+@synthesize sketcher = _sketcher;
+
+- (void)dealloc {
+ [_sketcher release];
+ [super dealloc];
+}
+
+- (id)initWithFrame:(NSRect)frame {
+ self = [super initWithFrame:frame];
+ if (self) {
+
+
+ }
+ return self;
+}
+
+- (void)drawRect:(NSRect)dirtyRect {
+
+ [[NSColor whiteColor] set];
+ NSRectFill(dirtyRect);
+
+ [_sketcher callDrawWithRect:dirtyRect];
+}
+
+- (void)mouseMoved:(NSEvent *)event {
+ [_sketcher callMouseMovedWithEvent:event];
+}
+
+- (BOOL)isFlipped {
+ return [_sketcher isFlipped];
+}
+
+@end
+
+
+
+
+
+@implementation JSTFakePoint
+
+@synthesize x = _x;
+@synthesize y = _y;
+
+@end
+
+@implementation JSTFakeSize
+
+@synthesize width = _width;
+@synthesize height = _height;
+
+@end
+
+@implementation JSTFakeRect
+
+@synthesize origin = _origin;
+@synthesize size = _size;
+
++ (id)rectWithRect:(NSRect)rect {
+
+ JSTFakeRect *r = [[[JSTFakeRect alloc] init] autorelease];
+
+ r.origin.x = rect.origin.x;
+ r.origin.y = rect.origin.y;
+ r.size.width = rect.size.width;
+ r.size.height = rect.size.height;
+
+ return r;
+}
+
+@end
+
2  plugins/imagetools/JSTImageTools.h
View
@@ -7,7 +7,7 @@
//
#import <Cocoa/Cocoa.h>
-
+#import <JSTalk/JSTalk.h>
@interface JSTImageTools : NSObject {
2  plugins/imagetools/JSTImageTools.m
View
@@ -8,6 +8,7 @@
#import "JSTImageTools.h"
#import "JSTOpenCLProgram.h"
+#import "JSTCodeSketcher.h"
#import <QuartzCore/QuartzCore.h>
@implementation NSImage (JSTExtras)
@@ -227,6 +228,7 @@ + (void)viewCIImage:(CIImage*)img inWindowNamed:(NSString*)winName extent:(CGRec
}
+
static BOOL JSTImageToolsCISWRender = NO;
+ (void)setShouldUseCISofwareRenderer:(BOOL)b {
JSTImageToolsCISWRender = b;
Please sign in to comment.
Something went wrong with that request. Please try again.