Move stepper drawing code into GSTheme.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@28983 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2009-11-09 13:01:48 +00:00
parent e533cbec58
commit 6f96e84bc6
8 changed files with 137 additions and 104 deletions

View file

@ -1,3 +1,13 @@
2009-11-09 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSControl.m,
* Headers/AppKit/NSStepper.h,
* Headers/AppKit/NSStepperCell.h,
* Source/NSStepper.m: White space changes and cleanup.
* Source/NSStepperCell.m,
* Headers/Additions/GNUstepGUI/GSTheme.h,
* Source/GSThemeDrawing.m: Move stepper drawing code into GSTheme.
2009-11-09 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSScroller.m: make offset of buttons inside scroller adjustable

View file

@ -652,6 +652,20 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification;
- (BOOL) toolbarIsOpaque;
// Methods to deal with steppers..
/**
* Draw a stepper cell
*/
- (void) drawStepperCell: (NSCell*)cell
withFrame: (NSRect)cellFrame
inView: (NSView*)controlView
highlightUp: (BOOL)highlightUp
highlightDown: (BOOL)highlightDown;
// Stepper cell helper methods
- (NSRect) stepperUpButtonRectWithFrame: (NSRect)frame;
- (NSRect) stepperDownButtonRectWithFrame: (NSRect)frame;
- (void) drawStepperBorder: (NSRect)frame;
/**
* Draw light colored stepper using the border and clip rects
*/

View file

