From bf02ce442e7cf5b1fcf3a164a8b70926c48d2c6e Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Sun, 5 Jun 2022 14:54:44 -0500 Subject: [PATCH] VolumeView: Fix unarchiving --- src/VolumeView.cpp | 36 +++++++++++++++++++----------------- src/VolumeView.h | 3 +-- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/VolumeView.cpp b/src/VolumeView.cpp index 9dfa5c7..856d19f 100644 --- a/src/VolumeView.cpp +++ b/src/VolumeView.cpp @@ -20,18 +20,10 @@ static const uint32 VOLUME_CHANGED = 'vvch'; VolumeView::VolumeView(BRect frame) : - ReplicantView(frame, "Volume", B_FOLLOW_RIGHT, B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW) + ReplicantView(frame, "Volume", B_FOLLOW_RIGHT, B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS) { - SetViewColor(B_TRANSPARENT_COLOR); - - fSlider = new BSlider(frame, "volumeSlider", NULL, NULL, 0, 1000, B_HORIZONTAL, B_BLOCK_THUMB, - B_FOLLOW_LEFT_RIGHT); - fSlider->SetModificationMessage(new BMessage(VOLUME_CHANGED)); - fSlider->UseFillColor(true, &kVolumeGreen); - fSlider->SetViewColor(B_TRANSPARENT_COLOR); - AddChild(fSlider); - - _Init(); + _InitInterface(); + Pulse(); } @@ -39,10 +31,12 @@ VolumeView::VolumeView(BMessage* data) : ReplicantView(data) { + // For some reason, the BSlider gets archived with a wacko frame― better to just nuke it. fSlider = dynamic_cast(FindView("volumeSlider")); - if (fSlider->IsHidden()) - fSlider->Show(); - _Init(); + delete fSlider; + + _InitInterface(); + Pulse(); } @@ -122,13 +116,21 @@ VolumeView::SetInactive(bool inactive) void -VolumeView::_Init() +VolumeView::_InitInterface() { + SetViewColor(B_TRANSPARENT_COLOR); + + fSlider = new BSlider(BRect(), "volumeSlider", NULL, NULL, 0, 1000, B_HORIZONTAL, B_BLOCK_THUMB, + B_FOLLOW_LEFT_RIGHT); + fSlider->SetModificationMessage(new BMessage(VOLUME_CHANGED)); + fSlider->UseFillColor(true, &kVolumeGreen); + fSlider->SetViewColor(B_TRANSPARENT_COLOR); + AddChild(fSlider); + float height = 20.0; fSlider->GetPreferredSize(NULL, &height); SetExplicitMaxSize(BSize(B_SIZE_UNSET, height + 16)); - - Pulse(); + fSlider->ResizeTo(Frame().Size()); } diff --git a/src/VolumeView.h b/src/VolumeView.h index 6dff927..231990e 100644 --- a/src/VolumeView.h +++ b/src/VolumeView.h @@ -26,8 +26,7 @@ public: virtual void SetInactive(bool inactive); private: - void _Init(); - + void _InitInterface(); float _VolumeToPosition(float volume); float _PositionToVolume(float position);