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

Class ErrmsgWindow

src/error_gui.cpp:99–252  ·  view source on GitHub ↗

Window class for displaying an error message window. */

Source from the content-addressed store, hash-verified

97
98/** Window class for displaying an error message window. */
99struct ErrmsgWindow : public Window, ErrorMessageData {
100private:
101 uint height_summary = 0; ///< Height of the #summary_msg string in pixels in the #WID_EM_MESSAGE widget.
102 uint height_detailed = 0; ///< Height of the #detailed_msg string in pixels in the #WID_EM_MESSAGE widget.
103 uint height_extra = 0; ///< Height of the #extra_msg string in pixels in the #WID_EM_MESSAGE widget.
104
105 TimeoutTimer<TimerWindow> display_timeout = {std::chrono::seconds(_settings_client.gui.errmsg_duration), [this]() {
106 this->Close();
107 }};
108
109public:
110 ErrmsgWindow(const ErrorMessageData &data) :
111 Window(data.HasFace() ? _errmsg_face_desc : _errmsg_desc),
112 ErrorMessageData(data)
113 {
114 this->InitNested();
115 }
116
117 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
118 {
119 switch (widget) {
120 case WID_EM_MESSAGE: {
121 this->height_summary = GetStringHeight(this->summary_msg.GetDecodedString(), size.width);
122 this->height_detailed = (this->detailed_msg.empty()) ? 0 : GetStringHeight(this->detailed_msg.GetDecodedString(), size.width);
123 this->height_extra = (this->extra_msg.empty()) ? 0 : GetStringHeight(this->extra_msg.GetDecodedString(), size.width);
124
125 uint panel_height = this->height_summary;
126 if (!this->detailed_msg.empty()) panel_height += this->height_detailed + WidgetDimensions::scaled.vsep_wide;
127 if (!this->extra_msg.empty()) panel_height += this->height_extra + WidgetDimensions::scaled.vsep_wide;
128
129 size.height = std::max(size.height, panel_height);
130 break;
131 }
132 case WID_EM_FACE:
133 size = maxdim(size, GetScaledSpriteSize(SPR_GRADIENT));
134 break;
135 }
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. */

Callers

nothing calls this directly

Calls 1

CloseMethod · 0.95

Tested by

no test coverage detected