xref: /haiku/src/apps/soundrecorder/TrackSlider.cpp (revision 7f4d1af49dd1d67ecbf1d934eddd92cae7c4c558)
157e2f323SJérôme Duval /*
257e2f323SJérôme Duval  * Copyright 2005, Jérôme Duval. All rights reserved.
357e2f323SJérôme Duval  * Distributed under the terms of the MIT License.
457e2f323SJérôme Duval  *
53ee96407SJérôme Duval  * Inspired by SoundCapture from Be newsletter (Media Kit Basics: Consumers
63ee96407SJérôme Duval  * and Producers)
757e2f323SJérôme Duval  */
857e2f323SJérôme Duval 
957e2f323SJérôme Duval #include <stdio.h>
10758b1d0eSIngo Weinhold #include <string.h>
1142f70a5dSJérôme Duval #include <Screen.h>
1257e2f323SJérôme Duval 
1357e2f323SJérôme Duval #include "TrackSlider.h"
1457e2f323SJérôme Duval #include "icon_button.h"
1557e2f323SJérôme Duval 
163ee96407SJérôme Duval TrackSlider::TrackSlider(BRect rect, const char *title, BMessage *msg,
173ee96407SJérôme Duval 	uint32 resizeFlags)
183ee96407SJérôme Duval 	:
193ee96407SJérôme Duval 	BControl(rect, "slider", NULL, msg, resizeFlags, B_WILL_DRAW
203ee96407SJérôme Duval 		| B_FRAME_EVENTS),
213ee96407SJérôme Duval 	fLeftTime(0),
223ee96407SJérôme Duval 	fRightTime(1000000),
233ee96407SJérôme Duval 	fMainTime(0),
243ee96407SJérôme Duval 	fTotalTime(1000000),
253ee96407SJérôme Duval 	fLeftTracking(false),
263ee96407SJérôme Duval 	fRightTracking(false),
273ee96407SJérôme Duval 	fMainTracking(false),
283ee96407SJérôme Duval 	fBitmap(NULL),
293ee96407SJérôme Duval 	fBitmapView(NULL)
3057e2f323SJérôme Duval {
3157e2f323SJérôme Duval 	fFont.SetSize(8.0);
3257e2f323SJérôme Duval 	fFont.SetFlags(B_DISABLE_ANTIALIASING);
3357e2f323SJérôme Duval 
3457e2f323SJérôme Duval 	int32 numFamilies = count_font_families();
3557e2f323SJérôme Duval 	for (int32 i = 0; i < numFamilies; i++ ) {
3657e2f323SJérôme Duval 		font_family family;
3757e2f323SJérôme Duval 		uint32 flags;
3857e2f323SJérôme Duval 		if ((get_font_family(i, &family, &flags) == B_OK)
3957e2f323SJérôme Duval 			&& (strcmp(family, "Baskerville") == 0)) {
4057e2f323SJérôme Duval 			fFont.SetFamilyAndFace(family, B_REGULAR_FACE);
4157e2f323SJérôme Duval 			break;
4257e2f323SJérôme Duval 		}
4357e2f323SJérôme Duval 	}
4457e2f323SJérôme Duval 
4557e2f323SJérôme Duval }
4657e2f323SJérôme Duval 
4757e2f323SJérôme Duval 
4857e2f323SJérôme Duval TrackSlider::~TrackSlider()
4957e2f323SJérôme Duval {
5042f70a5dSJérôme Duval 	delete fBitmap;
5157e2f323SJérôme Duval }
5257e2f323SJérôme Duval 
5357e2f323SJérôme Duval 
5457e2f323SJérôme Duval void
5557e2f323SJérôme Duval TrackSlider::AttachedToWindow()
5657e2f323SJérôme Duval {
5757e2f323SJérôme Duval 	BControl::AttachedToWindow();
5857e2f323SJérôme Duval 	SetViewColor(B_TRANSPARENT_COLOR);
59ad0c65eaSJérôme Duval 	_InitBitmap();
60ad0c65eaSJérôme Duval 	_RenderBitmap();
6157e2f323SJérôme Duval }
6257e2f323SJérôme Duval 
6357e2f323SJérôme Duval 
6442f70a5dSJérôme Duval void
65ad0c65eaSJérôme Duval TrackSlider::_InitBitmap()
6642f70a5dSJérôme Duval {
6742f70a5dSJérôme Duval 	if (fBitmapView) {
6842f70a5dSJérôme Duval 		fBitmap->RemoveChild(fBitmapView);
6942f70a5dSJérôme Duval 		delete fBitmapView;
7042f70a5dSJérôme Duval 	}
7142f70a5dSJérôme Duval 	if (fBitmap)
7242f70a5dSJérôme Duval 		delete fBitmap;
7342f70a5dSJérôme Duval 
7442f70a5dSJérôme Duval 	BRect rect = Bounds();
7542f70a5dSJérôme Duval 
7642f70a5dSJérôme Duval 	fBitmap = new BBitmap(rect, BScreen().ColorSpace(), true);
7742f70a5dSJérôme Duval 
784c9da6dcSStephan Aßmus 	fBitmapView = new SliderOffscreenView(rect.OffsetToSelf(B_ORIGIN), "bitmapView");
7942f70a5dSJérôme Duval 	fBitmap->AddChild(fBitmapView);
8042f70a5dSJérôme Duval 
8142f70a5dSJérôme Duval 	fBitmapView->fRight = Bounds().right - kLeftRightTrackSliderWidth;
8242f70a5dSJérôme Duval 	if (fTotalTime == 0) {
8342f70a5dSJérôme Duval 		fBitmapView->fLeftX = 14;
8442f70a5dSJérôme Duval 		fBitmapView->fRightX = fBitmapView->fRight;
8542f70a5dSJérôme Duval 		fBitmapView->fPositionX = 15;
8642f70a5dSJérôme Duval 	} else {
873ee96407SJérôme Duval 		fBitmapView->fLeftX = 14 + (fBitmapView->fRight - 15)
883ee96407SJérôme Duval 			* ((double)fLeftTime / fTotalTime);
893ee96407SJérôme Duval 		fBitmapView->fRightX = 15 + (fBitmapView->fRight - 16)
903ee96407SJérôme Duval 			* ((double)fRightTime / fTotalTime);
913ee96407SJérôme Duval 		fBitmapView->fPositionX = 15 + (fBitmapView->fRight - 14)
923ee96407SJérôme Duval 			* ((double)fMainTime / fTotalTime);
9342f70a5dSJérôme Duval 	}
9442f70a5dSJérôme Duval }
9542f70a5dSJérôme Duval 
9657e2f323SJérôme Duval #define SLIDER_BASE 10
9757e2f323SJérôme Duval 
9857e2f323SJérôme Duval void
99ad0c65eaSJérôme Duval TrackSlider::_RenderBitmap()
10042f70a5dSJérôme Duval {
10142f70a5dSJérôme Duval 	/* rendering */
10242f70a5dSJérôme Duval 	if (fBitmap->Lock()) {
10342f70a5dSJérôme Duval 		fBitmapView->DrawX();
10442f70a5dSJérôme Duval 		fBitmap->Unlock();
10542f70a5dSJérôme Duval 	}
10642f70a5dSJérôme Duval }
10742f70a5dSJérôme Duval 
10842f70a5dSJérôme Duval 
10942f70a5dSJérôme Duval void
11057e2f323SJérôme Duval TrackSlider::Draw(BRect updateRect)
11157e2f323SJérôme Duval {
11242f70a5dSJérôme Duval 	DrawBitmapAsync(fBitmap, BPoint(0,0));
11342f70a5dSJérôme Duval 
114ad0c65eaSJérôme Duval 	_DrawCounter(fMainTime, fBitmapView->fPositionX, fMainTracking);
11542f70a5dSJérôme Duval 	if (fLeftTracking)
116ad0c65eaSJérôme Duval 		_DrawCounter(fLeftTime, fBitmapView->fLeftX, fLeftTracking);
11742f70a5dSJérôme Duval 	else if (fRightTracking)
118ad0c65eaSJérôme Duval 		_DrawCounter(fRightTime, fBitmapView->fRightX, fRightTracking);
11942f70a5dSJérôme Duval 
120ad0c65eaSJérôme Duval 	_DrawMarker(fBitmapView->fPositionX);
12142f70a5dSJérôme Duval 
12242f70a5dSJérôme Duval 	Sync();
12342f70a5dSJérôme Duval }
12442f70a5dSJérôme Duval 
12542f70a5dSJérôme Duval 
12642f70a5dSJérôme Duval void
127ad0c65eaSJérôme Duval TrackSlider::_DrawCounter(bigtime_t timestamp, float position, bool isTracking)
12842f70a5dSJérôme Duval {
12942f70a5dSJérôme Duval 	// timecounter
13042f70a5dSJérôme Duval 
13142f70a5dSJérôme Duval 	rgb_color gray = {128,128,128};
13242f70a5dSJérôme Duval 	rgb_color blue = {0,0,140};
13342f70a5dSJérôme Duval 	rgb_color blue2 = {146,146,214};
13442f70a5dSJérôme Duval 	rgb_color white = {255,255,255};
13542f70a5dSJérôme Duval 
13642f70a5dSJérôme Duval 	char string[12];
137ad0c65eaSJérôme Duval 	_TimeToString(timestamp, string);
13842f70a5dSJérôme Duval 	int32 halfwidth = ((int32)fFont.StringWidth(string)) / 2;
13942f70a5dSJérôme Duval 
14042f70a5dSJérôme Duval 	float counterX = position;
14142f70a5dSJérôme Duval 	if (counterX < 39)
14242f70a5dSJérôme Duval 		counterX = 39;
14342f70a5dSJérôme Duval 	if (counterX > fBitmapView->fRight - 23)
14442f70a5dSJérôme Duval 		counterX = fBitmapView->fRight - 23;
14542f70a5dSJérôme Duval 
14642f70a5dSJérôme Duval 	BeginLineArray(4);
14742f70a5dSJérôme Duval 	if (!isTracking) {
1483ee96407SJérôme Duval 		AddLine(BPoint(counterX-halfwidth-3,SLIDER_BASE+1),
1493ee96407SJérôme Duval 			BPoint(counterX+halfwidth+3,SLIDER_BASE+1), gray);
1503ee96407SJérôme Duval 		AddLine(BPoint(counterX+halfwidth+4,SLIDER_BASE+1),
1513ee96407SJérôme Duval 			BPoint(counterX+halfwidth+4,SLIDER_BASE-8), gray);
1523ee96407SJérôme Duval 		AddLine(BPoint(counterX-halfwidth-4,SLIDER_BASE+1),
1533ee96407SJérôme Duval 			BPoint(counterX-halfwidth-4,SLIDER_BASE-9), white);
1543ee96407SJérôme Duval 		AddLine(BPoint(counterX-halfwidth-3,SLIDER_BASE-9),
1553ee96407SJérôme Duval 			BPoint(counterX+halfwidth+4,SLIDER_BASE-9), white);
15642f70a5dSJérôme Duval 		SetHighColor(216,216,216);
15742f70a5dSJérôme Duval 	} else {
1583ee96407SJérôme Duval 		AddLine(BPoint(counterX-halfwidth-3,SLIDER_BASE+1),
1593ee96407SJérôme Duval 			BPoint(counterX+halfwidth+3,SLIDER_BASE+1), blue);
1603ee96407SJérôme Duval 		AddLine(BPoint(counterX+halfwidth+4,SLIDER_BASE+1),
1613ee96407SJérôme Duval 			BPoint(counterX+halfwidth+4,SLIDER_BASE-9), blue2);
1623ee96407SJérôme Duval 		AddLine(BPoint(counterX-halfwidth-4,SLIDER_BASE+1),
1633ee96407SJérôme Duval 			BPoint(counterX-halfwidth-4,SLIDER_BASE-9), blue2);
1643ee96407SJérôme Duval 		AddLine(BPoint(counterX-halfwidth-3,SLIDER_BASE-9),
1653ee96407SJérôme Duval 			BPoint(counterX+halfwidth+3,SLIDER_BASE-9), blue2);
16642f70a5dSJérôme Duval 		SetHighColor(48,48,241);
16742f70a5dSJérôme Duval 	}
16842f70a5dSJérôme Duval 	EndLineArray();
1693ee96407SJérôme Duval 	FillRect(BRect(counterX-halfwidth-3,SLIDER_BASE-8,counterX+halfwidth+3,
1703ee96407SJérôme Duval 		SLIDER_BASE));
17142f70a5dSJérôme Duval 
17242ee4863SJérôme Duval #ifdef __HAIKU__
17342ee4863SJérôme Duval 	SetDrawingMode(B_OP_OVER);
17442ee4863SJérôme Duval #else
17542f70a5dSJérôme Duval 	SetDrawingMode(B_OP_COPY);
17642ee4863SJérôme Duval #endif
17742f70a5dSJérôme Duval 	if (isTracking)
17842f70a5dSJérôme Duval 		SetHighColor(255,255,255);
17942f70a5dSJérôme Duval 	else
18042f70a5dSJérôme Duval 		SetHighColor(0,0,0);
18142f70a5dSJérôme Duval 	SetLowColor(ViewColor());
18242f70a5dSJérôme Duval 
18342f70a5dSJérôme Duval 	SetFont(&fFont);
18442f70a5dSJérôme Duval 	DrawString(string, BPoint(counterX-halfwidth, SLIDER_BASE-1));
18542f70a5dSJérôme Duval 
18642f70a5dSJérôme Duval }
18742f70a5dSJérôme Duval 
18842f70a5dSJérôme Duval 
18942f70a5dSJérôme Duval void
190ad0c65eaSJérôme Duval TrackSlider::_DrawMarker(float position)
19142f70a5dSJérôme Duval {
19242f70a5dSJérôme Duval 	rgb_color black = {0,0,0};
19342f70a5dSJérôme Duval 	rgb_color rose = {255,152,152};
19442f70a5dSJérôme Duval 	rgb_color red = {255,0,0};
19542f70a5dSJérôme Duval 	rgb_color bordeau = {178,0,0};
19642f70a5dSJérôme Duval 	rgb_color white = {255,255,255};
19742f70a5dSJérôme Duval 
19842f70a5dSJérôme Duval 	BeginLineArray(30);
1993ee96407SJérôme Duval 	AddLine(BPoint(position,SLIDER_BASE+7), BPoint(position-4,SLIDER_BASE+3),
2003ee96407SJérôme Duval 		black);
2013ee96407SJérôme Duval 	AddLine(BPoint(position-4,SLIDER_BASE+3), BPoint(position-4,SLIDER_BASE+1),
2023ee96407SJérôme Duval 		black);
2033ee96407SJérôme Duval 	AddLine(BPoint(position-4,SLIDER_BASE+1), BPoint(position+4,SLIDER_BASE+1),
2043ee96407SJérôme Duval 		black);
2053ee96407SJérôme Duval 	AddLine(BPoint(position+4,SLIDER_BASE+1), BPoint(position+4,SLIDER_BASE+3),
2063ee96407SJérôme Duval 		black);
2073ee96407SJérôme Duval 	AddLine(BPoint(position+4,SLIDER_BASE+3), BPoint(position,SLIDER_BASE+7),
2083ee96407SJérôme Duval 		black);
20942f70a5dSJérôme Duval 
21042f70a5dSJérôme Duval 
2113ee96407SJérôme Duval 	AddLine(BPoint(position-3,SLIDER_BASE+2), BPoint(position+3,SLIDER_BASE+2),
2123ee96407SJérôme Duval 		rose);
2133ee96407SJérôme Duval 	AddLine(BPoint(position-3,SLIDER_BASE+3), BPoint(position-1,SLIDER_BASE+5),
2143ee96407SJérôme Duval 		rose);
21542f70a5dSJérôme Duval 
2163ee96407SJérôme Duval 	AddLine(BPoint(position-2,SLIDER_BASE+3), BPoint(position+2,SLIDER_BASE+3),
2173ee96407SJérôme Duval 		red);
2183ee96407SJérôme Duval 	AddLine(BPoint(position-1,SLIDER_BASE+4), BPoint(position+1,SLIDER_BASE+4),
2193ee96407SJérôme Duval 		red);
2203ee96407SJérôme Duval 	AddLine(BPoint(position,SLIDER_BASE+5), BPoint(position,SLIDER_BASE+5),
2213ee96407SJérôme Duval 		red);
22242f70a5dSJérôme Duval 
2233ee96407SJérôme Duval 	AddLine(BPoint(position,SLIDER_BASE+6), BPoint(position+3,SLIDER_BASE+3),
2243ee96407SJérôme Duval 		bordeau);
22542f70a5dSJérôme Duval 
2263ee96407SJérôme Duval 	AddLine(BPoint(position,SLIDER_BASE+12), BPoint(position-4,SLIDER_BASE+16),
2273ee96407SJérôme Duval 		black);
2283ee96407SJérôme Duval 	AddLine(BPoint(position-4,SLIDER_BASE+16), BPoint(position-4,
2293ee96407SJérôme Duval 		SLIDER_BASE+17), black);
2303ee96407SJérôme Duval 	AddLine(BPoint(position-4,SLIDER_BASE+17), BPoint(position+4,
2313ee96407SJérôme Duval 		SLIDER_BASE+17), black);
2323ee96407SJérôme Duval 	AddLine(BPoint(position+4,SLIDER_BASE+17), BPoint(position+4,
2333ee96407SJérôme Duval 		SLIDER_BASE+16), black);
2343ee96407SJérôme Duval 	AddLine(BPoint(position+4,SLIDER_BASE+16), BPoint(position,SLIDER_BASE+12),
2353ee96407SJérôme Duval 		black);
2363ee96407SJérôme Duval 	AddLine(BPoint(position-4,SLIDER_BASE+18), BPoint(position+4,
2373ee96407SJérôme Duval 		SLIDER_BASE+18), white);
23842f70a5dSJérôme Duval 
2393ee96407SJérôme Duval 	AddLine(BPoint(position-3,SLIDER_BASE+16), BPoint(position,SLIDER_BASE+13),
2403ee96407SJérôme Duval 		rose);
24142f70a5dSJérôme Duval 
2423ee96407SJérôme Duval 	AddLine(BPoint(position-2,SLIDER_BASE+16), BPoint(position+2,
2433ee96407SJérôme Duval 		SLIDER_BASE+16), red);
2443ee96407SJérôme Duval 	AddLine(BPoint(position-1,SLIDER_BASE+15), BPoint(position+1,
2453ee96407SJérôme Duval 		SLIDER_BASE+15), red);
2463ee96407SJérôme Duval 	AddLine(BPoint(position,SLIDER_BASE+14), BPoint(position,
2473ee96407SJérôme Duval 		SLIDER_BASE+14), red);
24842f70a5dSJérôme Duval 
2493ee96407SJérôme Duval 	AddLine(BPoint(position+1,SLIDER_BASE+14), BPoint(position+3,
2503ee96407SJérôme Duval 		SLIDER_BASE+16), bordeau);
25142f70a5dSJérôme Duval 
25242f70a5dSJérôme Duval 	EndLineArray();
25342f70a5dSJérôme Duval }
25442f70a5dSJérôme Duval 
25542f70a5dSJérôme Duval 
25642f70a5dSJérôme Duval void
25742f70a5dSJérôme Duval TrackSlider::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
25842f70a5dSJérôme Duval {
25942f70a5dSJérôme Duval 	if (!IsTracking())
26042f70a5dSJérôme Duval 		return;
26142f70a5dSJérôme Duval 
26242f70a5dSJérôme Duval 	uint32 mouseButtons;
26342f70a5dSJérôme Duval 	BPoint where;
26442f70a5dSJérôme Duval 	GetMouse(&where, &mouseButtons, true);
26542f70a5dSJérôme Duval 
26642f70a5dSJérôme Duval 	// button not pressed, exit
26742f70a5dSJérôme Duval 	if (! (mouseButtons & B_PRIMARY_MOUSE_BUTTON)) {
26842f70a5dSJérôme Duval 		Invoke();
26942f70a5dSJérôme Duval 		SetTracking(false);
27042f70a5dSJérôme Duval 	}
27142f70a5dSJérôme Duval 
272ad0c65eaSJérôme Duval 	_UpdatePosition(point);
27342f70a5dSJérôme Duval }
27442f70a5dSJérôme Duval 
27542f70a5dSJérôme Duval 
27642f70a5dSJérôme Duval void
27742f70a5dSJérôme Duval TrackSlider::MouseDown(BPoint point)
27842f70a5dSJérôme Duval {
27942f70a5dSJérôme Duval 	if (!Bounds().InsetBySelf(2,2).Contains(point))
28042f70a5dSJérôme Duval 		return;
28142f70a5dSJérôme Duval 
282ad0c65eaSJérôme Duval 	_UpdatePosition(point);
28342f70a5dSJérôme Duval 	SetTracking(true);
2843ee96407SJérôme Duval 	SetMouseEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY
2853ee96407SJérôme Duval 		| B_LOCK_WINDOW_FOCUS);
28642f70a5dSJérôme Duval }
28742f70a5dSJérôme Duval 
28842f70a5dSJérôme Duval 
28942f70a5dSJérôme Duval void
29042f70a5dSJérôme Duval TrackSlider::MouseUp(BPoint point)
29142f70a5dSJérôme Duval {
29242f70a5dSJérôme Duval 	if (!IsTracking())
29342f70a5dSJérôme Duval 		return;
29442f70a5dSJérôme Duval 	if (Bounds().InsetBySelf(2,2).Contains(point)) {
295ad0c65eaSJérôme Duval 		_UpdatePosition(point);
29642f70a5dSJérôme Duval 	}
29742f70a5dSJérôme Duval 
29842f70a5dSJérôme Duval 	fLeftTracking = fRightTracking = fMainTracking = false;
29942f70a5dSJérôme Duval 
30042f70a5dSJérôme Duval 	Invoke();
30142f70a5dSJérôme Duval 	SetTracking(false);
30242f70a5dSJérôme Duval 	Draw(Bounds());
30342f70a5dSJérôme Duval 	Flush();
30442f70a5dSJérôme Duval }
30542f70a5dSJérôme Duval 
30642f70a5dSJérôme Duval 
30742f70a5dSJérôme Duval void
308ad0c65eaSJérôme Duval TrackSlider::_UpdatePosition(BPoint point)
30942f70a5dSJérôme Duval {
3103ee96407SJérôme Duval 	BRect leftRect(fBitmapView->fLeftX-9, SLIDER_BASE+3, fBitmapView->fLeftX,
3113ee96407SJérôme Duval 		SLIDER_BASE+16);
3123ee96407SJérôme Duval 	BRect rightRect(fBitmapView->fRightX, SLIDER_BASE+3,
3133ee96407SJérôme Duval 		fBitmapView->fRightX+9, SLIDER_BASE+16);
31442f70a5dSJérôme Duval 
3153ee96407SJérôme Duval 	if (!(fRightTracking || fMainTracking) && (fLeftTracking
3163ee96407SJérôme Duval 		|| ((point.x < fBitmapView->fPositionX-4) && leftRect.Contains(point)))) {
31742f70a5dSJérôme Duval 		if (!IsTracking())
31842f70a5dSJérôme Duval 			fBitmapView->fLastX = point.x - fBitmapView->fLeftX;
3193ee96407SJérôme Duval 		fBitmapView->fLeftX = MIN(MAX(point.x - fBitmapView->fLastX, 15),
3203ee96407SJérôme Duval 			fBitmapView->fRight);
3213ee96407SJérôme Duval 		fLeftTime = (bigtime_t)(MAX(MIN((fBitmapView->fLeftX - 15)
3223ee96407SJérôme Duval 			/ (fBitmapView->fRight - 14),1), 0) * fTotalTime);
32342f70a5dSJérôme Duval 		fLeftTracking = true;
32442f70a5dSJérôme Duval 
32542f70a5dSJérôme Duval 		BMessage msg = *Message();
32642f70a5dSJérôme Duval 		msg.AddInt64("left", fLeftTime);
32742f70a5dSJérôme Duval 
32842f70a5dSJérôme Duval 		if (fBitmapView->fPositionX < fBitmapView->fLeftX) {
32942f70a5dSJérôme Duval 			fBitmapView->fPositionX = fBitmapView->fLeftX + 1;
33042f70a5dSJérôme Duval 			fMainTime = fLeftTime;
33142f70a5dSJérôme Duval 			msg.AddInt64("main", fMainTime);
33242f70a5dSJérôme Duval 			if (fBitmapView->fRightX < fBitmapView->fPositionX) {
33342f70a5dSJérôme Duval 				fBitmapView->fRightX = fBitmapView->fPositionX;
33442f70a5dSJérôme Duval 				fRightTime = fMainTime;
33542f70a5dSJérôme Duval 				msg.AddInt64("right", fRightTime);
33642f70a5dSJérôme Duval 			}
33742f70a5dSJérôme Duval 		}
33842f70a5dSJérôme Duval 
33942f70a5dSJérôme Duval 		Invoke(&msg);
340ad0c65eaSJérôme Duval 		_RenderBitmap();
34142f70a5dSJérôme Duval 
34242f70a5dSJérôme Duval 		//printf("fLeftPos : %Ld\n", fLeftTime);
3433ee96407SJérôme Duval 	} else if (!fMainTracking && (fRightTracking
3443ee96407SJérôme Duval 		|| ((point.x > fBitmapView->fPositionX+4)
3453ee96407SJérôme Duval 		&& rightRect.Contains(point)))) {
34642f70a5dSJérôme Duval 		if (!IsTracking())
34742f70a5dSJérôme Duval 			fBitmapView->fLastX = point.x - fBitmapView->fRightX;
3483ee96407SJérôme Duval 		fBitmapView->fRightX = MIN(MAX(point.x - fBitmapView->fLastX, 15),
3493ee96407SJérôme Duval 			fBitmapView->fRight);
3503ee96407SJérôme Duval 		fRightTime = (bigtime_t)(MAX(MIN((fBitmapView->fRightX - 15)
3513ee96407SJérôme Duval 			/ (fBitmapView->fRight - 14),1), 0) * fTotalTime);
35242f70a5dSJérôme Duval 		fRightTracking = true;
35342f70a5dSJérôme Duval 
35442f70a5dSJérôme Duval 		BMessage msg = *Message();
35542f70a5dSJérôme Duval 		msg.AddInt64("right", fRightTime);
35642f70a5dSJérôme Duval 
35742f70a5dSJérôme Duval 		if (fBitmapView->fPositionX > fBitmapView->fRightX) {
35842f70a5dSJérôme Duval 			fBitmapView->fPositionX = fBitmapView->fRightX;
35942f70a5dSJérôme Duval 			fMainTime = fRightTime;
36042f70a5dSJérôme Duval 			msg.AddInt64("main", fMainTime);
36142f70a5dSJérôme Duval 			if (fBitmapView->fLeftX > fBitmapView->fPositionX) {
36242f70a5dSJérôme Duval 				fBitmapView->fLeftX = fBitmapView->fPositionX - 1;
36342f70a5dSJérôme Duval 				fLeftTime = fMainTime;
36442f70a5dSJérôme Duval 				msg.AddInt64("left", fLeftTime);
36542f70a5dSJérôme Duval 			}
36642f70a5dSJérôme Duval 		}
36742f70a5dSJérôme Duval 
36842f70a5dSJérôme Duval 		Invoke(&msg);
369ad0c65eaSJérôme Duval 		_RenderBitmap();
37042f70a5dSJérôme Duval 
37142f70a5dSJérôme Duval 		//printf("fRightPos : %Ld\n", fRightTime);
37242f70a5dSJérôme Duval 	} else {
37342f70a5dSJérôme Duval 		fBitmapView->fPositionX = MIN(MAX(point.x, 15), fBitmapView->fRight);
3743ee96407SJérôme Duval 		fMainTime = (bigtime_t)(MAX(MIN((fBitmapView->fPositionX - 15)
3753ee96407SJérôme Duval 			/ (fBitmapView->fRight - 14),1), 0) * fTotalTime);
37642f70a5dSJérôme Duval 		fMainTracking = true;
37742f70a5dSJérôme Duval 
37842f70a5dSJérôme Duval 		BMessage msg = *Message();
37942f70a5dSJérôme Duval 		msg.AddInt64("main", fMainTime);
38042f70a5dSJérôme Duval 
38142f70a5dSJérôme Duval 		if (fBitmapView->fRightX < fBitmapView->fPositionX) {
38242f70a5dSJérôme Duval 			fBitmapView->fRightX = fBitmapView->fPositionX;
38342f70a5dSJérôme Duval 			fRightTime = fMainTime;
38442f70a5dSJérôme Duval 			msg.AddInt64("right", fRightTime);
385ad0c65eaSJérôme Duval 			_RenderBitmap();
38642f70a5dSJérôme Duval 		} else if (fBitmapView->fLeftX > fBitmapView->fPositionX) {
38742f70a5dSJérôme Duval 			fBitmapView->fLeftX = fBitmapView->fPositionX - 1;
38842f70a5dSJérôme Duval 			fLeftTime = fMainTime;
38942f70a5dSJérôme Duval 			msg.AddInt64("left", fLeftTime);
390ad0c65eaSJérôme Duval 			_RenderBitmap();
39142f70a5dSJérôme Duval 		}
39242f70a5dSJérôme Duval 
39342f70a5dSJérôme Duval 		Invoke(&msg);
39442f70a5dSJérôme Duval 		//printf("fPosition : %Ld\n", fMainTime);
39542f70a5dSJérôme Duval 	}
39642f70a5dSJérôme Duval 	Draw(Bounds());
39742f70a5dSJérôme Duval 	Flush();
39842f70a5dSJérôme Duval }
39942f70a5dSJérôme Duval 
40042f70a5dSJérôme Duval 
40142f70a5dSJérôme Duval void
402ad0c65eaSJérôme Duval TrackSlider::_TimeToString(bigtime_t timestamp, char *string)
40342f70a5dSJérôme Duval {
40442f70a5dSJérôme Duval 	uint32 hours = timestamp / 3600000000LL;
40542f70a5dSJérôme Duval 	timestamp -= hours * 3600000000LL;
40642f70a5dSJérôme Duval 	uint32 minutes = timestamp / 60000000LL;
40742f70a5dSJérôme Duval 	timestamp -= minutes * 60000000LL;
40842f70a5dSJérôme Duval 	uint32 seconds = timestamp / 1000000LL;
40942f70a5dSJérôme Duval 	timestamp -= seconds * 1000000LL;
41042f70a5dSJérôme Duval 	uint32 centiseconds = timestamp / 10000LL;
411*7f4d1af4SSergei Reznikov 	sprintf(string, "%02" B_PRId32 ":%02" B_PRId32 ":%02" B_PRId32 ":%02"
412*7f4d1af4SSergei Reznikov 		B_PRId32, hours, minutes, seconds, centiseconds);
41342f70a5dSJérôme Duval }
41442f70a5dSJérôme Duval 
41542f70a5dSJérôme Duval 
41642f70a5dSJérôme Duval void
41742f70a5dSJérôme Duval TrackSlider::SetMainTime(bigtime_t timestamp, bool reset)
41842f70a5dSJérôme Duval {
41942f70a5dSJérôme Duval 	fMainTime = timestamp;
4203ee96407SJérôme Duval 	fBitmapView->fPositionX = 15 + (fBitmapView->fRight - 14)
4213ee96407SJérôme Duval 		* ((double)fMainTime / fTotalTime);
42242f70a5dSJérôme Duval 	if (reset) {
42342f70a5dSJérôme Duval 		fRightTime = fTotalTime;
42442f70a5dSJérôme Duval 		fLeftTime = 0;
4253ee96407SJérôme Duval 		fBitmapView->fLeftX = 14 + (fBitmapView->fRight - 15)
4263ee96407SJérôme Duval 			* ((double)fLeftTime / fTotalTime);
4273ee96407SJérôme Duval 		fBitmapView->fRightX = 15 + (fBitmapView->fRight - 16)
4283ee96407SJérôme Duval 			* ((double)fRightTime / fTotalTime);
429ad0c65eaSJérôme Duval 		_RenderBitmap();
43042f70a5dSJérôme Duval 	}
43142f70a5dSJérôme Duval 	Invalidate();
43242f70a5dSJérôme Duval }
43342f70a5dSJérôme Duval 
43442f70a5dSJérôme Duval void
43542f70a5dSJérôme Duval TrackSlider::SetTotalTime(bigtime_t timestamp, bool reset)
43642f70a5dSJérôme Duval {
43742f70a5dSJérôme Duval 	fTotalTime = timestamp;
43842f70a5dSJérôme Duval 	if (reset) {
43942f70a5dSJérôme Duval 		fMainTime = 0;
44042f70a5dSJérôme Duval 		fRightTime = fTotalTime;
44142f70a5dSJérôme Duval 		fLeftTime = 0;
44242f70a5dSJérôme Duval 	}
4433ee96407SJérôme Duval 	fBitmapView->fPositionX = 15 + (fBitmapView->fRight - 14)
4443ee96407SJérôme Duval 		* ((double)fMainTime / fTotalTime);
4453ee96407SJérôme Duval 	fBitmapView->fLeftX = 14 + (fBitmapView->fRight - 15)
4463ee96407SJérôme Duval 		* ((double)fLeftTime / fTotalTime);
4473ee96407SJérôme Duval 	fBitmapView->fRightX = 15 + (fBitmapView->fRight - 16)
4483ee96407SJérôme Duval 		* ((double)fRightTime / fTotalTime);
449ad0c65eaSJérôme Duval 	_RenderBitmap();
45042f70a5dSJérôme Duval 	Invalidate();
45142f70a5dSJérôme Duval }
45242f70a5dSJérôme Duval 
45342f70a5dSJérôme Duval 
45442f70a5dSJérôme Duval void
45542f70a5dSJérôme Duval TrackSlider::ResetMainTime()
45642f70a5dSJérôme Duval {
45742f70a5dSJérôme Duval 	fMainTime = fLeftTime;
4583ee96407SJérôme Duval 	fBitmapView->fPositionX = 15 + (fBitmapView->fRight - 14)
4593ee96407SJérôme Duval 		* ((double)fMainTime / fTotalTime);
46042f70a5dSJérôme Duval 	Invalidate();
46142f70a5dSJérôme Duval }
46242f70a5dSJérôme Duval 
46342f70a5dSJérôme Duval 
46442f70a5dSJérôme Duval void
46542f70a5dSJérôme Duval TrackSlider::FrameResized(float width, float height)
46642f70a5dSJérôme Duval {
46742f70a5dSJérôme Duval 	fBitmapView->fRight = Bounds().right - kLeftRightTrackSliderWidth;
4683ee96407SJérôme Duval 	fBitmapView->fPositionX = 15 + (fBitmapView->fRight - 14)
4693ee96407SJérôme Duval 		* ((double)fMainTime / fTotalTime);
470ad0c65eaSJérôme Duval 	_InitBitmap();
4713ee96407SJérôme Duval 	fBitmapView->fLeftX = 14 + (fBitmapView->fRight - 15)
4723ee96407SJérôme Duval 		* ((double)fLeftTime / fTotalTime);
4733ee96407SJérôme Duval 	fBitmapView->fRightX = 15 + (fBitmapView->fRight - 16)
4743ee96407SJérôme Duval 		* ((double)fRightTime / fTotalTime);
475ad0c65eaSJérôme Duval 	_RenderBitmap();
47642f70a5dSJérôme Duval 	Invalidate();
47742f70a5dSJérôme Duval }
47842f70a5dSJérôme Duval 
47942f70a5dSJérôme Duval 
4804c9da6dcSStephan Aßmus SliderOffscreenView::SliderOffscreenView(BRect frame, const char *name)
48142f70a5dSJérôme Duval 	: BView(frame, name, B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW),
48242f70a5dSJérôme Duval 	leftBitmap(BRect(BPoint(0,0), kLeftRightTrackSliderSize), B_CMAP8),
48342f70a5dSJérôme Duval 	rightBitmap(BRect(BPoint(0,0), kLeftRightTrackSliderSize), B_CMAP8),
4843ee96407SJérôme Duval 	leftThumbBitmap(BRect(0, 0, kLeftRightThumbWidth - 1,
4853ee96407SJérôme Duval 		kLeftRightThumbHeight - 1), B_CMAP8),
4863ee96407SJérôme Duval 	rightThumbBitmap(BRect(0, 0, kLeftRightThumbWidth - 1,
4873ee96407SJérôme Duval 		kLeftRightThumbHeight - 1), B_CMAP8)
48842f70a5dSJérôme Duval {
4893ee96407SJérôme Duval 	leftBitmap.SetBits(kLeftTrackSliderBits,
4903ee96407SJérôme Duval 		kLeftRightTrackSliderWidth * kLeftRightTrackSliderHeight, 0, B_CMAP8);
4913ee96407SJérôme Duval 	rightBitmap.SetBits(kRightTrackSliderBits,
4923ee96407SJérôme Duval 		kLeftRightTrackSliderWidth * kLeftRightTrackSliderHeight, 0, B_CMAP8);
4933ee96407SJérôme Duval 	leftThumbBitmap.SetBits(kLeftThumbBits,
4943ee96407SJérôme Duval 		kLeftRightThumbWidth * kLeftRightThumbHeight, 0, B_CMAP8);
4953ee96407SJérôme Duval 	rightThumbBitmap.SetBits(kRightThumbBits,
4963ee96407SJérôme Duval 		kLeftRightThumbWidth * kLeftRightThumbHeight, 0, B_CMAP8);
49742f70a5dSJérôme Duval }
49842f70a5dSJérôme Duval 
49942f70a5dSJérôme Duval 
50042f70a5dSJérôme Duval SliderOffscreenView::~SliderOffscreenView()
50142f70a5dSJérôme Duval {
50242f70a5dSJérôme Duval 
50342f70a5dSJérôme Duval }
50442f70a5dSJérôme Duval 
50542f70a5dSJérôme Duval 
50642f70a5dSJérôme Duval void
50742f70a5dSJérôme Duval SliderOffscreenView::DrawX()
50842f70a5dSJérôme Duval {
5095fa040e3SStephan Aßmus 	SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
51042f70a5dSJérôme Duval 	FillRect(Bounds());
51142f70a5dSJérôme Duval 
51257e2f323SJérôme Duval 	SetHighColor(189, 186, 189);
51357e2f323SJérôme Duval 	StrokeLine(BPoint(11, SLIDER_BASE + 1), BPoint(fRight, SLIDER_BASE + 1));
51457e2f323SJérôme Duval 	SetHighColor(0, 0, 0);
51557e2f323SJérôme Duval 	StrokeLine(BPoint(11, SLIDER_BASE + 2), BPoint(fRight, SLIDER_BASE + 2));
51657e2f323SJérôme Duval 	SetHighColor(255, 255, 255);
51757e2f323SJérôme Duval 	StrokeLine(BPoint(11, SLIDER_BASE + 17), BPoint(fRight, SLIDER_BASE + 17));
51857e2f323SJérôme Duval 	SetHighColor(231, 227, 231);
51957e2f323SJérôme Duval 	StrokeLine(BPoint(11, SLIDER_BASE + 18), BPoint(fRight, SLIDER_BASE + 18));
52057e2f323SJérôme Duval 
52157e2f323SJérôme Duval 	SetDrawingMode(B_OP_OVER);
52257e2f323SJérôme Duval 	SetLowColor(HighColor());
52357e2f323SJérôme Duval 
52457e2f323SJérôme Duval 	BPoint leftPoint(5, SLIDER_BASE + 1);
5253ee96407SJérôme Duval 	DrawBitmapAsync(&leftBitmap, BRect(BPoint(0, 0),
5263ee96407SJérôme Duval 		kLeftRightTrackSliderSize - BPoint(5, 0)),
52757e2f323SJérôme Duval 		BRect(leftPoint, leftPoint + kLeftRightTrackSliderSize - BPoint(5, 0)));
52857e2f323SJérôme Duval 	BPoint rightPoint(fRight + 1, SLIDER_BASE + 1);
52957e2f323SJérôme Duval 	DrawBitmapAsync(&rightBitmap, BRect(BPoint(5, 0), kLeftRightTrackSliderSize),
53057e2f323SJérôme Duval 		BRect(rightPoint, rightPoint + kLeftRightTrackSliderSize-BPoint(5, 0)));
53157e2f323SJérôme Duval 
53257e2f323SJérôme Duval 	SetHighColor(153, 153, 153);
53357e2f323SJérôme Duval 	FillRect(BRect(11, SLIDER_BASE + 3, fLeftX - 9, SLIDER_BASE + 16));
53457e2f323SJérôme Duval 	FillRect(BRect(fRightX + 9, SLIDER_BASE + 3, fRight, SLIDER_BASE + 16));
53557e2f323SJérôme Duval 	if (fLeftX > 19) {
5363ee96407SJérôme Duval 		StrokeLine(BPoint(fLeftX - 9, SLIDER_BASE + 3), BPoint(fLeftX - 6,
5373ee96407SJérôme Duval 			SLIDER_BASE + 3));
5383ee96407SJérôme Duval 		StrokeLine(BPoint(fLeftX - 9, SLIDER_BASE + 4), BPoint(fLeftX - 7,
5393ee96407SJérôme Duval 			SLIDER_BASE + 4));
5403ee96407SJérôme Duval 		StrokeLine(BPoint(fLeftX - 9, SLIDER_BASE + 5), BPoint(fLeftX - 8,
5413ee96407SJérôme Duval 			SLIDER_BASE + 5));
5423ee96407SJérôme Duval 		StrokeLine(BPoint(fLeftX - 9, SLIDER_BASE + 16), BPoint(fLeftX - 6,
5433ee96407SJérôme Duval 			SLIDER_BASE + 16));
5443ee96407SJérôme Duval 		StrokeLine(BPoint(fLeftX - 9, SLIDER_BASE + 15), BPoint(fLeftX - 7,
5453ee96407SJérôme Duval 			SLIDER_BASE + 15));
5463ee96407SJérôme Duval 		StrokeLine(BPoint(fLeftX - 9, SLIDER_BASE + 14), BPoint(fLeftX - 8,
5473ee96407SJérôme Duval 			SLIDER_BASE + 14));
54857e2f323SJérôme Duval 	}
54957e2f323SJérôme Duval 	if (fRightX < fRight - 5) {
5503ee96407SJérôme Duval 		StrokeLine(BPoint(fRightX + 5, SLIDER_BASE + 3), BPoint(fRightX + 8,
5513ee96407SJérôme Duval 			SLIDER_BASE + 3));
5523ee96407SJérôme Duval 		StrokeLine(BPoint(fRightX + 7, SLIDER_BASE + 4), BPoint(fRightX + 8,
5533ee96407SJérôme Duval 			SLIDER_BASE + 4));
5543ee96407SJérôme Duval 		StrokeLine(BPoint(fRightX + 8, SLIDER_BASE + 5), BPoint(fRightX + 8,
5553ee96407SJérôme Duval 			SLIDER_BASE + 6));
5563ee96407SJérôme Duval 		StrokeLine(BPoint(fRightX + 8, SLIDER_BASE + 13), BPoint(fRightX + 8,
5573ee96407SJérôme Duval 			SLIDER_BASE + 14));
5583ee96407SJérôme Duval 		StrokeLine(BPoint(fRightX + 5, SLIDER_BASE + 16), BPoint(fRightX + 8,
5593ee96407SJérôme Duval 			SLIDER_BASE + 16));
5603ee96407SJérôme Duval 		StrokeLine(BPoint(fRightX + 7, SLIDER_BASE + 15), BPoint(fRightX + 8,
5613ee96407SJérôme Duval 			SLIDER_BASE + 15));
56257e2f323SJérôme Duval 	}
56357e2f323SJérôme Duval 	SetHighColor(144, 186, 136);
56457e2f323SJérôme Duval 	FillRect(BRect(fLeftX + 1, SLIDER_BASE + 3, fRightX, SLIDER_BASE + 4));
56557e2f323SJérôme Duval 	FillRect(BRect(fLeftX + 1, SLIDER_BASE + 5, fLeftX + 2, SLIDER_BASE + 16));
56657e2f323SJérôme Duval 	SetHighColor(171, 221, 161);
56757e2f323SJérôme Duval 	FillRect(BRect(fLeftX + 3, SLIDER_BASE + 5, fRightX, SLIDER_BASE + 16));
56857e2f323SJérôme Duval 
56957e2f323SJérôme Duval 	int i = 17;
57057e2f323SJérôme Duval 	int j = 18;
57157e2f323SJérôme Duval 	SetHighColor(128, 128, 128);
57257e2f323SJérôme Duval 	for (; i < fLeftX - 9; i += 6) {
57357e2f323SJérôme Duval 		StrokeLine(BPoint(i, SLIDER_BASE + 7), BPoint(i, SLIDER_BASE + 13));
57457e2f323SJérôme Duval 	}
57557e2f323SJérôme Duval 	SetHighColor(179, 179, 179);
57657e2f323SJérôme Duval 	for (; j < fLeftX - 9; j += 6) {
57757e2f323SJérôme Duval 		StrokeLine(BPoint(j, SLIDER_BASE + 7), BPoint(j, SLIDER_BASE + 13));
57857e2f323SJérôme Duval 	}
57957e2f323SJérôme Duval 
58057e2f323SJérôme Duval 	while (i <= fLeftX)
58157e2f323SJérôme Duval 		i += 6;
58257e2f323SJérôme Duval 	while (j <= fLeftX)
58357e2f323SJérôme Duval 		j += 6;
58457e2f323SJérôme Duval 
58557e2f323SJérôme Duval 	SetHighColor(144, 186, 136);
58657e2f323SJérôme Duval 	for (; i <= fRightX; i += 6) {
58757e2f323SJérôme Duval 		StrokeLine(BPoint(i, SLIDER_BASE + 7), BPoint(i, SLIDER_BASE + 13));
58857e2f323SJérôme Duval 	}
58957e2f323SJérôme Duval 	SetHighColor(189, 244, 178);
59057e2f323SJérôme Duval 	for (; j <= fRightX; j += 6) {
59157e2f323SJérôme Duval 		StrokeLine(BPoint(j, SLIDER_BASE + 7), BPoint(j, SLIDER_BASE + 13));
59257e2f323SJérôme Duval 	}
59357e2f323SJérôme Duval 
59457e2f323SJérôme Duval 	while (i <= fRightX + 9)
59557e2f323SJérôme Duval 		i += 6;
59657e2f323SJérôme Duval 	while (j <= fRightX + 9)
59757e2f323SJérôme Duval 		j += 6;
59857e2f323SJérôme Duval 
59957e2f323SJérôme Duval 	SetHighColor(128, 128, 128);
60057e2f323SJérôme Duval 	for (; i <= fRight + 1; i += 6) {
60157e2f323SJérôme Duval 		StrokeLine(BPoint(i, SLIDER_BASE + 7), BPoint(i, SLIDER_BASE + 13));
60257e2f323SJérôme Duval 	}
60357e2f323SJérôme Duval 	SetHighColor(179, 179, 179);
60457e2f323SJérôme Duval 	for (; j <= fRight + 1; j += 6) {
60557e2f323SJérôme Duval 		StrokeLine(BPoint(j, SLIDER_BASE + 7), BPoint(j, SLIDER_BASE + 13));
60657e2f323SJérôme Duval 	}
60757e2f323SJérôme Duval 
60857e2f323SJérôme Duval 	SetLowColor(HighColor());
60957e2f323SJérôme Duval 
61057e2f323SJérôme Duval 	BPoint leftThumbPoint(fLeftX - 8, SLIDER_BASE + 3);
6113ee96407SJérôme Duval 	DrawBitmapAsync(&leftThumbBitmap, BRect(BPoint(0, 0),
6123ee96407SJérôme Duval 		kLeftRightThumbSize - BPoint(7, 0)),
6133ee96407SJérôme Duval 		BRect(leftThumbPoint, leftThumbPoint
6143ee96407SJérôme Duval 			+ kLeftRightThumbSize - BPoint(7, 0)));
61557e2f323SJérôme Duval 
61657e2f323SJérôme Duval 	BPoint rightThumbPoint(fRightX, SLIDER_BASE + 3);
6173ee96407SJérôme Duval 	DrawBitmapAsync(&rightThumbBitmap, BRect(BPoint(6, 0),
6183ee96407SJérôme Duval 		kLeftRightThumbSize),
6193ee96407SJérôme Duval 		BRect(rightThumbPoint, rightThumbPoint
6203ee96407SJérôme Duval 			+ kLeftRightThumbSize-BPoint(6, 0)));
62157e2f323SJérôme Duval 
62242f70a5dSJérôme Duval 	Sync();
62357e2f323SJérôme Duval }
624