Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Left Container View를 Develop합니다. #75

Merged
merged 15 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 60 additions & 25 deletions Box42.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions Box42/BoxWindowController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// BoxWindowController.swift
// Box42
//
// Created by Chanhee Kim on 8/11/23.
//

import Cocoa

class BoxWindowController: NSWindowController, NSWindowDelegate {
override init(window: NSWindow?) {
let contentRect = BoxSizeManager.shared.boxViewSizeNSRect
let styleMask: NSWindow.StyleMask = [.resizable, .titled, .fullSizeContentView, .closable, .miniaturizable]
let windowInstance = NSWindow(contentRect: contentRect, styleMask: styleMask, backing: .buffered, defer: false)
super.init(window: windowInstance)
windowInstance.delegate = self

windowInstance.title = "Box"
windowInstance.titlebarAppearsTransparent = true
windowInstance.titleVisibility = .hidden
windowInstance.isReleasedWhenClosed = false
windowInstance.isMovableByWindowBackground = true

let boxViewController = BoxBaseContainerViewController(nibName: nil, bundle: nil)
windowInstance.contentViewController = boxViewController
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

extension BoxWindowController {
func windowWillClose(_ notification: Notification) {
StateManager.shared.showWindow = false
}

func windowWillMiniaturize(_ notification: Notification) {
StateManager.shared.showWindow = false
}
}
35 changes: 35 additions & 0 deletions Box42/ButtonGroup/ButtonGroupViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// ButtonGroupViewController.swift
// Box42
//
// Created by Chanhee Kim on 8/25/23.
//

import Cocoa

class ButtonGroupViewController: NSViewController {
override func loadView() {
// let ButtonViewGroup = BoxButtonViewGroup()
let ButtonViewGroup = NSView()
ButtonViewGroup.wantsLayer = true
ButtonViewGroup.layer?.backgroundColor = NSColor.black.cgColor
self.view = ButtonViewGroup
}

override func viewDidLoad() {
super.viewDidLoad()
}

func preference() {
print("preference")
}

func pin() {
print("pin")
}

func quit() {
print("quit")
NSApplication.shared.terminate(self)
}
}
30 changes: 30 additions & 0 deletions Box42/Extensions/HexValue+NSColor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// NSColor.swift
// Box42
//
// Created by Chanhee Kim on 8/24/23.
//

import AppKit

extension NSColor {
convenience init(hex: String) {
let hex = hex.trimmingCharacters(in: CharacterSet.alphanumerics.inverted)
var int: UInt64 = 0

Scanner(string: hex).scanHexInt64(&int)
let a, r, g, b: UInt64
switch hex.count {
case 3: // RGB (12-bit)
(a, r, g, b) = (255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17)
case 6: // RGB (24-bit)
(a, r, g, b) = (255, int >> 16, int >> 8 & 0xFF, int & 0xFF)
case 8: // ARGB (32-bit)
(a, r, g, b) = (int >> 24, int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF)
default:
(a, r, g, b) = (255, 0, 0, 0)
}

self.init(red: CGFloat(r) / 255, green: CGFloat(g) / 255, blue: CGFloat(b) / 255, alpha: CGFloat(a) / 255)
}
}
10 changes: 8 additions & 2 deletions Box42/Extensions/NSScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import Cocoa
extension NSScreen {
static let screenSize = NSScreen.main?.visibleFrame.size
static let screenWidth = screenSize!.width
static let screenHeight = screenSize!.height
static let screenHeight = screenSize!.height - 60
static let halfOfScreen = (x: screenWidth / 2, y: screenHeight / 2)
static let customScreenSize = (x: CGFloat(900), y: screenHeight - 132)
static let contentsScreenSize = CGSize(width: CGFloat(768), height: screenHeight)
static let buttonGroupSize = CGSize(width: CGFloat(200), height: screenHeight)
static let customScreenSize = contentsScreenSize + buttonGroupSize
}

func +(left: CGSize, right: CGSize) -> CGSize {
return CGSize(width: left.width + right.width, height: left.height)
}
7 changes: 7 additions & 0 deletions Box42/FunctionButton/BoxFunctionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ class BoxFunctionViewController: NSViewController {
NSApplication.shared.terminate(self)
}

weak var delegate: BoxFunctionViewControllerDelegate?

func box() {
print("box")
delegate?.didTapBoxButton()
}
}

protocol BoxFunctionViewControllerDelegate: AnyObject {
func didTapBoxButton()
}
4 changes: 3 additions & 1 deletion Box42/FunctionButton/View/BoxFunctionButtonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class BoxFunctionButtonView: NSButton {
super.init(frame: .zero)

self.image = image
self.bezelStyle = .texturedRounded
self.isBordered = false // 버튼의 테두리를 제거
self.wantsLayer = true
self.layer?.backgroundColor = NSColor.clear.cgColor
self.target = self
self.action = #selector(BoxFunction)
self.callback = completion
Expand Down
4 changes: 3 additions & 1 deletion Box42/FunctionButton/View/PinButtonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class PinButtonView: NSButton {
super.init(frame: .zero)

self.image = image
self.bezelStyle = .texturedRounded
self.isBordered = false // 버튼의 테두리를 제거
self.wantsLayer = true
self.layer?.backgroundColor = NSColor.clear.cgColor
self.target = self
self.action = #selector(pin)
self.callback = completion
Expand Down
4 changes: 3 additions & 1 deletion Box42/FunctionButton/View/PreferenceButtonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ class PreferenceButtonView: NSButton {
init(image: NSImage, completion: @escaping () -> Void) {
super.init(frame: .zero)
self.image = image
self.bezelStyle = .texturedRounded
self.isBordered = false // 버튼의 테두리를 제거
self.wantsLayer = true
self.layer?.backgroundColor = NSColor.clear.cgColor
self.target = self
self.action = #selector(preference)
self.callback = completion
Expand Down
4 changes: 3 additions & 1 deletion Box42/FunctionButton/View/QuitButtonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class QuitButtonView: NSButton {
super.init(frame: .zero)

self.image = image
self.bezelStyle = .texturedRounded
self.isBordered = false // 버튼의 테두리를 제거
self.wantsLayer = true
self.layer?.backgroundColor = NSColor.clear.cgColor
self.target = self
self.action = #selector(QuitButton)
self.callback = completion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,27 @@ class BoxBaseContainerViewController: NSViewController {
var contentGroup: BoxContentsViewGroup = BoxContentsViewGroup()
var toolbarGroupVC: ToolbarViewController = ToolbarViewController()
var functionGroupVC: BoxFunctionViewController = BoxFunctionViewController()
let windowViewGroup: WindowButtonViewController = WindowButtonViewController()
var buttonGroup: BoxButtonViewGroup!
var leftContainer: MovableContainerView!

let windowViewGroupVC: WindowButtonViewController = WindowButtonViewController()
var leftContainer: MovableContainerView = MovableContainerView()
var buttonGroupVC: ButtonGroupViewController = ButtonGroupViewController()
weak var menubarVCDelegate: MenubarViewControllerDelegate? // extension

override func loadView() {
self.view = NSView()
// self.view.wantsLayer = true
// self.view.layer?.backgroundColor = NSColor.red.cgColor
self.view.addSubview(splitView)
splitView.delegate = self

buttonGroup = BoxButtonViewGroupInit()

// buttonGroup = BoxButtonViewGroupInit()

leftContainerInit()
viewInit()
}

override func viewDidLoad() {
self.view.wantsLayer = true
self.view.layer?.backgroundColor = NSColor(hex: "#FF9548").cgColor
}

func BoxButtonViewGroupInit() -> BoxButtonViewGroup {

let buttonGroup = BoxButtonViewGroup { sender in
Expand All @@ -40,56 +43,70 @@ class BoxBaseContainerViewController: NSViewController {
return buttonGroup
}

func clickBtn(sender: NSButton) {
guard let clickCount = NSApp.currentEvent?.clickCount else { return }
if clickCount == 2 {
WebViewManager.shared.list[sender.title]!.reload()
print("Dobule Click")
} else if clickCount > 2 {
if let currentURL = WebViewManager.shared.hostingWebView?.url {
NSWorkspace.shared.open(currentURL)
func clickBtn(sender: Any?) {
if let button = sender as? NSButton {
guard let clickCount = NSApp.currentEvent?.clickCount else { return }
if clickCount == 2 {
WebViewManager.shared.list[button.title]!.reload()
print("Dobule Click")
} else if clickCount > 2 {
if let currentURL = WebViewManager.shared.hostingWebView?.url {
NSWorkspace.shared.open(currentURL)
}
print("Triple Click")
} else if clickCount < 2 {
contentGroup.removeAllSubviews()
contentGroup.showWebviews(button)
}
} else {
if let str = sender as? String {
if str == "box" {
contentGroup.removeAllSubviews()
print("box inside")
}
}
print("Triple Click")
} else if clickCount < 2 {
contentGroup.removeAllSubviews()
contentGroup.showWebviews(sender)
}
}

private func leftContainerInit() {
leftContainer = MovableContainerView()
leftContainer.addSubview(buttonGroup)
leftContainer.addSubview(windowViewGroup.view)
leftContainer.frame.size.width = BoxSizeManager.shared.windowButtonGroupSize.width
leftContainer.frame.size.height = BoxSizeManager.shared.windowButtonGroupSize.height
// leftContainer.addSubview(windowViewGroupVC.view)
leftContainer.addSubview(buttonGroupVC.view)
leftContainer.addSubview(toolbarGroupVC.view)
leftContainer.addSubview(functionGroupVC.view)

leftContainerAutolayout()
leftContainer.frame.size.width = BoxSizeManager.shared.windowButtonGroupSize.width
}

private func leftContainerAutolayout() {
windowViewGroup.view.snp.makeConstraints { make in
make.top.equalTo(leftContainer).offset(Constants.UI.GroupAutolayout)
make.right.equalTo(leftContainer).offset(-Constants.UI.GroupAutolayout)
make.left.equalTo(leftContainer)
}
// windowViewGroupVC.view.snp.makeConstraints { make in
// make.top.equalTo(leftContainer)
// make.left.equalTo(leftContainer).offset(3)
// make.width.equalTo(77)
// make.height.equalTo(21)
// }

toolbarGroupVC.view.snp.makeConstraints { make in
make.top.equalTo(windowViewGroup.view.snp.bottom).offset(Constants.UI.GroupAutolayout)
make.right.equalTo(leftContainer).offset(-Constants.UI.GroupAutolayout)
make.left.equalTo(leftContainer)
}

buttonGroup.snp.makeConstraints { make in
make.top.equalTo(toolbarGroupVC.view.snp.bottom).offset(Constants.UI.GroupAutolayout)
make.right.equalTo(leftContainer).offset(-Constants.UI.GroupAutolayout)
// make.top.equalTo(windowViewGroupVC.view.snp.bottom).offset(31)
make.top.equalTo(leftContainer).offset(31) // wVGVC 없으면
make.right.equalTo(leftContainer)
make.left.equalTo(leftContainer)
make.height.equalTo(44 + 14 + 24)
}

functionGroupVC.view.snp.makeConstraints { make in
make.top.equalTo(buttonGroup.snp.bottom).offset(Constants.UI.GroupAutolayout)
make.right.equalTo(leftContainer).offset(-Constants.UI.GroupAutolayout)
// make.top.equalTo(buttonGroup.snp.bottom).offset(Constants.UI.groupAutolayout)
make.right.equalTo(leftContainer).offset(-Constants.UI.groupAutolayout)
make.left.bottom.equalTo(leftContainer)
}

buttonGroupVC.view.snp.makeConstraints { make in
make.top.equalTo(toolbarGroupVC.view.snp.bottom).offset(Constants.UI.groupAutolayout)
make.right.equalTo(leftContainer).offset(-Constants.UI.groupAutolayout)
make.left.equalTo(leftContainer)
make.bottom.equalTo(functionGroupVC.view.snp.top).offset(-Constants.UI.groupAutolayout)
}
}

func viewInit() {
Expand All @@ -100,10 +117,10 @@ class BoxBaseContainerViewController: NSViewController {
self.view.addSubview(splitView)

splitView.snp.makeConstraints { make in
make.top.equalTo(self.view).offset(Constants.UI.GroupAutolayout)
make.left.equalTo(self.view).offset(Constants.UI.GroupAutolayout)
make.right.equalTo(self.view).offset(-Constants.UI.GroupAutolayout)
make.bottom.equalTo(self.view).offset(-Constants.UI.GroupAutolayout)
make.top.equalToSuperview().offset(Constants.UI.groupAutolayout)
make.left.equalToSuperview().offset(Constants.UI.groupAutolayout)
make.right.equalToSuperview().offset(-Constants.UI.groupAutolayout)
make.bottom.equalToSuperview().offset(-Constants.UI.groupAutolayout)
}
}

Expand Down Expand Up @@ -140,3 +157,9 @@ extension BoxBaseContainerViewController: NSSplitViewDelegate {
contentGroup.frame = NSRect(x: leftWidth + dividerThickness, y: 0, width: contentWidth, height: splitView.bounds.height)
}
}

extension BoxBaseContainerViewController: BoxFunctionViewControllerDelegate {
func didTapBoxButton() {
clickBtn(sender: "box")
}
}
Loading