⛏️ index : haiku.git

author Augustin Cavalier <waddlesplash@gmail.com> 2025-12-15 12:43:02.0 -05:00:00
committer Augustin Cavalier <waddlesplash@gmail.com> 2025-12-15 13:34:23.0 -05:00:00
commit
4523120b971dfd858fcab1ddb74a6ee2d4ffb4ff [patch]
tree
a8348ef75bab5fdc1a9d6e72ba573e4ad6f3c5be
parent
42bb2865fde9c69bf6f567e8b6eb8fb196f57ef2
download
4523120b971dfd858fcab1ddb74a6ee2d4ffb4ff.tar.gz

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(-)

diff --git a/src/apps/processcontroller/PCWindow.cpp b/src/apps/processcontroller/PCWindow.cpp
index e7e8177..6bbefe0 100644
--- a/src/apps/processcontroller/PCWindow.cpp
+++ b/src/apps/processcontroller/PCWindow.cpp
@@ -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;

	// For the memory bar
	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);

	// set up a rectangle && instantiate a new view
	// view rect should be same size as window rect but with left top at (0, 0)
	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);

	// make window visible
	Show();
diff --git a/src/apps/processcontroller/ProcessController.cpp b/src/apps/processcontroller/ProcessController.cpp
index 18dbdd2..49f3545 100644
--- a/src/apps/processcontroller/ProcessController.cpp
+++ b/src/apps/processcontroller/ProcessController.cpp
@@ -127,7 +127,16 @@
instantiate_deskbar_item(float maxWidth, float maxHeight)
{
	gInDeskbar = true;
	return new ProcessController(ProcessController::ComposeSize(maxWidth, maxHeight));
}


//	#pragma mark -


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);
}


//	#pragma mark -


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),
diff --git a/src/apps/processcontroller/ProcessController.h b/src/apps/processcontroller/ProcessController.h
index 0ab0e86..3ec6b80 100644
--- a/src/apps/processcontroller/ProcessController.h
+++ b/src/apps/processcontroller/ProcessController.h
@@ -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);