MCPcopy Create free account
hub / github.com/Duet3D/RepRapFirmware / DisplayMessageBox

Method DisplayMessageBox

src/Display/Menu.cpp:138–192  ·  view source on GitHub ↗

Display a M291 message box

Source from the content-addressed store, hash-verified

136
137// Display a M291 message box
138void Menu::DisplayMessageBox(const MessageBox& mbox) noexcept
139{
140 ResetCache();
141 displayingMessageBox = true;
142 timeoutValue = 0;
143
144 const PixelNumber topBottomMargin = 4;
145 const PixelNumber sideMargin = 4;
146
147 // Draw and a box and clear the interior
148 const PixelNumber nr = lcd.GetNumRows(), nc = lcd.GetNumCols();
149 lcd.SetRightMargin(nc);
150 lcd.Line(topBottomMargin, sideMargin, topBottomMargin, nc - sideMargin - 1, true);
151 lcd.Line(topBottomMargin, nc - sideMargin - 1, nr - topBottomMargin - 1, nc - sideMargin - 1, true);
152 lcd.Line(nr - topBottomMargin - 1, sideMargin, nr - topBottomMargin - 1, nc - sideMargin - 1, true);
153 lcd.Line(topBottomMargin, sideMargin, nr - topBottomMargin - 1, sideMargin, true);
154 lcd.Clear(topBottomMargin + 1, sideMargin + 1, nr - topBottomMargin - 1, nc - sideMargin - 1);
155
156 // We could draw the static text directly, but it is easier to use the existing classes
157 const uint8_t fontToUse = 0;
158 const PixelNumber insideMargin = 2;
159 const PixelNumber rowHeight = lcd.GetFontHeight(fontToUse) + 1;
160 const PixelNumber top = topBottomMargin + 1 + insideMargin;
161 const PixelNumber left = sideMargin + 1 + insideMargin;
162 const PixelNumber right = nc - left;
163 const PixelNumber availableWidth = right - left;
164 AddItem(new TextMenuItem(top, left, availableWidth, MenuItem::CentreAlign, fontToUse, mbox.GetTitle()), false);
165 AddItem(new TextMenuItem(top + rowHeight, left, availableWidth, MenuItem::CentreAlign, fontToUse, mbox.GetMessage()), false); // only 1 row for now
166
167 // Add whichever XYZ jog buttons we have been asked to display - assume only XYZ for now
168 const PixelNumber axisButtonWidth = availableWidth/4;
169 const PixelNumber axisButtonStep = (availableWidth - 3 *axisButtonWidth)/2 + axisButtonWidth;
170 if (mbox.GetControls().IsBitSet(X_AXIS))
171 {
172 AddItem(new ValueMenuItem(top + 2 * rowHeight, left, axisButtonWidth, MenuItem::CentreAlign, fontToUse, true, nullptr, 510, 1), true);
173 }
174 if (mbox.GetControls().IsBitSet(Y_AXIS))
175 {
176 AddItem(new ValueMenuItem(top + 2 * rowHeight, left + axisButtonStep, axisButtonWidth, MenuItem::CentreAlign, fontToUse, true, nullptr, 511, 1), true);
177 }
178 if (mbox.GetControls().IsBitSet(Z_AXIS))
179 {
180 AddItem(new ValueMenuItem(top + 2 * rowHeight, left + 2 * axisButtonStep, axisButtonWidth, MenuItem::CentreAlign, fontToUse, true, nullptr, 512, 2), true);
181 }
182
183 const PixelNumber okCancelButtonWidth = 30;
184 if (mbox.GetMode() & 2)
185 {
186 AddItem(new ButtonMenuItem(top + 3 * rowHeight, left, okCancelButtonWidth, fontToUse, "OK", "M292 P0", nullptr), true);
187 }
188 if (mbox.GetMode() & 1)
189 {
190 AddItem(new ButtonMenuItem(top + 3 * rowHeight, right - okCancelButtonWidth, okCancelButtonWidth, fontToUse, "Cancel", "M292 P1", nullptr), true);
191 }
192}
193
194// Clear the message box and display the menu underneath it
195void Menu::ClearMessageBox() noexcept

Callers 1

SpinMethod · 0.80

Calls 6

SetRightMarginMethod · 0.80
LineMethod · 0.80
GetMessageMethod · 0.80
ClearMethod · 0.45
GetFontHeightMethod · 0.45
GetModeMethod · 0.45

Tested by

no test coverage detected