From 2e7ab4b052d71fea0c503c581cd8b9d659752408 Mon Sep 17 00:00:00 2001 From: mac Date: Sat, 31 Oct 2026 03:48:44 +0800 Subject: [PATCH] fix: present LUT browser through FxPlug host window and refine native controls --- research/ANALYSIS.md | 2 +- 大鱼调色/Plugin/DYInspector.mm | 49 ++++++++++++---- 大鱼调色/Plugin/DYLUTBrowser.h | 4 ++ 大鱼调色/Plugin/DYLUTBrowser.mm | 75 ++++++++++++++++++------- 大鱼调色/Plugin/DYTheme.mm | 19 +++++-- 大鱼调色/Plugin/Info.plist | 2 +- 大鱼调色/Wrapper Application/Info.plist | 2 +- 7 files changed, 113 insertions(+), 40 deletions(-) diff --git a/research/ANALYSIS.md b/research/ANALYSIS.md index c300db0..642d260 100644 --- a/research/ANALYSIS.md +++ b/research/ANALYSIS.md @@ -19,7 +19,7 @@ LumiGrade-analysis.json包含REA/Ghidra返回的20条证据及分析限制;关 ## 适配与边界 -重建的是调色行为与可编辑控件,界面使用大鱼标识;白平衡与颜色归同组、肤色保护独立旁路以对应实际数学依赖。未接原厂许可、售后或联网服务。吸管使用系统取色器,未复用原厂Viewer OSC。用户LUT采用文件选择,未照搬原厂缩略图浏览库和主题切换。 +重建的是调色行为与可编辑控件,界面保留大鱼标识,并按原版收紧工具栏、主题色块、标题胶囊、参数行与分组;白平衡/光影/鲜艳度/饱和度合入基础组,HSL、色阶和色彩平衡按通道切换显示。肤色保护维持独立数学旁路,设置单独折叠。未接原厂许可、售后或联网服务。吸管使用系统取色器,未复用原厂Viewer OSC。五套主题按原版完整17色和控件用途恢复,偏好使用独立大鱼域并跨实例同步。风格 LUT 可用菜单、文件选择或缩略图浏览器;浏览器按原版760×560、16:9缩略图、70–255尺寸范围及目录/尺寸记忆实现,另支持安全导入、搜索和懒加载。原版用户LUT内容未复制,产品库在 ~/Movies/大鱼调色LUT/look LUTs。主题和浏览库的静态证据见 ThemeLUT-analysis.md。 自动分析同为320×180 RGB8,转换前后量化并先应用输入LUT;Metal双线性缩图与原CoreGraphics缩图可能在边缘产生微小差异。原GPU使用half纹理和输出;32位宿主也遵循这一原精度边界。局部增强/全帧统计需要完整源帧,超大图受GPU纹理/内存限制。Cube仅保存逐像素颜色,无法承载邻域纹理、清晰度或逐画面分析。 diff --git a/大鱼调色/Plugin/DYInspector.mm b/大鱼调色/Plugin/DYInspector.mm index f7652da..62087e2 100644 --- a/大鱼调色/Plugin/DYInspector.mm +++ b/大鱼调色/Plugin/DYInspector.mm @@ -13,7 +13,7 @@ static NSColor *DYAccent(void) { return DYThemeColor(@"accent"); } static NSColor *DYInk(void) { return DYThemeColor(@"text"); } static NSTextField *DYLabel(NSString *text, CGFloat size) { NSTextField *v=[NSTextField labelWithString:text?:@""]; - v.font=[NSFont systemFontOfSize:size]; v.textColor=DYInk(); + v.font=[NSFont systemFontOfSize:size weight:size==11?NSFontWeightMedium:NSFontWeightRegular]; v.textColor=DYInk(); v.lineBreakMode=NSLineBreakByTruncatingTail; return v; } @@ -32,8 +32,8 @@ static NSString *DYNumber(double value,NSDictionary *d) { @interface DYBlueSliderCell : NSSliderCell @end @implementation DYBlueSliderCell - (void)drawBarInside:(NSRect)rect flipped:(BOOL)flipped { - NSRect track=NSMakeRect(rect.origin.x,NSMidY(rect)-2,rect.size.width,4); - [DYThemeColor(@"track") setFill];[[NSBezierPath bezierPathWithRoundedRect:track xRadius:2 yRadius:2] fill]; + NSRect track=NSMakeRect(rect.origin.x,NSMidY(rect)-2.5,rect.size.width,5); + NSBezierPath *bar=[NSBezierPath bezierPathWithRoundedRect:track xRadius:2.5 yRadius:2.5];NSGradient *base=[[[NSGradient alloc]initWithStartingColor:DYThemePalette()[@"slot8"] endingColor:DYThemePalette()[@"slot9"]]autorelease];[base drawInBezierPath:bar angle:90];[[NSColor colorWithWhite:0 alpha:.28]setStroke];bar.lineWidth=.6;[bar stroke]; double fraction=(self.doubleValue-self.minValue)/fmax(.000001,self.maxValue-self.minValue); NSRect active=track;active.size.width*=fmax(0,fmin(1,fraction));NSGradient *g=[[[NSGradient alloc]initWithStartingColor:DYThemePalette()[@"activeTop"] endingColor:DYThemePalette()[@"activeBottom"]]autorelease];[g drawInBezierPath:[NSBezierPath bezierPathWithRoundedRect:active xRadius:2 yRadius:2] angle:90]; } @@ -44,6 +44,15 @@ static NSString *DYNumber(double value,NSDictionary *d) { } @end +@interface DYNumberFieldCell : NSTextFieldCell @end +@implementation DYNumberFieldCell +- (void)drawWithFrame:(NSRect)frame inView:(NSView *)view { + NSRect rect=NSInsetRect(frame,.5,.5);NSBezierPath *p=[NSBezierPath bezierPathWithRoundedRect:rect xRadius:2.5 yRadius:2.5]; + NSGradient *gradient=[[[NSGradient alloc]initWithStartingColor:DYThemePalette()[@"slot5"] endingColor:DYThemePalette()[@"slot4"]]autorelease];[gradient drawInBezierPath:p angle:90];[[DYThemePalette()[@"accent"]colorWithAlphaComponent:.65]setStroke];p.lineWidth=.9;[p stroke]; + [self drawInteriorWithFrame:NSInsetRect(frame,4,3) inView:view]; +} +@end + // FxPlug's remote view bridge needs an explicit container tree; an ignored // NSView document can otherwise make a populated NSScrollView appear empty. static NSArray *DYAccessibleSubviews(NSView *view, BOOL visibleOnly) { @@ -101,6 +110,7 @@ static NSArray *DYAccessibleSubviews(NSView *view, BOOL visibleOnly) { NSBezierPath *path=[NSBezierPath bezierPathWithRoundedRect:NSInsetRect(self.bounds,.5,.5) xRadius:11 yRadius:11]; [path fill]; [DYThemeColor(@"border") setStroke]; path.lineWidth=1; [path stroke]; + [[NSColor colorWithWhite:.52 alpha:1]setFill];[[NSBezierPath bezierPathWithOvalInRect:NSMakeRect(32,19,5,5)]fill]; } @end @@ -127,6 +137,7 @@ static NSArray *DYAccessibleSubviews(NSView *view, BOOL visibleOnly) { - (void)dealloc {[_swatch release];[super dealloc];} - (void)drawRect:(NSRect)dirtyRect { NSRect r=NSInsetRect(self.bounds,3,3);[_swatch setFill];NSBezierPath *p=[NSBezierPath bezierPathWithRoundedRect:r xRadius:5 yRadius:5];[p fill]; + if([self.identifier isEqual:@"customColorSwatch"]){NSGradient *g=[[[NSGradient alloc]initWithColors:@[NSColor.systemRedColor,NSColor.systemYellowColor,NSColor.systemGreenColor,NSColor.systemCyanColor,NSColor.systemBlueColor,NSColor.systemPurpleColor]]autorelease];[g drawInBezierPath:p angle:45];[@"⌾" drawInRect:NSInsetRect(r,3,1) withAttributes:@{NSFontAttributeName:[NSFont boldSystemFontOfSize:16],NSForegroundColorAttributeName:NSColor.whiteColor}];} if(self.state==NSControlStateValueOn){[DYInk() setStroke];p.lineWidth=2;[p stroke];} } @end @@ -375,7 +386,7 @@ static NSImage *DYWheelImage(void) { self.appearance=[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]; _brand=[DYLabel(@"◒ 大鱼调色",16) retain]; _brand.font=[NSFont boldSystemFontOfSize:16]; _subtitle=[DYLabel(@"1.1",9) retain]; _subtitle.textColor=DYThemeColor(@"secondary"); - _resetAll=[DYButton(@"↺",self,@selector(resetAll:)) retain]; _resetAll.toolTip=@"恢复全部调色参数与 LUT";_resetAll.accessibilityLabel=@"全部还原"; + _resetAll=[DYButton(@"↺",self,@selector(resetAll:)) retain];_resetAll.bordered=NO; _resetAll.toolTip=@"恢复全部调色参数与 LUT";_resetAll.accessibilityLabel=@"全部还原"; _save=[DYButton(@"保存预设",self,@selector(savePreset:)) retain]; _load=[DYButton(@"载入预设",self,@selector(loadPreset:)) retain]; _export=[DYButton(@"导出 LUT",self,@selector(exportLUT:)) retain]; @@ -443,7 +454,7 @@ static NSImage *DYWheelImage(void) { [self setNeedsLayout:YES];NSAccessibilityPostNotification(self,NSAccessibilityLayoutChangedNotification); } - (void)addLook:(id)sender {_visibleLooks=MIN(5,_visibleLooks+1);[self setNeedsLayout:YES];} -- (void)previewChanged:(NSNotification *)note {if(_browser.window.visible)[_browser updatePreview:[_renderer preview]];} +- (void)previewChanged:(NSNotification *)note {if(_browser.visible)[_browser updatePreview:[_renderer preview]];} - (void)buildCards { NSInteger index=0; for(NSDictionary *section in _sections) { @@ -461,6 +472,7 @@ static NSImage *DYWheelImage(void) { enabled.accessibilityLabel=[section[@"title"] stringByAppendingString:@"启用"]; [card addSubview:enabled]; enabled.hidden=section[@"enabled"]==nil; NSButton *reset=DYButton(@"↺",self,@selector(resetSection:)); reset.tag=index; + reset.bordered=NO; reset.toolTip=@"还原本组"; reset.accessibilityLabel=[section[@"title"] stringByAppendingString:@"还原"]; [card addSubview:reset]; NSMutableArray *body=[NSMutableArray array]; @@ -483,7 +495,7 @@ static NSImage *DYWheelImage(void) { } if([key isEqual:@"hsl"]) { DYFlippedView *tabs=[[[DYFlippedView alloc]initWithFrame:NSZeroRect]autorelease];tabs.identifier=@"hslTabs"; - for(NSInteger i=0;i<9;i++){DYSwatchButton *b=[[[DYSwatchButton alloc]initWithFrame:NSZeroRect]autorelease];[b setButtonType:NSButtonTypePushOnPushOff];b.swatch=i<8?[NSColor colorWithSRGBRed:((double[]){1,1,1,.15,0,0,.75,1})[i] green:((double[]){.2,.55,.84,.76,.76,.47,.15,.15})[i] blue:((double[]){.25,.12,0,.25,.8,1,.9,.65})[i] alpha:1]:DYAccent();b.title=@"";b.tag=i;b.target=self;b.action=@selector(tabChanged:);b.state=i==0?NSControlStateValueOn:NSControlStateValueOff;b.accessibilityLabel=[@[@"红",@"橙",@"黄",@"绿",@"青",@"蓝",@"紫",@"洋红",@"自定义"][i] stringByAppendingString:@" HSL"];[tabs addSubview:b];} + for(NSInteger i=0;i<9;i++){DYSwatchButton *b=[[[DYSwatchButton alloc]initWithFrame:NSZeroRect]autorelease];[b setButtonType:NSButtonTypePushOnPushOff];b.swatch=i<8?[NSColor colorWithSRGBRed:((double[]){1,1,1,.15,0,0,.75,1})[i] green:((double[]){.2,.55,.84,.76,.76,.47,.15,.15})[i] blue:((double[]){.25,.12,0,.25,.8,1,.9,.65})[i] alpha:1]:DYAccent();b.title=@"";if(i==8)b.identifier=@"customColorSwatch";b.tag=i;b.target=self;b.action=@selector(tabChanged:);b.state=i==0?NSControlStateValueOn:NSControlStateValueOff;b.accessibilityLabel=[@[@"红",@"橙",@"黄",@"绿",@"青",@"蓝",@"紫",@"洋红",@"自定义"][i] stringByAppendingString:@" HSL"];[tabs addSubview:b];} [card addSubview:tabs];[body addObject:tabs]; DYFlippedView *actions=[[[DYFlippedView alloc]initWithFrame:NSZeroRect]autorelease];actions.identifier=@"sampleControls"; NSButton *picker=DYButton(@"吸取自定义 HSL 颜色",self,@selector(sampleCustomColor:));[actions addSubview:picker];[card addSubview:actions];[body addObject:actions]; @@ -525,15 +537,16 @@ static NSImage *DYWheelImage(void) { slider.minValue=[d[@"min"]doubleValue];slider.maxValue=[d[@"max"]doubleValue];slider.doubleValue=[d[@"default"]doubleValue];slider.target=self;slider.action=@selector(scalarChanged:); slider.tag=[pid integerValue]; slider.continuous=YES; slider.controlSize=NSControlSizeSmall; slider.accessibilityLabel=d[@"title"]; [row addSubview:slider]; record[@"slider"]=slider; - NSTextField *field=[[[NSTextField alloc] initWithFrame:NSZeroRect] autorelease]; + NSTextField *field=[[[NSTextField alloc] initWithFrame:NSZeroRect] autorelease];field.cell=[[[DYNumberFieldCell alloc]initTextCell:@"0"]autorelease]; field.font=[NSFont monospacedDigitSystemFontOfSize:11 weight:NSFontWeightMedium]; field.textColor=DYInk(); field.backgroundColor=DYThemeColor(@"field"); - field.bezeled=YES; field.bezelStyle=NSTextFieldRoundedBezel; - field.alignment=NSTextAlignmentRight; field.target=self; field.action=@selector(scalarChanged:); + field.bezeled=NO;field.bordered=NO;field.drawsBackground=NO; + field.alignment=NSTextAlignmentCenter; field.target=self; field.action=@selector(scalarChanged:); field.tag=[pid integerValue]; field.accessibilityLabel=[d[@"title"] stringByAppendingString:@"数值"]; [row addSubview:field]; record[@"field"]=field; } NSButton *itemReset=DYButton(@"↺",self,@selector(resetScalar:)); + itemReset.bordered=NO; itemReset.tag=[pid integerValue]; itemReset.toolTip=@"还原此项"; itemReset.accessibilityLabel=[d[@"title"] stringByAppendingString:@"还原"]; [row addSubview:itemReset]; record[@"reset"]=itemReset; @@ -561,7 +574,9 @@ static NSImage *DYWheelImage(void) { NSButton *remove=DYButton(@"×",self,@selector(removeAsset:)); remove.identifier=key; remove.toolTip=@"移除此 LUT"; remove.accessibilityLabel=[title stringByAppendingString:@"移除"]; [row addSubview:remove]; NSButton *folder=DYButton(@"",self,@selector(openLibraryFolder:));folder.identifier=key;folder.bordered=NO;folder.image=[NSImage imageWithSystemSymbolName:@"folder" accessibilityDescription:@"LUT文件夹"];folder.accessibilityLabel=[title stringByAppendingString:@"文件夹"];[row addSubview:folder]; - _assetButtons[key]=@{@"row":row,@"label":label,@"choose":choose,@"remove":remove,@"browse":browse,@"folder":folder}; + NSMutableDictionary *record=[NSMutableDictionary dictionaryWithDictionary:@{@"row":row,@"label":label,@"choose":choose,@"remove":remove,@"browse":browse,@"folder":folder}]; + if([key hasPrefix:@"look"]&&[[key substringFromIndex:4]integerValue]>0){NSButton *eye=DYButton(@"",self,@selector(lookEnabled:));eye.identifier=key;eye.bordered=NO;[eye setButtonType:NSButtonTypePushOnPushOff];eye.accessibilityLabel=[title stringByAppendingString:@"启用"];[row addSubview:eye];record[@"eye"]=eye;} + _assetButtons[key]=record; return row; } - (BOOL)showRow:(NSView *)row section:(NSString *)section { @@ -619,7 +634,7 @@ static NSImage *DYWheelImage(void) { if(record[@"slider"]){[record[@"slider"]setFrame:NSMakeRect(lw+7,7,MAX(25,rw-lw-94),18)];[record[@"field"]setFrame:NSMakeRect(rw-81,4,54,24)];} } for(NSString *key in _assetButtons){NSDictionary *r=_assetButtons[key];CGFloat rw=[r[@"row"]bounds].size.width;BOOL input=[key isEqual:@"input"]; - [r[@"browse"]setHidden:input];[r[@"browse"]setFrame:NSMakeRect(0,4,20,24)];[r[@"label"]setFrame:NSMakeRect(input?2:25,7,input?86:69,18)]; + [r[@"browse"]setHidden:input];[r[@"eye"]setFrame:NSMakeRect(0,5,18,20)];[r[@"browse"]setFrame:NSMakeRect(r[@"eye"]?20:0,4,20,24)];[r[@"label"]setFrame:NSMakeRect(input?2:r[@"eye"]?43:25,7,input?86:r[@"eye"]?51:69,18)]; [r[@"choose"]setFrame:NSMakeRect(97,3,MAX(65,rw-152),26)];[r[@"folder"]setFrame:NSMakeRect(rw-51,4,24,24)];[r[@"remove"]setFrame:NSMakeRect(rw-23,4,22,24)]; } [_document setFrameSize:NSMakeSize(_scroll.contentSize.width,MAX(y,_scroll.contentSize.height))]; @@ -659,6 +674,7 @@ static NSImage *DYWheelImage(void) { if([key isEqual:@"input"]&&!path.length){double profile=0;[get getFloatValue:&profile fromParameter:2013 atTime:t];for(NSDictionary *d in DYDescriptors())if([d[@"key"]isEqual:@"inputProfile"]){NSArray *options=d[@"options"];NSInteger index=MAX(0,MIN((NSInteger)llround(profile),(NSInteger)options.count-1));name=options[index];break;}} button.title=name; button.toolTip=path.length?path:@"选择输入转换或 LUT;点击网格图标浏览缩略图"; [_assetButtons[key][@"remove"] setEnabled:path.length>0]; + NSButton *eye=_assetButtons[key][@"eye"];if(eye){NSInteger slot=[[key substringFromIndex:4]integerValue];double enabled=1;[get getFloatValue:&enabled fromParameter:2040+(UInt32)slot-1 atTime:t];eye.state=enabled>=.5?NSControlStateValueOn:NSControlStateValueOff;eye.image=[NSImage imageWithSystemSymbolName:enabled>=.5?@"eye":@"eye.slash" accessibilityDescription:enabled>=.5?@"启用":@"旁路"];} } for(NSInteger i=1;i<5;i++)if([assets.paths[[NSString stringWithFormat:@"look%ld",(long)i]]length])_visibleLooks=MAX(_visibleLooks,i+1); [self setNeedsLayout:YES]; @@ -792,8 +808,17 @@ static NSImage *DYWheelImage(void) { [_browser close];[_browser release];_browser=nil; id a=[self actionAPI];if(!a)return;[a startAction:self];NSString *selected=nil;@try{selected=[DYReadAssets(_manager,a.currentTime).paths[sender.identifier]copy];}@finally{[a endAction:self];} __block DYInspector *owner=self;NSString *key=[[sender.identifier copy]autorelease]; - _browser=[[DYLUTBrowser alloc]initWithLibrary:_library preview:[_renderer preview] selectedPath:selected palette:DYThemePalette() selection:^(NSString *path){[owner setAssetPath:path forKey:key];}];[selected release];[_browser showRelativeToView:sender]; + _browser=[[DYLUTBrowser alloc]initWithLibrary:_library preview:[_renderer preview] selectedPath:selected palette:DYThemePalette() selection:^(NSString *path){[owner setAssetPath:path forKey:key];}];[selected release]; + id remote=[_manager apiForProtocol:@protocol(FxRemoteWindowAPI_v3)]; + if(!remote)remote=[_manager apiForProtocol:@protocol(FxRemoteWindowAPI_v2)];if(!remote)remote=[_manager apiForProtocol:@protocol(FxRemoteWindowAPI)]; + DYLUTBrowser *browser=_browser;id closer=[_manager apiForProtocol:@protocol(FxRemoteWindowAPI_v3)]; + if(remote){[remote remoteWindowOfSize:CGSizeMake(760,560) reply:^(FxXPView *parent,NSError *error){dispatch_async(dispatch_get_main_queue(),^{ + if(_browser!=browser)return; + if(parent){[browser showInRemoteParent:parent close:^{[closer closeRemoteWindow];}];} + else [browser showRelativeToView:sender]; + });}];}else [browser showRelativeToView:sender]; } +- (void)lookEnabled:(NSButton *)sender {NSInteger slot=[[sender.identifier substringFromIndex:4]integerValue];if(slot<1||slot>4)return;[self writeGraphicValues:@{[NSString stringWithFormat:@"look%ldEnabled",(long)slot+1]:@(sender.state==NSControlStateValueOn)}];} - (void)openLibraryFolder:(id)sender { NSError *error=nil;if(![[NSFileManager defaultManager]createDirectoryAtURL:_library.rootURL withIntermediateDirectories:YES attributes:nil error:&error]){[self showError:error.localizedDescription];return;}[[NSWorkspace sharedWorkspace]openURL:_library.rootURL]; } diff --git a/大鱼调色/Plugin/DYLUTBrowser.h b/大鱼调色/Plugin/DYLUTBrowser.h index b33d72e..5a95138 100644 --- a/大鱼调色/Plugin/DYLUTBrowser.h +++ b/大鱼调色/Plugin/DYLUTBrowser.h @@ -5,12 +5,16 @@ /// A nonmodal browser. Selecting a validated thumbnail applies that LUT. /// All UI and selection callbacks run on the main thread. @interface DYLUTBrowser : NSWindowController +@property(nonatomic,readonly) BOOL visible; - (instancetype)initWithLibrary:(DYLUTLibrary *)library preview:(NSData *)rgba selectedPath:(NSString *)path palette:(NSDictionary *)palette selection:(void (^)(NSString *path))selection; - (void)showRelativeToView:(NSView *)view; +/// Attach to the FxRemoteWindow API's supplied parent; the caller owns that API. +/// Completion, double-click and close dismiss through closeAction exactly once. +- (void)showInRemoteParent:(NSView *)parent close:(void (^)(void))closeAction; - (void)updatePalette:(NSDictionary *)palette; /// Replace the source frame after the renderer captures a new playhead image. /// Passing identical bytes keeps the current thumbnail jobs and cache intact. diff --git a/大鱼调色/Plugin/DYLUTBrowser.mm b/大鱼调色/Plugin/DYLUTBrowser.mm index 6fac072..e5b2a2a 100644 --- a/大鱼调色/Plugin/DYLUTBrowser.mm +++ b/大鱼调色/Plugin/DYLUTBrowser.mm @@ -100,12 +100,14 @@ static NSString *const DYBrowserFolderPreference=@"com.dayu.color.lookLUTPreview @end @implementation DYBrowserWork @end -@interface DYLUTBrowser () { +@interface DYLUTBrowser () { DYLUTLibrary *_library; NSData *_preview; NSString *_selectedPath,*_folder; NSDictionary *_palette; void (^_selection)(NSString *); + void (^_closeAction)(void); + NSPopover *_popover; DYBrowserCanvas *_root,*_folderDocument,*_gridDocument; NSScrollView *_folderScroll,*_gridScroll; NSTextField *_titleLabel,*_countLabel,*_statusLabel,*_sizeLabel,*_emptyLabel; @@ -119,7 +121,7 @@ static NSString *const DYBrowserFolderPreference=@"com.dayu.color.lookLUTPreview NSCache *_thumbnailCache; dispatch_queue_t _previewQueue; DYBrowserWork *_work; - BOOL _closed,_sizing; + BOOL _closed,_sizing,_visible,_remoteMode,_importing; } @end @@ -157,6 +159,9 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(gridScrolled:) name:NSViewBoundsDidChangeNotification object:_gridScroll.contentView]; for(NSView *view in @[_titleLabel,_countLabel,_statusLabel,_sizeLabel,_search,_importFiles,_importFolder,_reveal,_refresh,_none,_done,_sizeSlider,_folderScroll,_gridScroll])[_root addSubview:view]; [_gridDocument addSubview:_emptyLabel]; + _root.postsFrameChangedNotifications=YES;_root.postsBoundsChangedNotifications=YES; + [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(browserRootResized:) name:NSViewFrameDidChangeNotification object:_root]; + [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(browserRootResized:) name:NSViewBoundsDidChangeNotification object:_root]; [self reloadLibrary:nil];[self updatePalette:palette];[self layoutBrowser]; } return self; @@ -164,7 +169,8 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b - (void)dealloc{ [NSObject cancelPreviousPerformRequestsWithTarget:self];[[NSNotificationCenter defaultCenter]removeObserver:self]; _work.cancelled=YES;_work.owner=nil;[_work release];self.window.delegate=nil; - [_library release];[_preview release];[_selectedPath release];[_folder release];[_palette release];[_selection release]; + _popover.delegate=nil;[_popover close];[_popover release];[_root removeFromSuperview]; + [_library release];[_preview release];[_selectedPath release];[_folder release];[_palette release];[_selection release];[_closeAction release]; [_root release];[_folderDocument release];[_gridDocument release];[_folderScroll release];[_gridScroll release]; [_titleLabel release];[_countLabel release];[_statusLabel release];[_sizeLabel release];[_emptyLabel release];[_search release]; [_importFiles release];[_importFolder release];[_reveal release];[_refresh release];[_none release];[_done release];[_sizeSlider release]; @@ -172,21 +178,49 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b dispatch_release(_previewQueue);[super dealloc]; } - (void)showRelativeToView:(NSView *)view{ - if(_closed)return; - NSWindow *parent=view.window; - if(parent){ - NSRect frame=self.window.frame,parentFrame=parent.frame; - NSScreen *screen=parent.screen?:NSScreen.mainScreen;NSRect safe=screen.visibleFrame; - NSPoint p=NSMakePoint(NSMidX(parentFrame)-frame.size.width/2,NSMidY(parentFrame)-frame.size.height/2); - p.x=MAX(NSMinX(safe),MIN(p.x,NSMaxX(safe)-frame.size.width));p.y=MAX(NSMinY(safe),MIN(p.y,NSMaxY(safe)-frame.size.height));[self.window setFrameOrigin:p]; - }else [self.window center]; - [self showWindow:nil];[self.window makeKeyAndOrderFront:nil]; + if(_closed||_remoteMode||!view.window)return; + if(_popover.shown)return; + // A plug-in process is prohibited from making its own NSPanel key. Only + // FxRemoteWindow or a host-anchored popover may present this content. + self.window.contentView=[[[NSView alloc]initWithFrame:NSMakeRect(0,0,1,1)]autorelease]; + [_root removeFromSuperview];_root.frame=NSMakeRect(0,0,760,560);_root.autoresizingMask=NSViewWidthSizable|NSViewHeightSizable; + _popover=[[NSPopover alloc]init];_popover.behavior=NSPopoverBehaviorTransient;_popover.animates=YES;_popover.delegate=self;_popover.contentSize=NSMakeSize(760,560); + NSViewController *controller=[[[NSViewController alloc]init]autorelease];controller.view=_root;_popover.contentViewController=controller; + [self layoutBrowser]; + @try {[_popover showRelativeToRect:view.bounds ofView:view preferredEdge:NSRectEdgeMaxX];_visible=_popover.shown;} + @catch(NSException *exception){[self finishClosing];} } +- (BOOL)visible{return !_closed&&(_remoteMode?_visible:_popover.shown);} +- (void)showInRemoteParent:(NSView *)parent close:(void (^)(void))closeAction{ + if(_closed||!parent||self.visible)return; + _remoteMode=YES;_visible=YES;[_closeAction release];_closeAction=[closeAction copy]; + self.window.contentView=[[[NSView alloc]initWithFrame:NSMakeRect(0,0,1,1)]autorelease]; + [_root removeFromSuperview];_root.frame=parent.bounds;_root.autoresizingMask=NSViewWidthSizable|NSViewHeightSizable;parent.autoresizesSubviews=YES;_root.hidden=NO; + [parent addSubview:_root];[self layoutBrowser];[_root setNeedsDisplay:YES]; + NSAccessibilityPostNotification(parent,NSAccessibilityLayoutChangedNotification); +} +- (void)browserRootResized:(NSNotification *)notification{if(!_closed)[self layoutBrowser];} - (void)windowDidResize:(NSNotification *)notification{[self layoutBrowser];} -- (void)windowWillClose:(NSNotification *)notification{ +- (void)windowWillClose:(NSNotification *)notification{[self finishClosing];} +- (BOOL)popoverShouldClose:(NSPopover *)popover{return !_importing;} +- (void)popoverDidClose:(NSNotification *)notification{[self finishClosing];} +- (void)close{ + if(_closed)return; + if(_popover.shown){[_popover close];if(!_closed)[self finishClosing];} + else [self finishClosing]; +} +- (void)finishClosing{ + if(_closed)return; + // The API owner's completion may release this controller synchronously. + [self retain]; [NSObject cancelPreviousPerformRequestsWithTarget:self]; - _closed=YES;_work.cancelled=YES;_work.owner=nil; + _closed=YES;_visible=NO;_work.cancelled=YES;_work.owner=nil; + _popover.delegate=nil;if(_popover.shown)[_popover close]; + [_root removeFromSuperview];[_queuedPaths removeAllObjects];[_thumbnailCache removeAllObjects]; [_selection release];_selection=nil; + void (^closeAction)(void)=[_closeAction copy];[_closeAction release];_closeAction=nil; + if(closeAction)closeAction();[closeAction release]; + [self release]; } - (void)layoutBrowser{ CGFloat w=_root.bounds.size.width,h=_root.bounds.size.height,left=162; @@ -214,6 +248,7 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b browserPalette[@"background"]=[NSColor colorWithCalibratedRed:.035 green:.08 blue:.12 alpha:1]; [_palette release];_palette=[browserPalette copy];_root.palette=_palette;_folderDocument.palette=_palette;_gridDocument.palette=_palette; self.window.backgroundColor=DYBrowserColor(_palette,@"background");self.window.appearance=[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]; + _root.appearance=[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua]; for(NSTextField *label in @[_titleLabel,_countLabel,_statusLabel,_sizeLabel,_emptyLabel])label.textColor=DYBrowserColor(_palette,label==_titleLabel?@"text":@"secondary"); for(NSButton *button in @[_importFiles,_importFolder,_reveal,_refresh,_none,_done])button.contentTintColor=DYBrowserColor(_palette,@"accent"); _search.textColor=DYBrowserColor(_palette,@"text");_search.backgroundColor=DYBrowserColor(_palette,@"field"); @@ -332,16 +367,16 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b } - (void)done:(id)sender{[self close];} - (void)showImportError:(NSError *)error{ - if(!error)return;NSAlert *alert=[[[NSAlert alloc]init]autorelease];alert.messageText=@"LUT 导入未完成";alert.informativeText=error.localizedDescription?:@"请选择有效的 .cube LUT 文件。";[alert addButtonWithTitle:@"好"];[alert beginSheetModalForWindow:self.window completionHandler:nil]; + if(!error||_closed)return;NSAlert *alert=[[[NSAlert alloc]init]autorelease];alert.messageText=@"LUT 导入未完成";alert.informativeText=error.localizedDescription?:@"请选择有效的 .cube LUT 文件。";[alert addButtonWithTitle:@"好"]; + _importing=YES;[alert runModal];_importing=NO; } - (void)importPanelForFolders:(BOOL)folders{ NSOpenPanel *panel=[NSOpenPanel openPanel];panel.canChooseFiles=!folders;panel.canChooseDirectories=folders;panel.allowsMultipleSelection=YES;panel.title=folders?@"导入 LUT 文件夹":@"导入 LUT 文件";panel.message=folders?@"所选文件夹中的 .cube 文件会按目录复制到大鱼调色 LUT 库。":@"选择要复制到大鱼调色 LUT 库的 .cube 文件。"; if(!folders)panel.allowedFileTypes=@[@"cube"]; - [panel beginSheetModalForWindow:self.window completionHandler:^(NSModalResponse response){ - if(response!=NSModalResponseOK||_closed)return;NSError *error=nil;NSArray *imported=[_library importURLs:panel.URLs error:&error]; - if(!imported){[self showImportError:error];return;} - [self rebuildFolders];[self rebuildGrid];[self setStatus:[NSString stringWithFormat:@"已导入 %lu 个 LUT",(unsigned long)imported.count]]; - }]; + _importing=YES;NSModalResponse response=[panel runModal];_importing=NO; + if(response!=NSModalResponseOK||_closed)return;NSError *error=nil;NSArray *imported=[_library importURLs:panel.URLs error:&error]; + if(!imported){[self showImportError:error];return;} + [self rebuildFolders];[self rebuildGrid];[self setStatus:[NSString stringWithFormat:@"已导入 %lu 个 LUT",(unsigned long)imported.count]]; } - (void)importFiles:(id)sender{[self importPanelForFolders:NO];} - (void)importFolder:(id)sender{[self importPanelForFolders:YES];} diff --git a/大鱼调色/Plugin/DYTheme.mm b/大鱼调色/Plugin/DYTheme.mm index dbf74f1..3303b63 100644 --- a/大鱼调色/Plugin/DYTheme.mm +++ b/大鱼调色/Plugin/DYTheme.mm @@ -35,9 +35,18 @@ static const double paletteRGB[5][17][3]={ NSColor *DYThemeSwatch(NSInteger index){static const double values[5][3]={{.30,.33,.38},{.28,.72,1},{.58,.52,1},{.30,.86,.52},{1,.61,.28}};index=MAX(0,MIN(4,index));return rgb(values[index][0],values[index][1],values[index][2]);} void DYSetThemeIndex(NSInteger index){if(index<0||index>4)return;[store().defaults setInteger:index forKey:@"themeIndex"];[store().defaults synchronize];[[NSNotificationCenter defaultCenter]postNotificationName:DYThemeDidChange object:nil];[[NSDistributedNotificationCenter defaultCenter]postNotificationName:distributedChange object:preferenceDomain userInfo:nil deliverImmediately:YES];} NSDictionary *DYThemePalette(void){ - NSInteger index=DYThemeIndex();const double (*p)[3]=paletteRGB[index]; - NSMutableDictionary *d=[NSMutableDictionary dictionary];for(int i=0;i<17;i++)d[[NSString stringWithFormat:@"slot%d",i]]=rgb(p[i][0],p[i][1],p[i][2]); - NSColor *accent=index==0?rgb(.72,.77,.84):index==1?rgb(.22,.67,1):DYThemeSwatch(index); - [d addEntriesFromDictionary:@{@"background":d[@"slot1"],@"card":d[@"slot3"],@"border":[accent colorWithAlphaComponent:.38],@"text":d[@"slot14"],@"secondary":d[@"slot16"],@"accent":accent,@"field":d[@"slot4"],@"headerTop":d[@"slot6"],@"headerBottom":d[@"slot7"],@"track":d[@"slot8"],@"activeTop":d[@"slot10"],@"activeBottom":d[@"slot11"],@"knob":d[@"slot12"]}];return d; + static NSArray *palettes;static dispatch_once_t once;dispatch_once(&once,^{ + NSMutableArray *all=[NSMutableArray array]; + for(NSInteger index=0;index<5;index++){ + const double (*p)[3]=paletteRGB[index];NSMutableDictionary *d=[NSMutableDictionary dictionary]; + for(int i=0;i<17;i++)d[[NSString stringWithFormat:@"slot%d",i]]=rgb(p[i][0],p[i][1],p[i][2]); + NSColor *accent=index==0?rgb(.72,.77,.84):index==1?rgb(.22,.67,1):DYThemeSwatch(index); + [d addEntriesFromDictionary:@{@"background":d[@"slot1"],@"card":d[@"slot3"],@"border":[accent colorWithAlphaComponent:.38],@"text":d[@"slot14"],@"secondary":d[@"slot16"],@"accent":accent,@"field":d[@"slot4"],@"headerTop":d[@"slot6"],@"headerBottom":d[@"slot7"],@"track":d[@"slot8"],@"activeTop":d[@"slot10"],@"activeBottom":d[@"slot11"],@"knob":d[@"slot12"]}];[all addObject:[[d copy]autorelease]]; + }palettes=[all copy]; + });return palettes[DYThemeIndex()]; +} +NSColor *DYThemeColor(NSString *role){ + static NSDictionary *colors;static dispatch_once_t once;dispatch_once(&once,^{ + NSMutableDictionary *all=[NSMutableDictionary dictionary];for(NSString *key in DYThemePalette())all[key]=[NSColor colorWithName:[@"Dayu." stringByAppendingString:key] dynamicProvider:^NSColor *(NSAppearance *appearance){return DYThemePalette()[key];}];colors=[all copy]; + });return colors[role]?:NSColor.whiteColor; } -NSColor *DYThemeColor(NSString *role){return [NSColor colorWithName:[@"Dayu." stringByAppendingString:role] dynamicProvider:^NSColor *(NSAppearance *appearance){return DYThemePalette()[role]?:[NSColor whiteColor];}];} diff --git a/大鱼调色/Plugin/Info.plist b/大鱼调色/Plugin/Info.plist index 7f1d397..9b047ce 100644 --- a/大鱼调色/Plugin/Info.plist +++ b/大鱼调色/Plugin/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 1.1.0 CFBundleVersion - 3 + 4 NSHumanReadableCopyright PlugInKit diff --git a/大鱼调色/Wrapper Application/Info.plist b/大鱼调色/Wrapper Application/Info.plist index 0674da5..1a1d7ac 100644 --- a/大鱼调色/Wrapper Application/Info.plist +++ b/大鱼调色/Wrapper Application/Info.plist @@ -19,7 +19,7 @@ CFBundleShortVersionString 1.1.0 CFBundleVersion - 3 + 4 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) NSHumanReadableCopyright