MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / DrawMouseCursor

Function DrawMouseCursor

src/gfx.cpp:1352–1414  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1350}
1351
1352void DrawMouseCursor()
1353{
1354 /* Don't draw mouse cursor if it is handled by the video driver. */
1355 if (VideoDriver::GetInstance()->UseSystemCursor()) return;
1356
1357 /* Don't draw the mouse cursor if the screen is not ready */
1358 if (_screen.dst_ptr == nullptr) return;
1359
1360 Blitter *blitter = BlitterFactory::GetCurrentBlitter();
1361
1362 /* Redraw mouse cursor but only when it's inside the window */
1363 if (!_cursor.in_window) return;
1364
1365 /* Don't draw the mouse cursor if it's already drawn */
1366 if (_cursor.visible) {
1367 if (!_cursor.dirty) return;
1368 UndrawMouseCursor();
1369 }
1370
1371 /* Determine visible area */
1372 int left = _cursor.pos.x + _cursor.total_offs.x;
1373 int width = _cursor.total_size.x;
1374 if (left < 0) {
1375 width += left;
1376 left = 0;
1377 }
1378 if (left + width > _screen.width) {
1379 width = _screen.width - left;
1380 }
1381 if (width <= 0) return;
1382
1383 int top = _cursor.pos.y + _cursor.total_offs.y;
1384 int height = _cursor.total_size.y;
1385 if (top < 0) {
1386 height += top;
1387 top = 0;
1388 }
1389 if (top + height > _screen.height) {
1390 height = _screen.height - top;
1391 }
1392 if (height <= 0) return;
1393
1394 _cursor.draw_pos.x = left;
1395 _cursor.draw_pos.y = top;
1396 _cursor.draw_size.x = width;
1397 _cursor.draw_size.y = height;
1398
1399 uint8_t *buffer = _cursor_backup.Allocate(blitter->BufferSize(_cursor.draw_size.x, _cursor.draw_size.y));
1400
1401 /* Make backup of stuff below cursor */
1402 blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), buffer, _cursor.draw_size.x, _cursor.draw_size.y);
1403
1404 /* Draw cursor on screen */
1405 _cur_dpi = &_screen;
1406 for (const auto &cs : _cursor.sprites) {
1407 DrawSprite(cs.image.sprite, cs.image.pal, _cursor.pos.x + cs.pos.x, _cursor.pos.y + cs.pos.y);
1408 }
1409

Callers 1

UpdateWindowsFunction · 0.85

Calls 8

UndrawMouseCursorFunction · 0.85
DrawSpriteFunction · 0.85
UseSystemCursorMethod · 0.45
AllocateMethod · 0.45
BufferSizeMethod · 0.45
CopyToBufferMethod · 0.45
MoveToMethod · 0.45
MakeDirtyMethod · 0.45

Tested by

no test coverage detected