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

Method OnInitialPosition

src/error_gui.cpp:138–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136 }
137
138 Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
139 {
140 /* Position (0, 0) given, center the window. */
141 if (this->position.x == 0 && this->position.y == 0) {
142 Point pt = {(_screen.width - sm_width) >> 1, (_screen.height - sm_height) >> 1};
143 return pt;
144 }
145
146 constexpr int distance_to_cursor = 200;
147
148 /* Position the error window just above the cursor. This makes the
149 * error window clearly visible, without being in the way of what
150 * the user is doing. */
151 Point pt;
152 pt.x = _cursor.pos.x - sm_width / 2;
153 pt.y = _cursor.pos.y - (distance_to_cursor + sm_height);
154
155 if (pt.y < GetMainViewTop()) {
156 /* Window didn't fit above cursor, so place it below. */
157 pt.y = _cursor.pos.y + distance_to_cursor;
158 }
159
160 return pt;
161 }
162
163 /**
164 * Some data on this window has become invalid.

Callers

nothing calls this directly

Calls 1

GetMainViewTopFunction · 0.85

Tested by

no test coverage detected