* 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:
Axel Dörfler 2006-05-29 19:43:45 +00:00
parent 0480cf1a60
commit f4ccbdaa3a
7 changed files with 335 additions and 283 deletions

View File

@ -1,9 +1,5 @@
/*
KernelMemoryBarMenuItem.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,65 +15,76 @@
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 "KernelMemoryBarMenuItem.h"
#include "MemoryBarMenu.h"
#include "Colors.h"
#include "PCView.h"
#include <stdio.h>
// --------------------------------------------------------------
KernelMemoryBarMenuItem::KernelMemoryBarMenuItem (system_info* sinfo)
:BMenuItem ("System Resources & Caches...", NULL)
KernelMemoryBarMenuItem::KernelMemoryBarMenuItem(system_info* sinfo)
: BMenuItem("System Resources & Caches...", NULL)
{
fTotalWriteMemory = -1;
fLastSum = -1;
fGrenze1 = -1;
fGrenze2 = -1;
fPhsysicalMemory = float (int (sinfo->max_pages * B_PAGE_SIZE / 1024));
fCommitedMemory = float (int (sinfo->used_pages * B_PAGE_SIZE / 1024));
fPhsysicalMemory = float(int(sinfo->max_pages * B_PAGE_SIZE / 1024));
fCommitedMemory = float(int(sinfo->used_pages * B_PAGE_SIZE / 1024));
}
// --------------------------------------------------------------
void KernelMemoryBarMenuItem::DrawContent ()
void
KernelMemoryBarMenuItem::DrawContent()
{
DrawBar (true);
Menu ()->MovePenTo (ContentLocation ());
BMenuItem::DrawContent ();
DrawBar(true);
Menu()->MovePenTo(ContentLocation());
BMenuItem::DrawContent();
}
// --------------------------------------------------------------
void KernelMemoryBarMenuItem::UpdateSituation (float commitedMemory, float totalWriteMemory)
void
KernelMemoryBarMenuItem::UpdateSituation(float commitedMemory,
float totalWriteMemory)
{
if (commitedMemory < totalWriteMemory)
totalWriteMemory = commitedMemory;
fCommitedMemory = commitedMemory;
fTotalWriteMemory = totalWriteMemory;
DrawBar (false);
DrawBar(false);
}
// --------------------------------------------------------------
void KernelMemoryBarMenuItem::DrawBar (bool force)
void
KernelMemoryBarMenuItem::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 (fTotalWriteMemory < 0)
return;
if (fLastSum < 0)
force = true;
if (force) {
if (selected)
menu->SetHighColor (gFrameColorSelected);
menu->SetHighColor(gFrameColorSelected);
else
menu->SetHighColor (gFrameColor);
menu->SetHighColor(gFrameColor);
menu->StrokeRect (cadre);
}
cadre.InsetBy (1, 1);
cadre.InsetBy(1, 1);
BRect r = cadre;
float grenze1 = cadre.left + (cadre.right - cadre.left) * fTotalWriteMemory / fPhsysicalMemory;
float grenze2 = cadre.left + (cadre.right - cadre.left) * fCommitedMemory / fPhsysicalMemory;
if (grenze1 > cadre.right)
@ -89,10 +96,10 @@ void KernelMemoryBarMenuItem::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->SetHighColor(gKernelColor);
// menu->SetHighColor(gKernelColor);
menu->FillRect (r);
}
r.left = grenze1;
@ -105,10 +112,10 @@ void KernelMemoryBarMenuItem::DrawBar (bool force)
}
if (r.left < r.right) {
if (selected)
menu->SetHighColor (tint_color (kLavender, B_HIGHLIGHT_BACKGROUND_TINT));
menu->SetHighColor(tint_color (kLavender, B_HIGHLIGHT_BACKGROUND_TINT));
else
menu->SetHighColor (kLavender);
// menu->SetHighColor (gUserColor);
menu->SetHighColor(kLavender);
// menu->SetHighColor(gUserColor);
menu->FillRect (r);
}
r.left = grenze2;
@ -117,48 +124,49 @@ void KernelMemoryBarMenuItem::DrawBar (bool 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
double sum = fTotalWriteMemory * FLT_MAX + fCommitedMemory;
if (force || sum != fLastSum)
{
if (selected)
{
menu->SetLowColor (gMenuBackColorSelected);
menu->SetHighColor (gMenuBackColorSelected);
if (force || sum != fLastSum) {
if (selected) {
menu->SetLowColor(gMenuBackColorSelected);
menu->SetHighColor(gMenuBackColorSelected);
} else {
menu->SetLowColor(gMenuBackColor);
menu->SetHighColor(gMenuBackColor);
}
else
{
menu->SetLowColor (gMenuBackColor);
menu->SetHighColor (gMenuBackColor);
}
BRect trect (cadre.left - kMargin - kTextWidth, frame.top, cadre.left - kMargin, frame.bottom);
menu->FillRect (trect);
menu->SetHighColor (kBlack);
BRect trect(cadre.left - kMargin - gMemoryTextWidth, frame.top,
cadre.left - kMargin, frame.bottom);
menu->FillRect(trect);
menu->SetHighColor(kBlack);
char infos[128];
sprintf (infos, "%.1f MB", fTotalWriteMemory / 1024.f);
BPoint loc (cadre.left - kMargin - kTextWidth / 2 - menu->StringWidth (infos), cadre.bottom + 1);
menu->DrawString (infos, loc);
sprintf (infos, "%.1f MB", fCommitedMemory / 1024.f);
loc.x = cadre.left - kMargin - menu->StringWidth (infos);
menu->DrawString (infos, loc);
sprintf(infos, "%.1f MB", fTotalWriteMemory / 1024.f);
BPoint loc(cadre.left - kMargin - gMemoryTextWidth / 2 - menu->StringWidth(infos),
cadre.bottom + 1);
menu->DrawString(infos, loc);
sprintf(infos, "%.1f MB", fCommitedMemory / 1024.f);
loc.x = cadre.left - kMargin - menu->StringWidth(infos);
menu->DrawString(infos, loc);
fLastSum = sum;
}
}
// --------------------------------------------------------------
void KernelMemoryBarMenuItem::GetContentSize (float* width, float* height)
void
KernelMemoryBarMenuItem::GetContentSize(float* _width, float* _height)
{
BMenuItem::GetContentSize (width, height);
if (*height < 16)
*height = 16;
*width += 20 + kBarWidth;
BMenuItem::GetContentSize(_width, _height);
if (*_height < 16)
*_height = 16;
*_width += 20 + kBarWidth + kMargin + gMemoryTextWidth;
}

View File

@ -1,9 +1,5 @@
/*
KernelMemoryBarMenuItem.h
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,26 +15,23 @@
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
*/
#ifndef _KERNEL_MEMORY_BAR_MENU_ITEM_H_
#define _KERNEL_MEMORY_BAR_MENU_ITEM_H_
#include <MenuItem.h>
//---------------------------------------------------------------
class KernelMemoryBarMenuItem : public BMenuItem {
public:
KernelMemoryBarMenuItem(system_info* systemInfo);
virtual void DrawContent();
virtual void GetContentSize(float* _width, float* _height);
void DrawBar(bool force);
void UpdateSituation(float commitedMemory, float totalWriteMemory);
public:
KernelMemoryBarMenuItem (system_info* sinfo);
virtual void DrawContent ();
virtual void GetContentSize (float* width, float* height);
void DrawBar (bool force);
void UpdateSituation (float commitedMemory, float totalWriteMemory);
private:
private:
float fTotalWriteMemory;
float fPhsysicalMemory;
float fCommitedMemory;

View File

@ -1,9 +1,5 @@
/*
MemoryBarMenu.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,59 +15,79 @@
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 <Roster.h>
#include <Bitmap.h>
#include <stdlib.h>
#include "MemoryBarMenu.h"
#include "MemoryBarMenuItem.h"
#include "KernelMemoryBarMenuItem.h"
#include "PCView.h"
#include <Bitmap.h>
#include <Roster.h>
#include <Window.h>
#include <stdlib.h>
#define EXTRA 10
MemoryBarMenu::MemoryBarMenu (const char* name, infosPack *infos, system_info* sinfo)
:BMenu (name), fFirstShow (true)
float gMemoryTextWidth;
MemoryBarMenu::MemoryBarMenu(const char* name, infosPack *infos, system_info* sinfo)
: BMenu(name),
fFirstShow(true)
{
fTeamCount = sinfo->used_teams + EXTRA;
SetFlags (Flags () | B_PULSE_NEEDED);
fTeamList = (team_id*) malloc (sizeof (team_id) * fTeamCount);
SetFlags(Flags() | B_PULSE_NEEDED);
fTeamList = (team_id*)malloc(sizeof (team_id) * fTeamCount);
int k;
for (k = 0; k < sinfo->used_teams; k++)
for (k = 0; k < sinfo->used_teams; k++) {
fTeamList[k] = infos[k].tminfo.team;
while (k < fTeamCount)
}
while (k < fTeamCount) {
fTeamList[k++] = -1;
}
gMemoryTextWidth = 2 * StringWidth("99999 KB") + 20;
fRecycleCount = EXTRA;
fRecycleList = (MRecycleItem*) malloc (sizeof (MRecycleItem) * fRecycleCount);
SetFont (be_plain_font);
AddItem (new KernelMemoryBarMenuItem (sinfo));
fRecycleList = (MRecycleItem*)malloc(sizeof(MRecycleItem) * fRecycleCount);
SetFont(be_plain_font);
AddItem(new KernelMemoryBarMenuItem(sinfo));
}
MemoryBarMenu::~MemoryBarMenu()
{
free (fTeamList);
free (fRecycleList);
free(fTeamList);
free(fRecycleList);
}
void MemoryBarMenu::Draw (BRect updateRect)
void
MemoryBarMenu::Draw(BRect updateRect)
{
if (fFirstShow)
{
Pulse ();
if (fFirstShow) {
Pulse();
fFirstShow = false;
}
BMenu::Draw (updateRect);
BMenu::Draw(updateRect);
}
void MemoryBarMenu::Pulse ()
void
MemoryBarMenu::Pulse()
{
system_info sinfo;
get_system_info (&sinfo);
int commitedMemory = int (sinfo.used_pages * B_PAGE_SIZE / 1024);
Window ()->BeginViewTransaction ();
get_system_info(&sinfo);
int commitedMemory = int(sinfo.used_pages * B_PAGE_SIZE / 1024);
Window()->BeginViewTransaction();
// create the list of items to remove, for their team is gone. Update the old teams.
int lastRecycle = 0;
@ -84,13 +100,14 @@ void MemoryBarMenu::Pulse ()
if (m < 0) {
if (lastRecycle == fRecycleCount) {
fRecycleCount += EXTRA;
fRecycleList = (MRecycleItem*) realloc (fRecycleList, sizeof (MRecycleItem) * fRecycleCount);
fRecycleList = (MRecycleItem*)realloc(fRecycleList,
sizeof(MRecycleItem) * fRecycleCount);
}
fRecycleList[lastRecycle].index = k;
fRecycleList[lastRecycle++].item = item;
} else {
if (lastRecycle > 0) {
RemoveItems (fRecycleList[0].index, lastRecycle, true);
RemoveItems(fRecycleList[0].index, lastRecycle, true);
k -= lastRecycle;
lastRecycle = 0;
}
@ -102,25 +119,30 @@ void MemoryBarMenu::Pulse ()
int32 cookie = 0;
infosPack infos;
item = NULL;
while (get_next_team_info (&cookie, &infos.tminfo) == B_OK) {
while (get_next_team_info(&cookie, &infos.tminfo) == B_OK) {
int j = 0;
while (j < fTeamCount && infos.tminfo.team != fTeamList[j])
while (j < fTeamCount && infos.tminfo.team != fTeamList[j]) {
j++;
}
if (infos.tminfo.team != fTeamList[j]) {
// new team
team_info info;
j = 0;
while (j < fTeamCount && fTeamList[j] != -1)
while (j < fTeamCount && fTeamList[j] != -1) {
if (get_team_info (fTeamList[j], &info) != B_OK)
fTeamList[j] = -1;
else
j++;
}
if (j == fTeamCount) {
fTeamCount += 10;
fTeamList = (team_id*) realloc (fTeamList, sizeof (team_id) * fTeamCount);
fTeamList = (team_id*)realloc(fTeamList, sizeof (team_id) * fTeamCount);
}
fTeamList[j] = infos.tminfo.team;
if (!get_team_name_and_icon (infos, true)) {
if (!get_team_name_and_icon(infos, true)) {
// the team is already gone!
delete infos.tmicon;
fTeamList[j] = -1;
@ -129,10 +151,13 @@ void MemoryBarMenu::Pulse ()
item = fRecycleList[firstRecycle++].item;
}
if (item)
item->Reset (infos.tmname, infos.tminfo.team, infos.tmicon, true);
else
AddItem (item = new MemoryBarMenuItem (infos.tmname, infos.tminfo.team, infos.tmicon, true, NULL));
int m = item->UpdateSituation (commitedMemory);
item->Reset(infos.tmname, infos.tminfo.team, infos.tmicon, true);
else {
AddItem(item = new MemoryBarMenuItem (infos.tmname,
infos.tminfo.team, infos.tmicon, true, NULL));
}
int m = item->UpdateSituation(commitedMemory);
if (m >= 0) {
total += m;
item = NULL;
@ -141,18 +166,21 @@ void MemoryBarMenu::Pulse ()
}
}
}
if (item) {
RemoveItem (item);
RemoveItem(item);
delete item;
}
// Delete the items that haven't been recycled.
if (firstRecycle < lastRecycle)
RemoveItems (IndexOf (fRecycleList[firstRecycle].item), lastRecycle - firstRecycle, true);
if (firstRecycle < lastRecycle) {
RemoveItems(IndexOf(fRecycleList[firstRecycle].item),
lastRecycle - firstRecycle, true);
}
fLastTotalTime = system_time ();
KernelMemoryBarMenuItem *kernelItem;
if ((kernelItem = (KernelMemoryBarMenuItem*) ItemAt (0)) != NULL)
if ((kernelItem = (KernelMemoryBarMenuItem*)ItemAt(0)) != NULL)
kernelItem->UpdateSituation (commitedMemory, total);
Window()->EndViewTransaction();

View File

@ -1,9 +1,5 @@
/*
MemoryBarMenu.h
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,16 +15,16 @@
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
*/
#ifndef _MEMORY_BAR_MENU_H_
#define _MEMORY_BAR_MENU_H_
#include "PCUtils.h"
#include <Menu.h>
class MemoryBarMenuItem;
typedef struct {
@ -36,15 +32,16 @@ typedef struct {
int index;
} MRecycleItem;
class MemoryBarMenu : public BMenu
{
public:
MemoryBarMenu (const char* name, infosPack *infos, system_info* sinfo);
virtual ~MemoryBarMenu ();
virtual void Draw (BRect updateRect);
virtual void Pulse ();
class MemoryBarMenu : public BMenu {
public:
MemoryBarMenu(const char* name, infosPack *infos,
system_info* sinfo);
virtual ~MemoryBarMenu();
private:
virtual void Draw(BRect updateRect);
virtual void Pulse();
private:
team_id* fTeamList;
int fTeamCount;
MRecycleItem* fRecycleList;
@ -53,4 +50,6 @@ private:
bool fFirstShow;
};
extern float gMemoryTextWidth;
#endif // _MEMORY_BAR_MENU_H_

View File

@ -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,62 +58,63 @@ 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 ();
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);
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;
@ -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);
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)
{
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();
}

