Keep clone stamp preview through host save and use the action clock
这个提交包含在:
1 父节点
df9b3c0253
当前提交
5032ce70ab
6 个文件已更改
+98
-40
没有与搜索条件相匹配的文件
+28
-14
@@ -5,12 +5,12 @@
|
||||
@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 _stampHasSource,_stampDragging;
|
||||
BOOL _stampHasSource,_stampDragging,_stampSaving,_stampNeedsRedraw;
|
||||
NSPoint _stampSource,_stampStart,_stampEnd;
|
||||
CMTime _stampTime;
|
||||
NSString *_stampFailure;
|
||||
}
|
||||
- (instancetype)initWithAPIManager:(id<PROAPIAccessing>)manager{if((self=[super init])){_apiManager=manager;_viewerControls=[DYViewerControls new];_handles=[NSMutableArray new];_lastRoute=-1;_uiScale=1;os_log(OS_LOG_DEFAULT,"dayu_tool_osc_init");}return self;}
|
||||
- (void)dealloc{[_viewerControls release];[_device release];[_queue release];[_context release];[_mask release];[_handles release];[_outline release];[super dealloc];}
|
||||
- (void)dealloc{[_viewerControls release];[_device release];[_queue release];[_context release];[_mask release];[_handles release];[_outline release];[_stampFailure release];[super dealloc];}
|
||||
- (FxDrawingCoordinates)drawingCoordinates{return kFxDrawingCoordinates_CANVAS;}
|
||||
- (DYPlugIn*)pluginAtTime:(CMTime)time{NSString *value=nil;id<FxParameterRetrievalAPI_v6>get=[_apiManager apiForProtocol:@protocol(FxParameterRetrievalAPI_v6)];[get getStringParameterValue:&value fromParameter:DYCanvasSessionParameterID];@synchronized(DYToolCanvasSessions()){return [DYToolCanvasSessions()objectForKey:value];}}
|
||||
- (NSPoint)canvasPoint:(float)x y:(float)y parameters:(DYMaskParameters)p{
|
||||
@@ -23,10 +23,9 @@
|
||||
NSRect v=NSIntersectionRect(_imageRect,NSMakeRect(0,0,_canvasWidth,_height));CGFloat scale=MAX(.01,MIN(_uiScale,MIN(v.size.width/300.,v.size.height/100.)));
|
||||
return NSMakeRect(NSMinX(v)+(item==9?8:76)*scale,NSMaxY(v)-61*scale,64*scale,24*scale);
|
||||
}
|
||||
- (void)updateStampAtTime:(CMTime)time{
|
||||
if(!_viewerControls.stampArmed||!CMTIME_IS_NUMERIC(time)||!CMTIME_IS_NUMERIC(_stampTime)||CMTimeCompare(_stampTime,time)!=0){
|
||||
_stampHasSource=_stampDragging=NO;_stampTime=time;
|
||||
}
|
||||
- (void)clearStampCreation{
|
||||
_stampHasSource=_stampDragging=NO;
|
||||
[_stampFailure release];_stampFailure=nil;
|
||||
}
|
||||
- (NSRect)stampControlRect:(NSInteger)index{
|
||||
NSRect viewport=NSIntersectionRect(_imageRect,NSMakeRect(0,0,_canvasWidth,_height));
|
||||
@@ -53,10 +52,10 @@
|
||||
if(_viewerControls.stampArmed){
|
||||
NSRect cell=NSUnionRect([self stampControlRect:0],[self stampControlRect:3]);
|
||||
DYDrawSoftControl(cell,4,NO,NO,NO);
|
||||
NSString *prompt=_stampHasSource?@"拖出要覆盖的椭圆 · Esc 取消":@"点击画面选择取样中心 · Esc 取消";
|
||||
NSString *prompt=_stampSaving?@"正在保存仿制图章…":_stampFailure?:(_stampHasSource?@"拖出要覆盖的椭圆 · Esc 取消":@"点击画面选择取样中心 · Esc 取消");
|
||||
[prompt drawInRect:NSInsetRect(cell,6,4) withAttributes:@{NSForegroundColorAttributeName:NSColor.whiteColor,NSFontAttributeName:[NSFont systemFontOfSize:MAX(8.,NSHeight(cell)*.48)]}];
|
||||
if(_stampHasSource)[self drawStampSource:_stampSource];
|
||||
if(_stampDragging){
|
||||
if(_stampDragging||_stampSaving||_stampFailure){
|
||||
NSRect target=[self stampTarget];
|
||||
NSRect oval=NSMakeRect(NSMinX(_imageRect)+target.origin.x*NSWidth(_imageRect),NSMinY(_imageRect)+target.origin.y*NSHeight(_imageRect),target.size.width*NSWidth(_imageRect),target.size.height*NSHeight(_imageRect));
|
||||
NSBezierPath *outline=[NSBezierPath bezierPathWithOvalInRect:oval];outline.lineWidth=2*_uiScale;[NSColor.systemCyanColor setStroke];[outline stroke];
|
||||
@@ -79,7 +78,6 @@
|
||||
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];
|
||||
if(plugin&&canvasWidth>0&&_height>0&&canvasWidth<16384&&_height<16384&&_imageRect.size.width>0&&_imageRect.size.height>0){
|
||||
[self updateStampAtTime:time];
|
||||
NSRect region=mask||_viewerControls.stampArmed?NSMakeRect(0,0,canvasWidth,_height):NSIntegralRect([_viewerControls drawingBounds]);
|
||||
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];
|
||||
@@ -131,9 +129,10 @@
|
||||
- (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 updateStampAtTime:time];
|
||||
if(_stampSaving)return YES;
|
||||
if(!_viewerControls.stampArmed)[self clearStampCreation];
|
||||
if(type==NSEventTypeKeyDown&&key==27&&_viewerControls.stampArmed){
|
||||
_viewerControls.stampArmed=NO;[self updateStampAtTime:time];return YES;
|
||||
_viewerControls.stampArmed=NO;[self clearStampCreation];return YES;
|
||||
}
|
||||
if(type==NSEventTypeLeftMouseDown&&part>=10011&&part<=10013){
|
||||
NSInteger direction=[_mask[@"tracking"]boolValue]?9:part-10012;
|
||||
@@ -142,6 +141,7 @@
|
||||
if(plugin&&_viewerControls.stampArmed&&NSWidth(_imageRect)>0&&NSHeight(_imageRect)>0){
|
||||
NSPoint uv=NSMakePoint(fmax(0,fmin(1,(x-NSMinX(_imageRect))/NSWidth(_imageRect))),fmax(0,fmin(1,(canvasPoint.y-NSMinY(_imageRect))/NSHeight(_imageRect))));
|
||||
if(type==NSEventTypeLeftMouseDown&&part==10014){
|
||||
[_stampFailure release];_stampFailure=nil;
|
||||
if(!_stampHasSource){_stampSource=uv;_stampHasSource=YES;}
|
||||
else {_stampStart=_stampEnd=uv;_stampDragging=YES;}
|
||||
return YES;
|
||||
@@ -151,7 +151,21 @@
|
||||
if(type==NSEventTypeLeftMouseUp){
|
||||
NSRect target=[self stampTarget];_stampDragging=NO;
|
||||
if(NSWidth(target)>=.001&&NSHeight(target)>=.001&&NSWidth(target)*NSWidth(_imageRect)>=3*_uiScale&&NSHeight(target)*NSHeight(_imageRect)>=3*_uiScale){
|
||||
[plugin addCloneStampFrom:_stampSource target:target atTime:time];_viewerControls.stampArmed=NO;[self updateStampAtTime:time];
|
||||
_stampSaving=YES;
|
||||
DYViewerParameterBridge *bridge=_viewerControls.bridge;
|
||||
[plugin addCloneStampFrom:_stampSource target:target atTime:time completion:^(NSString *failure){
|
||||
@synchronized(self){
|
||||
self->_stampSaving=NO;
|
||||
if(self->_viewerControls.bridge!=bridge||!self->_viewerControls.stampArmed){[self clearStampCreation];return;}
|
||||
self->_stampNeedsRedraw=YES;
|
||||
if(failure){
|
||||
[self->_stampFailure release];self->_stampFailure=[failure copy];
|
||||
}else{
|
||||
self->_viewerControls.stampArmed=NO;
|
||||
[self clearStampCreation];
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
return YES;
|
||||
@@ -171,7 +185,7 @@
|
||||
- (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];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?NSCursor.crosshairCursor:part>=10000?NSCursor.pointingHandCursor:(drawing||part>=1000)?NSCursor.crosshairCursor:part?NSCursor.openHandCursor:NSCursor.arrowCursor;[[_apiManager apiForProtocol:@protocol(FxOnScreenControlAPI_v4)]setCursor:cursor];if([mask[@"drawing"]boolValue]&&!viewerHit)[self event:NSEventTypeMouseMoved x:x y:y part:part modifiers:m key:0 time:t];if(update)*update=redraw||[mask[@"drawing"]boolValue];
|
||||
DYPlugIn*plugin=[self pluginAtTime:t];[_viewerControls setBridge:[plugin viewerParameterBridge]];[_viewerControls setViewport:_imageRect];[_viewerControls prepareWithSize:NSMakeSize(_canvasWidth,_height) scale:_uiScale atTime:t];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?NSCursor.crosshairCursor:part>=10000?NSCursor.pointingHandCursor:(drawing||part>=1000)?NSCursor.crosshairCursor:part?NSCursor.openHandCursor:NSCursor.arrowCursor;[[_apiManager apiForProtocol:@protocol(FxOnScreenControlAPI_v4)]setCursor:cursor];if([mask[@"drawing"]boolValue]&&!viewerHit)[self event:NSEventTypeMouseMoved x:x y:y part:part modifiers:m key:0 time:t];if(update)*update=redraw||[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;}}
|
||||
|
||||
在新工单中引用
屏蔽一个用户