1 /*
2 * Copyright 2009, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7 #include "PositionToolTip.h"
8
9 #include <stdio.h>
10
11 #include <StringView.h>
12
13 #include "DurationToString.h"
14
15
16 class PositionToolTip::PositionView : public BStringView {
17 public:
PositionView()18 PositionView()
19 :
20 BStringView("position", ""),
21 fPosition(0),
22 fDuration(0)
23 {
24 }
25
~PositionView()26 virtual ~PositionView()
27 {
28 }
29
AttachedToWindow()30 virtual void AttachedToWindow()
31 {
32 BStringView::AttachedToWindow();
33 AdoptParentColors();
34 Update(-1, -1);
35 }
36
Update(bigtime_t position,bigtime_t duration)37 void Update(bigtime_t position, bigtime_t duration)
38 {
39 if (!LockLooper())
40 return;
41
42 if (position != -1) {
43 position /= 1000000L;
44 duration /= 1000000L;
45 if (position == fPosition && duration == fDuration) {
46 UnlockLooper();
47 return;
48 }
49
50 fPosition = position;
51 fDuration = duration;
52 }
53
54 char positionText[32];
55 duration_to_string(fPosition, positionText, sizeof(positionText));
56
57 char durationText[32];
58 duration_to_string(fDuration, durationText, sizeof(durationText));
59
60 char text[66];
61 snprintf(text, sizeof(text), "%s / %s", positionText, durationText);
62 SetText(text);
63
64 UnlockLooper();
65 }
66
67 private:
68 time_t fPosition;
69 time_t fDuration;
70 };
71
72
73 // #pragma mark -
74
75
PositionToolTip()76 PositionToolTip::PositionToolTip()
77 {
78 fView = new PositionView();
79 }
80
81
~PositionToolTip()82 PositionToolTip::~PositionToolTip()
83 {
84 delete fView;
85 }
86
87
88 BView*
View() const89 PositionToolTip::View() const
90 {
91 return fView;
92 }
93
94
95 void
Update(bigtime_t position,bigtime_t duration)96 PositionToolTip::Update(bigtime_t position, bigtime_t duration)
97 {
98 fView->Update(position, duration);
99 }
100