feat: wire canvas HSL and spider editors, face support and lens repair (validation pending)
这个提交包含在:
1 父节点
e2aa0bd9a1
当前提交
a3bd2ceb26
19 个文件已更改
+245
-43
没有与搜索条件相匹配的文件
@@ -1,4 +1,14 @@
|
||||
// Methods of DYViewerParameterPanel. Geometry is shared by drawing and input.
|
||||
- (BOOL)graphicKind:(NSString*)kind{return [@[@"curvePlot",@"wheel",@"hslPlot",@"spiderPlot"]containsObject:kind];}
|
||||
- (NSData*)spiderData {if(_spiderDraft)return _spiderDraft;return [_nodeID hasPrefix:@"base:"]?_snapshot[@"spider"]:[self node][@"layer"][@"spider"];}
|
||||
- (void)beginSpiderData {[_bridge beginSpider:[self spiderData] node:_nodeID enabled:[self graphicValue:@"spiderEnabled"] atTime:_time];}
|
||||
- (void)spiderAction:(NSInteger)action {
|
||||
auto mesh=DYSpiderMesh([self spiderData]);if(action==0){mesh=dy::neutralMesh(mesh.hues,mesh.rings+1);}
|
||||
else if(action==3||action==4){int count=action==3?mesh.hues:mesh.rings+1;int next=count<12?12:count<24?24:6;mesh=dy::resampleMesh(mesh,action==3?next:mesh.hues,action==4?next:mesh.rings+1);_selectedSpider=-1;}
|
||||
else if(_selectedSpider>=0&&_selectedSpider<dy::meshCount(mesh)){if(action==1)mesh.pins[_selectedSpider]=dy::meshBoundary(mesh,(int)_selectedSpider)||!mesh.pins[_selectedSpider];else {auto neutral=dy::neutralMesh(mesh.hues,mesh.rings+1);mesh.x[_selectedSpider]=neutral.x[_selectedSpider];mesh.y[_selectedSpider]=neutral.y[_selectedSpider];}}
|
||||
else return;
|
||||
[self beginSpiderData];[_bridge changeSpider:[NSData dataWithBytes:&mesh length:sizeof(mesh)]];[_bridge endGesture];
|
||||
}
|
||||
- (double)graphicValue:(NSString*)key{return [self valueForDescriptor:[self descriptorForKey:key]];}
|
||||
- (NSArray*)curveSlots{
|
||||
NSMutableArray*slots=[NSMutableArray array];NSInteger n=_channel==0?4:2;
|
||||
@@ -11,7 +21,14 @@
|
||||
}
|
||||
- (void)layoutGraphicAt:(CGFloat)y{
|
||||
if(!_snapshot||![self node]||_panel.size.width<180*_scale||_panel.size.height<180*_scale)return;CGFloat s=_scale,x=_panel.origin.x,w=_panel.size.width;
|
||||
if([_toolType isEqual:@"curve"]){
|
||||
if([_toolType isEqual:@"hsl"]){
|
||||
for(NSInteger axis=0;axis<3;axis++)[self addArea:NSMakeRect(x+12*s+axis*(w-24*s)/3,y,(w-30*s)/3,23*s)part:22210+axis kind:@"hslAxis" title:@[@"色相",@"饱和度",@"明亮度"][axis]descriptor:nil index:axis];
|
||||
[self addArea:NSMakeRect(x+18*s,y+34*s,w-36*s,MAX(40*s,NSMaxY(_panel)-y-85*s))part:22200 kind:@"hslPlot" title:@"" descriptor:nil index:0];
|
||||
}else if([_toolType isEqual:@"spider"]){
|
||||
CGFloat d=MAX(30*s,MIN(w-36*s,NSMaxY(_panel)-y-67*s));[self addArea:NSMakeRect(x+(w-d)/2,y,d,d)part:22300 kind:@"spiderPlot" title:@"" descriptor:nil index:0];
|
||||
auto mesh=DYSpiderMesh([self spiderData]);NSArray *titles=@[@"全盘还原",@"固定点",@"还原点",[NSString stringWithFormat:@"色相 %d",mesh.hues],[NSString stringWithFormat:@"环数 %d",mesh.rings+1]];
|
||||
for(NSInteger i=0;i<5;i++)[self addArea:NSMakeRect(x+8*s+i*(w-16*s)/5,NSMaxY(_panel)-53*s,(w-20*s)/5,23*s)part:22310+i kind:@"spiderAction" title:titles[i] descriptor:nil index:i];
|
||||
}else if([_toolType isEqual:@"curve"]){
|
||||
for(NSInteger c=0;c<4;c++)[self addArea:NSMakeRect(x+12*s+c*(w-24*s)/4,y,(w-30*s)/4,23*s)part:22010+c kind:@"channel" title:@[@"RGB",@"红",@"绿",@"蓝"][c] descriptor:nil index:c];
|
||||
NSRect graph=NSMakeRect(x+18*s,y+31*s,w-36*s,MAX(45*s,NSMaxY(_panel)-y-84*s));[self addArea:graph part:22000 kind:@"curvePlot" title:@"" descriptor:nil index:0];
|
||||
if(_selectedX)[self addArea:NSMakeRect(x+12*s,NSMaxY(_panel)-47*s,90*s,20*s)part:22020 kind:@"deletePoint" title:@"删除选中点" descriptor:nil index:0];
|
||||
@@ -23,6 +40,23 @@
|
||||
- (NSPoint)curvePosition:(NSDictionary*)p rect:(NSRect)r{return NSMakePoint(r.origin.x+[p[@"x"]doubleValue]*r.size.width,r.origin.y+(1-[p[@"y"]doubleValue])*r.size.height);}
|
||||
- (void)drawGraphic:(NSDictionary*)area{
|
||||
CGFloat s=_scale;NSRect r=[area[@"rect"]rectValue];NSColor*ink=DYThemeColor(@"text"),*accent=DYThemeColor(@"accent");
|
||||
if([area[@"kind"]isEqual:@"hslPlot"]){
|
||||
[NSGraphicsContext saveGraphicsState];NSRectClip(r);[[ink colorWithAlphaComponent:.18]setStroke];NSBezierPath *mid=[NSBezierPath bezierPath];[mid moveToPoint:NSMakePoint(NSMinX(r),NSMidY(r))];[mid lineToPoint:NSMakePoint(NSMaxX(r),NSMidY(r))];[mid stroke];
|
||||
NSBezierPath *curve=[NSBezierPath bezierPath];curve.lineWidth=1.5*s;
|
||||
for(int i=0;i<8;i++){double v=[self graphicValue:[NSString stringWithFormat:@"hsl%ld_%d",(long)_hslAxis,i]];CGFloat xx=NSMinX(r)+(i+.5)*r.size.width/8,yy=NSMidY(r)-v/200*r.size.height;NSPoint point=NSMakePoint(xx,yy);if(i==0)[curve moveToPoint:point];else[curve lineToPoint:point];}
|
||||
[accent setStroke];[curve stroke];
|
||||
for(int i=0;i<8;i++){double v=[self graphicValue:[NSString stringWithFormat:@"hsl%ld_%d",(long)_hslAxis,i]];CGFloat xx=NSMinX(r)+(i+.5)*r.size.width/8,yy=NSMidY(r)-v/200*r.size.height;NSColor *c=[NSColor colorWithHue:i/8. saturation:.7 brightness:.95 alpha:.9];[c setFill];[[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(xx-5*s,yy-5*s,10*s,10*s)]fill];[self text:[NSString stringWithFormat:@"%.0f",v]rect:NSMakeRect(xx-15*s,MIN(NSMaxY(r)-15*s,yy+7*s),30*s,15*s)size:8 color:ink alignment:NSTextAlignmentCenter];}
|
||||
[NSGraphicsContext restoreGraphicsState];[self text:@"红 橙 黄 绿 青 蓝 紫 洋红" rect:NSMakeRect(r.origin.x,NSMaxY(r)+3*s,r.size.width,15*s)size:9 color:ink alignment:NSTextAlignmentCenter];return;
|
||||
}
|
||||
if([area[@"kind"]isEqual:@"spiderPlot"]){
|
||||
auto mesh=DYSpiderMesh([self spiderData]);CGFloat rad=r.size.width/2;NSPoint center=NSMakePoint(NSMidX(r),NSMidY(r));
|
||||
for(int i=0;i<64;i++){double a=i*2*M_PI/64,b=(i+1)*2*M_PI/64;NSBezierPath *wedge=[NSBezierPath bezierPath];[wedge moveToPoint:center];[wedge lineToPoint:NSMakePoint(center.x+cos(a)*rad,center.y+sin(a)*rad)];[wedge lineToPoint:NSMakePoint(center.x+cos(b)*rad,center.y+sin(b)*rad)];[wedge closePath];[[NSColor colorWithHue:i/64. saturation:.8 brightness:.8 alpha:.24]setFill];[wedge fill];}
|
||||
auto point=[&](int i){return NSMakePoint(r.origin.x+mesh.x[i]*r.size.width,r.origin.y+mesh.y[i]*r.size.height);};NSBezierPath *net=[NSBezierPath bezierPath];net.lineWidth=.6*s;
|
||||
for(int ring=1;ring<=mesh.rings;ring++)for(int hue=0;hue<=mesh.hues;hue++){NSPoint q=point(dy::meshIndex(mesh,hue%mesh.hues,ring));if(hue==0)[net moveToPoint:q];else[net lineToPoint:q];}
|
||||
for(int hue=0;hue<mesh.hues;hue++){[net moveToPoint:point(dy::meshCount(mesh)-1)];for(int ring=1;ring<=mesh.rings;ring++)[net lineToPoint:point(dy::meshIndex(mesh,hue,ring))];}
|
||||
[[ink colorWithAlphaComponent:.5]setStroke];[net stroke];
|
||||
for(int i=0;i<dy::meshCount(mesh);i++){NSPoint q=point(i);CGFloat rr=(i==_selectedSpider?4:2)*s;[(i==_selectedSpider?accent:ink)setFill];[[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(q.x-rr,q.y-rr,2*rr,2*rr)]fill];if(mesh.pins[i]){[NSColor.blackColor setFill];NSRectFill(NSMakeRect(q.x-s,q.y-s,2*s,2*s));}}return;
|
||||
}
|
||||
if([area[@"kind"]isEqual:@"wheel"]){
|
||||
NSInteger index=[area[@"index"]integerValue];[self text:area[@"title"]rect:NSMakeRect(r.origin.x,r.origin.y-19*s,r.size.width,17*s)size:10 color:ink alignment:NSTextAlignmentCenter];
|
||||
// Cached raster is generated from the same HSV convention as the renderer controls.
|
||||
@@ -34,7 +68,9 @@
|
||||
NSPoint p=NSMakePoint(NSMidX(r)+cos(angle)*rad,NSMidY(r)-sin(angle)*rad);[NSColor.blackColor setStroke];NSBezierPath*knob=[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(p.x-5*s,p.y-5*s,10*s,10*s)];knob.lineWidth=3*s;[knob stroke];[NSColor.whiteColor setStroke];knob.lineWidth=1.4*s;[knob stroke];
|
||||
return;
|
||||
}
|
||||
DYDrawSoftControl(r,4*s,YES,NO,NO);[NSGraphicsContext saveGraphicsState];NSRectClip(r);
|
||||
[[ink colorWithAlphaComponent:.06]setFill];[[NSBezierPath bezierPathWithRect:r]fill];[NSGraphicsContext saveGraphicsState];NSRectClip(r);
|
||||
NSData *rawHistogram=_snapshot[@"histogram"];const DYHistogram *hist=rawHistogram.length==sizeof(DYHistogram)?(const DYHistogram*)rawHistogram.bytes:nullptr;
|
||||
if(hist&&hist->samples){uint32_t peak=1;for(int c=0;c<4;c++)if(_channel==0||c==_channel)for(int b=0;b<256;b++)peak=MAX(peak,hist->bins[c][b]);NSArray *colors=@[ink,NSColor.systemRedColor,NSColor.systemGreenColor,NSColor.systemBlueColor];for(int c=3;c>=0;c--){if(_channel&&c!=_channel)continue;NSBezierPath *area=[NSBezierPath bezierPath];[area moveToPoint:NSMakePoint(NSMinX(r),NSMaxY(r))];for(int b=0;b<256;b++)[area lineToPoint:NSMakePoint(NSMinX(r)+b/255.*r.size.width,NSMaxY(r)-sqrt(hist->bins[c][b]/double(peak))*r.size.height*.86)];[area lineToPoint:NSMakePoint(NSMaxX(r),NSMaxY(r))];[area closePath];[[colors[c]colorWithAlphaComponent:c==0?.08:.2]setFill];[area fill];}}
|
||||
[[ink colorWithAlphaComponent:.16]setStroke];NSBezierPath*grid=[NSBezierPath bezierPath];grid.lineWidth=.5*s;
|
||||
for(int i=0;i<5;i++){CGFloat x=r.origin.x+r.size.width*i/4,y=r.origin.y+r.size.height*i/4;[grid moveToPoint:NSMakePoint(x,NSMinY(r))];[grid lineToPoint:NSMakePoint(x,NSMaxY(r))];[grid moveToPoint:NSMakePoint(NSMinX(r),y)];[grid lineToPoint:NSMakePoint(NSMaxX(r),y)];}[grid stroke];
|
||||
[[ink colorWithAlphaComponent:.2]setStroke];NSBezierPath*diagonal=[NSBezierPath bezierPath];[diagonal moveToPoint:NSMakePoint(NSMinX(r),NSMaxY(r))];[diagonal lineToPoint:NSMakePoint(NSMaxX(r),NSMinY(r))];[diagonal stroke];
|
||||
@@ -51,6 +87,8 @@
|
||||
}
|
||||
- (void)beginGraphicAt:(NSPoint)p{
|
||||
if(!_snapshot||![self node])return;NSMutableDictionary*c=[[_captured mutableCopy]autorelease];NSRect r=[c[@"rect"]rectValue];NSString*xKey=nil,*yKey=nil;
|
||||
if([c[@"kind"]isEqual:@"spiderPlot"]){auto mesh=DYSpiderMesh([self spiderData]);double best=12*_scale;NSInteger chosen=-1;for(int i=0;i<dy::meshCount(mesh);i++){double distance=hypot(p.x-(r.origin.x+mesh.x[i]*r.size.width),p.y-(r.origin.y+mesh.y[i]*r.size.height));if(distance<best){best=distance;chosen=i;}}if(chosen<0)return;_selectedSpider=chosen;c[@"meshStart"]=[NSData dataWithBytes:&mesh length:sizeof(mesh)];[_captured release];_captured=[c copy];[self beginSpiderData];return;}
|
||||
if([c[@"kind"]isEqual:@"hslPlot"]){NSInteger color=MAX(0,MIN(7,(NSInteger)((p.x-r.origin.x)/r.size.width*8)));NSString *key=[NSString stringWithFormat:@"hsl%ld_%ld",(long)_hslAxis,(long)color];c[@"hslKey"]=key;[_captured release];_captured=[c copy];[_bridge beginParameter:[self descriptorForKey:key]node:_nodeID value:[self graphicValue:key]atTime:_time];return;}
|
||||
if([c[@"kind"]isEqual:@"curvePlot"]){NSDictionary*nearest=nil;double distance=12*_scale;for(NSDictionary*point in [self curvePoints]){NSPoint q=[self curvePosition:point rect:r];double d=hypot(q.x-p.x,q.y-p.y);if(d<distance){distance=d;nearest=point;}}
|
||||
if(!nearest)for(NSDictionary*slot in [self curveSlots])if([self graphicValue:slot[@"xKey"]]<0){nearest=slot;break;}
|
||||
if(!nearest)return;xKey=nearest[@"xKey"];yKey=nearest[@"yKey"];[_selectedX release];_selectedX=[xKey copy];c[@"newPoint"]=@([self graphicValue:xKey]<0);
|
||||
@@ -60,6 +98,8 @@
|
||||
if([c[@"newPoint"]boolValue]||[c[@"kind"]isEqual:@"wheel"])[self updateGraphicAt:p];
|
||||
}
|
||||
- (void)updateGraphicAt:(NSPoint)p{
|
||||
if([_captured[@"kind"]isEqual:@"spiderPlot"]){NSData *start=_captured[@"meshStart"];if(!start||_selectedSpider<0)return;NSRect r=[_captured[@"rect"]rectValue];auto mesh=DYSpiderMesh(start);std::bitset<dy::SpiderMeshCapacity> selected;selected[_selectedSpider]=true;auto moved=dy::moveMesh(mesh,selected,(p.x-_down.x)/r.size.width,(p.y-_down.y)/r.size.height);[_spiderDraft release];_spiderDraft=[[NSData alloc]initWithBytes:&moved length:sizeof(moved)];[_bridge changeSpider:_spiderDraft];return;}
|
||||
if([_captured[@"kind"]isEqual:@"hslPlot"]){NSString *key=_captured[@"hslKey"];if(!key)return;NSRect r=[_captured[@"rect"]rectValue];double v=MAX(-100.,MIN(100.,(NSMidY(r)-p.y)/r.size.height*200));_draftValues[key]=@(v);[_bridge changeValue:v];return;}
|
||||
NSString*xKey=_captured[@"xKey"],*yKey=_captured[@"yKey"];if(!xKey||!yKey)return;NSRect r=[_captured[@"rect"]rectValue];double x,y;
|
||||
if([_captured[@"kind"]isEqual:@"curvePlot"]){x=MAX(.001,MIN(.999,(p.x-r.origin.x)/MAX(1.,r.size.width)));double output=MAX(0.,MIN(1.,1-(p.y-r.origin.y)/MAX(1.,r.size.height)));
|
||||
for(NSDictionary*point in [self curvePoints])if(![point[@"xKey"]isEqual:xKey]){double other=[point[@"x"]doubleValue];if(fabs(x-other)<.001)x=x<other?other-.001:other+.001;}x=MAX(.001,MIN(.999,x));y=(output-x)*100;
|
||||
|
||||
在新工单中引用
屏蔽一个用户