Skip to content

Commit

Permalink
Full support for translucency
Browse files Browse the repository at this point in the history
  • Loading branch information
LEOYoon-Tsaw committed Oct 1, 2021
1 parent 4fd444a commit 40e3b53
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 20 deletions.
16 changes: 8 additions & 8 deletions Squirrel Designer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
D24509952621F4AF00EB4BAC /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
D2830BBA24FEC87E00BF44BE /* Template.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Template.swift; sourceTree = "<group>"; };
D2830BBE24FEFDD400BF44BE /* CodeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeView.swift; sourceTree = "<group>"; };
D2A25D2F262211D20008E455 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/Main.strings"; sourceTree = "<group>"; };
D2A25D31262212A90008E455 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Main.strings"; sourceTree = "<group>"; };
D2A48D2F2707BDA7002F5086 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Main.strings"; sourceTree = "<group>"; };
D2A48D312707BDBD002F5086 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/Main.strings"; sourceTree = "<group>"; };
D2B5B51C24FD85CA00F7304E /* Squirrel Designer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Squirrel Designer.app"; sourceTree = BUILT_PRODUCTS_DIR; };
D2B5B51F24FD85CA00F7304E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
D2B5B52124FD85CA00F7304E /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -170,8 +170,8 @@
isa = PBXVariantGroup;
children = (
D24509832621E8D800EB4BAC /* Base */,
D2A25D2F262211D20008E455 /* zh-Hant */,
D2A25D31262212A90008E455 /* zh-Hans */,
D2A48D2F2707BDA7002F5086 /* zh-Hans */,
D2A48D312707BDBD002F5086 /* zh-Hant */,
);
name = Main.storyboard;
sourceTree = "<group>";
Expand Down Expand Up @@ -315,7 +315,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 18;
CURRENT_PROJECT_VERSION = 19;
DEVELOPMENT_TEAM = 28HU5A7B46;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "Squirrel Designer/Info.plist";
Expand All @@ -324,7 +324,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.6;
MARKETING_VERSION = 1.7;
PRODUCT_BUNDLE_IDENTIFIER = "Rime.Squirrel-Designer";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -339,7 +339,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 18;
CURRENT_PROJECT_VERSION = 19;
DEVELOPMENT_TEAM = 28HU5A7B46;
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "Squirrel Designer/Info.plist";
Expand All @@ -348,7 +348,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.6;
MARKETING_VERSION = 1.7;
PRODUCT_BUNDLE_IDENTIFIER = "Rime.Squirrel-Designer";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand Down
27 changes: 22 additions & 5 deletions Squirrel Designer/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="18122" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" initialViewController="B8D-0N-5wS">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="17701"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="18122"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -943,14 +943,23 @@
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Iyf-Q3-0yV">
<rect key="frame" x="18" y="251" width="110" height="32"/>
<rect key="frame" x="19" y="215" width="110" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" enabled="NO" allowsUndo="NO" title="Colorspace" id="GFQ-yL-V2f" customClass="VerticallyCenteredTextFieldCell" customModule="Squirrel_Designer" customModuleProvider="target">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="qRt-a9-n5u">
<rect key="frame" x="19" y="252" width="110" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" enabled="NO" allowsUndo="NO" title="Translucency" id="pT7-cp-v6P" customClass="VerticallyCenteredTextFieldCell" customModule="Squirrel_Designer" customModuleProvider="target">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<colorWell fixedFrame="YES" enabled="NO" translatesAutoresizingMaskIntoConstraints="NO" id="48F-Nd-T0T">
<rect key="frame" x="183" y="291" width="44" height="23"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
Expand Down Expand Up @@ -1560,7 +1569,7 @@
</gridCells>
</gridView>
<popUpButton verticalHuggingPriority="750" fixedFrame="YES" placeholderIntrinsicWidth="80" placeholderIntrinsicHeight="21" translatesAutoresizingMaskIntoConstraints="NO" id="9KM-lc-afm">
<rect key="frame" x="131" y="253" width="100" height="26"/>
<rect key="frame" x="132" y="217" width="100" height="26"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="push" title="Display P3" bezelStyle="rounded" alignment="left" lineBreakMode="truncatingTail" state="on" borderStyle="borderAndBezel" imageScaling="proportionallyDown" inset="2" selectedItem="h2z-xi-wWP" id="07L-3c-jFg">
<behavior key="behavior" lightByBackground="YES" lightByGray="YES"/>
Expand Down Expand Up @@ -1594,6 +1603,13 @@
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<switch horizontalHuggingPriority="750" verticalHuggingPriority="750" fixedFrame="YES" baseWritingDirection="leftToRight" alignment="left" translatesAutoresizingMaskIntoConstraints="NO" id="DDY-zH-Cfe">
<rect key="frame" x="186" y="256" width="42" height="24"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<connections>
<action selector="translucencyToggled:" target="XfG-lQ-9wD" id="REo-lU-xRe"/>
</connections>
</switch>
</subviews>
</view>
</subviews>
Expand All @@ -1602,7 +1618,7 @@
<rect key="frame" x="-100" y="-100" width="523" height="16"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" doubleValue="0.30526315789473679" horizontal="NO" id="heW-H9-Cu5">
<scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="heW-H9-Cu5">
<rect key="frame" x="509" y="0.0" width="16" height="310"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
Expand Down Expand Up @@ -1674,6 +1690,7 @@
<outlet property="scrollView" destination="eG7-5q-ARK" id="pO8-EA-sL7"/>
<outlet property="showPreviewButton" destination="X23-Hi-l4l" id="Wsk-ma-mkU"/>
<outlet property="textOrientationSwitch" destination="1QS-Jy-1dl" id="eD6-x9-lrn"/>
<outlet property="translucencyToggle" destination="DDY-zH-Cfe" id="bKy-IZ-8CU"/>
<outlet property="windowAlphaField" destination="FtX-BV-c6q" id="0sg-z6-YA0"/>
</connections>
</viewController>
Expand Down
67 changes: 60 additions & 7 deletions Squirrel Designer/LayoutModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,35 @@

