2006-05-23 20:01:09 +00:00
|
|
|
/*
|
2020-10-10 15:57:49 -04:00
|
|
|
* Copyright 2000, Georges-Edouard Berenger. All rights reserved.
|
|
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
|
*/
|
2006-05-23 20:01:09 +00:00
|
|
|
|
2006-05-29 19:43:45 +00:00
|
|
|
|
2006-05-23 20:01:09 +00:00
|
|
|
#include "MemoryBarMenuItem.h"
|
2006-05-30 01:32:41 +00:00
|
|
|
|
2006-05-23 20:01:09 +00:00
|
|
|
#include "Colors.h"
|
2006-05-30 01:32:41 +00:00
|
|
|
#include "MemoryBarMenu.h"
|
|
|
|
|
#include "ProcessController.h"
|
2006-05-29 19:43:45 +00:00
|
|
|
|
2006-05-23 20:01:09 +00:00
|
|
|
#include <Bitmap.h>
|
2011-03-02 16:08:24 +00:00
|
|
|
#include <StringForSize.h>
|
2006-05-29 19:43:45 +00:00
|
|
|
|
2006-05-23 20:01:09 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
2006-05-29 19:43:45 +00:00
|
|
|
|
|
|
|
|
MemoryBarMenuItem::MemoryBarMenuItem(const char *label, team_id team,
|
|
|
|
|
BBitmap* icon, bool deleteIcon, BMessage* message)
|
|
|
|
|
: BMenuItem(label, message),
|
|
|
|
|
fTeamID(team),
|
|
|
|
|
fIcon(icon),
|
|
|
|
|
fDeleteIcon(deleteIcon)
|
2006-05-23 20:01:09 +00:00
|
|
|
{
|
2006-05-29 19:43:45 +00:00
|
|
|
Init();
|
2006-05-23 20:01:09 +00:00
|
|
|
}
|
|
|
|
|
|
2006-05-29 19:43:45 +00:00
|
|
|
|
|
|
|
|
MemoryBarMenuItem::~MemoryBarMenuItem()
|
|
|
|
|
{
|
|
|
|
|
if (fDeleteIcon)
|
|
|
|
|
delete fIcon;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MemoryBarMenuItem::Init()
|
2006-05-23 20:01:09 +00:00
|
|
|
{
|
|
|
|
|
fWriteMemory = -1;
|
|
|
|
|
fAllMemory = -1;
|
|
|
|
|
fGrenze1 = -1;
|
|
|
|
|
fGrenze2 = -1;
|
2013-07-19 20:50:36 -04:00
|
|
|
fLastCommitted = -1;
|
2006-05-23 20:01:09 +00:00
|
|
|
fLastWrite = -1;
|
|
|
|
|
fLastAll = -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-05-29 19:43:45 +00:00
|
|
|
void
|
|
|
|
|
MemoryBarMenuItem::DrawContent()
|
2006-05-23 20:01:09 +00:00
|
|
|
{
|
2006-05-29 19:43:45 +00:00
|
|
|
DrawIcon();
|
2006-05-23 20:01:09 +00:00
|
|
|
if (fWriteMemory < 0)
|
2006-05-29 19:43:45 +00:00
|
|
|
BarUpdate();
|
2006-05-23 20:01:09 +00:00
|
|
|
else
|
2006-05-29 19:43:45 +00:00
|
|
|
DrawBar(true);
|
|
|
|
|
|
|
|
|
|
BPoint loc = ContentLocation();
|
2006-05-23 20:01:09 +00:00
|
|
|
loc.x += 20;
|
2006-05-29 19:43:45 +00:00
|
|
|
Menu()->MovePenTo(loc);
|
|
|
|
|
BMenuItem::DrawContent();
|
2006-05-23 20:01:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-05-29 19:43:45 +00:00
|
|
|
void
|
|
|
|
|
MemoryBarMenuItem::DrawIcon()
|
|
|
|
|
{
|
2006-11-17 09:51:33 +00:00
|
|
|
// TODO: exact code duplication with TeamBarMenuItem::DrawIcon()
|
|
|
|
|
if (!fIcon)
|
|
|
|
|
return;
|
|
|
|
|
|
2006-05-29 19:43:45 +00:00
|
|
|
BPoint loc = ContentLocation();
|
|
|
|
|
BRect frame = Frame();
|
2006-11-17 09:51:33 +00:00
|
|
|
|
2006-05-23 20:01:09 +00:00
|
|
|
loc.y = frame.top + (frame.bottom - frame.top - 15) / 2;
|
2006-05-29 19:43:45 +00:00
|
|
|
|
2006-11-17 09:51:33 +00:00
|
|
|
BMenu* menu = Menu();
|
|
|
|
|
|
|
|
|
|
if (fIcon->ColorSpace() == B_RGBA32) {
|
|
|
|
|
menu->SetDrawingMode(B_OP_ALPHA);
|
|
|
|
|
menu->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY);
|
|
|
|
|
} else
|
|
|
|
|
menu->SetDrawingMode(B_OP_OVER);
|
|
|
|
|
|
|
|
|
|
menu->DrawBitmap(fIcon, loc);
|
|
|
|
|
|
|
|
|
|
menu->SetDrawingMode(B_OP_COPY);
|
2006-05-23 20:01:09 +00:00
|
|
|
}
|
|
|
|
|
|
2006-05-29 19:43:45 +00:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MemoryBarMenuItem::DrawBar(bool force)
|
2006-05-23 20:01:09 +00:00
|
|
|
{
|
2006-05-30 01:32:41 +00:00
|
|
|
// only draw anything if something has changed
|
|
|
|
|
if (!force && fWriteMemory == fLastWrite && fAllMemory == fLastAll
|
2013-07-19 20:50:36 -04:00
|
|
|
&& fCommittedMemory == fLastCommitted)
|
2006-05-30 01:32:41 +00:00
|
|
|
return;
|
|
|
|
|
|
2006-05-29 19:43:45 +00:00
|
|
|
bool selected = IsSelected();
|
|
|
|
|
BRect frame = Frame();
|
|
|
|
|
BMenu* menu = Menu();
|
2015-04-06 11:21:59 +00:00
|
|
|
rgb_color highColor = menu->HighColor();
|
2006-05-29 19:43:45 +00:00
|
|
|
|
2019-11-24 13:07:30 +01:00
|
|
|
BFont font;
|
|
|
|
|
menu->GetFont(&font);
|
|
|
|
|
BRect rect = bar_rect(frame, &font);
|
2006-05-30 01:32:41 +00:00
|
|
|
|
2019-11-24 13:07:30 +01:00
|
|
|
// draw the bar itself
|
2006-05-23 20:01:09 +00:00
|
|
|
if (fWriteMemory < 0)
|
|
|
|
|
return;
|
2006-05-29 19:43:45 +00:00
|
|
|
|
2006-05-23 20:01:09 +00:00
|
|
|
if (fGrenze1 < 0)
|
|
|
|
|
force = true;
|
2006-05-29 19:43:45 +00:00
|
|
|
|
2006-05-23 20:01:09 +00:00
|
|
|
if (force) {
|
|
|
|
|
if (selected)
|
2006-05-29 19:43:45 +00:00
|
|
|
menu->SetHighColor(gFrameColorSelected);
|
2006-05-23 20:01:09 +00:00
|
|
|
else
|
2006-05-29 19:43:45 +00:00
|
|
|
menu->SetHighColor(gFrameColor);
|
2006-05-30 01:32:41 +00:00
|
|
|
menu->StrokeRect(rect);
|
2006-05-23 20:01:09 +00:00
|
|
|
}
|
2006-05-29 19:43:45 +00:00
|
|
|
|
2006-05-30 01:32:41 +00:00
|
|
|
rect.InsetBy(1, 1);
|
|
|
|
|
BRect r = rect;
|
2013-07-19 20:50:36 -04:00
|
|
|
double grenze1 = rect.left + (rect.right - rect.left) * float(fWriteMemory)
|
|
|
|
|
/ fCommittedMemory;
|
|
|
|
|
double grenze2 = rect.left + (rect.right - rect.left) * float(fAllMemory)
|
|
|
|
|
/ fCommittedMemory;
|
2006-05-30 01:32:41 +00:00
|
|
|
if (grenze1 > rect.right)
|
|
|
|
|
grenze1 = rect.right;
|
|
|
|
|
if (grenze2 > rect.right)
|
|
|
|
|
grenze2 = rect.right;
|
2006-05-23 20:01:09 +00:00
|
|
|
r.right = grenze1;
|
|
|
|
|
if (!force)
|
|
|
|
|
r.left = fGrenze1;
|
|
|
|
|
if (r.left < r.right) {
|
|
|
|
|
if (selected)
|
2006-05-29 19:43:45 +00:00
|
|
|
menu->SetHighColor(gKernelColorSelected);
|
2006-05-23 20:01:09 +00:00
|
|
|
else
|
2006-05-29 19:43:45 +00:00
|
|
|
menu->SetHighColor(gKernelColor);
|
2006-05-23 20:01:09 +00:00
|
|
|
menu->FillRect(r);
|
|
|
|
|
}
|
2006-05-29 19:43:45 +00:00
|
|
|
|
2006-05-23 20:01:09 +00:00
|
|
|
r.left = grenze1;
|
|
|
|
|
r.right = grenze2;
|
2006-05-29 19:43:45 +00:00
|
|
|
|
2006-05-23 20:01:09 +00:00
|
|
|
if (!force) {
|
|
|
|
|
if (fGrenze2 > r.left && r.left >= fGrenze1)
|
|
|
|
|
r.left = fGrenze2;
|
|
|
|
|
if (fGrenze1 < r.right && r.right <= fGrenze2)
|
|
|
|
|
r.right = fGrenze1;
|
|
|
|
|
}
|
2006-05-29 19:43:45 +00:00
|
|
|
|
2006-05-23 20:01:09 +00:00
|
|
|
if (r.left < r.right) {
|
|
|
|
|
if (selected)
|
2006-05-29 19:43:45 +00:00
|
|
|
menu->SetHighColor(gUserColorSelected);
|
2006-05-23 20:01:09 +00:00
|
|
|
else
|
2006-05-29 19:43:45 +00:00
|
|
|
menu->SetHighColor(gUserColor);
|
|
|
|
|
menu->FillRect(r);
|
2006-05-23 20:01:09 +00:00
|
|
|
}
|
2006-05-29 19:43:45 +00:00
|
|
|
|
2006-05-23 20:01:09 +00:00
|
|
|
r.left = grenze2;
|
2006-05-30 01:32:41 +00:00
|
|
|
r.right = rect.right;
|
2006-05-29 19:43:45 +00:00
|
|
|
|
2006-05-23 20:01:09 +00:00
|
|
|
if (!force)
|
|
|
|
|
r.right = fGrenze2;
|
2006-05-29 19:43:45 +00:00
|
|
|
|
2006-05-23 20:01:09 +00:00
|
|
|
if (r.left < r.right) {
|
|
|
|
|
if (selected)
|
2006-05-29 19:43:45 +00:00
|
|
|
menu->SetHighColor(gWhiteSelected);
|
2006-05-23 20:01:09 +00:00
|
|
|
else
|
2006-05-29 19:43:45 +00:00
|
|
|
menu->SetHighColor(kWhite);
|
|
|
|
|
menu->FillRect(r);
|
2006-05-23 20:01:09 +00:00
|
|
|
}
|
2006-05-29 19:43:45 +00:00
|
|
|
|
2015-04-06 11:21:59 +00:00
|
|
|
menu->SetHighColor(highColor);
|
2006-05-23 20:01:09 +00:00
|
|
|
fGrenze1 = grenze1;
|
|
|
|
|
fGrenze2 = grenze2;
|
|
|
|
|
|
2013-07-19 20:50:36 -04:00
|
|
|
fLastCommitted = fCommittedMemory;
|
2006-05-30 01:32:41 +00:00
|
|
|
|
|
|
|
|
// Draw the values if necessary; if only fCommitedMemory changes, only
|
|
|
|
|
// the bar might have to be updated
|
|
|
|
|
|
|
|
|
|
if (!force && fWriteMemory == fLastWrite && fAllMemory == fLastAll)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (selected)
|
|
|
|
|
menu->SetLowColor(gMenuBackColorSelected);
|
|
|
|
|
else
|
|
|
|
|
menu->SetLowColor(gMenuBackColor);
|
|
|
|
|
|
|
|
|
|
BRect textRect(rect.left - kMargin - gMemoryTextWidth, frame.top,
|
|
|
|
|
rect.left - kMargin, frame.bottom);
|
|
|
|
|
menu->FillRect(textRect, B_SOLID_LOW);
|
|
|
|
|
|
|
|
|
|
fLastWrite = fWriteMemory;
|
|
|
|
|
fLastAll = fAllMemory;
|
|
|
|
|
|
2015-04-06 11:21:59 +00:00
|
|
|
if (selected)
|
|
|
|
|
menu->SetHighColor(ui_color(B_MENU_SELECTED_ITEM_TEXT_COLOR));
|
|
|
|
|
else
|
|
|
|
|
menu->SetHighColor(ui_color(B_MENU_ITEM_TEXT_COLOR));
|
2006-05-30 01:32:41 +00:00
|
|
|
|
|
|
|
|
char infos[128];
|
2011-03-02 16:08:24 +00:00
|
|
|
string_for_size(fWriteMemory * 1024.0, infos, sizeof(infos));
|
2006-05-30 01:32:41 +00:00
|
|
|
|
|
|
|
|
BPoint loc(rect.left - kMargin - gMemoryTextWidth / 2 - menu->StringWidth(infos),
|
|
|
|
|
rect.bottom + 1);
|
|
|
|
|
menu->DrawString(infos, loc);
|
|
|
|
|
|
2011-03-02 16:08:24 +00:00
|
|
|
string_for_size(fAllMemory * 1024.0, infos, sizeof(infos));
|
2006-05-30 01:32:41 +00:00
|
|
|
loc.x = rect.left - kMargin - menu->StringWidth(infos);
|
|
|
|
|
menu->DrawString(infos, loc);
|
2015-04-06 11:21:59 +00:00
|
|
|
menu->SetHighColor(highColor);
|
2006-05-23 20:01:09 +00:00
|
|
|
}
|
|
|
|
|
|
2006-05-29 19:43:45 +00:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MemoryBarMenuItem::GetContentSize(float* _width, float* _height)
|
2006-05-23 20:01:09 +00:00
|
|
|
{
|
2006-05-29 19:43:45 +00:00
|
|
|
BMenuItem::GetContentSize(_width, _height);
|
|
|
|
|
if (*_height < 16)
|
|
|
|
|
*_height = 16;
|
|
|
|
|
*_width += 30 + kBarWidth + kMargin + gMemoryTextWidth;
|
2006-05-23 20:01:09 +00:00
|
|
|
}
|
|
|
|
|
|
2006-05-29 19:43:45 +00:00
|
|
|
|
|
|
|
|
int
|
2013-07-19 20:50:36 -04:00
|
|
|
MemoryBarMenuItem::UpdateSituation(int64 committedMemory)
|
2006-05-23 20:01:09 +00:00
|
|
|
{
|
2013-07-19 20:50:36 -04:00
|
|
|
fCommittedMemory = committedMemory;
|
2006-05-29 19:43:45 +00:00
|
|
|
BarUpdate();
|
2006-05-23 20:01:09 +00:00
|
|
|
return fWriteMemory;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-29 19:43:45 +00:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MemoryBarMenuItem::BarUpdate()
|
2006-05-23 20:01:09 +00:00
|
|
|
{
|
2008-01-13 21:07:14 +00:00
|
|
|
area_info areaInfo;
|
2012-07-29 09:31:14 +01:00
|
|
|
ssize_t cookie = 0;
|
2012-04-30 21:56:30 -04:00
|
|
|
int64 lram_size = 0;
|
|
|
|
|
int64 lwram_size = 0;
|
2006-05-29 19:43:45 +00:00
|
|
|
bool exists = false;
|
|
|
|
|
|
2008-01-13 21:07:14 +00:00
|
|
|
while (get_next_area_info(fTeamID, &cookie, &areaInfo) == B_OK) {
|
2006-05-23 20:01:09 +00:00
|
|
|
exists = true;
|
2008-01-13 21:07:14 +00:00
|
|
|
lram_size += areaInfo.ram_size;
|
2006-05-29 19:43:45 +00:00
|
|
|
|
|
|
|
|
// TODO: this won't work this way anymore under Haiku!
|
2008-01-13 21:07:14 +00:00
|
|
|
// int zone = (int (areaInfo.address) & 0xf0000000) >> 24;
|
|
|
|
|
if ((areaInfo.protection & B_WRITE_AREA) != 0)
|
|
|
|
|
lwram_size += areaInfo.ram_size;
|
2006-05-30 01:32:41 +00:00
|
|
|
// && (zone & 0xf0) != 0xA0 // Exclude media buffers
|
|
|
|
|
// && (fTeamID != gAppServerTeamID || zone != 0x90)) // Exclude app_server side of bitmaps
|
2006-05-23 20:01:09 +00:00
|
|
|
}
|
|
|
|
|
if (!exists) {
|
2006-05-29 19:43:45 +00:00
|
|
|
team_info info;
|
|
|
|
|
exists = get_team_info(fTeamID, &info) == B_OK;
|
2006-05-23 20:01:09 +00:00
|
|
|
}
|
|
|
|
|
if (exists) {
|
|
|
|
|
fWriteMemory = lwram_size / 1024;
|
|
|
|
|
fAllMemory = lram_size / 1024;
|
2006-05-29 19:43:45 +00:00
|
|
|
DrawBar(false);
|
2006-05-23 20:01:09 +00:00
|
|
|
} else
|
|
|
|
|
fWriteMemory = -1;
|
|
|
|
|
}
|
|
|
|
|
|
2006-05-29 19:43:45 +00:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
MemoryBarMenuItem::Reset(char* name, team_id team, BBitmap* icon,
|
|
|
|
|
bool deleteIcon)
|
2006-05-23 20:01:09 +00:00
|
|
|
{
|
2006-05-29 19:43:45 +00:00
|
|
|
SetLabel(name);
|
2006-05-23 20:01:09 +00:00
|
|
|
fTeamID = team;
|
|
|
|
|
if (fDeleteIcon)
|
|
|
|
|
delete fIcon;
|
2006-05-29 19:43:45 +00:00
|
|
|
|
|
|
|
|
fDeleteIcon = deleteIcon;
|
2006-05-23 20:01:09 +00:00
|
|
|
fIcon = icon;
|
2006-05-29 19:43:45 +00:00
|
|
|
Init();
|
2006-05-23 20:01:09 +00:00
|
|
|
}
|