-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConsoleOutputView.j
More file actions
96 lines (85 loc) · 3.71 KB
/
ConsoleOutputView.j
File metadata and controls
96 lines (85 loc) · 3.71 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// (c) 2010-2011 by Anton Korenyushkin
@import "SmartScrollView.j"
@implementation QAView : CPView
{
CPImageView spinnerImageView;
}
- (id)initWithOrigin:(CGPoint)origin question:(CPString)question // public
{
var questionSize = [question realSizeWithFont:MonospaceFont];
if (self = [super initWithFrame:CGRectMake(origin.x, origin.y, questionSize.width + 40, questionSize.height + 40)]) {
var questionLabel = [[CPTextField alloc] initWithFrame:CGRectMake(20, 0, questionSize.width, questionSize.height)];
[questionLabel setStringValue:question];
[questionLabel setFont:MonospaceFont];
[questionLabel setTextColor:[CPColor blueColor]];
[questionLabel setSelectable:YES];
[self addSubview:questionLabel];
spinnerImageView = [[CPImageView alloc] initWithFrame:CGRectMake(23, questionSize.height + 2, 16, 16)];
[spinnerImageView setImage:[CPImage imageFromPath:"WhiteSpinner16.gif"]];
[self addSubview:spinnerImageView];
}
return self;
}
- (void)setAnswer:(CPString)answer negative:(BOOL)negative // public
{
[spinnerImageView removeFromSuperview];
var answerSize = [answer || " " realSizeWithFont:MonospaceFont];
var frameSize = [self frameSize];
var answerLabel = [[CPTextField alloc] initWithFrame:CGRectMake(20, frameSize.height - 40,
answerSize.width, answerSize.height)];
[answerLabel setStringValue:answer];
[answerLabel setFont:MonospaceFont];
if (negative)
[answerLabel setTextColor:NegativeColor];
[answerLabel setSelectable:YES];
[self addSubview:answerLabel];
[self setFrameSize:CGSizeMake(MAX(frameSize.width, answerSize.width + 40), frameSize.height + answerSize.height - 20)];
}
@end
@implementation ConsoleOutputView : SmartScrollView
{
CPView talkView;
}
- (void)initWithFrame:(CGRect)frame // public
{
if (self = [super initWithFrame:frame]) {
[self setAutohidesScrollers:YES];
var documentView = [[CPView alloc] initWithFrame:[self bounds]];
talkView = [[CPView alloc] initWithFrame:CGRectMake(0, 0, 0, 20)];
[documentView addSubview:talkView];
[self setDocumentView:talkView];
}
return self;
}
- (void)setTalkViewSize:(CGSize)size // private
{
[self setBaseSize:size];
[talkView setFrame:CGRectMake(0, [[self documentView] boundsSize].height - size.height, size.width, size.height)];
}
- (unsigned)addQuestion:(CPString)question // public
{
var talkViewSize = [talkView frameSize];
var qaView = [[QAView alloc] initWithOrigin:CGPointMake(0, talkViewSize.height) question:question];
var qaViewSize = [qaView frameSize];
[self setTalkViewSize:CGSizeMake(MAX(talkViewSize.width, qaViewSize.width), talkViewSize.height + qaViewSize.height)];
[talkView addSubview:qaView];
[talkView scrollRectToVisible:[qaView frame]];
return [talkView subviews].length - 1;
}
- (void)setAnswer:(CPString)answer negative:(BOOL)negative forQuestionNumber:(unsigned)questionNumber // public
{
var qaViews = [talkView subviews];
var qaView = qaViews[questionNumber];
var oldQAViewSize = [qaView frameSize];
[qaView setAnswer:answer negative:negative];
var newQAViewSize = [qaView frameSize];
var heightShift = newQAViewSize.height - oldQAViewSize.height;
var talkViewSize = [talkView frameSize];
[self setTalkViewSize:CGSizeMake(MAX(talkViewSize.width, newQAViewSize.width), talkViewSize.height + heightShift)];
if (heightShift) {
for (var i = questionNumber + 1; i < qaViews.length; ++i)
[qaViews[i] setFrameOrigin:CGPointMake(0, [qaViews[i] frameOrigin].y + heightShift)];
[self moveByOffset:CGSizeMake(0, heightShift)];
}
}
@end