Implement image cursor

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@6111 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fedor 2000-02-25 17:09:49 +00:00
parent bbdbc3844b
commit 936275a658
2 changed files with 35 additions and 12 deletions

View file

@ -1,3 +1,7 @@
2000-02-25 Adam Fedor <fedor@gnu.org>
* Source/NSCursor.m ([NSCursor -setImage:]): Implement.
Fri Feb 25 07:07:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk> Fri Feb 25 07:07:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSWorkspace.m: Removed a little unused code and fixed a * Source/NSWorkspace.m: Removed a little unused code and fixed a

View file

@ -29,6 +29,8 @@
#include <gnustep/gui/config.h> #include <gnustep/gui/config.h>
#include <Foundation/NSArray.h> #include <Foundation/NSArray.h>
#include <AppKit/NSCursor.h> #include <AppKit/NSCursor.h>
#include <AppKit/NSImage.h>
#include <AppKit/NSBitmapImageRep.h>
#include <AppKit/NSGraphicsContext.h> #include <AppKit/NSGraphicsContext.h>
#include <AppKit/DPSOperators.h> #include <AppKit/DPSOperators.h>
@ -86,7 +88,7 @@ static BOOL gnustep_gui_hidden_until_move;
if ([gnustep_gui_current_cursor _cid]) if ([gnustep_gui_current_cursor _cid])
{ {
DPSsetcursorcolor(GSCurrentContext(), 0, 0, 0, 1, 1, 1, DPSsetcursorcolor(GSCurrentContext(), -1, 0, 0, 1, 1, 1,
[gnustep_gui_current_cursor _cid]); [gnustep_gui_current_cursor _cid]);
} }
} }
@ -151,14 +153,11 @@ static BOOL gnustep_gui_hidden_until_move;
- (id) initWithImage: (NSImage *)newImage hotSpot: (NSPoint)spot - (id) initWithImage: (NSImage *)newImage hotSpot: (NSPoint)spot
{ {
self = [super init]; hot_spot = spot;
if (self != nil) is_set_on_mouse_entered = NO;
{ is_set_on_mouse_exited = NO;
cursor_image = newImage; if (newImage)
hot_spot = spot; [self setImage: newImage];
is_set_on_mouse_entered = NO;
is_set_on_mouse_exited = NO;
}
return self; return self;
} }
@ -182,7 +181,27 @@ static BOOL gnustep_gui_hidden_until_move;
- (void) setImage: (NSImage *)newImage - (void) setImage: (NSImage *)newImage
{ {
cursor_image = newImage; void *c;
NSBitmapImageRep *rep;
ASSIGN(cursor_image, newImage);
rep = [newImage bestRepresentationForDevice: nil];
/* FIXME: Handle cached image reps also */
if (!rep || ![rep respondsToSelector: @selector(samplesPerPixel)])
{
NSLog(@"NSCursor can only handle NSBitmapImageReps for now");
return;
}
if (hot_spot.x >= [rep pixelsWide])
hot_spot.x = [rep pixelsWide]-1;
if (hot_spot.y >= [rep pixelsHigh])
hot_spot.y = [rep pixelsHigh]-1;
DPSimagecursor(GSCurrentContext(), hot_spot.x, hot_spot.y,
[rep pixelsWide], [rep pixelsHigh],
[rep samplesPerPixel], [rep bitmapData], &c);
[self _setCid: c];
} }
/* /*
@ -241,7 +260,7 @@ static BOOL gnustep_gui_hidden_until_move;
gnustep_gui_current_cursor = self; gnustep_gui_current_cursor = self;
if (cid) if (cid)
{ {
DPSsetcursorcolor(GSCurrentContext(), 0, 0, 0, 1, 1, 1, cid); DPSsetcursorcolor(GSCurrentContext(), -1, 0, 0, 1, 1, 1, cid);
} }
} }
@ -250,7 +269,7 @@ static BOOL gnustep_gui_hidden_until_move;
gnustep_gui_current_cursor = self; gnustep_gui_current_cursor = self;
if (cid) if (cid)
{ {
DPSsetcursorcolor(GSCurrentContext(), 0, 0, 0, 1, 1, 1, cid); DPSsetcursorcolor(GSCurrentContext(), -1, 0, 0, 1, 1, 1, cid);
} }
} }