Correct colour sliders to work in flipped views and simplified code.

Let text fields and controls pass on not used mouse down events to next
responder.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@25707 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2007-12-08 22:12:48 +00:00
parent 8730f4cab8
commit ec5e0a3c38
5 changed files with 90 additions and 136 deletions

View file

@ -1,3 +1,14 @@
2007-12-08 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSControl.m (-mouseDown:): Forward event, if not enabled.
* Source/NSTextField.m (-mouseDown:): Send event to next
responder not to super, if not selectable or disabled.
* ColorPickers/GSStandardColorPicker.m (GSColorSliderCell):
Corrected to work with horizontal and vertial views and for
flipped ones.
* ColorPickers/GSWheelColorPicker.m: Replace
GSWheelColorSliderCell with GSColorSliderCell.
2007-12-07 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSTableView.m (-initWithCoder:): Don't create a header

View file

@ -34,6 +34,7 @@
#include "GSHSBColorPicker.h"
#include "GSCMYKColorPicker.h"
#include "GSGrayColorPicker.h"
#include "GSStandardColorPicker.h"
@interface GSStandardColorPicker: NSColorPicker <NSColorPickingCustom>
{
@ -273,12 +274,6 @@
@end
#include "GSStandardColorPicker.h"
#include <GNUstepGUI/GSVbox.h>
#include <GNUstepGUI/GSHbox.h>
#define KNOB_WIDTH 6
@ -294,14 +289,14 @@
case 2:
case 3:
case 10:
[_titleCell setTextColor: [NSColor whiteColor]];
break;
[_titleCell setTextColor: [NSColor whiteColor]];
break;
case 4:
case 5:
case 6:
case 7:
[_titleCell setTextColor: [NSColor blackColor]];
break;
[_titleCell setTextColor: [NSColor blackColor]];
break;
}
[_titleCell setAlignment: NSLeftTextAlignment];
}
@ -314,9 +309,9 @@
if (mode == 8 || mode == 9)
{
if (c>0.7)
[_titleCell setTextColor: [NSColor blackColor]];
[_titleCell setTextColor: [NSColor blackColor]];
else
[_titleCell setTextColor: [NSColor whiteColor]];
[_titleCell setTextColor: [NSColor whiteColor]];
}
}
@ -354,34 +349,67 @@
-(void) drawBarInside: (NSRect)r flipped: (BOOL)flipped
{
float i, f;
for (i = r.origin.x; i < r.origin.x + r.size.width; i += 1)
if (_isVertical)
{
f = (0.5 + i) / r.size.width;
switch (mode)
{
case 0: PSsetgray(f); break;
for (i = 0; i < r.size.height; i += 1)
{
f = (0.5 + i) / r.size.height;
if (flipped)
{
f = 1 - f;
}
switch (mode)
{
case 0: PSsetgray(f); break;
case 1: PSsetrgbcolor(f, 0, 0); break;
case 2: PSsetrgbcolor(0, f, 0); break;
case 3: PSsetrgbcolor(0, 0, f); break;
case 4: PSsetcmykcolor(f, 0, 0, 0); break;
case 5: PSsetcmykcolor(0, f, 0, 0); break;
case 6: PSsetcmykcolor(0, 0, f, 0); break;
case 7: PSsetcmykcolor(0, 0, 0, f); break;
case 8: PSsethsbcolor(f, values[1], values[2]); break;
case 9: PSsethsbcolor(values[0], f, values[2]); break;
case 10: PSsethsbcolor(values[0], values[1], f); break;
}
if (i + 1 < r.origin.x + r.size.width)
PSrectfill(i, r.origin.y, 1, r.size.height);
else
PSrectfill(i, r.origin.y, r.size.width - i, r.size.height);
case 1: PSsetrgbcolor(f, 0, 0); break;
case 2: PSsetrgbcolor(0, f, 0); break;
case 3: PSsetrgbcolor(0, 0, f); break;
case 4: PSsetcmykcolor(f, 0, 0, 0); break;
case 5: PSsetcmykcolor(0, f, 0, 0); break;
case 6: PSsetcmykcolor(0, 0, f, 0); break;
case 7: PSsetcmykcolor(0, 0, 0, f); break;
case 8: PSsethsbcolor(f, values[1], values[2]); break;
case 9: PSsethsbcolor(values[0], f, values[2]); break;
case 10: PSsethsbcolor(values[0], values[1], f); break;
}
if (i + 1 < r.size.height)
PSrectfill(r.origin.x, i + r.origin.y, r.size.width, 1);
else
PSrectfill(r.origin.x, i + r.origin.y, r.size.width, r.size.height - i);
}
}
if (_isVertical == NO)
else
{
for (i = 0; i < r.size.width; i += 1)
{
f = (0.5 + i) / r.size.width;
switch (mode)
{
case 0: PSsetgray(f); break;
case 1: PSsetrgbcolor(f, 0, 0); break;
case 2: PSsetrgbcolor(0, f, 0); break;
case 3: PSsetrgbcolor(0, 0, f); break;
case 4: PSsetcmykcolor(f, 0, 0, 0); break;
case 5: PSsetcmykcolor(0, f, 0, 0); break;
case 6: PSsetcmykcolor(0, 0, f, 0); break;
case 7: PSsetcmykcolor(0, 0, 0, f); break;
case 8: PSsethsbcolor(f, values[1], values[2]); break;
case 9: PSsethsbcolor(values[0], f, values[2]); break;
case 10: PSsethsbcolor(values[0], values[1], f); break;
}
if (i + 1 < r.size.width)
PSrectfill(i, r.origin.y, 1, r.size.height);
else
PSrectfill(i, r.origin.y, r.size.width - i, r.size.height);
}
[_titleCell drawInteriorWithFrame: r inView: _control_view];
}
}
@ -396,14 +424,11 @@
cellFrame.size.width += 2;
cellFrame.size.height += 2;
[controlView lockFocus];
_trackRect = cellFrame;
[self drawBarInside: cellFrame flipped: [controlView isFlipped]];
[self drawKnob];
[controlView unlockFocus];
}
- (float) knobThickness

