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
|
status_t
|
||||||
Controller::SaveState(bool reset)
|
Controller::SaveState(bool reset)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ public:
|
|||||||
|
|
||||||
bigtime_t TimeDuration();
|
bigtime_t TimeDuration();
|
||||||
bigtime_t TimePosition();
|
bigtime_t TimePosition();
|
||||||
|
bigtime_t TimePositionFor(float value);
|
||||||
status_t SaveState(bool reset = false);
|
status_t SaveState(bool reset = false);
|
||||||
void RestoreState();
|
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 -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ public:
|
|||||||
virtual void VolumeChanged(float value);
|
virtual void VolumeChanged(float value);
|
||||||
virtual void ToggleMute();
|
virtual void ToggleMute();
|
||||||
virtual void PositionChanged(float value);
|
virtual void PositionChanged(float value);
|
||||||
|
virtual bigtime_t TimePositionFor(float value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void AttachedToWindow();
|
void AttachedToWindow();
|
||||||
|
|||||||
@@ -78,6 +78,13 @@ DurationView::MaxSize()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bigtime_t
|
||||||
|
DurationView::TimeDuration()
|
||||||
|
{
|
||||||
|
return fDuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ public:
|
|||||||
virtual BSize MinSize();
|
virtual BSize MinSize();
|
||||||
virtual BSize MaxSize();
|
virtual BSize MaxSize();
|
||||||
|
|
||||||
|
bigtime_t TimeDuration();
|
||||||
|
|
||||||
// DurationView
|
// DurationView
|
||||||
void Update(bigtime_t position, bigtime_t duration);
|
void Update(bigtime_t position, bigtime_t duration);
|
||||||
|
|
||||||
|
|||||||
@@ -17,11 +17,12 @@
|
|||||||
static const rgb_color kThumbRed = (rgb_color){ 255, 52, 52, 255 };
|
static const rgb_color kThumbRed = (rgb_color){ 255, 52, 52, 255 };
|
||||||
|
|
||||||
|
|
||||||
SeekSlider::SeekSlider(const char* name, BMessage* message, int32 minValue,
|
SeekSlider::SeekSlider(const char* name, BMessage* message, BMessage* hoverMessage,
|
||||||
int32 maxValue)
|
int32 minValue, int32 maxValue)
|
||||||
:
|
:
|
||||||
BSlider(name, NULL, NULL, minValue, maxValue, B_HORIZONTAL,
|
BSlider(name, NULL, NULL, minValue, maxValue, B_HORIZONTAL,
|
||||||
B_TRIANGLE_THUMB),
|
B_TRIANGLE_THUMB),
|
||||||
|
fHoverMessage(hoverMessage),
|
||||||
fTracking(false),
|
fTracking(false),
|
||||||
fLastTrackTime(0),
|
fLastTrackTime(0),
|
||||||
fDisabledString(""),
|
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
|
void
|
||||||
SeekSlider::GetPreferredSize(float* _width, float* _height)
|
SeekSlider::GetPreferredSize(float* _width, float* _height)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
class SeekSlider : public BSlider {
|
class SeekSlider : public BSlider {
|
||||||
public:
|
public:
|
||||||
SeekSlider(const char* name, BMessage* message,
|
SeekSlider(const char* name, BMessage* message,
|
||||||
int32 minValue, int32 maxValue);
|
BMessage* hoverMessage, int32 minValue, int32 maxValue);
|
||||||
|
|
||||||
virtual ~SeekSlider();
|
virtual ~SeekSlider();
|
||||||
|
|
||||||
@@ -24,6 +24,8 @@ public:
|
|||||||
virtual void DrawThumb();
|
virtual void DrawThumb();
|
||||||
virtual void MouseDown(BPoint where);
|
virtual void MouseDown(BPoint where);
|
||||||
virtual void MouseUp(BPoint where);
|
virtual void MouseUp(BPoint where);
|
||||||
|
virtual void MouseMoved(BPoint point, uint32 transit,
|
||||||
|
const BMessage* dragMessage);
|
||||||
virtual void GetPreferredSize(float* _width,
|
virtual void GetPreferredSize(float* _width,
|
||||||
float* _height);
|
float* _height);
|
||||||
virtual BSize MinSize();
|
virtual BSize MinSize();
|
||||||
@@ -36,6 +38,8 @@ public:
|
|||||||
void SetSymbolScale(float scale);
|
void SetSymbolScale(float scale);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
BMessage* fHoverMessage;
|
||||||
|
|
||||||
bool fTracking;
|
bool fTracking;
|
||||||
bigtime_t fLastTrackTime;
|
bigtime_t fLastTrackTime;
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
enum {
|
enum {
|
||||||
MSG_SEEK = 'seek',
|
MSG_SEEK = 'seek',
|
||||||
|
MSG_SEEK_HOVER = 'hovr',
|
||||||
MSG_PLAY = 'play',
|
MSG_PLAY = 'play',
|
||||||
MSG_STOP = 'stop',
|
MSG_STOP = 'stop',
|
||||||
MSG_REWIND = 'rwnd',
|
MSG_REWIND = 'rwnd',
|
||||||
@@ -39,7 +40,7 @@ enum {
|
|||||||
MSG_SKIP_FORWARD = 'skpf',
|
MSG_SKIP_FORWARD = 'skpf',
|
||||||
MSG_SET_VOLUME = 'stvl',
|
MSG_SET_VOLUME = 'stvl',
|
||||||
MSG_SET_MUTE = 'stmt',
|
MSG_SET_MUTE = 'stmt',
|
||||||
MSG_DURATION_TOOLTIP = 'msdt'
|
MSG_DURATION_TOOLTIP = 'msdt',
|
||||||
};
|
};
|
||||||
|
|
||||||
// the range of the volume sliders (in dB)
|
// the range of the volume sliders (in dB)
|
||||||
@@ -83,7 +84,7 @@ TransportControlGroup::TransportControlGroup(BRect frame, bool useSkipButtons,
|
|||||||
|
|
||||||
// Seek slider
|
// Seek slider
|
||||||
fSeekSlider = new SeekSlider("seek slider", new BMessage(MSG_SEEK),
|
fSeekSlider = new SeekSlider("seek slider", new BMessage(MSG_SEEK),
|
||||||
0, kPositionFactor);
|
new BMessage(MSG_SEEK_HOVER), 0, kPositionFactor);
|
||||||
fSeekLayout->AddView(fSeekSlider);
|
fSeekLayout->AddView(fSeekSlider);
|
||||||
|
|
||||||
fPositionToolTip = new PositionToolTip();
|
fPositionToolTip = new PositionToolTip();
|
||||||
@@ -284,6 +285,16 @@ TransportControlGroup::MessageReceived(BMessage* message)
|
|||||||
break;
|
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:
|
default:
|
||||||
BView::MessageReceived(message);
|
BView::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
@@ -310,7 +321,7 @@ void TransportControlGroup::SkipForward() {}
|
|||||||
void TransportControlGroup::VolumeChanged(float value) {}
|
void TransportControlGroup::VolumeChanged(float value) {}
|
||||||
void TransportControlGroup::ToggleMute() {}
|
void TransportControlGroup::ToggleMute() {}
|
||||||
void TransportControlGroup::PositionChanged(float value) {}
|
void TransportControlGroup::PositionChanged(float value) {}
|
||||||
|
bigtime_t TransportControlGroup::TimePositionFor(float value) { return 0; }
|
||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
@@ -492,11 +503,12 @@ void
|
|||||||
TransportControlGroup::SetPosition(float value, bigtime_t position,
|
TransportControlGroup::SetPosition(float value, bigtime_t position,
|
||||||
bigtime_t duration)
|
bigtime_t duration)
|
||||||
{
|
{
|
||||||
fPositionToolTip->Update(position, duration);
|
|
||||||
fDurationView->Update(position, duration);
|
fDurationView->Update(position, duration);
|
||||||
|
|
||||||
if (fSeekSlider->IsTracking())
|
if (fSeekSlider->IsTracking()) {
|
||||||
|
fPositionToolTip->Update(position, duration);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
fSeekSlider->SetPosition(value);
|
fSeekSlider->SetPosition(value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ public:
|
|||||||
virtual void VolumeChanged(float value);
|
virtual void VolumeChanged(float value);
|
||||||
virtual void ToggleMute();
|
virtual void ToggleMute();
|
||||||
virtual void PositionChanged(float value);
|
virtual void PositionChanged(float value);
|
||||||
|
virtual bigtime_t TimePositionFor(float value);
|
||||||
|
|
||||||
void SetEnabled(uint32 whichButtons);
|
void SetEnabled(uint32 whichButtons);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user