-------------------------------------------------------------------------------------- Description: Creates a new cursor. Arguments: bitmap - Bitmap containing cursor image. Needs to have B8G8R8A8 format and usually should be 32 by 32 pixels. hotspotX - X coordinate of hotspot hotspotY - Y coordinate of hotspot Return Value: true If the cursor was successfully created false Otherwise -------------
| 264 | // false Otherwise |
| 265 | // -------------------------------------------------------------------------------------- |
| 266 | bool Tr2MouseCursor::Create( Tr2HostBitmap* bitmap, int hotspotX, int hotspotY, const std::vector<Tr2HostBitmap*>& representations ) |
| 267 | { |
| 268 | if( bitmap == nullptr ) |
| 269 | { |
| 270 | CCP_LOGERR( "Tr2MouseCursor.Create: nullptr is passed for bitmap" ); |
| 271 | return false; |
| 272 | } |
| 273 | |
| 274 | #ifdef _WIN32 |
| 275 | if( m_cursor ) |
| 276 | { |
| 277 | DeleteObject( m_cursor ); |
| 278 | } |
| 279 | m_cursor = nullptr; |
| 280 | #endif |
| 281 | // Check the format: we really need B8G8R8A8 for cursor, |
| 282 | // but we also support BC1 and BC3 for compatibility with |
| 283 | // existing cursor images |
| 284 | switch( bitmap->GetFormat() ) |
| 285 | { |
| 286 | case Tr2RenderContextEnum::PIXEL_FORMAT_BC1_TYPELESS: |
| 287 | case Tr2RenderContextEnum::PIXEL_FORMAT_BC1_UNORM: |
| 288 | case Tr2RenderContextEnum::PIXEL_FORMAT_BC1_UNORM_SRGB: |
| 289 | |
| 290 | case Tr2RenderContextEnum::PIXEL_FORMAT_BC2_TYPELESS: |
| 291 | case Tr2RenderContextEnum::PIXEL_FORMAT_BC2_UNORM: |
| 292 | case Tr2RenderContextEnum::PIXEL_FORMAT_BC2_UNORM_SRGB: |
| 293 | |
| 294 | case Tr2RenderContextEnum::PIXEL_FORMAT_B8G8R8A8_TYPELESS: |
| 295 | case Tr2RenderContextEnum::PIXEL_FORMAT_B8G8R8A8_UNORM: |
| 296 | case Tr2RenderContextEnum::PIXEL_FORMAT_B8G8R8A8_UNORM_SRGB: |
| 297 | break; |
| 298 | default: |
| 299 | CCP_LOGERR( "Tr2MouseCursor.Create: unsupported bitmap format (only B8G8R8A8, BC1 and BC2 are supported)" ); |
| 300 | return false; |
| 301 | } |
| 302 | |
| 303 | #if defined( _WIN32 ) |
| 304 | BITMAPV5HEADER bi; |
| 305 | ZeroMemory( &bi, sizeof( BITMAPV5HEADER ) ); |
| 306 | bi.bV5Size = sizeof( BITMAPV5HEADER ); |
| 307 | bi.bV5Width = bitmap->GetWidth(); |
| 308 | bi.bV5Height = bitmap->GetHeight(); |
| 309 | bi.bV5Planes = 1; |
| 310 | bi.bV5BitCount = 32; |
| 311 | bi.bV5Compression = BI_BITFIELDS; |
| 312 | bi.bV5RedMask = 0x00FF0000; |
| 313 | bi.bV5GreenMask = 0x0000FF00; |
| 314 | bi.bV5BlueMask = 0x000000FF; |
| 315 | bi.bV5AlphaMask = 0xFF000000; |
| 316 | bi.bV5CSType = LCS_WINDOWS_COLOR_SPACE; |
| 317 | |
| 318 | HDC hdc; |
| 319 | hdc = GetDC( nullptr ); |
| 320 | |
| 321 | void* bits; |
| 322 | HBITMAP bmp = CreateDIBSection( hdc, (BITMAPINFO*)&bi, DIB_RGB_COLORS, &bits, NULL, 0 ); |
| 323 |
no test coverage detected