Add theme drawing for toolbar view.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27806 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2009-02-07 21:58:12 +00:00
parent ed0250e6ee
commit f508832e85
4 changed files with 74 additions and 80 deletions

View file

@ -1,3 +1,11 @@
2009-02-07 Fred Kiefer <FredKiefer@gmx.de>
* Headers/Additions/GNUstepGUI/GSTheme.h,
* Source/GSTheme.m (-drawToobarRect:frame:borderMask:): New method
for toolbar view drawing
* Source/GSToolbarView.m (-drawRect:): Use new theme method.
Clean up use of colours.
2009-02-07 Richard Frith-Macdonald <rfm@gnu.org> 2009-02-07 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSThemeTools.m: Add a few checks for tile sizes * Source/GSThemeTools.m: Add a few checks for tile sizes

View file

@ -528,6 +528,13 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification;
- (NSCell*) cellForScrollerKnob: (BOOL)horizontal; - (NSCell*) cellForScrollerKnob: (BOOL)horizontal;
- (NSCell*) cellForScrollerKnobSlot: (BOOL)horizontal; - (NSCell*) cellForScrollerKnobSlot: (BOOL)horizontal;
- (float) defaultScrollerWidth; - (float) defaultScrollerWidth;
/** Method for toolbar theming.
*/
- (void) drawToobarRect: (NSRect)aRect
frame: (NSRect)viewFrame
borderMask: (unsigned int)borderMask;
@end @end
/** /**

View file

@ -27,10 +27,13 @@
*/ */
#import "GSThemePrivate.h" #import "GSThemePrivate.h"
#include "AppKit/NSBezierPath.h"
#import "AppKit/NSColorList.h" #import "AppKit/NSColorList.h"
#import "AppKit/NSGraphics.h" #import "AppKit/NSGraphics.h"
#import "AppKit/NSImage.h" #import "AppKit/NSImage.h"
#include "GNUstepGUI/GSToolbarView.h"
@implementation GSTheme (Drawing) @implementation GSTheme (Drawing)
@ -394,5 +397,40 @@
return 18.0; return 18.0;
} }
- (void) drawToobarRect: (NSRect)aRect
frame: (NSRect)viewFrame
borderMask: (unsigned int)borderMask
{
// We draw the background
[[NSColor toolbarBackgroundColor] set];
[NSBezierPath fillRect: aRect];
// We draw the border
[[NSColor toolbarBorderColor] set];
if (borderMask & GSToolbarViewBottomBorder)
{
[NSBezierPath strokeLineFromPoint: NSMakePoint(0, 0.5)
toPoint: NSMakePoint(viewFrame.size.width, 0.5)];
}
if (borderMask & GSToolbarViewTopBorder)
{
[NSBezierPath strokeLineFromPoint: NSMakePoint(0,
viewFrame.size.height - 0.5)
toPoint: NSMakePoint(viewFrame.size.width,
viewFrame.size.height - 0.5)];
}
if (borderMask & GSToolbarViewLeftBorder)
{
[NSBezierPath strokeLineFromPoint: NSMakePoint(0.5, 0)
toPoint: NSMakePoint(0.5, viewFrame.size.height)];
}
if (borderMask & GSToolbarViewRightBorder)
{
[NSBezierPath strokeLineFromPoint: NSMakePoint(viewFrame.size.width - 0.5,0)
toPoint: NSMakePoint(viewFrame.size.width - 0.5,
viewFrame.size.height)];
}
}
@end @end

View file