import AppKit

extension NSBezierPath {

var cgPath: CGPath {
let path = CGMutablePath()
var points = [CGPoint](repeating: .zero, count: 3)
for i in 0 ..< self.elementCount {
let type = self.element(at: i, associatedPoints: &points)

switch type {
case .moveTo:
path.move(to: points[0])

case .lineTo:
path.addLine(to: points[0])

case .curveTo:
path.addCurve(to: points[2], control1: points[0], control2: points[1])

case .closePath:
path.closeSubpath()

@unknown default:
break
}
}
return path
}
}

class SquirrelLayout {
static var template: String?

Expand All @@ -31,6 +60,7 @@ class SquirrelLayout {
var vertical = false
var inlinePreedit = false
var isDisplayP3 = true
var translucency = false

var fonts: Array<NSFont> = [NSFont.userFont(ofSize: 15)!]
var labelFonts = Array<NSFont>()
Expand Down Expand Up @@ -184,6 +214,7 @@ class SquirrelLayout {
encoded += "candidate_list_layout: \(linear ? "linear" : "stacked")\n"
encoded += "text_orientation: \(vertical ? "vertical" : "horizontal")\n"
encoded += "inline_preedit: \(inlinePreedit ? "true" : "false")\n"
encoded += "translucency: \(translucency)\n"
if cornerRadius != 0 {
encoded += "corner_radius: \(cornerRadius)\n"
}
Expand Down Expand Up @@ -343,6 +374,7 @@ class SquirrelLayout {
vertical = getBool(values["vertical"])
}
let inlinePreedit = getBool(values["inline_preedit"])
let translucency = getBool(values["translucency"])
let name = values["name"]
let cornerRadius = getFloat(values["corner_radius"])
let hilitedCornerRadius = getFloat(values["hilited_corner_radius"])
Expand Down Expand Up @@ -383,6 +415,7 @@ class SquirrelLayout {
self.linear = linear ?? false
self.vertical = vertical ?? false
self.inlinePreedit = inlinePreedit ?? false
self.translucency = translucency ?? false
self.isDisplayP3 = isDisplayP3
self.backgroundColor = backgroundColor ?? NSColor.windowBackgroundColor
self.candidateTextColor = candidateTextColor ?? NSColor.controlTextColor
Expand Down Expand Up @@ -421,6 +454,7 @@ func blendColor(foregroundColor: NSColor, backgroundColor: NSColor?) -> NSColor
}

class SquirrelView: NSView {
var shape: CAShapeLayer = CAShapeLayer()
private var _layout: SquirrelLayout
private let _text: NSTextStorage
private var _highlightedRange = NSMakeRange(NSNotFound, 0)
Expand Down Expand Up @@ -861,6 +895,7 @@ class SquirrelView: NSView {

NSBezierPath.defaultLineWidth = 0
backgroundPath = drawSmoothLines(vertex(ofRect: backgroundRect), alpha: 0.3*_layout.cornerRadius, beta: 1.4*_layout.cornerRadius)
shape.path = backgroundPath?.cgPath
// Nothing should extend beyond backgroundPath
borderPath = backgroundPath?.copy() as? NSBezierPath
borderPath?.addClip()
Expand Down Expand Up @@ -928,6 +963,7 @@ class SquirrelPanel: NSWindow {
static let kOffsetHeight: CGFloat = 5
private var _position: NSRect
private let _view: SquirrelView
private let _back: NSVisualEffectView
private var _preeditRange = NSMakeRange(NSNotFound, 0)
private var _screenRect = NSZeroRect
private var _maxHeight: CGFloat = 0
Expand All @@ -946,12 +982,22 @@ class SquirrelPanel: NSWindow {
init(position: NSRect) {
_position = position
_view = SquirrelView(frame: position)
let blurView = NSVisualEffectView()
blurView.blendingMode = .behindWindow
blurView.material = .hudWindow
blurView.state = .active
blurView.wantsLayer = true
blurView.layer!.mask = _view.shape
_back = blurView
super.init(contentRect: position, styleMask: .borderless, backing: .buffered, defer: true)
self.alphaValue = 1
self.hasShadow = true
self.isOpaque = false
self.backgroundColor = .clear
self.contentView = _view
let contentView = NSView()
self.contentView = contentView
contentView.addSubview(_back)
contentView.addSubview(_view)
self.isMovableByWindowBackground = true
}

Expand Down Expand Up @@ -1068,16 +1114,23 @@ class SquirrelPanel: NSWindow {
if NSMinY(windowRect) < NSMinY(_screenRect) {
windowRect.origin.y = NSMinY(_screenRect)
}
self.alphaValue = self.layout.alpha
self.setFrame(windowRect, display: true)
// rotate the view, the core in vertical mode!
if self.layout.vertical {
_view.boundsRotation = 90.0
_view.setBoundsOrigin(NSMakePoint(0, windowRect.size.width))
self.contentView?.boundsRotation = -90.0
self.contentView?.setBoundsOrigin(NSMakePoint(0, windowRect.size.width))
} else {
_view.boundsRotation = 0
_view.setBoundsOrigin(NSMakePoint(0, 0))
self.contentView?.boundsRotation = 0
self.contentView?.setBoundsOrigin(NSMakePoint(0, 0))
}
_view.frame = _view.superview!.bounds
if layout.translucency {
_back.frame = _back.superview!.bounds
_back.isHidden = false
} else {
_back.isHidden = true
}
self.alphaValue = self.layout.alpha
self.setFrame(windowRect, display: true)
self.invalidateShadow()
self.orderFront(nil)
self._visible = true
Expand Down
6 changes: 6 additions & 0 deletions Squirrel Designer/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class ViewController: NSViewController {
@IBOutlet weak var hilitedLabelTextColorToggle: NSSwitch!
@IBOutlet weak var hilitedLabelTextColorPicker: NSColorWell!
@IBOutlet weak var colorSpacePicker: NSPopUpButton!
@IBOutlet weak var translucencyToggle: NSSwitch!

@IBOutlet weak var borderHeightField: NSTextField!
@IBOutlet weak var borderWidthField: NSTextField!
Expand Down Expand Up @@ -359,6 +360,10 @@ class ViewController: NSViewController {
}
preview.layout = layout
}
@IBAction func translucencyToggled(_ sender: Any) {
layout.translucency = translucencyToggle.state == .on
preview.layout = layout
}

@IBAction func candidateListLayoutToggled(_ sender: Any) {
layout.linear = candidateListLayoutSwitch.selectedSegment == 1
Expand Down Expand Up @@ -853,6 +858,7 @@ class ViewController: NSViewController {
hilitedLabelTextColorPicker.color = blendColor(foregroundColor: hilitedCandidateTextColorPicker.color, backgroundColor: hilitedCandidateBackColorPicker.color)
layout.highlightedCandidateLabelColor = hilitedLabelTextColorPicker.color
}
translucencyToggle.state = layout.translucency ? .on : .off

borderHeightField.stringValue = "\(layout.borderHeight)"
borderWidthField.stringValue = "\(layout.borderWidth)"
Expand Down
3 changes: 3 additions & 0 deletions Squirrel Designer/zh-Hans.lproj/Main.strings
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@
/* Class = "NSTextFieldCell"; title = "Colorspace"; ObjectID = "GFQ-yL-V2f"; */
"GFQ-yL-V2f.title" = "色空间";

/* Class = "NSTextFieldCell"; title = "Translucency "; ObjectID = "pT7-cp-v6P"; */
"pT7-cp-v6P.title" = "磨砂";

/* Class = "NSMenuItem"; title = "Use Default"; ObjectID = "GUa-eO-cwY"; */
"GUa-eO-cwY.title" = "默认";

Expand Down
3 changes: 3 additions & 0 deletions Squirrel Designer/zh-Hant.lproj/Main.strings
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@
/* Class = "NSTextFieldCell"; title = "Colorspace"; ObjectID = "GFQ-yL-V2f"; */
"GFQ-yL-V2f.title" = "色空間";

/* Class = "NSTextFieldCell"; title = "Translucency "; ObjectID = "pT7-cp-v6P"; */
"pT7-cp-v6P.title" = "磨砂";

/* Class = "NSMenuItem"; title = "Use Default"; ObjectID = "GUa-eO-cwY"; */
"GUa-eO-cwY.title" = "默認";

Expand Down

2 comments on commit 40e3b53

@GJRobert
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that You have pushed the translucency support for Squirrel in Oct 2021, but not merged yet, so this great translucency is in Squirrel Designer already but not in Squirrel itself, am I catching it right?

@LEOYoon-Tsaw
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s in my forked version of squirrel

Please sign in to comment.