Model Redesign: Added Reference Frames
Added Inverse Functions UI Redesign Cleaned Code
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
|
||||
#import "MPExpressionLayout.h"
|
||||
#import "MPFunctionLayout.h"
|
||||
#import "MPPowerFunction.h"
|
||||
#import "MPPowerFunctionLayout.h"
|
||||
|
||||
#import "NSString+MPExpressionElement.h"
|
||||
#import "NSIndexPath+MPAdditions.h"
|
||||
@@ -91,11 +93,11 @@
|
||||
#pragma mark Drawing Methods
|
||||
- (NSRect)generateBounds
|
||||
{
|
||||
if (self.expression.numberOfElements == 0) {
|
||||
if (self.expression.countElements == 0) {
|
||||
return NSMakeRect(0, kMPEmptyBoxYOrigin, kMPEmptyBoxWidth, kMPEmptyBoxHeight);
|
||||
}
|
||||
CGFloat x = 0, y = 0, width = 0, height = 0;
|
||||
for (NSUInteger index = 0; index < self.expression.numberOfElements; index++) {
|
||||
for (NSUInteger index = 0; index < self.expression.countElements; index++) {
|
||||
NSRect elementBounds = [self boundsOfElementAtIndex:index];
|
||||
width += elementBounds.size.width;
|
||||
height = MAX(height, elementBounds.size.height);
|
||||
@@ -107,8 +109,10 @@
|
||||
- (NSRect)boundingRectForRange:(NSRange)range
|
||||
{
|
||||
NSUInteger startOffset;
|
||||
NSUInteger startElementIndex = [self.expression indexOfElementAtLocation:range.location
|
||||
offset:&startOffset];
|
||||
NSUInteger startElementIndex = [self.expression convertIndex:range.location
|
||||
fromReferenceFrame:MPSymbolReferenceFrame
|
||||
toReferenceFrame:MPElementReferenceFrame
|
||||
offset:&startOffset];
|
||||
// Calculate x position
|
||||
CGFloat x = 0, width = 0;
|
||||
for (NSUInteger index = 0; index < startElementIndex; index++) {
|
||||
@@ -122,7 +126,7 @@
|
||||
x += xOffset;
|
||||
width += CTLineGetBoundsWithOptions(line, 0).size.width - xOffset;
|
||||
CFRelease(line);
|
||||
} else if (startElementIndex < self.expression.numberOfElements) { // Otherwise the selection is after the last symbol
|
||||
} else if (startElementIndex < self.expression.countElements) { // Otherwise the selection is after the last symbol
|
||||
width += [self boundsOfElementAtIndex:startElementIndex].size.width;
|
||||
}
|
||||
|
||||
@@ -132,8 +136,10 @@
|
||||
}
|
||||
|
||||
NSUInteger endOffset;
|
||||
NSUInteger endElementIndex = [self.expression indexOfElementAtLocation:NSMaxRange(range)
|
||||
offset:&endOffset];
|
||||
NSUInteger endElementIndex = [self.expression convertIndex:NSMaxRange(range)
|
||||
fromReferenceFrame:MPSymbolReferenceFrame
|
||||
toReferenceFrame:MPElementReferenceFrame
|
||||
offset:&endOffset];
|
||||
|
||||
// Selection is inside of one string element
|
||||
if (startElementIndex == endElementIndex) {
|
||||
@@ -171,7 +177,7 @@
|
||||
- (NSIndexPath *)indexPathForMousePoint:(NSPoint)point
|
||||
{
|
||||
NSUInteger currentPosition = 0;
|
||||
for (NSUInteger index = 0; index < self.expression.numberOfElements; index++) {
|
||||
for (NSUInteger index = 0; index < self.expression.countElements; index++) {
|
||||
NSRect elementBounds = [self boundsOfElementAtIndex:index];
|
||||
NSPoint elementOffset = [self offsetOfChildLayoutAtIndex:index];
|
||||
elementBounds.origin.x += elementOffset.x;
|
||||
@@ -206,7 +212,7 @@
|
||||
if (point.x < self.bounds.size.width / 2) {
|
||||
return [NSIndexPath indexPathWithIndex:0];
|
||||
} else {
|
||||
return [NSIndexPath indexPathWithIndex:self.expression.length];
|
||||
return [NSIndexPath indexPathWithIndex:self.expression.countSymbols];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,21 +223,8 @@
|
||||
(CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
|
||||
CGContextSaveGState(context);
|
||||
|
||||
#ifdef MPDEBUG_DRAW_ORIGIN
|
||||
[[NSColor blueColor] set];
|
||||
[[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(-2, -2, 4, 4)] fill];
|
||||
#endif
|
||||
|
||||
[[NSColor textColor] set];
|
||||
|
||||
#ifdef MPDEBUG_DRAW_BOUNDS
|
||||
[[NSColor greenColor] set];
|
||||
[[NSBezierPath bezierPathWithRect:self.bounds] stroke];
|
||||
[[NSColor textColor] set];
|
||||
#endif
|
||||
|
||||
if (self.expression.numberOfElements == 0) {
|
||||
|
||||
if (self.expression.countElements == 0) {
|
||||
CGContextRestoreGState(context);
|
||||
NSBezierPath *path = [NSBezierPath bezierPathWithRect:NSMakeRect(0, kMPEmptyBoxDrawingYOrigin, kMPEmptyBoxDrawingWidth, kMPEmptyBoxDrawingHeight)];
|
||||
path.lineWidth = 0.5;
|
||||
@@ -245,7 +238,7 @@
|
||||
// Track the x position
|
||||
CGFloat x = 0;
|
||||
|
||||
for (NSUInteger index = 0; index < self.expression.numberOfElements; index++) {
|
||||
for (NSUInteger index = 0; index < self.expression.countElements; index++) {
|
||||
// The current element
|
||||
id element = [self.expression elementAtIndex:index];
|
||||
NSRect elementBounds = [self boundsOfElementAtIndex:index];
|
||||
@@ -258,16 +251,15 @@
|
||||
// Move to the appropriate position
|
||||
CGContextSetTextPosition(context, x, 0);
|
||||
|
||||
#ifdef MPDEBUG_DRAW_BASELINE
|
||||
[[NSColor redColor] set];
|
||||
NSRectFill(NSMakeRect(x, -1, elementBounds.size.width, 1));
|
||||
[[NSColor textColor] set];
|
||||
#endif
|
||||
|
||||
// Perform the drawing
|
||||
CTLineDraw(line, context);
|
||||
|
||||
CFRelease(line);
|
||||
|
||||
if (index < self.expression.countElements-1 && [[self.expression elementAtIndex:index+1] isKindOfClass:[MPPowerFunction class]]) {
|
||||
MPPowerFunctionLayout *layout = (MPPowerFunctionLayout *)[self childLayoutAtIndex:index+1];
|
||||
layout.baseBounds = elementBounds;
|
||||
}
|
||||
} else {
|
||||
// Let the child layout draw itself
|
||||
MPLayout *layout = [self childLayoutAtIndex:index];
|
||||
|
||||
Reference in New Issue
Block a user