@ -30,7 +30,7 @@
#ifndef _GNUstep_H_NSStepper
#define _GNUstep_H_NSStepper
#include <AppKit/NSControl.h>
#import <AppKit/NSControl.h>
@interface NSStepper : NSControl
{

View file

@ -28,7 +28,7 @@
#ifndef _GNUstep_H_NSStepperCell
#define _GNUstep_H_NSStepperCell
#include <AppKit/NSActionCell.h>
#import <AppKit/NSActionCell.h>
@interface NSStepperCell : NSActionCell
{

View file

@ -483,6 +483,49 @@
}
}
// NSStepperCell drawing
// Hard coded values for button sizes
#define STEPPER_WIDTH 15
#define STEPPER_HEIGHT 11
- (NSRect) stepperUpButtonRectWithFrame: (NSRect)frame
{
NSRect upRect;
upRect.size.width = STEPPER_WIDTH;
upRect.size.height = STEPPER_HEIGHT;
upRect.origin.x = NSMaxX(frame) - STEPPER_WIDTH - 1;
upRect.origin.y = NSMinY(frame) + ((int)frame.size.height / 2) + 1;
return upRect;
}
- (NSRect) stepperDownButtonRectWithFrame: (NSRect)frame
{
NSRect downRect;
downRect.size.width = STEPPER_WIDTH;
downRect.size.height = STEPPER_HEIGHT;
downRect.origin.x = NSMaxX(frame) - STEPPER_WIDTH - 1;
downRect.origin.y = NSMinY(frame) + ((int)frame.size.height / 2) - STEPPER_HEIGHT + 1;
return downRect;
}
- (void) drawStepperBorder: (NSRect)frame
{
NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge};
NSColor *black = [NSColor controlDarkShadowColor];
NSColor *grays[] = {black, black};
NSRect twoButtons;
twoButtons.origin.x = NSMaxX(frame) - STEPPER_WIDTH - 1;
twoButtons.origin.y = NSMinY(frame) + ((int)frame.size.height / 2) - STEPPER_HEIGHT;
twoButtons.size.width = STEPPER_WIDTH + 1;
twoButtons.size.height = 2 * STEPPER_HEIGHT + 1;
NSDrawColorTiledRects(twoButtons, NSZeroRect,
up_sides, grays, 2);
}
- (NSRect) drawStepperLightButton: (NSRect)border : (NSRect)clip
{
/*
@ -593,6 +636,31 @@
PSstroke();
}
- (void) drawStepperCell: (NSCell*)cell
withFrame: (NSRect)cellFrame
inView: (NSView*)controlView
highlightUp: (BOOL)highlightUp
highlightDown: (BOOL)highlightDown
{
NSRect upRect;
NSRect downRect;
[self drawStepperBorder: cellFrame];
upRect = [self stepperUpButtonRectWithFrame: cellFrame];
downRect = [self stepperDownButtonRectWithFrame: cellFrame];
if (highlightUp)
[self drawStepperHighlightUpButton: upRect];
else
[self drawStepperUpButton: upRect];
if (highlightDown)
[self drawStepperHighlightDownButton: downRect];
else
[self drawStepperDownButton: downRect];
}
- (void) drawImage: (NSImage *)image
inButtonCell: (NSButtonCell *) cell
withFrame: (NSRect) aRect

View file

@ -26,14 +26,9 @@
#include "config.h"
#include <Foundation/NSDebug.h>
#include <Foundation/NSException.h>
#include "AppKit/NSStepper.h"
#include "AppKit/NSControl.h"
#include "AppKit/NSEvent.h"
#include "AppKit/NSWindow.h"
#include "AppKit/NSApplication.h"
#include "AppKit/NSStepperCell.h"
#import "AppKit/NSStepper.h"
#import "AppKit/NSEvent.h"
#import "AppKit/NSStepperCell.h"
//
// class variables

View file

@ -28,20 +28,13 @@
#include "config.h"
#include "AppKit/NSApplication.h"
#include "AppKit/NSColor.h"
#include "AppKit/NSControl.h"
#include "AppKit/NSEvent.h"
#include "AppKit/NSGraphics.h"
#include "AppKit/NSGraphicsContext.h"
#include "AppKit/NSStepperCell.h"
#include "AppKit/NSWindow.h"
#import "AppKit/NSApplication.h"
#import "AppKit/NSControl.h"
#import "AppKit/NSEvent.h"
#import "AppKit/NSStepperCell.h"
#import "AppKit/NSWindow.h"
#include "GNUstepGUI/GSTheme.h"
// Hard coded values for button sizes
#define STEPPER_WIDTH 15
#define STEPPER_HEIGHT 11
@interface NSStepperCell (Private)
- (void) _increment;
- (void) _decrement;
@ -49,8 +42,6 @@
upButton: (BOOL)upButton
withFrame: (NSRect)frame
inView: (NSView*)controlView;
- (NSRect) upButtonRectWithFrame: (NSRect)frame;
- (NSRect) downButtonRectWithFrame: (NSRect)frame;
@end
@implementation NSStepperCell
@ -74,6 +65,8 @@
- (id) init
{
self = [super init];
if (!self)
return nil;
[self setIntValue: 0];
[self setAlignment: NSRightTextAlignment];
@ -143,36 +136,11 @@
- (void) drawInteriorWithFrame: (NSRect)cellFrame
inView: (NSView*)controlView
{
NSRect upRect;
NSRect downRect;
NSRect twoButtons;
upRect = [self upButtonRectWithFrame: cellFrame];
downRect = [self downButtonRectWithFrame: cellFrame];
twoButtons = downRect;
twoButtons.origin.y--;
twoButtons.size.width++;
twoButtons.size.height = 2 * STEPPER_HEIGHT + 1;
if (highlightUp)
[[GSTheme theme] drawStepperHighlightUpButton: upRect];
else
[[GSTheme theme] drawStepperUpButton: upRect];
if (highlightDown)
[[GSTheme theme] drawStepperHighlightDownButton: downRect];
else
[[GSTheme theme] drawStepperDownButton: downRect];
{
NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge};
NSColor *black = [NSColor controlDarkShadowColor];
NSColor *grays[] = {black, black};
NSDrawColorTiledRects(twoButtons, NSZeroRect,
up_sides, grays, 2);
}
[[GSTheme theme] drawStepperCell: self
withFrame: cellFrame
inView: controlView
highlightUp: highlightUp
highlightDown: highlightDown];
}
- (void) getPeriodicDelay: (float*)delay interval: (float*)interval
@ -214,8 +182,8 @@
if ([theEvent type] != NSLeftMouseDown)
return NO;
upRect = [self upButtonRectWithFrame: cellFrame];
downRect = [self downButtonRectWithFrame: cellFrame];
upRect = [[GSTheme theme] stepperUpButtonRectWithFrame: cellFrame];
downRect = [[GSTheme theme] stepperDownButtonRectWithFrame: cellFrame];
// Did the mouse go down in the up or in the down part?
if (NSMouseInRect(point, upRect, NO))
@ -475,26 +443,4 @@
[controlView setNeedsDisplayInRect: frame];
}
- (NSRect) upButtonRectWithFrame: (NSRect)frame
{
NSRect upRect;
upRect.size.width = STEPPER_WIDTH;
upRect.size.height = STEPPER_HEIGHT;
upRect.origin.x = NSMaxX(frame) - STEPPER_WIDTH - 1;
upRect.origin.y = NSMinY(frame) + ((int)frame.size.height / 2) + 1;
return upRect;
}
- (NSRect) downButtonRectWithFrame: (NSRect)frame
{
NSRect downRect;
downRect.size.width = STEPPER_WIDTH;
downRect.size.height = STEPPER_HEIGHT;
downRect.origin.x = NSMaxX(frame) - STEPPER_WIDTH - 1;
downRect.origin.y = NSMinY(frame) + ((int)frame.size.height / 2) - STEPPER_HEIGHT + 1;
return downRect;
}
@end