mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 08:30:59 +00:00
* Headers/Additions/GNUstepGUI/GSTheme.h:
* Source/GSTheme.m: Declare GSSliderHorizontalTrack and GSSliderVerticalTrack part names for themeing the background of NSSlider * Source/GSThemeDrawing.m: Add new drawSliderBorderAndBackground:frame:inCell:isHorizontal: method to draw the slider border and background. * Source/GSThemePrivate.h: * Source/GSThemeTools.m: Add a -size method on GSDrawTiles which returns the total original size of the tiles, so we can easily compute a rect that scales the tiles in only one dimension. * Source/NSSliderCell.m: Override _drawBorderAndBackgroundWithFrame: to call new GSTheme method. Also, tweak the knob drawing code; the knob is now centered and drawn at its native size. This still looks correct with the default slider sizes create by Gorm. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@37185 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d3be1c555f
commit
2347347cf9
7 changed files with 147 additions and 17 deletions
20
ChangeLog
20
ChangeLog
|
@ -1,3 +1,23 @@
|
|||
2013-10-02 Eric Wasylishen <ewasylishen@gmail.com>
|
||||
|
||||
* Headers/Additions/GNUstepGUI/GSTheme.h:
|
||||
* Source/GSTheme.m:
|
||||
Declare GSSliderHorizontalTrack and GSSliderVerticalTrack
|
||||
part names for themeing the background of NSSlider
|
||||
* Source/GSThemeDrawing.m:
|
||||
Add new drawSliderBorderAndBackground:frame:inCell:isHorizontal:
|
||||
method to draw the slider border and background.
|
||||
* Source/GSThemePrivate.h:
|
||||
* Source/GSThemeTools.m:
|
||||
Add a -size method on GSDrawTiles which returns the total
|
||||
original size of the tiles, so we can easily compute a rect
|
||||
that scales the tiles in only one dimension.
|
||||
* Source/NSSliderCell.m:
|
||||
Override _drawBorderAndBackgroundWithFrame: to call new
|
||||
GSTheme method. Also, tweak the knob drawing code; the knob
|
||||
is now centered and drawn at its native size. This still looks
|
||||
correct with the default slider sizes create by Gorm.
|
||||
|
||||
2013-10-02 Eric Wasylishen <ewasylishen@gmail.com>
|
||||
|
||||
* Source/NSMenuView.m (heightForItem:, yOriginForItem:):
|
||||
|
|
|
@ -301,6 +301,10 @@ APPKIT_EXPORT NSString *GSProgressIndicatorBarDeterminate;
|
|||
*/
|
||||
APPKIT_EXPORT NSString *GSColorWell;
|
||||
|
||||
/* NSSliderCell parts */
|
||||
APPKIT_EXPORT NSString *GSSliderHorizontalTrack;
|
||||
APPKIT_EXPORT NSString *GSSliderVerticalTrack;
|
||||
|
||||
/**
|
||||
* Structure to describe the size of top/bottom/left/right margins inside
|
||||
* a button
|
||||
|
@ -1132,6 +1136,11 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification;
|
|||
- (void) drawScrollViewRect: (NSRect)rect
|
||||
inView: (NSView *)view;
|
||||
|
||||
- (void) drawSliderBorderAndBackground: (NSBorderType)aType
|
||||
frame: (NSRect)cellFrame
|
||||
inCell: (NSCell *)cell
|
||||
isHorizontal: (BOOL)horizontal;
|
||||
|
||||
- (void) drawBarInside: (NSRect)rect
|
||||
inCell: (NSCell *)cell
|
||||
flipped: (BOOL)flipped;
|
||||
|
|
|
@ -105,6 +105,10 @@ NSString *GSProgressIndicatorBarDeterminate
|
|||
// Color well part names
|
||||
NSString *GSColorWell = @"GSColorWell";
|
||||
|
||||
// Slider part names
|
||||
NSString *GSSliderHorizontalTrack = @"GSSliderHorizontalTrack";
|
||||
NSString *GSSliderVerticalTrack = @"GSSliderVerticalTrack";
|
||||
|
||||
NSString *GSThemeDidActivateNotification
|
||||
= @"GSThemeDidActivateNotification";
|
||||
NSString *GSThemeDidDeactivateNotification
|
||||
|
|
|
@ -2399,6 +2399,54 @@ static NSDictionary *titleTextAttributes[3] = {nil, nil, nil};
|
|||
}
|
||||
}
|
||||
|
||||
- (void) drawSliderBorderAndBackground: (NSBorderType)aType
|
||||
frame: (NSRect)cellFrame
|
||||
inCell: (NSCell *)cell
|
||||
isHorizontal: (BOOL)horizontal
|
||||
{
|
||||
NSSliderType type = [(NSSliderCell *)cell sliderType];
|
||||
if (type == NSLinearSlider)
|
||||
{
|
||||
NSString *partName = (horizontal ? GSSliderHorizontalTrack : GSSliderVerticalTrack);
|
||||
GSDrawTiles *tiles = [self tilesNamed: partName
|
||||
state: GSThemeNormalState];
|
||||
|
||||
if (tiles == nil)
|
||||
{
|
||||
[[GSTheme theme] drawBorderType: aType
|
||||
frame: cellFrame
|
||||
view: [cell controlView]];
|
||||
}
|
||||
else
|
||||
{
|
||||
// FIXME: This code could be factored out
|
||||
NSSize tilesNaturalSize = [tiles size];
|
||||
NSRect tilesRect;
|
||||
|
||||
// Only stretch the tiles in one direction
|
||||
if (horizontal)
|
||||
{
|
||||
tilesRect.size = NSMakeSize(cellFrame.size.width, tilesNaturalSize.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
tilesRect.size = NSMakeSize(tilesNaturalSize.width, cellFrame.size.height);
|
||||
}
|
||||
tilesRect.origin = NSMakePoint((cellFrame.size.width - tilesRect.size.width) / 2.0,
|
||||
(cellFrame.size.height - tilesRect.size.height) / 2.0);
|
||||
|
||||
if ([cell controlView] != nil)
|
||||
{
|
||||
tilesRect = [[cell controlView] centerScanRect: tilesRect];
|
||||
}
|
||||
|
||||
[self fillRect: tilesRect
|
||||
withTiles: tiles
|
||||
background: [NSColor clearColor]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void) drawBarInside: (NSRect)rect
|
||||
inCell: (NSCell *)cell
|
||||
flipped: (BOOL)flipped
|
||||
|
@ -2406,8 +2454,18 @@ static NSDictionary *titleTextAttributes[3] = {nil, nil, nil};
|
|||
NSSliderType type = [(NSSliderCell *)cell sliderType];
|
||||
if (type == NSLinearSlider)
|
||||
{
|
||||
[[NSColor scrollBarColor] set];
|
||||
NSRectFill(rect);
|
||||
BOOL horizontal = (rect.size.width > rect.size.height);
|
||||
NSString *partName = (horizontal ? GSSliderHorizontalTrack : GSSliderVerticalTrack);
|
||||
GSDrawTiles *tiles = [self tilesNamed: partName
|
||||
state: GSThemeNormalState];
|
||||
|
||||
if (tiles == nil)
|
||||
{
|
||||
[[NSColor scrollBarColor] set];
|
||||
NSRectFill(rect);
|
||||
}
|
||||
// Don't draw anything if we have tiles, they are drawn
|
||||
// in -drawSliderBorderAndBackground:...
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -130,6 +130,15 @@ typedef enum {
|
|||
- (GSThemeFillStyle) fillStyle;
|
||||
- (void) setFillStyle: (GSThemeFillStyle)aStyle;
|
||||
|
||||
/**
|
||||
* Returns the sum of the widths of the left, middle, and right tiles,
|
||||
* and the sum of the heights of the top, center, and bottom tiles, before scaling.
|
||||
*
|
||||
* Can be used to calculate a rect to draw the tiles in such that they are only
|
||||
* filled in one direction.
|
||||
*/
|
||||
- (NSSize) size;
|
||||
|
||||
@end
|
||||
|
||||
/** This is the panel used to select and inspect themes.
|
||||
|
|
|
@ -1609,5 +1609,18 @@ withRepeatedImage: (NSImage*)image
|
|||
style = aStyle;
|
||||
}
|
||||
|
||||
- (NSSize) size
|
||||
{
|
||||
const CGFloat width = rects[TileCL].size.width
|
||||
+ rects[TileCM].size.width
|
||||
+ rects[TileCR].size.width;
|
||||
|
||||
const CGFloat height = rects[TileTM].size.height
|
||||
+ rects[TileCM].size.height
|
||||
+ rects[TileBM].size.height;
|
||||
|
||||
return NSMakeSize(width, height);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -224,6 +224,25 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
|
|||
}
|
||||
}
|
||||
|
||||
- (void) _drawBorderAndBackgroundWithFrame: (NSRect)cellFrame
|
||||
inView: (NSView*)controlView
|
||||
{
|
||||
NSBorderType aType;
|
||||
|
||||
if (_cell.is_bordered)
|
||||
aType = NSLineBorder;
|
||||
else if (_cell.is_bezeled)
|
||||
aType = NSBezelBorder;
|
||||
else
|
||||
aType = NSNoBorder;
|
||||
|
||||
[[GSTheme theme] drawSliderBorderAndBackground: aType
|
||||
frame: cellFrame
|
||||
inCell: self
|
||||
isHorizontal: ![self isVertical]];
|
||||
}
|
||||
|
||||
|
||||
/** <p>Draws the slider's track, not including the bezel, in <var>aRect</var>
|
||||
<var>flipped</var> indicates whether the control view has a flipped
|
||||
coordinate system.</p>
|
||||
|
@ -274,15 +293,26 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
|
|||
if (_isVertical == YES)
|
||||
{
|
||||
origin = _trackRect.origin;
|
||||
origin.x += (_trackRect.size.width - size.width) / 2.0; // center horizontally
|
||||
origin.y += (_trackRect.size.height - size.height) * floatValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
origin = _trackRect.origin;
|
||||
origin.x += (_trackRect.size.width - size.width) * floatValue;
|
||||
origin.y += (_trackRect.size.height - size.height) / 2.0; // center vertically
|
||||
}
|
||||
|
||||
return NSMakeRect (origin.x, origin.y, size.width, size.height);
|
||||
{
|
||||
NSRect result = NSMakeRect (origin.x, origin.y, size.width, size.height);
|
||||
|
||||
if ([self controlView])
|
||||
{
|
||||
result = [[self controlView] centerScanRect: result];
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/** <p>Calculates the rect in which to draw the knob, then calls
|
||||
|
@ -366,30 +396,17 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
|
|||
else if (_type == NSLinearSlider)
|
||||
{
|
||||
BOOL vertical = (cellFrame.size.height > cellFrame.size.width);
|
||||
NSImage *image;
|
||||
NSSize size;
|
||||
|
||||
if (vertical != _isVertical)
|
||||
{
|
||||
NSImage *image;
|
||||
if (vertical == YES)
|
||||
{
|
||||
image = [NSImage imageNamed: @"common_SliderVert"];
|
||||
if (image != nil)
|
||||
{
|
||||
size = [image size];
|
||||
[image setScalesWhenResized: YES];
|
||||
[image setSize: NSMakeSize(cellFrame.size.width, size.height)];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
image = [NSImage imageNamed: @"common_SliderHoriz"];
|
||||
if (image != nil)
|
||||
{
|
||||
size = [image size];
|
||||
[image setScalesWhenResized: YES];
|
||||
[image setSize: NSMakeSize(size.width, cellFrame.size.height)];
|
||||
}
|
||||
}
|
||||
[_knobCell setImage: image];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue