Skip to content
Open
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
Binary file not shown.
16 changes: 14 additions & 2 deletions inductionApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
2F945183244FFF7F009521F7 /* pdf_sat-practice-test-1.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 2F945182244FFF7F009521F7 /* pdf_sat-practice-test-1.pdf */; };
2F9451852450009D009521F7 /* josh.jpeg in Resources */ = {isa = PBXBuildFile; fileRef = 2F9451842450009D009521F7 /* josh.jpeg */; };
2F9C109C244F693100A7C6FF /* AppRootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2F9C109B244F693100A7C6FF /* AppRootView.swift */; };
2FAB7857245149570038DCF4 /* CanvasRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FAB7856245149570038DCF4 /* CanvasRepresentable.swift */; };
2FEEE3FF2450B5B0003DE2BD /* AnswerSheetRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FEEE3FE2450B5B0003DE2BD /* AnswerSheetRow.swift */; };
2FEEE4012450B94C003DE2BD /* AnswerSheetList.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2FEEE4002450B94C003DE2BD /* AnswerSheetList.swift */; };
D9DE365D4A1ADBF66FB1DE56 /* Pods_InductionApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7153C925F845E1499489472E /* Pods_InductionApp.framework */; };
Expand All @@ -47,6 +48,7 @@
2F945182244FFF7F009521F7 /* pdf_sat-practice-test-1.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = "pdf_sat-practice-test-1.pdf"; sourceTree = "<group>"; };
2F9451842450009D009521F7 /* josh.jpeg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = josh.jpeg; sourceTree = "<group>"; };
2F9C109B244F693100A7C6FF /* AppRootView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppRootView.swift; path = InductionApp/AppRootView.swift; sourceTree = SOURCE_ROOT; };
2FAB7856245149570038DCF4 /* CanvasRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CanvasRepresentable.swift; path = InductionApp/CanvasRepresentable.swift; sourceTree = SOURCE_ROOT; };
2FEEE3FE2450B5B0003DE2BD /* AnswerSheetRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AnswerSheetRow.swift; path = InductionApp/AnswerSheetRow.swift; sourceTree = SOURCE_ROOT; };
2FEEE4002450B94C003DE2BD /* AnswerSheetList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AnswerSheetList.swift; path = InductionApp/AnswerSheetList.swift; sourceTree = SOURCE_ROOT; };
7153C925F845E1499489472E /* Pods_InductionApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_InductionApp.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -89,15 +91,15 @@
children = (
03BEBC4C244E7B69001576EC /* AppDelegate.swift */,
03BEBC4E244E7B69001576EC /* SceneDelegate.swift */,
03BEBC50244E7B69001576EC /* ContentView.swift */,
2FAB784C245135490038DCF4 /* Login and Signup */,
2F945180244FFA33009521F7 /* TestView.swift */,
2FEEE3FE2450B5B0003DE2BD /* AnswerSheetRow.swift */,
2FAB7856245149570038DCF4 /* CanvasRepresentable.swift */,
2FEEE4002450B94C003DE2BD /* AnswerSheetList.swift */,
2F945182244FFF7F009521F7 /* pdf_sat-practice-test-1.pdf */,
2F9C109B244F693100A7C6FF /* AppRootView.swift */,
2F0DD2C7244F5F3D00AFFADE /* UserModel.swift */,
2F0DD2C9244F5F6300AFFADE /* TestModel.swift */,
038753F7244E9AA900F85970 /* LoginView.swift */,
038753F9244E9AC800F85970 /* UserHomepageView.swift */,
2F9451842450009D009521F7 /* josh.jpeg */,
03BEBC52244E7B6A001576EC /* Assets.xcassets */,
Expand All @@ -118,6 +120,15 @@
path = "Preview Content";
sourceTree = "<group>";
};
2FAB784C245135490038DCF4 /* Login and Signup */ = {
isa = PBXGroup;
children = (
03BEBC50244E7B69001576EC /* ContentView.swift */,
038753F7244E9AA900F85970 /* LoginView.swift */,
);
path = "Login and Signup";
sourceTree = "<group>";
};
8AB41C41DEDE2DE06E9D7DE1 /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -277,6 +288,7 @@
2F0DD2CA244F5F6300AFFADE /* TestModel.swift in Sources */,
03BEBC4D244E7B69001576EC /* AppDelegate.swift in Sources */,
2FEEE4012450B94C003DE2BD /* AnswerSheetList.swift in Sources */,
2FAB7857245149570038DCF4 /* CanvasRepresentable.swift in Sources */,
2FEEE3FF2450B5B0003DE2BD /* AnswerSheetRow.swift in Sources */,
03BEBC4F244E7B69001576EC /* SceneDelegate.swift in Sources */,
2F945181244FFA33009521F7 /* TestView.swift in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions inductionApp/AnswerSheetRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ struct AnswerSheetRow: View {

var body: some View {
VStack{


HStack{
Text("A")
Spacer()
Expand Down
41 changes: 41 additions & 0 deletions inductionApp/CanvasRepresentable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// DrawingPadRepresentation.swift
// InductionApp
//
// Created by Ben Altschuler on 4/22/20.
// Copyright © 2020 Josh Breite. All rights reserved.
//

import Foundation
import SwiftUI
import PencilKit


struct CanvasRepresentable: UIViewRepresentable {
@Binding var canvasToDraw: PKCanvasView

// class Coordinator: NSObject {
// @Binding var canvasToDraw: PKCanvasView?
//
// init(canvasToDraw: Binding<UIImage?>){
// _canvasToDraw = canvasToDraw
// }
//
//// @objc func drawingImageChanged(_ sender: CanvasView) {
//// self.drawingImage = sender.drawingImage
//// }
// }

func makeUIView(context: Context) -> PKCanvasView {
let c = PKCanvasView()
c.isOpaque = false
c.allowsFingerDrawing = true
return c
}

func updateUIView(_ uiView: PKCanvasView, context: Context) {

}


}
89 changes: 89 additions & 0 deletions inductionApp/CanvasView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//
// CanvasView.swift
// InductionApp
//
// Created by Ben Altschuler on 4/22/20.
// Copyright © 2020 Josh Breite. All rights reserved.
//

import Foundation
import UIKit
import PencilKit

class CanvasView: UIControl, PKCanvasViewDelegate {
var drawingImage: UIImage?
private let defaultLineWidth: CGFloat = 0.5
private let minLineWidth: CGFloat = 0.4
private let forceSensitivity: CGFloat = 1

var canvasViewPK: PKCanvasView

init(drawingImage: UIImage?) {
self.drawingImage = drawingImage
self.canvasViewPK = PKCanvasView()

super.init(frame: .zero)
self.addSubview(self.canvasViewPK)
}

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

override func didMoveToWindow() {
canvasViewPK.delegate = self
print("BEN")
canvasViewPK.drawing = PKDrawing()
canvasViewPK.allowsFingerDrawing = false
}

// MARK: Canvas View Delegate

/// Delegate method: Note that the drawing has changed.
func canvasViewDrawingDidChange(_ canvasView: PKCanvasView) {
print("Drawing Canvas View Drawing Did Change")

}

override func draw(_ rect: CGRect) {
drawingImage?.draw(in: rect)
}

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
sendActions(for: .valueChanged)
}

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else { return }
drawingImage = UIGraphicsImageRenderer(size: bounds.size).image { context in
UIColor.white.setFill()
context.fill(bounds)
drawingImage?.draw(in: bounds)
var touches = [UITouch]()
if let coalescedTouches = event?.coalescedTouches(for: touch){
touches = coalescedTouches
}else{
touches.append(touch)
}
drawStroke(context: context.cgContext, touch: touch)
setNeedsDisplay()
}
}

private func drawStroke(context: CGContext, touch: UITouch) {
let previousLocation = touch.previousLocation(in: self)
let location = touch.location(in: self)

var lineWidth: CGFloat = defaultLineWidth
if touch.force > 0{
lineWidth = touch.force * forceSensitivity
}
context.setLineWidth(lineWidth)
context.setLineCap(.round)


context.move(to: previousLocation)
context.addLine(to: location)
context.strokePath()
}
}
Loading