#pragma once #import #include "DYScopeMath.hpp" // The spider and the OSC both draw in top-down coordinates. Keep the // scopes below the editable mesh and clip the raster to the wheel. static inline void DYDrawSpiderScope(NSRect rect, NSData *raster, CGFloat scale) { if(NSIsEmptyRect(rect))return; [NSGraphicsContext saveGraphicsState]; [[NSBezierPath bezierPathWithOvalInRect:rect]addClip]; constexpr size_t side=dyscope::SpiderBins; if(raster.length==side*side*4){ CGDataProviderRef provider=CGDataProviderCreateWithCFData((CFDataRef)raster); CGColorSpaceRef space=CGColorSpaceCreateDeviceRGB(); CGImageRef image=CGImageCreate(side,side,8,32,side*4,space,kCGImageAlphaPremultipliedLast, provider,nullptr,false,kCGRenderingIntentDefault); if(image){ NSImage *trace=[[[NSImage alloc]initWithCGImage:image size:NSZeroSize]autorelease]; [trace drawInRect:rect fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1 respectFlipped:YES hints:@{NSImageHintInterpolation:@(NSImageInterpolationLow)}]; CGImageRelease(image); } CGColorSpaceRelease(space);CGDataProviderRelease(provider); } NSPoint center=NSMakePoint(NSMidX(rect),NSMidY(rect)); CGFloat radius=NSWidth(rect)*.5; CGFloat dx=cos(dyscope::SpiderSkinAngle),dy=sin(dyscope::SpiderSkinAngle); NSBezierPath *line=[NSBezierPath bezierPath]; [line moveToPoint:NSMakePoint(center.x+dx*radius*.08,center.y+dy*radius*.08)]; [line lineToPoint:NSMakePoint(center.x+dx*radius*.91,center.y+dy*radius*.91)]; CGFloat dashes[]={4*scale,3*scale}; [line setLineDash:dashes count:2 phase:0]; line.lineWidth=2.6*scale; [[NSColor colorWithWhite:0 alpha:.85]setStroke];[line stroke]; line.lineWidth=1.2*scale; [[NSColor colorWithSRGBRed:1 green:.79 blue:.57 alpha:1]setStroke];[line stroke]; if(radius>=36*scale){ NSDictionary *attrs=@{NSFontAttributeName:[NSFont systemFontOfSize:9*scale weight:NSFontWeightMedium], NSForegroundColorAttributeName:[NSColor colorWithSRGBRed:1 green:.88 blue:.74 alpha:1]}; NSString *label=@"肤色";NSSize size=[label sizeWithAttributes:attrs]; NSPoint anchor=NSMakePoint(center.x+dx*radius*.73-size.width/2,center.y+dy*radius*.73+4*scale); NSRect tag=NSInsetRect(NSMakeRect(anchor.x,anchor.y,size.width,size.height),-3*scale,-1*scale); [[NSColor colorWithWhite:.08 alpha:.92]setFill]; [[NSBezierPath bezierPathWithRoundedRect:tag xRadius:3*scale yRadius:3*scale]fill]; [label drawAtPoint:anchor withAttributes:attrs]; } [NSGraphicsContext restoreGraphicsState]; }