|
@@ -1977,28 +1977,53 @@ void OS_Windows::set_cursor_shape(CursorShape p_shape) {
|
|
cursor_shape = p_shape;
|
|
cursor_shape = p_shape;
|
|
}
|
|
}
|
|
|
|
|
|
-void OS_Windows::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot){
|
|
|
|
|
|
+void OS_Windows::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot) {
|
|
if (p_cursor.is_valid()) {
|
|
if (p_cursor.is_valid()) {
|
|
Ref<ImageTexture> texture = p_cursor;
|
|
Ref<ImageTexture> texture = p_cursor;
|
|
|
|
+ Ref<AtlasTexture> atlas_texture = p_cursor;
|
|
|
|
+ Size2 texture_size;
|
|
|
|
+ Rect2 atlas_rect;
|
|
|
|
+
|
|
|
|
+ if (!texture.is_valid() && atlas_texture.is_valid()) {
|
|
|
|
+ texture = atlas_texture->get_atlas();
|
|
|
|
+
|
|
|
|
+ atlas_rect.size.width = texture->get_width();
|
|
|
|
+ atlas_rect.size.height = texture->get_height();
|
|
|
|
+ atlas_rect.pos.x = atlas_texture->get_region().pos.x;
|
|
|
|
+ atlas_rect.pos.y = atlas_texture->get_region().pos.y;
|
|
|
|
+
|
|
|
|
+ texture_size.width = atlas_texture->get_region().size.x;
|
|
|
|
+ texture_size.height = atlas_texture->get_region().size.y;
|
|
|
|
+ } else {
|
|
|
|
+ texture_size.width = texture->get_width();
|
|
|
|
+ texture_size.height = texture->get_height();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ERR_FAIL_COND(!texture.is_valid());
|
|
|
|
+ ERR_FAIL_COND(texture_size.width > 256 || texture_size.height > 256);
|
|
|
|
+
|
|
Image image = texture->get_data();
|
|
Image image = texture->get_data();
|
|
|
|
|
|
- UINT image_size = texture->get_width() * texture->get_height();
|
|
|
|
|
|
+ UINT image_size = texture_size.width * texture_size.height;
|
|
UINT size = sizeof(UINT) * image_size;
|
|
UINT size = sizeof(UINT) * image_size;
|
|
|
|
|
|
- ERR_FAIL_COND(texture->get_width() > 256 || texture->get_height() > 256);
|
|
|
|
-
|
|
|
|
// Create the BITMAP with alpha channel
|
|
// Create the BITMAP with alpha channel
|
|
COLORREF *buffer = (COLORREF *)malloc(sizeof(COLORREF) * image_size);
|
|
COLORREF *buffer = (COLORREF *)malloc(sizeof(COLORREF) * image_size);
|
|
|
|
|
|
for (UINT index = 0; index < image_size; index++) {
|
|
for (UINT index = 0; index < image_size; index++) {
|
|
- int row_index = floor(index / texture->get_width());
|
|
|
|
- int column_index = index % texture->get_width();
|
|
|
|
|
|
+ int row_index = floor(index / texture_size.width) + atlas_rect.pos.y;
|
|
|
|
+ int column_index = (index % int(texture_size.width)) + atlas_rect.pos.x;
|
|
|
|
+
|
|
|
|
+ if (atlas_texture.is_valid()) {
|
|
|
|
+ column_index = MIN(column_index, atlas_rect.size.width - 1);
|
|
|
|
+ row_index = MIN(row_index, atlas_rect.size.height - 1);
|
|
|
|
+ }
|
|
|
|
|
|
*(buffer + index) = image.get_pixel(column_index, row_index).to_ARGB32();
|
|
*(buffer + index) = image.get_pixel(column_index, row_index).to_ARGB32();
|
|
}
|
|
}
|
|
|
|
|
|
// Using 4 channels, so 4 * 8 bits
|
|
// Using 4 channels, so 4 * 8 bits
|
|
- HBITMAP bitmap = CreateBitmap(texture->get_width(), texture->get_height(), 1, 4 * 8, buffer);
|
|
|
|
|
|
+ HBITMAP bitmap = CreateBitmap(texture_size.width, texture_size.height, 1, 4 * 8, buffer);
|
|
COLORREF clrTransparent = -1;
|
|
COLORREF clrTransparent = -1;
|
|
|
|
|
|
// Create the AND and XOR masks for the bitmap
|
|
// Create the AND and XOR masks for the bitmap
|
|
@@ -2012,7 +2037,7 @@ void OS_Windows::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shap
|
|
}
|
|
}
|
|
|
|
|
|
// Finally, create the icon
|
|
// Finally, create the icon
|
|
- ICONINFO iconinfo = {0};
|
|
|
|
|
|
+ ICONINFO iconinfo = { 0 };
|
|
iconinfo.fIcon = FALSE;
|
|
iconinfo.fIcon = FALSE;
|
|
iconinfo.xHotspot = p_hotspot.x;
|
|
iconinfo.xHotspot = p_hotspot.x;
|
|
iconinfo.yHotspot = p_hotspot.y;
|
|
iconinfo.yHotspot = p_hotspot.y;
|
|
@@ -2030,7 +2055,7 @@ void OS_Windows::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shap
|
|
}
|
|
}
|
|
|
|
|
|
if (hXorMask != NULL) {
|
|
if (hXorMask != NULL) {
|
|
- DeleteObject(hXorMask);
|
|
|
|
|
|
+ DeleteObject(hXorMask);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -2072,7 +2097,7 @@ void OS_Windows::GetMaskBitmaps(HBITMAP hSourceBitmap, COLORREF clrTransparent,
|
|
SetBkColor(hXorMaskDC, RGB(0, 0, 0));
|
|
SetBkColor(hXorMaskDC, RGB(0, 0, 0));
|
|
SetTextColor(hXorMaskDC, RGB(255, 255, 255));
|
|
SetTextColor(hXorMaskDC, RGB(255, 255, 255));
|
|
BitBlt(hXorMaskDC, 0, 0, bm.bmWidth, bm.bmHeight, hAndMaskDC, 0, 0, SRCCOPY);
|
|
BitBlt(hXorMaskDC, 0, 0, bm.bmWidth, bm.bmHeight, hAndMaskDC, 0, 0, SRCCOPY);
|
|
- BitBlt(hXorMaskDC, 0, 0, bm.bmWidth, bm.bmHeight, hMainDC, 0,0, SRCAND);
|
|
|
|
|
|
+ BitBlt(hXorMaskDC, 0, 0, bm.bmWidth, bm.bmHeight, hMainDC, 0, 0, SRCAND);
|
|
|
|
|
|
// Deselect bitmaps from the helper DC
|
|
// Deselect bitmaps from the helper DC
|
|
SelectObject(hMainDC, hOldMainBitmap);
|
|
SelectObject(hMainDC, hOldMainBitmap);
|