Skip to content

Commit

Permalink
improved ui
Browse files Browse the repository at this point in the history
  • Loading branch information
jmenter committed Mar 31, 2019
1 parent 1159e27 commit e80ef7d
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 36 deletions.
6 changes: 6 additions & 0 deletions Pixelizer.xcodeproj/project.pbxproj
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
630BFD36225103AD00C430A8 /* LabeledSlider.m in Sources */ = {isa = PBXBuildFile; fileRef = 630BFD35225103AD00C430A8 /* LabeledSlider.m */; };
6378EC0721A7122F0071B6A8 /* BoxesScene.m in Sources */ = {isa = PBXBuildFile; fileRef = 6378EC0521A7122F0071B6A8 /* BoxesScene.m */; };
6378EC4721A712B70071B6A8 /* cpSpace.c in Sources */ = {isa = PBXBuildFile; fileRef = 6378EC0921A712B70071B6A8 /* cpSpace.c */; };
6378EC4821A712B70071B6A8 /* cpSpaceStep.c in Sources */ = {isa = PBXBuildFile; fileRef = 6378EC0A21A712B70071B6A8 /* cpSpaceStep.c */; };
Expand Down Expand Up @@ -52,6 +53,8 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
630BFD34225103AD00C430A8 /* LabeledSlider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LabeledSlider.h; sourceTree = "<group>"; };
630BFD35225103AD00C430A8 /* LabeledSlider.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LabeledSlider.m; sourceTree = "<group>"; };
6378EC0521A7122F0071B6A8 /* BoxesScene.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BoxesScene.m; sourceTree = "<group>"; };
6378EC0621A7122F0071B6A8 /* BoxesScene.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BoxesScene.h; sourceTree = "<group>"; };
6378EC0921A712B70071B6A8 /* cpSpace.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = cpSpace.c; sourceTree = "<group>"; };
Expand Down Expand Up @@ -236,6 +239,8 @@
6378EC0821A712B70071B6A8 /* chipmunk */,
63815F6321A6216700AEAE77 /* AppDelegate.h */,
63815F6421A6216700AEAE77 /* AppDelegate.m */,
630BFD34225103AD00C430A8 /* LabeledSlider.h */,
630BFD35225103AD00C430A8 /* LabeledSlider.m */,
63815F6621A6216700AEAE77 /* ViewController.h */,
63815F6721A6216700AEAE77 /* ViewController.m */,
6378EC0621A7122F0071B6A8 /* BoxesScene.h */,
Expand Down Expand Up @@ -357,6 +362,7 @@
6378EC5321A712B70071B6A8 /* cpPinJoint.c in Sources */,
6378EC6621A712B70071B6A8 /* cpHastySpace.c in Sources */,
6378EC5D21A712B70071B6A8 /* cpConstraint.c in Sources */,
630BFD36225103AD00C430A8 /* LabeledSlider.m in Sources */,
6378EC5021A712B70071B6A8 /* cpSweep1D.c in Sources */,
6378EC6521A712B70071B6A8 /* cpSlideJoint.c in Sources */,
6378EC6221A712B70071B6A8 /* cpRotaryLimitJoint.c in Sources */,
Expand Down
Binary file removed Pixelizer/.DS_Store
Binary file not shown.
43 changes: 25 additions & 18 deletions Pixelizer/Base.lproj/Main.storyboard
@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
Expand All @@ -21,50 +21,57 @@
<skView contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="xtN-8W-xyG">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</skView>
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="32" minValue="4" maxValue="64" translatesAutoresizingMaskIntoConstraints="NO" id="ZXn-L9-yih">
<rect key="frame" x="14" y="20" width="153" height="31"/>
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="32" minValue="4" maxValue="64" translatesAutoresizingMaskIntoConstraints="NO" id="ZXn-L9-yih" customClass="LabeledSlider">
<rect key="frame" x="14" y="56" width="347" height="31"/>
<connections>
<action selector="sliderChanged:" destination="BYZ-38-t0r" eventType="valueChanged" id="8fW-UD-x4x"/>
</connections>
</slider>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Dxs-bA-hAn">
<rect key="frame" x="16" y="58" width="343" height="343"/>
<rect key="frame" x="16" y="94" width="343" height="343"/>
<constraints>
<constraint firstAttribute="width" secondItem="Dxs-bA-hAn" secondAttribute="height" multiplier="1:1" id="XSR-f6-DG0"/>
</constraints>
</imageView>
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="1" translatesAutoresizingMaskIntoConstraints="NO" id="gxH-69-w5U">
<rect key="frame" x="191.5" y="20" width="167.5" height="29"/>
<segments>
<segment title="Static"/>
<segment title="Live"/>
</segments>
</segmentedControl>
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="tI9-Ig-FUX">
<rect key="frame" x="173" y="20" width="129" height="29"/>
<rect key="frame" x="16" y="20" width="167.5" height="29"/>
<segments>
<segment title="Squares"/>
<segment title="Circles"/>
</segments>
</segmentedControl>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="7Vn-TV-KzU">
<rect key="frame" x="310" y="20" width="51" height="31"/>
</switch>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="7Vn-TV-KzU" firstAttribute="leading" secondItem="tI9-Ig-FUX" secondAttribute="trailing" constant="8" id="2bJ-Vv-3k6"/>
<constraint firstItem="tI9-Ig-FUX" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="16" id="3BC-jk-UbH"/>
<constraint firstItem="tI9-Ig-FUX" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="4ay-da-mAA"/>
<constraint firstItem="ZXn-L9-yih" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="16" id="J0Y-Qr-ldQ"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="Dxs-bA-hAn" secondAttribute="trailing" constant="16" id="NNI-j1-Dqc"/>
<constraint firstItem="7Vn-TV-KzU" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="Nzb-r7-8Ip"/>
<constraint firstItem="Dxs-bA-hAn" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="16" id="Qf3-dK-UEo"/>
<constraint firstItem="Dxs-bA-hAn" firstAttribute="top" secondItem="ZXn-L9-yih" secondAttribute="bottom" constant="8" id="T5o-TO-6q1"/>
<constraint firstItem="ZXn-L9-yih" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="UEN-lu-RdZ"/>
<constraint firstItem="gxH-69-w5U" firstAttribute="leading" secondItem="tI9-Ig-FUX" secondAttribute="trailing" constant="8" id="UUp-Zc-fsG"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="gxH-69-w5U" secondAttribute="trailing" constant="16" id="WEs-u2-0l7"/>
<constraint firstItem="tI9-Ig-FUX" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="bH6-dH-tme"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="7Vn-TV-KzU" secondAttribute="trailing" constant="16" id="bxy-yy-Cx7"/>
<constraint firstItem="tI9-Ig-FUX" firstAttribute="leading" secondItem="ZXn-L9-yih" secondAttribute="trailing" constant="8" id="ncA-8u-wia"/>
<constraint firstItem="ZXn-L9-yih" firstAttribute="top" secondItem="tI9-Ig-FUX" secondAttribute="bottom" constant="8" id="ftx-Ut-0Zl"/>
<constraint firstItem="tI9-Ig-FUX" firstAttribute="width" secondItem="gxH-69-w5U" secondAttribute="width" id="lX9-on-ykN"/>
<constraint firstItem="6Tk-OE-BBY" firstAttribute="trailing" secondItem="ZXn-L9-yih" secondAttribute="trailing" constant="16" id="mjo-84-hj6"/>
<constraint firstItem="gxH-69-w5U" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" id="o8e-OP-N4h"/>
</constraints>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
<connections>
<outlet property="imageView" destination="Dxs-bA-hAn" id="n6f-ap-7AS"/>
<outlet property="liveColor" destination="7Vn-TV-KzU" id="kBK-Ti-3Rw"/>
<outlet property="segmentedControl" destination="tI9-Ig-FUX" id="jFL-G8-bfC"/>
<outlet property="liveControl" destination="gxH-69-w5U" id="Efx-EI-OB5"/>
<outlet property="shapeControl" destination="tI9-Ig-FUX" id="jFL-G8-bfC"/>
<outlet property="skView" destination="xtN-8W-xyG" id="KHI-92-jcg"/>
<outlet property="slider" destination="ZXn-L9-yih" id="J8v-08-Q1X"/>
</connections>
Expand Down
25 changes: 13 additions & 12 deletions Pixelizer/BoxesScene.m
Expand Up @@ -53,6 +53,8 @@ - (void)createPhysicsWorld;

