diff options
author | StapleButter <thetotalworm@gmail.com> | 2017-09-09 02:30:51 +0200 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2017-09-09 02:30:51 +0200 |
commit | 70e4841d311d68689724768157cc9cbfbde7a9fc (patch) | |
tree | ba9499f77d1258530a7e60aa6e1732c41d98161c /src/libui_sdl/libui/darwin/progressbar.m | |
parent | 81747d6c34eb159481a6ca3f283d065fa3568617 (diff) |
another UI attempt, I guess.
sorry.
Diffstat (limited to 'src/libui_sdl/libui/darwin/progressbar.m')
-rw-r--r-- | src/libui_sdl/libui/darwin/progressbar.m | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/libui_sdl/libui/darwin/progressbar.m b/src/libui_sdl/libui/darwin/progressbar.m new file mode 100644 index 0000000..b538228 --- /dev/null +++ b/src/libui_sdl/libui/darwin/progressbar.m @@ -0,0 +1,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; +} |