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 "MemoryBarMenuItem.h"
24 #include "MemoryBarMenu.h"
25 #include "ProcessController.h"
28 #include <StringForSize.h>
33 MemoryBarMenuItem::MemoryBarMenuItem(const char *label
, team_id team
,
34 BBitmap
* icon
, bool deleteIcon
, BMessage
* message
)
35 : BMenuItem(label
, message
),
38 fDeleteIcon(deleteIcon
)
44 MemoryBarMenuItem::~MemoryBarMenuItem()
52 MemoryBarMenuItem::Init()
65 MemoryBarMenuItem::DrawContent()
73 BPoint loc
= ContentLocation();
75 Menu()->MovePenTo(loc
);
76 BMenuItem::DrawContent();
81 MemoryBarMenuItem::DrawIcon()
83 // TODO: exact code duplication with TeamBarMenuItem::DrawIcon()
87 BPoint loc
= ContentLocation();
88 BRect frame
= Frame();
90 loc
.y
= frame
.top
+ (frame
.bottom
- frame
.top
- 15) / 2;
94 if (fIcon
->ColorSpace() == B_RGBA32
) {
95 menu
->SetDrawingMode(B_OP_ALPHA
);
96 menu
->SetBlendingMode(B_PIXEL_ALPHA
, B_ALPHA_OVERLAY
);
98 menu
->SetDrawingMode(B_OP_OVER
);
100 menu
->DrawBitmap(fIcon
, loc
);
102 menu
->SetDrawingMode(B_OP_COPY
);
107 MemoryBarMenuItem::DrawBar(bool force
)
109 // only draw anything if something has changed
110 if (!force
&& fWriteMemory
== fLastWrite
&& fAllMemory
== fLastAll
111 && fCommittedMemory
== fLastCommitted
)
114 bool selected
= IsSelected();
115 BRect frame
= Frame();
116 BMenu
* menu
= Menu();
117 rgb_color highColor
= menu
->HighColor();
119 // draw the bar itself
121 BRect
rect(frame
.right
- kMargin
- kBarWidth
, frame
.top
+ 5,
122 frame
.right
- kMargin
, frame
.top
+ 13);
123 if (fWriteMemory
< 0)
131 menu
->SetHighColor(gFrameColorSelected
);
133 menu
->SetHighColor(gFrameColor
);
134 menu
->StrokeRect(rect
);
139 double grenze1
= rect
.left
+ (rect
.right
- rect
.left
) * float(fWriteMemory
)
141 double grenze2
= rect
.left
+ (rect
.right
- rect
.left
) * float(fAllMemory
)
143 if (grenze1
> rect
.right
)
144 grenze1
= rect
.right
;
145 if (grenze2
> rect
.right
)
146 grenze2
= rect
.right
;
150 if (r
.left
< r
.right
) {
152 menu
->SetHighColor(gKernelColorSelected
);
154 menu
->SetHighColor(gKernelColor
);
162 if (fGrenze2
> r
.left
&& r
.left
>= fGrenze1
)
164 if (fGrenze1
< r
.right
&& r
.right
<= fGrenze2
)
168 if (r
.left
< r
.right
) {
170 menu
->SetHighColor(gUserColorSelected
);
172 menu
->SetHighColor(gUserColor
);
177 r
.right
= rect
.right
;
182 if (r
.left
< r
.right
) {
184 menu
->SetHighColor(gWhiteSelected
);
186 menu
->SetHighColor(kWhite
);
190 menu
->SetHighColor(highColor
);
194 fLastCommitted
= fCommittedMemory
;
196 // Draw the values if necessary; if only fCommitedMemory changes, only
197 // the bar might have to be updated
199 if (!force
&& fWriteMemory
== fLastWrite
&& fAllMemory
== fLastAll
)
203 menu
->SetLowColor(gMenuBackColorSelected
);
205 menu
->SetLowColor(gMenuBackColor
);
207 BRect
textRect(rect
.left
- kMargin
- gMemoryTextWidth
, frame
.top
,
208 rect
.left
- kMargin
, frame
.bottom
);
209 menu
->FillRect(textRect
, B_SOLID_LOW
);
211 fLastWrite
= fWriteMemory
;
212 fLastAll
= fAllMemory
;
215 menu
->SetHighColor(ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR
));
217 menu
->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR
));
220 string_for_size(fWriteMemory
* 1024.0, infos
, sizeof(infos
));
222 BPoint
loc(rect
.left
- kMargin
- gMemoryTextWidth
/ 2 - menu
->StringWidth(infos
),
224 menu
->DrawString(infos
, loc
);
226 string_for_size(fAllMemory
* 1024.0, infos
, sizeof(infos
));
227 loc
.x
= rect
.left
- kMargin
- menu
->StringWidth(infos
);
228 menu
->DrawString(infos
, loc
);
229 menu
->SetHighColor(highColor
);
234 MemoryBarMenuItem::GetContentSize(float* _width
, float* _height
)
236 BMenuItem::GetContentSize(_width
, _height
);
239 *_width
+= 30 + kBarWidth
+ kMargin
+ gMemoryTextWidth
;
244 MemoryBarMenuItem::UpdateSituation(int64 committedMemory
)
246 fCommittedMemory
= committedMemory
;
253 MemoryBarMenuItem::BarUpdate()
258 int64 lwram_size
= 0;
261 while (get_next_area_info(fTeamID
, &cookie
, &areaInfo
) == B_OK
) {
263 lram_size
+= areaInfo
.ram_size
;
265 // TODO: this won't work this way anymore under Haiku!
266 // int zone = (int (areaInfo.address) & 0xf0000000) >> 24;
267 if ((areaInfo
.protection
& B_WRITE_AREA
) != 0)
268 lwram_size
+= areaInfo
.ram_size
;
269 // && (zone & 0xf0) != 0xA0 // Exclude media buffers
270 // && (fTeamID != gAppServerTeamID || zone != 0x90)) // Exclude app_server side of bitmaps
274 exists
= get_team_info(fTeamID
, &info
) == B_OK
;
277 fWriteMemory
= lwram_size
/ 1024;
278 fAllMemory
= lram_size
/ 1024;
286 MemoryBarMenuItem::Reset(char* name
, team_id team
, BBitmap
* icon
,
294 fDeleteIcon
= deleteIcon
;