.m -> .mm

git-svn-id: svn://qnap.local/TwoTerm/trunk@3112 5590a31f-7b70-45f8-8c82-aa3a8e5f4507
This commit is contained in:
Kelvin Sherlock 2016-07-11 02:21:13 +00:00
parent ae61aaa524
commit 27ccd18f1b
3 changed files with 497 additions and 0 deletions

146
CharacterGenerator.mm Normal file
View File

@ -0,0 +1,146 @@
//
// CharacterGenerator.mm
// 2Term
//
// Created by Kelvin Sherlock on 7/4/2010.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "CharacterGenerator.h"
@implementation CharacterGenerator
@synthesize characterSize = _size;
static CGImageRef PNGImage(NSString *path)
{
CGImageRef image = NULL;
CGDataProviderRef provider = NULL;
if (!path) return NULL;
provider = CGDataProviderCreateWithFilename([path fileSystemRepresentation]);
if (provider)
{
image = CGImageCreateWithPNGDataProvider( provider, NULL, NO, kCGRenderingIntentDefault);
CGDataProviderRelease(provider);
}
return image;
}
+(id)generator
{
return [[self new] autorelease];
}
-(id)init
{
if ((self = [super init]))
{
NSBundle *mainBundle;
NSString *imagePath;
CGImageRef mask;
CGImageRef src;
NSSize size;
mainBundle = [NSBundle mainBundle];
imagePath = [mainBundle pathForResource: @"a2-charset-80" ofType: @"png"];
//imagePath = [mainBundle pathForResource: @"vt100-charset" ofType: @"png"];
_characters = [[NSMutableArray alloc] initWithCapacity: 256];
_size = NSMakeSize(7, 16);
src = PNGImage(imagePath);
size.width = CGImageGetWidth(src);
size.height = CGImageGetHeight(src);
size.width /= 16;
size.height /= 16;
_size = size;
if (src)
{
mask = CGImageMaskCreate(CGImageGetWidth(src),
CGImageGetHeight(src),
CGImageGetBitsPerComponent(src),
CGImageGetBitsPerPixel(src),
CGImageGetBytesPerRow(src),
CGImageGetDataProvider(src),
NULL, NO);
for (unsigned i = 0; i < 16; ++i)
{
for (unsigned j = 0; j < 16; ++j)
{
CGImageRef cgimg = CGImageCreateWithImageInRect(mask, CGRectMake(j * _size.width, i * _size.height, _size.width, _size.height));
NSImage *nsimg = [[NSImage alloc] initWithCGImage: cgimg size: _size];
[_characters addObject: nsimg];
CGImageRelease(cgimg);
[nsimg release];
}
}
CGImageRelease(src);
CGImageRelease(mask);
}
}
return self;
}
-(void)dealloc
{
if (_image) CGImageRelease(_image);
[_characters release];
[super dealloc];
}
-(NSImage *)imageForCharacter: (unsigned)character
{
if (character > [_characters count]) return nil;
return (NSImage *)[_characters objectAtIndex: character];
}
-(void)drawCharacter: (unsigned)character atPoint: (NSPoint)point
{
NSImage *img = [self imageForCharacter: character];
if (!img) return;
[img drawInRect: (NSRect){point, _size}
fromRect: NSZeroRect
operation: NSCompositeCopy
fraction: 1.0
respectFlipped: YES
hints: nil];
}
@end

View File

