2 * Copyright 2010, Stephan Aßmus <superstippi@gmx.de>.
3 * Distributed under the terms of the MIT License.
7 #include "DurationView.h"
9 #include <LayoutUtils.h>
11 #include "DurationToString.h"
14 DurationView::DurationView(const char* name
)
16 BStringView(name
, ""),
24 SetAlignment(B_ALIGN_RIGHT
);
31 DurationView::AttachedToWindow()
33 BStringView::AttachedToWindow();
39 DurationView::MouseDown(BPoint where
)
41 // Switch through the modes
42 uint32 mode
= fMode
+ 1;
43 if (mode
== kLastMode
)
50 DurationView::MessageReceived(BMessage
* message
)
52 if (message
->what
== B_COLORS_UPDATED
53 && message
->HasColor(ui_color_name(B_PANEL_TEXT_COLOR
)))
56 BStringView::MessageReceived(message
);
61 DurationView::MinSize()
65 duration_to_string(int32(fDuration
/ -1000000LL), string
, sizeof(string
));
66 size
.width
= StringWidth(string
);
67 font_height fontHeight
;
68 GetFontHeight(&fontHeight
);
69 size
.height
= ceilf(fontHeight
.ascent
) + ceilf(fontHeight
.descent
);
70 return BLayoutUtils::ComposeSize(ExplicitMinSize(), size
);
75 DurationView::MaxSize()
77 return BLayoutUtils::ComposeSize(ExplicitMaxSize(), MinSize());
85 DurationView::Update(bigtime_t position
, bigtime_t duration
)
87 if (position
== fPosition
&& duration
== fDuration
)
91 if (fDuration
!= duration
) {
100 DurationView::SetMode(uint32 mode
)
111 DurationView::SetSymbolScale(float scale
)
114 BFont
font(be_bold_font
);
115 font
.SetSize(font
.Size() * scale
* 1.2);
118 SetFont(be_plain_font
);
125 DurationView::_Update()
129 _GenerateString(fPosition
);
133 _GenerateString(fPosition
- fDuration
);
136 _GenerateString(fDuration
);
143 DurationView::_UpdateTextColor()
145 SetHighColor(mix_color(ViewColor(), ui_color(B_PANEL_TEXT_COLOR
), 128));
150 DurationView::_GenerateString(bigtime_t duration
)
153 if (fDisplayDuration
== duration
)
156 fDisplayDuration
= duration
;
159 duration_to_string(duration
, string
, sizeof(string
));