改用原生画布HSL吸管与当前帧显示取样,准备139宿主验收
这个提交包含在:
1 父节点
2d7feb5aa2
当前提交
e6fecdad7b
11 个文件已更改
+65
-20
没有与搜索条件相匹配的文件
+17
-7
@@ -5,6 +5,7 @@
|
||||
@implementation DYToolOSC {
|
||||
id<MTLDevice> _device;id<MTLCommandQueue> _queue;CIContext *_context;
|
||||
DYViewerControls *_viewerControls;CGFloat _height,_canvasWidth,_uiScale;BOOL _maskCapturing;DYPlugIn *_maskCaptureOwner;NSRect _imageRect;NSDictionary *_mask;NSMutableArray *_handles;NSBezierPath *_outline;NSInteger _lastRoute;NSUInteger _drawCount,_hitDiagnostics,_eventDiagnostics;
|
||||
BOOL _hslSampling;
|
||||
BOOL _stampHasSource,_stampDragging,_stampSaving,_stampNeedsRedraw;
|
||||
NSPoint _stampSource,_stampStart,_stampEnd;
|
||||
NSString *_stampFailure,*_levelFailure;
|
||||
@@ -58,7 +59,7 @@
|
||||
@synchronized(self){
|
||||
self->_levelSaving=NO;
|
||||
if(self->_viewerControls.bridge!=bridge)return;
|
||||
[self updateLevelFrom:plugin];[self restoreLevelReference];
|
||||
[self updateLevelFrom:plugin];_hslSampling=[plugin canvasHSLSampling];[self restoreLevelReference];
|
||||
self->_levelFailure=[failure copy];
|
||||
}
|
||||
}];
|
||||
@@ -213,10 +214,11 @@
|
||||
id<FxOnScreenControlAPI_v4>api=[_apiManager apiForProtocol:@protocol(FxOnScreenControlAPI_v4)];double lx=0,ly=0,ux=0,uy=0;[api convertPointFromSpace:kFxDrawingCoordinates_OBJECT fromX:0 fromY:0 toSpace:kFxDrawingCoordinates_CANVAS toX:&lx toY:&ly];[api convertPointFromSpace:kFxDrawingCoordinates_OBJECT fromX:1 fromY:1 toSpace:kFxDrawingCoordinates_CANVAS toX:&ux toY:&uy];_imageRect=NSMakeRect(lx,_height-uy,ux-lx,uy-ly);_uiScale=[api respondsToSelector:@selector(backingScaleFactor)]?MAX(1.,MIN(3.,[api backingScaleFactor])):1.;
|
||||
DYPlugIn *plugin=[self pluginAtTime:time];NSDictionary *mask=[plugin toolCanvasMaskAtTime:time];NSInteger route=(plugin?1:0)+(mask?2:0);if(route!=_lastRoute||_drawCount++<2){_lastRoute=route;os_log(OS_LOG_DEFAULT,"dayu_tool_osc_route plugin=%{public}d mask=%{public}d width=%{public}.2f height=%{public}.2f",plugin!=nil,mask!=nil,_imageRect.size.width,_imageRect.size.height);}[_mask release];_mask=[mask copy];[_handles removeAllObjects];[_outline release];_outline=nil;
|
||||
[_viewerControls setBridge:[plugin viewerParameterBridge]];[_viewerControls setViewport:_imageRect];[_viewerControls prepareWithSize:NSMakeSize(canvasWidth,_height) scale:_uiScale atTime:time];
|
||||
[self updateLevelFrom:plugin];
|
||||
[self updateLevelFrom:plugin];_hslSampling=[plugin canvasHSLSampling];
|
||||
if(_levelMode)mask=nil;
|
||||
if(plugin&&canvasWidth>0&&_height>0&&canvasWidth<16384&&_height<16384&&_imageRect.size.width>0&&_imageRect.size.height>0){
|
||||
NSRect region=mask||_viewerControls.stampArmed||_levelMode?NSMakeRect(0,0,canvasWidth,_height):NSIntegralRect([_viewerControls drawingBounds]);
|
||||
if(_hslSampling)region=NSIntegralRect(NSUnionRect(region,[self hslPickerRect]));
|
||||
if(NSIsEmptyRect(region)){[commands commit];[commands waitUntilCompleted];return;}
|
||||
NSBitmapImageRep *bitmap=[[[NSBitmapImageRep alloc]initWithBitmapDataPlanes:NULL pixelsWide:(NSInteger)NSWidth(region) pixelsHigh:(NSInteger)NSHeight(region) bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace bytesPerRow:(NSInteger)NSWidth(region)*4 bitsPerPixel:32]autorelease];
|
||||
if(!bitmap){[commands commit];[commands waitUntilCompleted];return;}
|
||||
@@ -241,13 +243,16 @@
|
||||
for(NSInteger item=9;item<=10;item++){NSString *title=item==9?@"✓ 完成":@"取消";NSRect cell=[self toolbarRectForItem:item];CGFloat size=cell.size.height*.48;[title drawInRect:NSInsetRect(cell,0,MAX(0.,(cell.size.height-size-3)/2))withAttributes:@{NSFontAttributeName:[NSFont systemFontOfSize:size weight:NSFontWeightMedium],NSForegroundColorAttributeName:NSColor.whiteColor,NSShadowAttributeName:shadow,NSParagraphStyleAttributeName:style}];}
|
||||
}
|
||||
}if(_levelMode)[self drawLevelControls];else [self drawStampControls];[_viewerControls draw];
|
||||
if(_hslSampling){NSRect prompt=[self hslPickerRect];DYDrawSoftControl(prompt,4,NO,NO,NO);[@"HSL 吸管:点击画面取色 · Esc 取消" drawInRect:NSInsetRect(prompt,7*_uiScale,5*_uiScale) withAttributes:@{NSForegroundColorAttributeName:NSColor.whiteColor,NSFontAttributeName:[NSFont systemFontOfSize:11*_uiScale]}];}
|
||||
[NSGraphicsContext restoreGraphicsState];CIImage *overlay=[CIImage imageWithCGImage:bitmap.CGImage options:@{kCIImageColorSpace:NSNull.null}];overlay=[overlay imageByApplyingTransform:CGAffineTransformMakeTranslation(NSMinX(region),texture.height-NSMaxY(region))];[_context render:overlay toMTLTexture:texture commandBuffer:commands bounds:CGRectMake(0,0,texture.width,texture.height) colorSpace:nil];
|
||||
}[commands commit];[commands waitUntilCompleted];
|
||||
}}}
|
||||
- (NSRect)hslPickerRect {return NSMakeRect(NSMinX(_imageRect)+12*_uiScale,MAX(NSMinY(_imageRect)+4*_uiScale,NSMaxY(_imageRect)-100*_uiScale),MIN(370*_uiScale,MAX(1.,NSWidth(_imageRect)-24*_uiScale)),28*_uiScale);}
|
||||
- (NSInteger)partAtPoint:(NSPoint)point {
|
||||
BOOL drawing=[_mask[@"drawing"]boolValue];
|
||||
if(drawing&&!_levelMode)for(NSInteger i=9;i<=10;i++)if(NSPointInRect(point,[self toolbarRectForItem:i]))return 10000+i;
|
||||
NSInteger viewerHit=[_viewerControls partAtPoint:point];if(viewerHit)return viewerHit;
|
||||
if(_hslSampling)return NSPointInRect(point,_imageRect)?10030:0;
|
||||
if(_levelMode){
|
||||
if(_levelPlaced)for(NSInteger i=0;i<2;i++){NSPoint endpoint=[self canvasDisplayPoint:_level.toOutput(i?_levelLast:_levelFirst)];if(hypot(point.x-endpoint.x,point.y-endpoint.y)<=12*_uiScale)return 10016+i;}
|
||||
return NSPointInRect(point,_imageRect)?10015:0;
|
||||
@@ -269,11 +274,16 @@
|
||||
for(NSDictionary *h in _handles){NSPoint q=[h[@"point"]pointValue];if(hypot(q.x-point.x,q.y-point.y)<=9*_uiScale)return [h[@"part"]integerValue];}
|
||||
if(p.kind==DYMaskBezier||p.kind==DYMaskLinearGradient||[_outline containsPoint:point])return 1;return 0;
|
||||
}
|
||||
- (void)hitTestOSCAtMousePositionX:(double)x mousePositionY:(double)y activePart:(NSInteger*)part atTime:(CMTime)time{@synchronized(self){DYPlugIn*plugin=[self pluginAtTime:time];[_viewerControls setBridge:[plugin viewerParameterBridge]];[_viewerControls setViewport:_imageRect];[_viewerControls prepareWithSize:NSMakeSize(_canvasWidth,_height) scale:_uiScale atTime:time];NSDictionary *fresh=[plugin toolCanvasMaskAtTime:time];[_mask release];_mask=[fresh copy];[self updateLevelFrom:plugin];NSInteger hit=[self partAtPoint:NSMakePoint(x,_height-y)];if(part)*part=hit;if(_hitDiagnostics++<16)os_log(OS_LOG_DEFAULT,"dayu_tool_osc_hit x=%{public}.2f y=%{public}.2f height=%{public}.2f rect=%{public}.2f,%{public}.2f,%{public}.2f,%{public}.2f mask=%{public}d hit=%{public}ld",x,y,_height,_imageRect.origin.x,_imageRect.origin.y,_imageRect.size.width,_imageRect.size.height,_mask!=nil,(long)hit);}}
|
||||
- (void)hitTestOSCAtMousePositionX:(double)x mousePositionY:(double)y activePart:(NSInteger*)part atTime:(CMTime)time{@synchronized(self){DYPlugIn*plugin=[self pluginAtTime:time];[_viewerControls setBridge:[plugin viewerParameterBridge]];[_viewerControls setViewport:_imageRect];[_viewerControls prepareWithSize:NSMakeSize(_canvasWidth,_height) scale:_uiScale atTime:time];NSDictionary *fresh=[plugin toolCanvasMaskAtTime:time];[_mask release];_mask=[fresh copy];[self updateLevelFrom:plugin];_hslSampling=[plugin canvasHSLSampling];NSInteger hit=[self partAtPoint:NSMakePoint(x,_height-y)];if(part)*part=hit;if(_hitDiagnostics++<16)os_log(OS_LOG_DEFAULT,"dayu_tool_osc_hit x=%{public}.2f y=%{public}.2f height=%{public}.2f rect=%{public}.2f,%{public}.2f,%{public}.2f,%{public}.2f mask=%{public}d hit=%{public}ld",x,y,_height,_imageRect.origin.x,_imageRect.origin.y,_imageRect.size.width,_imageRect.size.height,_mask!=nil,(long)hit);}}
|
||||
- (BOOL)event:(NSEventType)type x:(double)x y:(double)y part:(NSInteger)part modifiers:(FxModifierKeys)modifiers key:(unichar)key time:(CMTime)time {@synchronized(self){
|
||||
DYPlugIn *plugin=[self pluginAtTime:time];if(_eventDiagnostics++<12)os_log(OS_LOG_DEFAULT,"dayu_tool_osc_event type=%{public}ld part=%{public}ld x=%{public}.2f y=%{public}.2f plugin=%{public}d",(long)type,(long)part,x,y,plugin!=nil);[_viewerControls setBridge:[plugin viewerParameterBridge]];[_viewerControls setViewport:_imageRect];[_viewerControls prepareWithSize:NSMakeSize(_canvasWidth,_height) scale:_uiScale atTime:time];NSPoint canvasPoint=NSMakePoint(x,_height-y);
|
||||
if(_maskCapturing&&plugin!=_maskCaptureOwner){_maskCapturing=NO;_maskCaptureOwner=nil;return NO;}
|
||||
[self updateLevelFrom:plugin];
|
||||
[self updateLevelFrom:plugin];_hslSampling=[plugin canvasHSLSampling];
|
||||
if(_hslSampling){
|
||||
if(type==NSEventTypeKeyDown&&key==27){[plugin finishCanvasHSLWithColor:nil];_hslSampling=NO;return YES;}
|
||||
if(type==NSEventTypeLeftMouseDown&&part==10030){[plugin selectCanvasHSLAtPoint:[self clampedDisplayUV:canvasPoint] atTime:time];_hslSampling=[plugin canvasHSLSampling];return YES;}
|
||||
if(type==NSEventTypeLeftMouseUp&&part==10030)return YES;
|
||||
}
|
||||
if(_stampSaving)return YES;
|
||||
if([self handleLevelEvent:type point:canvasPoint part:part key:key time:time plugin:plugin])return YES;
|
||||
if(!_viewerControls.stampArmed)[self clearStampCreation];
|
||||
@@ -325,7 +335,7 @@
|
||||
if(type==NSEventTypeKeyDown&&key==27&&[_viewerControls capturing])return [_viewerControls finishCapture];
|
||||
BOOL penAction=type==NSEventTypeLeftMouseDown&&(part==10009||part==10010);
|
||||
if(!ownedMask&&!penAction&&type!=NSEventTypeKeyDown&&[_viewerControls event:type point:canvasPoint atTime:time]){
|
||||
[self updateLevelFrom:plugin];
|
||||
[self updateLevelFrom:plugin];_hslSampling=[plugin canvasHSLSampling];
|
||||
if(_viewerControls.levelResetRequested){_viewerControls.levelResetRequested=NO;[self commitLevelState:@{} plugin:plugin];}
|
||||
else if(_viewerControls.levelMeasureRequested){_viewerControls.levelMeasureRequested=NO;NSMutableDictionary *state=[NSMutableDictionary dictionaryWithDictionary:_levelState?:@{}];state[@"levelMeasureOnly"]=@(![state[@"levelMeasureOnly"]boolValue]);[self commitLevelState:state plugin:plugin];}
|
||||
else if(_viewerControls.levelDirectionRequested){_viewerControls.levelDirectionRequested=NO;if(_levelPlaced)[self commitLevelReference:plugin];}
|
||||
@@ -342,10 +352,10 @@
|
||||
- (void)mouseUpAtPositionX:(double)x positionY:(double)y activePart:(NSInteger)part modifiers:(FxModifierKeys)m forceUpdate:(BOOL*)update atTime:(CMTime)t{BOOL result=[self event:NSEventTypeLeftMouseUp x:x y:y part:part modifiers:m key:0 time:t];if(update)*update=result;}
|
||||
- (void)keyDownAtPositionX:(double)x positionY:(double)y keyPressed:(unsigned short)key modifiers:(FxModifierKeys)m forceUpdate:(BOOL*)update didHandle:(BOOL*)handled atTime:(CMTime)t{BOOL result=(key==27||key==13||key==10||key==3||key==8||key==127)&&[self event:NSEventTypeKeyDown x:x y:y part:1 modifiers:m key:key time:t];if(update)*update=result;if(handled)*handled=result;}
|
||||
- (void)mouseMovedAtPositionX:(double)x positionY:(double)y activePart:(NSInteger)part modifiers:(FxModifierKeys)m forceUpdate:(BOOL*)update atTime:(CMTime)t{@synchronized(self){
|
||||
DYPlugIn*plugin=[self pluginAtTime:t];[_viewerControls setBridge:[plugin viewerParameterBridge]];[_viewerControls setViewport:_imageRect];[_viewerControls prepareWithSize:NSMakeSize(_canvasWidth,_height) scale:_uiScale atTime:t];[self updateLevelFrom:plugin];NSPoint point=NSMakePoint(x,_height-y);NSInteger viewerHit=[_viewerControls partAtPoint:point];BOOL redraw=[_viewerControls mouseMoved:point];NSDictionary *mask=[plugin toolCanvasMaskAtTime:t];BOOL drawing=[mask[@"drawing"]boolValue]||[mask[@"drawShape"]boolValue];NSCursor *cursor=[_viewerControls headerAtPoint:point]?([_viewerControls capturing]?NSCursor.closedHandCursor:NSCursor.openHandCursor):viewerHit?NSCursor.pointingHandCursor:(part==10014||part==10015)?NSCursor.crosshairCursor:part>=10000?NSCursor.pointingHandCursor:(drawing||part>=1000)?NSCursor.crosshairCursor:part?NSCursor.openHandCursor:NSCursor.arrowCursor;[[_apiManager apiForProtocol:@protocol(FxOnScreenControlAPI_v4)]setCursor:cursor];if(_levelMode&&_levelHasFirst&&!_levelDown&&!_levelSaving&&!viewerHit&&part==10015){
|
||||
DYPlugIn*plugin=[self pluginAtTime:t];[_viewerControls setBridge:[plugin viewerParameterBridge]];[_viewerControls setViewport:_imageRect];[_viewerControls prepareWithSize:NSMakeSize(_canvasWidth,_height) scale:_uiScale atTime:t];[self updateLevelFrom:plugin];_hslSampling=[plugin canvasHSLSampling];NSPoint point=NSMakePoint(x,_height-y);NSInteger viewerHit=[_viewerControls partAtPoint:point];BOOL redraw=[_viewerControls mouseMoved:point];NSDictionary *mask=[plugin toolCanvasMaskAtTime:t];BOOL drawing=[mask[@"drawing"]boolValue]||[mask[@"drawShape"]boolValue];NSCursor *cursor=[_viewerControls headerAtPoint:point]?([_viewerControls capturing]?NSCursor.closedHandCursor:NSCursor.openHandCursor):viewerHit?NSCursor.pointingHandCursor:(part==10014||part==10015||part==10030)?NSCursor.crosshairCursor:part>=10000?NSCursor.pointingHandCursor:(drawing||part>=1000)?NSCursor.crosshairCursor:part?NSCursor.openHandCursor:NSCursor.arrowCursor;[[_apiManager apiForProtocol:@protocol(FxOnScreenControlAPI_v4)]setCursor:cursor];if(_levelMode&&_levelHasFirst&&!_levelDown&&!_levelSaving&&!viewerHit&&part==10015){
|
||||
_levelLast=_level.toSource([self clampedDisplayUV:point]);redraw=YES;
|
||||
}else if(!_levelMode&&[mask[@"drawing"]boolValue]&&!viewerHit)[self event:NSEventTypeMouseMoved x:x y:y part:part modifiers:m key:0 time:t];
|
||||
if(update)*update=redraw||(!_levelMode&&[mask[@"drawing"]boolValue])||_stampNeedsRedraw;_stampNeedsRedraw=NO;
|
||||
if(update)*update=_hslSampling||redraw||(!_levelMode&&[mask[@"drawing"]boolValue])||_stampNeedsRedraw;_stampNeedsRedraw=NO;
|
||||
}}
|
||||
- (void)mouseEnteredAtPositionX:(double)x positionY:(double)y modifiers:(FxModifierKeys)m forceUpdate:(BOOL*)update atTime:(CMTime)t{[self mouseMovedAtPositionX:x positionY:y activePart:0 modifiers:m forceUpdate:update atTime:t];}
|
||||
- (void)mouseExitedAtPositionX:(double)x positionY:(double)y modifiers:(FxModifierKeys)m forceUpdate:(BOOL*)update atTime:(CMTime)t{@synchronized(self){BOOL changed=[_viewerControls mouseExited];if(update)*update=changed;}}
|
||||
|
||||
在新工单中引用
屏蔽一个用户