* 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:
parent
0480cf1a60
commit
f4ccbdaa3a
@ -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,15 +15,17 @@
|
||||
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)
|
||||
{
|
||||
@ -39,34 +37,42 @@ KernelMemoryBarMenuItem::KernelMemoryBarMenuItem (system_info* sinfo)
|
||||
fCommitedMemory = float(int(sinfo->used_pages * B_PAGE_SIZE / 1024));
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void KernelMemoryBarMenuItem::DrawContent ()
|
||||
|
||||
void
|
||||
KernelMemoryBarMenuItem::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);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void KernelMemoryBarMenuItem::DrawBar (bool force)
|
||||
|
||||
void
|
||||
KernelMemoryBarMenuItem::DrawBar(bool force)
|
||||
{
|
||||
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) {
|
||||
@ -78,6 +84,7 @@ void KernelMemoryBarMenuItem::DrawBar (bool force)
|
||||
}
|
||||
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)
|
||||
@ -128,24 +135,23 @@ void KernelMemoryBarMenuItem::DrawBar (bool force)
|
||||
|
||||
// draw the value
|
||||
double sum = fTotalWriteMemory * FLT_MAX + fCommitedMemory;
|
||||
if (force || sum != fLastSum)
|
||||
{
|
||||
if (selected)
|
||||
{
|
||||
if (force || sum != fLastSum) {
|
||||
if (selected) {
|
||||
menu->SetLowColor(gMenuBackColorSelected);
|
||||
menu->SetHighColor(gMenuBackColorSelected);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
menu->SetLowColor(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->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);
|
||||
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);
|
||||
@ -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);
|
||||
if (*height < 16)
|
||||
*height = 16;
|
||||
*width += 20 + kBarWidth;
|
||||
BMenuItem::GetContentSize(_width, _height);
|
||||
if (*_height < 16)
|
||||
*_height = 16;
|
||||
|
||||
*_width += 20 + kBarWidth + kMargin + gMemoryTextWidth;
|
||||
}
|
||||
|
@ -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,22 +15,19 @@
|
||||
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* sinfo);
|
||||
KernelMemoryBarMenuItem(system_info* systemInfo);
|
||||
virtual void DrawContent();
|
||||
virtual void GetContentSize (float* width, float* height);
|
||||
virtual void GetContentSize(float* _width, float* _height);
|
||||
void DrawBar(bool force);
|
||||
void UpdateSituation(float commitedMemory, float totalWriteMemory);
|
||||
|
||||
|
@ -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,54 +15,74 @@
|
||||
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
|
||||
|
||||
float gMemoryTextWidth;
|
||||
|
||||
|
||||
MemoryBarMenu::MemoryBarMenu(const char* name, infosPack *infos, system_info* sinfo)
|
||||
:BMenu (name), fFirstShow (true)
|
||||
: BMenu(name),
|
||||
fFirstShow(true)
|
||||
{
|
||||
fTeamCount = sinfo->used_teams + EXTRA;
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
MemoryBarMenu::~MemoryBarMenu()
|
||||
{
|
||||
free(fTeamList);
|
||||
free(fRecycleList);
|
||||
}
|
||||
|
||||
void MemoryBarMenu::Draw (BRect updateRect)
|
||||
{
|
||||
if (fFirstShow)
|
||||
|
||||
void
|
||||
MemoryBarMenu::Draw(BRect updateRect)
|
||||
{
|
||||
if (fFirstShow) {
|
||||
Pulse();
|
||||
fFirstShow = false;
|
||||
}
|
||||
|
||||
BMenu::Draw(updateRect);
|
||||
}
|
||||
|
||||
void MemoryBarMenu::Pulse ()
|
||||
|
||||
void
|
||||
MemoryBarMenu::Pulse()
|
||||
{
|
||||
system_info sinfo;
|
||||
get_system_info(&sinfo);
|
||||
@ -84,7 +100,8 @@ 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;
|
||||
@ -104,21 +121,26 @@ void MemoryBarMenu::Pulse ()
|
||||
item = NULL;
|
||||
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[j] = infos.tminfo.team;
|
||||
if (!get_team_name_and_icon(infos, true)) {
|
||||
// the team is already gone!
|
||||
@ -130,8 +152,11 @@ void MemoryBarMenu::Pulse ()
|
||||
}
|
||||
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));
|
||||
else {
|
||||
AddItem(item = new MemoryBarMenuItem (infos.tmname,
|
||||
infos.tminfo.team, infos.tmicon, true, NULL));
|
||||
}
|
||||
|
||||
int m = item->UpdateSituation(commitedMemory);
|
||||
if (m >= 0) {
|
||||
total += m;
|
||||
@ -141,14 +166,17 @@ void MemoryBarMenu::Pulse ()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (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;
|
||||
|
@ -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,11 +32,12 @@ typedef struct {
|
||||
int index;
|
||||
} MRecycleItem;
|
||||
|
||||
class MemoryBarMenu : public BMenu
|
||||
{
|
||||
class MemoryBarMenu : public BMenu {
|
||||
public:
|
||||
MemoryBarMenu (const char* name, infosPack *infos, system_info* sinfo);
|
||||
MemoryBarMenu(const char* name, infosPack *infos,
|
||||
system_info* sinfo);
|
||||
virtual ~MemoryBarMenu();
|
||||
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void Pulse();
|
||||
|
||||
@ -53,4 +50,6 @@ private:
|
||||
bool fFirstShow;
|
||||
};
|
||||
|
||||
extern float gMemoryTextWidth;
|
||||
|
||||
#endif // _MEMORY_BAR_MENU_H_
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void MemoryBarMenuItem::Init ()
|
||||
|
||||
MemoryBarMenuItem::~MemoryBarMenuItem()
|
||||
{
|
||||
if (fDeleteIcon)
|
||||
delete fIcon;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MemoryBarMenuItem::Init()
|
||||
{
|
||||
fWriteMemory = -1;
|
||||
fAllMemory = -1;
|
||||
@ -48,54 +58,54 @@ void MemoryBarMenuItem::Init ()
|
||||
fLastAll = -1;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
MemoryBarMenuItem::~MemoryBarMenuItem ()
|
||||
{
|
||||
if (fDeleteIcon)
|
||||
delete fIcon;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
void MemoryBarMenuItem::DrawContent ()
|
||||
void
|
||||
MemoryBarMenuItem::DrawContent()
|
||||
{
|
||||
BPoint loc;
|
||||
|
||||
DrawIcon();
|
||||
if (fWriteMemory < 0)
|
||||
BarUpdate();
|
||||
else
|
||||
DrawBar(true);
|
||||
loc = ContentLocation ();
|
||||
|
||||
BPoint loc = ContentLocation();
|
||||
loc.x += 20;
|
||||
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;
|
||||
|
||||
if (fIcon) {
|
||||
Menu()->SetDrawingMode(B_OP_OVER);
|
||||
if (fIcon)
|
||||
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();
|
||||
|
||||
// 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);
|
||||
@ -103,6 +113,7 @@ void MemoryBarMenuItem::DrawBar (bool force)
|
||||
menu->SetHighColor(gFrameColor);
|
||||
menu->StrokeRect(cadre);
|
||||
}
|
||||
|
||||
cadre.InsetBy(1, 1);
|
||||
BRect r = cadre;
|
||||
float grenze1 = cadre.left + (cadre.right - cadre.left) * float (fWriteMemory) / fCommitedMemory;
|
||||
@ -121,14 +132,17 @@ void MemoryBarMenuItem::DrawBar (bool force)
|
||||
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);
|
||||
@ -136,10 +150,13 @@ void MemoryBarMenuItem::DrawBar (bool force)
|
||||
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);
|
||||
@ -147,33 +164,38 @@ void MemoryBarMenuItem::DrawBar (bool force)
|
||||
menu->SetHighColor(kWhite);
|
||||
menu->FillRect(r);
|
||||
}
|
||||
|
||||
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);
|
||||
else
|
||||
menu->SetLowColor(gMenuBackColor);
|
||||
if (force || fWriteMemory != fLastWrite || fAllMemory != fLastAll)
|
||||
{
|
||||
|
||||
if (force || fWriteMemory != fLastWrite || fAllMemory != fLastAll) {
|
||||
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);
|
||||
fLastWrite = fWriteMemory;
|
||||
fLastAll = fAllMemory;
|
||||
}
|
||||
fLastCommited = fCommitedMemory;
|
||||
menu->SetHighColor(kBlack);
|
||||
|
||||
char infos[128];
|
||||
// if (fWriteMemory >= 1024)
|
||||
// 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);
|
||||
|
||||
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);
|
||||
@ -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);
|
||||
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();
|
||||
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,8 +247,8 @@ 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;
|
||||
@ -231,14 +258,18 @@ void MemoryBarMenuItem::BarUpdate ()
|
||||
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);
|
||||
fTeamID = team;
|
||||
if (fDeleteIcon)
|
||||
delete fIcon;
|
||||
fDeleteIcon = DeleteIcon;
|
||||
|
||||
fDeleteIcon = deleteIcon;
|
||||
fIcon = icon;
|
||||
Init();
|
||||
}
|
||||
|
||||
|
@ -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,31 +15,31 @@
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
void Reset(char* name, team_id team, BBitmap* icon, bool deleteIcon);
|
||||
|
||||
private:
|
||||
int fPhysicalMemory;
|
||||
|
@ -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_
|
||||
|
Loading…
Reference in New Issue
Block a user