improve user experience with the color picker magnifying glass, particularly on Windows which would crash

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_testplant_branch@39193 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Doug Simons 2015-11-23 19:52:22 +00:00
parent fef3c6ca6d
commit 04f41a193a
2 changed files with 53 additions and 15 deletions

View file

@ -1,3 +1,9 @@
2015-11-23 Doug Simons <doug.simons@testplant.com>
* Source/NSColorPanel.m: Improve the user experience when using
the magnifying glass to select a color from the screen. Also,
allow typing Escape to cancel the magnify mode.
2015-09-10 Doug Simons <doug.simons@testplant.com> and Paul Landers <paul.landers@testplant.com>
* Source/NSLayoutManager.m: Fix a bug that would try to adjust

View file

@ -58,6 +58,7 @@
#import "GNUstepGUI/GSDisplayServer.h"
#import "GNUstepGUI/IMLoading.h"
#import "unistd.h"
#import "GSGuiPrivate.h"
@ -372,6 +373,13 @@ static int _gs_gui_color_picker_mode = NSRGBModeColorPanel;
{
NSEvent *currentEvent;
NSCursor *cursor;
NSColor *color = nil;
BOOL cancel = NO;
BOOL liveFeedback = YES; // set to show color dynamically in the panel while mouse is moving
#if defined(__MINGW__)
liveFeedback = NO; // live feedback causes serious problems on Windows
#endif
liveFeedback = NO; // even on Linux the experience is better without the feedback (at least on CentOS 6.5)
[self _captureMouse: self];
@ -387,30 +395,54 @@ static int _gs_gui_color_picker_mode = NSRGBModeColorPanel;
NS_DURING
{
NSPoint mouseLoc;
NSImage *img;
do {
NSPoint mouseLoc;
NSImage *img;
CREATE_AUTORELEASE_POOL(pool);
currentEvent = [NSApp nextEventMatchingMask: NSLeftMouseDownMask | NSLeftMouseUpMask | NSMouseMovedMask
currentEvent = [NSApp nextEventMatchingMask: NSLeftMouseDownMask | NSLeftMouseUpMask | NSMouseMovedMask | NSKeyDownMask | NSKeyUpMask
untilDate: [NSDate distantFuture]
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
mouseLoc = [self convertBaseToScreen: [self mouseLocationOutsideOfEventStream]];
img = [GSCurrentServer() contentsOfScreen: [[self screen] screenNumber]
inRect: NSMakeRect(mouseLoc.x, mouseLoc.y, 1, 1)];
if (img != nil)
if ([currentEvent type] == NSKeyUp || [currentEvent type] == NSKeyDown)
{
NSBitmapImageRep *rep = (NSBitmapImageRep *)[img bestRepresentationForDevice: nil];
NSColor *color = [rep colorAtX: 0 y: 0];
[self setColor: color];
if ([[currentEvent charactersIgnoringModifiers] isEqualToString:@"\e"])
{
cancel = YES; // allow Escape to cancel the magnifier
}
}
[pool drain];
} while ([currentEvent type] != NSLeftMouseUp &&
else if (liveFeedback)
{
mouseLoc = [self convertBaseToScreen: [self mouseLocationOutsideOfEventStream]];
img = [GSCurrentServer() contentsOfScreen: [[self screen] screenNumber]
inRect: NSMakeRect(mouseLoc.x, mouseLoc.y, 1, 1)];
if (img != nil)
{
NSBitmapImageRep *rep = (NSBitmapImageRep *)[img bestRepresentationForDevice: nil];
color = [rep colorAtX: 0 y: 0];
[_colorWell setColor: color]; // show color for feedback, but don't send action yet
}
}
[pool drain];
} while (!cancel &&
[currentEvent type] != NSLeftMouseUp &&
[currentEvent type] != NSLeftMouseDown);
if (!liveFeedback && !cancel)
{
mouseLoc = [self convertBaseToScreen: [self mouseLocationOutsideOfEventStream]];
img = [GSCurrentServer() contentsOfScreen: [[self screen] screenNumber]
inRect: NSMakeRect(mouseLoc.x, mouseLoc.y, 1, 1)];
if (img != nil)
{
NSBitmapImageRep *rep = (NSBitmapImageRep *)[img bestRepresentationForDevice: nil];
color = [rep colorAtX: 0 y: 0];
}
}
if (color && !cancel)
[self setColor: color];
}
NS_HANDLER
{