From db5c4a3b16aaf39a2828ffb6b0bcab75055fae42 Mon Sep 17 00:00:00 2001 From: Philippe Houdoin Date: Thu, 30 Mar 2006 16:14:08 +0000 Subject: [PATCH] - The CPU clock speed string was assumed to be shorter than processor name string. The best font size for speed is now dynamically computed to fit too. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16933 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/pulse/NormalPulseView.cpp | 26 ++++++++++++++++---------- src/apps/pulse/NormalPulseView.h | 2 +- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/apps/pulse/NormalPulseView.cpp b/src/apps/pulse/NormalPulseView.cpp index 914ef6d008..298c8e9b88 100644 --- a/src/apps/pulse/NormalPulseView.cpp +++ b/src/apps/pulse/NormalPulseView.cpp @@ -112,7 +112,7 @@ NormalPulseView::~NormalPulseView() void -NormalPulseView::CalculateFontSize() +NormalPulseView::CalculateFontSizes() { BFont font; GetFont(&font); @@ -201,20 +201,26 @@ NormalPulseView::Draw(BRect rect) #endif // Draw processor type and speed + SetDrawingMode(B_OP_OVER); + SetHighColor(240, 240, 240); + + SetFontSize(fProcessorFontSize); + float width = StringWidth(fProcessor); + MovePenTo(10 + (32 - width / 2), 48); + DrawString(fProcessor); + char buffer[64]; int32 cpuSpeed = get_rounded_cpu_speed(); if (cpuSpeed > 1000 && (cpuSpeed % 10) == 0) snprintf(buffer, sizeof(buffer), "%.2f GHz", cpuSpeed / 1000.0f); else snprintf(buffer, sizeof(buffer), "%ld MHz", cpuSpeed); - SetDrawingMode(B_OP_OVER); - SetHighColor(240, 240, 240); - SetFontSize(fProcessorFontSize); - - float width = StringWidth(fProcessor); - MovePenTo(10 + (32 - width / 2), 48); - DrawString(fProcessor); - + + // We can't assume anymore that a CPU clock speed is always static. + // Let's compute the best font size for the CPU speed string each time... + BFont font; + GetFont(&font); + SetFontSize(max_font_size(font, buffer, 11.0f, 46.0f)); width = StringWidth(buffer); MovePenTo(10 + (32 - width / 2), 60); DrawString(buffer); @@ -246,7 +252,7 @@ void NormalPulseView::AttachedToWindow() { SetFont(be_bold_font); - CalculateFontSize(); + CalculateFontSizes(); fPreviousTime = system_time(); diff --git a/src/apps/pulse/NormalPulseView.h b/src/apps/pulse/NormalPulseView.h index de0cb8e3ce..765b1f8be3 100644 --- a/src/apps/pulse/NormalPulseView.h +++ b/src/apps/pulse/NormalPulseView.h @@ -29,7 +29,7 @@ class NormalPulseView : public PulseView { private: void DetermineVendorAndProcessor(); - void CalculateFontSize(); + void CalculateFontSizes(); char fVendor[32], fProcessor[32]; bigtime_t fPreviousTime;