Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make views draw their background color into their context so that we …

…get subpixel AA, little bit a refactoring
  • Loading branch information...
commit fa446bbfc4e712c2db408d0e88768d4634b106ed 1 parent 27f3a75
@joshaber authored
Showing with 11 additions and 17 deletions.
  1. +1 −1  Classes/MAUIKit/MAUIView.h
  2. +10 −16 Classes/MAUIKit/MAUIView.m
View
2  Classes/MAUIKit/MAUIView.h
@@ -41,7 +41,7 @@ typedef enum {
- (void)setNeedsDisplay;
- (void)layoutSubviews;
-- (void)drawRect:(CGRect)rect;
+- (void)drawRect:(CGRect)dirtyRect;
- (CGPoint)convertPoint:(CGPoint)point fromView:(MAUIView *)view;
- (CGPoint)convertPoint:(CGPoint)point toView:(MAUIView *)view;
View
26 Classes/MAUIKit/MAUIView.m
@@ -7,13 +7,12 @@
//
#import "MAUIView.h"
-#import "NSColor+MAUIKitExtensions.h"
static NSMutableArray *animationStack = nil;
@interface MAUIView ()
@property (nonatomic, retain) CALayer *layer;
-@property (nonatomic, assign) BOOL manuallyDraw;
+@property (nonatomic, assign) BOOL manuallyDrawingIntoSuperview;
@end
@@ -27,7 +26,8 @@ - (void)layoutSublayersOfLayer:(CALayer *)inLayer {
}
- (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context {
- if(self.layer.hidden && !self.manuallyDraw) return;
+ // If a superview is flattening its subviews then those subviews are actually hidden. But we still want to draw if we're compositing the view into its superview.
+ if(self.layer.hidden && !self.manuallyDrawingIntoSuperview) return;
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:YES]];
@@ -48,9 +48,9 @@ - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context {
}
subview.layer.hidden = YES;
- subview.manuallyDraw = YES;
+ subview.manuallyDrawingIntoSuperview = YES;
[subview.layer drawInContext:cgContext];
- subview.manuallyDraw = NO;
+ subview.manuallyDrawingIntoSuperview = NO;
[NSGraphicsContext restoreGraphicsState];
}
@@ -74,8 +74,9 @@ - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)context {
@synthesize subviews;
@synthesize superview;
@synthesize flattenSubviews;
-@synthesize manuallyDraw;
+@synthesize manuallyDrawingIntoSuperview;
@synthesize userInteractionEnabled;
+@synthesize backgroundColor;
+ (void)initialize {
if(self == [MAUIView class]) {
@@ -157,16 +158,9 @@ - (void)layoutSubviews {
}
-- (void)drawRect:(CGRect)rect {
-
-}
-
-- (NSColor *)backgroundColor {
- return [NSColor colorWithCGColor:self.layer.backgroundColor];
-}
-
-- (void)setBackgroundColor:(NSColor *)newColor {
- self.layer.backgroundColor = newColor.CGColor;
+- (void)drawRect:(CGRect)dirtyRect {
+ [self.backgroundColor set];
+ NSRectFillUsingOperation(dirtyRect, NSCompositeSourceOver);
}
- (CGFloat)alpha {
Please sign in to comment.
Something went wrong with that request. Please try again.