@ -30,11 +30,11 @@
#include <Foundation/NSObject.h> #include <Foundation/NSObject.h>
#include <Foundation/NSArray.h> #include <Foundation/NSArray.h>
#include <Foundation/NSDictionary.h> #include <Foundation/NSDictionary.h>
#include <Foundation/NSEnumerator.h>
#include <Foundation/NSException.h> #include <Foundation/NSException.h>
#include <Foundation/NSNotification.h> #include <Foundation/NSNotification.h>
#include <Foundation/NSUserDefaults.h> #include <Foundation/NSUserDefaults.h>
#include <Foundation/NSString.h> #include <Foundation/NSString.h>
#include "AppKit/NSBezierPath.h"
#include "AppKit/NSButton.h" #include "AppKit/NSButton.h"
#include "AppKit/NSClipView.h" #include "AppKit/NSClipView.h"
#include "AppKit/NSColor.h" #include "AppKit/NSColor.h"
@ -48,6 +48,8 @@
#include "AppKit/NSToolbarItem.h" #include "AppKit/NSToolbarItem.h"
#include "AppKit/NSView.h" #include "AppKit/NSView.h"
#include "AppKit/NSWindow.h" #include "AppKit/NSWindow.h"
#include "GNUstepGUI/GSTheme.h"
#include "GNUstepGUI/GSToolbarView.h" #include "GNUstepGUI/GSToolbarView.h"
#include "NSToolbarFrameworkPrivate.h" #include "NSToolbarFrameworkPrivate.h"
@ -63,10 +65,6 @@ static const int ClippedItemsViewWidth = 28;
// Internal // Internal
static const int current_version = 1; static const int current_version = 1;
static NSColorList *SystemExtensionsColors; static NSColorList *SystemExtensionsColors;
static NSColor *StandardBackgroundColor;
static NSColor *BackgroundColor;
static NSColor *BorderColor;
// Toolbar color extensions // Toolbar color extensions
@ -77,24 +75,18 @@ static void initSystemExtensionsColors(void)
NSDictionary *colors; NSDictionary *colors;
/* Set up a dictionary containing the names of all the system extensions /* Set up a dictionary containing the names of all the system extensions
colors as keys and with colors in string format as values. */ colours as keys and with colours as values. */
toolbarBorderColor = [NSColor colorWithCalibratedRed: 0.5 toolbarBorderColor = [NSColor colorWithCalibratedRed: 0.5
green: 0.5 green: 0.5
blue: 0.5 blue: 0.5
alpha: 1.0]; alpha: 1.0];
// Window background color by tranparency // Window background color by tranparency
toolbarBackgroundColor = [NSColor clearColor]; toolbarBackgroundColor = [NSColor clearColor];
// Window backgound color hardcoded
/* toolbarBackgroundColor = [NSColor colorWithCalibratedRed: 0.8
green: 0.8
blue: 0.8
alpha: 1.0]; */
colors = [[NSDictionary alloc] initWithObjectsAndKeys: colors = [[NSDictionary alloc] initWithObjectsAndKeys:
toolbarBackgroundColor, @"toolbarBackgroundColor",toolbarBorderColor, toolbarBackgroundColor, @"toolbarBackgroundColor",
@"toolbarBorderColor", nil]; toolbarBorderColor, @"toolbarBorderColor", nil];
SystemExtensionsColors = [NSColorList colorListNamed: @"System extensions"]; SystemExtensionsColors = [NSColorList colorListNamed: @"System extensions"];
if (SystemExtensionsColors == nil) if (SystemExtensionsColors == nil)
@ -126,20 +118,6 @@ static void initSystemExtensionsColors(void)
if (changed) if (changed)
[SystemExtensionsColors writeToFile: nil]; [SystemExtensionsColors writeToFile: nil];
} }
/* Never released, but that's not a problem because the variables are
static and then will be deallocated with the class when the application
quits. */
StandardBackgroundColor =
[NSColor colorWithCalibratedRed: 0.8 green: 0.8 blue: 0.8 alpha: 1.0];
RETAIN(StandardBackgroundColor);
BackgroundColor =
[SystemExtensionsColors colorWithKey: @"toolbarBackgroundColor"];
BorderColor =
[SystemExtensionsColors colorWithKey: @"toolbarBorderColor"];
RETAIN(BackgroundColor);
RETAIN(BorderColor);
} }
@implementation NSColor (GSToolbarViewAdditions) @implementation NSColor (GSToolbarViewAdditions)
@ -309,6 +287,7 @@ static void initSystemExtensionsColors(void)
NSMakeRect(0, 0, frame.size.width, NSMakeRect(0, 0, frame.size.width,
_heightFromLayout)]; _heightFromLayout)];
[_clipView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)]; [_clipView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
[_clipView setDrawsBackground: NO];
[self addSubview: _clipView]; [self addSubview: _clipView];
// Adjust the clip view frame // Adjust the clip view frame
[self setBorderMask: GSToolbarViewTopBorder | GSToolbarViewBottomBorder [self setBorderMask: GSToolbarViewTopBorder | GSToolbarViewBottomBorder
@ -436,47 +415,14 @@ static void initSystemExtensionsColors(void)
- (void) drawRect: (NSRect)aRect - (void) drawRect: (NSRect)aRect
{ {
NSRect viewFrame = [self frame]; [[GSTheme theme] drawToobarRect: aRect
frame: [self frame]
// We draw the background borderMask: _borderMask];
if (![BackgroundColor isEqual: [NSColor clearColor]])
{
[BackgroundColor set];
[NSBezierPath fillRect: aRect];
}
// We draw the border
[BorderColor set];
if (_borderMask & GSToolbarViewBottomBorder)
{
[NSBezierPath strokeLineFromPoint: NSMakePoint(0, 0.5)
toPoint: NSMakePoint(viewFrame.size.width, 0.5)];
}
if (_borderMask & GSToolbarViewTopBorder)
{
[NSBezierPath strokeLineFromPoint: NSMakePoint(0,
viewFrame.size.height - 0.5)
toPoint: NSMakePoint(viewFrame.size.width,
viewFrame.size.height - 0.5)];
}
if (_borderMask & GSToolbarViewLeftBorder)
{
[NSBezierPath strokeLineFromPoint: NSMakePoint(0.5, 0)
toPoint: NSMakePoint(0.5, viewFrame.size.height)];
}
if (_borderMask & GSToolbarViewRightBorder)
{
[NSBezierPath strokeLineFromPoint: NSMakePoint(viewFrame.size.width - 0.5,0)
toPoint: NSMakePoint(viewFrame.size.width - 0.5,
viewFrame.size.height)];
}
[super drawRect: aRect];
} }
- (BOOL) isOpaque - (BOOL) isOpaque
{ {
if ([BackgroundColor isEqual: [NSColor clearColor]]) if ([[NSColor toolbarBackgroundColor] alphaComponent] < 1.0)
{ {
return NO; return NO;
} }
@ -576,11 +522,6 @@ static void initSystemExtensionsColors(void)
[self _reload]; [self _reload];
} }
- (NSColor *) standardBackgroundColor
{
return StandardBackgroundColor;
}
// Private methods // Private methods
- (void) _handleBackViewsFrame - (void) _handleBackViewsFrame
@ -837,21 +778,21 @@ static void initSystemExtensionsColors(void)
} }
- (NSColor *) standardBackgroundColor
{
NSLog(@"Use of deprecated method %@", NSStringFromSelector(_cmd));
return nil;
}
- (BOOL) _usesStandardBackgroundColor - (BOOL) _usesStandardBackgroundColor
{ {
return [BackgroundColor isEqual: [self standardBackgroundColor]]; NSLog(@"Use of deprecated method %@", NSStringFromSelector(_cmd));
return NO;
} }
- (void) _setUsesStandardBackgroundColor: (BOOL)standard - (void) _setUsesStandardBackgroundColor: (BOOL)standard
{ {
if (standard) NSLog(@"Use of deprecated method %@", NSStringFromSelector(_cmd));
{
ASSIGN(BackgroundColor, [self standardBackgroundColor]);
}
else
{
ASSIGN(BackgroundColor, [NSColor clearColor]);
}
} }
@end @end