* 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
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
KernelMemoryBarMenuItem.cpp
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,15 +15,17 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "KernelMemoryBarMenuItem.h" #include "KernelMemoryBarMenuItem.h"
#include "MemoryBarMenu.h"
#include "Colors.h" #include "Colors.h"
#include "PCView.h" #include "PCView.h"
#include <stdio.h> #include <stdio.h>
// --------------------------------------------------------------
KernelMemoryBarMenuItem::KernelMemoryBarMenuItem(system_info* sinfo) KernelMemoryBarMenuItem::KernelMemoryBarMenuItem(system_info* sinfo)
: BMenuItem("System Resources & Caches...", NULL) : BMenuItem("System Resources & Caches...", NULL)
{ {
@@ -39,34 +37,42 @@ KernelMemoryBarMenuItem::KernelMemoryBarMenuItem (system_info* sinfo)
fCommitedMemory = float(int(sinfo->used_pages * B_PAGE_SIZE / 1024)); fCommitedMemory = float(int(sinfo->used_pages * B_PAGE_SIZE / 1024));
} }
// --------------------------------------------------------------
void KernelMemoryBarMenuItem::DrawContent () void
KernelMemoryBarMenuItem::DrawContent()
{ {
DrawBar(true); DrawBar(true);
Menu()->MovePenTo(ContentLocation()); Menu()->MovePenTo(ContentLocation());
BMenuItem::DrawContent(); BMenuItem::DrawContent();
} }
// --------------------------------------------------------------
void KernelMemoryBarMenuItem::UpdateSituation (float commitedMemory, float totalWriteMemory) void
KernelMemoryBarMenuItem::UpdateSituation(float commitedMemory,
float totalWriteMemory)
{ {
if (commitedMemory < totalWriteMemory) if (commitedMemory < totalWriteMemory)
totalWriteMemory = commitedMemory; totalWriteMemory = commitedMemory;
fCommitedMemory = commitedMemory; fCommitedMemory = commitedMemory;
fTotalWriteMemory = totalWriteMemory; fTotalWriteMemory = totalWriteMemory;
DrawBar(false); DrawBar(false);
} }
// --------------------------------------------------------------
void KernelMemoryBarMenuItem::DrawBar (bool force) void
KernelMemoryBarMenuItem::DrawBar(bool force)
{ {
bool selected = IsSelected(); bool selected = IsSelected();
BRect frame = Frame(); BRect frame = Frame();
BMenu* menu = Menu(); BMenu* menu = Menu();
// draw the bar itself // 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) if (fTotalWriteMemory < 0)
return; return;
if (fLastSum < 0) if (fLastSum < 0)
force = true; force = true;
if (force) { if (force) {
@@ -78,6 +84,7 @@ void KernelMemoryBarMenuItem::DrawBar (bool force)
} }
cadre.InsetBy(1, 1); cadre.InsetBy(1, 1);
BRect r = cadre; BRect r = cadre;
float grenze1 = cadre.left + (cadre.right - cadre.left) * fTotalWriteMemory / fPhsysicalMemory; float grenze1 = cadre.left + (cadre.right - cadre.left) * fTotalWriteMemory / fPhsysicalMemory;
float grenze2 = cadre.left + (cadre.right - cadre.left) * fCommitedMemory / fPhsysicalMemory; float grenze2 = cadre.left + (cadre.right - cadre.left) * fCommitedMemory / fPhsysicalMemory;
if (grenze1 > cadre.right) if (grenze1 > cadre.right)
@@ -128,24 +135,23 @@ void KernelMemoryBarMenuItem::DrawBar (bool force)
// draw the value // draw the value
double sum = fTotalWriteMemory * FLT_MAX + fCommitedMemory; double sum = fTotalWriteMemory * FLT_MAX + fCommitedMemory;
if (force || sum != fLastSum) if (force || sum != fLastSum) {
{ if (selected) {
if (selected)
{
menu->SetLowColor(gMenuBackColorSelected); menu->SetLowColor(gMenuBackColorSelected);
menu->SetHighColor(gMenuBackColorSelected); menu->SetHighColor(gMenuBackColorSelected);
} } else {
else
{
menu->SetLowColor(gMenuBackColor); menu->SetLowColor(gMenuBackColor);
menu->SetHighColor(gMenuBackColor); menu->SetHighColor(gMenuBackColor);
} }
BRect trect (cadre.left - kMargin - kTextWidth, frame.top, cadre.left - kMargin, frame.bottom); BRect trect(cadre.left - kMargin - gMemoryTextWidth, frame.top,
cadre.left - kMargin, frame.bottom);
menu->FillRect(trect); menu->FillRect(trect);
menu->SetHighColor(kBlack); menu->SetHighColor(kBlack);
char infos[128]; char infos[128];
sprintf(infos, "%.1f MB", fTotalWriteMemory / 1024.f); sprintf(infos, "%.1f MB", fTotalWriteMemory / 1024.f);
BPoint loc (cadre.left - kMargin - kTextWidth / 2 - menu->StringWidth (infos), cadre.bottom + 1); BPoint loc(cadre.left - kMargin - gMemoryTextWidth / 2 - menu->StringWidth(infos),
cadre.bottom + 1);
menu->DrawString(infos, loc); menu->DrawString(infos, loc);
sprintf(infos, "%.1f MB", fCommitedMemory / 1024.f); sprintf(infos, "%.1f MB", fCommitedMemory / 1024.f);
loc.x = cadre.left - kMargin - menu->StringWidth(infos); loc.x = cadre.left - kMargin - menu->StringWidth(infos);
@@ -154,11 +160,13 @@ void KernelMemoryBarMenuItem::DrawBar (bool force)
} }
} }
// --------------------------------------------------------------
void KernelMemoryBarMenuItem::GetContentSize (float* width, float* height) void
KernelMemoryBarMenuItem::GetContentSize(float* _width, float* _height)
{ {
BMenuItem::GetContentSize (width, height); BMenuItem::GetContentSize(_width, _height);
if (*height < 16) if (*_height < 16)
*height = 16; *_height = 16;
*width += 20 + kBarWidth;
*_width += 20 + kBarWidth + kMargin + gMemoryTextWidth;
} }
@@ -1,9 +1,5 @@
/* /*
ProcessController @ 2000, Georges-Edouard Berenger, All Rights Reserved.
KernelMemoryBarMenuItem.h
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,22 +15,19 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef _KERNEL_MEMORY_BAR_MENU_ITEM_H_ #ifndef _KERNEL_MEMORY_BAR_MENU_ITEM_H_
#define _KERNEL_MEMORY_BAR_MENU_ITEM_H_ #define _KERNEL_MEMORY_BAR_MENU_ITEM_H_
#include <MenuItem.h> #include <MenuItem.h>
//---------------------------------------------------------------
class KernelMemoryBarMenuItem : public BMenuItem { class KernelMemoryBarMenuItem : public BMenuItem {
public: public:
KernelMemoryBarMenuItem (system_info* sinfo); KernelMemoryBarMenuItem(system_info* systemInfo);
virtual void DrawContent(); virtual void DrawContent();
virtual void GetContentSize (float* width, float* height); virtual void GetContentSize(float* _width, float* _height);
void DrawBar(bool force); void DrawBar(bool force);
void UpdateSituation(float commitedMemory, float totalWriteMemory); void UpdateSituation(float commitedMemory, float totalWriteMemory);
+51 -23
View File
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
MemoryBarMenu.cpp
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,54 +15,74 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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 "MemoryBarMenu.h"
#include "MemoryBarMenuItem.h" #include "MemoryBarMenuItem.h"
#include "KernelMemoryBarMenuItem.h" #include "KernelMemoryBarMenuItem.h"
#include "PCView.h" #include "PCView.h"
#include <Bitmap.h>
#include <Roster.h>
#include <Window.h> #include <Window.h>
#include <stdlib.h>
#define EXTRA 10 #define EXTRA 10
float gMemoryTextWidth;
MemoryBarMenu::MemoryBarMenu(const char* name, infosPack *infos, system_info* sinfo) MemoryBarMenu::MemoryBarMenu(const char* name, infosPack *infos, system_info* sinfo)
:BMenu (name), fFirstShow (true) : BMenu(name),
fFirstShow(true)
{ {
fTeamCount = sinfo->used_teams + EXTRA; fTeamCount = sinfo->used_teams + EXTRA;
SetFlags(Flags() | B_PULSE_NEEDED); SetFlags(Flags() | B_PULSE_NEEDED);
fTeamList = (team_id*)malloc(sizeof (team_id) * fTeamCount); fTeamList = (team_id*)malloc(sizeof (team_id) * fTeamCount);
int k; int k;
for (k = 0; k < sinfo->used_teams; k++) for (k = 0; k < sinfo->used_teams; k++) {
fTeamList[k] = infos[k].tminfo.team; fTeamList[k] = infos[k].tminfo.team;
while (k < fTeamCount) }
while (k < fTeamCount) {
fTeamList[k++] = -1; fTeamList[k++] = -1;
}
gMemoryTextWidth = 2 * StringWidth("99999 KB") + 20;
fRecycleCount = EXTRA; fRecycleCount = EXTRA;
fRecycleList = (MRecycleItem*)malloc(sizeof(MRecycleItem) * fRecycleCount); fRecycleList = (MRecycleItem*)malloc(sizeof(MRecycleItem) * fRecycleCount);
SetFont(be_plain_font); SetFont(be_plain_font);
AddItem(new KernelMemoryBarMenuItem(sinfo)); AddItem(new KernelMemoryBarMenuItem(sinfo));
} }
MemoryBarMenu::~MemoryBarMenu() MemoryBarMenu::~MemoryBarMenu()
{ {
free(fTeamList); free(fTeamList);
free(fRecycleList); free(fRecycleList);
} }
void MemoryBarMenu::Draw (BRect updateRect)
{ void
if (fFirstShow) MemoryBarMenu::Draw(BRect updateRect)
{ {
if (fFirstShow) {
Pulse(); Pulse();
fFirstShow = false; fFirstShow = false;
} }
BMenu::Draw(updateRect); BMenu::Draw(updateRect);
} }
void MemoryBarMenu::Pulse ()
void
MemoryBarMenu::Pulse()
{ {
system_info sinfo; system_info sinfo;
get_system_info(&sinfo); get_system_info(&sinfo);
@@ -84,7 +100,8 @@ void MemoryBarMenu::Pulse ()
if (m < 0) { if (m < 0) {
if (lastRecycle == fRecycleCount) { if (lastRecycle == fRecycleCount) {
fRecycleCount += EXTRA; fRecycleCount += EXTRA;
fRecycleList = (MRecycleItem*) realloc (fRecycleList, sizeof (MRecycleItem) * fRecycleCount); fRecycleList = (MRecycleItem*)realloc(fRecycleList,
sizeof(MRecycleItem) * fRecycleCount);
} }
fRecycleList[lastRecycle].index = k; fRecycleList[lastRecycle].index = k;
fRecycleList[lastRecycle++].item = item; fRecycleList[lastRecycle++].item = item;
@@ -104,21 +121,26 @@ void MemoryBarMenu::Pulse ()
item = NULL; 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; int j = 0;
while (j < fTeamCount && infos.tminfo.team != fTeamList[j]) while (j < fTeamCount && infos.tminfo.team != fTeamList[j]) {
j++; j++;
}
if (infos.tminfo.team != fTeamList[j]) { if (infos.tminfo.team != fTeamList[j]) {
// new team // new team
team_info info; team_info info;
j = 0; j = 0;
while (j < fTeamCount && fTeamList[j] != -1) while (j < fTeamCount && fTeamList[j] != -1) {
if (get_team_info (fTeamList[j], &info) != B_OK) if (get_team_info (fTeamList[j], &info) != B_OK)
fTeamList[j] = -1; fTeamList[j] = -1;
else else
j++; j++;
}
if (j == fTeamCount) { if (j == fTeamCount) {
fTeamCount += 10; 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; 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! // the team is already gone!
@@ -130,8 +152,11 @@ void MemoryBarMenu::Pulse ()
} }
if (item) if (item)
item->Reset(infos.tmname, infos.tminfo.team, infos.tmicon, true); item->Reset(infos.tmname, infos.tminfo.team, infos.tmicon, true);
else else {
AddItem (item = new MemoryBarMenuItem (infos.tmname, infos.tminfo.team, infos.tmicon, true, NULL)); AddItem(item = new MemoryBarMenuItem (infos.tmname,
infos.tminfo.team, infos.tmicon, true, NULL));
}
int m = item->UpdateSituation(commitedMemory); int m = item->UpdateSituation(commitedMemory);
if (m >= 0) { if (m >= 0) {
total += m; total += m;
@@ -141,14 +166,17 @@ void MemoryBarMenu::Pulse ()
} }
} }
} }
if (item) { if (item) {
RemoveItem(item); RemoveItem(item);
delete item; delete item;
} }
// Delete the items that haven't been recycled. // Delete the items that haven't been recycled.
if (firstRecycle < lastRecycle) if (firstRecycle < lastRecycle) {
RemoveItems (IndexOf (fRecycleList[firstRecycle].item), lastRecycle - firstRecycle, true); RemoveItems(IndexOf(fRecycleList[firstRecycle].item),
lastRecycle - firstRecycle, true);
}
fLastTotalTime = system_time (); fLastTotalTime = system_time ();
KernelMemoryBarMenuItem *kernelItem; KernelMemoryBarMenuItem *kernelItem;
+9 -10
View File
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
MemoryBarMenu.h
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or 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 You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef _MEMORY_BAR_MENU_H_ #ifndef _MEMORY_BAR_MENU_H_
#define _MEMORY_BAR_MENU_H_ #define _MEMORY_BAR_MENU_H_
#include "PCUtils.h" #include "PCUtils.h"
#include <Menu.h> #include <Menu.h>
class MemoryBarMenuItem; class MemoryBarMenuItem;
typedef struct { typedef struct {
@@ -36,11 +32,12 @@ typedef struct {
int index; int index;
} MRecycleItem; } MRecycleItem;
class MemoryBarMenu : public BMenu class MemoryBarMenu : public BMenu {
{
public: public:
MemoryBarMenu (const char* name, infosPack *infos, system_info* sinfo); MemoryBarMenu(const char* name, infosPack *infos,
system_info* sinfo);
virtual ~MemoryBarMenu(); virtual ~MemoryBarMenu();
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
virtual void Pulse(); virtual void Pulse();
@@ -53,4 +50,6 @@ private:
bool fFirstShow; bool fFirstShow;
}; };
extern float gMemoryTextWidth;
#endif // _MEMORY_BAR_MENU_H_ #endif // _MEMORY_BAR_MENU_H_
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
MemoryBarMenuItem.cpp
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or 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 You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "PCView.h" #include "PCView.h"
#include "MemoryBarMenuItem.h" #include "MemoryBarMenuItem.h"
#include "MemoryBarMenu.h" #include "MemoryBarMenu.h"
#include "Colors.h" #include "Colors.h"
#include <Bitmap.h> #include <Bitmap.h>
#include <stdio.h> #include <stdio.h>
// --------------------------------------------------------------
MemoryBarMenuItem::MemoryBarMenuItem (const char *label, team_id team, BBitmap* icon, bool DeleteIcon, BMessage* message) MemoryBarMenuItem::MemoryBarMenuItem(const char *label, team_id team,
:BMenuItem (label, message), fTeamID (team), fIcon (icon), fDeleteIcon (DeleteIcon) 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; fWriteMemory = -1;
fAllMemory = -1; fAllMemory = -1;
@@ -48,54 +58,54 @@ void MemoryBarMenuItem::Init ()
fLastAll = -1; fLastAll = -1;
} }
// --------------------------------------------------------------
MemoryBarMenuItem::~MemoryBarMenuItem ()
{
if (fDeleteIcon)
delete fIcon;
}
// -------------------------------------------------------------- void
void MemoryBarMenuItem::DrawContent () MemoryBarMenuItem::DrawContent()
{ {
BPoint loc;
DrawIcon(); DrawIcon();
if (fWriteMemory < 0) if (fWriteMemory < 0)
BarUpdate(); BarUpdate();
else else
DrawBar(true); DrawBar(true);
loc = ContentLocation ();
BPoint loc = ContentLocation();
loc.x += 20; loc.x += 20;
Menu()->MovePenTo(loc); Menu()->MovePenTo(loc);
BMenuItem::DrawContent(); BMenuItem::DrawContent();
} }
// --------------------------------------------------------------
void MemoryBarMenuItem::DrawIcon ()
{
BPoint loc;
loc = ContentLocation (); void
MemoryBarMenuItem::DrawIcon()
{
BPoint loc = ContentLocation();
BRect frame = Frame(); BRect frame = Frame();
loc.y = frame.top + (frame.bottom - frame.top - 15) / 2; loc.y = frame.top + (frame.bottom - frame.top - 15) / 2;
if (fIcon) {
Menu()->SetDrawingMode(B_OP_OVER); Menu()->SetDrawingMode(B_OP_OVER);
if (fIcon)
Menu()->DrawBitmap(fIcon, loc); Menu()->DrawBitmap(fIcon, loc);
Menu()->SetDrawingMode(B_OP_COPY);
}
} }
// --------------------------------------------------------------
void MemoryBarMenuItem::DrawBar (bool force) void
MemoryBarMenuItem::DrawBar(bool force)
{ {
bool selected = IsSelected(); bool selected = IsSelected();
BRect frame = Frame(); BRect frame = Frame();
BMenu* menu = Menu(); BMenu* menu = Menu();
// draw the bar itself // 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) if (fWriteMemory < 0)
return; return;
if (fGrenze1 < 0) if (fGrenze1 < 0)
force = true; force = true;
if (force) { if (force) {
if (selected) if (selected)
menu->SetHighColor(gFrameColorSelected); menu->SetHighColor(gFrameColorSelected);
@@ -103,6 +113,7 @@ void MemoryBarMenuItem::DrawBar (bool force)
menu->SetHighColor(gFrameColor); menu->SetHighColor(gFrameColor);
menu->StrokeRect(cadre); menu->StrokeRect(cadre);
} }
cadre.InsetBy(1, 1); cadre.InsetBy(1, 1);
BRect r = cadre; BRect r = cadre;
float grenze1 = cadre.left + (cadre.right - cadre.left) * float (fWriteMemory) / fCommitedMemory; float grenze1 = cadre.left + (cadre.right - cadre.left) * float (fWriteMemory) / fCommitedMemory;
@@ -121,14 +132,17 @@ void MemoryBarMenuItem::DrawBar (bool force)
menu->SetHighColor(gKernelColor); menu->SetHighColor(gKernelColor);
menu->FillRect(r); menu->FillRect(r);
} }
r.left = grenze1; r.left = grenze1;
r.right = grenze2; r.right = grenze2;
if (!force) { if (!force) {
if (fGrenze2 > r.left && r.left >= fGrenze1) if (fGrenze2 > r.left && r.left >= fGrenze1)
r.left = fGrenze2; r.left = fGrenze2;
if (fGrenze1 < r.right && r.right <= fGrenze2) if (fGrenze1 < r.right && r.right <= fGrenze2)
r.right = fGrenze1; r.right = fGrenze1;
} }
if (r.left < r.right) { if (r.left < r.right) {
if (selected) if (selected)
menu->SetHighColor(gUserColorSelected); menu->SetHighColor(gUserColorSelected);
@@ -136,10 +150,13 @@ void MemoryBarMenuItem::DrawBar (bool force)
menu->SetHighColor(gUserColor); menu->SetHighColor(gUserColor);
menu->FillRect(r); menu->FillRect(r);
} }
r.left = grenze2; r.left = grenze2;
r.right = cadre.right; r.right = cadre.right;
if (!force) if (!force)
r.right = fGrenze2; r.right = fGrenze2;
if (r.left < r.right) { if (r.left < r.right) {
if (selected) if (selected)
menu->SetHighColor(gWhiteSelected); menu->SetHighColor(gWhiteSelected);
@@ -147,33 +164,38 @@ void MemoryBarMenuItem::DrawBar (bool force)
menu->SetHighColor(kWhite); menu->SetHighColor(kWhite);
menu->FillRect(r); menu->FillRect(r);
} }
menu->SetHighColor(kBlack); menu->SetHighColor(kBlack);
fGrenze1 = grenze1; fGrenze1 = grenze1;
fGrenze2 = grenze2; fGrenze2 = grenze2;
// draw the value // draw the value
if (force || fCommitedMemory != fLastCommited || fWriteMemory != fLastWrite || fAllMemory != fLastAll) if (force || fCommitedMemory != fLastCommited || fWriteMemory != fLastWrite
{ || fAllMemory != fLastAll) {
if (selected) if (selected)
menu->SetLowColor(gMenuBackColorSelected); menu->SetLowColor(gMenuBackColorSelected);
else else
menu->SetLowColor(gMenuBackColor); menu->SetLowColor(gMenuBackColor);
if (force || fWriteMemory != fLastWrite || fAllMemory != fLastAll)
{ if (force || fWriteMemory != fLastWrite || fAllMemory != fLastAll) {
menu->SetHighColor(menu->LowColor()); menu->SetHighColor(menu->LowColor());
BRect trect (cadre.left - kMargin - kTextWidth, frame.top, cadre.left - kMargin, frame.bottom); BRect trect(cadre.left - kMargin - gMemoryTextWidth, frame.top,
cadre.left - kMargin, frame.bottom);
menu->FillRect(trect); menu->FillRect(trect);
fLastWrite = fWriteMemory; fLastWrite = fWriteMemory;
fLastAll = fAllMemory; fLastAll = fAllMemory;
} }
fLastCommited = fCommitedMemory; fLastCommited = fCommitedMemory;
menu->SetHighColor(kBlack); menu->SetHighColor(kBlack);
char infos[128]; char infos[128];
// if (fWriteMemory >= 1024) // if (fWriteMemory >= 1024)
// sprintf(infos, "%.1f MB", float (fWriteMemory) / 1024.f); // sprintf(infos, "%.1f MB", float (fWriteMemory) / 1024.f);
// else // else
sprintf(infos, "%d KB", fWriteMemory); sprintf(infos, "%d KB", fWriteMemory);
BPoint loc (cadre.left - kMargin - kTextWidth / 2 - menu->StringWidth (infos), cadre.bottom + 1);
BPoint loc(cadre.left - kMargin - gMemoryTextWidth / 2 - menu->StringWidth (infos),
cadre.bottom + 1);
menu->DrawString(infos, loc); menu->DrawString(infos, loc);
// if (fAllMemory >= 1024) // if (fAllMemory >= 1024)
// sprintf (infos, "%.1f MB", float (fAllMemory) / 1024.f); // sprintf (infos, "%.1f MB", float (fAllMemory) / 1024.f);
@@ -184,35 +206,40 @@ void MemoryBarMenuItem::DrawBar (bool force)
} }
} }
// --------------------------------------------------------------
void MemoryBarMenuItem::GetContentSize (float* width, float* height) void
MemoryBarMenuItem::GetContentSize(float* _width, float* _height)
{ {
BMenuItem::GetContentSize (width, height); BMenuItem::GetContentSize(_width, _height);
if (*height < 16) if (*_height < 16)
*height = 16; *_height = 16;
*width += 30 + kBarWidth + kMargin + kTextWidth; *_width += 30 + kBarWidth + kMargin + gMemoryTextWidth;
} }
// --------------------------------------------------------------
int MemoryBarMenuItem::UpdateSituation (int commitedMemory) int
MemoryBarMenuItem::UpdateSituation(int commitedMemory)
{ {
fCommitedMemory = commitedMemory; fCommitedMemory = commitedMemory;
BarUpdate(); BarUpdate();
return fWriteMemory; return fWriteMemory;
} }
// --------------------------------------------------------------
void MemoryBarMenuItem::BarUpdate () void
MemoryBarMenuItem::BarUpdate()
{ {
area_info ainfo; area_info ainfo;
int32 cookie = 0; int32 cookie = 0;
size_t lram_size = 0; size_t lram_size = 0;
size_t lwram_size = 0; size_t lwram_size = 0;
bool exists = false; 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; exists = true;
lram_size += ainfo.ram_size; lram_size += ainfo.ram_size;
// TODO: this won't work this way anymore under Haiku!
int zone = (int (ainfo.address) & 0xf0000000) >> 24; int zone = (int (ainfo.address) & 0xf0000000) >> 24;
if ((ainfo.protection & B_WRITE_AREA) if ((ainfo.protection & B_WRITE_AREA)
&& (zone & 0xf0) != 0xA0 // Exclude media buffers && (zone & 0xf0) != 0xA0 // Exclude media buffers
@@ -220,8 +247,8 @@ void MemoryBarMenuItem::BarUpdate ()
lwram_size += ainfo.ram_size; lwram_size += ainfo.ram_size;
} }
if (!exists) { if (!exists) {
team_info infos; team_info info;
exists = get_team_info(fTeamID, &infos) == B_OK; exists = get_team_info(fTeamID, &info) == B_OK;
} }
if (exists) { if (exists) {
fWriteMemory = lwram_size / 1024; fWriteMemory = lwram_size / 1024;
@@ -231,14 +258,18 @@ void MemoryBarMenuItem::BarUpdate ()
fWriteMemory = -1; 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; fTeamID = team;
if (fDeleteIcon) if (fDeleteIcon)
delete fIcon; delete fIcon;
fDeleteIcon = DeleteIcon;
fDeleteIcon = deleteIcon;
fIcon = icon; fIcon = icon;
Init(); Init();
} }
+8 -12
View File
@@ -1,9 +1,5 @@
/* /*
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
MemoryBarMenuItem.h
ProcessController
© 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@@ -19,31 +15,31 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef _MEMORY_BAR_MENU_ITEM_H_ #ifndef _MEMORY_BAR_MENU_ITEM_H_
#define _MEMORY_BAR_MENU_ITEM_H_ #define _MEMORY_BAR_MENU_ITEM_H_
#include <MenuItem.h> #include <MenuItem.h>
class BBitmap; class BBitmap;
//---------------------------------------------------------------
class MemoryBarMenuItem : public BMenuItem { class MemoryBarMenuItem : public BMenuItem {
public: public:
MemoryBarMenuItem (const char *label, team_id team, BBitmap* icon, bool DeleteIcon, BMessage* message); MemoryBarMenuItem(const char *label, team_id team,
BBitmap* icon, bool deleteIcon, BMessage* message);
virtual ~MemoryBarMenuItem(); virtual ~MemoryBarMenuItem();
virtual void DrawContent(); virtual void DrawContent();
virtual void GetContentSize (float* width, float* height); virtual void GetContentSize(float* _width, float* _height);
void DrawIcon(); void DrawIcon();
void DrawBar(bool force); void DrawBar(bool force);
int UpdateSituation(int commitedMemory); int UpdateSituation(int commitedMemory);
void BarUpdate(); void BarUpdate();
void Init(); void Init();
void Reset (char* name, team_id team, BBitmap* icon, bool DeleteIcon); void Reset(char* name, team_id team, BBitmap* icon, bool deleteIcon);
private: private:
int fPhysicalMemory; int fPhysicalMemory;
+1 -4
View File
@@ -1,6 +1,4 @@
/* /*
PCView.h
ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved. ProcessController © 2000, Georges-Edouard Berenger, All Rights Reserved.
Copyright (C) 2004 beunited.org Copyright (C) 2004 beunited.org
@@ -31,7 +29,7 @@ class BMessageRunner;
class ThreadBarMenu; class ThreadBarMenu;
class _EXPORT ProcessController : public BView { class ProcessController : public BView {
public: public:
ProcessController(BRect frame, bool temp = false); ProcessController(BRect frame, bool temp = false);
ProcessController(BMessage *data); ProcessController(BMessage *data);
@@ -92,7 +90,6 @@ extern bool gInDeskbar;
extern int32 gMimicPulse; extern int32 gMimicPulse;
#define kBarWidth 100 #define kBarWidth 100
#define kTextWidth 110
#define kMargin 12 #define kMargin 12
#endif // _PCVIEW_H_ #endif // _PCVIEW_H_