From 953623b990fb65a0a9676071022ae8ce50436d53 Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Thu, 9 Feb 2023 22:51:47 +0100 Subject: Improve drawing, add padding to bezel --- Flat Bezel/BBFlatBezelInterface.m | 2 +- Flat Bezel/BBFlatBezelInterface.xib | 36 ++++---- Flat Bezel/BBSearchObjectView.m | 33 ++++++- Flat Bezel/FlatBezelObjectCell.swift | 133 +++++++++++++++++++++++++++++ Flat Bezel/FlatBezelSearchObjectView.swift | 16 ++++ Flat Bezel/gear-black.png | Bin 14198 -> 0 bytes Flat Bezel/gear-white.png | Bin 15108 -> 0 bytes Flat Bezel/search-black.png | Bin 13605 -> 0 bytes Flat Bezel/search-white.png | Bin 15201 -> 0 bytes 9 files changed, 197 insertions(+), 23 deletions(-) create mode 100644 Flat Bezel/FlatBezelObjectCell.swift create mode 100644 Flat Bezel/FlatBezelSearchObjectView.swift delete mode 100755 Flat Bezel/gear-black.png delete mode 100755 Flat Bezel/gear-white.png delete mode 100755 Flat Bezel/search-black.png delete mode 100755 Flat Bezel/search-white.png (limited to 'Flat Bezel') 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 -- cgit