@ -0,0 +1,243 @@
//
// NewTerminalWindowController.m
// 2Term
//
// Created by Kelvin Sherlock on 10/5/2010.
// Copyright (c) 2010 __MyCompanyName__. All rights reserved.
//
#import "NewTerminalWindowController.h"
#import "Emulator.h"
#import "Defaults.h"
#import "ExampleView.h"
@implementation NewTerminalWindowController
@synthesize exampleView = _exampleView;
@synthesize terminalTypeButton = _terminalTypeButton;
@synthesize colorSchemeButton = _colorSchemeButton;
@synthesize effectsButton = _effectsButton;
@synthesize foregroundColorControl = _foregroundColorControl;
@synthesize backgroundColorControl = _backgroundColorControl;
@synthesize blurSlider = _blurSlider;
@synthesize lightenSlider = _lightenSlider;
@synthesize darkenSlider = _darkenSlider;
@synthesize effectsEnabled = _effectsEnabled;
// colors
enum {
kCustom = 0,
kGreenBlack,
kBlueBlack,
kWhiteBlue,
kAmberBlack
};
+(id)new
{
return [[self alloc] initWithWindowNibName: @"NewTerminal"];
}
- (void)dealloc {
// Clean-up code here.
[_terminalTypeButton release];
[_colorSchemeButton release];
[_foregroundColorControl release];
[_backgroundColorControl release];
[_effectsButton release];
[_blurSlider release];
[_lightenSlider release];
[_darkenSlider release];
[_exampleView release];
[super dealloc];
}
- (void)windowDidLoad {
NSWindow *window;
[super windowDidLoad];
window = [self window];
//[window setAutorecalculatesContentBorderThickness: NO forEdge: NSMinYEdge];
//[window setAutorecalculatesContentBorderThickness: NO forEdge: NSMaxYEdge];
[self setEffectsEnabled: YES];
[_terminalTypeButton setMenu: [EmulatorManager emulatorMenu]];
// set color schemes.
[_colorSchemeButton setMenu: [self colorMenu]];
}
-(NSMenu *)colorMenu
{
NSMenuItem *item;
NSMenu *menu = [[NSMenu new] autorelease];
item = [[NSMenuItem new] autorelease];
[item setTitle: @"Green Black"];
[item setTag: kGreenBlack];
[menu addItem: item];
item = [[NSMenuItem new] autorelease];
[item setTitle: @"Blue Black"];
[item setTag: kBlueBlack];
[menu addItem: item];
item = [[NSMenuItem new] autorelease];
[item setTitle: @"White Blue"];
[item setTag: kWhiteBlue];
[menu addItem: item];
item = [[NSMenuItem new] autorelease];
[item setTitle: @"Amber Black"];
[item setTag: kAmberBlack];
[menu addItem: item];
item = [[NSMenuItem new] autorelease];
[item setTitle: @"Custom"];
[item setTag: kCustom];
[menu addItem: item];
return menu;
}
#pragma mark -
#pragma mark IBActions
-(IBAction)cancelButton: (id)sender
{
[[self window] performClose: self];
}
-(IBAction)connectButton: (id)sender
{
NSMenuItem *item = [_terminalTypeButton selectedItem];
NSUInteger tag = [item tag];
Class klass = [EmulatorManager emulatorForTag: (unsigned)tag];
if (klass)
{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithCapacity: 5];
[userInfo setObject: klass forKey: kClass];
[userInfo setObject: [_foregroundColorControl color] forKey: kForegroundColor];
[userInfo setObject: [_backgroundColorControl color] forKey: kBackgroundColor];
if (_effectsEnabled)
{
[userInfo setObject: [_exampleView contentFilters] forKey: kContentFilters];
}
[nc postNotificationName: kNotificationNewTerminal object: self userInfo: userInfo];
// post notificiation...
}
[[self window] performClose: self];
}
-(IBAction)colorChanged:(id)sender
{
[_colorSchemeButton selectItemWithTag: kCustom];
// redraw sample...
}
-(IBAction)setColorScheme:(id)sender
{
switch ([_colorSchemeButton selectedTag])
{
case kGreenBlack:
[_foregroundColorControl setColor: [NSColor greenColor]];
[_backgroundColorControl setColor: [NSColor blackColor]];
break;
case kBlueBlack:
[_foregroundColorControl setColor: [NSColor colorWithCalibratedRed:0.0 green: 0.5 blue: 1.0 alpha: 1.0]];
[_backgroundColorControl setColor: [NSColor blackColor]];
break;
case kWhiteBlue:
[_foregroundColorControl setColor: [NSColor whiteColor]];
[_backgroundColorControl setColor: [NSColor blueColor]];
break;
case kAmberBlack:
[_foregroundColorControl setColor: [NSColor colorWithDeviceRed: 1.0 green: 0.5 blue: 0.0 alpha: 1.0]];
[_backgroundColorControl setColor: [NSColor blackColor]];
break;
case kCustom:
break;
}
[self filterParameterChanged: nil];
}
-(IBAction)filterParameterChanged: (id)sender
{
[_exampleView setForegroundColor: [_foregroundColorControl color]];
[_exampleView setColor: [_backgroundColorControl color]];
if (_effectsEnabled)
{
[_exampleView setBlur: [_blurSlider floatValue]];
[_exampleView setLighten: [_lightenSlider floatValue]];
[_exampleView setDarken: [_darkenSlider floatValue]];
}
else
{
[_exampleView setBlur: 0.0];
[_exampleView setLighten: 0.0];
[_exampleView setDarken: 0.0];
}
[_exampleView updateEffects];
[_exampleView setNeedsDisplay: YES];
}
-(void)setEffectsEnabled:(BOOL)effectsEnabled
{
_effectsEnabled = effectsEnabled;
[self filterParameterChanged: nil];
}
#pragma mark -
#pragma mark NSWindowDelegate
-(void)windowWillClose:(NSNotification *)notification
{
[_foregroundColorControl deactivate];
[_backgroundColorControl deactivate];
[self autorelease];
}
@end