View file

@ -35,6 +35,7 @@
#include <Foundation/Foundation.h>
#include <AppKit/AppKit.h>
#include <GNUstepGUI/GSHbox.h>
#include "GSStandardColorPicker.h"
@interface GSColorWheel : NSView
@ -248,96 +249,6 @@
@end
#define KNOB_WIDTH 6
@interface GSColorWheelSliderCell : NSSliderCell
{
float values[2];
}
-(void) _setColorWheelSliderCellValues: (float)a : (float)b;
@end
@implementation GSColorWheelSliderCell : NSSliderCell
-(void) _setColorWheelSliderCellValues: (float)a : (float)b
{
values[0] = a;
values[1] = b;
}
- (NSRect) knobRectFlipped: (BOOL)flipped
{
NSPoint origin;
float floatValue = [self floatValue];
if (_isVertical && flipped)
{
floatValue = _maxValue + _minValue - floatValue;
}
floatValue = (floatValue - _minValue) / (_maxValue - _minValue);
origin = _trackRect.origin;
if (_isVertical == YES)
{
origin.y += (_trackRect.size.height - KNOB_WIDTH) * floatValue;
return NSMakeRect (origin.x, origin.y, _trackRect.size.width, KNOB_WIDTH);
}
else
{
origin.x += (_trackRect.size.width - KNOB_WIDTH) * floatValue;
return NSMakeRect (origin.x, origin.y, KNOB_WIDTH, _trackRect.size.height);
}
}
- (void) drawKnob: (NSRect)knobRect
{
[[NSColor blackColor] set];
NSDrawButton(knobRect, knobRect);
}
-(void) drawBarInside: (NSRect)r flipped: (BOOL)flipped
{
float i, f;
for (i = r.origin.y; i < r.origin.y + r.size.height; i += 1)
{
f = (0.5 + i) / r.size.height;
PSsethsbcolor(values[0], values[1], f);
if (i + 1 < r.origin.y + r.size.height)
PSrectfill(r.origin.x, i, r.size.width, 1);
else
PSrectfill(r.origin.x, i, r.size.width, r.size.height - i);
}
}
-(void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView *)controlView
{
_isVertical = (cellFrame.size.height > cellFrame.size.width);
cellFrame = [self drawingRectForBounds: cellFrame];
cellFrame.origin.x -= 1;
cellFrame.origin.y -= 1;
cellFrame.size.width += 2;
cellFrame.size.height += 2;
[controlView lockFocus];
_trackRect = cellFrame;
[self drawBarInside: cellFrame flipped: [controlView isFlipped]];
[self drawKnob];
[controlView unlockFocus];
}
- (float) knobThickness
{
return KNOB_WIDTH;
}
@end
@interface GSWheelColorPicker: NSColorPicker <NSColorPickingCustom>
{
GSHbox *baseView;
@ -395,8 +306,8 @@
c = [color colorUsingColorSpaceName: NSCalibratedRGBColorSpace];
[c getHue: &hue saturation: &saturation brightness: &brightness alpha: &alpha];
[(GSColorWheelSliderCell *)[brightnessSlider cell]
_setColorWheelSliderCellValues: hue : saturation];
[(GSColorSliderCell *)[brightnessSlider cell]
_setColorSliderCellValues: hue : saturation : brightness];
[brightnessSlider setNeedsDisplay: YES];
[brightnessSlider setFloatValue: brightness];
[wheel setHue: hue saturation: saturation brightness: brightness];
@ -417,7 +328,8 @@
s = brightnessSlider = [[NSSlider alloc] initWithFrame: NSMakeRect(0,0,16,0)];
[s setAutoresizingMask: NSViewHeightSizable];
[s setCell: [[GSColorWheelSliderCell alloc] init]];
[s setCell: [[GSColorSliderCell alloc] init]];
[(GSColorSliderCell *)[s cell] _setColorSliderCellMode: 10];
[s setContinuous: NO];
[s setMinValue: 0.0];
[s setMaxValue: 1.0];
@ -436,8 +348,8 @@
float alpha = [_colorPanel alpha];
NSColor *c;
[(GSColorWheelSliderCell *)[brightnessSlider cell]
_setColorWheelSliderCellValues: hue : saturation];
[(GSColorSliderCell *)[brightnessSlider cell]
_setColorSliderCellValues: hue : saturation : brightness];
[brightnessSlider setNeedsDisplay: YES];
c = [NSColor colorWithCalibratedHue: hue

View file

@ -820,7 +820,10 @@ static NSNotificationCenter *nc;
// If not enabled ignore mouse clicks
if (![self isEnabled])
return;
{
[super mouseDown: theEvent];
return;
}
// Ignore multiple clicks, if configured to do so
if (_ignoresMultiClick && ([theEvent clickCount] > 1))

View file

@ -347,7 +347,10 @@ static Class textFieldCellClass;
{
if ([self isSelectable] == NO || [self isEnabled] == NO)
{
[super mouseDown: theEvent];
if (_next_responder)
[_next_responder mouseDown: theEvent];
else
[super mouseDown: theEvent];
return;
}