Add number and memory size formatting throughout the UI
[blender.git] / source / blender / editors / space_info / info_stats.c
index 8dc6c4229b24cb453029bb3762e09300121f800f..10b5eded8d4dc629f79926289eebeeab491b1544 100644 (file)
@@ -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);
                }
        }