diff options
author | Johan Paulsson <gonz@badcode.net> | 2014-03-23 02:45:56 +0000 |
---|---|---|
committer | Johan Paulsson <gonz@badcode.net> | 2014-03-23 02:45:56 +0000 |
commit | 2d6b88d5d016237acbc8cb63f2cf2477ccfe9e69 (patch) | |
tree | 8ed28e84d5a7bb0a8b9b1fa795e7272a3f1c4370 /tikzit/src/osx | |
parent | 5506611ee009498f1f9bce89b6e6735b19d6b137 (diff) |
osx gui: initial creation of custom node shapes preference panel
Diffstat (limited to 'tikzit/src/osx')
-rw-r--r-- | tikzit/src/osx/CustomNodeCellView.h | 23 | ||||
-rw-r--r-- | tikzit/src/osx/CustomNodeCellView.m | 79 | ||||
-rw-r--r-- | tikzit/src/osx/CustomNodeController.h | 33 | ||||
-rw-r--r-- | tikzit/src/osx/CustomNodeController.m | 89 | ||||
-rw-r--r-- | tikzit/src/osx/CustomNodes.xib | 15 |
5 files changed, 239 insertions, 0 deletions
diff --git a/tikzit/src/osx/CustomNodeCellView.h b/tikzit/src/osx/CustomNodeCellView.h new file mode 100644 index 0000000..5b3b1ee --- /dev/null +++ b/tikzit/src/osx/CustomNodeCellView.h @@ -0,0 +1,23 @@ +// +// CustomNodeCellView.h +// TikZiT +// +// Created by Johan Paulsson on 12/12/13. +// Copyright (c) 2013 Aleks Kissinger. All rights reserved. +// + +#import <Cocoa/Cocoa.h> + +#import "NodeLayer.h" +#import "NodeStyle.h" +#import "NodeStyle+Coder.h" + +@interface CustomNodeCellView : NSTableCellView{ + NodeLayer *nodeLayer; + NodeStyle *nodeStyle; + BOOL selected; +} + +@property (retain) id objectValue; + +@end diff --git a/tikzit/src/osx/CustomNodeCellView.m b/tikzit/src/osx/CustomNodeCellView.m new file mode 100644 index 0000000..57ef24a --- /dev/null +++ b/tikzit/src/osx/CustomNodeCellView.m @@ -0,0 +1,79 @@ +// +// CustomNodeCellView.m +// TikZiT +// +// Created by Johan Paulsson on 12/12/13. +// Copyright (c) 2013 Aleks Kissinger. All rights reserved. +// + +#import "CustomNodeCellView.h" + +@implementation CustomNodeCellView + +- (id)initWithFrame:(NSRect)frame +{ + self = [super initWithFrame:frame]; + if (self) { + // Initialization code here. + } + return self; +} + +- (void)drawRect:(NSRect)dirtyRect +{ + [super drawRect:dirtyRect]; + + // Drawing code here. +} + +- (id) objectValue{ + return [super objectValue]; +} + +-(void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context { + NSLog(@"drawing layer ^^"); + + if (nodeLayer!=nil) { + if (![[[self layer] sublayers] containsObject:nodeLayer]) { + [[self layer] addSublayer:nodeLayer]; + NSPoint c = NSMakePoint((CGRectGetMinX([[self layer] frame])+CGRectGetWidth([nodeLayer bounds])/2), + CGRectGetMidY([[self layer] frame])); + //c = NSMakePoint(-16.5,-16.5); + [nodeLayer setCenter:c andAnimateWhen:NO]; + [[self textField] setFrame:NSMakeRect(CGRectGetWidth([nodeLayer bounds]), CGRectGetMidY([[self layer] frame]), CGRectGetWidth([[self textField] frame]), CGRectGetHeight([[self textField] frame]))]; + } + + if (selected){ + [nodeStyle setStrokeColor:[NSColor whiteColor]]; + [[nodeLayer node] setStyle:nodeStyle]; + }else{ + [nodeStyle setStrokeColor:[NSColor blackColor]]; + [[nodeLayer node] setStyle:nodeStyle]; + } + + [nodeLayer updateFrame]; + } +} + +- (void) setObjectValue:(id)objectValue{ + [[self textField] setStringValue:[(NodeStyle *)objectValue shapeName]]; + nodeStyle = (NodeStyle *)objectValue; + + if (nodeLayer == nil) { + nodeLayer = [[NodeLayer alloc] initWithNode:[Node node] + transformer:[Transformer defaultTransformer]]; + [nodeLayer setRescale:NO]; + } + + [[nodeLayer node] setStyle:nodeStyle]; + [nodeLayer updateFrame]; +} + +- (void)setBackgroundStyle:(NSBackgroundStyle)backgroundStyle { + [super setBackgroundStyle:backgroundStyle]; + + selected = (backgroundStyle == NSBackgroundStyleDark); + [self setNeedsDisplay:YES]; +} + +@end diff --git a/tikzit/src/osx/CustomNodeController.h b/tikzit/src/osx/CustomNodeController.h new file mode 100644 index 0000000..55f0e0b --- /dev/null +++ b/tikzit/src/osx/CustomNodeController.h @@ -0,0 +1,33 @@ +// +// CustomNodeController.h +// TikZiT +// +// Created by Johan Paulsson on 12/4/13. +// Copyright (c) 2013 Aleks Kissinger. All rights reserved. +// + +#import <Cocoa/Cocoa.h> +#import "Shape.h" +#import "TikzShape.h" + +#import "GraphicsView.h" +#import "TikzSourceController.h" + +#import "SupportDir.h" + +@interface CustomNodeController : NSViewController <NSTableViewDelegate>{ + NSDictionary* nodeStyles; + NSMutableArray* customNodeStyles; + NSMutableArray* onodeStyles; + + GraphicsView *graphicsView; + TikzSourceController *tikzSourceController; +} + +@property (readonly) NSDictionary *nodeStyles; +@property (readonly) NSMutableArray* onodeStyles; + +@property IBOutlet GraphicsView *graphicsView; +@property IBOutlet TikzSourceController *tikzSourceController; + +@end diff --git a/tikzit/src/osx/CustomNodeController.m b/tikzit/src/osx/CustomNodeController.m new file mode 100644 index 0000000..ef6b5bd --- /dev/null +++ b/tikzit/src/osx/CustomNodeController.m @@ -0,0 +1,89 @@ +// +// CustomNodeController.m +// TikZiT +// +// Created by Johan Paulsson on 12/4/13. +// Copyright (c) 2013 Aleks Kissinger. All rights reserved. +// + +#import "CustomNodeController.h" +#import "NodeStyle.h" + +@interface CustomNodeController () + +@end + +@implementation CustomNodeController + +@synthesize nodeStyles, onodeStyles; +@synthesize graphicsView, tikzSourceController; + +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil +{ + if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { +// [SupportDir createUserSupportDir]; +// NSString *supportDir = [SupportDir userSupportDir]; + +// NSString *ns = [supportDir stringByAppendingPathComponent:@"nodeStyles.plist"]; +// NSString *es = [supportDir stringByAppendingPathComponent:@"edgeStyles.plist"]; +// onodeStyles = (NSMutableArray*)[NSKeyedUnarchiver +// unarchiveObjectWithFile:ns]; + // edgeStyles = (NSMutableArray*)[NSKeyedUnarchiver +// unarchiveObjectWithFile:es]; + + if (onodeStyles == nil) onodeStyles = [NSMutableArray array]; +// if (edgeStyles == nil) edgeStyles = [NSMutableArray array]; + +// [[self window] setLevel:NSNormalWindowLevel]; +// [self showWindow:self]; + + // Initialization code here. + + NSLog(@"Custom Node controller up and running!"); + + nodeStyles= [Shape shapeDictionary]; + + customNodeStyles = [NSMutableArray array]; + + NSLog(@"Got a shape dictionary?"); + + NSString *meh; + + for(id key in nodeStyles) { + Shape *value = [nodeStyles objectForKey:key]; + + if([value isKindOfClass:[TikzShape class]]){ + NSLog(@"Got a custom node shape!"); + NodeStyle *newNodeStyle = [[NodeStyle alloc] init]; + [newNodeStyle setShapeName:key]; + + [customNodeStyles addObject:newNodeStyle]; + [onodeStyles addObject:newNodeStyle]; + +// meh = [(TikzShape *) value tikz]; + } + } + + NSLog(@"Trying to display tikz."); + +// [tikzSourceController setTikz:meh]; +// [tikzSourceController parseTikz:self]; + } + + return self; +} + +-(NSArray *)onodeStyles{ + return onodeStyles; + //return [nodeStyles allValues]; +} + +- (void)tableViewSelectionDidChange:(NSNotification *)aNotification{ + NSLog(@"Changed selection!"); +} + +- (id)valueForUndefinedKey:(NSString *)key{ + return nil; +} + +@end diff --git a/tikzit/src/osx/CustomNodes.xib b/tikzit/src/osx/CustomNodes.xib new file mode 100644 index 0000000..8b2587a --- /dev/null +++ b/tikzit/src/osx/CustomNodes.xib @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="4450" systemVersion="12D78" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES"> + <dependencies> + <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="4450"/> + </dependencies> + <objects> + <customObject id="-2" userLabel="File's Owner"/> + <customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/> + <customObject id="-3" userLabel="Application"/> + <customView id="1"> + <rect key="frame" x="0.0" y="0.0" width="480" height="272"/> + <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/> + </customView> + </objects> +</document>
\ No newline at end of file |