* cache the result of visiting the partitions

* make sure the colors are bright enough


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23294 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2008-01-09 00:30:24 +00:00
parent 5f50c05486
commit 789091541e
3 changed files with 21 additions and 20 deletions
+18 -18
View File
@@ -60,13 +60,13 @@ struct PartitionBox {
}; };
class PartitionDrawer : public BDiskDeviceVisitor { class DiskView::PartitionDrawer : public BDiskDeviceVisitor {
public: public:
PartitionDrawer(BView* view, partition_id selectedPartition) PartitionDrawer(BView* view)
: fView(view) : fView(view)
, fBoxMap() , fBoxMap()
, fColorIndex(0) , fColorIndex(0)
, fSelectedPartition(selectedPartition) , fSelectedPartition(-1)
{ {
} }
@@ -103,6 +103,11 @@ public:
return false; return false;
} }
void SetSelectedPartition(partition_id id)
{
fSelectedPartition = id;
}
void Draw(BView* view) void Draw(BView* view)
{ {
PartitionBoxMap::Iterator iterator = fBoxMap.GetIterator(); PartitionBoxMap::Iterator iterator = fBoxMap.GetIterator();
@@ -150,12 +155,12 @@ public:
DiskView::DiskView(const BRect& frame, uint32 resizeMode) DiskView::DiskView(const BRect& frame, uint32 resizeMode)
: Inherited(frame, "diskview", resizeMode, B_WILL_DRAW) : Inherited(frame, "diskview", resizeMode, B_WILL_DRAW)
, fDisk(NULL) , fDisk(NULL)
, fSelectedParition(-1) , fPartitionDrawer(new PartitionDrawer(this))
{ {
for (int32 i = 0; i < kMaxPartitionColors; i++) { for (int32 i = 0; i < kMaxPartitionColors; i++) {
kPartitionColors[i].red = (i * 1675) & 0xff; kPartitionColors[i].red = 120 + ((i * 1675) & 120);
kPartitionColors[i].green = (i * 318) & 0xff; kPartitionColors[i].green = 120 + ((i * 318) & 120);
kPartitionColors[i].blue = (i * 9328) & 0xff; kPartitionColors[i].blue = 120 + ((i * 9328) & 120);
kPartitionColors[i].alpha = 255; kPartitionColors[i].alpha = 255;
} }
} }
@@ -164,6 +169,7 @@ DiskView::DiskView(const BRect& frame, uint32 resizeMode)
DiskView::~DiskView() DiskView::~DiskView()
{ {
SetDisk(NULL, -1); SetDisk(NULL, -1);
delete fPartitionDrawer;
} }
@@ -179,25 +185,19 @@ DiskView::Draw(BRect updateRect)
return; return;
} }
// TODO: render the partitions (use PartitionDrawer to iterate our disk) fPartitionDrawer->Draw(this);
SetHighColor(255, 255, 120);
FillRect(bounds);
PartitionDrawer drawer(this, fSelectedParition);
BDiskDeviceRoster roster;
roster.VisitEachPartition(&drawer, fDisk);
drawer.Draw(this);
} }
void void
DiskView::SetDisk(BDiskDevice* disk, partition_id selectedPartition) DiskView::SetDisk(BDiskDevice* disk, partition_id selectedPartition)
{ {
printf("DiskView::SetDisk(%p, %ld)\n", disk, selectedPartition);
delete fDisk; delete fDisk;
fDisk = disk; fDisk = disk;
fSelectedParition = selectedPartition; fPartitionDrawer->SetSelectedPartition(selectedPartition);
BDiskDeviceRoster roster;
roster.VisitEachPartition(fPartitionDrawer, fDisk);
Invalidate(); Invalidate();
} }
+3 -1
View File
@@ -24,7 +24,9 @@ public:
partition_id selectedPartition); partition_id selectedPartition);
private: private:
BDiskDevice* fDisk; BDiskDevice* fDisk;
partition_id fSelectedParition;
class PartitionDrawer;
PartitionDrawer* fPartitionDrawer;
}; };
@@ -165,7 +165,6 @@ MainWindow::MessageReceived(BMessage* message)
break; break;
case MSG_PARTITION_ROW_SELECTED: case MSG_PARTITION_ROW_SELECTED:
printf("MSG_PARTITION_ROW_SELECTED\n");
_AdaptToSelectedPartition(); _AdaptToSelectedPartition();
break; break;