108
TwoTermAppDelegate.mm Normal file
View File

@ -0,0 +1,108 @@
//
// TwoTermAppDelegate.m
// 2Term
//
// Created by Kelvin Sherlock on 6/29/2010.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "TwoTermAppDelegate.h"
#import "TermWindowController.h"
#import "NewTerminalWindowController.h"
#import "Defaults.h"
#import "VT52.h"
#import "ScanLineFilter.h"
@implementation TwoTermAppDelegate
@synthesize window;
@synthesize imageView;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
TermWindowController *controller;
NSMutableArray *filters;
NSDictionary *parameters;
CIFilter *filter;
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver: self selector: @selector(newTerminal:) name: kNotificationNewTerminal object: nil];
filters = [NSMutableArray arrayWithCapacity: 3];
//add the scanlines
filter = [[ScanLineFilter new] autorelease];
[filter setValue: [NSNumber numberWithFloat: .5] forKey: @"inputDarken"];
[filter setValue: [NSNumber numberWithFloat: .02] forKey: @"inputLighten"];
[filters addObject: filter];
//blur it a bit...
filter = [CIFilter filterWithName: @"CIGaussianBlur"];
[filter setDefaults];
[filter setValue: [NSNumber numberWithFloat: .33] forKey: @"inputRadius"];
[filters addObject: filter];
parameters = [NSDictionary dictionaryWithObject: filters forKey: kContentFilters];
controller = [TermWindowController new];
[controller setParameters: parameters];
[controller showWindow: nil];
// this leak is ok.
}
-(void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver: self];
[super dealloc];
}
-(IBAction)newDocument: (id)sender
{
NewTerminalWindowController *controller = [NewTerminalWindowController new];
[controller showWindow: nil];
// this leak is ok.
}
#pragma mark -
#pragma mark Notificiations
-(void)newTerminal: (NSNotification *)notification
{
TermWindowController *controller;
NSDictionary *userInfo = [notification userInfo];
/*
Class klass = [userInfo objectForKey: @"Class"];
if (![klass conformsToProtocol: @protocol(Emulator)])
klass = [VT52 class];
*/
controller = [TermWindowController new];
[controller setParameters: userInfo];
//[controller setEmulator: [[klass new] autorelease]];
[controller showWindow: nil];
// this leak is ok.
}
@end