Archived
1

Added MPExpressionLayout, MPFunctionLayout and MPExpressionStorage as Rendering System for Expressions

This commit is contained in:
Kim Wittenburg
2014-04-23 03:13:55 +02:00
parent 8605a6ac7b
commit 3116925315
8 changed files with 597 additions and 6 deletions

View File

@@ -7,23 +7,73 @@
//
#import "MPExpressionView.h"
#import "MPExpressionLayout.h"
#import "MPExpressionStorage.h"
#import "NSObject+MPStringTest.h"
#import "MPSumFunction.h"
@interface MPExpressionView ()
@end
@implementation MPExpressionView
#pragma mark Creation Methods
- (instancetype)init
{
self = [super init];
if (self) {
[self initializeObjects];
}
return self;
}
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
[self initializeObjects];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
[self initializeObjects];
}
return self;
}
- (void)initializeObjects
{
MPExpressionStorage *expressionStorage = [[MPExpressionStorage alloc] initWithSymbols:@[@"12345", [[MPSumFunction alloc] init]]];
_expressionStorage = expressionStorage;
}
#pragma mark Properties
- (MPExpressionLayout *)expressionLayout
{
return self.expressionStorage.expressionLayout;
}
#pragma mark Drawing Methods
- (void)drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];
// Drawing code here.
[[NSColor whiteColor] set];
NSRectFill(self.bounds);
[[NSColor blackColor] set];
NSSize expressionSize = [self.expressionLayout sizeForAllSymbols];
CGFloat y = (self.bounds.size.height - expressionSize.height) / 2;
NSLog(@"%f", self.bounds.origin.y);
NSPoint point = NSMakePoint(self.bounds.origin.x, self.bounds.origin.y + y);
[self.expressionLayout drawAllSymbolsAtPoint:point];
}
@end