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: 18 PositionView() 19 : 20 BStringView("position", ""), 21 fPosition(0), 22 fDuration(0) 23 { 24 } 25 26 virtual ~PositionView() 27 { 28 } 29 30 virtual void AttachedToWindow() 31 { 32 BStringView::AttachedToWindow(); 33 Update(-1, -1); 34 } 35 36 void Update(bigtime_t position, bigtime_t duration) 37 { 38 if (!LockLooper()) 39 return; 40 41 if (position != -1) { 42 position /= 1000000L; 43 duration /= 1000000L; 44 if (position == fPosition && duration == fDuration) { 45 UnlockLooper(); 46 return; 47 } 48 49 fPosition = position; 50 fDuration = duration; 51 } 52 53 char positionText[32]; 54 duration_to_string(fPosition, positionText, sizeof(positionText)); 55 56 char durationText[32]; 57 duration_to_string(fDuration, durationText, sizeof(durationText)); 58 59 char text[64]; 60 snprintf(text, sizeof(text), "%s / %s", positionText, durationText); 61 SetText(text); 62 63 UnlockLooper(); 64 } 65 66 private: 67 time_t fPosition; 68 time_t fDuration; 69 }; 70 71 72 // #pragma mark - 73 74 75 PositionToolTip::PositionToolTip() 76 { 77 fView = new PositionView(); 78 } 79 80 81 PositionToolTip::~PositionToolTip() 82 { 83 delete fView; 84 } 85 86 87 BView* 88 PositionToolTip::View() const 89 { 90 return fView; 91 } 92 93 94 void 95 PositionToolTip::Update(bigtime_t position, bigtime_t duration) 96 { 97 fView->Update(position, duration); 98 } 99