MediaPlayer: Improvements to time tooltip.

* Make PositionToolTip update even when not attached to a window.

 * Always use the "hover" message to update the tooltip,
   never SetPosition.

 * Use BControl::Invoke so that hover messages are sent instantly.

 * Position the tooltip above the slider always.

Combined with the fixes to the Interface Kit, this provides a much
nicer experience for slider time tooltips.


Change-Id: Ib7f884ca91c253ed7e6639946fd2378166137d80
Reviewed-on: https://review.haiku-os.org/c/haiku/+/9122
Haiku-Format: Haiku-format Bot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Augustin Cavalier
2025-03-14 17:50:43 +00:00
committed by waddlesplash
parent 1725765ef7
commit c97ebaf1c7
3 changed files with 14 additions and 15 deletions
@@ -8,6 +8,7 @@
#include <stdio.h>
#include <Autolock.h>
#include <StringView.h>
#include "DurationToString.h"
@@ -36,16 +37,15 @@ public:
void Update(bigtime_t position, bigtime_t duration)
{
if (!LockLooper())
BAutolock locker(Looper());
if (Looper() != NULL && !locker.IsLocked())
return;
if (position != -1) {
position /= 1000000L;
duration /= 1000000L;
if (position == fPosition && duration == fDuration) {
UnlockLooper();
if (position == fPosition && duration == fDuration)
return;
}
fPosition = position;
fDuration = duration;
@@ -60,8 +60,6 @@ public:
char text[66];
snprintf(text, sizeof(text), "%s / %s", positionText, durationText);
SetText(text);
UnlockLooper();
}
private:
@@ -124,9 +124,9 @@ SeekSlider::MouseUp(BPoint where)
void
SeekSlider::MouseMoved(BPoint point, uint32 transit, const BMessage* dragMessage)
{
if (!IsTracking()) {
if (fHoverMessage != NULL) {
fHoverMessage->SetInt32("value", ValueForPoint(point));
Invoke(fHoverMessage);
BControl::Invoke(fHoverMessage);
}
BSlider::MouseMoved(point, transit, dragMessage);
}
@@ -88,6 +88,8 @@ TransportControlGroup::TransportControlGroup(BRect frame, bool useSkipButtons,
fSeekLayout->AddView(fSeekSlider);
fPositionToolTip = new PositionToolTip();
fPositionToolTip->SetAlignment(BAlignment(B_ALIGN_CENTER, B_ALIGN_TOP));
fPositionToolTip->SetMouseRelativeLocation(BPoint(0, 0));
fSeekSlider->SetToolTip(fPositionToolTip);
// Duration view
@@ -278,10 +280,11 @@ TransportControlGroup::MessageReceived(BMessage* message)
case MSG_DURATION_TOOLTIP:
{
BToolTipManager* manager = BToolTipManager::Manager();
BPoint tipPoint;
GetMouse(&tipPoint, NULL, false);
manager->ShowTip(fPositionToolTip, tipPoint, this);
fSeekSlider->GetMouse(&tipPoint, NULL, false);
tipPoint.y = 0;
fSeekSlider->ConvertToScreen(&tipPoint);
BToolTipManager::Manager()->ShowTip(fPositionToolTip, tipPoint, this);
break;
}
@@ -291,6 +294,7 @@ TransportControlGroup::MessageReceived(BMessage* message)
if (message->FindInt32("value", &value) == B_OK) {
bigtime_t position = TimePositionFor(value / (float)kPositionFactor);
fPositionToolTip->Update(position, fDurationView->TimeDuration());
Looper()->PostMessage(MSG_DURATION_TOOLTIP, this);
}
break;
}
@@ -505,11 +509,8 @@ TransportControlGroup::SetPosition(float value, bigtime_t position,
{
fDurationView->Update(position, duration);
if (fSeekSlider->IsTracking()) {
fPositionToolTip->Update(position, duration);
if (fSeekSlider->IsTracking())
return;
}
fSeekSlider->SetPosition(value);
}