mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-25 12:41:01 +00:00
Better implementation of NSProgressIndicator based on patch by Uli
Kusterer <witness.of.teachtext@gmx.net>. -- Diese und die folgenden Zeilen werden ignoriert -- M Source/NSProgressIndicator.m M Headers/AppKit/NSProgressIndicator.h M ChangeLog AM Images/common_ProgressSpinning_4.tiff AM Images/common_ProgressIndeterminate_3.tiff AM Images/common_ProgressSpinning_8.tiff M Images/GNUmakefile AM Images/common_ProgressSpinning_1.tiff AM Images/common_ProgressSpinning_5.tiff AM Images/common_ProgressIndeterminate_4.tiff AM Images/common_ProgressSpinning_2.tiff AM Images/common_ProgressIndeterminate_1.tiff AM Images/common_ProgressSpinning_6.tiff AM Images/common_ProgressIndeterminate_5.tiff AM Images/common_ProgressSpinning_3.tiff AM Images/common_ProgressIndeterminate_2.tiff AM Images/common_ProgressSpinning_7.tiff AM Images/common_ProgressIndeterminate_6.tiff git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@28900 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
1443a6b299
commit
9c7aff20ab
18 changed files with 269 additions and 110 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2009-10-27 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Headers/AppKit/NSProgressIndicator.h,
|
||||
* Source/NSProgressIndicator.m: Add missing OSX 10.5 methods and
|
||||
use the pattern colour patch by Uli Kusterer
|
||||
<witness.of.teachtext@gmx.net>.
|
||||
* Images/common_ProgressSpinning_?.tiff
|
||||
* Images/common_ProgressIndeterminate_?.tiff
|
||||
New image files by Uli Kusterer <witness.of.teachtext@gmx.net>.
|
||||
* Images/GNUmakefile: Add the new images.
|
||||
|
||||
2009-10-27 Thomas Gamper <icicle@cg.tuwien.ac.at>
|
||||
|
||||
* Source/GSDisplayServer.m
|
||||
|
|
|
@ -27,34 +27,48 @@
|
|||
|
||||
#ifndef _GNUstep_H_NSProgressIndicator
|
||||
#define _GNUstep_H_NSProgressIndicator
|
||||
#import <GNUstepBase/GSVersionMacros.h>
|
||||
|
||||
#include <AppKit/NSView.h>
|
||||
#import <AppKit/NSView.h>
|
||||
|
||||
/* For NSControlTint */
|
||||
#import <AppKit/NSColor.h>
|
||||
|
||||
/* For NSControlSize */
|
||||
#import <AppKit/NSCell.h>
|
||||
|
||||
@class NSTimer;
|
||||
@class NSThread;
|
||||
|
||||
/* For NSControlTint */
|
||||
#include <AppKit/NSColor.h>
|
||||
typedef enum _NSProgressIndicatorThickness
|
||||
{
|
||||
NSProgressIndicatorPreferredThickness = 14,
|
||||
NSProgressIndicatorPreferredSmallThickness = 10,
|
||||
NSProgressIndicatorPreferredLargeThickness = 18,
|
||||
NSProgressIndicatorPreferredAquaThickness = 12
|
||||
} NSProgressIndicatorThickness;
|
||||
|
||||
/* For NSControlSize */
|
||||
#include <AppKit/NSCell.h>
|
||||
|
||||
#define NSProgressIndicatorPreferredThickness 14
|
||||
#define NSProgressIndicatorPreferredSmallThickness 10
|
||||
#define NSProgressIndicatorPreferredLargeThickness 18
|
||||
#define NSProgressIndicatorPreferredAquaThickness 12
|
||||
typedef enum _NSProgressIndicatorStyle
|
||||
{
|
||||
NSProgressIndicatorBarStyle = 0,
|
||||
NSProgressIndicatorSpinningStyle = 1
|
||||
} NSProgressIndicatorStyle;
|
||||
|
||||
@interface NSProgressIndicator : NSView
|
||||
{
|
||||
BOOL _isIndeterminate;
|
||||
BOOL _isBezeled;
|
||||
BOOL _usesThreadedAnimation;
|
||||
NSTimeInterval _animationDelay;
|
||||
double _doubleValue;
|
||||
double _minValue;
|
||||
double _maxValue;
|
||||
BOOL _isVertical;
|
||||
NSTimeInterval _animationDelay;
|
||||
NSProgressIndicatorStyle _style;
|
||||
BOOL _isIndeterminate;
|
||||
BOOL _isBezeled;
|
||||
BOOL _usesThreadedAnimation;
|
||||
BOOL _isDisplayedWhenStopped;
|
||||
NSControlTint _controlTint;
|
||||
NSControlSize _controlSize;
|
||||
@private
|
||||
BOOL _isVertical;
|
||||
BOOL _isRunning;
|
||||
int _count;
|
||||
NSTimer *_timer;
|
||||
|
@ -64,9 +78,13 @@
|
|||
//
|
||||
// Animating the progress indicator
|
||||
//
|
||||
|
||||
#if OS_API_VERSION(GS_API_LATEST, MAC_OS_X_VERSION_10_5)
|
||||
- (void)animate:(id)sender;
|
||||
- (NSTimeInterval)animationDelay;
|
||||
- (void)setAnimationDelay:(NSTimeInterval)delay;
|
||||
#endif
|
||||
|
||||
- (void)startAnimation:(id)sender;
|
||||
- (void)stopAnimation:(id)sender;
|
||||
- (BOOL)usesThreadedAnimation;
|
||||
|
@ -99,6 +117,14 @@
|
|||
- (NSControlTint)controlTint;
|
||||
- (void)setControlTint:(NSControlTint)tint;
|
||||
|
||||
#if OS_API_VERSION(MAC_OS_X_VERSION_10_2, GS_API_LATEST)
|
||||
- (BOOL)isDisplayedWhenStopped;
|
||||
- (void)setDisplayedWhenStopped:(BOOL)flag;
|
||||
- (void)setStyle:(NSProgressIndicatorStyle)style;
|
||||
- (NSProgressIndicatorStyle)style;
|
||||
- (void)sizeToFit;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
#if OS_API_VERSION(GS_API_NONE, GS_API_NONE)
|
||||
|
|
|
@ -128,6 +128,20 @@ Images_RESOURCE_FILES = \
|
|||
common_outlineUnexpandable.tiff \
|
||||
common_ret.tiff \
|
||||
common_retH.tiff \
|
||||
common_ProgressIndeterminate_1.tiff \
|
||||
common_ProgressIndeterminate_2.tiff \
|
||||
common_ProgressIndeterminate_3.tiff \
|
||||
common_ProgressIndeterminate_4.tiff \
|
||||
common_ProgressIndeterminate_5.tiff \
|
||||
common_ProgressIndeterminate_6.tiff \
|
||||
common_ProgressSpinning_1.tiff \
|
||||
common_ProgressSpinning_2.tiff \
|
||||
common_ProgressSpinning_3.tiff \
|
||||
common_ProgressSpinning_4.tiff \
|
||||
common_ProgressSpinning_5.tiff \
|
||||
common_ProgressSpinning_6.tiff \
|
||||
common_ProgressSpinning_7.tiff \
|
||||
common_ProgressSpinning_8.tiff \
|
||||
nsmapping.strings \
|
||||
page_landscape.tiff \
|
||||
page_portrait.tiff
|
||||
|
|
BIN
Images/common_ProgressIndeterminate_1.tiff
Normal file
BIN
Images/common_ProgressIndeterminate_1.tiff
Normal file
Binary file not shown.
BIN
Images/common_ProgressIndeterminate_2.tiff
Normal file
BIN
Images/common_ProgressIndeterminate_2.tiff
Normal file
Binary file not shown.
BIN
Images/common_ProgressIndeterminate_3.tiff
Normal file
BIN
Images/common_ProgressIndeterminate_3.tiff
Normal file
Binary file not shown.
BIN
Images/common_ProgressIndeterminate_4.tiff
Normal file
BIN
Images/common_ProgressIndeterminate_4.tiff
Normal file
Binary file not shown.
BIN
Images/common_ProgressIndeterminate_5.tiff
Normal file
BIN
Images/common_ProgressIndeterminate_5.tiff
Normal file
Binary file not shown.
BIN
Images/common_ProgressIndeterminate_6.tiff
Normal file
BIN
Images/common_ProgressIndeterminate_6.tiff
Normal file
Binary file not shown.
BIN
Images/common_ProgressSpinning_1.tiff
Normal file
BIN
Images/common_ProgressSpinning_1.tiff
Normal file
Binary file not shown.
BIN
Images/common_ProgressSpinning_2.tiff
Normal file
BIN
Images/common_ProgressSpinning_2.tiff
Normal file
Binary file not shown.
BIN
Images/common_ProgressSpinning_3.tiff
Normal file
BIN
Images/common_ProgressSpinning_3.tiff
Normal file
Binary file not shown.
BIN
Images/common_ProgressSpinning_4.tiff
Normal file
BIN
Images/common_ProgressSpinning_4.tiff
Normal file
Binary file not shown.
BIN
Images/common_ProgressSpinning_5.tiff
Normal file
BIN
Images/common_ProgressSpinning_5.tiff
Normal file
Binary file not shown.
BIN
Images/common_ProgressSpinning_6.tiff
Normal file
BIN
Images/common_ProgressSpinning_6.tiff
Normal file
Binary file not shown.
BIN
Images/common_ProgressSpinning_7.tiff
Normal file
BIN
Images/common_ProgressSpinning_7.tiff
Normal file
Binary file not shown.
BIN
Images/common_ProgressSpinning_8.tiff
Normal file
BIN
Images/common_ProgressSpinning_8.tiff
Normal file
Binary file not shown.
|
@ -27,6 +27,7 @@
|
|||
#include <Foundation/NSTimer.h>
|
||||
#include "AppKit/NSProgressIndicator.h"
|
||||
#include "AppKit/NSGraphics.h"
|
||||
#include "AppKit/NSImage.h"
|
||||
#include "AppKit/NSWindow.h"
|
||||
#include "GNUstepGUI/GSTheme.h"
|
||||
#include "GNUstepGUI/GSNibLoading.h"
|
||||
|
@ -34,24 +35,60 @@
|
|||
@implementation NSProgressIndicator
|
||||
|
||||
static NSColor *fillColour = nil;
|
||||
#define maxCount 1
|
||||
//static NSImage *images[maxCount];
|
||||
#define MaxCount 10
|
||||
static int indeterminateMaxCount = MaxCount;
|
||||
static int spinningMaxCount = MaxCount;
|
||||
static NSColor *indeterminateColors[MaxCount];
|
||||
static NSImage *spinningImages[MaxCount];
|
||||
|
||||
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSProgressIndicator class])
|
||||
{
|
||||
int i;
|
||||
|
||||
[self setVersion: 1];
|
||||
// FIXME: Should come from defaults and should be reset when defaults change
|
||||
// FIXME: Should probably get the color from the color extension list (see NSToolbar)
|
||||
fillColour = RETAIN([NSColor controlShadowColor]);
|
||||
// FIXME: Load the images and set maxCount
|
||||
|
||||
// Load images for indeterminate style
|
||||
for (i = 0; i < MaxCount; i++)
|
||||
{
|
||||
NSString *imgName = [NSString stringWithFormat: @"common_ProgressIndeterminate_%d", i + 1];
|
||||
NSImage *image = [NSImage imageNamed: imgName];
|
||||
|
||||
if (image == nil)
|
||||
{
|
||||
indeterminateMaxCount = i;
|
||||
break;
|
||||
}
|
||||
indeterminateColors[i] = RETAIN([NSColor colorWithPatternImage: image]);
|
||||
}
|
||||
|
||||
// Load images for spinning style
|
||||
for (i = 0; i < MaxCount; i++)
|
||||
{
|
||||
NSString *imgName = [NSString stringWithFormat: @"common_ProgressSpinning_%d", i + 1];
|
||||
NSImage *image = [NSImage imageNamed: imgName];
|
||||
|
||||
if (image == nil)
|
||||
{
|
||||
spinningMaxCount = i;
|
||||
break;
|
||||
}
|
||||
spinningImages[i] = RETAIN(image);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(NSRect)frameRect
|
||||
{
|
||||
self = [super initWithFrame: frameRect];
|
||||
if (!self)
|
||||
return nil;
|
||||
|
||||
_isIndeterminate = YES;
|
||||
_isBezeled = YES;
|
||||
_isVertical = NO;
|
||||
|
@ -60,6 +97,10 @@ static NSColor *fillColour = nil;
|
|||
_doubleValue = 0.0;
|
||||
_minValue = 0.0;
|
||||
_maxValue = 100.0;
|
||||
_controlTint = NSDefaultControlTint;
|
||||
_controlSize = NSRegularControlSize;
|
||||
[self setStyle: NSProgressIndicatorBarStyle];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -80,13 +121,18 @@ static NSColor *fillColour = nil;
|
|||
return;
|
||||
|
||||
_count++;
|
||||
if (_count == maxCount)
|
||||
if (((_style == NSProgressIndicatorSpinningStyle) && (_count >= spinningMaxCount))
|
||||
|| ((_style == NSProgressIndicatorBarStyle) && (_count >= indeterminateMaxCount)))
|
||||
_count = 0;
|
||||
|
||||
[self setNeedsDisplay:YES];
|
||||
}
|
||||
|
||||
- (NSTimeInterval)animationDelay { return _animationDelay; }
|
||||
- (NSTimeInterval)animationDelay
|
||||
{
|
||||
return _animationDelay;
|
||||
}
|
||||
|
||||
- (void)setAnimationDelay:(NSTimeInterval)delay
|
||||
{
|
||||
_animationDelay = delay;
|
||||
|
@ -107,7 +153,7 @@ static NSColor *fillColour = nil;
|
|||
}
|
||||
else
|
||||
{
|
||||
// Not implemented
|
||||
// FIXME: Not implemented
|
||||
}
|
||||
|
||||
_isRunning = YES;
|
||||
|
@ -125,7 +171,7 @@ static NSColor *fillColour = nil;
|
|||
}
|
||||
else
|
||||
{
|
||||
// Not implemented
|
||||
// FIXME: Not implemented
|
||||
}
|
||||
|
||||
_isRunning = NO;
|
||||
|
@ -158,7 +204,11 @@ static NSColor *fillColour = nil;
|
|||
[self setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
- (double)doubleValue { return _doubleValue; }
|
||||
- (double)doubleValue
|
||||
{
|
||||
return _doubleValue;
|
||||
}
|
||||
|
||||
- (void)setDoubleValue:(double)aValue
|
||||
{
|
||||
if (_doubleValue != aValue)
|
||||
|
@ -168,7 +218,11 @@ static NSColor *fillColour = nil;
|
|||
}
|
||||
}
|
||||
|
||||
- (double)minValue { return _minValue; }
|
||||
- (double)minValue
|
||||
{
|
||||
return _minValue;
|
||||
}
|
||||
|
||||
- (void)setMinValue:(double)newMinimum
|
||||
{
|
||||
if (_minValue != newMinimum)
|
||||
|
@ -178,7 +232,11 @@ static NSColor *fillColour = nil;
|
|||
}
|
||||
}
|
||||
|
||||
- (double)maxValue { return _maxValue; }
|
||||
- (double)maxValue
|
||||
{
|
||||
return _maxValue;
|
||||
}
|
||||
|
||||
- (void)setMaxValue:(double)newMaximum
|
||||
{
|
||||
if (_maxValue != newMaximum)
|
||||
|
@ -188,7 +246,11 @@ static NSColor *fillColour = nil;
|
|||
}
|
||||
}
|
||||
|
||||
- (BOOL)isBezeled { return _isBezeled; }
|
||||
- (BOOL)isBezeled
|
||||
{
|
||||
return _isBezeled;
|
||||
}
|
||||
|
||||
- (void)setBezeled:(BOOL)flag
|
||||
{
|
||||
if (_isBezeled != flag)
|
||||
|
@ -198,7 +260,11 @@ static NSColor *fillColour = nil;
|
|||
}
|
||||
}
|
||||
|
||||
- (BOOL)isIndeterminate { return _isIndeterminate; }
|
||||
- (BOOL)isIndeterminate
|
||||
{
|
||||
return _isIndeterminate;
|
||||
}
|
||||
|
||||
- (void)setIndeterminate:(BOOL)flag
|
||||
{
|
||||
_isIndeterminate = flag;
|
||||
|
@ -207,24 +273,49 @@ static NSColor *fillColour = nil;
|
|||
[self stopAnimation: self];
|
||||
}
|
||||
|
||||
- (BOOL)isDisplayedWhenStopped
|
||||
{
|
||||
return _isDisplayedWhenStopped;
|
||||
}
|
||||
|
||||
- (void)setDisplayedWhenStopped:(BOOL)flag
|
||||
{
|
||||
_style = _isDisplayedWhenStopped;
|
||||
}
|
||||
|
||||
- (NSProgressIndicatorStyle) style
|
||||
{
|
||||
return _style;
|
||||
}
|
||||
|
||||
- (void)setStyle:(NSProgressIndicatorStyle)style
|
||||
{
|
||||
_style = style;
|
||||
_count = 0;
|
||||
[self setDisplayedWhenStopped: (style == NSProgressIndicatorBarStyle)];
|
||||
}
|
||||
|
||||
- (NSControlSize)controlSize
|
||||
{
|
||||
// FIXME
|
||||
return NSRegularControlSize;
|
||||
return _controlSize;
|
||||
}
|
||||
|
||||
- (void)setControlSize:(NSControlSize)size
|
||||
{
|
||||
// FIXME
|
||||
_controlSize = size;
|
||||
}
|
||||
|
||||
- (NSControlTint)controlTint
|
||||
{
|
||||
// FIXME
|
||||
return NSDefaultControlTint;
|
||||
return _controlTint;
|
||||
}
|
||||
|
||||
- (void)setControlTint:(NSControlTint)tint
|
||||
{
|
||||
_controlTint = tint;
|
||||
}
|
||||
|
||||
- (void) sizeToFit
|
||||
{
|
||||
// FIXME
|
||||
}
|
||||
|
@ -240,14 +331,30 @@ static NSColor *fillColour = nil;
|
|||
r = [[GSTheme theme] drawGrayBezel: _bounds withClip: rect];
|
||||
}
|
||||
else
|
||||
{
|
||||
r = _bounds;
|
||||
|
||||
if (_isIndeterminate) // Draw indeterminate
|
||||
{
|
||||
// FIXME: Do nothing at this stage
|
||||
}
|
||||
else // Draw determinate
|
||||
|
||||
if (_style == NSProgressIndicatorSpinningStyle)
|
||||
{
|
||||
NSRect imgBox = {{0,0}, {0,0}};
|
||||
|
||||
imgBox.size = [spinningImages[_count] size];
|
||||
[spinningImages[_count] drawInRect: r
|
||||
fromRect: imgBox
|
||||
operation: NSCompositeSourceOver
|
||||
fraction: 1.0];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_isIndeterminate)
|
||||
{
|
||||
[indeterminateColors[_count] set];
|
||||
NSRectFill(r);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Draw determinate
|
||||
if (_doubleValue > _minValue)
|
||||
{
|
||||
double val;
|
||||
|
@ -270,6 +377,7 @@ static NSColor *fillColour = nil;
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// It does not seem that Gnustep has a copyWithZone: on NSView, it is private
|
||||
// under openstep
|
||||
|
|
Loading…
Reference in a new issue