Skip to content

Commit

Permalink
ivars etc
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianEberius committed Apr 1, 2010
1 parent ec96599 commit 5d1ca1a
Show file tree
Hide file tree
Showing 11 changed files with 288 additions and 125 deletions.
41 changes: 41 additions & 0 deletions AsyncDrawOperation.m
Expand Up @@ -96,6 +96,7 @@ - (void)makePartialSnapshot
return;

[image lockFocus];
[fillColor set];
NSRectFill(NSMakeRect(0, 0, [image size].width, [image size].height));
// new image is longer or equal
if (h >= [old_image size].height) {
Expand All @@ -121,6 +122,46 @@ - (void)makePartialSnapshot
[[minimapView drawLock] unlock];
}

<<<<<<< HEAD
=======
- (void)partialBackgroundDraw
{
[[minimapView drawLock] lock];
NSImage* image = [minimapView theImage];

if ([self checkCancelled])
return;
NSRect tvBounds = [[minimapView textView] bounds];
int gutterSize = [minimapView gutterSize];
float scaleFactor = tvBounds.size.height / [image size].height;
NSRect rectToRedraw = NSMakeRect(gutterSize,
partToDraw.origin.y*scaleFactor,
tvBounds.size.width - gutterSize,
partToDraw.size.height*scaleFactor);
NSImage* drawnPart = [[minimapView textView] snapshotByDrawingInRect:rectToRedraw];

if ([self checkCancelled])
return;

[image lockFocus];
[drawnPart drawInRect:partToDraw
fromRect:rectToRedraw
operation:NSCompositeSourceOver fraction:1.0];
[image unlockFocus];

NSRect visRect = [minimapView getVisiblePartOfMinimap];
int p1 = partToDraw.origin.y;
int p2 = partToDraw.origin.y+partToDraw.size.height;
int l1 = visRect.origin.y;
int l2 = visRect.origin.y+visRect.size.height;
if ((p1>=l1 && p1<=l2) || (p2>=l1 && p2 <= l2)) {
[minimapView performSelectorOnMainThread:@selector(minorRefresh) withObject:NULL waitUntilDone:FALSE];

}
[[minimapView drawLock] unlock];
}

>>>>>>> newesttry
- (BOOL)checkCancelled
{
if ([self isCancelled]) {
Expand Down
30 changes: 30 additions & 0 deletions BackgroundUpdater.m
Expand Up @@ -54,7 +54,11 @@ - (void)setDirtyExceptForVisiblePart
{
NSImage* image = [minimapView theImage];
NSRect visRect = [minimapView getVisiblePartOfMinimap];
<<<<<<< HEAD

=======

>>>>>>> newesttry
int i = visRect.origin.y+visRect.size.height;
int t = visRect.origin.y;
BOOL goUp = TRUE;
Expand All @@ -65,6 +69,7 @@ - (void)setDirtyExceptForVisiblePart
if ((i+length) > [image size].height) {
length = [image size].height - i;
}
<<<<<<< HEAD
NSRange range = NSMakeRange(i, length+1);
[self setRangeDirty:range];
i=i+50;
Expand Down Expand Up @@ -111,6 +116,31 @@ - (void)setCompleteImageDirty
}
NSRange range = NSMakeRange(i-1,length+1);
[dirtyRegions addObject:[NSValue valueWithRange:range]];
=======

NSRect rectToDraw = NSMakeRect(visRect.origin.x, i-1, visRect.size.width, length+1);
AsyncDrawOperation* op = [[[AsyncDrawOperation alloc] initWithMinimapView:minimapView andMode:MM_BACKGROUND_DRAW] autorelease];
[op setPartToDraw:rectToDraw];
[operationQueue addOperation:op];
i=i+50;
if (i>[image size].height)
goDown = FALSE;
}
if (goUp) {
int length = 50;
if ((t-length) < 0) {
length = t;
}

NSRect rectToDraw = NSMakeRect(visRect.origin.x, t-length-1, visRect.size.width, length+1);
AsyncDrawOperation* op = [[[AsyncDrawOperation alloc] initWithMinimapView:minimapView andMode:MM_BACKGROUND_DRAW] autorelease];
[op setPartToDraw:rectToDraw];
[operationQueue addOperation:op];
t = t-50;
if (t<0)
goUp = FALSE;
}
>>>>>>> newesttry
}
}
@end
10 changes: 9 additions & 1 deletion MinimapView.h
Expand Up @@ -16,14 +16,18 @@ extern int const scaleDownTo;

NSWindowController* windowController;
NSView* textView;
NSRange viewableRange;
NSImage* theImage;
NSOperationQueue* queue;
NSTimer* timer;
NSLock* drawLock;
BackgroundUpdater* updater;

