From 4dee702332abee23086dc0d26e79f014a27a3bb3 Mon Sep 17 00:00:00 2001 From: Diego Gangl Date: Fri, 25 May 2018 22:17:15 +0200 Subject: Add number and memory size formatting throughout the UI This commit adds number formatting (thousands separator) to the baking panel. It also adds a new function to format memory sizes (KB/GB/etc) and applies it to the baking panel and scene stats. The new function is unit tested. Reviewers: Severin Tags: #user_interface Differential Revision: https://developer.blender.org/D1248 --- source/blender/editors/space_info/info_stats.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'source/blender/editors/space_info') diff --git a/source/blender/editors/space_info/info_stats.c b/source/blender/editors/space_info/info_stats.c index 8dc6c4229b2..10b5eded8d4 100644 --- a/source/blender/editors/space_info/info_stats.c +++ b/source/blender/editors/space_info/info_stats.c @@ -384,6 +384,7 @@ static void stats_string(Scene *scene) uintptr_t mem_in_use, mmap_in_use; char memstr[MAX_INFO_MEM_LEN]; char gpumemstr[MAX_INFO_MEM_LEN] = ""; + char formatted_mem[15]; char *s; size_t ofs = 0; @@ -419,20 +420,25 @@ static void stats_string(Scene *scene) /* get memory statistics */ - ofs = BLI_snprintf(memstr, MAX_INFO_MEM_LEN, IFACE_(" | Mem:%.2fM"), - (double)((mem_in_use - mmap_in_use) >> 10) / 1024.0); - if (mmap_in_use) - BLI_snprintf(memstr + ofs, MAX_INFO_MEM_LEN - ofs, IFACE_(" (%.2fM)"), (double)((mmap_in_use) >> 10) / 1024.0); + BLI_str_format_byte_unit(formatted_mem, mem_in_use - mmap_in_use, true); + ofs = BLI_snprintf(memstr, MAX_INFO_MEM_LEN, IFACE_(" | Mem: %s"), formatted_mem); + + if (mmap_in_use) { + BLI_str_format_byte_unit(formatted_mem, mmap_in_use, true); + BLI_snprintf(memstr + ofs, MAX_INFO_MEM_LEN - ofs, IFACE_(" (%s)"), formatted_mem); + } if (GPU_mem_stats_supported()) { int gpu_free_mem, gpu_tot_memory; GPU_mem_stats_get(&gpu_tot_memory, &gpu_free_mem); - ofs = BLI_snprintf(gpumemstr, MAX_INFO_MEM_LEN, IFACE_(" | Free GPU Mem:%.2fM"), (double)((gpu_free_mem)) / 1024.0); + BLI_str_format_byte_unit(formatted_mem, gpu_free_mem, true); + ofs = BLI_snprintf(gpumemstr, MAX_INFO_MEM_LEN, IFACE_(" | Free GPU Mem: %s"), formatted_mem); if (gpu_tot_memory) { - BLI_snprintf(gpumemstr + ofs, MAX_INFO_MEM_LEN - ofs, IFACE_("/%.2fM"), (double)((gpu_tot_memory)) / 1024.0); + BLI_str_format_byte_unit(formatted_mem, gpu_tot_memory, true); + BLI_snprintf(gpumemstr + ofs, MAX_INFO_MEM_LEN - ofs, IFACE_("/%s"), formatted_mem); } } -- cgit v1.2.3