Skip to content

Commit

Permalink
Merge pull request #22 from AdAstraCA/main
Browse files Browse the repository at this point in the history
Variety of Issue Fixes(Size adjustments, Rectangle Filter, gitignore, sfx)
  • Loading branch information
truedat101 authored Jan 28, 2023
2 parents 1d7f7e0 + 91792d5 commit fd23016
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 55 deletions.
5 changes: 3 additions & 2 deletions Shared/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
import SwiftUI

struct Constant {
static var num = 116
static var sizeWidthPreview: CGFloat = 150
static var num: Int = 116
static var height: Int = 180
static var sizeWidthPreview: CGFloat = 150
static var minSizeShape: CGFloat = 5
static var borderWidth: CGFloat = 2
}
151 changes: 115 additions & 36 deletions Shared/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
// Shared
//
// Created by Delta on 24/5/22.
// Edited by Astra on 1/8/23.
// Edited by Astra on 1/27/23.
//

import AVFoundation
import SwiftUI

var swipePreview = true
var chosenColor = 1.0
var swipePreview = true;
var chosenColor = 1.0;

struct ContentView: View {
var body: some View {
Expand All @@ -29,7 +29,8 @@ struct CameraView: View{
FilterModel(filter: .circle, isPreview: true, color: chosenColor),
FilterModel(filter: .rectangle, isPreview: true, color: abs(chosenColor - 1.0)),
FilterModel(filter: .lines, isPreview: true, color: abs(chosenColor - 1.0)),
FilterModel(filter: .start, isPreview: true, color: chosenColor)
FilterModel(filter: .start, isPreview: true, color: chosenColor),
FilterModel(filter: .horizontal, isPreview: true, color: abs(chosenColor - 1.0))
]
@StateObject var camera = CameraModel()
@StateObject var viewModel = ViewModel()
Expand All @@ -47,7 +48,57 @@ struct CameraView: View{
}
}.onAppear {
camera.Check()
}.frame(width: geometry.size.width, height: geometry.size.height / 1.4, alignment: .center).clipped()
}.frame(width: geometry.size.width, height: geometry.size.height / 1.6, alignment: .center).clipped()
HStack{

// if taken showing save and again take button...

if camera.isTaken{
Spacer()

Button(action: camera.reTake, label: {

Image(systemName: "arrow.triangle.2.circlepath.camera")
.foregroundColor(.black)
.padding()
.background(Color.white)
.clipShape(Circle())
})
.padding(.trailing,10)

Spacer()

Button(action: {if !camera.isSaved{camera.savePic()}}, label: {
Text(camera.isSaved ? "Saved" : "Save")
.foregroundColor(.black)
.fontWeight(.semibold)
.padding(.vertical,10)
.padding(.horizontal,20)
.background(Color.white)
.clipShape(Capsule())
})
.padding(.leading)

Spacer()
}
else{

Button(action: camera.takePic, label: {

ZStack{

Circle()
.fill(Color.white)
.frame(width: 65, height: 65)

Circle()
.stroke(Color.white,lineWidth: 2)
.frame(width: 75, height: 75)
}
})
}
}
.frame(height: 75)
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(filtersPreview,id: \.filter) { filterPreview in
Expand Down Expand Up @@ -85,44 +136,16 @@ struct CameraView: View{
}
}

struct TakePictureButton: View {
var isTaken: Bool
var body: some View {
VStack{
HStack{
if isTaken {
Button(action: {}, label: {

//todo
})
}else{
Button(action: {
//todo
}, label:
{
ZStack{
Circle()
.fill(Color.white)
.frame(width: 65, height: 65, alignment: .center)
Circle()
.stroke(Color.white, lineWidth: 2)
.frame(width: 75, height: 75, alignment: .center)
}
})
}
}
}
}
}

//camera model

