| 204 | } |
| 205 | |
| 206 | void DrawLegend(size_t height, wxPaintDC& dc, wxGraphicsContext& gc) |
| 207 | { |
| 208 | using namespace DynamicRangeProcessorPanel; |
| 209 | |
| 210 | constexpr auto legendWidth = 16; |
| 211 | constexpr auto legendHeight = 16; |
| 212 | constexpr auto legendSpacing = 8; |
| 213 | constexpr auto legendX = 5; |
| 214 | const auto legendY = height - 5 - legendHeight; |
| 215 | const auto legendTextX = legendX + legendWidth + 5; |
| 216 | const auto legendTextHeight = dc.GetTextExtent("X").GetHeight(); |
| 217 | const auto legendTextYOffset = (legendHeight - legendTextHeight) / 2; |
| 218 | const auto legendTextY = legendY + legendTextYOffset; |
| 219 | |
| 220 | struct LegendInfo |
| 221 | { |
| 222 | const wxColor color; |
| 223 | const TranslatableString text; |
| 224 | }; |
| 225 | |
| 226 | std::vector<LegendInfo> legends = { |
| 227 | { inputColor, XO("Input") }, |
| 228 | { outputColor, XO("Output") }, |
| 229 | }; |
| 230 | |
| 231 | int legendTextXOffset = 0; |
| 232 | dc.SetTextForeground(*wxBLACK); |
| 233 | dc.SetFont( |
| 234 | { 10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL }); |
| 235 | for (const auto& legend : legends) |
| 236 | { |
| 237 | // First fill with background color so that transparent foreground colors |
| 238 | // yield the same result as on the graph. |
| 239 | gc.SetPen(*wxTRANSPARENT_PEN); |
| 240 | gc.SetBrush(backgroundColor); |
| 241 | gc.DrawRectangle( |
| 242 | legendX + legendTextXOffset, legendY, legendWidth, legendHeight); |
| 243 | |
| 244 | gc.SetBrush(wxColor { legend.color.GetRGB() }); |
| 245 | gc.DrawRectangle( |
| 246 | legendX + legendTextXOffset, legendY, legendWidth, legendHeight); |
| 247 | |
| 248 | gc.SetPen(lineColor); |
| 249 | gc.SetBrush(*wxTRANSPARENT_BRUSH); |
| 250 | gc.DrawRectangle( |
| 251 | legendX + legendTextXOffset, legendY, legendWidth, legendHeight); |
| 252 | |
| 253 | dc.DrawText( |
| 254 | legend.text.Translation(), legendTextX + legendTextXOffset, |
| 255 | legendTextY); |
| 256 | const auto legendTextWidth = |
| 257 | dc.GetTextExtent(legend.text.Translation()).GetWidth(); |
| 258 | legendTextXOffset += legendWidth + 5 + legendTextWidth + legendSpacing; |
| 259 | } |
| 260 | |
| 261 | const auto lineY = legendY + legendHeight / 2.; |
| 262 | constexpr auto lineWidth = 24; |
| 263 |
no test coverage detected