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