btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / mediaplayer / interface / PositionToolTip.cpp
blob698727ba701116667d3a8fb08fc4f29566071fe6
1 /*
2 * Copyright 2009, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "PositionToolTip.h"
9 #include <stdio.h>
11 #include <StringView.h>
13 #include "DurationToString.h"
16 class PositionToolTip::PositionView : public BStringView {
17 public:
18 PositionView()
20 BStringView("position", ""),
21 fPosition(0),
22 fDuration(0)
26 virtual ~PositionView()
30 virtual void AttachedToWindow()
32 BStringView::AttachedToWindow();
33 AdoptParentColors();
34 Update(-1, -1);
37 void Update(bigtime_t position, bigtime_t duration)
39 if (!LockLooper())
40 return;
42 if (position != -1) {
43 position /= 1000000L;
44 duration /= 1000000L;
45 if (position == fPosition && duration == fDuration) {
46 UnlockLooper();
47 return;
50 fPosition = position;
51 fDuration = duration;
54 char positionText[32];
55 duration_to_string(fPosition, positionText, sizeof(positionText));
57 char durationText[32];
58 duration_to_string(fDuration, durationText, sizeof(durationText));
60 char text[64];
61 snprintf(text, sizeof(text), "%s / %s", positionText, durationText);
62 SetText(text);
64 UnlockLooper();
67 private:
68 time_t fPosition;
69 time_t fDuration;
73 // #pragma mark -
76 PositionToolTip::PositionToolTip()
78 fView = new PositionView();
82 PositionToolTip::~PositionToolTip()
84 delete fView;
88 BView*
89 PositionToolTip::View() const
91 return fView;
95 void
96 PositionToolTip::Update(bigtime_t position, bigtime_t duration)
98 fView->Update(position, duration);