Skip to content

Commit

Permalink
Added bezel
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Benzi-Tobar committed Apr 23, 2019
1 parent 254db5a commit 3a75a46
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 24 deletions.
11 changes: 11 additions & 0 deletions TetraVex/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,17 @@
<constraint firstAttribute="width" constant="90" id="mFf-sq-ktO"/>
<constraint firstAttribute="height" constant="90" id="wPv-KD-V0z"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="pieceWidth">
<real key="value" value="90"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="pieceHeight">
<real key="value" value="90"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="insetStrokeLineWidth">
<real key="value" value="3"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</customView>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="eGK-La-Z1J">
<rect key="frame" x="20" y="228" width="90" height="22"/>
Expand Down
61 changes: 38 additions & 23 deletions TetraVex/TVBoardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,45 +36,60 @@ class TVBoardView: NSView {

let path = NSBezierPath(roundedRect: self.bounds, xRadius: 3, yRadius: 3)

NSColor.gray.setFill()
NSColor.lightGray.setFill()
NSColor.black.setStroke()

path.fill()
path.stroke()


guard let model = model else {
return
}

let pathSquare = NSBezierPath(
rect: NSRect(
let pathSquare = NSRect(
x: 0,
y: 0,
width: pieceWidth,
height: pieceHeight)
)

for i in 0..<model.boardWidth {
for j in 0..<model.boardHeight {
drawInsetLine(
CGPoint(x: CGFloat(i+1)*pieceWidth, y: CGFloat(j)*pieceHeight),
to: CGPoint(x: CGFloat(i+1)*pieceWidth, y: CGFloat(j+1)*pieceHeight),
color: .white)
drawInsetLine(
CGPoint(x: CGFloat(i)*pieceWidth, y: CGFloat(j)*pieceHeight),
to: CGPoint(x: CGFloat(i+1)*pieceWidth, y: CGFloat(j)*pieceHeight),
color: .white)

drawInsetLine(
CGPoint(x: CGFloat(i)*pieceWidth, y: CGFloat(j)*pieceHeight),
to: CGPoint(x: CGFloat(i)*pieceWidth, y: CGFloat(j+1)*pieceHeight),
color: .gray)
drawInsetLine(
CGPoint(x: CGFloat(i)*pieceWidth, y: CGFloat(j+1)*pieceHeight),
to: CGPoint(x: CGFloat(i+1)*pieceWidth, y: CGFloat(j+1)*pieceHeight),
color: .gray)
let sqr = pathSquare.offsetBy(dx: CGFloat(i)*pieceWidth,
dy: CGFloat(j)*pieceHeight)
drawPieceBezel(in: sqr)
}
}

path.stroke()
}

func drawPieceBezel(in pathRect:NSRect, outerStrokeLineWidth : CGFloat = 10,
outerStrokeOffset : CGFloat = 2) {

drawInsetLine(NSPoint(x:pathRect.maxX - outerStrokeOffset,
y:pathRect.minY + outerStrokeOffset),
to: NSPoint(x: pathRect.maxX - outerStrokeOffset,
y: pathRect.maxY + outerStrokeOffset),
color: .white,
lineWidth: outerStrokeLineWidth)
drawInsetLine(NSPoint(x:pathRect.minX + outerStrokeOffset,
y:pathRect.minY - outerStrokeOffset),
to: NSPoint(x: pathRect.minX + outerStrokeOffset,
y: pathRect.maxY + outerStrokeOffset),
color: .gray,
lineWidth: outerStrokeLineWidth)
drawInsetLine(NSPoint(x:pathRect.minX - outerStrokeOffset,
y:pathRect.maxY - outerStrokeOffset),
to: NSPoint(x: pathRect.maxX + outerStrokeOffset,
y: pathRect.maxY - outerStrokeOffset),
color: .gray,
lineWidth: outerStrokeLineWidth)
drawInsetLine(NSPoint(x:pathRect.minX + outerStrokeOffset,
y:pathRect.minY + outerStrokeOffset),
to: NSPoint(x: pathRect.maxX - outerStrokeOffset,
y: pathRect.minY + outerStrokeOffset),
color: .white,
lineWidth: outerStrokeLineWidth)
}

func drawInsetLine(_ from: CGPoint, to: CGPoint, color: NSColor, lineWidth:CGFloat = 1) {
Expand All @@ -87,7 +102,7 @@ class TVBoardView: NSView {
}

override func prepareForInterfaceBuilder() {
model = TVBoardModel(width: 2, height: 2)
model = TVBoardModel(width: 1, height: 1)
}

func prepareBoard(with model:TVBoardModel) {
Expand Down
2 changes: 1 addition & 1 deletion TetraVex/TVPieceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class TVPieceView : NSView, NSAccessibilityButton {
y:pathRect.minY + outerStrokeOffset),
to: NSPoint(x: pathRect.maxX - outerStrokeOffset,
y: pathRect.maxY + outerStrokeOffset),
color: .gray,
color: .gray,s
lineWidth: outerStrokeLineWidth)
drawInsetLine(NSPoint(x:pathRect.minX + outerStrokeOffset,
y:pathRect.minY - outerStrokeOffset),
Expand Down

0 comments on commit 3a75a46

Please sign in to comment.