Overview
I have painting APP. It registers mouse events and sends it to NSMutableArray. Later values from array are being transfered to GLfloat and drawn like vertex array. So all brush stroke is redrawn at every mouse event.
What I want to do?
I want to implement undo-redo functions and something like brush stroke variety (softness and etc), so I need somehow to do that every vertex (mouse event location) could have few additional settings. I want to ask if it is possible at all.
Explanation
If user draws 10 points with 100% softness (in one mouse drag) and then changes softness to 0% and draws, first 10 point’s brush texture has to be set to img1 and second brush stroke brush’s texture has to be set to img2.
If there would be possibility for indexing arrays (for example something like this NSMutableArray *array[i++] = [[NSMutableArray alloc] init]) I think it would be possible to do something similar to what I want pretty easy. But is it possible? Or maby you could suggest any other solution?
P.S. NSMutableArray *array[i++] = [[NSMutableArray alloc] init] doesn’t shows me any error, but does’t works too.
Attempt using NSMutableDictionary
At mousedown and mousedragged:
locll = [self convertPoint: [event locationInWindow] fromView:nil];
NSValue *locationValuell = [NSValue valueWithPoint:locll];
[vertices addObject:locationValuell];
at mouseUp
NSString *index = [NSString stringWithFormat:@"%d", aIndex++];
[aDict setObject:vertices forKey:index];
NSArray *allKeys = [aDict allKeys];
NSLog(@"dict count: %ld", [allKeys count]);
NSString *index1 = [NSString stringWithFormat:@"%d", aIndex];
NSMutableArray *a = [aDict objectForKey:index1];
NSLog(@"a count:%li", [a count]);
at initWithCoder
int aIndex = 0;
dict count returns how many objects are stored in dictionary. And it works. But later when I try to get array back from dictionary, I check how much objects array has and it returns 0.
If i understand your question right , here’s what you can do :
NSMutableArrayof pointswith same softness level.
NSMutableDictionarywith Key as thesoftness-level and Value with this path array.
pair and draw the strokes.
a temporary dictionary.
Thanx for posting the code. I tried this and it works absolutely fine :
NOTE: Be careful with the index you are passing.