Cursor::Cursor(Image* image, const IntPoint& hotSpot) { #ifndef QT_NO_CURSOR IntPoint effectiveHotSpot = determineHotSpot(image, hotSpot); m_impl = QCursor(*(image->nativeImageForCurrentFrame()), effectiveHotSpot.x(), effectiveHotSpot.y()); #endif }
Cursor::Cursor(Image* image, const IntPoint& hotSpot) : m_type(Custom) , m_image(image) , m_hotSpot(determineHotSpot(image, hotSpot)) , m_platformCursor(0) { }
static QCursor* createCustomCursor(Image* image, const IntPoint& hotSpot) { if (!image->nativeImageForCurrentFrame()) return 0; IntPoint effectiveHotSpot = determineHotSpot(image, hotSpot); return new QCursor(*(image->nativeImageForCurrentFrame()), effectiveHotSpot.x(), effectiveHotSpot.y()); }
Cursor::Cursor(Image* image, bool hotSpotSpecified, const IntPoint& hotSpot, float scale) : m_type(Custom) , m_image(image) , m_hotSpot(determineHotSpot(image, hotSpotSpecified, hotSpot)) , m_imageScaleFactor(scale) { }
Cursor::Cursor(Image* image, const IntPoint& hotSpot) : m_type(Custom) , m_image(image) , m_hotSpot(determineHotSpot(image, hotSpot)) , m_imageScaleFactor(1) { }
Cursor::Cursor(Image* image, const IntPoint& hotSpot, float scale) : m_type(Custom) , m_image(image) , m_hotSpot(determineHotSpot(image, hotSpot)) , m_imageScaleFactor(scale) , m_platformCursor(0) { }
Cursor::Cursor(Image* image, const IntPoint& hotSpot) : m_type(Custom) , m_image(image) , m_hotSpot(determineHotSpot(image, hotSpot)) #if ENABLE(MOUSE_CURSOR_SCALE) , m_imageScaleFactor(1) #endif , m_platformCursor(0) { }
static GRefPtr<GdkCursor> createCustomCursor(Image* image, const IntPoint& hotSpot) { GRefPtr<GdkPixbuf> pixbuf = adoptGRef(image->getGdkPixbuf()); if (!image->nativeImageForCurrentFrame() || !pixbuf) return 0; IntPoint effectiveHotSpot = determineHotSpot(image, hotSpot); return adoptGRef(gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf.get(), effectiveHotSpot.x(), effectiveHotSpot.y())); }
static PassRefPtr<SharedCursor> createSharedCursor(Image* img, const IntPoint& hotSpot) { RefPtr<SharedCursor> impl; IntPoint effectiveHotSpot = determineHotSpot(img, hotSpot); static bool doAlpha = windowsVersion() >= WindowsXP; BitmapInfo cursorImage = BitmapInfo::create(IntSize(img->width(), img->height())); HWndDC dc(0); auto workingDC = adoptGDIObject(::CreateCompatibleDC(dc)); if (doAlpha) { auto hCursor = adoptGDIObject(::CreateDIBSection(dc, (BITMAPINFO *)&cursorImage, DIB_RGB_COLORS, 0, 0, 0)); ASSERT(hCursor); img->getHBITMAP(hCursor.get()); HBITMAP hOldBitmap = (HBITMAP)SelectObject(workingDC.get(), hCursor.get()); SetBkMode(workingDC.get(), TRANSPARENT); SelectObject(workingDC.get(), hOldBitmap); Vector<unsigned char, 128> maskBits; maskBits.fill(0xff, (img->width() + 7) / 8 * img->height()); auto hMask = adoptGDIObject(::CreateBitmap(img->width(), img->height(), 1, 1, maskBits.data())); ICONINFO ii; ii.fIcon = FALSE; ii.xHotspot = effectiveHotSpot.x(); ii.yHotspot = effectiveHotSpot.y(); ii.hbmMask = hMask.get(); ii.hbmColor = hCursor.get(); impl = SharedCursor::create(::CreateIconIndirect(&ii)); } else { // Platform doesn't support alpha blended cursors, so we need // to create the mask manually auto andMaskDC = adoptGDIObject(::CreateCompatibleDC(dc)); auto xorMaskDC = adoptGDIObject(::CreateCompatibleDC(dc)); auto hCursor = adoptGDIObject(::CreateDIBSection(dc, &cursorImage, DIB_RGB_COLORS, 0, 0, 0)); ASSERT(hCursor); img->getHBITMAP(hCursor.get()); BITMAP cursor; GetObject(hCursor.get(), sizeof(BITMAP), &cursor); auto andMask = adoptGDIObject(::CreateBitmap(cursor.bmWidth, cursor.bmHeight, 1, 1, 0)); auto xorMask = adoptGDIObject(::CreateCompatibleBitmap(dc, cursor.bmWidth, cursor.bmHeight)); HBITMAP oldCursor = (HBITMAP)SelectObject(workingDC.get(), hCursor.get()); HBITMAP oldAndMask = (HBITMAP)SelectObject(andMaskDC.get(), andMask.get()); HBITMAP oldXorMask = (HBITMAP)SelectObject(xorMaskDC.get(), xorMask.get()); SetBkColor(workingDC.get(), RGB(0, 0, 0)); BitBlt(andMaskDC.get(), 0, 0, cursor.bmWidth, cursor.bmHeight, workingDC.get(), 0, 0, SRCCOPY); SetBkColor(xorMaskDC.get(), RGB(255, 255, 255)); SetTextColor(xorMaskDC.get(), RGB(255, 255, 255)); BitBlt(xorMaskDC.get(), 0, 0, cursor.bmWidth, cursor.bmHeight, andMaskDC.get(), 0, 0, SRCCOPY); BitBlt(xorMaskDC.get(), 0, 0, cursor.bmWidth, cursor.bmHeight, workingDC.get(), 0, 0, SRCAND); SelectObject(workingDC.get(), oldCursor); SelectObject(andMaskDC.get(), oldAndMask); SelectObject(xorMaskDC.get(), oldXorMask); ICONINFO icon = {0}; icon.fIcon = FALSE; icon.xHotspot = effectiveHotSpot.x(); icon.yHotspot = effectiveHotSpot.y(); icon.hbmMask = andMask.get(); icon.hbmColor = xorMask.get(); impl = SharedCursor::create(CreateIconIndirect(&icon)); } return impl.release(); }
static PlatformRefPtr<GdkCursor> createCustomCursor(Image* image, const IntPoint& hotSpot) { IntPoint effectiveHotSpot = determineHotSpot(image, hotSpot); PlatformRefPtr<GdkPixbuf> pixbuf = adoptPlatformRef(image->getGdkPixbuf()); return adoptPlatformRef(gdk_cursor_new_from_pixbuf(gdk_display_get_default(), pixbuf.get(), effectiveHotSpot.x(), effectiveHotSpot.y())); }