From 2d6b88d5d016237acbc8cb63f2cf2477ccfe9e69 Mon Sep 17 00:00:00 2001 From: Johan Paulsson Date: Sun, 23 Mar 2014 02:45:56 +0000 Subject: osx gui: initial creation of custom node shapes preference panel --- tikzit/src/osx/CustomNodeCellView.h | 23 +++++++++ tikzit/src/osx/CustomNodeCellView.m | 79 +++++++++++++++++++++++++++++++ tikzit/src/osx/CustomNodeController.h | 33 +++++++++++++ tikzit/src/osx/CustomNodeController.m | 89 +++++++++++++++++++++++++++++++++++ tikzit/src/osx/CustomNodes.xib | 15 ++++++ 5 files changed, 239 insertions(+) create mode 100644 tikzit/src/osx/CustomNodeCellView.h create mode 100644 tikzit/src/osx/CustomNodeCellView.m create mode 100644 tikzit/src/osx/CustomNodeController.h create mode 100644 tikzit/src/osx/CustomNodeController.m create mode 100644 tikzit/src/osx/CustomNodes.xib (limited to 'tikzit/src') 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 + +#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 +#import "Shape.h" +#import "TikzShape.h" + +#import "GraphicsView.h" +#import "TikzSourceController.h" + +#import "SupportDir.h" + +@interface CustomNodeController : NSViewController { + 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 @@ + + + + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3