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

Function NetworkUndrawChatMessage

src/network/network_chat_gui.cpp:120–164  ·  view source on GitHub ↗

Hide the chatbox */

Source from the content-addressed store, hash-verified

118
119/** Hide the chatbox */
120void 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. */
167static const IntervalTimer<TimerWindow> network_message_expired_interval(std::chrono::seconds(1), [](auto) {

Callers 4

GfxScrollFunction · 0.85
RedrawScreenRectFunction · 0.85
ReInitAllWindowsFunction · 0.85
NetworkDrawChatMessageFunction · 0.85

Calls 6

UndrawMouseCursorFunction · 0.85
nowClass · 0.85
GetBufferMethod · 0.80
CopyFromBufferMethod · 0.45
MoveToMethod · 0.45
MakeDirtyMethod · 0.45

Tested by

no test coverage detected