-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTAOController.j
71 lines (53 loc) · 2.11 KB
/
TAOController.j
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
This file is part of FrACT10, a vision test battery.
Copyright © 2021 Michael Bach, bach@uni-freiburg.de, <https://michaelbach.de>
TAOController.j
2020-05-23
This class loads the 10 Auckland Optotype (TAO) images.
When all are loaded, the referenced button is enabled.
imageArray returns an id pointing at the image array.
*/
@import <Foundation/Foundation.j>
@import <AppKit/AppKit.j>
@implementation TAOController: CPObject {
int nImages @accessors;
id _taoImages;
CPButton _button;
int _nTAOImagesLoaded;
}
- (id) initWithButton2Enable: (CPButton) button { //console.info("TAOController>initWithButton2Enable");
self = [super init];
if (self) {
_button = button;
[_button setEnabled: NO];
[self setNImages: 0];
const _taoImageNames = ["butterfly", "car", "duck", "flower", "heart", "house", "moon", "rabbit", "rocket", "tree"];
_taoImages = [];
_nTAOImagesLoaded = 0;
for (let i=0; i < _taoImageNames.length; i++) {
_taoImages[i] = [[CPImage alloc] initWithContentsOfFile: [[CPBundle mainBundle] pathForResource: "TAOs/" + _taoImageNames[i] + ".png"]];
[_taoImages[i] setDelegate: self];
}
}
return self;
}
- (void) imageDidLoad: (CPNotification) aNotification { //console.info("TAOController>didLoadRepresentation: ", aNotification);
if ([aNotification loadStatus] == CPImageLoadStatusCompleted) {
if (++_nTAOImagesLoaded > 9) {
[self setNImages: _nTAOImagesLoaded];
[_button setEnabled: YES];
}
}
}
- (id) imageArray {
return _taoImages;
}
- (id) imageNumber: (int) number {
return _taoImages[number];
}
- (void) drawTaoWithStrokeInPx: (float) stroke taoNumber: (int) taoNumber { //console.info("TAOController>drawTaoWithStrokeInPx", taoNumber, taoNumber);
const sizeInPix = stroke * 5 * 8.172 / 5;// correction for stroke width (Dakin)
const imageRect = CGRectMake(-sizeInPix / 2, -sizeInPix / 2, sizeInPix, sizeInPix);
CGContextDrawImage([[CPGraphicsContext currentContext] graphicsPort], imageRect, _taoImages[taoNumber]);
}
@end