mirror of
https://github.com/darlinghq/darling-cocotron.git
synced 2025-02-25 14:31:58 +00:00
Add a Quartz Debug style redraw debugging feature
This commit is contained in:
parent
3f0f39beef
commit
32a2fa2f81
@ -70,3 +70,14 @@ typedef enum {
|
||||
|
||||
@end
|
||||
|
||||
@interface NSGraphicsContext (QuartzDebugging)
|
||||
|
||||
+ (void)setQuartzDebuggingEnabled:(BOOL)enabled;
|
||||
|
||||
+ (BOOL)quartzDebuggingIsEnabled;
|
||||
|
||||
+ (BOOL)inQuartzDebugMode;
|
||||
|
||||
+ (void)setQuartzDebugMode:(BOOL)mode;
|
||||
|
||||
@end
|
||||
|
@ -17,6 +17,22 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
||||
|
||||
@implementation NSGraphicsContext
|
||||
|
||||
+ (void)initialize
|
||||
{
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
||||
|
||||
BOOL enabled = [defaults boolForKey: @"NSQuartzDebugEnabled"];
|
||||
|
||||
if (enabled) {
|
||||
NSLog(@"enabling Quartz Debugging emulation");
|
||||
}
|
||||
|
||||
[NSGraphicsContext setQuartzDebuggingEnabled: enabled];
|
||||
|
||||
[pool drain];
|
||||
}
|
||||
|
||||
-initWithWindow:(NSWindow *)window {
|
||||
_graphicsPort=CGContextRetain([window cgContext]);
|
||||
_focusStack=[NSMutableArray new];
|
||||
@ -237,4 +253,29 @@ NSMutableArray *NSCurrentFocusStack() {
|
||||
|
||||
@end
|
||||
|
||||
static BOOL sQuartzDebuggingEnabled = NO;
|
||||
static BOOL sQuartzDebugging = NO;
|
||||
|
||||
@implementation NSGraphicsContext (QuartzDebugging)
|
||||
|
||||
+ (void)setQuartzDebuggingEnabled:(BOOL)enabled
|
||||
{
|
||||
sQuartzDebuggingEnabled = enabled;
|
||||
}
|
||||
|
||||
+ (BOOL)quartzDebuggingIsEnabled
|
||||
{
|
||||
return sQuartzDebuggingEnabled;
|
||||
}
|
||||
|
||||
+ (BOOL)inQuartzDebugMode
|
||||
{
|
||||
return sQuartzDebuggingEnabled && sQuartzDebugging;
|
||||
}
|
||||
|
||||
+ (void)setQuartzDebugMode:(BOOL)mode
|
||||
{
|
||||
sQuartzDebugging = mode;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1642,6 +1642,9 @@ static void clearInvalidRects(NSView *self){
|
||||
}
|
||||
|
||||
static void clearNeedsDisplay(NSView *self){
|
||||
if ([NSGraphicsContext inQuartzDebugMode]) {
|
||||
return;
|
||||
}
|
||||
clearInvalidRects(self);
|
||||
self->_needsDisplay=NO;
|
||||
}
|
||||
@ -1873,8 +1876,13 @@ static NSGraphicsContext *graphicsContextForView(NSView *view){
|
||||
NSRect visibleRect=[self visibleRect];
|
||||
|
||||
rect=NSIntersectionRect(rect,visibleRect);
|
||||
removeRectFromInvalidInVisibleRect(self,rect,visibleRect);
|
||||
|
||||
if ([NSGraphicsContext inQuartzDebugMode]) {
|
||||
// Don't do anything to interfere with what will be drawn in non-debug mode
|
||||
} else {
|
||||
removeRectFromInvalidInVisibleRect(self,rect,visibleRect);
|
||||
}
|
||||
|
||||
if(NSIsEmptyRect(rect))
|
||||
return;
|
||||
|
||||
@ -1888,7 +1896,12 @@ static NSGraphicsContext *graphicsContextForView(NSView *view){
|
||||
|
||||
CGContextClipToRect(graphicsPort,rect);
|
||||
|
||||
[self drawRect:rect];
|
||||
if ([NSGraphicsContext inQuartzDebugMode]) {
|
||||
[[NSColor yellowColor] set];
|
||||
NSRectFill(rect);
|
||||
} else {
|
||||
[self drawRect:rect];
|
||||
}
|
||||
[self unlockFocus];
|
||||
|
||||
NSInteger i,count=[_subviews count];
|
||||
|
@ -1684,6 +1684,18 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
|
||||
if([self isVisible] && ![self isMiniaturized] && [self viewsNeedDisplay]){
|
||||
NSAutoreleasePool *pool=[NSAutoreleasePool new];
|
||||
|
||||
if ([NSGraphicsContext quartzDebuggingIsEnabled] == YES) {
|
||||
|
||||
// Show all the views getting redrawn
|
||||
[NSGraphicsContext setQuartzDebugMode: YES];
|
||||
[self disableFlushWindow];
|
||||
[_backgroundView displayIfNeeded];
|
||||
[self enableFlushWindow];
|
||||
[self flushWindowIfNeeded];
|
||||
}
|
||||
|
||||
[NSGraphicsContext setQuartzDebugMode: NO];
|
||||
|
||||
[self disableFlushWindow];
|
||||
[_backgroundView displayIfNeeded];
|
||||
[self enableFlushWindow];
|
||||
@ -1698,7 +1710,20 @@ NSString * const NSWindowDidAnimateNotification=@"NSWindowDidAnimateNotification
|
||||
*/
|
||||
if([self isVisible]){
|
||||
NSAutoreleasePool *pool=[NSAutoreleasePool new];
|
||||
[self disableFlushWindow];
|
||||
|
||||
if ([NSGraphicsContext quartzDebuggingIsEnabled] == YES) {
|
||||
|
||||
// Show all the views getting redrawn
|
||||
[NSGraphicsContext setQuartzDebugMode: YES];
|
||||
[self disableFlushWindow];
|
||||
[_backgroundView display];
|
||||
[self enableFlushWindow];
|
||||
[self flushWindowIfNeeded];
|
||||
}
|
||||
|
||||
[NSGraphicsContext setQuartzDebugMode: NO];
|
||||
|
||||
[self disableFlushWindow];
|
||||
[_backgroundView display];
|
||||
[self enableFlushWindow];
|
||||
[self flushWindowIfNeeded];
|
||||
|
Loading…
x
Reference in New Issue
Block a user