- (void)createSceneContents;
{
CGFloat verticalOffset = 94;
CGFloat horizontalMargin = 16;
CGImageRef image = self.image.CGImage;
size_t width = CGImageGetWidth(image);
size_t height = CGImageGetHeight(image);
Expand All @@ -61,24 +63,22 @@ - (void)createSceneContents;
CFDataRef rawData = CGDataProviderCopyData(CGImageGetDataProvider(image));
UInt8 *imageBuffer = (UInt8 *)CFDataGetBytePtr(rawData);

CGFloat boxWidth = (self.size.width - 16) / width;
CGFloat pixelWidth = (self.size.width - 16) / width;
CGFloat boxWidth = (self.size.width - horizontalMargin * 2) / width;
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
NSInteger pixelIndex = (width * y) + x * components;
UInt8 pixelComponentB = imageBuffer[pixelIndex];
UInt8 pixelComponentG = imageBuffer[pixelIndex + 1];
UInt8 pixelComponentR = imageBuffer[pixelIndex + 2];
UIColor *color = [UIColor colorWithRed:pixelComponentR / 255.f
green:pixelComponentG / 255.f
blue:pixelComponentB / 255.f alpha:1];
NSInteger index = (x + (width * y)) * components;
UInt8 pixelComponentB = imageBuffer[index];
UInt8 pixelComponentG = imageBuffer[index + 1];
UInt8 pixelComponentR = imageBuffer[index + 2];
UIColor *color = [UIColor colorWithRed:pixelComponentR / 255.f green:pixelComponentG / 255.f blue:pixelComponentB / 255.f alpha:1];
CGSize boxSize = CGSizeMake(boxWidth, boxWidth);
SKAssignableSpriteNode *spriteNode = [SKAssignableSpriteNode shapeWithColor:color
size:boxSize
circular:_circles];
spriteNode.pixelXPosition = x;
spriteNode.pixelYPosition = y;
spriteNode.position = CGPointMake( (x * pixelWidth) + 16, self.view.bounds.size.height - 58 - (y * pixelWidth));
spriteNode.position = CGPointMake((x * boxWidth) + 16,
self.view.bounds.size.height - verticalOffset - (y * boxWidth));
spriteNode.mass = (pixelComponentG / 25.f) + 1;
[self addChild:spriteNode];
cpFloat moment;
Expand Down Expand Up @@ -135,8 +135,9 @@ - (void)update:(NSTimeInterval)currentTime;
UInt8 pixelComponent = buffer[pixelIndex];
UInt8 pixelComponent2 = buffer[pixelIndex + 1];
UInt8 pixelComponent3 = buffer[pixelIndex + 2];
UIColor *color = [UIColor colorWithRed:pixelComponent3 / 255.f green:pixelComponent2 / 255.f blue:pixelComponent / 255.f alpha:1];

UIColor *color = [UIColor colorWithRed:pixelComponent3 / 255.f
green:pixelComponent2 / 255.f
blue:pixelComponent / 255.f alpha:1];
if (useCircles) {
node.texture = [SKTexture circleTextureWithColor:color size:node.size];
} else {
Expand Down
11 changes: 11 additions & 0 deletions Pixelizer/LabeledSlider.h
@@ -0,0 +1,11 @@

@import UIKit;

@interface LabeledSlider : UISlider

@property (nonatomic) UILabel *label;

- (NSString *)labelText;
- (UIColor *)labelTextColor;

@end
39 changes: 39 additions & 0 deletions Pixelizer/LabeledSlider.m
@@ -0,0 +1,39 @@

#import "LabeledSlider.h"

@implementation LabeledSlider

- (instancetype)initWithCoder:(NSCoder *)aDecoder;
{
if (!(self = [super initWithCoder:aDecoder])) return nil;

self.label = UILabel.new;
self.label.textAlignment = NSTextAlignmentCenter;
self.label.font = [UIFont fontWithName:@"AvenirNextCondensed-Medium" size:17.f];
self.label.adjustsFontSizeToFitWidth = YES;
self.label.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
[self addSubview:self.label];

return self;
}

- (void)layoutSubviews;
{
[super layoutSubviews];
[self bringSubviewToFront:self.label];
self.label.frame = CGRectInset([self thumbRectForBounds:self.bounds trackRect:[self trackRectForBounds:self.bounds] value:self.value], 4.f, 0.f);
self.label.text = self.labelText;
self.label.textColor = self.labelTextColor;
}

- (NSString *)labelText;
{
return [NSString stringWithFormat:@"%i", (int)roundf(self.value)];
}

- (UIColor *)labelTextColor;
{
return UIColor.darkGrayColor;
}

@end
17 changes: 11 additions & 6 deletions Pixelizer/ViewController.m
Expand Up @@ -10,8 +10,8 @@ @interface ViewController () <AVCaptureVideoDataOutputSampleBufferDelegate>

@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@property (weak, nonatomic) IBOutlet UISlider *slider;
@property (weak, nonatomic) IBOutlet UISegmentedControl *segmentedControl;
@property (weak, nonatomic) IBOutlet UISwitch *liveColor;
@property (weak, nonatomic) IBOutlet UISegmentedControl *shapeControl;
@property (weak, nonatomic) IBOutlet UISegmentedControl *liveControl;
@property (weak, nonatomic) IBOutlet SKView *skView;

@property (nonatomic) AVCaptureSession *session;
Expand Down Expand Up @@ -66,21 +66,26 @@ - (void)skViewTap:(UITapGestureRecognizer *)tapGR;
if (self.device) { [self.session startRunning]; }
self.imageView.hidden = NO;
self.skView.hidden = YES;
self.slider.enabled = YES;
self.shapeControl.enabled = YES;

[self.skView presentScene:[SKScene.alloc initWithSize:CGSizeZero]];
}

- (void)imageViewTap:(UITapGestureRecognizer *)tapGR;
{
if (!self.liveColor.on) {
if (!self.liveControl.selectedSegmentIndex) {
[self.session stopRunning];
}
BoxesScene *scene = [BoxesScene.alloc initWithSize:self.skView.bounds.size
image:self.imageView.image
circles:self.segmentedControl.selectedSegmentIndex == 1];
scene.liveColor = self.liveColor.on;
circles:self.shapeControl.selectedSegmentIndex == 1];
scene.liveColor = self.liveControl.selectedSegmentIndex;
[self.skView presentScene:scene];
self.skView.hidden = NO;
self.imageView.hidden = YES;
self.slider.enabled = NO;
self.shapeControl.enabled = NO;
}

- (void)captureOutput:(AVCaptureOutput *)captureOutput
Expand Down Expand Up @@ -115,7 +120,7 @@ - (void)processImage:(UIImage *)image;
[image drawInRect:scaledImageRect];
UIImage *scaledImage = [UIImage imageWithCGImage:UIGraphicsGetImageFromCurrentImageContext().CGImage];
self.imageView.image = scaledImage;
if (self.liveColor.on && !self.skView.hidden) {
if (self.liveControl.selectedSegmentIndex && !self.skView.hidden) {
((BoxesScene *)self.skView.scene).image = scaledImage;
}
}
Expand Down

0 comments on commit e80ef7d

Please sign in to comment.