* @brief Save the content behind the cursor to a temporary buffer, then draw the cursor. */
| 261 | * @brief Save the content behind the cursor to a temporary buffer, then draw the cursor. |
| 262 | */ |
| 263 | void DrawCursor(const Surface &out) |
| 264 | { |
| 265 | DrawnCursor &cursor = GetDrawnCursor(); |
| 266 | if (IsHardwareCursor()) { |
| 267 | SetHardwareCursorVisible(ShouldShowCursor()); |
| 268 | cursor.rect.size = { 0, 0 }; |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | if (pcurs <= CURSOR_NONE || !ShouldShowCursor()) { |
| 273 | cursor.rect.size = { 0, 0 }; |
| 274 | return; |
| 275 | } |
| 276 | |
| 277 | Size cursSize = GetInvItemSize(pcurs); |
| 278 | if (cursSize.width == 0 || cursSize.height == 0) { |
| 279 | cursor.rect.size = { 0, 0 }; |
| 280 | return; |
| 281 | } |
| 282 | |
| 283 | constexpr auto Clip = [](int &pos, int &length, int posEnd) { |
| 284 | if (pos + length <= 0 || pos >= posEnd) { |
| 285 | pos = 0; |
| 286 | length = 0; |
| 287 | } else if (pos < 0) { |
| 288 | length += pos; |
| 289 | pos = 0; |
| 290 | } else if (pos + length > posEnd) { |
| 291 | length = posEnd - pos; |
| 292 | } |
| 293 | }; |
| 294 | |
| 295 | // Copy the buffer before the item cursor and its 1px outline are drawn to a temporary buffer. |
| 296 | const int outlineWidth = !MyPlayer->HoldItem.isEmpty() ? 1 : 0; |
| 297 | Displacement offset = !MyPlayer->HoldItem.isEmpty() ? Displacement { cursSize / 2 } : Displacement { 0 }; |
| 298 | Point cursPosition = MousePosition - offset; |
| 299 | |
| 300 | Rectangle &rect = cursor.rect; |
| 301 | rect.position.x = cursPosition.x - outlineWidth; |
| 302 | rect.size.width = cursSize.width + 2 * outlineWidth; |
| 303 | Clip(rect.position.x, rect.size.width, out.w()); |
| 304 | |
| 305 | rect.position.y = cursPosition.y - outlineWidth; |
| 306 | rect.size.height = cursSize.height + 2 * outlineWidth; |
| 307 | Clip(rect.position.y, rect.size.height, out.h()); |
| 308 | |
| 309 | if (rect.size.width == 0 || rect.size.height == 0) |
| 310 | return; |
| 311 | |
| 312 | BlitCursor(cursor.behindBuffer, rect.size.width, &out[rect.position], out.pitch(), rect.size.width, rect.size.height); |
| 313 | DrawSoftwareCursor(out, cursPosition + Displacement { 0, cursSize.height - 1 }, pcurs); |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * @brief Render a missile sprite |
no test coverage detected