2 ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
3 Copyright (C) 2004 beunited.org
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "TeamBarMenuItem.h"
24 #include "ProcessController.h"
25 #include "ThreadBarMenu.h"
26 #include "ThreadBarMenuItem.h"
31 #define B_USAGE_SELF 0
34 TeamBarMenuItem::TeamBarMenuItem(BMenu
* menu
, BMessage
* kill_team
, team_id team
,
35 BBitmap
* icon
, bool deleteIcon
)
37 BMenuItem(menu
, kill_team
),
40 fDeleteIcon(deleteIcon
)
47 TeamBarMenuItem::Init()
49 if (get_team_usage_info(fTeamID
, B_USAGE_SELF
, &fTeamUsageInfo
) != B_OK
)
50 fTeamUsageInfo
.kernel_time
= fTeamUsageInfo
.user_time
= 0;
52 if (fTeamID
== B_SYSTEM_TEAM
) {
55 for (unsigned int t
= 1; t
<= gCPUcount
; t
++) {
56 if (get_thread_info(t
, &thinfos
) == B_OK
)
57 idle
+= thinfos
.kernel_time
+ thinfos
.user_time
;
59 fTeamUsageInfo
.kernel_time
+= fTeamUsageInfo
.user_time
;
60 fTeamUsageInfo
.user_time
= idle
;
63 fLastTime
= system_time();
70 TeamBarMenuItem::~TeamBarMenuItem()
78 TeamBarMenuItem::DrawContent()
88 loc
= ContentLocation();
90 Menu()->MovePenTo(loc
);
91 BMenuItem::DrawContent();
96 TeamBarMenuItem::DrawIcon()
101 BPoint loc
= ContentLocation();
102 BRect frame
= Frame();
104 loc
.y
= frame
.top
+ (frame
.bottom
- frame
.top
- 15) / 2;
106 BMenu
* menu
= Menu();
108 if (fIcon
->ColorSpace() == B_RGBA32
) {
109 menu
->SetDrawingMode(B_OP_ALPHA
);
110 menu
->SetBlendingMode(B_PIXEL_ALPHA
, B_ALPHA_OVERLAY
);
112 menu
->SetDrawingMode(B_OP_OVER
);
114 menu
->DrawBitmap(fIcon
, loc
);
116 menu
->SetDrawingMode(B_OP_COPY
);
121 TeamBarMenuItem::DrawBar(bool force
)
123 bool selected
= IsSelected ();
124 BRect frame
= Frame();
125 BMenu
* menu
= Menu ();
126 rgb_color highColor
= menu
->HighColor();
128 frame
.left
= frame
.right
-kBarWidth
;
130 frame
.bottom
= frame
.top
+8;
140 menu
->SetHighColor(gFrameColorSelected
);
142 menu
->SetHighColor(gFrameColor
);
144 menu
->StrokeRect(frame
);
149 float grenze1
= frame
.left
+ (frame
.right
- frame
.left
)
150 * fKernel
/ gCPUcount
;
151 float grenze2
= frame
.left
+ (frame
.right
- frame
.left
)
152 * (fKernel
+ fUser
) / gCPUcount
;
154 if (grenze1
> frame
.right
)
155 grenze1
= frame
.right
;
157 if (grenze2
> frame
.right
)
158 grenze2
= frame
.right
;
164 if (r
.left
< r
.right
) {
166 menu
->SetHighColor(gKernelColorSelected
);
168 menu
->SetHighColor(gKernelColor
);
177 if (fGrenze2
> r
.left
&& r
.left
>= fGrenze1
)
180 if (fGrenze1
< r
.right
&& r
.right
<= fGrenze2
)
184 if (r
.left
< r
.right
) {
186 menu
->SetHighColor(fTeamID
== B_SYSTEM_TEAM
188 : gUserColorSelected
);
190 menu
->SetHighColor(fTeamID
== B_SYSTEM_TEAM
199 r
.right
= frame
.right
;
204 if (r
.left
< r
.right
) {
206 menu
->SetHighColor(gWhiteSelected
);
208 menu
->SetHighColor(kWhite
);
213 menu
->SetHighColor(highColor
);
220 TeamBarMenuItem::GetContentSize(float* width
, float* height
)
222 BMenuItem::GetContentSize(width
, height
);
223 if (height
!= NULL
&& *height
< 16)
227 *width
+= 40 + kBarWidth
;
232 TeamBarMenuItem::BarUpdate()
234 team_usage_info usage
;
235 if (get_team_usage_info(fTeamID
, B_USAGE_SELF
, &usage
) == B_OK
) {
236 bigtime_t now
= system_time();
238 if (fTeamID
== B_SYSTEM_TEAM
) {
240 for (unsigned int t
= 1; t
<= gCPUcount
; t
++) {
241 if (get_thread_info(t
, &thinfos
) == B_OK
)
242 idle
+= thinfos
.kernel_time
+ thinfos
.user_time
;
244 usage
.kernel_time
+= usage
.user_time
;
245 usage
.user_time
= idle
;
246 idle
-= fTeamUsageInfo
.user_time
;
249 fKernel
= double(usage
.kernel_time
- fTeamUsageInfo
.kernel_time
- idle
)
250 / double(now
- fLastTime
);
252 fUser
= double(usage
.user_time
- fTeamUsageInfo
.user_time
)
253 / double(now
- fLastTime
);
259 fTeamUsageInfo
= usage
;
267 TeamBarMenuItem::Reset(char* name
, team_id team
, BBitmap
* icon
, bool deleteIcon
)
276 fDeleteIcon
= deleteIcon
;
278 Message()->ReplaceInt32("team", team
);
279 ((ThreadBarMenu
*)Submenu())->Reset(team
);