Search Results

Search found 3 results on 1 pages for 'xon1c'.

Page 1/1 | 1 

  • NSUndoManager won't undo editing of a NSMutableDictionary

    - by xon1c
    Hi, I'm experiencing problems with the undo operation. The following code won't undo an removeObjectForKey: operation but the redo operation setObject:ForKey: works. - (void) insertIntoDictionary:(NSBezierPath *)thePath { [[[window undoManager] prepareWithInvocationTarget:self] removeFromDictionary:thePath]; if(![[window undoManager] isUndoing]) [[window undoManager] setActionName:@"Save Path"]; NSLog(@"Object id is: %d and Key id is: %d", [currentPath objectAtIndex:0], thePath); [colorsForPaths setObject:[currentPath objectAtIndex:0] forKey:thePath]; } - (void) removeFromDictionary:(NSBezierPath *)thePath { [[[window undoManager] prepareWithInvocationTarget:self] insertIntoDictionary:thePath]; if(![[window undoManager] isUndoing]) [[window undoManager] setActionName:@"Delete Path"]; NSLog(@"Object id is: %d and Key id is: %d", [[colorsForPaths allKeys] objectAtIndex:0], thePath); [colorsForPaths removeObjectForKey:thePath]; } The output on the console looks like: // Before setObject:ForKey: Object id is: 1184384 and Key id is: 1530016 // Before removeObjectForKey: UNDO Object id is: 2413664 and Key id is: 1530016 I don't get why the Object id is different although the Key id remains the same. Is there some special undo/redo handling of NSMutableDictionary objects? thx xonic

    Read the article

  • Optimize a views drawing code

    - by xon1c
    Hi, in a simple drawing application I have a model which has a NSMutableArray curvedPaths holding all the lines the user has drawn. A line itself is also a NSMutableArray, containing the point objects. As I draw curved NSBezier paths, my point array has the following structure: linePoint, controlPoint, controlPoint, linePoint, controlPoint, controlPoint, etc... I thought having one array holding all the points plus control points would be more efficient than dealing with 2 or 3 different arrays. Obviously my view draws the paths it gets from the model, which leads to the actual question: Is there a way to optimize the following code (inside the view's drawRect method) in terms of speed? int lineCount = [[model curvedPaths] count]; // Go through paths for (int i=0; i < lineCount; i++) { // Get the Color NSColor *theColor = [model getColorOfPath:[[model curvedPaths] objectAtIndex:i]]; // Get the points NSArray *thePoints = [model getPointsOfPath:[[model curvedPaths] objectAtIndex:i]]; // Create a new path for performance reasons NSBezierPath *path = [[NSBezierPath alloc] init]; // Set the color [theColor set]; // Move to first point without drawing [path moveToPoint:[[thePoints objectAtIndex:0] myNSPoint]]; int pointCount = [thePoints count] - 3; // Go through points for (int j=0; j < pointCount; j+=3) { [path curveToPoint:[[thePoints objectAtIndex:j+3] myNSPoint] controlPoint1:[[thePoints objectAtIndex:j+1] myNSPoint] controlPoint2:[[thePoints objectAtIndex:j+2] myNSPoint]]; } // Draw the path [path stroke]; // Bye stuff [path release]; [theColor release]; } Thanks, xonic

    Read the article

  • Vector.erase(Iterator) causes bad memory access

    - by xon1c
    Hi, I am trying to do a Z-Index reordering of videoObjects stored in a vector. The plan is to identify the videoObject which is going to be put on the first position of the vector, erase it and then insert it at the first position. Unfortunately the erase() function always causes bad memory access. Here is my code: testApp.h: vector<videoObject> videoObjects; vector<videoObject>::iterator itVid; testApp.cpp: // Get the videoObject which relates to the user event for(itVid = videoObjects.begin(); itVid != videoObjects.end(); ++itVid){ if(videoObjects.at(itVid - videoObjects.begin()).isInside(ofPoint(tcur.getX(), tcur.getY()))){ videoObjects.erase(itVid); } } This should be so simple but I just don't see where I'm taking the wrong turn. Thx, xonic

    Read the article

1