class CameraModel: ObservableObject{
class CameraModel: NSObject, ObservableObject, AVCapturePhotoCaptureDelegate{
@Published var isTaken = false
@Published var session = AVCaptureSession()
@Published var alert = false
@Published var isSaved = false
@Published var output = AVCapturePhotoOutput()
@Published var preview: AVCaptureVideoPreviewLayer!
@Published var picData = Data(count: 0)

func Check(){
switch AVCaptureDevice.authorizationStatus(for: .video){
Expand Down Expand Up @@ -173,6 +196,62 @@ class CameraModel: ObservableObject{
print(error.localizedDescription)
}
}

//take and retake photos

func takePic(){

self.output.capturePhoto(with: AVCapturePhotoSettings(), delegate: self)

DispatchQueue.global(qos: .background).async {

self.session.stopRunning()

DispatchQueue.main.async {
withAnimation{self.isTaken.toggle()}
}
}
}

func reTake(){

DispatchQueue.global(qos: .background).async {

self.session.startRunning()

DispatchQueue.main.async {
withAnimation{self.isTaken.toggle()}
//clearing ...
self.isSaved = false
self.picData = Data(count: 0)
}
}
}

func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {

if error != nil{
return
}

print("pic taken...")

guard let imageData = photo.fileDataRepresentation() else{return}

self.picData = imageData
}

func savePic(){

guard let image = UIImage(data: self.picData) else{return}

// saving Image...
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)

self.isSaved = true

print("saved Successfully....")
}
}

// setting view for preview
Expand Down
9 changes: 5 additions & 4 deletions Shared/FCircle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@ struct FCircle: View{

init(isPreview: Bool, color: Double) {
self.isPreview = isPreview
self.numShapes = Constant.num / (isPreview ? 3 : 1)
self.numShapes = Constant.num / (isPreview ? 2 : 1)
self.color = color
}

var body: some View{
ZStack(alignment: .center){
ForEach(Array(stride(from: 0, to: numShapes, by: 4)), id: \.self) { i in
ForEach(Array(stride(from: 0, to: numShapes, by: 5)), id: \.self) { i in
Circle()
.stroke(Color(white: color), lineWidth: Constant.borderWidth)
.frame(
width: Constant.minSizeShape + (CGFloat(i) * 4),
height: Constant.minSizeShape + (CGFloat(i) * 4),
width: Constant.minSizeShape + (CGFloat(i) * (isPreview ? 2 : 3)) + (isPreview ? 20 : 0),
height: Constant.minSizeShape + (CGFloat(i) * (isPreview ? 2 : 3)) + (isPreview ? 20 : 0),
alignment: .center)
}
}
}
}

33 changes: 33 additions & 0 deletions Shared/FHorizontal.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// FHorizontal.swift
// MoireLens (iOS)
//
// Created by EJiii on 1/18/23.
//

import SwiftUI

struct FHorizontal: View{
var isPreview = false
var color = 0.0
var scale: Int
init(isPreview: Bool, color: Double) {
self.isPreview = isPreview
self.scale = isPreview ? 4 : 10
self.color = color
}
var body: some View{
GeometryReader { geometry in
VStack{
ForEach(0..<Constant.height, id: \.self) { i in
Rectangle()
.fill(Color(white: color))
.frame(
width: Constant.sizeWidthPreview * 3,
height: Constant.borderWidth)
Spacer()
}
}
}
}
}
5 changes: 3 additions & 2 deletions Shared/FReactangle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ struct FReactngle: View{
Rectangle()
.stroke(Color(white: color), lineWidth: Constant.borderWidth)
.frame(
width: Constant.minSizeShape + (CGFloat(i) * 4),
height: Constant.minSizeShape + (CGFloat(i) * 4),
width: Constant.minSizeShape + (CGFloat(i) * 3),
height: Constant.minSizeShape + (CGFloat(i) * 3),
alignment: .center)
}
}
}
}

7 changes: 5 additions & 2 deletions Shared/Filter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Filter.swift
// MoireLens (iOS)
//
// Created by Delta on 11/7/22
// Edited by Astra on 1/8/23
// Created by Delta on 11/7/22.
// Edited by Astra on 1/8/23.
//

import SwiftUI
Expand All @@ -13,6 +13,7 @@ enum FILTERS {
case circle
case start
case lines
case horizontal
}

struct Filter: View {
Expand All @@ -34,6 +35,8 @@ struct Filter: View {
FLines(isPreview: data.isPreview, color: data.color)
case .start:
FStart(isPreview: data.isPreview, color: data.color)
case .horizontal:
FHorizontal(isPreview: data.isPreview, color: data.color)
}
}.frame(width: geometry.size.width, height: geometry.size.height, alignment: .center)
}
Expand Down
Binary file added Shared/mixkit-camera-shutter-click-1133.wav
Binary file not shown.
9 changes: 0 additions & 9 deletions addition

This file was deleted.

Loading

0 comments on commit fd23016

Please sign in to comment.