Archived
1
This repository has been archived on 2022-08-08. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
mathpad/MathPad/MPExpressionView.m

80 lines
1.7 KiB
Objective-C

//
// MPExpressionView.m
// MathPad
//
// Created by Kim Wittenburg on 17.04.14.
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
//
#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) {
[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];
[[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