mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 16:10:48 +00:00
* Source/NSColorPanel.m: Make a magnifying glass cursor when using
the magnifying glass color picker. back/x11 isn't displaying the cursor at the moment. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@33543 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
a8c841bd33
commit
3958406375
2 changed files with 55 additions and 3 deletions
|
@ -1,3 +1,9 @@
|
|||
2011-07-13 Eric Wasylishen <ewasylishen@gmail.com>
|
||||
|
||||
* Source/NSColorPanel.m: Make a magnifying glass cursor when using
|
||||
the magnifying glass color picker. back/x11 isn't displaying
|
||||
the cursor at the moment.
|
||||
|
||||
2011-07-13 German Arias <german@xelalug.org>
|
||||
|
||||
* Resources/Spanish.lproj/Localizable.strings: More strings.
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#import "AppKit/NSBox.h"
|
||||
#import "AppKit/NSButton.h"
|
||||
#import "AppKit/NSButtonCell.h"
|
||||
#import "AppKit/NSBezierPath.h"
|
||||
#import "AppKit/NSColor.h"
|
||||
#import "AppKit/NSColorPanel.h"
|
||||
#import "AppKit/NSColorPicker.h"
|
||||
|
@ -369,12 +370,55 @@ static int _gs_gui_color_picker_mode = NSRGBModeColorPanel;
|
|||
[NSApp sendAction: _action to: _target from: self];
|
||||
}
|
||||
|
||||
- (NSImage *) _magnifyingGlassImageWithScreenshot: (NSImage*)screenshot
|
||||
{
|
||||
NSImage *result;
|
||||
NSGraphicsContext *ctx;
|
||||
NSImageInterpolation oldInterpolation;
|
||||
const NSRect glassFrame = NSMakeRect(3,11,19,18);
|
||||
const NSSize imageSize = NSMakeSize(32, 32); // These metrics are for Images/MagnifyGlass.tiff
|
||||
|
||||
result = [[[NSImage alloc] initWithSize: imageSize] autorelease];
|
||||
[result lockFocus];
|
||||
|
||||
ctx = [NSGraphicsContext currentContext];
|
||||
|
||||
// 1. draw the screenshot, clipped so it lies within the circle part of
|
||||
// the magnifying glass and with no interpolation
|
||||
[ctx saveGraphicsState];
|
||||
[[NSBezierPath bezierPathWithOvalInRect: glassFrame] addClip];
|
||||
oldInterpolation = [ctx imageInterpolation];
|
||||
[ctx setImageInterpolation: NSImageInterpolationNone];
|
||||
[screenshot drawInRect: glassFrame
|
||||
fromRect: NSZeroRect
|
||||
operation: NSCompositeSourceOver
|
||||
fraction: 1.0];
|
||||
[ctx setImageInterpolation: oldInterpolation];
|
||||
[ctx restoreGraphicsState];
|
||||
|
||||
// 2. draw the magnifying glass over top
|
||||
[[NSImage imageNamed: @"MagnifyGlass"] drawInRect: NSMakeRect(0, 0, imageSize.width, imageSize.height)
|
||||
fromRect: NSZeroRect
|
||||
operation: NSCompositeSourceOver
|
||||
fraction: 1.0];
|
||||
|
||||
[result unlockFocus];
|
||||
return result;
|
||||
}
|
||||
|
||||
- (NSCursor *) _magnifyingGlassCursorWithScreenshot: (NSImage*)screenshot
|
||||
{
|
||||
return [[[NSCursor alloc] initWithImage: [self _magnifyingGlassImageWithScreenshot: screenshot]
|
||||
hotSpot: NSMakePoint(13, 13)] autorelease];
|
||||
}
|
||||
|
||||
- (void) _magnify: (id) sender
|
||||
{
|
||||
NSEvent *currentEvent;
|
||||
|
||||
[self _captureMouse: self];
|
||||
[[NSCursor crosshairCursor] push];
|
||||
|
||||
[[self _magnifyingGlassCursorWithScreenshot: nil] push];
|
||||
|
||||
NS_DURING
|
||||
{
|
||||
|
@ -390,13 +434,15 @@ static int _gs_gui_color_picker_mode = NSRGBModeColorPanel;
|
|||
mouseLoc = [self convertBaseToScreen: [self mouseLocationOutsideOfEventStream]];
|
||||
|
||||
img = [GSCurrentServer() contentsOfScreen: [[self screen] screenNumber]
|
||||
inRect: NSMakeRect(mouseLoc.x, mouseLoc.y, 1, 1)];
|
||||
inRect: NSMakeRect(mouseLoc.x - 4, mouseLoc.y - 4, 9, 9)];
|
||||
|
||||
if (img != nil)
|
||||
{
|
||||
NSBitmapImageRep *rep = (NSBitmapImageRep *)[img bestRepresentationForDevice: nil];
|
||||
NSColor *color = [rep colorAtX: 0 y: 0];
|
||||
NSColor *color = [rep colorAtX: 5 y: 5];
|
||||
[self setColor: color];
|
||||
|
||||
[[self _magnifyingGlassCursorWithScreenshot: img] set];
|
||||
}
|
||||
} while ([currentEvent type] != NSLeftMouseUp &&
|
||||
[currentEvent type] != NSLeftMouseDown);
|
||||
|
|
Loading…
Reference in a new issue