MediaPlayer SeekSlider: show playing time corresponding to mouse position
Fixes #8567. Change-Id: I03f06f1ac5014d718919280686970a3dbd6ae7dc Reviewed-on: https://review.haiku-os.org/c/haiku/+/8997 Reviewed-by: waddlesplash <[email protected]> Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
acb9747e38
commit
1725765ef7
@@ -700,6 +700,18 @@ Controller::TimePosition()
|
||||
}
|
||||
|
||||
|
||||
bigtime_t
|
||||
Controller::TimePositionFor(float value)
|
||||
{
|
||||
if (fDuration == 0)
|
||||
return 0;
|
||||
|
||||
int32 frame = std::max((int32)0,
|
||||
std::min((int32)_FrameDuration(), (int32)(_FrameDuration() * value)));
|
||||
return frame * fDuration / _FrameDuration();
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
Controller::SaveState(bool reset)
|
||||
{
|
||||
|
||||
@@ -104,6 +104,7 @@ public:
|
||||
|
||||
bigtime_t TimeDuration();
|
||||
bigtime_t TimePosition();
|
||||
bigtime_t TimePositionFor(float value);
|
||||
status_t SaveState(bool reset = false);
|
||||
void RestoreState();
|
||||
|
||||
|
||||
@@ -159,6 +159,14 @@ ControllerView::PositionChanged(float value)
|
||||
}
|
||||
|
||||
|
||||
bigtime_t
|
||||
ControllerView::TimePositionFor(float value)
|
||||
{
|
||||
// 0.0 ... 1.0
|
||||
return fController->TimePositionFor(value);
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ public:
|
||||
virtual void VolumeChanged(float value);
|
||||
virtual void ToggleMute();
|
||||
virtual void PositionChanged(float value);
|
||||
virtual bigtime_t TimePositionFor(float value);
|
||||
|
||||
private:
|
||||
void AttachedToWindow();
|
||||
|
||||
@@ -78,6 +78,13 @@ DurationView::MaxSize()
|
||||
}
|
||||
|
||||
|
||||
bigtime_t
|
||||
DurationView::TimeDuration()
|
||||
{
|
||||
return fDuration;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ public:
|
||||
virtual BSize MinSize();
|
||||
virtual BSize MaxSize();
|
||||
|
||||
bigtime_t TimeDuration();
|
||||
|
||||
// DurationView
|
||||
void Update(bigtime_t position, bigtime_t duration);
|
||||
|
||||
|
||||
@@ -17,11 +17,12 @@
|
||||
static const rgb_color kThumbRed = (rgb_color){ 255, 52, 52, 255 };
|
||||
|
||||
|
||||
SeekSlider::SeekSlider(const char* name, BMessage* message, int32 minValue,
|
||||
int32 maxValue)
|
||||
SeekSlider::SeekSlider(const char* name, BMessage* message, BMessage* hoverMessage,
|
||||
int32 minValue, int32 maxValue)
|
||||
:
|
||||
BSlider(name, NULL, NULL, minValue, maxValue, B_HORIZONTAL,
|
||||
B_TRIANGLE_THUMB),
|
||||
fHoverMessage(hoverMessage),
|
||||
fTracking(false),
|
||||
fLastTrackTime(0),
|
||||
fDisabledString(""),
|
||||
@@ -120,6 +121,17 @@ SeekSlider::MouseUp(BPoint where)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SeekSlider::MouseMoved(BPoint point, uint32 transit, const BMessage* dragMessage)
|
||||
{
|
||||
if (!IsTracking()) {
|
||||
fHoverMessage->SetInt32("value", ValueForPoint(point));
|
||||
Invoke(fHoverMessage);
|
||||
}
|
||||
BSlider::MouseMoved(point, transit, dragMessage);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SeekSlider::GetPreferredSize(float* _width, float* _height)
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
class SeekSlider : public BSlider {
|
||||
public:
|
||||
SeekSlider(const char* name, BMessage* message,
|
||||
int32 minValue, int32 maxValue);
|
||||
BMessage* hoverMessage, int32 minValue, int32 maxValue);
|
||||
|
||||
virtual ~SeekSlider();
|
||||
|
||||
@@ -24,6 +24,8 @@ public:
|
||||
virtual void DrawThumb();
|
||||
virtual void MouseDown(BPoint where);
|
||||
virtual void MouseUp(BPoint where);
|
||||
virtual void MouseMoved(BPoint point, uint32 transit,
|
||||
const BMessage* dragMessage);
|
||||
virtual void GetPreferredSize(float* _width,
|
||||
float* _height);
|
||||
virtual BSize MinSize();
|
||||
@@ -36,6 +38,8 @@ public:
|
||||
void SetSymbolScale(float scale);
|
||||
|
||||
private:
|
||||
BMessage* fHoverMessage;
|
||||
|
||||
bool fTracking;
|
||||
bigtime_t fLastTrackTime;
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
enum {
|
||||
MSG_SEEK = 'seek',
|
||||
MSG_SEEK_HOVER = 'hovr',
|
||||
MSG_PLAY = 'play',
|
||||
MSG_STOP = 'stop',
|
||||
MSG_REWIND = 'rwnd',
|
||||
@@ -39,7 +40,7 @@ enum {
|
||||
MSG_SKIP_FORWARD = 'skpf',
|
||||
MSG_SET_VOLUME = 'stvl',
|
||||
MSG_SET_MUTE = 'stmt',
|
||||
MSG_DURATION_TOOLTIP = 'msdt'
|
||||
MSG_DURATION_TOOLTIP = 'msdt',
|
||||
};
|
||||
|
||||
// the range of the volume sliders (in dB)
|
||||
@@ -83,7 +84,7 @@ TransportControlGroup::TransportControlGroup(BRect frame, bool useSkipButtons,
|
||||
|
||||
// Seek slider
|
||||
fSeekSlider = new SeekSlider("seek slider", new BMessage(MSG_SEEK),
|
||||
0, kPositionFactor);
|
||||
new BMessage(MSG_SEEK_HOVER), 0, kPositionFactor);
|
||||
fSeekLayout->AddView(fSeekSlider);
|
||||
|
||||
fPositionToolTip = new PositionToolTip();
|
||||
@@ -284,6 +285,16 @@ TransportControlGroup::MessageReceived(BMessage* message)
|
||||
break;
|
||||
}
|
||||
|
||||
case MSG_SEEK_HOVER:
|
||||
{
|
||||
int32 value;
|
||||
if (message->FindInt32("value", &value) == B_OK) {
|
||||
bigtime_t position = TimePositionFor(value / (float)kPositionFactor);
|
||||
fPositionToolTip->Update(position, fDurationView->TimeDuration());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
BView::MessageReceived(message);
|
||||
break;
|
||||
@@ -310,7 +321,7 @@ void TransportControlGroup::SkipForward() {}
|
||||
void TransportControlGroup::VolumeChanged(float value) {}
|
||||
void TransportControlGroup::ToggleMute() {}
|
||||
void TransportControlGroup::PositionChanged(float value) {}
|
||||
|
||||
bigtime_t TransportControlGroup::TimePositionFor(float value) { return 0; }
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
@@ -492,11 +503,12 @@ void
|
||||
TransportControlGroup::SetPosition(float value, bigtime_t position,
|
||||
bigtime_t duration)
|
||||
{
|
||||
fPositionToolTip->Update(position, duration);
|
||||
fDurationView->Update(position, duration);
|
||||
|
||||
if (fSeekSlider->IsTracking())
|
||||
if (fSeekSlider->IsTracking()) {
|
||||
fPositionToolTip->Update(position, duration);
|
||||
return;
|
||||
}
|
||||
|
||||
fSeekSlider->SetPosition(value);
|
||||
}
|
||||
|
||||
@@ -57,6 +57,7 @@ public:
|
||||
virtual void VolumeChanged(float value);
|
||||
virtual void ToggleMute();
|
||||
virtual void PositionChanged(float value);
|
||||
virtual bigtime_t TimePositionFor(float value);
|
||||
|
||||
void SetEnabled(uint32 whichButtons);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user