Moved the CPU speed "clearing" function from Pulse to cpu_type.h header.
It's now also used by AboutHaiku. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13569 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
04d45bdb27
commit
26ca407bfc
@ -1,10 +1,10 @@
|
||||
/*
|
||||
* Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
|
||||
* Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
/* Taken from the Pulse application, and extended.
|
||||
* It's used by Pulse and sysinfo.
|
||||
* It's used by Pulse, AboutHaiku, and sysinfo.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -14,6 +14,7 @@ extern "C" {
|
||||
const char *get_cpu_vendor_string(enum cpu_types type);
|
||||
const char *get_cpu_model_string(enum cpu_types type);
|
||||
void get_cpu_type(char *vendorBuffer, size_t vendorSize, char *modelBuffer, size_t modelSize);
|
||||
int32 get_rounded_cpu_speed(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
@ -202,3 +203,27 @@ get_cpu_type(char *vendorBuffer, size_t vendorSize, char *modelBuffer, size_t mo
|
||||
strlcpy(modelBuffer, model, modelSize);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
get_rounded_cpu_speed(void)
|
||||
{
|
||||
system_info sys_info;
|
||||
get_system_info(&sys_info);
|
||||
|
||||
int target = sys_info.cpu_clock_speed / 1000000;
|
||||
int frac = target % 100;
|
||||
int delta = -frac;
|
||||
int at = 0;
|
||||
int freqs[] = { 100, 50, 25, 75, 33, 67, 20, 40, 60, 80, 10, 30, 70, 90 };
|
||||
|
||||
for (uint x = 0; x < sizeof(freqs) / sizeof(freqs[0]); x++) {
|
||||
int ndelta = freqs[x] - frac;
|
||||
if (abs(ndelta) < abs(delta)) {
|
||||
at = freqs[x];
|
||||
delta = ndelta;
|
||||
}
|
||||
}
|
||||
return target + delta;
|
||||
}
|
||||
|
||||
|
@ -207,10 +207,11 @@ AboutView::AboutView(const BRect &r)
|
||||
r.OffsetBy(0, labelHeight);
|
||||
r.bottom = r.top + textHeight;
|
||||
|
||||
if (systemInfo.cpu_clock_speed < 1000000000)
|
||||
sprintf(string,"%d MHz", int(systemInfo.cpu_clock_speed / 1000000.0f));
|
||||
int32 clockSpeed = get_rounded_cpu_speed();
|
||||
if (clockSpeed < 1000000000)
|
||||
sprintf(string,"%ld MHz", clockSpeed);
|
||||
else
|
||||
sprintf(string,"%.2f GHz", systemInfo.cpu_clock_speed / 1000000000.0f);
|
||||
sprintf(string,"%.2f GHz", clockSpeed / 1000.0f);
|
||||
|
||||
stringView = new BStringView(r, "mhztext", string);
|
||||
fInfoView->AddChild(stringView);
|
||||
|
@ -124,29 +124,6 @@ NormalPulseView::CalculateFontSize()
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
NormalPulseView::CalculateCPUSpeed()
|
||||
{
|
||||
system_info sys_info;
|
||||
get_system_info(&sys_info);
|
||||
|
||||
int target = sys_info.cpu_clock_speed / 1000000;
|
||||
int frac = target % 100;
|
||||
int delta = -frac;
|
||||
int at = 0;
|
||||
int freqs[] = { 100, 50, 25, 75, 33, 67, 20, 40, 60, 80, 10, 30, 70, 90 };
|
||||
|
||||
for (uint x = 0; x < sizeof(freqs) / sizeof(freqs[0]); x++) {
|
||||
int ndelta = freqs[x] - frac;
|
||||
if (abs(ndelta) < abs(delta)) {
|
||||
at = freqs[x];
|
||||
delta = ndelta;
|
||||
}
|
||||
}
|
||||
return target + delta;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
NormalPulseView::DetermineVendorAndProcessor()
|
||||
{
|
||||
@ -215,12 +192,12 @@ NormalPulseView::Draw(BRect rect)
|
||||
#endif
|
||||
|
||||
// Draw processor type and speed
|
||||
char buf[500];
|
||||
int cpu_speed = CalculateCPUSpeed();
|
||||
if (cpu_speed > 1000 && (cpu_speed % 10) == 0)
|
||||
sprintf(buf, "%.2f GHz", cpu_speed / 1000.0f);
|
||||
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
|
||||
sprintf(buf, "%d MHz", cpu_speed);
|
||||
snprintf(buffer, sizeof(buffer), "%d MHz", cpuSpeed);
|
||||
SetDrawingMode(B_OP_OVER);
|
||||
SetHighColor(240, 240, 240);
|
||||
SetFontSize(fProcessorFontSize);
|
||||
@ -229,9 +206,9 @@ NormalPulseView::Draw(BRect rect)
|
||||
MovePenTo(10 + (32 - width / 2), 48);
|
||||
DrawString(fProcessor);
|
||||
|
||||
width = StringWidth(buf);
|
||||
width = StringWidth(buffer);
|
||||
MovePenTo(10 + (32 - width / 2), 60);
|
||||
DrawString(buf);
|
||||
DrawString(buffer);
|
||||
|
||||
PopState();
|
||||
}
|
||||
|
@ -28,7 +28,6 @@ class NormalPulseView : public PulseView {
|
||||
void UpdateColors(BMessage *message);
|
||||
|
||||
private:
|
||||
int CalculateCPUSpeed();
|
||||
void DetermineVendorAndProcessor();
|
||||
void CalculateFontSize();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user