[haiku-commits] haiku: hrev45233 - src/apps/drivesetup headers/os/interface src/kits/interface

  • From: axeld@xxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 5 Feb 2013 00:25:10 +0100 (CET)

hrev45233 adds 4 changesets to branch 'master'
old head: cf0ea4fbba83aad60e13d8a421f3097f8da178b5
new head: 0a7975bfede13ecd4fbccf52d039099939b25eed
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=0a7975b+%5Ecf0ea4f

----------------------------------------------------------------------------

7ff0829: Minor style cleanup.

0d7d495: DriveSetup: improved size slider.
  
  * It uses size_for_string() to display all sizes which also fixes
    using MiB for one, and MB for the other size string.
  * It is no longer limited to 1M granularity by itself, but can have
    arbitrary granularity as long as the number of possible values
    remain smaller than 2^31.
  * This means it can also handle values beyond 4TB now.
  * The sizes that are set programmatically retain their full resolution.
  * CreateParametersPanel still uses 1M granularity for now, though,
    as we would otherwise need to be able to parse a size string with
    a unit.

0b319bd: Minor cleanup.

0a7975b: BSlider::SetPosition() now calls BSlider's SetValue().
  
  * Before it directly called the BControl version which doesn't really
    make any sense, and prevented visual updates.

                                   [ Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

7 files changed, 102 insertions(+), 59 deletions(-)
headers/os/interface/Slider.h                 | 14 ++--
src/apps/drivesetup/CreateParametersPanel.cpp | 22 +++---
src/apps/drivesetup/DiskView.cpp              |  4 +-
src/apps/drivesetup/MainWindow.cpp            |  4 +-
src/apps/drivesetup/Support.cpp               | 85 ++++++++++++++++-------
src/apps/drivesetup/Support.h                 | 22 +++---
src/kits/interface/Slider.cpp                 | 10 +--

############################################################################

Commit:      7ff0829758df3b277368ac294eed4ce89f52fd65
URL:         http://cgit.haiku-os.org/haiku/commit/?id=7ff0829
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Mon Feb  4 22:52:32 2013 UTC

Minor style cleanup.

----------------------------------------------------------------------------

diff --git a/src/apps/drivesetup/DiskView.cpp b/src/apps/drivesetup/DiskView.cpp
index 02e8872..8980cfe 100644
--- a/src/apps/drivesetup/DiskView.cpp
+++ b/src/apps/drivesetup/DiskView.cpp
@@ -287,8 +287,8 @@ public:
                        off_t offset;
                        off_t size;
                        for (int32 i = 0;
-                               info.GetPartitionableSpaceAt(i, &offset, &size) 
>= B_OK;
-                               i++) {
+                                       info.GetPartitionableSpaceAt(i, 
&offset, &size) >= B_OK;
+                                       i++) {
                                // TODO: remove again once Disk Device API is 
fixed
                                if (!is_valid_partitionable_space(size))
                                        continue;
diff --git a/src/apps/drivesetup/MainWindow.cpp 
b/src/apps/drivesetup/MainWindow.cpp
index 6376e88..346a885 100644
--- a/src/apps/drivesetup/MainWindow.cpp
+++ b/src/apps/drivesetup/MainWindow.cpp
@@ -102,8 +102,8 @@ private:
                        off_t offset;
                        off_t size;
                        for (int32 i = 0;
-                               info.GetPartitionableSpaceAt(i, &offset, &size) 
>= B_OK;
-                               i++) {
+                                       info.GetPartitionableSpaceAt(i, 
&offset, &size) >= B_OK;
+                                       i++) {
                                // TODO: remove again once Disk Device API is 
fixed
                                if (!is_valid_partitionable_space(size))
                                        continue;

############################################################################

Commit:      0d7d4957aa66aa619207df0807c1085c0b02c17f
URL:         http://cgit.haiku-os.org/haiku/commit/?id=0d7d495
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Mon Feb  4 22:54:49 2013 UTC

DriveSetup: improved size slider.

* It uses size_for_string() to display all sizes which also fixes
  using MiB for one, and MB for the other size string.
* It is no longer limited to 1M granularity by itself, but can have
  arbitrary granularity as long as the number of possible values
  remain smaller than 2^31.
* This means it can also handle values beyond 4TB now.
* The sizes that are set programmatically retain their full resolution.
* CreateParametersPanel still uses 1M granularity for now, though,
  as we would otherwise need to be able to parse a size string with
  a unit.

----------------------------------------------------------------------------

diff --git a/src/apps/drivesetup/CreateParametersPanel.cpp 
b/src/apps/drivesetup/CreateParametersPanel.cpp
index e25a569..44baa33 100644
--- a/src/apps/drivesetup/CreateParametersPanel.cpp
+++ b/src/apps/drivesetup/CreateParametersPanel.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright 2008-2013 Haiku Inc. All rights reserved.
+ * Copyright 2008-2013 Haiku, Inc. All rights reserved.
  * Distributed under the terms of the MIT license.
  *
  * Authors:
@@ -37,16 +37,14 @@ enum {
        MSG_SIZE_TEXTCONTROL            = 'stct'
 };
 
+static const uint32 kMegaByte = 0x100000;
+
 
 CreateParametersPanel::CreateParametersPanel(BWindow* window,
        BPartition* partition, off_t offset, off_t size)
        :
        AbstractParametersPanel(window)
 {
-       // Scale offset, and size from bytes to megabytes (2^20)
-       // so that we do not run over a signed int32.
-       offset /= kMegaByte;
-       size /= kMegaByte;
        _CreateViewControls(partition, offset, size);
 
        Init(B_CREATE_PARAMETER_EDITOR, "", partition);
@@ -65,8 +63,8 @@ CreateParametersPanel::Go(off_t& offset, off_t& size, 
BString& name,
        // The object will be deleted in Go(), so we need to get the values 
before
 
        // Return the value back as bytes.
-       size = (off_t)fSizeSlider->Size() * kMegaByte;
-       offset = (off_t)fSizeSlider->Offset() * kMegaByte;
+       size = fSizeSlider->Size();
+       offset = fSizeSlider->Offset();
 
        // get name
        name.SetTo(fNameTextControl->Text());
@@ -102,9 +100,9 @@ CreateParametersPanel::MessageReceived(BMessage* message)
 
                case MSG_SIZE_TEXTCONTROL:
                {
-                       int32 size = atoi(fSizeTextControl->Text());
+                       off_t size = atoi(fSizeTextControl->Text()) * kMegaByte;
                        if (size >= 0 && size <= 
fSizeSlider->MaxPartitionSize())
-                               fSizeSlider->SetValue(size + 
fSizeSlider->Offset());
+                               fSizeSlider->SetSize(size);
                        else
                                _UpdateSizeTextControl();
                        break;
@@ -147,8 +145,10 @@ CreateParametersPanel::_CreateViewControls(BPartition* 
parent, off_t offset,
        off_t size)
 {
        // Setup the controls
+       // TODO: use a lower granularity for smaller disks -- but this would
+       // require being able to parse arbitrary size strings with unit
        fSizeSlider = new SizeSlider("Slider", B_TRANSLATE("Partition size"), 
NULL,
-               offset, offset + size);
+               offset, size, kMegaByte);
        fSizeSlider->SetPosition(1.0);
        fSizeSlider->SetModificationMessage(new BMessage(MSG_SIZE_SLIDER));
 
@@ -191,6 +191,6 @@ void
 CreateParametersPanel::_UpdateSizeTextControl()
 {
        BString sizeString;
-       sizeString << fSizeSlider->Value() - fSizeSlider->Offset();
+       sizeString << fSizeSlider->Size() / kMegaByte;
        fSizeTextControl->SetText(sizeString.String());
 }
diff --git a/src/apps/drivesetup/Support.cpp b/src/apps/drivesetup/Support.cpp
index e33c445..5de07d6 100644
--- a/src/apps/drivesetup/Support.cpp
+++ b/src/apps/drivesetup/Support.cpp
@@ -1,12 +1,13 @@
 /*
- * Copyright 2002-2012 Haiku Inc. All rights reserved.
+ * Copyright 2002-2013 Haiku, Inc. All rights reserved.
  * Distributed under the terms of the MIT license.
  *
  * Authors:
- *             Erik Jaesler <ejakowatz@xxxxxxxxxxxxxxxxxxxxx>
  *             Ithamar R. Adema <ithamar@xxxxxxx>
  *             Stephan Aßmus <superstippi@xxxxxx>
+ *             Axel Dörfler, axeld@xxxxxxxxxxxxxxxx.
  *             Bryce Groff <bgroff@xxxxxxxxxx>
+ *             Erik Jaesler <ejakowatz@xxxxxxxxxxxxxxxxxxxxx>
  */
 
 
@@ -24,6 +25,10 @@
 #define B_TRANSLATION_CONTEXT "Support"
 
 
+static const int32 kMaxSliderLimit = 0x7fffff80;
+       // this is the maximum value that BSlider seem to work with fine
+
+
 void
 dump_partition_info(const BPartition* partition)
 {
@@ -94,23 +99,36 @@ SpaceIDMap::SpaceIDFor(partition_id parentID, off_t 
spaceOffset)
 }
 
 
+// #pragma mark -
+
+
 SizeSlider::SizeSlider(const char* name, const char* label,
-               BMessage* message, int32 minValue, int32 maxValue)
+               BMessage* message, off_t offset, off_t size, uint32 
minGranularity)
        :
-       BSlider(name, label, message, minValue, maxValue,
-       B_HORIZONTAL, B_TRIANGLE_THUMB),
-       fStartOffset(minValue),
-       fEndOffset(maxValue),
-       fMaxPartitionSize(maxValue - minValue)
+       BSlider(name, label, message, 0, kMaxSliderLimit, B_HORIZONTAL,
+               B_TRIANGLE_THUMB),
+       fStartOffset(offset),
+       fEndOffset(offset + size),
+       fMaxPartitionSize(size),
+       fGranularity(minGranularity)
 {
        rgb_color fillColor = ui_color(B_CONTROL_HIGHLIGHT_COLOR);
        UseFillColor(true, &fillColor);
+
+       // Lazy loop to get a power of two granularity
+       while (size / fGranularity > kMaxSliderLimit)
+               fGranularity *= 2;
+
+       SetKeyIncrementValue(int32(1024 * 1024 * 1.0 * kMaxSliderLimit
+               / ((MaxPartitionSize() - 1) / fGranularity) + 0.5));
+
+       char buffer[64];
        char minString[64];
        char maxString[64];
-       snprintf(minString, sizeof(minString), B_TRANSLATE("Offset: %ld MB"),
-               fStartOffset);
-       snprintf(maxString, sizeof(maxString), B_TRANSLATE("End: %ld MB"),
-               fEndOffset);
+       snprintf(minString, sizeof(minString), B_TRANSLATE("Offset: %s"),
+               string_for_size(fStartOffset, buffer, sizeof(buffer)));
+       snprintf(maxString, sizeof(maxString), B_TRANSLATE("End: %s"),
+               string_for_size(fEndOffset, buffer, sizeof(buffer)));
        SetLimitLabels(minString, maxString);
 }
 
@@ -120,35 +138,54 @@ SizeSlider::~SizeSlider()
 }
 
 
+void
+SizeSlider::SetValue(int32 value)
+{
+       BSlider::SetValue(value);
+
+       fSize = (off_t(1.0 * (MaxPartitionSize() - 1) * Value()
+               / kMaxSliderLimit + 0.5) / fGranularity) * fGranularity;
+}
+
+
 const char*
 SizeSlider::UpdateText() const
 {
-       // TODO: Perhaps replace with string_for_size, but it looks like
-       // Value() and fStartOffset are always in MiB.
-       snprintf(fStatusLabel, sizeof(fStatusLabel), B_TRANSLATE("%ld MiB"),
-               Value() - fStartOffset);
+       return string_for_size(Size(), fStatusLabel, sizeof(fStatusLabel));
+}
 
-       return fStatusLabel;
+
+off_t
+SizeSlider::Size() const
+{
+       return fSize;
 }
 
 
-int32
-SizeSlider::Size()
+void
+SizeSlider::SetSize(off_t size)
 {
-       return Value() - fStartOffset;
+       if (size == fSize)
+               return;
+
+       SetValue(int32(1.0 * kMaxSliderLimit / fGranularity * size
+               / ((MaxPartitionSize() - 1) / fGranularity) + 0.5));
+       fSize = size;
+       UpdateTextChanged();
 }
 
 
-int32
-SizeSlider::Offset()
+off_t
+SizeSlider::Offset() const
 {
        // TODO: This should be the changed offset once a double
        // headed slider is implemented.
        return fStartOffset;
 }
 
-int32
-SizeSlider::MaxPartitionSize()
+
+off_t
+SizeSlider::MaxPartitionSize() const
 {
        return fMaxPartitionSize;
 }
diff --git a/src/apps/drivesetup/Support.h b/src/apps/drivesetup/Support.h
index b7540c6..10b8e78 100644
--- a/src/apps/drivesetup/Support.h
+++ b/src/apps/drivesetup/Support.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2002-2007 Haiku Inc. All rights reserved.
+ * Copyright 2002-2013 Haiku, Inc. All rights reserved.
  * Distributed under the terms of the MIT license.
  */
 #ifndef SUPPORT_H
@@ -22,8 +22,6 @@ void dump_partition_info(const BPartition* partition);
 bool is_valid_partitionable_space(size_t size);
 
 
-static const uint32 kMegaByte = 0x100000;
-
 class SpaceIDMap : public HashMap<HashString, partition_id> {
 public:
                                                                SpaceIDMap();
@@ -36,23 +34,31 @@ private:
                        partition_id            fNextSpaceID;
 };
 
+
 class SizeSlider : public BSlider {
 public:
                                                                
SizeSlider(const char* name, const char* label,
-                                                               BMessage* 
message, int32 minValue,
-                                                               int32 maxValue);
+                                                                       
BMessage* message, off_t offset,
+                                                                       off_t 
size, uint32 minGranularity);
        virtual                                         ~SizeSlider();
 
+       virtual void                            SetValue(int32);
        virtual const char*                     UpdateText() const;
-                       int32                           Size();
-                       int32                           Offset();
-                       int32                           MaxPartitionSize();
+
+                       off_t                           Size() const;
+                       void                            SetSize(off_t size);
+
+                       off_t                           Offset() const;
+                       off_t                           MaxPartitionSize() 
const;
 
 private:
                        off_t                           fStartOffset;
                        off_t                           fEndOffset;
+                       off_t                           fSize;
                        off_t                           fMaxPartitionSize;
+                       uint32                          fGranularity;
        mutable char                            fStatusLabel[64];
 };
 
+
 #endif // SUPPORT_H

############################################################################

Commit:      0b319bd6f367608dec51a1e02ac63b8abc17b2f0
URL:         http://cgit.haiku-os.org/haiku/commit/?id=0b319bd
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Mon Feb  4 23:22:52 2013 UTC

Minor cleanup.

----------------------------------------------------------------------------

diff --git a/headers/os/interface/Slider.h b/headers/os/interface/Slider.h
index 7244407..8b76dfa 100644
--- a/headers/os/interface/Slider.h
+++ b/headers/os/interface/Slider.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001-2009, Haiku, Inc. All rights reserved.
+ * Copyright 2001-2013, Haiku, Inc. All rights reserved.
  * Distributed under the terms of the MIT License.
  */
 #ifndef _SLIDER_H
@@ -82,15 +82,14 @@ public:
                                                                        const 
char* maxLabel);
                        const char*                     MinLimitLabel() const;
                        const char*                     MaxLimitLabel() const;
-       virtual void                            SetValue(int32);
-       virtual int32                           ValueForPoint(BPoint) const;
+       virtual void                            SetValue(int32 value);
+       virtual int32                           ValueForPoint(BPoint point) 
const;
        virtual void                            SetPosition(float);
                        float                           Position() const;
        virtual void                            SetEnabled(bool on);
-                       void                            GetLimits(int32* 
minimum,
-                                                                       int32* 
maximum) const;
+                       void                            GetLimits(int32* 
minimum, int32* maximum) const;
 
-       virtual void                            Draw(BRect);
+       virtual void                            Draw(BRect updateRect);
        virtual void                            DrawSlider();
        virtual void                            DrawBar();
        virtual void                            DrawHashMarks();
@@ -120,7 +119,7 @@ public:
        virtual void                            
SetModificationMessage(BMessage* message);
                        BMessage*                       ModificationMessage() 
const;
 
-       virtual void                            SetSnoozeAmount(int32);
+       virtual void                            SetSnoozeAmount(int32 
microSeconds);
                        int32                           SnoozeAmount() const;
 
        virtual void                            SetKeyIncrementValue(int32 
value);
@@ -229,4 +228,5 @@ private:
                        uint32                          _reserved[4];
 };
 
+
 #endif // _SLIDER_H

############################################################################

Revision:    hrev45233
Commit:      0a7975bfede13ecd4fbccf52d039099939b25eed
URL:         http://cgit.haiku-os.org/haiku/commit/?id=0a7975b
Author:      Axel Dörfler <axeld@xxxxxxxxxxxxxxxx>
Date:        Mon Feb  4 23:23:10 2013 UTC

BSlider::SetPosition() now calls BSlider's SetValue().

* Before it directly called the BControl version which doesn't really
  make any sense, and prevented visual updates.

----------------------------------------------------------------------------

diff --git a/src/kits/interface/Slider.cpp b/src/kits/interface/Slider.cpp
index a91b973..6d654d8 100644
--- a/src/kits/interface/Slider.cpp
+++ b/src/kits/interface/Slider.cpp
@@ -1,11 +1,11 @@
 /*
- * Copyright 2001-2009, Haiku.
+ * Copyright 2001-2013 Haiku, Inc.
  * Distributed under the terms of the MIT License.
  *
  * Authors:
- *             Marc Flerackers (mflerackers@xxxxxxxxxx)
  *             Stephan Aßmus <superstippi@xxxxxx>
  *             Axel Dörfler, axeld@xxxxxxxxxxxxxxxx
+ *             Marc Flerackers (mflerackers@xxxxxxxxxx)
  */
 
 
@@ -758,11 +758,11 @@ void
 BSlider::SetPosition(float position)
 {
        if (position <= 0.0f)
-               BControl::SetValue(fMinValue);
+               SetValue(fMinValue);
        else if (position >= 1.0f)
-               BControl::SetValue(fMaxValue);
+               SetValue(fMaxValue);
        else
-               BControl::SetValue((int32)(position * (fMaxValue - fMinValue) + 
fMinValue));
+               SetValue((int32)(position * (fMaxValue - fMinValue) + 
fMinValue));
 }
 
 


Other related posts:

  • » [haiku-commits] haiku: hrev45233 - src/apps/drivesetup headers/os/interface src/kits/interface - axeld