<<<<<<< HEAD
float visRectPosBeforeScrolling;
=======
float scrollDiffToTextView;
NSRange viewableRange;
>>>>>>> newesttry
NSRect visiblePartOfImage;
Boolean refreshAll;
Boolean minimapIsScrollable;
Expand All @@ -46,7 +50,11 @@ extern int const scaleDownTo;
#pragma mark public-api
- (void)refreshDisplay;
- (void)refreshViewableRange;
<<<<<<< HEAD
- (void)smallRefresh;
=======
- (void)minorRefresh;
>>>>>>> newesttry
- (int)gutterSize;
- (void)updateGutterSize;
- (void)setNewDocument;
Expand Down
82 changes: 79 additions & 3 deletions MinimapView.m
Expand Up @@ -46,12 +46,20 @@ - (id)initWithTextView:(NSView*) tv
refreshAll = NO;
viewableRangeScale = 1.0;
gutterSize = -1;
<<<<<<< HEAD
visRectPosBeforeScrolling = -1;
textView = tv;
firstDraw = YES;
timer = NULL;
drawLock = [[[NSLock alloc] init] retain];
updater = [[BackgroundUpdater alloc] initWithMinimapView:self andOperationQueue:queue];
=======
scrollDiffToTextView = 0;
textView = tv;
firstDraw = YES;
timer = NULL;
updater = [[[BackgroundUpdater alloc] initWithMinimapView:self andOperationQueue:queue] retain];
>>>>>>> newesttry
}
return self;
}
Expand All @@ -74,14 +82,19 @@ - (void)dealloc
- (void)drawRect:(NSRect)rect
{
if (firstDraw) {
theImage = [[textView emptySnapshotImageFor:self] retain];
[windowController updateTrailingSpace];
firstDraw = NO;
<<<<<<< HEAD
theImage = [[textView emptySnapshotImageFor:self] retain];
[self fillWithBackground];
[self setNeedsDisplay:NO];
//Defer first drawing by small interval ... don't know a better way to wait till the tv is fully initialized
NSTimer* t = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(firstRefresh) userInfo:nil repeats:NO];
[self setTimer:t];
=======
refreshAll = YES;
>>>>>>> newesttry
return;
}

