1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
//
// CVTextLayerView.mm
// freej
//
// Created by xant on 12/30/09.
// Copyright 2009 dyne.org. All rights reserved.
//
#import <CVTextLayerController.h>
#import "CVTextLayerView.h"
@implementation CVTextLayerView
- (id)init {
attributes = [[NSMutableDictionary dictionary] retain];
[attributes
setObject:[textView font]
forKey:NSFontAttributeName
];
[attributes
setObject:[textView textColor]
forKey:NSForegroundColorAttributeName
];
[attributes
setObject:[[textView backgroundColor] colorWithAlphaComponent:0.0]
forKey:NSBackgroundColorAttributeName
];
return [super init];
}
- (void)changeDocumentBackgroundColor:(id)sender
{
[attributes setObject:[sender color] forKey:NSBackgroundColorAttributeName];
}
- (void)changeAttributes:(id)sender
{
NSDictionary *oldAttributes = attributes;
attributes = (NSMutableDictionary *)[sender convertAttributes: oldAttributes];
}
- (void)changeFont:(id)sender {
NSFont *oldFont = [attributes objectForKey:NSFontAttributeName];
NSFont *newFont = [sender convertFont:oldFont];
[attributes setObject:newFont forKey:NSFontAttributeName];
}
- (IBAction)showFontMenu:(id)sender {
NSFontManager *fontManager = [NSFontManager sharedFontManager];
[fontManager setDelegate:self];
[fontManager setTarget:self];
NSFontPanel *fontPanel = [fontManager fontPanel:YES];
[fontPanel setNextResponder:self];
[fontPanel orderFront:self];
}
- (IBAction)startText:(id)sender
{
NSString *text = [textView string];
[(CVTextLayerController *)layerController setText:text withAttributes:attributes];
}
// show the text while typing
- (IBAction)doLive:(id)sender
{
bool newValue = [sender intValue];
if (live != newValue) {
if (!live)
[self startText:self];
live = [sender intValue];
}
}
// if we are running in live mode... let's update the text when it changes
- (void)textDidChange:(NSNotification *)aNotification
{
if (live)
[self startText:self];
}
@end
|