Use string_for_size() to format and localize sizes in a consistent way.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40780 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin
2011-03-02 16:08:24 +00:00
parent e8cd700741
commit a559946f03
4 changed files with 48 additions and 44 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
SubDir HAIKU_TOP src apps processcontroller ; SubDir HAIKU_TOP src apps processcontroller ;
UsePrivateSystemHeaders ; UsePrivateSystemHeaders ;
UsePrivateHeaders shared ;
Application ProcessController : Application ProcessController :
AutoIcon.cpp AutoIcon.cpp
@@ -20,7 +21,7 @@ Application ProcessController :
ThreadBarMenu.cpp ThreadBarMenu.cpp
ThreadBarMenuItem.cpp ThreadBarMenuItem.cpp
Utilities.cpp Utilities.cpp
: be $(TARGET_LIBSUPC++) $(HAIKU_LOCALE_LIBS) : be libshared.a $(TARGET_LIBSUPC++) $(HAIKU_LOCALE_LIBS)
: ProcessController.rdef : ProcessController.rdef
; ;
@@ -1,20 +1,20 @@
/* /*
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
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version. version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details. Lesser General Public License for more details.
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
*/ */
@@ -27,6 +27,7 @@
#include <stdio.h> #include <stdio.h>
#include <Catalog.h> #include <Catalog.h>
#include <StringForSize.h>
#undef B_TRANSLATE_CONTEXT #undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "ProcessController" #define B_TRANSLATE_CONTEXT "ProcessController"
@@ -152,13 +153,11 @@ KernelMemoryBarMenuItem::DrawBar(bool force)
menu->SetHighColor(kBlack); menu->SetHighColor(kBlack);
char infos[128]; char infos[128];
snprintf(infos, sizeof(infos), string_for_size(fCachedMemory * 1024.0, infos, sizeof(infos));
B_TRANSLATE("%.1f MiB"), fCachedMemory / 1024.f);
BPoint loc(cadre.left, cadre.bottom + 1); BPoint loc(cadre.left, cadre.bottom + 1);
loc.x -= kMargin + gMemoryTextWidth / 2 + menu->StringWidth(infos); loc.x -= kMargin + gMemoryTextWidth / 2 + menu->StringWidth(infos);
menu->DrawString(infos, loc); menu->DrawString(infos, loc);
snprintf(infos, sizeof(infos), string_for_size(fCommittedMemory * 1024.0, infos, sizeof(infos));
B_TRANSLATE("%.1f MiB"), fCommittedMemory / 1024.f);
loc.x = cadre.left - kMargin - menu->StringWidth(infos); loc.x = cadre.left - kMargin - menu->StringWidth(infos);
menu->DrawString(infos, loc); menu->DrawString(infos, loc);
fLastSum = sum; fLastSum = sum;
+16 -13
View File
@@ -1,20 +1,20 @@
/* /*
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
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version. version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details. Lesser General Public License for more details.
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
*/ */
@@ -26,6 +26,7 @@
#include <Bitmap.h> #include <Bitmap.h>
#include <Catalog.h> #include <Catalog.h>
#include <Roster.h> #include <Roster.h>
#include <StringForSize.h>
#include <Window.h> #include <Window.h>
#include <stdlib.h> #include <stdlib.h>
@@ -57,7 +58,9 @@ MemoryBarMenu::MemoryBarMenu(const char* name, info_pack* infos, system_info& sy
fTeamList[k++] = -1; fTeamList[k++] = -1;
} }
gMemoryTextWidth = 2 * StringWidth(B_TRANSLATE("99999 KiB")) + 20; char buffer[64];
string_for_size(99999999.9, buffer, sizeof(buffer));
gMemoryTextWidth = 2 * StringWidth(buffer) + 32;
fRecycleCount = EXTRA; fRecycleCount = EXTRA;
fRecycleList = (MRecycleItem*)malloc(sizeof(MRecycleItem) * fRecycleCount); fRecycleList = (MRecycleItem*)malloc(sizeof(MRecycleItem) * fRecycleCount);
@@ -1,20 +1,20 @@
/* /*
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
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version. version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details. Lesser General Public License for more details.
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
*/ */
@@ -26,6 +26,7 @@
#include <Bitmap.h> #include <Bitmap.h>
#include <Catalog.h> #include <Catalog.h>
#include <StringForSize.h>
#include <stdio.h> #include <stdio.h>
@@ -214,13 +215,13 @@ MemoryBarMenuItem::DrawBar(bool force)
menu->SetHighColor(kBlack); menu->SetHighColor(kBlack);
char infos[128]; char infos[128];
snprintf(infos, sizeof(infos), B_TRANSLATE("%d KiB"), fWriteMemory); string_for_size(fWriteMemory * 1024.0, infos, sizeof(infos));
BPoint loc(rect.left - kMargin - gMemoryTextWidth / 2 - menu->StringWidth(infos), BPoint loc(rect.left - kMargin - gMemoryTextWidth / 2 - menu->StringWidth(infos),
rect.bottom + 1); rect.bottom + 1);
menu->DrawString(infos, loc); menu->DrawString(infos, loc);
snprintf(infos, sizeof(infos), B_TRANSLATE("%d KiB"), fAllMemory); string_for_size(fAllMemory * 1024.0, infos, sizeof(infos));
loc.x = rect.left - kMargin - menu->StringWidth(infos); loc.x = rect.left - kMargin - menu->StringWidth(infos);
menu->DrawString(infos, loc); menu->DrawString(infos, loc);
} }