ProcessController: Refactor size computation.
* Don't duplicate the logic, put it all in one place: in a
static method of the main class.
* Compose sizes in PCWindow.
Fixes #18049.
Diff
src/apps/processcontroller/PCWindow.cpp | 32 ++++++++++++++++++--------------
src/apps/processcontroller/ProcessController.cpp | 20 +++++++++++++++++---
src/apps/processcontroller/ProcessController.h | 4 +++-
3 files changed, 28 insertions(+), 28 deletions(-)
@@ -13,6 +13,7 @@
#include <Alert.h>
#include <Application.h>
#include <Catalog.h>
#include <ControlLook.h>
#include <Deskbar.h>
#include <Dragger.h>
#include <Roster.h>
@@ -29,31 +30,22 @@
preferences.SaveInt32(kCurrentVersion, kVersionName);
preferences.LoadWindowPosition(this, kPosPrefName);
system_info info;
get_system_info(&info);
int width = 4;
if (info.cpu_count > 4)
width = info.cpu_count;
if (info.cpu_count <= 16)
width *= 2;
width += 8;
BRect rect = Bounds();
BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW);
BView* topView = new BView(Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW);
topView->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
AddChild(topView);
BSize size = be_control_look->ComposeIconSize(16);
float spacing = be_control_look->ComposeSpacing(B_USE_ITEM_SPACING);
rect.Set(0, 0, width - 1, 15);
SetSizeLimits(rect.Width() + 21, rect.Width() + 21, 15 + 21, 15 + 21);
BView* processController = new ProcessController(BRect(BPoint(0, 0),
ProcessController::ComposeSize(size.Width() * 10, size.Height())), false);
rect.OffsetTo((Bounds().Width() - 16) / 2, (Bounds().Height() - 16) / 2);
BSize limits(processController->Bounds().Width() + spacing * 2,
processController->Bounds().Height() + spacing * 2);
SetSizeLimits(limits.Width(), limits.Width(), limits.Height(), limits.Height());
topView->AddChild(new ProcessController(rect));
topView->AddChild(processController);
processController->MoveTo(spacing, spacing);
Show();
@@ -127,7 +127,16 @@
instantiate_deskbar_item(float maxWidth, float maxHeight)
{
gInDeskbar = true;
return new ProcessController(ProcessController::ComposeSize(maxWidth, maxHeight));
}
BSize
ProcessController::ComposeSize(float maxWidth, float maxHeight)
{
system_info info;
get_system_info(&info);
int width = 4;
@@ -143,11 +152,8 @@
if (width > maxWidth)
width = (int)maxWidth;
return new ProcessController(width - 1, maxHeight - 1);
return BSize(width - 1, maxHeight - 1);
}
ProcessController::ProcessController(BRect frame, bool temp)
@@ -192,10 +198,10 @@
}
ProcessController::ProcessController(float width, float height)
ProcessController::ProcessController(BSize size)
:
BView(BRect (0, 0, width, height), kDeskbarItemName, B_FOLLOW_NONE,
B_WILL_DRAW),
BView(BRect(0, 0, size.Width(), size.Height()),
kDeskbarItemName, B_FOLLOW_NONE, B_WILL_DRAW),
fProcessControllerIcon(kSignature),
fProcessorIcon(k_cpu_mini),
fTrackerIcon(kTrackerSig),
@@ -18,9 +18,11 @@
class ProcessController : public BView {
public:
static BSize ComposeSize(float maxWidth, float maxHeight);
ProcessController(BRect frame, bool temp = false);
ProcessController(BMessage *data);
ProcessController(float width, float height);
ProcessController(BSize size);
virtual ~ProcessController();
virtual void MessageReceived(BMessage *message);