btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / mediaplayer / interface / SeekSlider.cpp
blobf18ed8cb60199fcc4f247f41fce3f23bfdfe2ea8
1 /*
2 * Copyright 2006-2010 Stephan Aßmus <superstippi@gmx.de>
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
7 #include "SeekSlider.h"
9 #include <stdio.h>
10 #include <string.h>
12 #include <ControlLook.h>
13 #include <Region.h>
14 #include <Shape.h>
17 static const rgb_color kThumbRed = (rgb_color){ 255, 52, 52, 255 };
20 SeekSlider::SeekSlider(const char* name, BMessage* message, int32 minValue,
21 int32 maxValue)
23 BSlider(name, NULL, NULL, minValue, maxValue, B_HORIZONTAL,
24 B_TRIANGLE_THUMB),
25 fTracking(false),
26 fLastTrackTime(0),
27 fDisabledString(""),
28 fScale(0.0f)
30 BFont font(be_plain_font);
31 font.SetSize(9.0);
32 SetFont(&font);
33 SetSymbolScale(1.0);
34 rgb_color fillColor = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
35 B_DARKEN_3_TINT);
36 UseFillColor(true, &fillColor);
37 SetModificationMessage(message);
41 SeekSlider::~SeekSlider()
46 status_t
47 SeekSlider::Invoke(BMessage* message)
49 fLastTrackTime = system_time();
50 return BSlider::Invoke(message);
54 BRect
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;
67 return frame;
71 void
72 SeekSlider::DrawBar()
74 BSlider::DrawBar();
75 if (IsEnabled())
76 return;
78 BRect r(BarFrame());
79 font_height fh;
80 GetFontHeight(&fh);
81 float width = ceilf(StringWidth(fDisabledString.String()));
82 BPoint textPos;
83 textPos.x = r.left + (r.Width() - width) / 2.0;
84 textPos.y = (r.top + r.bottom - ceilf(fh.ascent + fh.descent)) / 2.0
85 + ceilf(fh.ascent);
87 SetHighColor(tint_color(ui_color(B_PANEL_BACKGROUND_COLOR),
88 B_DARKEN_3_TINT));
89 SetDrawingMode(B_OP_OVER);
90 DrawString(fDisabledString.String(), textPos);
94 void
95 SeekSlider::DrawThumb()
97 if (!IsEnabled())
98 return;
100 BRect frame = ThumbFrame();
101 be_control_look->DrawSliderTriangle(this, frame, frame, kThumbRed, 0,
102 B_HORIZONTAL);
106 void
107 SeekSlider::MouseDown(BPoint where)
109 if (IsEnabled())
110 fTracking = true;
111 BSlider::MouseDown(where);
115 void
116 SeekSlider::MouseUp(BPoint where)
118 fTracking = false;
119 BSlider::MouseUp(where);
123 void
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();
139 BSize
140 SeekSlider::MinSize()
142 BSize size = BSlider::MinSize();
144 BRect unscaledThumbFrame = BSlider::ThumbFrame();
145 BRect scaledThumbFrame = ThumbFrame();
146 size.height += scaledThumbFrame.Height() - unscaledThumbFrame.Height();
148 return size;
152 BSize
153 SeekSlider::MaxSize()
155 BSize size = BSlider::MaxSize();
157 BRect unscaledThumbFrame = BSlider::ThumbFrame();
158 BRect scaledThumbFrame = ThumbFrame();
159 size.height += scaledThumbFrame.Height() - unscaledThumbFrame.Height();
161 return size;
165 bool
166 SeekSlider::IsTracking() const
168 if (fTracking)
169 return true;
170 return system_time() - fLastTrackTime < 250000;
174 void
175 SeekSlider::SetDisabledString(const char* string)
177 if (string == NULL)
178 string = "";
180 if (fDisabledString == string)
181 return;
183 fDisabledString = string;
185 if (!IsEnabled())
186 Invalidate();
190 void
191 SeekSlider::SetSymbolScale(float scale)
193 if (scale == fScale)
194 return;
196 fScale = scale;
197 SetBarThickness(fScale * 15.0);
198 InvalidateLayout();