@@ -19,6 +19,7 @@
|
|||||||
#include <IconUtils.h>
|
#include <IconUtils.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -29,28 +30,11 @@
|
|||||||
#define B_TRANSLATION_CONTEXT "NormalPulseView"
|
#define B_TRANSLATION_CONTEXT "NormalPulseView"
|
||||||
|
|
||||||
|
|
||||||
float
|
|
||||||
max_font_size(BFont font, const char* text, float maxSize, float maxWidth)
|
|
||||||
{
|
|
||||||
const float steps = 0.5f;
|
|
||||||
|
|
||||||
for (float size = maxSize; size > 4; size -= steps) {
|
|
||||||
font.SetSize(size);
|
|
||||||
if (font.StringWidth(text) <= maxWidth)
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
|
||||||
|
|
||||||
|
|
||||||
NormalPulseView::NormalPulseView(BRect rect)
|
NormalPulseView::NormalPulseView(BRect rect)
|
||||||
: PulseView(rect, "NormalPulseView"),
|
: PulseView(rect, "NormalPulseView"),
|
||||||
fBrandLogo(NULL)
|
fBrandLogo(NULL)
|
||||||
{
|
{
|
||||||
|
SetResizingMode(B_NOT_RESIZABLE);
|
||||||
SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
|
SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
|
||||||
SetLowUIColor(ViewUIColor());
|
SetLowUIColor(ViewUIColor());
|
||||||
|
|
||||||
@@ -60,6 +44,15 @@ NormalPulseView::NormalPulseView(BRect rect)
|
|||||||
mode2->SetMessage(new BMessage(PV_DESKBAR_MODE));
|
mode2->SetMessage(new BMessage(PV_DESKBAR_MODE));
|
||||||
|
|
||||||
DetermineVendorAndProcessor();
|
DetermineVendorAndProcessor();
|
||||||
|
BFont font(be_plain_font);
|
||||||
|
font.SetSize(8);
|
||||||
|
SetFont(&font);
|
||||||
|
|
||||||
|
float width = std::max(StringWidth(fProcessor), 48.0f);
|
||||||
|
fChipRect = BRect(10, (rect.Height() - width - 15) / 2, 25 + width,
|
||||||
|
(rect.Height() + width + 15) / 2);
|
||||||
|
float progressLeft = fChipRect.right + 29;
|
||||||
|
float cpuLeft = fChipRect.right + 5;
|
||||||
|
|
||||||
// Allocate progress bars and button pointers
|
// Allocate progress bars and button pointers
|
||||||
system_info systemInfo;
|
system_info systemInfo;
|
||||||
@@ -70,15 +63,15 @@ NormalPulseView::NormalPulseView(BRect rect)
|
|||||||
|
|
||||||
// Set up the CPU activity bars and buttons
|
// Set up the CPU activity bars and buttons
|
||||||
for (int x = 0; x < fCpuCount; x++) {
|
for (int x = 0; x < fCpuCount; x++) {
|
||||||
BRect r(PROGRESS_MLEFT, PROGRESS_MTOP + ITEM_OFFSET * x,
|
BRect r(progressLeft, PROGRESS_MTOP + ITEM_OFFSET * x,
|
||||||
PROGRESS_MLEFT + ProgressBar::PROGRESS_WIDTH,
|
progressLeft + ProgressBar::PROGRESS_WIDTH,
|
||||||
PROGRESS_MTOP + ITEM_OFFSET * x + ProgressBar::PROGRESS_HEIGHT);
|
PROGRESS_MTOP + ITEM_OFFSET * x + ProgressBar::PROGRESS_HEIGHT);
|
||||||
char* str2 = (char *)B_TRANSLATE("CPU progress bar");
|
char* str2 = (char *)B_TRANSLATE("CPU progress bar");
|
||||||
fProgressBars[x] = new ProgressBar(r, str2);
|
fProgressBars[x] = new ProgressBar(r, str2);
|
||||||
AddChild(fProgressBars[x]);
|
AddChild(fProgressBars[x]);
|
||||||
|
|
||||||
r.Set(CPUBUTTON_MLEFT, CPUBUTTON_MTOP + ITEM_OFFSET * x,
|
r.Set(cpuLeft, CPUBUTTON_MTOP + ITEM_OFFSET * x,
|
||||||
CPUBUTTON_MLEFT + CPUBUTTON_WIDTH + 7,
|
cpuLeft + CPUBUTTON_WIDTH + 7,
|
||||||
CPUBUTTON_MTOP + ITEM_OFFSET * x + CPUBUTTON_HEIGHT + 7);
|
CPUBUTTON_MTOP + ITEM_OFFSET * x + CPUBUTTON_HEIGHT + 7);
|
||||||
char temp[4];
|
char temp[4];
|
||||||
snprintf(temp, sizeof(temp), "%hhd", int8(x + 1));
|
snprintf(temp, sizeof(temp), "%hhd", int8(x + 1));
|
||||||
@@ -90,6 +83,8 @@ NormalPulseView::NormalPulseView(BRect rect)
|
|||||||
fProgressBars[0]->MoveBy(-3, 12);
|
fProgressBars[0]->MoveBy(-3, 12);
|
||||||
fCpuButtons[0]->Hide();
|
fCpuButtons[0]->Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResizeTo(progressLeft + ProgressBar::PROGRESS_WIDTH + 10, rect.Height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -101,19 +96,6 @@ NormalPulseView::~NormalPulseView()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
NormalPulseView::CalculateFontSizes()
|
|
||||||
{
|
|
||||||
BFont font;
|
|
||||||
GetFont(&font);
|
|
||||||
|
|
||||||
fProcessorFontSize = max_font_size(font, fProcessor, 11.0f, 46.0f);
|
|
||||||
|
|
||||||
if (fBrandLogo == NULL)
|
|
||||||
fVendorFontSize = max_font_size(font, fVendor, 13.0f, 46.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
NormalPulseView::DetermineVendorAndProcessor()
|
NormalPulseView::DetermineVendorAndProcessor()
|
||||||
{
|
{
|
||||||
@@ -247,6 +229,8 @@ NormalPulseView::DrawChip(BRect r)
|
|||||||
BPoint(innerRect.right - 8, innerRect.top), B_MIXED_COLORS);
|
BPoint(innerRect.right - 8, innerRect.top), B_MIXED_COLORS);
|
||||||
StrokeLine(BPoint(innerRect.left + 8, innerRect.bottom),
|
StrokeLine(BPoint(innerRect.left + 8, innerRect.bottom),
|
||||||
BPoint(innerRect.right - 8, innerRect.bottom), B_MIXED_COLORS);
|
BPoint(innerRect.right - 8, innerRect.bottom), B_MIXED_COLORS);
|
||||||
|
|
||||||
|
SetDrawingMode(B_OP_OVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -257,25 +241,24 @@ NormalPulseView::Draw(BRect rect)
|
|||||||
|
|
||||||
SetDrawingMode(B_OP_OVER);
|
SetDrawingMode(B_OP_OVER);
|
||||||
// Processor picture
|
// Processor picture
|
||||||
DrawChip(BRect(10, 10, 74, 74));
|
DrawChip(fChipRect);
|
||||||
|
|
||||||
if (fBrandLogo != NULL) {
|
if (fBrandLogo != NULL) {
|
||||||
DrawBitmap(fBrandLogo, BPoint(18, 17));
|
DrawBitmap(fBrandLogo, BPoint(
|
||||||
|
9 + (fChipRect.Width() - fBrandLogo->Bounds().Width()) / 2,
|
||||||
|
fChipRect.top + 8));
|
||||||
} else {
|
} else {
|
||||||
SetHighColor(240, 240, 240);
|
SetHighColor(240, 240, 240);
|
||||||
SetFontSize(fVendorFontSize);
|
|
||||||
|
|
||||||
float width = StringWidth(fVendor);
|
float width = StringWidth(fVendor);
|
||||||
MovePenTo(10 + (32 - width / 2), 30);
|
MovePenTo(10 + (fChipRect.Width() - width) / 2, fChipRect.top + 20);
|
||||||
DrawString(fVendor);
|
DrawString(fVendor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw processor type and speed
|
// Draw processor type and speed
|
||||||
SetHighColor(240, 240, 240);
|
SetHighColor(240, 240, 240);
|
||||||
|
|
||||||
SetFontSize(fProcessorFontSize);
|
|
||||||
float width = StringWidth(fProcessor);
|
float width = StringWidth(fProcessor);
|
||||||
MovePenTo(10 + (32 - width / 2), 55);
|
MovePenTo(10 + (fChipRect.Width() - width) / 2, fChipRect.top + 48);
|
||||||
DrawString(fProcessor);
|
DrawString(fProcessor);
|
||||||
|
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
@@ -287,11 +270,8 @@ NormalPulseView::Draw(BRect rect)
|
|||||||
|
|
||||||
// We can't assume anymore that a CPU clock speed is always static.
|
// 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...
|
// Let's compute the best font size for the CPU speed string each time...
|
||||||
BFont font;
|
|
||||||
GetFont(&font);
|
|
||||||
SetFontSize(max_font_size(font, buffer, fProcessorFontSize, 46.0f));
|
|
||||||
width = StringWidth(buffer);
|
width = StringWidth(buffer);
|
||||||
MovePenTo(10 + (32 - width / 2), 64);
|
MovePenTo(10 + (fChipRect.Width() - width) / 2, fChipRect.top + 58);
|
||||||
DrawString(buffer);
|
DrawString(buffer);
|
||||||
|
|
||||||
PopState();
|
PopState();
|
||||||
@@ -320,9 +300,6 @@ NormalPulseView::Pulse()
|
|||||||
void
|
void
|
||||||
NormalPulseView::AttachedToWindow()
|
NormalPulseView::AttachedToWindow()
|
||||||
{
|
{
|
||||||
SetFont(be_bold_font);
|
|
||||||
CalculateFontSizes();
|
|
||||||
|
|
||||||
fPreviousTime = system_time();
|
fPreviousTime = system_time();
|
||||||
|
|
||||||
BMessenger messenger(Window());
|
BMessenger messenger(Window());
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class NormalPulseView : public PulseView {
|
|||||||
int32 fCpuCount;
|
int32 fCpuCount;
|
||||||
BBitmap* fBrandLogo;
|
BBitmap* fBrandLogo;
|
||||||
|
|
||||||
float fVendorFontSize, fProcessorFontSize;
|
BRect fChipRect;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -51,8 +51,11 @@ PulseWindow::PulseWindow(BRect rect)
|
|||||||
fNormalPulseView->Hide();
|
fNormalPulseView->Hide();
|
||||||
SetSizeLimits(GetMinimumViewWidth() - 1, 4096, 2, 4096);
|
SetSizeLimits(GetMinimumViewWidth() - 1, 4096, 2, 4096);
|
||||||
ResizeTo(rect.Width(), rect.Height());
|
ResizeTo(rect.Width(), rect.Height());
|
||||||
} else
|
} else {
|
||||||
fMiniPulseView->Hide();
|
fMiniPulseView->Hide();
|
||||||
|
BRect r = fNormalPulseView->Bounds();
|
||||||
|
ResizeTo(r.Width(), r.Height());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -117,6 +120,7 @@ PulseWindow::SetMode(int newmode)
|
|||||||
|
|
||||||
switch (newmode) {
|
switch (newmode) {
|
||||||
case PV_NORMAL_MODE:
|
case PV_NORMAL_MODE:
|
||||||
|
{
|
||||||
if (fMode == MINI_WINDOW_MODE) {
|
if (fMode == MINI_WINDOW_MODE) {
|
||||||
pulseapp->fPrefs->mini_window_rect = Frame();
|
pulseapp->fPrefs->mini_window_rect = Frame();
|
||||||
pulseapp->fPrefs->window_mode = NORMAL_WINDOW_MODE;
|
pulseapp->fPrefs->window_mode = NORMAL_WINDOW_MODE;
|
||||||
@@ -127,12 +131,13 @@ PulseWindow::SetMode(int newmode)
|
|||||||
fMode = NORMAL_WINDOW_MODE;
|
fMode = NORMAL_WINDOW_MODE;
|
||||||
SetType(B_TITLED_WINDOW);
|
SetType(B_TITLED_WINDOW);
|
||||||
SetFlags(B_NOT_RESIZABLE | B_NOT_ZOOMABLE);
|
SetFlags(B_NOT_RESIZABLE | B_NOT_ZOOMABLE);
|
||||||
ResizeTo(pulseapp->fPrefs->normal_window_rect.IntegerWidth(),
|
BRect r = fNormalPulseView->Bounds();
|
||||||
pulseapp->fPrefs->normal_window_rect.IntegerHeight());
|
ResizeTo(r.Width(), r.Height());
|
||||||
MoveTo(pulseapp->fPrefs->normal_window_rect.left,
|
MoveTo(pulseapp->fPrefs->normal_window_rect.left,
|
||||||
pulseapp->fPrefs->normal_window_rect.top);
|
pulseapp->fPrefs->normal_window_rect.top);
|
||||||
MoveOnScreen(B_MOVE_IF_PARTIALLY_OFFSCREEN);
|
MoveOnScreen(B_MOVE_IF_PARTIALLY_OFFSCREEN);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case PV_MINI_MODE:
|
case PV_MINI_MODE:
|
||||||
if (fMode == NORMAL_WINDOW_MODE) {
|
if (fMode == NORMAL_WINDOW_MODE) {
|
||||||
|
|||||||
Reference in New Issue
Block a user