Moved get_pretty_memsize (core.h) to get_pretty_memory_size (mem_utils.h).

This commit is contained in:
David Capello 2010-07-16 16:05:56 -03:00
parent 81fcdb53a3
commit a82d721913
7 changed files with 71 additions and 25 deletions

View File

@ -12,6 +12,7 @@ COMMON_SOURCES = \
src/context.cpp \
src/gfxmode.cpp \
src/launcher.cpp \
src/mem_utils.cpp \
src/recent_files.cpp \
src/ui_context.cpp \
src/undoable.cpp \

View File

@ -22,10 +22,9 @@
#include "jinete/jinete.h"
#include "commands/command.h"
#include "sprite_wrappers.h"
#include "app.h"
#include "core/core.h"
#include "commands/command.h"
#include "mem_utils.h"
#include "modules/gui.h"
#include "raster/cel.h"
#include "raster/image.h"
@ -33,6 +32,7 @@
#include "raster/sprite.h"
#include "raster/stock.h"
#include "raster/undo.h"
#include "sprite_wrappers.h"
class CelPropertiesCommand : public Command
{
@ -108,9 +108,9 @@ void CelPropertiesCommand::execute(Context* context)
usprintf(buf, "%dx%d (",
sprite->getStock()->image[cel->image]->w,
sprite->getStock()->image[cel->image]->h);
get_pretty_memsize(memsize,
buf+ustrsize(buf),
sizeof(buf)-ustrsize(buf));
get_pretty_memory_size(memsize,
buf+ustrsize(buf),
sizeof(buf)-ustrsize(buf));
ustrcat(buf, ")");
label_size->setText(buf);

View File

@ -23,14 +23,14 @@
#include "jinete/jinete.h"
#include "commands/command.h"
#include "core/core.h"
#include "core/color.h"
#include "mem_utils.h"
#include "modules/gui.h"
#include "raster/image.h"
#include "raster/sprite.h"
#include "raster/palette.h"
#include "widgets/colbut.h"
#include "raster/sprite.h"
#include "sprite_wrappers.h"
#include "widgets/colbut.h"
/* TODO remove this */
void dialogs_frame_length(const SpriteReader& sprite, int sprite_frpos);
@ -106,9 +106,9 @@ void SpritePropertiesCommand::execute(Context* context)
/* sprite size (width and height) */
usprintf(buf, "%dx%d (", sprite->getWidth(), sprite->getHeight());
get_pretty_memsize(sprite->getMemSize(),
buf+ustrsize(buf),
sizeof(buf)-ustrsize(buf));
get_pretty_memory_size(sprite->getMemSize(),
buf+ustrsize(buf),
sizeof(buf)-ustrsize(buf));
ustrcat(buf, ")");
size->setText(buf);

View File

@ -118,18 +118,6 @@ bool is_interactive()
return ase_mode & MODE_GUI ? true: false;
}
char *get_pretty_memsize(unsigned int memsize, char *buf, unsigned int bufsize)
{
if (memsize < 1000)
uszprintf(buf, bufsize, "%d bytes", memsize);
else if (memsize < 1000*1000)
uszprintf(buf, bufsize, "%0.1fK", memsize/1024.0f);
else
uszprintf(buf, bufsize, "%0.1fM", memsize/(1024.0f*1024.0f));
return buf;
}
/**
* Like 'strerror' but thread-safe.
*

View File

@ -39,7 +39,6 @@ public:
void verbose_printf(const char *format, ...);
bool is_interactive();
char *get_pretty_memsize(unsigned int memsize, char *buf, unsigned int bufsize);
char *get_errno_string(int errnum, char *buf, int size);
#endif

33
src/mem_utils.cpp Normal file
View File

@ -0,0 +1,33 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2010 David Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "config.h"
#include <allegro/unicode.h>
char *get_pretty_memory_size(unsigned int memsize, char *buf, unsigned int bufsize)
{
if (memsize < 1000)
uszprintf(buf, bufsize, "%d bytes", memsize);
else if (memsize < 1000*1000)
uszprintf(buf, bufsize, "%0.1fK", memsize/1024.0f);
else
uszprintf(buf, bufsize, "%0.1fM", memsize/(1024.0f*1024.0f));
return buf;
}

25
src/mem_utils.h Normal file
View File

@ -0,0 +1,25 @@
/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2010 David Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef MEM_UTILS_H_INCLUDED
#define MEM_UTILS_H_INCLUDED
char* get_pretty_memory_size(unsigned int memsize, char* buf, unsigned int bufsize);
#endif