* Added DurationView, defaulting to show the time remaining to finish.
* Added DurationToString to support code, used by the PositionToolTip as well now. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38588 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -25,6 +25,7 @@ for sourceDir in $(sourceDirs) {
|
|||||||
|
|
||||||
Application MediaPlayer :
|
Application MediaPlayer :
|
||||||
# interface
|
# interface
|
||||||
|
DurationView.cpp
|
||||||
PeakView.cpp
|
PeakView.cpp
|
||||||
PlayPauseButton.cpp
|
PlayPauseButton.cpp
|
||||||
PositionToolTip.cpp
|
PositionToolTip.cpp
|
||||||
@@ -87,6 +88,7 @@ Application MediaPlayer :
|
|||||||
ColorSpaceToString.cpp
|
ColorSpaceToString.cpp
|
||||||
Command.cpp
|
Command.cpp
|
||||||
CommandStack.cpp
|
CommandStack.cpp
|
||||||
|
DurationToString.cpp
|
||||||
Event.cpp
|
Event.cpp
|
||||||
EventQueue.cpp
|
EventQueue.cpp
|
||||||
FileReadWrite.cpp
|
FileReadWrite.cpp
|
||||||
|
|||||||
@@ -0,0 +1,131 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010, Stephan Aßmus <[email protected]>.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "DurationView.h"
|
||||||
|
|
||||||
|
#include <LayoutUtils.h>
|
||||||
|
|
||||||
|
#include "DurationToString.h"
|
||||||
|
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
DurationView::DurationView(const char* name)
|
||||||
|
:
|
||||||
|
BStringView(name, ""),
|
||||||
|
fMode(kTimeToFinish),
|
||||||
|
fPosition(0),
|
||||||
|
fDuration(0),
|
||||||
|
fDisplayDuration(0)
|
||||||
|
{
|
||||||
|
BFont font(be_bold_font);
|
||||||
|
font.SetSize(font.Size() * 1.2);
|
||||||
|
SetFont(&font);
|
||||||
|
|
||||||
|
SetAlignment(B_ALIGN_RIGHT);
|
||||||
|
|
||||||
|
_Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DurationView::AttachedToWindow()
|
||||||
|
{
|
||||||
|
BStringView::AttachedToWindow();
|
||||||
|
SetHighColor(tint_color(ViewColor(), B_DARKEN_4_TINT));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DurationView::MouseDown(BPoint where)
|
||||||
|
{
|
||||||
|
// Switch through the modes
|
||||||
|
uint32 mode = fMode + 1;
|
||||||
|
if (mode == kLastMode)
|
||||||
|
mode = 0;
|
||||||
|
SetMode(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSize
|
||||||
|
DurationView::MinSize()
|
||||||
|
{
|
||||||
|
// If we wanted to have a fixed size:
|
||||||
|
// BSize size;
|
||||||
|
// size.width = StringWidth("-00:00:00");
|
||||||
|
// font_height fontHeight;
|
||||||
|
// GetFontHeight(&fontHeight);
|
||||||
|
// size.height = ceilf(fontHeight.ascent) + ceilf(fontHeight.descent);
|
||||||
|
// return BLayoutUtils::ComposeSize(ExplicitMinSize(), size);
|
||||||
|
return BStringView::MinSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BSize
|
||||||
|
DurationView::MaxSize()
|
||||||
|
{
|
||||||
|
return BLayoutUtils::ComposeSize(ExplicitMaxSize(), MinSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DurationView::Update(bigtime_t position, bigtime_t duration)
|
||||||
|
{
|
||||||
|
if (position == fPosition && duration == fDuration)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fPosition = position;
|
||||||
|
fDuration = duration;
|
||||||
|
_Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DurationView::SetMode(uint32 mode)
|
||||||
|
{
|
||||||
|
if (mode == fMode)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fMode = mode;
|
||||||
|
_Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DurationView::_Update()
|
||||||
|
{
|
||||||
|
switch (fMode) {
|
||||||
|
case kTimeElapsed:
|
||||||
|
_GenerateString(fPosition);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
case kTimeToFinish:
|
||||||
|
_GenerateString(fPosition - fDuration);
|
||||||
|
break;
|
||||||
|
case kDuration:
|
||||||
|
_GenerateString(fDuration);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DurationView::_GenerateString(bigtime_t duration)
|
||||||
|
{
|
||||||
|
duration /= 1000000;
|
||||||
|
if (fDisplayDuration == duration)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fDisplayDuration = duration;
|
||||||
|
|
||||||
|
char string[64];
|
||||||
|
duration_to_string(duration, string, sizeof(string));
|
||||||
|
|
||||||
|
SetText(string);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010, Stephan Aßmus <[email protected]>.
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef DURATION_VIEW_H
|
||||||
|
#define DURATION_VIEW_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <String.h>
|
||||||
|
#include <StringView.h>
|
||||||
|
|
||||||
|
|
||||||
|
class DurationView : public BStringView {
|
||||||
|
public:
|
||||||
|
DurationView(const char* name);
|
||||||
|
|
||||||
|
// BStringView interface
|
||||||
|
virtual void AttachedToWindow();
|
||||||
|
virtual void MouseDown(BPoint where);
|
||||||
|
virtual BSize MinSize();
|
||||||
|
virtual BSize MaxSize();
|
||||||
|
|
||||||
|
// DurationView
|
||||||
|
void Update(bigtime_t position, bigtime_t duration);
|
||||||
|
|
||||||
|
enum {
|
||||||
|
kTimeElapsed = 0,
|
||||||
|
kTimeToFinish,
|
||||||
|
kDuration,
|
||||||
|
|
||||||
|
kLastMode
|
||||||
|
};
|
||||||
|
|
||||||
|
void SetMode(uint32 mode);
|
||||||
|
uint32 Mode() const
|
||||||
|
{ return fMode; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void _Update();
|
||||||
|
void _GenerateString(bigtime_t duration);
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32 fMode;
|
||||||
|
bigtime_t fPosition;
|
||||||
|
bigtime_t fDuration;
|
||||||
|
bigtime_t fDisplayDuration;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // DURATION_VIEW_H
|
||||||
@@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
#include <StringView.h>
|
#include <StringView.h>
|
||||||
|
|
||||||
|
#include "DurationToString.h"
|
||||||
|
|
||||||
|
|
||||||
class PositionToolTip::PositionView : public BStringView {
|
class PositionToolTip::PositionView : public BStringView {
|
||||||
public:
|
public:
|
||||||
@@ -48,9 +50,14 @@ public:
|
|||||||
fDuration = duration;
|
fDuration = duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char positionText[32];
|
||||||
|
duration_to_string(fPosition, positionText, sizeof(positionText));
|
||||||
|
|
||||||
|
char durationText[32];
|
||||||
|
duration_to_string(fDuration, durationText, sizeof(durationText));
|
||||||
|
|
||||||
char text[64];
|
char text[64];
|
||||||
snprintf(text, sizeof(text), "%02ld:%02ld / %02ld:%02ld",
|
snprintf(text, sizeof(text), "%s / %s", positionText, durationText);
|
||||||
fPosition / 60, fPosition % 60, fDuration / 60, fDuration % 60);
|
|
||||||
SetText(text);
|
SetText(text);
|
||||||
|
|
||||||
UnlockLooper();
|
UnlockLooper();
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include <SpaceLayoutItem.h>
|
#include <SpaceLayoutItem.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
|
#include "DurationView.h"
|
||||||
#include "PeakView.h"
|
#include "PeakView.h"
|
||||||
#include "PlaybackState.h"
|
#include "PlaybackState.h"
|
||||||
#include "PlayPauseButton.h"
|
#include "PlayPauseButton.h"
|
||||||
@@ -62,14 +63,26 @@ TransportControlGroup::TransportControlGroup(BRect frame, bool useSkipButtons,
|
|||||||
{
|
{
|
||||||
float symbolHeight = 9;
|
float symbolHeight = 9;
|
||||||
|
|
||||||
// Seek Slider
|
BGroupView* seekGroup = new BGroupView(B_HORIZONTAL, 0);
|
||||||
|
BGroupLayout* seekLayout = seekGroup->GroupLayout();
|
||||||
|
GroupLayout()->AddView(seekGroup);
|
||||||
|
|
||||||
|
// Seek slider
|
||||||
fSeekSlider = new SeekSlider("seek slider", new BMessage(MSG_SEEK),
|
fSeekSlider = new SeekSlider("seek slider", new BMessage(MSG_SEEK),
|
||||||
0, kPositionFactor);
|
0, kPositionFactor);
|
||||||
GroupLayout()->AddView(fSeekSlider);
|
seekLayout->AddView(fSeekSlider);
|
||||||
|
|
||||||
fPositionToolTip = new PositionToolTip();
|
fPositionToolTip = new PositionToolTip();
|
||||||
fSeekSlider->SetToolTip(fPositionToolTip);
|
fSeekSlider->SetToolTip(fPositionToolTip);
|
||||||
|
|
||||||
|
// Duration view
|
||||||
|
fDurationView = new DurationView("duration view");
|
||||||
|
seekLayout->AddView(fDurationView);
|
||||||
|
|
||||||
|
seekLayout->AddItem(BSpaceLayoutItem::CreateHorizontalStrut(5));
|
||||||
|
|
||||||
|
// Buttons
|
||||||
|
|
||||||
BGroupView* controlGroup = new BGroupView(B_HORIZONTAL, 0);
|
BGroupView* controlGroup = new BGroupView(B_HORIZONTAL, 0);
|
||||||
controlGroup->GroupLayout()->SetInsets(7, 5, 7, 5);
|
controlGroup->GroupLayout()->SetInsets(7, 5, 7, 5);
|
||||||
GroupLayout()->AddView(controlGroup);
|
GroupLayout()->AddView(controlGroup);
|
||||||
@@ -82,8 +95,6 @@ TransportControlGroup::TransportControlGroup(BRect frame, bool useSkipButtons,
|
|||||||
uint32 topBottomBorder = BControlLook::B_TOP_BORDER
|
uint32 topBottomBorder = BControlLook::B_TOP_BORDER
|
||||||
| BControlLook::B_BOTTOM_BORDER;
|
| BControlLook::B_BOTTOM_BORDER;
|
||||||
|
|
||||||
// Buttons
|
|
||||||
|
|
||||||
if (useSkipButtons) {
|
if (useSkipButtons) {
|
||||||
// Skip Back
|
// Skip Back
|
||||||
fSkipBack = new SymbolButton(B_EMPTY_STRING,
|
fSkipBack = new SymbolButton(B_EMPTY_STRING,
|
||||||
@@ -137,8 +148,7 @@ TransportControlGroup::TransportControlGroup(BRect frame, bool useSkipButtons,
|
|||||||
} else
|
} else
|
||||||
fSkipForward = NULL;
|
fSkipForward = NULL;
|
||||||
|
|
||||||
controlGroup->GroupLayout()->AddItem(
|
controlLayout->AddItem(BSpaceLayoutItem::CreateHorizontalStrut(5));
|
||||||
BSpaceLayoutItem::CreateHorizontalStrut(5));
|
|
||||||
|
|
||||||
// Mute
|
// Mute
|
||||||
BShape* speakerShape = _CreateSpeakerShape(8);
|
BShape* speakerShape = _CreateSpeakerShape(8);
|
||||||
@@ -461,10 +471,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);
|
||||||
|
|
||||||
if (fSeekSlider->IsTracking())
|
if (fSeekSlider->IsTracking())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fPositionToolTip->Update(position, duration);
|
|
||||||
fSeekSlider->SetPosition(value);
|
fSeekSlider->SetPosition(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
|
|
||||||
class BShape;
|
class BShape;
|
||||||
|
class DurationView;
|
||||||
class PeakView;
|
class PeakView;
|
||||||
class PlayPauseButton;
|
class PlayPauseButton;
|
||||||
class PositionToolTip;
|
class PositionToolTip;
|
||||||
@@ -104,6 +105,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
SeekSlider* fSeekSlider;
|
SeekSlider* fSeekSlider;
|
||||||
|
DurationView* fDurationView;
|
||||||
PositionToolTip* fPositionToolTip;
|
PositionToolTip* fPositionToolTip;
|
||||||
PeakView* fPeakView;
|
PeakView* fPeakView;
|
||||||
VolumeSlider* fVolumeSlider;
|
VolumeSlider* fVolumeSlider;
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010, Stephan Aßmus <[email protected]>
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "DurationToString.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
duration_to_string(int32 seconds, char* string, size_t stringSize)
|
||||||
|
{
|
||||||
|
bool negative = seconds < 0;
|
||||||
|
if (negative)
|
||||||
|
seconds = -seconds;
|
||||||
|
|
||||||
|
int32 hours = seconds / 3600;
|
||||||
|
seconds -= hours * 3600;
|
||||||
|
int32 minutes = seconds / 60;
|
||||||
|
seconds = seconds % 60;
|
||||||
|
|
||||||
|
if (hours > 0) {
|
||||||
|
snprintf(string, stringSize, "%s%ld:%02ld:%02ld",
|
||||||
|
negative ? "-" : "", hours, minutes, seconds);
|
||||||
|
} else {
|
||||||
|
snprintf(string, stringSize, "%s%ld:%02ld",
|
||||||
|
negative ? "-" : "", minutes, seconds);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010, Stephan Aßmus <[email protected]>
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef DURATION_TO_STRING_H
|
||||||
|
#define DURATION_TO_STRING_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
|
||||||
|
void duration_to_string(int32 seconds, char* string, size_t stringSize);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // DURATION_TO_STRING_H
|
||||||
Reference in New Issue
Block a user