View File

@ -1,9 +1,5 @@
/*
MemoryBarMenuItem.h
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,33 +15,33 @@
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
*/
#ifndef _MEMORY_BAR_MENU_ITEM_H_
#define _MEMORY_BAR_MENU_ITEM_H_
#include <MenuItem.h>
class BBitmap;
//---------------------------------------------------------------
class MemoryBarMenuItem : public BMenuItem {
public:
MemoryBarMenuItem(const char *label, team_id team,
BBitmap* icon, bool deleteIcon, BMessage* message);
virtual ~MemoryBarMenuItem();
public:
MemoryBarMenuItem (const char *label, team_id team, BBitmap* icon, bool DeleteIcon, BMessage* message);
virtual ~MemoryBarMenuItem ();
virtual void DrawContent ();
virtual void GetContentSize (float* width, float* height);
void DrawIcon ();
void DrawBar (bool force);
int UpdateSituation (int commitedMemory);
void BarUpdate ();
void Init ();
void Reset (char* name, team_id team, BBitmap* icon, bool DeleteIcon);
virtual void DrawContent();
virtual void GetContentSize(float* _width, float* _height);
private:
void DrawIcon();
void DrawBar(bool force);
int UpdateSituation(int commitedMemory);
void BarUpdate();
void Init();
void Reset(char* name, team_id team, BBitmap* icon, bool deleteIcon);
private:
int fPhysicalMemory;
int fCommitedMemory;
int fWriteMemory;

View File

@ -1,6 +1,4 @@
/*
PCView.h
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org
@ -31,7 +29,7 @@ class BMessageRunner;
class ThreadBarMenu;
class _EXPORT ProcessController : public BView {
class ProcessController : public BView {
public:
ProcessController(BRect frame, bool temp = false);
ProcessController(BMessage *data);
@ -92,7 +90,6 @@ extern bool gInDeskbar;
extern int32 gMimicPulse;
#define kBarWidth 100
#define kTextWidth 110
#define kMargin 12
#endif // _PCVIEW_H_