ProcessController: style fixes to TeamBarMenuItem

This commit is contained in:
John Scipione
2014-06-30 17:23:38 -04:00
parent b3263ad3e1
commit 98ec4e9467
2 changed files with 83 additions and 59 deletions
+49 -26
View File
@@ -1,20 +1,20 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved. ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version. version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details. Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
@@ -33,7 +33,8 @@
TeamBarMenuItem::TeamBarMenuItem(BMenu* menu, BMessage* kill_team, team_id team, TeamBarMenuItem::TeamBarMenuItem(BMenu* menu, BMessage* kill_team, team_id team,
BBitmap* icon, bool deleteIcon) BBitmap* icon, bool deleteIcon)
: BMenuItem(menu, kill_team), :
BMenuItem(menu, kill_team),
fTeamID(team), fTeamID(team),
fIcon(icon), fIcon(icon),
fDeleteIcon(deleteIcon) fDeleteIcon(deleteIcon)
@@ -49,11 +50,12 @@ TeamBarMenuItem::Init()
get_team_info(fTeamID, &teamInfo); get_team_info(fTeamID, &teamInfo);
get_team_usage_info(fTeamID, B_USAGE_SELF, &fTeamUsageInfo); get_team_usage_info(fTeamID, B_USAGE_SELF, &fTeamUsageInfo);
if (fTeamID == B_SYSTEM_TEAM) { if (fTeamID == B_SYSTEM_TEAM) {
thread_info thinfos; thread_info thinfos;
bigtime_t idle = 0; bigtime_t idle = 0;
for (unsigned int t = 1; t <= gCPUcount; t++) for (unsigned int t = 1; t <= gCPUcount; t++) {
if (get_thread_info(t, &thinfos) == B_OK) if (get_thread_info(t, &thinfos) == B_OK)
idle += thinfos.kernel_time + thinfos.user_time; idle += thinfos.kernel_time + thinfos.user_time;
}
fTeamUsageInfo.kernel_time += fTeamUsageInfo.user_time; fTeamUsageInfo.kernel_time += fTeamUsageInfo.user_time;
fTeamUsageInfo.user_time = idle; fTeamUsageInfo.user_time = idle;
} }
@@ -82,6 +84,7 @@ TeamBarMenuItem::DrawContent()
BarUpdate(); BarUpdate();
else else
DrawBar(true); DrawBar(true);
loc = ContentLocation(); loc = ContentLocation();
loc.x += 20; loc.x += 20;
Menu()->MovePenTo(loc); Menu()->MovePenTo(loc);
@@ -92,7 +95,7 @@ TeamBarMenuItem::DrawContent()
void void
TeamBarMenuItem::DrawIcon() TeamBarMenuItem::DrawIcon()
{ {
if (!fIcon) if (fIcon == NULL)
return; return;
BPoint loc = ContentLocation(); BPoint loc = ContentLocation();
@@ -130,30 +133,39 @@ TeamBarMenuItem::DrawBar(bool force)
if (fGrenze1 < 0) if (fGrenze1 < 0)
force = true; force = true;
if (force) { if (force) {
if (selected) if (selected)
menu->SetHighColor(gFrameColorSelected); menu->SetHighColor(gFrameColorSelected);
else else
menu->SetHighColor(gFrameColor); menu->SetHighColor(gFrameColor);
menu->StrokeRect(frame); menu->StrokeRect(frame);
} }
frame.InsetBy(1, 1); frame.InsetBy(1, 1);
BRect r = frame; BRect r = frame;
float grenze1 = frame.left + (frame.right - frame.left) * fKernel / gCPUcount; float grenze1 = frame.left + (frame.right - frame.left)
float grenze2 = frame.left + (frame.right - frame.left) * (fKernel + fUser) / gCPUcount; * fKernel / gCPUcount;
float grenze2 = frame.left + (frame.right - frame.left)
* (fKernel + fUser) / gCPUcount;
if (grenze1 > frame.right) if (grenze1 > frame.right)
grenze1 = frame.right; grenze1 = frame.right;
if (grenze2 > frame.right) if (grenze2 > frame.right)
grenze2 = frame.right; grenze2 = frame.right;
r.right = grenze1; r.right = grenze1;
if (!force) if (!force)
r.left = fGrenze1; r.left = fGrenze1;
if (r.left < r.right) { if (r.left < r.right) {
if (selected) if (selected)
menu->SetHighColor(gKernelColorSelected); menu->SetHighColor(gKernelColorSelected);
else else
menu->SetHighColor(gKernelColor); menu->SetHighColor(gKernelColor);
menu->FillRect(r); menu->FillRect(r);
} }
@@ -163,15 +175,22 @@ TeamBarMenuItem::DrawBar(bool force)
if (!force) { if (!force) {
if (fGrenze2 > r.left && r.left >= fGrenze1) if (fGrenze2 > r.left && r.left >= fGrenze1)
r.left = fGrenze2; r.left = fGrenze2;
if (fGrenze1 < r.right && r.right <= fGrenze2)
if (fGrenze1 < r.right && r.right <= fGrenze2)
r.right = fGrenze1; r.right = fGrenze1;
} }
if (r.left < r.right) { if (r.left < r.right) {
if (selected) if (selected) {
menu->SetHighColor(fTeamID == B_SYSTEM_TEAM ? gIdleColorSelected : gUserColorSelected); menu->SetHighColor(fTeamID == B_SYSTEM_TEAM
else ? gIdleColorSelected
menu->SetHighColor(fTeamID == B_SYSTEM_TEAM ? gIdleColor : gUserColor); : gUserColorSelected);
} else {
menu->SetHighColor(fTeamID == B_SYSTEM_TEAM
? gIdleColor
: gUserColor);
}
menu->FillRect(r); menu->FillRect(r);
} }
@@ -180,11 +199,13 @@ TeamBarMenuItem::DrawBar(bool force)
if (!force) if (!force)
r.right = fGrenze2; r.right = fGrenze2;
if (r.left < r.right) { if (r.left < r.right) {
if (selected) if (selected)
menu->SetHighColor(gWhiteSelected); menu->SetHighColor(gWhiteSelected);
else else
menu->SetHighColor(kWhite); menu->SetHighColor(kWhite);
menu->FillRect(r); menu->FillRect(r);
} }
@@ -207,12 +228,12 @@ TeamBarMenuItem::GetContentSize(float* width, float* height)
void void
TeamBarMenuItem::BarUpdate() TeamBarMenuItem::BarUpdate()
{ {
team_usage_info usage; team_usage_info usage;
if (get_team_usage_info(fTeamID, B_USAGE_SELF, &usage) == B_OK) { if (get_team_usage_info(fTeamID, B_USAGE_SELF, &usage) == B_OK) {
bigtime_t now = system_time(); bigtime_t now = system_time();
bigtime_t idle = 0; bigtime_t idle = 0;
if (fTeamID == B_SYSTEM_TEAM) { if (fTeamID == B_SYSTEM_TEAM) {
thread_info thinfos; thread_info thinfos;
for (unsigned int t = 1; t <= gCPUcount; t++) { for (unsigned int t = 1; t <= gCPUcount; t++) {
if (get_thread_info(t, &thinfos) == B_OK) if (get_thread_info(t, &thinfos) == B_OK)
idle += thinfos.kernel_time + thinfos.user_time; idle += thinfos.kernel_time + thinfos.user_time;
@@ -225,10 +246,12 @@ TeamBarMenuItem::BarUpdate()
fKernel = double(usage.kernel_time - fTeamUsageInfo.kernel_time - idle) fKernel = double(usage.kernel_time - fTeamUsageInfo.kernel_time - idle)
/ double(now - fLastTime); / double(now - fLastTime);
fUser = double(usage.user_time - fTeamUsageInfo.user_time) / double(now - fLastTime); fUser = double(usage.user_time - fTeamUsageInfo.user_time)
/ double(now - fLastTime);
if (fKernel < 0) if (fKernel < 0)
fKernel = 0; fKernel = 0;
fLastTime = now; fLastTime = now;
fTeamUsageInfo = usage; fTeamUsageInfo = usage;
DrawBar(false); DrawBar(false);
+34 -33
View File
@@ -1,20 +1,20 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved. ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version. version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details. Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef _TEAM_BAR_MENU_ITEM_H_ #ifndef _TEAM_BAR_MENU_ITEM_H_
#define _TEAM_BAR_MENU_ITEM_H_ #define _TEAM_BAR_MENU_ITEM_H_
@@ -26,31 +26,32 @@ class BBitmap;
class TeamBarMenuItem : public BMenuItem { class TeamBarMenuItem : public BMenuItem {
public: public:
TeamBarMenuItem(BMenu* menu, BMessage* kill_team, team_id team, TeamBarMenuItem(BMenu* menu, BMessage* kill_team, team_id team,
BBitmap* icon, bool deleteIcon); BBitmap* icon, bool deleteIcon);
virtual ~TeamBarMenuItem(); virtual ~TeamBarMenuItem();
virtual void DrawContent(); virtual void DrawContent();
virtual void GetContentSize(float* width, float* height); virtual void GetContentSize(float* width, float* height);
void DrawIcon(); void DrawIcon();
void DrawBar(bool force); void DrawBar(bool force);
void BarUpdate(); void BarUpdate();
void Init(); void Init();
void Reset(char* name, team_id team, BBitmap* icon, bool deleteIcon); void Reset(char* name, team_id team, BBitmap* icon, bool deleteIcon);
double fUser; double fUser;
double fKernel; double fKernel;
private: private:
team_id fTeamID; team_id fTeamID;
BBitmap* fIcon; BBitmap* fIcon;
team_usage_info fTeamUsageInfo; team_usage_info fTeamUsageInfo;
bigtime_t fLastTime; bigtime_t fLastTime;
float fGrenze1; float fGrenze1;
float fGrenze2; float fGrenze2;
bool fDeleteIcon; bool fDeleteIcon;
}; };
#endif // _TEAM_BAR_MENU_ITEM_H_ #endif // _TEAM_BAR_MENU_ITEM_H_