From bd5177c19528ae6e3dcaf37c9e2a29840ced65b5 Mon Sep 17 00:00:00 2001 From: Bjorn Winckler Date: Wed, 3 Feb 2010 23:07:13 +0100 Subject: [PATCH] Avoid window flashing white when first shown This only applies to the Core Text renderer. --- src/MacVim/MMVimView.h | 2 ++ src/MacVim/MMVimView.m | 24 ++++++++++++++++++++++++ src/MacVim/MMWindowController.m | 1 + 3 files changed, 27 insertions(+) diff --git a/src/MacVim/MMVimView.h b/src/MacVim/MMVimView.h index 12c3a49c..189ec8e3 100644 --- a/src/MacVim/MMVimView.h +++ b/src/MacVim/MMVimView.h @@ -26,6 +26,7 @@ MMTextView *textView; NSMutableArray *scrollbars; NSRect lastTextViewFrame; + BOOL isDirty; } - (MMVimView *)initWithFrame:(NSRect)frame vimController:(MMVimController *)c; @@ -57,5 +58,6 @@ - (void)viewDidEndLiveResize; - (void)setFrameSize:(NSSize)size; - (void)setFrame:(NSRect)frame; +- (void)markDirty; @end diff --git a/src/MacVim/MMVimView.m b/src/MacVim/MMVimView.m index 14aed802..cf8fafa6 100644 --- a/src/MacVim/MMVimView.m +++ b/src/MacVim/MMVimView.m @@ -191,6 +191,23 @@ enum { - (void)drawRect:(NSRect)rect { + if (isDirty) { + // Clear the entire view + CGContextRef ctx = [[NSGraphicsContext currentContext] graphicsPort]; + NSRect rect = [self bounds]; + NSColor *color = [textView defaultBackgroundColor]; + CGContextSetBlendMode(ctx, kCGBlendModeCopy); + CGContextSetRGBFillColor(ctx, + [color redComponent], + [color greenComponent], + [color blueComponent], + [color alphaComponent]); + CGContextFillRect(ctx, *(CGRect*)&rect); + CGContextSetBlendMode(ctx, kCGBlendModeNormal); + + isDirty = NO; + } + NSRect textViewFrame = [textView frame]; if (!NSEqualRects(lastTextViewFrame, textViewFrame)) { // If the text view's frame changes we copy the contents of the old @@ -627,6 +644,13 @@ enum { [self frameSizeMayHaveChanged]; } +- (void)markDirty +{ + // When the view is marked as dirty, the entire background will be cleared + // the next time the view is redrawn. + isDirty = YES; +} + @end // MMVimView diff --git a/src/MacVim/MMWindowController.m b/src/MacVim/MMWindowController.m index ad6e74df..2660e63e 100644 --- a/src/MacVim/MMWindowController.m +++ b/src/MacVim/MMWindowController.m @@ -270,6 +270,7 @@ // later). if (!setupDone) return; + [vimView markDirty]; [[MMAppController sharedInstance] windowControllerWillOpen:self]; [[self window] makeKeyAndOrderFront:self]; } -- 2.11.4.GIT