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
20 #include "ThreadBarMenuItem.h"
23 #include "PriorityMenu.h"
24 #include "ProcessController.h"
29 ThreadBarMenuItem::ThreadBarMenuItem(const char* title
, thread_id thread
,
30 BMenu
*menu
, BMessage
* msg
)
31 : BMenuItem(menu
, msg
), fThreadID(thread
)
34 get_thread_info(fThreadID
, &fThreadInfo
);
35 fLastTime
= system_time();
43 ThreadBarMenuItem::DrawContent()
48 Menu()->MovePenTo(ContentLocation());
49 BMenuItem::DrawContent();
54 ThreadBarMenuItem::DrawBar(bool force
)
56 bool selected
= IsSelected();
57 BRect frame
= Frame();
59 rgb_color highColor
= menu
->HighColor();
61 frame
.left
= frame
.right
- kBarWidth
;
63 frame
.bottom
= frame
.top
+ 8;
72 menu
->SetHighColor(gFrameColorSelected
);
74 menu
->SetHighColor(gFrameColor
);
75 menu
->StrokeRect(frame
);
80 float grenze1
= frame
.left
+ (frame
.right
- frame
.left
) * fKernel
;
81 float grenze2
= frame
.left
+ (frame
.right
- frame
.left
) * (fKernel
+ fUser
);
82 if (grenze1
> frame
.right
)
83 grenze1
= frame
.right
;
84 if (grenze2
> frame
.right
)
85 grenze2
= frame
.right
;
91 if (r
.left
< r
.right
) {
93 menu
->SetHighColor(gKernelColorSelected
);
95 menu
->SetHighColor(gKernelColor
);
102 if (fGrenze2
> r
.left
&& r
.left
>= fGrenze1
)
104 if (fGrenze1
< r
.right
&& r
.right
<= fGrenze2
)
107 if (r
.left
< r
.right
) {
108 thread_info threadInfo
;
109 bool idleThread
= false;
110 if (get_thread_info(fThreadID
, &threadInfo
) == B_OK
)
111 idleThread
= threadInfo
.priority
== B_IDLE_PRIORITY
;
115 idleThread
? gIdleColorSelected
: gUserColorSelected
);
117 menu
->SetHighColor(idleThread
? gIdleColor
: gUserColor
);
121 r
.right
= frame
.right
;
124 if (r
.left
< r
.right
) {
126 menu
->SetHighColor(gWhiteSelected
);
128 menu
->SetHighColor(kWhite
);
131 menu
->SetHighColor(highColor
);
138 ThreadBarMenuItem::GetContentSize(float* width
, float* height
)
140 BMenuItem::GetContentSize(width
, height
);
143 *width
+= 10 + kBarWidth
;
148 ThreadBarMenuItem::Highlight(bool on
)
151 PriorityMenu
* popup
= (PriorityMenu
*)Submenu();
153 popup
->Update(fThreadInfo
.priority
);
155 BMenuItem::Highlight(on
);
160 ThreadBarMenuItem::BarUpdate()
163 if (get_thread_info(fThreadID
, &info
) == B_OK
) {
164 bigtime_t now
= system_time();
165 fKernel
= double(info
.kernel_time
- fThreadInfo
.kernel_time
) / double(now
- fLastTime
);
166 fUser
= double(info
.user_time
- fThreadInfo
.user_time
) / double(now
- fLastTime
);
167 if (info
.priority
== B_IDLE_PRIORITY
) {
171 fThreadInfo
.user_time
= info
.user_time
;
172 fThreadInfo
.kernel_time
= info
.kernel_time
;
175 PriorityMenu
* popup
= (PriorityMenu
*)Submenu();
176 if (popup
&& info
.priority
!= fThreadInfo
.priority
)
177 popup
->Update (info
.priority
);
179 fThreadInfo
.priority
= info
.priority
;