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 "KernelMemoryBarMenuItem.h"
24 #include "MemoryBarMenu.h"
25 #include "ProcessController.h"
30 #include <StringForSize.h>
32 #undef B_TRANSLATION_CONTEXT
33 #define B_TRANSLATION_CONTEXT "ProcessController"
36 KernelMemoryBarMenuItem::KernelMemoryBarMenuItem(system_info
& systemInfo
)
37 : BMenuItem(B_TRANSLATE("System resources & caches" B_UTF8_ELLIPSIS
), NULL
)
42 fPhysicalMemory
= (int64
)systemInfo
.max_pages
* B_PAGE_SIZE
/ 1024LL;
43 fCommittedMemory
= (int64
)systemInfo
.used_pages
* B_PAGE_SIZE
/ 1024LL;
44 fCachedMemory
= (int64
)systemInfo
.cached_pages
* B_PAGE_SIZE
/ 1024LL;
49 KernelMemoryBarMenuItem::DrawContent()
52 Menu()->MovePenTo(ContentLocation());
53 BMenuItem::DrawContent();
58 KernelMemoryBarMenuItem::UpdateSituation(int64 committedMemory
,
61 fCommittedMemory
= committedMemory
;
62 fCachedMemory
= cachedMemory
;
68 KernelMemoryBarMenuItem::DrawBar(bool force
)
70 bool selected
= IsSelected();
71 BRect frame
= Frame();
73 rgb_color highColor
= menu
->HighColor();
75 // draw the bar itself
76 BRect
cadre (frame
.right
- kMargin
- kBarWidth
, frame
.top
+ 5,
77 frame
.right
- kMargin
, frame
.top
+ 13);
83 menu
->SetHighColor(gFrameColorSelected
);
85 menu
->SetHighColor(gFrameColor
);
86 menu
->StrokeRect (cadre
);
91 double grenze1
= cadre
.left
+ (cadre
.right
- cadre
.left
)
92 * fCachedMemory
/ fPhysicalMemory
;
93 double grenze2
= cadre
.left
+ (cadre
.right
- cadre
.left
)
94 * fCommittedMemory
/ fPhysicalMemory
;
95 if (grenze1
> cadre
.right
)
96 grenze1
= cadre
.right
;
97 if (grenze2
> cadre
.right
)
98 grenze2
= cadre
.right
;
102 if (r
.left
< r
.right
) {
104 menu
->SetHighColor(gKernelColorSelected
);
106 menu
->SetHighColor(gKernelColor
);
107 // menu->SetHighColor(gKernelColor);
113 if (fGrenze2
> r
.left
&& r
.left
>= fGrenze1
)
115 if (fGrenze1
< r
.right
&& r
.right
<= fGrenze2
)
118 if (r
.left
< r
.right
) {
120 menu
->SetHighColor(tint_color (kLavender
, B_HIGHLIGHT_BACKGROUND_TINT
));
122 menu
->SetHighColor(kLavender
);
123 // menu->SetHighColor(gUserColor);
127 r
.right
= cadre
.right
;
130 if (r
.left
< r
.right
) {
132 menu
->SetHighColor(gWhiteSelected
);
134 menu
->SetHighColor(kWhite
);
137 menu
->SetHighColor(highColor
);
142 double sum
= fCachedMemory
* FLT_MAX
+ fCommittedMemory
;
143 if (force
|| sum
!= fLastSum
) {
145 menu
->SetLowColor(gMenuBackColorSelected
);
146 menu
->SetHighColor(gMenuBackColorSelected
);
148 menu
->SetLowColor(gMenuBackColor
);
149 menu
->SetHighColor(gMenuBackColor
);
151 BRect
trect(cadre
.left
- kMargin
- gMemoryTextWidth
, frame
.top
,
152 cadre
.left
- kMargin
, frame
.bottom
);
153 menu
->FillRect(trect
);
154 menu
->SetHighColor(highColor
);
157 string_for_size(fCachedMemory
* 1024.0, infos
, sizeof(infos
));
158 BPoint
loc(cadre
.left
, cadre
.bottom
+ 1);
159 loc
.x
-= kMargin
+ gMemoryTextWidth
/ 2 + menu
->StringWidth(infos
);
160 menu
->DrawString(infos
, loc
);
161 string_for_size(fCommittedMemory
* 1024.0, infos
, sizeof(infos
));
162 loc
.x
= cadre
.left
- kMargin
- menu
->StringWidth(infos
);
163 menu
->DrawString(infos
, loc
);
170 KernelMemoryBarMenuItem::GetContentSize(float* _width
, float* _height
)
172 BMenuItem::GetContentSize(_width
, _height
);
176 *_width
+= 20 + kBarWidth
+ kMargin
+ gMemoryTextWidth
;