From a0922d371835240594d4bf93cdd4ee0b977dd8dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 11 Aug 2009 12:35:57 +0000 Subject: [PATCH] * Added a volume tool tip to Deskbar's volume replicant, thus closing ticket #3118. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32250 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/bin/desklink/Jamfile | 2 +- src/bin/desklink/MediaReplicant.cpp | 66 ++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/bin/desklink/Jamfile b/src/bin/desklink/Jamfile index ee3d7ff0ee..74bf55d059 100644 --- a/src/bin/desklink/Jamfile +++ b/src/bin/desklink/Jamfile @@ -2,7 +2,7 @@ SubDir HAIKU_TOP src bin desklink ; SetSubDirSupportedPlatformsBeOSCompatible ; -UsePrivateHeaders app ; +UsePrivateHeaders app interface shared ; BinCommand desklink : desklink.cpp diff --git a/src/bin/desklink/MediaReplicant.cpp b/src/bin/desklink/MediaReplicant.cpp index 03420a4b73..7e076a60f6 100644 --- a/src/bin/desklink/MediaReplicant.cpp +++ b/src/bin/desklink/MediaReplicant.cpp @@ -10,8 +10,10 @@ * Axel Dörfler, axeld@pinc-software.de. */ + //! Volume control, and media shortcuts in Deskbar + #include #include @@ -25,6 +27,10 @@ #include #include #include +#include + +#include +#include #include "desklink.h" #include "iconfile.h" @@ -44,6 +50,56 @@ static const char* kReplicantName = "MediaReplicant"; static const char* kSettingsFile = "x-vnd.Haiku-desklink"; +class VolumeToolTip : public BToolTip { +public: + VolumeToolTip(int32 which = VOLUME_USE_MIXER) + : + fWhich(which) + { + fView = new BStringView("", ""); + } + + virtual ~VolumeToolTip() + { + delete fView; + } + + virtual BView* View() const + { + return fView; + } + + virtual void AttachedToWindow() + { + Update(); + } + + void SetWhich(int32 which) + { + fWhich = which; + } + + void Update() + { + if (!Lock()) + return; + + MixerControl control; + control.Connect(fWhich); + + char text[256]; + snprintf(text, sizeof(text), "%g dB", control.Volume()); + fView->SetText(text); + + Unlock(); + } + +private: + BStringView* fView; + int32 fWhich; +}; + + class MediaReplicant : public BView { public: MediaReplicant(BRect frame, const char* name, @@ -263,6 +319,12 @@ MediaReplicant::MessageReceived(BMessage* message) MixerControl mixerControl; mixerControl.Connect(fVolumeWhich); mixerControl.ChangeVolumeBy(deltaY < 0 ? 6 : -6); + + VolumeToolTip* tip = dynamic_cast(ToolTip()); + if (tip != NULL) { + tip->Update(); + ShowToolTip(tip); + } } break; } @@ -387,7 +449,9 @@ MediaReplicant::_Init() { fIcon = new BBitmap(BRect(0, 0, kSpeakerWidth - 1, kSpeakerHeight - 1), B_CMAP8); - fIcon->SetBits(kSpeakerBits, kSpeakerWidth*kSpeakerHeight, 0, B_CMAP8); + fIcon->SetBits(kSpeakerBits, kSpeakerWidth * kSpeakerHeight, 0, B_CMAP8); + + SetToolTip(new VolumeToolTip()); _LoadSettings(); }