From c5441fab87577df97ca052d49713a9743500a4b6 Mon Sep 17 00:00:00 2001 From: mac Date: Sat, 31 Oct 2026 03:36:12 +0800 Subject: [PATCH] WIP: add persistent theme palettes and reorganize inspector presentation; integration pending --- 大鱼调色/Plugin/DYInspector.h | 2 ++ 大鱼调色/Plugin/DYInspector.mm | 46 +++++++++++++++++++++++++++++----- 大鱼调色/Plugin/DYTheme.h | 9 +++++++ 大鱼调色/Plugin/DYTheme.mm | 36 ++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 大鱼调色/Plugin/DYTheme.h create mode 100644 大鱼调色/Plugin/DYTheme.mm diff --git a/大鱼调色/Plugin/DYInspector.h b/大鱼调色/Plugin/DYInspector.h index 75529fc..a84f281 100644 --- a/大鱼调色/Plugin/DYInspector.h +++ b/大鱼调色/Plugin/DYInspector.h @@ -1,8 +1,10 @@ #import #import +@class DYRenderer; /// Per-instance custom inspector. All host reads and edits are bracketed actions. @interface DYInspector : NSView - (instancetype)initWithAPIManager:(id)manager; +- (instancetype)initWithAPIManager:(id)manager renderer:(DYRenderer *)renderer; - (void)refresh; @end diff --git a/大鱼调色/Plugin/DYInspector.mm b/大鱼调色/Plugin/DYInspector.mm index 46ef223..ee78e67 100644 --- a/大鱼调色/Plugin/DYInspector.mm +++ b/大鱼调色/Plugin/DYInspector.mm @@ -1,12 +1,16 @@ #import "DYInspector.h" #import "DYModel.h" +#import "DYTheme.h" +#import "DYLUTLibrary.h" +#import "DYLUTBrowser.h" +#import "DYRenderer.h" #import #include #include #include -static NSColor *DYAccent(void) { return [NSColor colorWithSRGBRed:.26 green:.73 blue:.98 alpha:1]; } -static NSColor *DYInk(void) { return [NSColor colorWithSRGBRed:.83 green:.91 blue:.97 alpha:1]; } +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(); @@ -19,6 +23,7 @@ static NSButton *DYButton(NSString *title,id target,SEL action) { b.contentTintColor=DYAccent(); return b; } static NSString *DYNumber(double value,NSDictionary *d) { + if([d[@"key"] hasSuffix:@"Strength"]||[d[@"key"] isEqual:@"preLUTStrength"])return [NSString stringWithFormat:@"%.0f%%",value*100]; double step=[d[@"step"] doubleValue]; return [NSString stringWithFormat:step>0&&step<.1?@"%.2f":step>0&&step<1?@"%.1f":@"%.0f",value]; } @@ -28,13 +33,13 @@ static NSString *DYNumber(double value,NSDictionary *d) { @implementation DYBlueSliderCell - (void)drawBarInside:(NSRect)rect flipped:(BOOL)flipped { NSRect track=NSMakeRect(rect.origin.x,NSMidY(rect)-2,rect.size.width,4); - [[NSColor colorWithSRGBRed:.19 green:.30 blue:.37 alpha:1] setFill];[[NSBezierPath bezierPathWithRoundedRect:track xRadius:2 yRadius:2] fill]; + [DYThemeColor(@"field") setFill];[[NSBezierPath bezierPathWithRoundedRect:track xRadius:2 yRadius:2] fill]; double fraction=(self.doubleValue-self.minValue)/fmax(.000001,self.maxValue-self.minValue); NSRect active=track;active.size.width*=fmax(0,fmin(1,fraction));[DYAccent() setFill];[[NSBezierPath bezierPathWithRoundedRect:active xRadius:2 yRadius:2] fill]; } - (void)drawKnob:(NSRect)knobRect { NSRect circle=NSInsetRect(knobRect,1,1); - [[NSColor colorWithSRGBRed:.69 green:.88 blue:1 alpha:1] setFill];[[NSBezierPath bezierPathWithOvalInRect:circle] fill]; + [[DYThemePalette()[@"accent"] blendedColorWithFraction:.7 ofColor:NSColor.whiteColor] setFill];[[NSBezierPath bezierPathWithOvalInRect:circle] fill]; [DYAccent() setStroke];NSBezierPath *ring=[NSBezierPath bezierPathWithOvalInRect:circle];ring.lineWidth=.7;[ring stroke]; } @end @@ -92,9 +97,9 @@ static NSArray *DYAccessibleSubviews(NSView *view, BOOL visibleOnly) { @interface DYCard : DYFlippedView @end @implementation DYCard - (void)drawRect:(NSRect)rect { - [[NSColor colorWithSRGBRed:.045 green:.135 blue:.20 alpha:1] setFill]; + [DYThemeColor(@"card") setFill]; NSBezierPath *path=[NSBezierPath bezierPathWithRoundedRect:NSInsetRect(self.bounds,.5,.5) xRadius:11 yRadius:11]; - [path fill]; [[NSColor colorWithSRGBRed:.16 green:.34 blue:.45 alpha:1] setStroke]; + [path fill]; [DYThemeColor(@"border") setStroke]; path.lineWidth=1; [path stroke]; } @end @@ -103,12 +108,41 @@ static NSArray *DYAccessibleSubviews(NSView *view, BOOL visibleOnly) { @property SEL doubleClickAction; @end @implementation DYHeader +- (void)drawRect:(NSRect)dirtyRect { + NSRect r=NSInsetRect(self.bounds,.5,2); + NSColor *accent=DYThemePalette()[@"accent"],*card=DYThemePalette()[@"card"]; + NSGradient *g=[[[NSGradient alloc]initWithStartingColor:[card blendedColorWithFraction:.43 ofColor:accent] endingColor:[card blendedColorWithFraction:.16 ofColor:accent]]autorelease]; + [g drawInBezierPath:[NSBezierPath bezierPathWithRoundedRect:r xRadius:8 yRadius:8] angle:90]; + [self.title drawInRect:NSInsetRect(r,9,5) withAttributes:@{NSFontAttributeName:self.font,NSForegroundColorAttributeName:DYInk()}]; +} - (void)mouseDown:(NSEvent *)event { if(event.clickCount==2) [NSApp sendAction:self.doubleClickAction to:self.target from:self]; else [super mouseDown:event]; } @end +@interface DYSwatchButton : NSButton +@property(nonatomic,retain) NSColor *swatch; +@end +@implementation DYSwatchButton +- (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.state==NSControlStateValueOn){[DYInk() setStroke];p.lineWidth=2;[p stroke];} +} +@end + +static NSArray *DYPresentationSections(void) { + NSMutableDictionary *bySection=[NSMutableDictionary dictionary],*byKey=[NSMutableDictionary dictionary]; + for(NSDictionary *s in DYSections())bySection[s[@"key"]]=s; + for(NSDictionary *d in DYDescriptors())byKey[d[@"key"]]=d; + NSMutableDictionary *input=[[bySection[@"input"] mutableCopy]autorelease];input[@"rows"]=@[byKey[@"preLUTStrength"]]; + NSMutableDictionary *base=[[bySection[@"base"] mutableCopy]autorelease];NSMutableArray *rows=[NSMutableArray array]; + for(NSString *key in @[@"temperature",@"tint",@"exposure",@"contrast",@"highlights",@"shadows",@"whites",@"blacks",@"texture",@"clarity",@"dehaze",@"vibrance",@"saturation",@"skinEnabled",@"copyAutoGrade"]){NSDictionary*d=byKey[key];if(d)[rows addObject:d];} + base[@"rows"]=rows;base[@"extraEnabled"]=bySection[@"color"][@"enabled"]; + return @[input,base,bySection[@"skin"],bySection[@"look"],bySection[@"hsl"],bySection[@"curve"],bySection[@"grading"],bySection[@"primaries"],bySection[@"levels"],bySection[@"blackwhite"],bySection[@"balance"]]; +} + @protocol DYGraphicDelegate - (void)writeGraphicValues:(NSDictionary *)values; diff --git a/大鱼调色/Plugin/DYTheme.h b/大鱼调色/Plugin/DYTheme.h new file mode 100644 index 0000000..b546d16 --- /dev/null +++ b/大鱼调色/Plugin/DYTheme.h @@ -0,0 +1,9 @@ +#import + +FOUNDATION_EXPORT NSString *const DYThemeDidChange; +FOUNDATION_EXPORT NSArray *DYThemeNames(void); +FOUNDATION_EXPORT NSInteger DYThemeIndex(void); +FOUNDATION_EXPORT void DYSetThemeIndex(NSInteger index); +FOUNDATION_EXPORT NSDictionary *DYThemePalette(void); +FOUNDATION_EXPORT NSColor *DYThemeColor(NSString *role); +FOUNDATION_EXPORT NSColor *DYThemeSwatch(NSInteger index); diff --git a/大鱼调色/Plugin/DYTheme.mm b/大鱼调色/Plugin/DYTheme.mm new file mode 100644 index 0000000..ccb8b71 --- /dev/null +++ b/大鱼调色/Plugin/DYTheme.mm @@ -0,0 +1,36 @@ +#import "DYTheme.h" + +NSString *const DYThemeDidChange=@"DYThemeDidChange"; +static NSString *const preferenceDomain=@"com.dayu.color.preferences"; +static NSString *const distributedChange=@"com.dayu.color.theme.changed"; +static NSColor *rgb(double r,double g,double b){return [NSColor colorWithSRGBRed:r green:g blue:b alpha:1];} +@interface DYThemeStore : NSObject +@property(nonatomic,retain) NSUserDefaults *defaults; +@end +@implementation DYThemeStore +- (instancetype)init { + if((self=[super init])) { + _defaults=[[NSUserDefaults alloc]initWithSuiteName:preferenceDomain]; + [_defaults registerDefaults:@{@"themeIndex":@1}]; + [[NSDistributedNotificationCenter defaultCenter]addObserver:self selector:@selector(externalChange:) name:distributedChange object:preferenceDomain suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately]; + } + return self; +} +- (void)dealloc {[[NSDistributedNotificationCenter defaultCenter]removeObserver:self];[_defaults release];[super dealloc];} +- (void)externalChange:(NSNotification *)note { + [_defaults synchronize]; + dispatch_async(dispatch_get_main_queue(),^{[[NSNotificationCenter defaultCenter]postNotificationName:DYThemeDidChange object:nil];}); +} +@end +static DYThemeStore *store(void){static DYThemeStore *s;static dispatch_once_t once;dispatch_once(&once,^{s=[DYThemeStore new];});return s;} +NSArray *DYThemeNames(void){return @[@"深空灰",@"冰川蓝",@"薰衣草紫",@"翡翠绿",@"琥珀橙"];} +NSInteger DYThemeIndex(void){return MAX(0,MIN(4,[store().defaults integerForKey:@"themeIndex"]));} +NSColor *DYThemeSwatch(NSInteger index){switch(index){case 0:return rgb(.36,.40,.45);case 2:return rgb(.67,.58,.97);case 3:return rgb(.29,.83,.57);case 4:return rgb(1,.66,.32);default:return rgb(.27,.73,.97);}} +void DYSetThemeIndex(NSInteger index){index=MAX(0,MIN(4,index));[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();NSColor *accent=DYThemeSwatch(index); + double background[5][3]={{.085,.09,.10},{.018,.074,.12},{.065,.042,.13},{.022,.10,.073},{.14,.073,.028}}; + double card[5][3]={{.14,.15,.17},{.045,.135,.20},{.12,.084,.21},{.044,.17,.12},{.21,.126,.063}}; + return @{@"background":rgb(background[index][0],background[index][1],background[index][2]),@"card":rgb(card[index][0],card[index][1],card[index][2]),@"border":[accent colorWithAlphaComponent:.42],@"text":rgb(.86,.93,.97),@"secondary":rgb(.61,.71,.78),@"accent":accent,@"field":[rgb(card[index][0],card[index][1],card[index][2]) blendedColorWithFraction:.14 ofColor:accent]}; +} +NSColor *DYThemeColor(NSString *role){return [NSColor colorWithName:[@"Dayu." stringByAppendingString:role] dynamicProvider:^NSColor *(NSAppearance *appearance){return DYThemePalette()[role]?:[NSColor whiteColor];}];}