Implement persistent leveling and all standalone module templates; validation pending
这个提交包含在:
1 父节点
81b50538b4
当前提交
dc5769492d
33 个文件已更改
+8585
-88
没有与搜索条件相匹配的文件
+63
-36
@@ -12,23 +12,34 @@
|
||||
double _levelAngle;
|
||||
NSInteger _levelMode;
|
||||
CMTime _levelTime;
|
||||
BOOL _levelHasFirst,_levelDown,_levelSecondPress,_levelSaving;
|
||||
BOOL _levelHasFirst,_levelDown,_levelSecondPress,_levelSaving,_levelPlaced;
|
||||
NSInteger _levelEditingEnd; NSDictionary *_levelState;
|
||||
NSPoint _levelFirst,_levelLast;
|
||||
}
|
||||
- (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];[_stampFailure release];[_levelFailure release];[super dealloc];}
|
||||
- (void)dealloc{[_viewerControls release];[_device release];[_queue release];[_context release];[_mask release];[_handles release];[_outline release];[_stampFailure release];[_levelFailure release];[_levelState 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];}}
|
||||
- (void)clearLevelLine {
|
||||
_levelHasFirst=_levelDown=_levelSecondPress=NO;
|
||||
_levelHasFirst=_levelDown=_levelSecondPress=_levelPlaced=NO;_levelEditingEnd=0;
|
||||
[_levelFailure release];_levelFailure=nil;
|
||||
}
|
||||
- (void)restoreLevelReference {
|
||||
[self clearLevelLine];
|
||||
NSArray *points=_levelState[@"levelReference"][@"points"];
|
||||
if(points.count==4){_levelFirst=NSMakePoint([points[0]doubleValue],[points[1]doubleValue]);_levelLast=NSMakePoint([points[2]doubleValue],[points[3]doubleValue]);_levelPlaced=YES;}
|
||||
}
|
||||
- (void)updateLevelFrom:(DYPlugIn *)plugin {
|
||||
double angle=0;
|
||||
double fallback=NSWidth(_imageRect)>0&&NSHeight(_imageRect)>0?NSWidth(_imageRect)/NSHeight(_imageRect):1;
|
||||
_level=plugin?[plugin toolCanvasLevelForAspect:fallback rotation:&angle]:DYLevelTransform(0,fallback);
|
||||
if(_levelMode!=_viewerControls.levelMode||_levelAngle!=angle)[self clearLevelLine];
|
||||
NSDictionary *state=plugin?[plugin toolCanvasLevelState]:@{};
|
||||
BOOL changed=![_levelState isEqual:state];
|
||||
if(changed){[_levelState release];_levelState=[state copy];[self restoreLevelReference];}
|
||||
if(!_levelMode&&_viewerControls.levelMode){[self restoreLevelReference];NSInteger mode=[state[@"levelReference"][@"mode"]integerValue];if(mode)_viewerControls.levelMode=mode;}
|
||||
if(_levelMode&&!_viewerControls.levelMode)[self restoreLevelReference];
|
||||
_levelMode=_viewerControls.levelMode;_levelAngle=angle;
|
||||
_viewerControls.levelMeasureOnly=[state[@"levelMeasureOnly"]boolValue];
|
||||
}
|
||||
- (NSPoint)displayUV:(NSPoint)point {
|
||||
return NSMakePoint((point.x-NSMinX(_imageRect))/NSWidth(_imageRect),(point.y-NSMinY(_imageRect))/NSHeight(_imageRect));
|
||||
@@ -40,65 +51,76 @@
|
||||
- (NSPoint)canvasDisplayPoint:(NSPoint)uv {
|
||||
return NSMakePoint(NSMinX(_imageRect)+uv.x*NSWidth(_imageRect),NSMinY(_imageRect)+uv.y*NSHeight(_imageRect));
|
||||
}
|
||||
- (void)commitLevel:(double)angle plugin:(DYPlugIn *)plugin {
|
||||
if(_levelSaving)return;
|
||||
_levelSaving=YES;
|
||||
- (void)commitLevelState:(NSDictionary *)state plugin:(DYPlugIn *)plugin {
|
||||
if(_levelSaving)return;_levelSaving=YES;
|
||||
DYViewerParameterBridge *bridge=_viewerControls.bridge;
|
||||
[plugin saveCanvasLevel:angle replacing:_levelAngle completion:^(NSString *failure){
|
||||
[plugin saveCanvasLevel:state replacing:_levelState?:@{} completion:^(NSString *failure){
|
||||
@synchronized(self){
|
||||
self->_levelSaving=NO;
|
||||
if(self->_viewerControls.bridge!=bridge||!self->_viewerControls.levelMode)return;
|
||||
[self clearLevelLine];
|
||||
if(self->_viewerControls.bridge!=bridge)return;
|
||||
[self updateLevelFrom:plugin];[self restoreLevelReference];
|
||||
self->_levelFailure=[failure copy];
|
||||
}
|
||||
}];
|
||||
}
|
||||
- (void)commitLevelReference:(DYPlugIn *)plugin {
|
||||
double corrected=DYLevelDelta(_levelFirst,_levelLast,_level.aspect,_levelMode==2);
|
||||
NSMutableDictionary *state=[NSMutableDictionary dictionaryWithDictionary:_levelState?:@{}];
|
||||
state[@"levelRotation"]=@(fabs(corrected)<1e-7?0:corrected);
|
||||
state[@"levelReference"]=@{@"points":@[@(_levelFirst.x),@(_levelFirst.y),@(_levelLast.x),@(_levelLast.y)],@"aspect":@(_level.aspect),@"mode":@(_levelMode)};
|
||||
[self commitLevelState:state plugin:plugin];
|
||||
}
|
||||
- (BOOL)handleLevelEvent:(NSEventType)type point:(NSPoint)point part:(NSInteger)part key:(unichar)key time:(CMTime)time plugin:(DYPlugIn *)plugin {
|
||||
if(!_levelMode||!plugin)return NO;
|
||||
if(type==NSEventTypeKeyDown&&key==27){
|
||||
_viewerControls.levelMode=0;[self clearLevelLine];return YES;
|
||||
[self restoreLevelReference];_viewerControls.levelMode=0;return YES;
|
||||
}
|
||||
// FCP's drawing and event callbacks may report different sample times.
|
||||
// Compare events only and leave room for the host's sub-frame drift.
|
||||
if(_levelHasFirst&&(type==NSEventTypeLeftMouseDown||type==NSEventTypeLeftMouseUp)&&
|
||||
(time.epoch!=_levelTime.epoch||fabs(CMTimeGetSeconds(CMTimeSubtract(time,_levelTime)))>.05))[self clearLevelLine];
|
||||
if(type==NSEventTypeLeftMouseDown&&part==10015){
|
||||
(time.epoch!=_levelTime.epoch||fabs(CMTimeGetSeconds(CMTimeSubtract(time,_levelTime)))>.05))[self restoreLevelReference];
|
||||
if(type==NSEventTypeLeftMouseDown&&(part==10015||part==10016||part==10017)){
|
||||
if(_levelSaving)return YES;
|
||||
[_levelFailure release];_levelFailure=nil;
|
||||
_levelDown=YES;_levelSecondPress=_levelHasFirst;
|
||||
_levelLast=[self clampedDisplayUV:point];
|
||||
if(!_levelHasFirst){_levelFirst=_levelLast;_levelTime=time;_levelHasFirst=YES;}
|
||||
NSPoint source=_level.toSource([self clampedDisplayUV:point]);
|
||||
_levelEditingEnd=part==10016?1:part==10017?2:0;
|
||||
if(_levelEditingEnd){_levelTime=time;return YES;}
|
||||
_levelPlaced=NO;
|
||||
_levelLast=source;
|
||||
if(!_levelHasFirst){_levelFirst=source;_levelTime=time;_levelHasFirst=YES;}
|
||||
return YES;
|
||||
}
|
||||
if(!_levelDown||(type!=NSEventTypeLeftMouseDragged&&type!=NSEventTypeLeftMouseUp))return NO;
|
||||
_levelLast=[self clampedDisplayUV:point];
|
||||
NSPoint source=_level.toSource([self clampedDisplayUV:point]);
|
||||
if(_levelEditingEnd==1)_levelFirst=source;else _levelLast=source;
|
||||
if(type==NSEventTypeLeftMouseUp){
|
||||
_levelDown=NO;
|
||||
double distance=hypot((_levelLast.x-_levelFirst.x)*NSWidth(_imageRect),(_levelLast.y-_levelFirst.y)*NSHeight(_imageRect));
|
||||
if(distance>=5*_uiScale){
|
||||
double delta=DYLevelDelta(_levelFirst,_levelLast,_level.aspect,_levelMode==2);
|
||||
double corrected=std::remainder(_levelAngle+delta,2*M_PI);
|
||||
[self commitLevel:fabs(corrected)<1e-7?0:corrected plugin:plugin];
|
||||
}else if(_levelSecondPress){
|
||||
_levelFailure=[@"两点太近,请重新选择第二点。" copy];
|
||||
}
|
||||
NSPoint first=[self canvasDisplayPoint:_level.toOutput(_levelFirst)],last=[self canvasDisplayPoint:_level.toOutput(_levelLast)];
|
||||
double distance=hypot(last.x-first.x,last.y-first.y);
|
||||
if(distance>=5*_uiScale)[self commitLevelReference:plugin];
|
||||
else if(_levelSecondPress||_levelEditingEnd){[self restoreLevelReference];_levelFailure=[@"两点太近,请重新选择。" copy];}
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
- (void)drawLevelControls {
|
||||
if(!_levelMode)return;
|
||||
NSRect viewport=NSIntersectionRect(_imageRect,NSMakeRect(0,0,_canvasWidth,_height));
|
||||
CGFloat scale=MIN(_uiScale,NSWidth(viewport)/325.);
|
||||
NSRect prompt=NSMakeRect(NSMinX(viewport)+8*scale,NSMinY(viewport)+8*scale,290*scale,26*scale);
|
||||
CGFloat scale=MIN(_uiScale,NSWidth(viewport)/420.);
|
||||
NSRect prompt=NSMakeRect(NSMinX(viewport)+8*scale,NSMinY(viewport)+8*scale,400*scale,72*scale);
|
||||
DYDrawSoftControl(prompt,4*scale,NO,NO,NO);
|
||||
NSString *title=_levelFailure?:(_levelSaving?@"正在保存水平校正…":_levelHasFirst?@"选择参考线终点 · Esc 退出":@"点击两点或拖出参考线 · Esc 退出");
|
||||
[title drawInRect:NSInsetRect(prompt,6*scale,5*scale) withAttributes:@{NSForegroundColorAttributeName:NSColor.whiteColor,NSFontAttributeName:[NSFont systemFontOfSize:12*scale]}];
|
||||
if(!_levelHasFirst)return;
|
||||
NSPoint first=[self canvasDisplayPoint:_levelFirst],last=[self canvasDisplayPoint:_levelLast];
|
||||
NSString *title=_levelFailure?:(_levelSaving?@"正在保存水平校正…":_levelPlaced?@"拖动端点修正 · 空白处重画 · Esc 收起":_levelHasFirst?@"选择参考线终点 · Esc 取消":@"点击两点或拖出参考线 · Esc 收起");
|
||||
NSDictionary *attrs=@{NSForegroundColorAttributeName:NSColor.whiteColor,NSFontAttributeName:[NSFont systemFontOfSize:12*scale]};
|
||||
[title drawInRect:NSMakeRect(NSMinX(prompt)+6*scale,NSMinY(prompt)+5*scale,388*scale,18*scale) withAttributes:attrs];
|
||||
DYLevelTransform result(_levelAngle,_level.aspect);
|
||||
NSString *numbers=[NSString stringWithFormat:@"FCP 旋转 %+.2f° 缩放 %.2f%%(增加 %.2f%%)",-_levelAngle*180/M_PI,result.zoom*100,(result.zoom-1)*100];
|
||||
[numbers drawInRect:NSMakeRect(NSMinX(prompt)+6*scale,NSMinY(prompt)+27*scale,388*scale,18*scale) withAttributes:attrs];
|
||||
NSString *hint=_viewerControls.levelMeasureOnly?@"仅测量:数值用于原始变换;已有缩放请乘以上述比例。":@"插件已应用;改用原始变换前,请切换「仅测量」。";
|
||||
[hint drawInRect:NSMakeRect(NSMinX(prompt)+6*scale,NSMinY(prompt)+49*scale,388*scale,18*scale) withAttributes:@{NSForegroundColorAttributeName:NSColor.whiteColor,NSFontAttributeName:[NSFont systemFontOfSize:10*scale]}];
|
||||
if(!_levelHasFirst&&!_levelPlaced)return;
|
||||
NSPoint first=[self canvasDisplayPoint:_level.toOutput(_levelFirst)],last=[self canvasDisplayPoint:_level.toOutput(_levelLast)];
|
||||
[NSGraphicsContext saveGraphicsState];NSRectClip(viewport);
|
||||
NSBezierPath *line=[NSBezierPath bezierPath];[line moveToPoint:first];[line lineToPoint:last];
|
||||
for(NSValue *value in @[[NSValue valueWithPoint:first],[NSValue valueWithPoint:last]]){
|
||||
NSPoint point=value.pointValue;CGFloat r=3*_uiScale;
|
||||
NSPoint point=value.pointValue;CGFloat r=5*_uiScale;
|
||||
[line appendBezierPathWithOvalInRect:NSMakeRect(point.x-r,point.y-r,2*r,2*r)];
|
||||
}
|
||||
[NSColor.blackColor setStroke];line.lineWidth=3.5*_uiScale;[line stroke];
|
||||
@@ -210,7 +232,10 @@
|
||||
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(_levelMode)return NSPointInRect(point,_imageRect)?10015: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;
|
||||
}
|
||||
if(_viewerControls.stampArmed)return NSPointInRect(point,_imageRect)?10014:0;
|
||||
NSArray *source=_mask[@"stampSource"];
|
||||
if(source.count==4){
|
||||
@@ -280,7 +305,9 @@
|
||||
BOOL penAction=type==NSEventTypeLeftMouseDown&&(part==10009||part==10010);
|
||||
if(!ownedMask&&!penAction&&type!=NSEventTypeKeyDown&&[_viewerControls event:type point:canvasPoint atTime:time]){
|
||||
[self updateLevelFrom:plugin];
|
||||
if(_viewerControls.levelResetRequested){_viewerControls.levelResetRequested=NO;[self commitLevel:0 plugin:plugin];}
|
||||
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];}
|
||||
return YES;
|
||||
}
|
||||
if(_levelMode)return NO;
|
||||
@@ -295,7 +322,7 @@
|
||||
- (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){
|
||||
_levelLast=[self clampedDisplayUV:point];redraw=YES;
|
||||
_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;
|
||||
}}
|
||||
|
||||
在新工单中引用
屏蔽一个用户