aboutsummaryrefslogtreecommitdiff
path: root/src/libui_sdl/libui/darwin/progressbar.m
blob: b5382281951918eb2ff9e7531770932f59038b4b (plain)
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
// 14 august 2015
#import "uipriv_darwin.h"

// NSProgressIndicator has no intrinsic width by default; use the default width in Interface Builder
#define progressIndicatorWidth 100

@interface intrinsicWidthNSProgressIndicator : NSProgressIndicator
@end

@implementation intrinsicWidthNSProgressIndicator

- (NSSize)intrinsicContentSize
{
	NSSize s;

	s = [super intrinsicContentSize];
	s.width = progressIndicatorWidth;
	return s;
}

@end

struct uiProgressBar {
	uiDarwinControl c;
	NSProgressIndicator *pi;
};

uiDarwinControlAllDefaults(uiProgressBar, pi)

int uiProgressBarValue(uiProgressBar *p)
{
	if ([p->pi isIndeterminate])
		return -1;
	return [p->pi doubleValue];
}

void uiProgressBarSetValue(uiProgressBar *p, int value)
{
	if (value == -1) {
		[p->pi setIndeterminate:YES];
		[p->pi startAnimation:p->pi];
		return;
	}

	if ([p->pi isIndeterminate]) {
		[p->pi setIndeterminate:NO];
		[p->pi stopAnimation:p->pi];
	}

	if (value < 0 || value > 100)
		userbug("Value %d out of range for a uiProgressBar.", value);

	// on 10.8 there's an animation when the progress bar increases, just like with Aero
	if (value == 100) {
		[p->pi setMaxValue:101];
		[p->pi setDoubleValue:101];
		[p->pi setDoubleValue:100];
		[p->pi setMaxValue:100];
		return;
	}
	[p->pi setDoubleValue:((double) (value + 1))];
	[p->pi setDoubleValue:((double) value)];
}

uiProgressBar *uiNewProgressBar(void)
{
	uiProgressBar *p;

	uiDarwinNewControl(uiProgressBar, p);

	p->pi = [[intrinsicWidthNSProgressIndicator alloc] initWithFrame:NSZeroRect];
	[p->pi setControlSize:NSRegularControlSize];
	[p->pi setBezeled:YES];
	[p->pi setStyle:NSProgressIndicatorBarStyle];
	[p->pi setIndeterminate:NO];

	return p;
}