Expand All @@ -107,12 +120,20 @@ - (void)drawRect:(NSRect)rect
[queue addOperation:op];
[op release];
refreshAll = NO;
<<<<<<< HEAD
return;
=======
scrollDiffToTextView = 0;
>>>>>>> newesttry
}
if (ppl < scaleUpThreshold)
{
NSRect rectToSnapshot = [self getVisiblePartOfMinimap];
<<<<<<< HEAD
[theImage drawInRect:drawTo fromRect:rectToSnapshot operation:NSCompositeSourceOver fraction:1.0];
=======
[theImage drawInRect:[self bounds] fromRect:rectToSnapshot operation:NSCompositeSourceOver fraction:1.0];
>>>>>>> newesttry
}
else
{
Expand All @@ -130,7 +151,7 @@ - (void)drawRect:(NSRect)rect

- (NSRect)updateVisiblePartOfImage
{
NSRect bounds = [self bounds];
NSRect bounds = [self visibleRect];
int numLines = [self getNumberOfLines];

NSSize imgSize = [theImage size];
Expand All @@ -149,9 +170,15 @@ - (NSRect)updateVisiblePartOfImage
float begin = middle - (percentage*mysteriousHeight) - ([textView visibleRect].size.height/2);

NSRect visRect = NSMakeRect(0,
<<<<<<< HEAD
begin*scaleFactor,
[theImage size].width,
(visiblePercentage * imgSize.height));
=======
begin*scaleFactor,
[theImage size].width,
(visiblePercentage * imgSize.height));
>>>>>>> newesttry
[self setMinimapLinesStart:(begin/tvBounds.size.height)*numLines];
visiblePartOfImage = visRect;
return visRect;
Expand Down Expand Up @@ -201,10 +228,14 @@ - (void)drawVisRect:(NSRect)drawTo
float middle = percentage*(bounds.size.height-visRectHeight) + visRectHeight/2;
float mysteriousHeight = (rectProportion * bounds.size.height) - visRectHeight;
visRectPos = middle - (percentage*mysteriousHeight) - (visRectHeight/2);
<<<<<<< HEAD
if (visRectPosBeforeScrolling != -1) {
float scrolledPixels = (visiblePartOfImage.origin.y - visRectPosBeforeScrolling);
visRectPos -= scrolledPixels*(bounds.size.height/visiblePartOfImage.size.height);
}
=======
visRectPos -= scrollDiffToTextView;
>>>>>>> newesttry
}
else
{
Expand Down Expand Up @@ -254,6 +285,7 @@ - (void)mouseDown:(NSEvent *)theEvent
- (void)scrollWheel:(NSEvent *)theEvent
{
NSRect tvBounds = [textView bounds];
<<<<<<< HEAD
float scaleFactor = [theImage size].height / tvBounds.size.height;

NSRect newVisRect = visiblePartOfImage;
Expand All @@ -262,16 +294,32 @@ - (void)scrollWheel:(NSEvent *)theEvent

float newBegin = (newVisRect.origin.y / scaleFactor) + ([theEvent deltaY]/scaleFactor)*(-5);

=======
float scaleFactor = [theImage size].height / tvBounds.size.height;

NSRect newVisRect = visiblePartOfImage;
float newBegin = (newVisRect.origin.y / scaleFactor) + ([theEvent deltaY]/scaleFactor)*(-5);

>>>>>>> newesttry
if (newBegin < 0)
newBegin = 0;
float lowerBound = tvBounds.size.height-(newVisRect.size.height/scaleFactor);
if (newBegin > lowerBound)
newBegin = lowerBound;
<<<<<<< HEAD

newVisRect.origin.y = newBegin*scaleFactor;
[self setMinimapLinesStart:(newBegin/tvBounds.size.height)*[self getNumberOfLines]];
visiblePartOfImage = newVisRect;
[self setNeedsDisplay:YES];
=======

newVisRect.origin.y = newBegin*scaleFactor;
scrollDiffToTextView += newVisRect.origin.y-visiblePartOfImage.origin.y;
[self setMinimapLinesStart:(newBegin/tvBounds.size.height)*[self getNumberOfLines]];
visiblePartOfImage = newVisRect;
[self setNeedsDisplayInRect:[self visibleRect]];
>>>>>>> newesttry
}

- (void) viewDidEndLiveResize
Expand Down Expand Up @@ -304,8 +352,13 @@ - (void)firstRefresh {
[self setNeedsDisplayInRect:[self visibleRect]];}

- (void)refreshViewableRange{
<<<<<<< HEAD
[self updateVisiblePartOfImage];
visRectPosBeforeScrolling = -1;
=======
scrollDiffToTextView = 0;
[self updateVisiblePartOfImage];
>>>>>>> newesttry
[self setNeedsDisplayInRect:[self visibleRect]];

NSTimer* old_timer = [self timer];
Expand All @@ -316,7 +369,11 @@ - (void)refreshViewableRange{
NSTimer* t = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(refreshDisplay) userInfo:nil repeats:NO];
[self setTimer:t];
}
<<<<<<< HEAD
- (void)smallRefresh
=======
- (void)minorRefresh
>>>>>>> newesttry
{
[self setNeedsDisplayInRect:[self visibleRect]];
}
Expand All @@ -329,18 +386,27 @@ - (void)updateGutterSize

int i = 1;
NSColor* color = [[rawImg colorAtX:i y:0] colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
while (![color isEqual:refColor]) {
int imgWidth = [rawImg size].width;
while (![color isEqual:refColor] && i < imgWidth) {
i++;
color = [[rawImg colorAtX:i y:0] colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
}
gutterSize = i+1;
if (i == imgWidth)
gutterSize = 0;
else
gutterSize = i+1;
}
- (void)setNewDocument
{
<<<<<<< HEAD
[queue setSuspended:NO];
[queue cancelAllOperations];
// [theImage release];
// theImage = NULL;
=======
[theImage release];
theImage = NULL;
>>>>>>> newesttry
firstDraw = YES;
}

Expand Down Expand Up @@ -385,6 +451,7 @@ - (int)gutterSize
- (void)asyncDrawFinished: (NSImage*) bitmap
{
[bitmap retain];
<<<<<<< HEAD
[theImage release];
theImage = bitmap;
if (minimapIsScrollable) {
Expand All @@ -397,6 +464,15 @@ - (void)asyncDrawFinished: (NSImage*) bitmap
else
pixelPerLine = [self bounds].size.height / [self getNumberOfLines];

=======
[[self drawLock] lock];
[theImage release];
theImage = bitmap;
[updater startRedrawInBackground];
[[self drawLock] lock];

pixelPerLine = [self bounds].size.height / [self getNumberOfLines];
>>>>>>> newesttry
[self setNeedsDisplay:YES];
}

Expand Down
14 changes: 5 additions & 9 deletions NSScrollView+Minimap.m
Expand Up @@ -20,15 +20,11 @@ - (void) MM_reflectScrolledClipView:(NSClipView*)clipView
{
[self MM_reflectScrolledClipView:clipView];

id controller = [[self window] windowController];
if ([controller isKindOfClass:OakProjectController] || [controller isKindOfClass:OakDocumentController])
for (NSDrawer *drawer in [[self window] drawers])
if ([[drawer contentView] isKindOfClass:[MinimapView class]] ) {
MinimapView* textShapeView = (MinimapView*)[drawer contentView];

//refreshViewableRange is a "small" refresh, reusing the image, and just repositioning the visibleRect
[textShapeView refreshViewableRange];
}
NSWindowController* controller = [[self window] windowController];
if ([controller isKindOfClass:OakProjectController] || [controller isKindOfClass:OakDocumentController]) {
MinimapView* textShapeView = [controller getMinimapView];
[textShapeView refreshViewableRange];
}

}

Expand Down

0 comments on commit 5d1ca1a

Please sign in to comment.