From: Ruben Beltran del Rio Date: Thu, 9 Feb 2023 21:51:47 +0000 (+0100) Subject: Improve drawing, add padding to bezel X-Git-Tag: 1.0.0~5 X-Git-Url: https://git.r.bdr.sh/rbdr/Flat-Bezel.qsplugin/commitdiff_plain/953623b990fb65a0a9676071022ae8ce50436d53?ds=sidebyside Improve drawing, add padding to bezel --- diff --git a/Flat Bezel.xcodeproj/project.pbxproj b/Flat Bezel.xcodeproj/project.pbxproj index 1dc96c0..adb78ea 100644 --- a/Flat Bezel.xcodeproj/project.pbxproj +++ b/Flat Bezel.xcodeproj/project.pbxproj @@ -8,12 +8,10 @@ /* Begin PBXBuildFile section */ 42447D7D19407DA00077B4B2 /* BBSearchObjectView.m in Sources */ = {isa = PBXBuildFile; fileRef = 42447D7C19407DA00077B4B2 /* BBSearchObjectView.m */; }; - 42447D821940935E0077B4B2 /* gear-black.png in Resources */ = {isa = PBXBuildFile; fileRef = 42447D7F1940935E0077B4B2 /* gear-black.png */; }; - 42447D831940935E0077B4B2 /* search-black.png in Resources */ = {isa = PBXBuildFile; fileRef = 42447D801940935E0077B4B2 /* search-black.png */; }; 42663058193CC1FA00C0DD31 /* BBFlatBezelInterface.xib in Resources */ = {isa = PBXBuildFile; fileRef = 42663057193CC1FA00C0DD31 /* BBFlatBezelInterface.xib */; }; B576D2F52993FBD400A8B645 /* BackgroundView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B576D2F42993FBD400A8B645 /* BackgroundView.swift */; }; - CD3B1BE2285F2E8C004862D7 /* search-white.png in Resources */ = {isa = PBXBuildFile; fileRef = CD3B1BE0285F2E8C004862D7 /* search-white.png */; }; - CD3B1BE3285F2E8C004862D7 /* gear-white.png in Resources */ = {isa = PBXBuildFile; fileRef = CD3B1BE1285F2E8C004862D7 /* gear-white.png */; }; + B57F7B90299405B7005F64AC /* FlatBezelSearchObjectView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B57F7B8F299405B7005F64AC /* FlatBezelSearchObjectView.swift */; }; + B57F7B922994063C005F64AC /* FlatBezelObjectCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B57F7B912994063C005F64AC /* FlatBezelObjectCell.swift */; }; E470B7E31709F3A0000169F2 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E470B7E21709F3A0000169F2 /* Cocoa.framework */; }; E470B7E91709F3A0000169F2 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = E470B7E71709F3A0000169F2 /* InfoPlist.strings */; }; E470B7F81709F3A0000169F2 /* BBFlatBezelInterface.m in Sources */ = {isa = PBXBuildFile; fileRef = E470B7F71709F3A0000169F2 /* BBFlatBezelInterface.m */; }; @@ -22,13 +20,11 @@ /* Begin PBXFileReference section */ 42447D7B19407DA00077B4B2 /* BBSearchObjectView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BBSearchObjectView.h; sourceTree = ""; }; 42447D7C19407DA00077B4B2 /* BBSearchObjectView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BBSearchObjectView.m; sourceTree = ""; }; - 42447D7F1940935E0077B4B2 /* gear-black.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "gear-black.png"; sourceTree = ""; }; - 42447D801940935E0077B4B2 /* search-black.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "search-black.png"; sourceTree = ""; }; 42663057193CC1FA00C0DD31 /* BBFlatBezelInterface.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = BBFlatBezelInterface.xib; sourceTree = ""; }; B576D2F42993FBD400A8B645 /* BackgroundView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackgroundView.swift; sourceTree = ""; }; B576D2F62993FD7500A8B645 /* FlatBezel-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "FlatBezel-Bridging-Header.h"; sourceTree = ""; }; - CD3B1BE0285F2E8C004862D7 /* search-white.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "search-white.png"; sourceTree = ""; }; - CD3B1BE1285F2E8C004862D7 /* gear-white.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "gear-white.png"; sourceTree = ""; }; + B57F7B8F299405B7005F64AC /* FlatBezelSearchObjectView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlatBezelSearchObjectView.swift; sourceTree = ""; }; + B57F7B912994063C005F64AC /* FlatBezelObjectCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlatBezelObjectCell.swift; sourceTree = ""; }; E470B7DF1709F3A0000169F2 /* Flat Bezel.qsplugin */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Flat Bezel.qsplugin"; sourceTree = BUILT_PRODUCTS_DIR; }; E470B7E21709F3A0000169F2 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; E470B7E61709F3A0000169F2 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = SOURCE_ROOT; }; @@ -90,11 +86,9 @@ E470B7F61709F3A0000169F2 /* BBFlatBezelInterface.h */, E470B7F71709F3A0000169F2 /* BBFlatBezelInterface.m */, 42663057193CC1FA00C0DD31 /* BBFlatBezelInterface.xib */, + B57F7B8F299405B7005F64AC /* FlatBezelSearchObjectView.swift */, + B57F7B912994063C005F64AC /* FlatBezelObjectCell.swift */, B576D2F42993FBD400A8B645 /* BackgroundView.swift */, - CD3B1BE1285F2E8C004862D7 /* gear-white.png */, - CD3B1BE0285F2E8C004862D7 /* search-white.png */, - 42447D7F1940935E0077B4B2 /* gear-black.png */, - 42447D801940935E0077B4B2 /* search-black.png */, ); path = "Flat Bezel"; sourceTree = ""; @@ -182,12 +176,8 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - CD3B1BE3285F2E8C004862D7 /* gear-white.png in Resources */, 42663058193CC1FA00C0DD31 /* BBFlatBezelInterface.xib in Resources */, E470B7E91709F3A0000169F2 /* InfoPlist.strings in Resources */, - CD3B1BE2285F2E8C004862D7 /* search-white.png in Resources */, - 42447D821940935E0077B4B2 /* gear-black.png in Resources */, - 42447D831940935E0077B4B2 /* search-black.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -215,8 +205,10 @@ buildActionMask = 2147483647; files = ( B576D2F52993FBD400A8B645 /* BackgroundView.swift in Sources */, + B57F7B90299405B7005F64AC /* FlatBezelSearchObjectView.swift in Sources */, 42447D7D19407DA00077B4B2 /* BBSearchObjectView.m in Sources */, E470B7F81709F3A0000169F2 /* BBFlatBezelInterface.m in Sources */, + B57F7B922994063C005F64AC /* FlatBezelObjectCell.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Flat Bezel/BBFlatBezelInterface.m b/Flat Bezel/BBFlatBezelInterface.m index a05a924..e430de8 100644 --- a/Flat Bezel/BBFlatBezelInterface.m +++ b/Flat Bezel/BBFlatBezelInterface.m @@ -82,7 +82,7 @@ NSRect screenRect = [[NSScreen mainScreen] frame]; if (!shouldExpand) { - newRect.size.width -= 208; + newRect.size.width -= 192; } return NSOffsetRect(centerRectInRect(newRect, screenRect), 0, (NSHeight(screenRect) / 5)); diff --git a/Flat Bezel/BBFlatBezelInterface.xib b/Flat Bezel/BBFlatBezelInterface.xib index dae6222..3aa05ea 100644 --- a/Flat Bezel/BBFlatBezelInterface.xib +++ b/Flat Bezel/BBFlatBezelInterface.xib @@ -22,51 +22,51 @@ - + - + - + - - + + - + - - + + - + - - + + - + - + @@ -98,11 +98,11 @@ - - + + - - + + diff --git a/Flat Bezel/BBSearchObjectView.m b/Flat Bezel/BBSearchObjectView.m index ba88b0b..0722e0c 100644 --- a/Flat Bezel/BBSearchObjectView.m +++ b/Flat Bezel/BBSearchObjectView.m @@ -169,8 +169,33 @@ [titleString drawInRect:centerRectInRect(centerRect, textDrawRect)]; } -@end - - - +- (void)drawSearchPlaceholderWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { + NSString *defaultText = NSLocalizedStringWithDefaultValue(@"Type to search", nil, [NSBundle mainBundle], @"Type to search", @"Hint that appears in the first pane of the QS interface when it's empty."); + NSSize textSize = [defaultText sizeWithAttributes:nameAttributes]; + NSRect textRect = centerRectInRect(rectFromSize(textSize), cellFrame); + BOOL isFirstResponder = [[controlView window] firstResponder] == controlView && ![controlView isKindOfClass:[NSTableView class]]; + + if (isFirstResponder && [controlView isKindOfClass:[QSSearchObjectView class]]) { + NSImage *find = [NSImage imageWithSystemSymbolName:@"magnifyingglass.circle.fill" accessibilityDescription:nil]; + + + [find setSize:QSSize16]; + NSRect findImageRect = expelRectFromRectOnEdge(centerRectInRect(rectFromSize([find size]), cellFrame), textRect, NSRectEdgeMinX, -2); + + + NSGraphicsContext *graphicsContext = [NSGraphicsContext currentContext]; + [graphicsContext saveGraphicsState]; + CGContextRef context = [graphicsContext CGContext]; + CGContextBeginTransparencyLayerWithRect(context, findImageRect, nil); + CGContextSetBlendMode(context, kCGBlendModeNormal); + [find drawInRect:findImageRect fromRect:rectFromSize([find size]) operation:NSCompositingOperationSourceOver fraction:1]; + CGContextSetBlendMode(context, kCGBlendModeSourceIn); + CGContextSetFillColorWithColor(context, [[NSColor textColor] CGColor]); + CGContextFillRect(context, findImageRect); + CGContextEndTransparencyLayer(context); + + [defaultText drawInRect:textRect withAttributes:nameAttributes]; + } +} +@end diff --git a/Flat Bezel/FlatBezelObjectCell.swift b/Flat Bezel/FlatBezelObjectCell.swift new file mode 100644 index 0000000..211f332 --- /dev/null +++ b/Flat Bezel/FlatBezelObjectCell.swift @@ -0,0 +1,133 @@ +// +// FlatBezelObjectCell.swift +// Flat Bezel +// +// Created by Ruben Beltran del Rio on 2/8/23. +// Copyright © 2023 BRNBW. All rights reserved. +// +/* +import Foundation +import Cocoa + +class FlatBezelObjectCell: QSObjectCell { + let preferredImagePosition: NSControl.ImagePosition = .imageAbove + + override func draw(withFrame cellFrame: NSRect, in controlView: NSView!) { + let isFirstResponder = controlView.window?.firstResponder == controlView && !controlView.isKind(of: NSTableView.self) + + let dropTarget = self.isHighlighted && self.highlightsBy.contains(NSCell.StyleMask.changeBackgroundCellMask) && !self.isBezeled + + var fillColor: NSColor = self.backgroundColor ?? .textBackgroundColor + if (isFirstResponder) { + fillColor = self.highlightColor() + } + if (dropTarget) { + fillColor = NSColor(red: 0.77, green: 0.91, blue: 0.96, alpha: 1) + } + + var strokeColor: NSColor = .clear + + fillColor.setFill() + strokeColor.setStroke() + + let roundRect = NSBezierPath() + roundRect.appendRoundedRect(cellFrame, xRadius: cellRadiusFactor(), yRadius: cellRadiusFactor()) + roundRect.fill() + + self.drawInterior(withFrame: self.drawingRect(forBounds: cellFrame), in: controlView) + } + + override func titleRect(forBounds rect: NSRect) -> NSRect { + super.titleRect(forBounds: rect.offsetBy(dx: 0, dy: -4)) + } + + override func drawText(for drawObject: QSObject!, withFrame cellFrame: NSRect, in controlView: NSView!) { + if self.imagePosition == .imageOnly { + return; + } + + var abbrString: String? = nil + if controlView.responds(to: #selector(QSSearchObjectView.matchedString)) { + abbrString = (controlView as! QSSearchObjectView).matchedString() + } + + var nameString: String? = drawObject.displayName() + var hitMask: AutoreleasingUnsafeMutablePointer? = nil + + var ranker = drawObject.ranker() + if let ranker, let abbrString { + nameString = ranker.matchedString(forAbbreviation: abbrString, hitmask: hitMask, inContext: nil) + } + + var rankedStringIsName = nameString == drawObject.displayName() + if nameString == nil { + nameString = drawObject.identifier() ?? "Unknown" + } + + var useAlternateColor = false + if let controlView = controlView as? NSTableView { + useAlternateColor = controlView.isRowSelected(controlView.row(at: cellFrame.origin)) + } + + var mainColor: NSColor? = textColor() + if mainColor == nil { + mainColor = useAlternateColor ? .alternateSelectedControlTextColor : .controlTextColor + } + + var fadedColor = mainColor!.withAlphaComponent(0.50) + var textDrawRect = titleRect(forBounds: cellFrame) + + var titleString = NSMutableAttributedString(string: nameString!) + titleString.setAttributes(rankedStringIsName ? nameAttributes : detailAttributes, range: NSMakeRange(0, titleString.length)) + + if abbrString != nil && abbrString!.hasPrefix("QSActionMnemonic") { + titleString.addAttribute(.foregroundColor, value: rankedStringIsName ? fadedColor : fadedColor.withAlphaComponent(0.8), range: NSMakeRange(0, titleString.length)) + } else { + var i = 0 + var j = 0 + var hits: [Int] = [] + count = hitMask?. + } + } +} + + + NSUInteger i = 0; + NSUInteger j = 0; + NSUInteger hits[[titleString length]]; + NSUInteger count = [hitMask getIndexes:(NSUInteger *)&hits maxCount:[titleString length] inIndexRange:nil]; + NSDictionary *attributes = @{ + NSForegroundColorAttributeName: rankedStringIsName ? mainColor : fadedColor + }; + for(i = 0; i AnyClass { + return FlatBezelObjectCell.self + } +} +*/ diff --git a/Flat Bezel/gear-black.png b/Flat Bezel/gear-black.png deleted file mode 100755 index 3ebdfe6..0000000 Binary files a/Flat Bezel/gear-black.png and /dev/null differ diff --git a/Flat Bezel/gear-white.png b/Flat Bezel/gear-white.png deleted file mode 100755 index 169f6cb..0000000 Binary files a/Flat Bezel/gear-white.png and /dev/null differ diff --git a/Flat Bezel/search-black.png b/Flat Bezel/search-black.png deleted file mode 100755 index e85640e..0000000 Binary files a/Flat Bezel/search-black.png and /dev/null differ diff --git a/Flat Bezel/search-white.png b/Flat Bezel/search-white.png deleted file mode 100755 index e6048b7..0000000 Binary files a/Flat Bezel/search-white.png and /dev/null differ