[gparted] Simplify main window partition usage graphic code
- From: Curtis Gedak <gedakc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gparted] Simplify main window partition usage graphic code
- Date: Tue, 26 Jun 2012 20:15:25 +0000 (UTC)
commit ac3ce5ec2bf5821734de411dc4f8b0c948902a1f
Author: Mike Fleetwood <mike fleetwood googlemail com>
Date: Thu Jun 21 19:29:36 2012 +0100
Simplify main window partition usage graphic code
Stop using fraction_unallocated and fraction_used member variables of
the DrawingAreaVisualDisk class as intermediate storage of partition
usage fractions. Instead get the figures straight from the partition
class and use the new calc_usage_triple() to directly set pixels widths
for the partition usage graphic.
include/DrawingAreaVisualDisk.h | 5 +--
src/DrawingAreaVisualDisk.cc | 61 ++++++++++++++-------------------------
2 files changed, 23 insertions(+), 43 deletions(-)
---
diff --git a/include/DrawingAreaVisualDisk.h b/include/DrawingAreaVisualDisk.h
index cdc9e19..a96bbed 100644
--- a/include/DrawingAreaVisualDisk.h
+++ b/include/DrawingAreaVisualDisk.h
@@ -73,9 +73,6 @@ private:
struct visual_partition
{
double fraction ; //Partition size as a fraction of containing disk or extended partition size
- double fraction_used ; //Used space as a fraction of partition size
- double fraction_unallocated ; //Unallocated space as a fraction of partition size
-
int x_start, length ;
int y_start, height ;
int x_used_start, used_length ;
@@ -94,7 +91,7 @@ private:
visual_partition()
{
- fraction = fraction_used = fraction_unallocated = 0.0 ;
+ fraction = 0.0 ;
x_start = length =
y_start = height =
x_used_start = used_length =
diff --git a/src/DrawingAreaVisualDisk.cc b/src/DrawingAreaVisualDisk.cc
index 75bd854..81d2a04 100644
--- a/src/DrawingAreaVisualDisk.cc
+++ b/src/DrawingAreaVisualDisk.cc
@@ -97,34 +97,6 @@ void DrawingAreaVisualDisk::set_static_data( const std::vector<Partition> & part
Sector partition_length = partitions[ t ] .get_sector_length() ;
visual_partitions .back() .fraction = partition_length / static_cast<double>( length ) ;
- if ( partitions[ t ] .type == GParted::TYPE_UNALLOCATED || partitions[ t ] .type == GParted::TYPE_EXTENDED )
- {
- //Don't calculate or draw partition used, unused or unallocated rectangles
- // to show usage. Only partition color rectangle will be drawn.
- visual_partitions .back() .fraction_unallocated = -1.0 ;
- visual_partitions .back() .fraction_used = -1.0 ;
- }
- else
- {
- //Use sum_sectors as the denominator to calculate fraction_used and
- // fraction_unallocated in case it doesn't equal partition_length.
- Sector used = partitions[ t ] .get_sectors_used() ;
- Sector unused = partitions[ t ] .get_sectors_unused() ;
- Sector unallocated = partitions[ t ] .get_sectors_unallocated() ;
- Sector sum_sectors = used + unused + unallocated ;
- if ( unallocated > 0 )
- visual_partitions .back() .fraction_unallocated =
- unallocated / static_cast<double>( sum_sectors ) ;
- else
- visual_partitions .back() .fraction_unallocated = 0.0 ;
-
- //Calculate fraction used from free space so any hidden overhead is counted as used
- if ( unused >= 0 )
- visual_partitions .back() .fraction_used =
- 1.0 - visual_partitions .back() .fraction_unallocated
- - unused / static_cast<double>( sum_sectors ) ;
- }
-
visual_partitions .back() .color = partitions[ t ] .color;
get_colormap() ->alloc_color( visual_partitions .back() .color );
@@ -181,17 +153,28 @@ void DrawingAreaVisualDisk::calc_usage( std::vector<visual_partition> & visual_p
{
for ( unsigned int t = 0 ; t < visual_partitions .size() ; t++ )
{
- if ( visual_partitions[ t ] .fraction_used >= 0.0 )
- {
-
- Partition::calc_usage_triple( visual_partitions[ t ] .fraction_used,
- 1.0 - visual_partitions[ t ] .fraction_used
- - visual_partitions[ t ] .fraction_unallocated,
- visual_partitions[ t ] .fraction_unallocated,
- visual_partitions[ t ] .length - BORDER *2,
- visual_partitions[ t ] .used_length,
- visual_partitions[ t ] .unused_length,
- visual_partitions[ t ] .unallocated_length ) ;
+ if ( visual_partitions[ t ] .partition .type != GParted::TYPE_UNALLOCATED &&
+ visual_partitions[ t ] .partition .type != GParted::TYPE_EXTENDED )
+ {
+ if ( visual_partitions[ t ] .partition .sector_usage_known() )
+ {
+ Partition::calc_usage_triple(
+ visual_partitions[ t ] .partition .get_sectors_used(),
+ visual_partitions[ t ] .partition .get_sectors_unused(),
+ visual_partitions[ t ] .partition .get_sectors_unallocated(),
+ visual_partitions[ t ] .length - BORDER *2,
+ visual_partitions[ t ] .used_length,
+ visual_partitions[ t ] .unused_length,
+ visual_partitions[ t ] .unallocated_length ) ;
+ }
+ else
+ {
+ //Specifically show unknown figures as unused
+ visual_partitions[ t ] .used_length = 0 ;
+ visual_partitions[ t ] .unused_length = visual_partitions[ t ] .length - BORDER *2 ;
+ visual_partitions[ t ] .unallocated_length = 0 ;
+ }
+
//used
visual_partitions[ t ] .x_used_start = visual_partitions[ t ] .x_start + BORDER ;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]