Allow scaled image in Fl_Window::cursor(const Fl_RGB_Image *, int, int)
This commit is contained in:
parent
bb74d263e2
commit
f459fdb637
@ -3729,24 +3729,24 @@ int Fl_Cocoa_Window_Driver::set_cursor(const Fl_RGB_Image *image, int hotx, int
|
||||
|
||||
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc]
|
||||
initWithBitmapDataPlanes:NULL
|
||||
pixelsWide:image->w()
|
||||
pixelsHigh:image->h()
|
||||
pixelsWide:image->data_w()
|
||||
pixelsHigh:image->data_h()
|
||||
bitsPerSample:8
|
||||
samplesPerPixel:image->d()
|
||||
hasAlpha:!(image->d() & 1)
|
||||
isPlanar:NO
|
||||
colorSpaceName:(image->d()<=2) ? NSDeviceWhiteColorSpace : NSDeviceRGBColorSpace
|
||||
bytesPerRow:(image->w() * image->d())
|
||||
bytesPerRow:(image->data_w() * image->d())
|
||||
bitsPerPixel:(image->d()*8)];
|
||||
|
||||
// Alpha needs to be premultiplied for this format
|
||||
|
||||
const uchar *i = (const uchar*)*image->data();
|
||||
const int extra_data = image->ld() ? (image->ld() - image->w() * image->d()) : 0;
|
||||
const int extra_data = image->ld() ? (image->ld() - image->data_w() * image->d()) : 0;
|
||||
unsigned char *o = [bitmap bitmapData];
|
||||
for (int y = 0;y < image->h();y++) {
|
||||
for (int y = 0;y < image->data_h();y++) {
|
||||
if (!(image->d() & 1)) {
|
||||
for (int x = 0;x < image->w();x++) {
|
||||
for (int x = 0;x < image->data_w();x++) {
|
||||
unsigned int alpha;
|
||||
if (image->d() == 4) {
|
||||
alpha = i[3];
|
||||
@ -3761,7 +3761,7 @@ int Fl_Cocoa_Window_Driver::set_cursor(const Fl_RGB_Image *image, int hotx, int
|
||||
}
|
||||
} else {
|
||||
// No alpha, so we can just copy everything directly.
|
||||
int len = image->w() * image->d();
|
||||
int len = image->data_w() * image->d();
|
||||
memcpy(o, i, len);
|
||||
o += len;
|
||||
i += len;
|
||||
|
@ -2530,8 +2530,9 @@ int Fl_WinAPI_Window_Driver::set_cursor(Fl_Cursor c) {
|
||||
|
||||
int Fl_WinAPI_Window_Driver::set_cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
|
||||
HCURSOR new_cursor;
|
||||
|
||||
new_cursor = image_to_icon(image, false, hotx, hoty);
|
||||
Fl_RGB_Image *scaled_image = (Fl_RGB_Image*)image->copy();
|
||||
new_cursor = image_to_icon(scaled_image, false, hotx, hoty);
|
||||
delete scaled_image;
|
||||
if (new_cursor == NULL)
|
||||
return 0;
|
||||
|
||||
|
@ -2934,6 +2934,7 @@ int Fl_X11_Window_Driver::set_cursor(const Fl_RGB_Image *image, int hotx, int ho
|
||||
if (!cursor)
|
||||
return 0;
|
||||
|
||||
image = (Fl_RGB_Image*)image->copy();
|
||||
const int extra_data = image->ld() ? (image->ld()-image->w()*image->d()) : 0;
|
||||
const uchar *i = (const uchar*)*image->data();
|
||||
XcursorPixel *o = cursor->pixels;
|
||||
@ -2984,7 +2985,7 @@ int Fl_X11_Window_Driver::set_cursor(const Fl_RGB_Image *image, int hotx, int ho
|
||||
XFreeCursor(fl_display, xc);
|
||||
|
||||
XcursorImageDestroy(cursor);
|
||||
|
||||
delete image;
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user