XTachometer: place numerals by per-label radial extent
The glyph box farthest corner in the radial direction must stay inside the tick ring (inner end r-10) with 4 px clearance, so a wide 4-digit label never crosses the dial rim (the Rust demo showed 6400/8000 clipped at the rim at 720x480). Single-digit labels move inward only ~4 px; verified by re-shoot.
This commit is contained in:
1 parent
7da1a1ef93
commit
45f5f9d605
1 file changed
+9
-2
@@ -184,9 +184,16 @@ public:
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
std::string lab = fmt0(max_ * f / 1000.0);
|
||||
int lx = cx + (int)((r - 26) * std::cos(a));
|
||||
int ly = cy - (int)((r - 26) * std::sin(a));
|
||||
int lw = xframe::font_text_width(numeral_font, lab);
|
||||
// Numeral centre radius: the glyph box's farthest
|
||||
// corner in the radial direction must stay inside the
|
||||
// tick ring (inner end r-10) with 4 px clearance, so a
|
||||
// wide label never crosses the dial rim.
|
||||
double extent = (lw / 2.0) * std::fabs(std::cos(a))
|
||||
+ (numeral_px / 2.0) * std::fabs(std::sin(a));
|
||||
double lr = std::max(8.0, r - 10.0 - extent - 4.0);
|
||||
int lx = cx + (int)(lr * std::cos(a));
|
||||
int ly = cy - (int)(lr * std::sin(a));
|
||||
// Numerals at/after the redline render in red.
|
||||
Srgb lab_color = (f >= red_frac) ? redline_color_ : Srgb{20, 20, 20};
|
||||
xframe::draw_text_font(display_, window_, gc_, numeral_font,
|
||||
|
||||
Reference in new issue
Block a user