* Made memory menu font sensitive (fixes part of bug #633).
* Some cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17638 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,9 +1,5 @@
|
||||
/*
|
||||
|
||||
MemoryBarMenuItem.cpp
|
||||
|
||||
ProcessController
|
||||
© 2000, Georges-Edouard Berenger, All Rights Reserved.
|
||||
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
|
||||
Copyright (C) 2004 beunited.org
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
@@ -19,25 +15,39 @@
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include "PCView.h"
|
||||
#include "MemoryBarMenuItem.h"
|
||||
#include "MemoryBarMenu.h"
|
||||
#include "Colors.h"
|
||||
|
||||
#include <Bitmap.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
// --------------------------------------------------------------
|
||||
MemoryBarMenuItem::MemoryBarMenuItem (const char *label, team_id team, BBitmap* icon, bool DeleteIcon, BMessage* message)
|
||||
:BMenuItem (label, message), fTeamID (team), fIcon (icon), fDeleteIcon (DeleteIcon)
|
||||
|
||||
MemoryBarMenuItem::MemoryBarMenuItem(const char *label, team_id team,
|
||||
BBitmap* icon, bool deleteIcon, BMessage* message)
|
||||
: BMenuItem(label, message),
|
||||
fTeamID(team),
|
||||
fIcon(icon),
|
||||
fDeleteIcon(deleteIcon)
|
||||
{
|
||||
Init ();
|
||||
Init();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void MemoryBarMenuItem::Init ()
|
||||
|
||||
MemoryBarMenuItem::~MemoryBarMenuItem()
|
||||
{
|
||||
if (fDeleteIcon)
|
||||
delete fIcon;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MemoryBarMenuItem::Init()
|
||||
{
|
||||
fWriteMemory = -1;
|
||||
fAllMemory = -1;
|
||||
@@ -48,65 +58,66 @@ void MemoryBarMenuItem::Init ()
|
||||
fLastAll = -1;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
MemoryBarMenuItem::~MemoryBarMenuItem ()
|
||||
{
|
||||
if (fDeleteIcon)
|
||||
delete fIcon;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void MemoryBarMenuItem::DrawContent ()
|
||||
void
|
||||
MemoryBarMenuItem::DrawContent()
|
||||
{
|
||||
BPoint loc;
|
||||
|
||||
DrawIcon ();
|
||||
DrawIcon();
|
||||
if (fWriteMemory < 0)
|
||||
BarUpdate ();
|
||||
BarUpdate();
|
||||
else
|
||||
DrawBar (true);
|
||||
loc = ContentLocation ();
|
||||
DrawBar(true);
|
||||
|
||||
BPoint loc = ContentLocation();
|
||||
loc.x += 20;
|
||||
Menu ()->MovePenTo (loc);
|
||||
BMenuItem::DrawContent ();
|
||||
Menu()->MovePenTo(loc);
|
||||
BMenuItem::DrawContent();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void MemoryBarMenuItem::DrawIcon ()
|
||||
{
|
||||
BPoint loc;
|
||||
|
||||
loc = ContentLocation ();
|
||||
BRect frame = Frame();
|
||||
void
|
||||
MemoryBarMenuItem::DrawIcon()
|
||||
{
|
||||
BPoint loc = ContentLocation();
|
||||
BRect frame = Frame();
|
||||
loc.y = frame.top + (frame.bottom - frame.top - 15) / 2;
|
||||
Menu ()->SetDrawingMode (B_OP_OVER);
|
||||
if (fIcon)
|
||||
Menu ()->DrawBitmap (fIcon, loc);
|
||||
|
||||
if (fIcon) {
|
||||
Menu()->SetDrawingMode(B_OP_OVER);
|
||||
Menu()->DrawBitmap(fIcon, loc);
|
||||
Menu()->SetDrawingMode(B_OP_COPY);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void MemoryBarMenuItem::DrawBar (bool force)
|
||||
|
||||
void
|
||||
MemoryBarMenuItem::DrawBar(bool force)
|
||||
{
|
||||
bool selected = IsSelected ();
|
||||
BRect frame = Frame ();
|
||||
BMenu* menu = Menu ();
|
||||
bool selected = IsSelected();
|
||||
BRect frame = Frame();
|
||||
BMenu* menu = Menu();
|
||||
|
||||
// draw the bar itself
|
||||
BRect cadre (frame.right - kMargin - kBarWidth, frame.top + 5, frame.right - kMargin, frame.top + 13);
|
||||
BRect cadre(frame.right - kMargin - kBarWidth, frame.top + 5,
|
||||
frame.right - kMargin, frame.top + 13);
|
||||
if (fWriteMemory < 0)
|
||||
return;
|
||||
|
||||
if (fGrenze1 < 0)
|
||||
force = true;
|
||||
|
||||
if (force) {
|
||||
if (selected)
|
||||
menu->SetHighColor (gFrameColorSelected);
|
||||
menu->SetHighColor(gFrameColorSelected);
|
||||
else
|
||||
menu->SetHighColor (gFrameColor);
|
||||
menu->StrokeRect (cadre);
|
||||
menu->SetHighColor(gFrameColor);
|
||||
menu->StrokeRect(cadre);
|
||||
}
|
||||
cadre.InsetBy (1, 1);
|
||||
BRect r = cadre;
|
||||
float grenze1 = cadre.left + (cadre.right - cadre.left) * float (fWriteMemory) / fCommitedMemory;
|
||||
float grenze2 = cadre.left + (cadre.right - cadre.left) * float (fAllMemory) / fCommitedMemory;
|
||||
|
||||
cadre.InsetBy(1, 1);
|
||||
BRect r = cadre;
|
||||
float grenze1 = cadre.left + (cadre.right - cadre.left) * float (fWriteMemory) / fCommitedMemory;
|
||||
float grenze2 = cadre.left + (cadre.right - cadre.left) * float (fAllMemory) / fCommitedMemory;
|
||||
if (grenze1 > cadre.right)
|
||||
grenze1 = cadre.right;
|
||||
if (grenze2 > cadre.right)
|
||||
@@ -116,103 +127,119 @@ void MemoryBarMenuItem::DrawBar (bool force)
|
||||
r.left = fGrenze1;
|
||||
if (r.left < r.right) {
|
||||
if (selected)
|
||||
menu->SetHighColor (gKernelColorSelected);
|
||||
menu->SetHighColor(gKernelColorSelected);
|
||||
else
|
||||
menu->SetHighColor (gKernelColor);
|
||||
menu->SetHighColor(gKernelColor);
|
||||
menu->FillRect(r);
|
||||
}
|
||||
|
||||
r.left = grenze1;
|
||||
r.right = grenze2;
|
||||
|
||||
if (!force) {
|
||||
if (fGrenze2 > r.left && r.left >= fGrenze1)
|
||||
r.left = fGrenze2;
|
||||
if (fGrenze1 < r.right && r.right <= fGrenze2)
|
||||
r.right = fGrenze1;
|
||||
}
|
||||
|
||||
if (r.left < r.right) {
|
||||
if (selected)
|
||||
menu->SetHighColor (gUserColorSelected);
|
||||
menu->SetHighColor(gUserColorSelected);
|
||||
else
|
||||
menu->SetHighColor (gUserColor);
|
||||
menu->FillRect (r);
|
||||
menu->SetHighColor(gUserColor);
|
||||
menu->FillRect(r);
|
||||
}
|
||||
|
||||
r.left = grenze2;
|
||||
r.right = cadre.right;
|
||||
|
||||
if (!force)
|
||||
r.right = fGrenze2;
|
||||
|
||||
if (r.left < r.right) {
|
||||
if (selected)
|
||||
menu->SetHighColor (gWhiteSelected);
|
||||
menu->SetHighColor(gWhiteSelected);
|
||||
else
|
||||
menu->SetHighColor (kWhite);
|
||||
menu->FillRect (r);
|
||||
menu->SetHighColor(kWhite);
|
||||
menu->FillRect(r);
|
||||
}
|
||||
menu->SetHighColor (kBlack);
|
||||
|
||||
menu->SetHighColor(kBlack);
|
||||
fGrenze1 = grenze1;
|
||||
fGrenze2 = grenze2;
|
||||
|
||||
// draw the value
|
||||
if (force || fCommitedMemory != fLastCommited || fWriteMemory != fLastWrite || fAllMemory != fLastAll)
|
||||
{
|
||||
if (force || fCommitedMemory != fLastCommited || fWriteMemory != fLastWrite
|
||||
|| fAllMemory != fLastAll) {
|
||||
if (selected)
|
||||
menu->SetLowColor (gMenuBackColorSelected);
|
||||
menu->SetLowColor(gMenuBackColorSelected);
|
||||
else
|
||||
menu->SetLowColor (gMenuBackColor);
|
||||
if (force || fWriteMemory != fLastWrite || fAllMemory != fLastAll)
|
||||
{
|
||||
menu->SetHighColor (menu->LowColor ());
|
||||
BRect trect (cadre.left - kMargin - kTextWidth, frame.top, cadre.left - kMargin, frame.bottom);
|
||||
menu->FillRect (trect);
|
||||
menu->SetLowColor(gMenuBackColor);
|
||||
|
||||
if (force || fWriteMemory != fLastWrite || fAllMemory != fLastAll) {
|
||||
menu->SetHighColor(menu->LowColor());
|
||||
BRect trect(cadre.left - kMargin - gMemoryTextWidth, frame.top,
|
||||
cadre.left - kMargin, frame.bottom);
|
||||
menu->FillRect(trect);
|
||||
fLastWrite = fWriteMemory;
|
||||
fLastAll = fAllMemory;
|
||||
}
|
||||
fLastCommited = fCommitedMemory;
|
||||
menu->SetHighColor (kBlack);
|
||||
char infos[128];
|
||||
menu->SetHighColor(kBlack);
|
||||
|
||||
char infos[128];
|
||||
// if (fWriteMemory >= 1024)
|
||||
// sprintf (infos, "%.1f MB", float (fWriteMemory) / 1024.f);
|
||||
// sprintf(infos, "%.1f MB", float (fWriteMemory) / 1024.f);
|
||||
// else
|
||||
sprintf (infos, "%d KB", fWriteMemory);
|
||||
BPoint loc (cadre.left - kMargin - kTextWidth / 2 - menu->StringWidth (infos), cadre.bottom + 1);
|
||||
menu->DrawString (infos, loc);
|
||||
sprintf(infos, "%d KB", fWriteMemory);
|
||||
|
||||
BPoint loc(cadre.left - kMargin - gMemoryTextWidth / 2 - menu->StringWidth (infos),
|
||||
cadre.bottom + 1);
|
||||
menu->DrawString(infos, loc);
|
||||
// if (fAllMemory >= 1024)
|
||||
// sprintf (infos, "%.1f MB", float (fAllMemory) / 1024.f);
|
||||
// else
|
||||
sprintf (infos, "%d KB", fAllMemory);
|
||||
loc.x = cadre.left - kMargin - menu->StringWidth (infos);
|
||||
menu->DrawString (infos, loc);
|
||||
sprintf(infos, "%d KB", fAllMemory);
|
||||
loc.x = cadre.left - kMargin - menu->StringWidth(infos);
|
||||
menu->DrawString(infos, loc);
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void MemoryBarMenuItem::GetContentSize (float* width, float* height)
|
||||
|
||||
void
|
||||
MemoryBarMenuItem::GetContentSize(float* _width, float* _height)
|
||||
{
|
||||
BMenuItem::GetContentSize (width, height);
|
||||
if (*height < 16)
|
||||
*height = 16;
|
||||
*width += 30 + kBarWidth + kMargin + kTextWidth;
|
||||
BMenuItem::GetContentSize(_width, _height);
|
||||
if (*_height < 16)
|
||||
*_height = 16;
|
||||
*_width += 30 + kBarWidth + kMargin + gMemoryTextWidth;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
int MemoryBarMenuItem::UpdateSituation (int commitedMemory)
|
||||
|
||||
int
|
||||
MemoryBarMenuItem::UpdateSituation(int commitedMemory)
|
||||
{
|
||||
fCommitedMemory = commitedMemory;
|
||||
BarUpdate ();
|
||||
BarUpdate();
|
||||
return fWriteMemory;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void MemoryBarMenuItem::BarUpdate ()
|
||||
|
||||
void
|
||||
MemoryBarMenuItem::BarUpdate()
|
||||
{
|
||||
area_info ainfo;
|
||||
int32 cookie = 0;
|
||||
size_t lram_size = 0;
|
||||
size_t lwram_size = 0;
|
||||
bool exists = false;
|
||||
while (get_next_area_info (fTeamID, &cookie, &ainfo) == B_OK)
|
||||
{
|
||||
area_info ainfo;
|
||||
int32 cookie = 0;
|
||||
size_t lram_size = 0;
|
||||
size_t lwram_size = 0;
|
||||
bool exists = false;
|
||||
|
||||
while (get_next_area_info(fTeamID, &cookie, &ainfo) == B_OK) {
|
||||
exists = true;
|
||||
lram_size += ainfo.ram_size;
|
||||
|
||||
// TODO: this won't work this way anymore under Haiku!
|
||||
int zone = (int (ainfo.address) & 0xf0000000) >> 24;
|
||||
if ((ainfo.protection & B_WRITE_AREA)
|
||||
&& (zone & 0xf0) != 0xA0 // Exclude media buffers
|
||||
@@ -220,25 +247,29 @@ void MemoryBarMenuItem::BarUpdate ()
|
||||
lwram_size += ainfo.ram_size;
|
||||
}
|
||||
if (!exists) {
|
||||
team_info infos;
|
||||
exists = get_team_info(fTeamID, &infos) == B_OK;
|
||||
team_info info;
|
||||
exists = get_team_info(fTeamID, &info) == B_OK;
|
||||
}
|
||||
if (exists) {
|
||||
fWriteMemory = lwram_size / 1024;
|
||||
fAllMemory = lram_size / 1024;
|
||||
DrawBar (false);
|
||||
DrawBar(false);
|
||||
} else
|
||||
fWriteMemory = -1;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void MemoryBarMenuItem::Reset (char* name, team_id team, BBitmap* icon, bool DeleteIcon)
|
||||
|
||||
void
|
||||
MemoryBarMenuItem::Reset(char* name, team_id team, BBitmap* icon,
|
||||
bool deleteIcon)
|
||||
{
|
||||
SetLabel (name);
|
||||
SetLabel(name);
|
||||
fTeamID = team;
|
||||
if (fDeleteIcon)
|
||||
delete fIcon;
|
||||
fDeleteIcon = DeleteIcon;
|
||||
|
||||
fDeleteIcon = deleteIcon;
|
||||
fIcon = icon;
|
||||
Init ();
|
||||
Init();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user