1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
//  Controller.m
//
//  Created by Tommy Bergeron on 10-01-18.
//  Copyright 2010 Egzakt. All rights reserved.
//

#import "Controller.h"

@implementation Controller

- (IBAction)decrease:(id)sender {
	if (numberOfSidesLabel.text.integerValue > polygon.minimumNumberOfSides) {
		polygon.numberOfSides = numberOfSidesLabel.text.integerValue -1;
	} else {
		decreaseButton.enabled = NO;
	}
	
	[self updateInterface];
}


- (IBAction)inscrease:(id)sender {
	if (numberOfSidesLabel.text.integerValue < polygon.maximumNumberOfSides) {
		polygon.numberOfSides = numberOfSidesLabel.text.integerValue +1;
	} else {
		increaseButton.enabled = NO;
	}
	
	[self updateInterface];
}


- (void)updateInterface {
	numberOfSidesLabel.text = [NSString stringWithFormat:@"%i", polygon.numberOfSides];
	NSLog(@"The polygon now has %i sides.", polygon.numberOfSides);

	[view setNeedsDisplay];
}


- (void)awakeFromNib {
	int sides = numberOfSidesLabel.text.integerValue;
	int minimum = 3;
	int maximum = 12;

	polygon = [[PolygonShape alloc] initWithNumberOfSides:(int)sides
									minimumNumberOfSides:(int)minimum
									maximumNumberOfSides:(int)maximum
			   ];
	
	NSLog(@"My polygon: %@", polygon.description);
}

@end