Cleanup: use const custom cursor arguments to GHOST
Also use int[2] for size & hot-spot arguments to avoid passing around so many arguments.
This commit is contained in:
@@ -332,20 +332,16 @@ extern GHOST_TSuccess GHOST_HasCursorShape(GHOST_WindowHandle windowhandle,
|
||||
* \param windowhandle: The handle to the window.
|
||||
* \param bitmap: The bitmap data for the cursor.
|
||||
* \param mask: The mask for 1bpp cursor, nullptr if RGBA cursor.
|
||||
* \param sizex: The width of the cursor.
|
||||
* \param sizey: The height of the cursor.
|
||||
* \param hotX: The X coordinate of the cursor hot-spot.
|
||||
* \param hotY: The Y coordinate of the cursor hot-spot.
|
||||
* \param size: The width & height of the cursor.
|
||||
* \param hot_spot: The X,Y coordinates of the cursor hot-spot.
|
||||
* \param canInvertColor: Let macOS invert cursor color to match platform convention.
|
||||
* \return Indication of success.
|
||||
*/
|
||||
extern GHOST_TSuccess GHOST_SetCustomCursorShape(GHOST_WindowHandle windowhandle,
|
||||
uint8_t *bitmap,
|
||||
uint8_t *mask,
|
||||
int sizex,
|
||||
int sizey,
|
||||
int hotX,
|
||||
int hotY,
|
||||
const uint8_t *bitmap,
|
||||
const uint8_t *mask,
|
||||
const int size[2],
|
||||
const int hot_spot[2],
|
||||
bool canInvertColor);
|
||||
|
||||
extern GHOST_TSuccess GHOST_GetCursorBitmap(GHOST_WindowHandle windowhandle,
|
||||
|
||||
@@ -322,16 +322,14 @@ class GHOST_IWindow {
|
||||
* Set the shape of the cursor to a custom cursor.
|
||||
* \param bitmap: The bitmap data for the cursor.
|
||||
* \param mask: The mask data for the cursor.
|
||||
* \param hotX: The X coordinate of the cursor hot-spot.
|
||||
* \param hotY: The Y coordinate of the cursor hot-spot.
|
||||
* \param size: The X,Y size of the cursor in pixels.
|
||||
* \param hot_spot: The X,Y coordinate of the cursor hot-spot.
|
||||
* \return Indication of success.
|
||||
*/
|
||||
virtual GHOST_TSuccess setCustomCursorShape(uint8_t *bitmap,
|
||||
uint8_t *mask,
|
||||
int sizex,
|
||||
int sizey,
|
||||
int hotX,
|
||||
int hotY,
|
||||
virtual GHOST_TSuccess setCustomCursorShape(const uint8_t *bitmap,
|
||||
const uint8_t *mask,
|
||||
const int size[2],
|
||||
const int hot_spot[2],
|
||||
bool canInvertColor) = 0;
|
||||
|
||||
virtual GHOST_TSuccess getCursorBitmap(GHOST_CursorBitmapRef *bitmap) = 0;
|
||||
|
||||
@@ -295,17 +295,14 @@ GHOST_TSuccess GHOST_HasCursorShape(GHOST_WindowHandle windowhandle,
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_SetCustomCursorShape(GHOST_WindowHandle windowhandle,
|
||||
uint8_t *bitmap,
|
||||
uint8_t *mask,
|
||||
int sizex,
|
||||
int sizey,
|
||||
int hotX,
|
||||
int hotY,
|
||||
const uint8_t *bitmap,
|
||||
const uint8_t *mask,
|
||||
const int size[2],
|
||||
const int hot_spot[2],
|
||||
bool canInvertColor)
|
||||
{
|
||||
GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
|
||||
|
||||
return window->setCustomCursorShape(bitmap, mask, sizex, sizey, hotX, hotY, canInvertColor);
|
||||
return window->setCustomCursorShape(bitmap, mask, size, hot_spot, canInvertColor);
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_GetCursorBitmap(GHOST_WindowHandle windowhandle,
|
||||
|
||||
@@ -8652,10 +8652,8 @@ GHOST_TSuccess GHOST_SystemWayland::cursor_shape_check(const GHOST_TStandardCurs
|
||||
|
||||
GHOST_TSuccess GHOST_SystemWayland::cursor_shape_custom_set(const uint8_t *bitmap,
|
||||
const uint8_t *mask,
|
||||
const int sizex,
|
||||
const int sizey,
|
||||
const int hotX,
|
||||
const int hotY,
|
||||
const int size[2],
|
||||
const int hot_spot[2],
|
||||
const bool /*canInvertColor*/)
|
||||
{
|
||||
/* Caller needs to lock `server_mutex`. */
|
||||
@@ -8671,9 +8669,8 @@ GHOST_TSuccess GHOST_SystemWayland::cursor_shape_custom_set(const uint8_t *bitma
|
||||
cursor->custom_data_size = 0; /* Not needed, but the value is no longer meaningful. */
|
||||
}
|
||||
|
||||
const int32_t size_xy[2] = {sizex, sizey};
|
||||
wl_buffer *buffer = ghost_wl_buffer_create_for_image(display_->wl.shm,
|
||||
size_xy,
|
||||
size,
|
||||
WL_SHM_FORMAT_ARGB8888,
|
||||
&cursor->custom_data,
|
||||
&cursor->custom_data_size);
|
||||
@@ -8692,8 +8689,8 @@ GHOST_TSuccess GHOST_SystemWayland::cursor_shape_custom_set(const uint8_t *bitma
|
||||
uint8_t datab = 0, maskb = 0;
|
||||
uint32_t *px_dst = static_cast<uint32_t *>(cursor->custom_data);
|
||||
|
||||
for (int y = 0; y < sizey; y++) {
|
||||
for (int x = 0; x < sizex; x++) {
|
||||
for (int y = 0; y < size[1]; y++) {
|
||||
for (int x = 0; x < size[0]; x++) {
|
||||
if ((x % 8) == 0) {
|
||||
datab = *bitmap++;
|
||||
maskb = *mask++;
|
||||
@@ -8718,8 +8715,8 @@ GHOST_TSuccess GHOST_SystemWayland::cursor_shape_custom_set(const uint8_t *bitma
|
||||
/* RGBA color (direct copy). */
|
||||
const uint32_t *px_src = reinterpret_cast<const uint32_t *>(bitmap);
|
||||
uint32_t *px_dst = static_cast<uint32_t *>(cursor->custom_data);
|
||||
for (int y = 0; y < sizey; y++) {
|
||||
for (int x = 0; x < sizex; x++) {
|
||||
for (int y = 0; y < size[1]; y++) {
|
||||
for (int x = 0; x < size[0]; x++) {
|
||||
*px_dst++ = *px_src++;
|
||||
}
|
||||
}
|
||||
@@ -8754,7 +8751,7 @@ GHOST_TSuccess GHOST_SystemWayland::cursor_shape_custom_set(const uint8_t *bitma
|
||||
output_scale = 1;
|
||||
}
|
||||
|
||||
const int custom_size = std::max(sizex, sizey);
|
||||
const int custom_size = std::max(size[0], size[1]);
|
||||
const int target_size = seat->cursor.theme_size * output_scale;
|
||||
|
||||
cursor->custom_scale = std::max(1, (output_scale * custom_size) / target_size);
|
||||
@@ -8763,17 +8760,17 @@ GHOST_TSuccess GHOST_SystemWayland::cursor_shape_custom_set(const uint8_t *bitma
|
||||
* problems with odd-scaling (HI-DPI scale of 300% or 500% for example).
|
||||
* In these cases the custom cursor will be a little too large. */
|
||||
while ((cursor->custom_scale > 1) &&
|
||||
!((sizex % cursor->custom_scale) == 0 && (sizey % cursor->custom_scale) == 0))
|
||||
!((size[0] % cursor->custom_scale) == 0 && (size[1] % cursor->custom_scale) == 0))
|
||||
{
|
||||
cursor->custom_scale -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
cursor->wl.buffer = buffer;
|
||||
cursor->wl.image.width = uint32_t(sizex);
|
||||
cursor->wl.image.height = uint32_t(sizey);
|
||||
cursor->wl.image.hotspot_x = uint32_t(hotX);
|
||||
cursor->wl.image.hotspot_y = uint32_t(hotY);
|
||||
cursor->wl.image.width = uint32_t(size[0]);
|
||||
cursor->wl.image.height = uint32_t(size[1]);
|
||||
cursor->wl.image.hotspot_x = uint32_t(hot_spot[0]);
|
||||
cursor->wl.image.hotspot_y = uint32_t(hot_spot[1]);
|
||||
cursor->wl.theme_cursor = nullptr;
|
||||
cursor->wl.theme_cursor_name = nullptr;
|
||||
|
||||
|
||||
@@ -235,10 +235,8 @@ class GHOST_SystemWayland : public GHOST_System {
|
||||
|
||||
GHOST_TSuccess cursor_shape_custom_set(const uint8_t *bitmap,
|
||||
const uint8_t *mask,
|
||||
int sizex,
|
||||
int sizey,
|
||||
int hotX,
|
||||
int hotY,
|
||||
const int size[2],
|
||||
const int hot_spot[2],
|
||||
bool canInvertColor);
|
||||
|
||||
GHOST_TSuccess cursor_bitmap_get(GHOST_CursorBitmapRef *bitmap);
|
||||
|
||||
@@ -234,10 +234,13 @@ GHOST_TSuccess GHOST_Window::setCursorShape(GHOST_TStandardCursor cursorShape)
|
||||
return GHOST_kFailure;
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_Window::setCustomCursorShape(
|
||||
uint8_t *bitmap, uint8_t *mask, int sizex, int sizey, int hotX, int hotY, bool canInvertColor)
|
||||
GHOST_TSuccess GHOST_Window::setCustomCursorShape(const uint8_t *bitmap,
|
||||
const uint8_t *mask,
|
||||
const int size[2],
|
||||
const int hot_spot[2],
|
||||
bool canInvertColor)
|
||||
{
|
||||
if (setWindowCustomCursorShape(bitmap, mask, sizex, sizey, hotX, hotY, canInvertColor)) {
|
||||
if (setWindowCustomCursorShape(bitmap, mask, size, hot_spot, canInvertColor)) {
|
||||
m_cursorShape = GHOST_kStandardCursorCustom;
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
|
||||
@@ -113,12 +113,10 @@ class GHOST_Window : public GHOST_IWindow {
|
||||
GHOST_TSuccess setCursorShape(GHOST_TStandardCursor cursorShape) override;
|
||||
|
||||
/** \copydoc #GHOST_IWindow::setCustomCursorShape */
|
||||
GHOST_TSuccess setCustomCursorShape(uint8_t *bitmap,
|
||||
uint8_t *mask,
|
||||
int sizex,
|
||||
int sizey,
|
||||
int hotX,
|
||||
int hotY,
|
||||
GHOST_TSuccess setCustomCursorShape(const uint8_t *bitmap,
|
||||
const uint8_t *mask,
|
||||
const int size[2],
|
||||
const int hot_spot[2],
|
||||
bool canInvertColor) override;
|
||||
|
||||
GHOST_TSuccess getCursorBitmap(GHOST_CursorBitmapRef *bitmap) override;
|
||||
@@ -289,12 +287,10 @@ class GHOST_Window : public GHOST_IWindow {
|
||||
virtual GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape) = 0;
|
||||
|
||||
/** \copydoc #GHOST_IWindow::setWindowCustomCursorShape */
|
||||
virtual GHOST_TSuccess setWindowCustomCursorShape(uint8_t *bitmap,
|
||||
uint8_t *mask,
|
||||
int szx,
|
||||
int szy,
|
||||
int hotX,
|
||||
int hotY,
|
||||
virtual GHOST_TSuccess setWindowCustomCursorShape(const uint8_t *bitmap,
|
||||
const uint8_t *mask,
|
||||
const int size[2],
|
||||
const int hot_size[2],
|
||||
bool canInvertColor) = 0;
|
||||
|
||||
GHOST_TSuccess releaseNativeHandles();
|
||||
|
||||
@@ -283,12 +283,10 @@ class GHOST_WindowCocoa : public GHOST_Window {
|
||||
* Sets the cursor shape on the window using
|
||||
* native window system calls.
|
||||
*/
|
||||
GHOST_TSuccess setWindowCustomCursorShape(uint8_t *bitmap,
|
||||
uint8_t *mask,
|
||||
int sizex,
|
||||
int sizey,
|
||||
int hotX,
|
||||
int hotY,
|
||||
GHOST_TSuccess setWindowCustomCursorShape(const uint8_t *bitmap,
|
||||
const uint8_t *mask,
|
||||
const int size[2],
|
||||
const int hot_spot[2],
|
||||
bool canInvertColor) override;
|
||||
|
||||
/** The window containing the view */
|
||||
|
||||
@@ -1218,8 +1218,11 @@ static uint16_t uns16ReverseBits(uint16_t shrt)
|
||||
return shrt;
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_WindowCocoa::setWindowCustomCursorShape(
|
||||
uint8_t *bitmap, uint8_t *mask, int sizex, int sizey, int hotX, int hotY, bool canInvertColor)
|
||||
GHOST_TSuccess GHOST_WindowCocoa::setWindowCustomCursorShape(const uint8_t *bitmap,
|
||||
const uint8_t *mask,
|
||||
const int size[2],
|
||||
const int hot_spot[2],
|
||||
const bool canInvertColor)
|
||||
{
|
||||
@autoreleasepool {
|
||||
if (m_customCursor) {
|
||||
@@ -1229,14 +1232,14 @@ GHOST_TSuccess GHOST_WindowCocoa::setWindowCustomCursorShape(
|
||||
|
||||
NSBitmapImageRep *cursorImageRep = [[NSBitmapImageRep alloc]
|
||||
initWithBitmapDataPlanes:nil
|
||||
pixelsWide:sizex
|
||||
pixelsHigh:sizey
|
||||
pixelsWide:size[0]
|
||||
pixelsHigh:size[1]
|
||||
bitsPerSample:1
|
||||
samplesPerPixel:2
|
||||
hasAlpha:YES
|
||||
isPlanar:YES
|
||||
colorSpaceName:NSDeviceWhiteColorSpace
|
||||
bytesPerRow:(sizex / 8 + (sizex % 8 > 0 ? 1 : 0))
|
||||
bytesPerRow:(size[0] / 8 + (size[0] % 8 > 0 ? 1 : 0))
|
||||
bitsPerPixel:1];
|
||||
|
||||
uint16_t *cursorBitmap = (uint16_t *)cursorImageRep.bitmapData;
|
||||
@@ -1258,11 +1261,11 @@ GHOST_TSuccess GHOST_WindowCocoa::setWindowCustomCursorShape(
|
||||
}
|
||||
}
|
||||
|
||||
const NSSize imSize = {(CGFloat)sizex, (CGFloat)sizey};
|
||||
const NSSize imSize = {(CGFloat)size[0], (CGFloat)size[1]};
|
||||
NSImage *cursorImage = [[NSImage alloc] initWithSize:imSize];
|
||||
[cursorImage addRepresentation:cursorImageRep];
|
||||
|
||||
const NSPoint hotSpotPoint = {(CGFloat)(hotX), (CGFloat)(hotY)};
|
||||
const NSPoint hotSpotPoint = {(CGFloat)(hot_spot[0]), (CGFloat)(hot_spot[1])};
|
||||
|
||||
/* Foreground and background color parameter is not handled for now (10.6). */
|
||||
m_customCursor = [[NSCursor alloc] initWithImage:cursorImage hotSpot:hotSpotPoint];
|
||||
|
||||
@@ -52,12 +52,10 @@ class GHOST_WindowNULL : public GHOST_Window {
|
||||
{
|
||||
return GHOST_kSuccess;
|
||||
}
|
||||
GHOST_TSuccess setWindowCustomCursorShape(uint8_t * /*bitmap*/,
|
||||
uint8_t * /*mask*/,
|
||||
int /*sizex*/,
|
||||
int /*sizey*/,
|
||||
int /*hotX*/,
|
||||
int /*hotY*/,
|
||||
GHOST_TSuccess setWindowCustomCursorShape(const uint8_t * /*bitmap*/,
|
||||
const uint8_t * /*mask*/,
|
||||
const int /*size*/[2],
|
||||
const int /*hot_spot*/[2],
|
||||
bool /*canInvertColor*/) override
|
||||
{
|
||||
return GHOST_kSuccess;
|
||||
|
||||
@@ -502,7 +502,7 @@ static SDL_Cursor *sdl_std_cursor_array[int(GHOST_kStandardCursorNumCursors)] =
|
||||
/* utility function mostly a copy of SDL_CreateCursor but allows us to change
|
||||
* color and supports blenders flipped bits */
|
||||
static SDL_Cursor *sdl_ghost_CreateCursor(
|
||||
const Uint8 *data, const Uint8 *mask, int w, int h, int hot_x, int hot_y)
|
||||
const uint8_t *data, const uint8_t *mask, int w, int h, int hot_x, int hot_y)
|
||||
{
|
||||
SDL_Surface *surface;
|
||||
SDL_Cursor *cursor;
|
||||
@@ -616,12 +616,10 @@ GHOST_TSuccess GHOST_WindowSDL::hasCursorShape(GHOST_TStandardCursor shape)
|
||||
return (getStandardCursorShape(shape)) ? GHOST_kSuccess : GHOST_kFailure;
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_WindowSDL::setWindowCustomCursorShape(uint8_t *bitmap,
|
||||
uint8_t *mask,
|
||||
int sizex,
|
||||
int sizey,
|
||||
int hotX,
|
||||
int hotY,
|
||||
GHOST_TSuccess GHOST_WindowSDL::setWindowCustomCursorShape(const uint8_t *bitmap,
|
||||
const uint8_t *mask,
|
||||
const int size[2],
|
||||
const int hot_spot[2],
|
||||
bool /*canInvertColor*/)
|
||||
{
|
||||
if (m_sdl_custom_cursor) {
|
||||
@@ -629,7 +627,7 @@ GHOST_TSuccess GHOST_WindowSDL::setWindowCustomCursorShape(uint8_t *bitmap,
|
||||
}
|
||||
|
||||
m_sdl_custom_cursor = sdl_ghost_CreateCursor(
|
||||
(const Uint8 *)bitmap, (const Uint8 *)mask, sizex, sizey, hotX, hotY);
|
||||
bitmap, mask, size[0], size[1], hot_spot[0], hot_spot[1]);
|
||||
|
||||
SDL_SetCursor(m_sdl_custom_cursor);
|
||||
return GHOST_kSuccess;
|
||||
|
||||
@@ -83,12 +83,10 @@ class GHOST_WindowSDL : public GHOST_Window {
|
||||
GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape) override;
|
||||
GHOST_TSuccess hasCursorShape(GHOST_TStandardCursor shape) override;
|
||||
|
||||
GHOST_TSuccess setWindowCustomCursorShape(uint8_t *bitmap,
|
||||
uint8_t *mask,
|
||||
int sizex,
|
||||
int sizey,
|
||||
int hotX,
|
||||
int hotY,
|
||||
GHOST_TSuccess setWindowCustomCursorShape(const uint8_t *bitmap,
|
||||
const uint8_t *mask,
|
||||
const int size[2],
|
||||
const int hot_spot[2],
|
||||
bool canInvertColor) override;
|
||||
|
||||
GHOST_TSuccess setWindowCursorVisibility(bool visible) override;
|
||||
|
||||
@@ -328,13 +328,8 @@ static void gwl_window_cursor_custom_store(GWL_WindowCursorCustomShape &ccs,
|
||||
static GHOST_TSuccess gwl_window_cursor_custom_load(const GWL_WindowCursorCustomShape &ccs,
|
||||
GHOST_SystemWayland *system)
|
||||
{
|
||||
return system->cursor_shape_custom_set(ccs.bitmap,
|
||||
ccs.mask,
|
||||
ccs.size[0],
|
||||
ccs.size[1],
|
||||
ccs.hot_spot[0],
|
||||
ccs.hot_spot[1],
|
||||
ccs.can_invert_color);
|
||||
return system->cursor_shape_custom_set(
|
||||
ccs.bitmap, ccs.mask, ccs.size, ccs.hot_spot, ccs.can_invert_color);
|
||||
}
|
||||
|
||||
static GHOST_TSuccess gwl_window_cursor_shape_refresh(GHOST_TStandardCursor shape,
|
||||
@@ -2275,8 +2270,11 @@ bool GHOST_WindowWayland::getCursorGrabUseSoftwareDisplay()
|
||||
return system_->cursor_grab_use_software_display_get(m_cursorGrab);
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_WindowWayland::setWindowCustomCursorShape(
|
||||
uint8_t *bitmap, uint8_t *mask, int sizex, int sizey, int hotX, int hotY, bool canInvertColor)
|
||||
GHOST_TSuccess GHOST_WindowWayland::setWindowCustomCursorShape(const uint8_t *bitmap,
|
||||
const uint8_t *mask,
|
||||
const int size[2],
|
||||
const int hot_spot[2],
|
||||
const bool canInvertColor)
|
||||
{
|
||||
#ifdef USE_EVENT_BACKGROUND_THREAD
|
||||
std::lock_guard lock_server_guard{*system_->server_mutex};
|
||||
@@ -2284,8 +2282,6 @@ GHOST_TSuccess GHOST_WindowWayland::setWindowCustomCursorShape(
|
||||
|
||||
const bool is_active = this == static_cast<const GHOST_WindowWayland *>(
|
||||
system_->getWindowManager()->getActiveWindow());
|
||||
const int32_t size[2] = {sizex, sizey};
|
||||
const int32_t hot_spot[2] = {hotX, hotY};
|
||||
|
||||
gwl_window_cursor_custom_store(
|
||||
window_->cursor_custom_shape, bitmap, mask, size, hot_spot, canInvertColor);
|
||||
|
||||
@@ -95,12 +95,10 @@ class GHOST_WindowWayland : public GHOST_Window {
|
||||
|
||||
GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape) override;
|
||||
|
||||
GHOST_TSuccess setWindowCustomCursorShape(uint8_t *bitmap,
|
||||
uint8_t *mask,
|
||||
int sizex,
|
||||
int sizey,
|
||||
int hotX,
|
||||
int hotY,
|
||||
GHOST_TSuccess setWindowCustomCursorShape(const uint8_t *bitmap,
|
||||
const uint8_t *mask,
|
||||
const int size[2],
|
||||
const int hot_spot[2],
|
||||
bool canInvertColor) override;
|
||||
bool getCursorGrabUseSoftwareDisplay() override;
|
||||
|
||||
|
||||
@@ -1158,12 +1158,10 @@ static uint16_t uns16ReverseBits(uint16_t shrt)
|
||||
}
|
||||
#endif
|
||||
|
||||
GHOST_TSuccess GHOST_WindowWin32::setWindowCustomCursorShape(uint8_t *bitmap,
|
||||
uint8_t *mask,
|
||||
int sizeX,
|
||||
int sizeY,
|
||||
int hotX,
|
||||
int hotY,
|
||||
GHOST_TSuccess GHOST_WindowWin32::setWindowCustomCursorShape(const uint8_t *bitmap,
|
||||
const uint8_t *mask,
|
||||
const int size[2],
|
||||
const int hot_spot[2],
|
||||
bool /*canInvertColor*/)
|
||||
{
|
||||
if (mask) {
|
||||
@@ -1173,8 +1171,8 @@ GHOST_TSuccess GHOST_WindowWin32::setWindowCustomCursorShape(uint8_t *bitmap,
|
||||
uint32_t fullBitRow, fullMaskRow;
|
||||
int x, y, cols;
|
||||
|
||||
cols = sizeX / 8; /* Number of whole bytes per row (width of bitmap/mask). */
|
||||
if (sizeX % 8) {
|
||||
cols = size[0] / 8; /* Number of whole bytes per row (width of bitmap/mask). */
|
||||
if (size[0] % 8) {
|
||||
cols++;
|
||||
}
|
||||
|
||||
@@ -1186,7 +1184,7 @@ GHOST_TSuccess GHOST_WindowWin32::setWindowCustomCursorShape(uint8_t *bitmap,
|
||||
memset(&andData, 0xFF, sizeof(andData));
|
||||
memset(&xorData, 0, sizeof(xorData));
|
||||
|
||||
for (y = 0; y < sizeY; y++) {
|
||||
for (y = 0; y < size[1]; y++) {
|
||||
fullBitRow = 0;
|
||||
fullMaskRow = 0;
|
||||
for (x = cols - 1; x >= 0; x--) {
|
||||
@@ -1199,7 +1197,8 @@ GHOST_TSuccess GHOST_WindowWin32::setWindowCustomCursorShape(uint8_t *bitmap,
|
||||
andData[y] = ~fullMaskRow;
|
||||
}
|
||||
|
||||
m_customCursor = ::CreateCursor(::GetModuleHandle(0), hotX, hotY, 32, 32, andData, xorData);
|
||||
m_customCursor = ::CreateCursor(
|
||||
::GetModuleHandle(0), hot_spot[0], hot_spot[1], 32, 32, andData, xorData);
|
||||
|
||||
if (!m_customCursor) {
|
||||
return GHOST_kFailure;
|
||||
@@ -1217,8 +1216,8 @@ GHOST_TSuccess GHOST_WindowWin32::setWindowCustomCursorShape(uint8_t *bitmap,
|
||||
BITMAPV5HEADER header;
|
||||
memset(&header, 0, sizeof(BITMAPV5HEADER));
|
||||
header.bV5Size = sizeof(BITMAPV5HEADER);
|
||||
header.bV5Width = (LONG)sizeX;
|
||||
header.bV5Height = (LONG)sizeY;
|
||||
header.bV5Width = (LONG)size[0];
|
||||
header.bV5Height = (LONG)size[1];
|
||||
header.bV5Planes = 1;
|
||||
header.bV5BitCount = 32;
|
||||
header.bV5Compression = BI_BITFIELDS;
|
||||
@@ -1234,8 +1233,8 @@ GHOST_TSuccess GHOST_WindowWin32::setWindowCustomCursorShape(uint8_t *bitmap,
|
||||
ReleaseDC(NULL, hdc);
|
||||
|
||||
uint32_t *ptr = (uint32_t *)bits;
|
||||
char w = sizeX;
|
||||
char h = sizeY;
|
||||
char w = size[0];
|
||||
char h = size[1];
|
||||
for (int y = h - 1; y >= 0; y--) {
|
||||
for (int x = 0; x < w; x++) {
|
||||
int i = (y * w * 4) + (x * 4);
|
||||
@@ -1247,11 +1246,11 @@ GHOST_TSuccess GHOST_WindowWin32::setWindowCustomCursorShape(uint8_t *bitmap,
|
||||
}
|
||||
}
|
||||
|
||||
HBITMAP empty_mask = CreateBitmap(sizeX, sizeY, 1, 1, NULL);
|
||||
HBITMAP empty_mask = CreateBitmap(size[0], size[1], 1, 1, NULL);
|
||||
ICONINFO icon_info;
|
||||
icon_info.fIcon = FALSE;
|
||||
icon_info.xHotspot = (DWORD)hotX;
|
||||
icon_info.yHotspot = (DWORD)hotY;
|
||||
icon_info.xHotspot = (DWORD)hot_spot[0];
|
||||
icon_info.yHotspot = (DWORD)hot_spot[1];
|
||||
icon_info.hbmMask = empty_mask;
|
||||
icon_info.hbmColor = bmp;
|
||||
|
||||
|
||||
@@ -358,12 +358,10 @@ class GHOST_WindowWin32 : public GHOST_Window {
|
||||
* Sets the cursor shape on the window using
|
||||
* native window system calls.
|
||||
*/
|
||||
GHOST_TSuccess setWindowCustomCursorShape(uint8_t *bitmap,
|
||||
uint8_t *mask,
|
||||
int sizex,
|
||||
int sizey,
|
||||
int hotX,
|
||||
int hotY,
|
||||
GHOST_TSuccess setWindowCustomCursorShape(const uint8_t *bitmap,
|
||||
const uint8_t *mask,
|
||||
const int size[2],
|
||||
const int hot_spot[2],
|
||||
bool canInvertColor);
|
||||
|
||||
/* Registration of the AppModel Properties that govern the taskbar button and jump lists. */
|
||||
|
||||
@@ -1454,12 +1454,10 @@ GHOST_TSuccess GHOST_WindowX11::hasCursorShape(GHOST_TStandardCursor shape)
|
||||
return getStandardCursor(shape, xcursor);
|
||||
}
|
||||
|
||||
GHOST_TSuccess GHOST_WindowX11::setWindowCustomCursorShape(uint8_t *bitmap,
|
||||
uint8_t *mask,
|
||||
int sizex,
|
||||
int sizey,
|
||||
int hotX,
|
||||
int hotY,
|
||||
GHOST_TSuccess GHOST_WindowX11::setWindowCustomCursorShape(const uint8_t *bitmap,
|
||||
const uint8_t *mask,
|
||||
const int size[2],
|
||||
const int hot_spot[2],
|
||||
bool /*canInvertColor*/)
|
||||
{
|
||||
Colormap colormap = DefaultColormap(m_display, m_visualInfo->screen);
|
||||
@@ -1477,10 +1475,11 @@ GHOST_TSuccess GHOST_WindowX11::setWindowCustomCursorShape(uint8_t *bitmap,
|
||||
XFreeCursor(m_display, m_custom_cursor);
|
||||
}
|
||||
|
||||
bitmap_pix = XCreateBitmapFromData(m_display, m_window, (char *)bitmap, sizex, sizey);
|
||||
mask_pix = XCreateBitmapFromData(m_display, m_window, (char *)mask, sizex, sizey);
|
||||
bitmap_pix = XCreateBitmapFromData(m_display, m_window, (char *)bitmap, size[0], size[1]);
|
||||
mask_pix = XCreateBitmapFromData(m_display, m_window, (char *)mask, size[0], size[1]);
|
||||
|
||||
m_custom_cursor = XCreatePixmapCursor(m_display, bitmap_pix, mask_pix, &fg, &bg, hotX, hotY);
|
||||
m_custom_cursor = XCreatePixmapCursor(
|
||||
m_display, bitmap_pix, mask_pix, &fg, &bg, hot_spot[0], hot_spot[1]);
|
||||
XDefineCursor(m_display, m_window, m_custom_cursor);
|
||||
XFlush(m_display);
|
||||
|
||||
|
||||
@@ -188,12 +188,10 @@ class GHOST_WindowX11 : public GHOST_Window {
|
||||
* Sets the cursor shape on the window using
|
||||
* native window system calls (Arbitrary size/color).
|
||||
*/
|
||||
GHOST_TSuccess setWindowCustomCursorShape(uint8_t *bitmap,
|
||||
uint8_t *mask,
|
||||
int sizex,
|
||||
int sizey,
|
||||
int hotX,
|
||||
int hotY,
|
||||
GHOST_TSuccess setWindowCustomCursorShape(const uint8_t *bitmap,
|
||||
const uint8_t *mask,
|
||||
const int size[2],
|
||||
const int hot_spot[2],
|
||||
bool canInvertColor) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -730,7 +730,10 @@ static void extrawindow_spin_cursor(ExtraWindow *ew, uint64_t time)
|
||||
mask[y][x / 8] |= (1 << (x % 8));
|
||||
}
|
||||
|
||||
GHOST_SetCustomCursorShape(ew->win, &bitmap[0][0], &mask[0][0], 16, 16, 0, 0, true);
|
||||
const int size[2] = {16, 16};
|
||||
const int hot_spot[2] = {0, 0};
|
||||
|
||||
GHOST_SetCustomCursorShape(ew->win, &bitmap[0][0], &mask[0][0], size, hot_spot, true);
|
||||
}
|
||||
|
||||
static void extrawindow_handle(void *priv, GHOST_EventHandle evt)
|
||||
|
||||
@@ -151,8 +151,7 @@ static float cursor_size()
|
||||
|
||||
static blender::Array<uint8_t> cursor_bitmap_from_svg(const char *svg,
|
||||
float size,
|
||||
size_t &r_width,
|
||||
size_t &r_height)
|
||||
int r_bitmap_size[2])
|
||||
{
|
||||
/* Nano alters the source string. */
|
||||
std::string svg_source = svg;
|
||||
@@ -182,22 +181,23 @@ static blender::Array<uint8_t> cursor_bitmap_from_svg(const char *svg,
|
||||
nsvgDeleteRasterizer(rast);
|
||||
nsvgDelete(image);
|
||||
|
||||
r_width = dest_w;
|
||||
r_height = dest_h;
|
||||
r_bitmap_size[0] = dest_w;
|
||||
r_bitmap_size[1] = dest_h;
|
||||
|
||||
return render_bmp;
|
||||
}
|
||||
|
||||
/* Convert 32-bit RGBA bitmap (1-32 x 1-32) to 32x32 1bpp XBitMap bitmap and mask. */
|
||||
/**
|
||||
* Convert 32-bit RGBA bitmap (1-32 x 1-32) to 32x32 1bpp XBitMap bitmap and mask.
|
||||
*/
|
||||
static void cursor_rgba_to_xbm_32(const blender::Array<uint8_t> rgba,
|
||||
const size_t width,
|
||||
const size_t height,
|
||||
const int bitmap_size[2],
|
||||
uint8_t *bitmap,
|
||||
uint8_t *mask)
|
||||
{
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
int i = (y * width * 4) + (x * 4);
|
||||
for (int y = 0; y < bitmap_size[1]; y++) {
|
||||
for (int x = 0; x < bitmap_size[0]; x++) {
|
||||
int i = (y * bitmap_size[0] * 4) + (x * 4);
|
||||
int j = (y * 4) + (x >> 3);
|
||||
int k = (x % 8);
|
||||
if (rgba[i + 3] > 128) {
|
||||
@@ -221,35 +221,34 @@ static bool window_set_custom_cursor(wmWindow *win, BCursor *cursor)
|
||||
const int max_size = use_rgba ? 128 : 32;
|
||||
const float size = std::min(cursor_size(), float(max_size));
|
||||
|
||||
size_t width;
|
||||
size_t height;
|
||||
int bitmap_size[2];
|
||||
blender::Array<uint8_t> render_bmp = cursor_bitmap_from_svg(
|
||||
cursor->svg_source, size, width, height);
|
||||
cursor->svg_source, size, bitmap_size);
|
||||
|
||||
int hotspot_x = int(cursor->hotspot_x * (width - 1));
|
||||
int hotspot_y = int(cursor->hotspot_y * (height - 1));
|
||||
const int hot_spot[2] = {
|
||||
int(cursor->hotspot_x * (bitmap_size[0] - 1)),
|
||||
int(cursor->hotspot_y * (bitmap_size[1] - 1)),
|
||||
};
|
||||
|
||||
if (use_rgba) {
|
||||
return GHOST_SetCustomCursorShape(static_cast<GHOST_WindowHandle>(win->ghostwin),
|
||||
render_bmp.data(),
|
||||
nullptr,
|
||||
width,
|
||||
height,
|
||||
hotspot_x,
|
||||
hotspot_y,
|
||||
bitmap_size,
|
||||
hot_spot,
|
||||
cursor->can_invert) == GHOST_kSuccess;
|
||||
}
|
||||
else {
|
||||
int bitmap_size_fixed[2] = {32, 32};
|
||||
|
||||
uint8_t bitmap[4 * 32] = {0};
|
||||
uint8_t mask[4 * 32] = {0};
|
||||
cursor_rgba_to_xbm_32(render_bmp, width, height, bitmap, mask);
|
||||
cursor_rgba_to_xbm_32(render_bmp, bitmap_size, bitmap, mask);
|
||||
return GHOST_SetCustomCursorShape(static_cast<GHOST_WindowHandle>(win->ghostwin),
|
||||
bitmap,
|
||||
mask,
|
||||
32,
|
||||
32,
|
||||
hotspot_x,
|
||||
hotspot_y,
|
||||
bitmap_size_fixed,
|
||||
hot_spot,
|
||||
cursor->can_invert) == GHOST_kSuccess;
|
||||
}
|
||||
}
|
||||
@@ -505,8 +504,8 @@ static bool wm_cursor_time_large(wmWindow *win, int nr)
|
||||
0x30, 0x0c, 0x30, 0x1c, 0x30, 0xf8, 0x3f, 0xf0, 0x3f, 0x00, 0x38,
|
||||
0x00, 0x1c, 0x00, 0x0e, 0xfc, 0x07, 0xfc, 0x03, 0x00, 0x00},
|
||||
};
|
||||
uchar mask[32][4] = {{0}};
|
||||
uchar bitmap[32][4] = {{0}};
|
||||
uint8_t mask[32][4] = {{0}};
|
||||
uint8_t bitmap[32][4] = {{0}};
|
||||
|
||||
/* Print number bottom right justified. */
|
||||
for (int idx = 3; nr && idx >= 0; idx--) {
|
||||
@@ -526,13 +525,13 @@ static bool wm_cursor_time_large(wmWindow *win, int nr)
|
||||
nr /= 10;
|
||||
}
|
||||
|
||||
const int size[2] = {32, 32};
|
||||
const int hot_spot[2] = {15, 15};
|
||||
return GHOST_SetCustomCursorShape(static_cast<GHOST_WindowHandle>(win->ghostwin),
|
||||
(uint8_t *)bitmap,
|
||||
(uint8_t *)mask,
|
||||
32,
|
||||
32,
|
||||
15,
|
||||
15,
|
||||
bitmap[0],
|
||||
mask[0],
|
||||
size,
|
||||
hot_spot,
|
||||
false) == GHOST_kSuccess;
|
||||
}
|
||||
|
||||
@@ -551,8 +550,8 @@ static void wm_cursor_time_small(wmWindow *win, int nr)
|
||||
{0, 60, 66, 66, 60, 66, 66, 60},
|
||||
{0, 56, 68, 68, 120, 64, 68, 56},
|
||||
};
|
||||
uchar mask[16][2] = {{0}};
|
||||
uchar bitmap[16][2] = {{0}};
|
||||
uint8_t mask[16][2] = {{0}};
|
||||
uint8_t bitmap[16][2] = {{0}};
|
||||
|
||||
/* Print number bottom right justified. */
|
||||
for (int idx = 3; nr && idx >= 0; idx--) {
|
||||
@@ -569,13 +568,13 @@ static void wm_cursor_time_small(wmWindow *win, int nr)
|
||||
nr /= 10;
|
||||
}
|
||||
|
||||
const int size[2] = {16, 16};
|
||||
const int hot_spot[2] = {7, 7};
|
||||
GHOST_SetCustomCursorShape(static_cast<GHOST_WindowHandle>(win->ghostwin),
|
||||
(uint8_t *)bitmap,
|
||||
(uint8_t *)mask,
|
||||
16,
|
||||
16,
|
||||
7,
|
||||
7,
|
||||
size,
|
||||
hot_spot,
|
||||
false);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user