Hide the chatbox */
| 118 | |
| 119 | /** Hide the chatbox */ |
| 120 | void NetworkUndrawChatMessage() |
| 121 | { |
| 122 | /* Sometimes we also need to hide the cursor |
| 123 | * This is because both textmessage and the cursor take a shot of the |
| 124 | * screen before drawing. |
| 125 | * Now the textmessage takes its shot and paints its data before the cursor |
| 126 | * does, so in the shot of the cursor is the screen-data of the textmessage |
| 127 | * included when the cursor hangs somewhere over the textmessage. To |
| 128 | * avoid wrong repaints, we undraw the cursor in that case, and everything |
| 129 | * looks nicely ;) |
| 130 | * (and now hope this story above makes sense to you ;)) |
| 131 | */ |
| 132 | if (_cursor.visible && |
| 133 | _cursor.draw_pos.x + _cursor.draw_size.x >= _chatmsg_box.x && |
| 134 | _cursor.draw_pos.x <= _chatmsg_box.x + _chatmsg_box.width && |
| 135 | _cursor.draw_pos.y + _cursor.draw_size.y >= _screen.height - _chatmsg_box.y - _chatmsg_box.height && |
| 136 | _cursor.draw_pos.y <= _screen.height - _chatmsg_box.y) { |
| 137 | UndrawMouseCursor(); |
| 138 | } |
| 139 | |
| 140 | if (_chatmessage_visible) { |
| 141 | Blitter *blitter = BlitterFactory::GetCurrentBlitter(); |
| 142 | int x = _chatmsg_box.x; |
| 143 | int y = _screen.height - _chatmsg_box.y - _chatmsg_box.height; |
| 144 | int width = _chatmsg_box.width; |
| 145 | int height = _chatmsg_box.height; |
| 146 | if (y < 0) { |
| 147 | height = std::max(height + y, std::min(_chatmsg_box.height, _screen.height)); |
| 148 | y = 0; |
| 149 | } |
| 150 | if (x + width >= _screen.width) { |
| 151 | width = _screen.width - x; |
| 152 | } |
| 153 | if (width <= 0 || height <= 0) return; |
| 154 | |
| 155 | _chatmessage_visible = false; |
| 156 | /* Put our 'shot' back to the screen */ |
| 157 | blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, x, y), _chatmessage_backup.GetBuffer(), width, height); |
| 158 | /* And make sure it is updated next time */ |
| 159 | VideoDriver::GetInstance()->MakeDirty(x, y, width, height); |
| 160 | |
| 161 | _chatmessage_dirty_time = std::chrono::steady_clock::now(); |
| 162 | _chatmessage_dirty = true; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | /** Check if a message is expired on a regular interval. */ |
| 167 | static const IntervalTimer<TimerWindow> network_message_expired_interval(std::chrono::seconds(1), [](auto) { |
no test coverage detected