2 * Copyright 2006-2010 Stephan Aßmus <superstippi@gmx.de>
3 * All rights reserved. Distributed under the terms of the MIT License.
7 #include "SeekSlider.h"
12 #include <ControlLook.h>
17 static const rgb_color kThumbRed
= (rgb_color
){ 255, 52, 52, 255 };
20 SeekSlider::SeekSlider(const char* name
, BMessage
* message
, int32 minValue
,
23 BSlider(name
, NULL
, NULL
, minValue
, maxValue
, B_HORIZONTAL
,
30 BFont
font(be_plain_font
);
34 rgb_color fillColor
= tint_color(ui_color(B_PANEL_BACKGROUND_COLOR
),
36 UseFillColor(true, &fillColor
);
37 SetModificationMessage(message
);
41 SeekSlider::~SeekSlider()
47 SeekSlider::Invoke(BMessage
* message
)
49 fLastTrackTime
= system_time();
50 return BSlider::Invoke(message
);
55 SeekSlider::ThumbFrame() const
57 BRect frame
= BSlider::ThumbFrame();
59 float center
= (frame
.left
+ frame
.right
) / 2.0f
;
60 float height
= ceilf(frame
.Height() * fScale
);
61 float width
= ceilf(frame
.Width() * fScale
);
63 frame
.left
= floorf(center
- width
/ 2) + 1;
64 frame
.right
= frame
.left
+ width
;
65 frame
.bottom
= frame
.top
+ height
;
81 float width
= ceilf(StringWidth(fDisabledString
.String()));
83 textPos
.x
= r
.left
+ (r
.Width() - width
) / 2.0;
84 textPos
.y
= (r
.top
+ r
.bottom
- ceilf(fh
.ascent
+ fh
.descent
)) / 2.0
87 SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR
),
89 SetDrawingMode(B_OP_OVER
);
90 DrawString(fDisabledString
.String(), textPos
);
95 SeekSlider::DrawThumb()
100 BRect frame
= ThumbFrame();
101 be_control_look
->DrawSliderTriangle(this, frame
, frame
, kThumbRed
, 0,
107 SeekSlider::MouseDown(BPoint where
)
111 BSlider::MouseDown(where
);
116 SeekSlider::MouseUp(BPoint where
)
119 BSlider::MouseUp(where
);
124 SeekSlider::GetPreferredSize(float* _width
, float* _height
)
126 BSlider::GetPreferredSize(_width
, _height
);
127 if (_width
!= NULL
) {
128 float minWidth
= 15.0 + StringWidth(fDisabledString
.String()) + 15.0;
129 *_width
= max_c(*_width
, minWidth
);
131 if (_height
!= NULL
) {
132 BRect unscaledThumbFrame
= BSlider::ThumbFrame();
133 BRect scaledThumbFrame
= ThumbFrame();
134 *_height
+= scaledThumbFrame
.Height() - unscaledThumbFrame
.Height();
140 SeekSlider::MinSize()
142 BSize size
= BSlider::MinSize();
144 BRect unscaledThumbFrame
= BSlider::ThumbFrame();
145 BRect scaledThumbFrame
= ThumbFrame();
146 size
.height
+= scaledThumbFrame
.Height() - unscaledThumbFrame
.Height();
153 SeekSlider::MaxSize()
155 BSize size
= BSlider::MaxSize();
157 BRect unscaledThumbFrame
= BSlider::ThumbFrame();
158 BRect scaledThumbFrame
= ThumbFrame();
159 size
.height
+= scaledThumbFrame
.Height() - unscaledThumbFrame
.Height();
166 SeekSlider::IsTracking() const
170 return system_time() - fLastTrackTime
< 250000;
175 SeekSlider::SetDisabledString(const char* string
)
180 if (fDisabledString
== string
)
183 fDisabledString
= string
;
191 SeekSlider::SetSymbolScale(float scale
)
197 SetBarThickness(fScale
* 15.0);