MediaControlView.cpp 44.9 KB
Newer Older
1 2 3 4
/*****************************************************************************
 * MediaControlView.cpp: beos interface
 *****************************************************************************
 * Copyright (C) 1999, 2000, 2001 VideoLAN
5
 * $Id$
6 7
 *
 * Authors: Tony Castley <tony@castley.net>
8
 *          Stephan Aßmus <stippi@yellowbites.com>
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

/* System headers */
#include <InterfaceKit.h>
#include <AppKit.h>
Eric Petit's avatar
Eric Petit committed
28
#include <String.h>
29 30 31 32 33
#include <string.h>

/* VLC headers */
#include <vlc/vlc.h>
#include <vlc/intf.h>
34
#include <vlc/input.h>
Eric Petit's avatar
Eric Petit committed
35 36 37 38
extern "C"
{
  #include <audio_output.h>
}
39 40 41

/* BeOS interface headers */
#include "Bitmaps.h"
42 43 44
#include "DrawingTidbits.h"
#include "InterfaceWindow.h"
#include "MsgVals.h"
45
#include "TransportButton.h"
46
#include "ListViews.h"
47 48
#include "MediaControlView.h"

49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
#define BORDER_INSET 6.0
#define MIN_SPACE 4.0
#define SPEAKER_SLIDER_DIST 6.0
#define VOLUME_MIN_WIDTH 70.0
#define DIM_LEVEL 0.4
#define VOLUME_SLIDER_LAYOUT_WEIGHT 2.0
#define SEEK_SLIDER_KNOB_WIDTH 8.0

// slider colors are hardcoded here, because that's just
// what they currently are within those bitmaps
const rgb_color kGreen = (rgb_color){ 152, 203, 152, 255 };
const rgb_color kGreenShadow = (rgb_color){ 102, 152, 102, 255 };
const rgb_color kBackground = (rgb_color){ 216, 216, 216, 255 };
const rgb_color kSeekGreen = (rgb_color){ 171, 221, 161, 255 };
const rgb_color kSeekGreenShadow = (rgb_color){ 144, 186, 136, 255 };
const rgb_color kSeekRed = (rgb_color){ 255, 0, 0, 255 };
const rgb_color kSeekRedLight = (rgb_color){ 255, 152, 152, 255 };
const rgb_color kSeekRedShadow = (rgb_color){ 178, 0, 0, 255 };
67

68
#define DISABLED_SEEK_MESSAGE _("Drop files to play")
69
#define SEEKSLIDER_RANGE 2048
70 71

enum
72
{
73 74 75 76 77 78 79
	MSG_REWIND				= 'rwnd',
	MSG_FORWARD				= 'frwd',
	MSG_SKIP_BACKWARDS		= 'skpb',
	MSG_SKIP_FORWARD		= 'skpf',
};

// constructor
80
MediaControlView::MediaControlView( intf_thread_t * _p_intf, BRect frame)
81 82
	: BBox(frame, NULL, B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS | B_PULSE_NEEDED,
		   B_PLAIN_BORDER),
83
      p_intf( _p_intf ),
84 85
      fCurrentRate(INPUT_RATE_DEFAULT),
      fCurrentStatus(-1),
86 87
      fBottomControlHeight(0.0),
      fIsEnabled( true )
88 89
{
	BRect frame(0.0, 0.0, 10.0, 10.0);
90
	
91
    // Seek Slider
Eric Petit's avatar
Eric Petit committed
92
    fSeekSlider = new SeekSlider( p_intf, frame, "seek slider", this );
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
    fSeekSlider->SetValue(0);
    fSeekSlider->ResizeToPreferred();
    AddChild( fSeekSlider );

    // Buttons
    // Skip Back
    frame.SetRightBottom(kSkipButtonSize);
	fBottomControlHeight = kRewindBitmapHeight - 1.0;
    fSkipBack = new TransportButton(frame, B_EMPTY_STRING,
                                    kSkipBackBitmapBits,
                                    kPressedSkipBackBitmapBits,
                                    kDisabledSkipBackBitmapBits,
                                    new BMessage(MSG_SKIP_BACKWARDS));
    AddChild( fSkipBack );

	// Play Pause
    frame.SetRightBottom(kPlayButtonSize);
	if (fBottomControlHeight < kPlayPauseBitmapHeight - 1.0)
		fBottomControlHeight = kPlayPauseBitmapHeight - 1.0;
    fPlayPause = new PlayPauseButton(frame, B_EMPTY_STRING,
                                     kPlayButtonBitmapBits,
                                     kPressedPlayButtonBitmapBits,
                                     kDisabledPlayButtonBitmapBits,
                                     kPlayingPlayButtonBitmapBits,
                                     kPressedPlayingPlayButtonBitmapBits,
                                     kPausedPlayButtonBitmapBits,
                                     kPressedPausedPlayButtonBitmapBits,
                                     new BMessage(START_PLAYBACK));

    AddChild( fPlayPause );

    // Skip Foward
    frame.SetRightBottom(kSkipButtonSize);
    fSkipForward = new TransportButton(frame, B_EMPTY_STRING,
                                       kSkipForwardBitmapBits,
                                       kPressedSkipForwardBitmapBits,
                                       kDisabledSkipForwardBitmapBits,
                                       new BMessage(MSG_SKIP_FORWARD));
    AddChild( fSkipForward );
132

133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
	// Forward
	fForward = new TransportButton(frame, B_EMPTY_STRING,
								   kForwardBitmapBits,
								   kPressedForwardBitmapBits,
								   kDisabledForwardBitmapBits,
								   new BMessage(MSG_FORWARD));
//	AddChild( fForward );

	// Rewind
	fRewind = new TransportButton(frame, B_EMPTY_STRING,
								  kRewindBitmapBits,
								  kPressedRewindBitmapBits,
								  kDisabledRewindBitmapBits,
								  new BMessage(MSG_REWIND));
//	AddChild( fRewind );

    // Stop
    frame.SetRightBottom(kStopButtonSize);
	if (fBottomControlHeight < kStopBitmapHeight - 1.0)
		fBottomControlHeight = kStopBitmapHeight - 1.0;
    fStop = new TransportButton(frame, B_EMPTY_STRING,
                                kStopButtonBitmapBits,
                                kPressedStopButtonBitmapBits,
                                kDisabledStopButtonBitmapBits,
                                new BMessage(STOP_PLAYBACK));
	AddChild( fStop );

	// Mute
    frame.SetRightBottom(kSpeakerButtonSize);
	if (fBottomControlHeight < kSpeakerIconBitmapHeight - 1.0)
		fBottomControlHeight = kSpeakerIconBitmapHeight - 1.0;
    fMute = new TransportButton(frame, B_EMPTY_STRING,
                                kSpeakerIconBits,
                                kPressedSpeakerIconBits,
                                kSpeakerIconBits,
                                new BMessage(VOLUME_MUTE));

	AddChild( fMute );

    // Volume Slider
	fVolumeSlider = new VolumeSlider(BRect(0.0, 0.0, VOLUME_MIN_WIDTH,
										   kVolumeSliderBitmapHeight - 1.0),
									 "volume slider", 1, AOUT_VOLUME_MAX,
									 new BMessage(VOLUME_CHG));
177
	fVolumeSlider->SetValue( config_GetInt( p_intf, "volume" ) );
178
	AddChild( fVolumeSlider );
Eric Petit's avatar
Eric Petit committed
179 180 181 182 183 184
	
	// Position Info View
    fPositionInfo = new PositionInfoView(BRect(0.0, 0.0, 10.0, 10.0), "led",
                                         p_intf);
    fPositionInfo->ResizeToPreferred();
    AddChild( fPositionInfo );
185 186
}

187
// destructor
188 189 190 191
MediaControlView::~MediaControlView()
{
}

192 193 194 195 196 197 198 199 200 201 202 203
// AttachedToWindow
void
MediaControlView::AttachedToWindow()
{
	// we are now a valid BHandler
	fRewind->SetTarget(this);
	fForward->SetTarget(this);
	fSkipBack->SetTarget(this);
	fSkipForward->SetTarget(this);
	fVolumeSlider->SetTarget(Window());

	BRect r(_MinFrame());
204 205 206 207 208 209 210 211 212 213 214
	if (BMenuBar* menuBar = Window()->KeyMenuBar()) {
		float width, height;
		menuBar->GetPreferredSize(&width, &height);
//		r.bottom += menuBar->Bounds().Height();
		r.bottom += height;
		// see that our calculated minimal width is not smaller than what
		// the menubar can be
		width -= r.Width();
		if (width > 0.0)
			r.right += width;
	}
215

Eric Petit's avatar
Eric Petit committed
216
	Window()->SetSizeLimits(r.Width(), r.Width() * 1.8, r.Height(), r.Height() * 1.3);
217 218 219 220 221 222 223 224 225 226 227 228
	if (!Window()->Bounds().Contains(r))
		Window()->ResizeTo(r.Width(), r.Height());
	else
		FrameResized(Bounds().Width(), Bounds().Height());

	// get pulse message every two frames
	Window()->SetPulseRate(80000);
}

// FrameResized
void
MediaControlView::FrameResized(float width, float height)
229
{
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
	BRect r(Bounds());
	// make sure we don't leave dirty pixels
	// (B_FULL_UPDATE_ON_RESIZE == annoying flicker -> this is smarter)
	if (fOldBounds.Width() < r.Width())
		Invalidate(BRect(fOldBounds.right, fOldBounds.top + 1.0,
						 fOldBounds.right, fOldBounds.bottom - 1.0));
	else
		Invalidate(BRect(r.right, r.top + 1.0,
						 r.right, r.bottom - 1.0));
	if (fOldBounds.Height() < r.Height())
		Invalidate(BRect(fOldBounds.left + 1.0, fOldBounds.bottom,
						 fOldBounds.right - 1.0, fOldBounds.bottom));
	else
		Invalidate(BRect(r.left + 1.0, r.bottom,
						 r.right - 1.0, r.bottom));
	// remember for next time
	fOldBounds = r;
	// layout controls
	r.InsetBy(BORDER_INSET, BORDER_INSET);
	_LayoutControls(r);
250 251
}

252 253 254
// GetPreferredSize
void
MediaControlView::GetPreferredSize(float* width, float* height)
255
{
256 257 258 259 260 261
	if (width && height)
	{
		BRect r(_MinFrame());
		*width = r.Width();
		*height = r.Height();
	}
262 263
}

264 265 266
// MessageReceived
void
MediaControlView::MessageReceived(BMessage* message)
267
{
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
	switch (message->what)
	{
		case MSG_REWIND:
			break;
		case MSG_FORWARD:
			break;
		case MSG_SKIP_BACKWARDS:
			Window()->PostMessage(NAVIGATE_PREV);
			break;
		case MSG_SKIP_FORWARD:
			Window()->PostMessage(NAVIGATE_NEXT);
			break;
		default:
		    BBox::MessageReceived(message);
		    break;
	}
}

// Pulse
void
MediaControlView::Pulse()
{
	InterfaceWindow* window = dynamic_cast<InterfaceWindow*>(Window());
	if (window && window->IsStopped())
			fPlayPause->SetStopped();
Eric Petit's avatar
Eric Petit committed
293 294 295 296

    unsigned short i_volume;
    aout_VolumeGet( p_intf, (audio_volume_t*)&i_volume );
    fVolumeSlider->SetValue( i_volume );
297 298 299 300
}

// SetProgress
void
301
MediaControlView::SetProgress( float position )
302
{
303
	fSeekSlider->SetPosition( position );
304 305 306 307 308 309 310 311 312
}

// SetStatus
void
MediaControlView::SetStatus(int status, int rate)
{
	// we need to set the button status periodically
	// (even if it is the same) to get a blinking button
	fCurrentStatus = status;
313 314 315
    switch( status )
    {
        case PLAYING_S:
316
            fPlayPause->SetPlaying();
317 318
            break;
        case PAUSE_S:
319
            fPlayPause->SetPaused();
320 321
            break;
        default:
322
            fPlayPause->SetStopped();
323 324
            break;
    }
325 326 327
	if (rate != fCurrentRate)
	{
		fCurrentRate = rate;
328
	    if ( rate < INPUT_RATE_DEFAULT )
329 330 331 332 333 334 335 336 337 338
	    {
	    	// TODO: ...
	    }
	}
}

// SetEnabled
void
MediaControlView::SetEnabled(bool enabled)
{
339 340 341 342 343 344 345 346
    if( ( enabled && fIsEnabled ) ||
        ( !enabled && !fIsEnabled ) )
    {
        /* do not redraw if it is not necessary */
        return;
    }
    
	if( LockLooper() )
347 348 349 350 351 352 353 354 355 356 357
	{
		fSkipBack->SetEnabled( enabled );
		fPlayPause->SetEnabled( enabled );
		fSkipForward->SetEnabled( enabled );
		fStop->SetEnabled( enabled );
		fMute->SetEnabled( enabled );
		fVolumeSlider->SetEnabled( enabled );
		fSeekSlider->SetEnabled( enabled );
		fRewind->SetEnabled( enabled );
		fForward->SetEnabled( enabled );
		UnlockLooper();
358
		fIsEnabled = enabled;
359
	}
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
}

// SetAudioEnabled
void
MediaControlView::SetAudioEnabled(bool enabled)
{
	fMute->SetEnabled(enabled);
	fVolumeSlider->SetEnabled(enabled);
}

// GetVolume
uint32
MediaControlView::GetVolume() const
{
	return fVolumeSlider->Value();
375 376
}

377 378 379
// SetSkippable
void
MediaControlView::SetSkippable(bool backward, bool forward)
380
{
381 382
	fSkipBack->SetEnabled(backward);
	fSkipForward->SetEnabled(forward);
383 384
}

385 386 387
// SetMuted
void
MediaControlView::SetMuted(bool mute)
388
{
389
	fVolumeSlider->SetMuted(mute);
390 391
}

392 393 394
// _LayoutControls
void
MediaControlView::_LayoutControls(BRect frame) const
395
{
396 397 398 399 400 401 402 403 404 405 406
	// seek slider
	BRect r(frame);
	// calculate absolutly minimal width
	float minWidth = fSkipBack->Bounds().Width();
//	minWidth += fRewind->Bounds().Width();
	minWidth += fStop->Bounds().Width();
	minWidth += fPlayPause->Bounds().Width();
//	minWidth += fForward->Bounds().Width();
	minWidth += fSkipForward->Bounds().Width();
	minWidth += fMute->Bounds().Width();
	minWidth += VOLUME_MIN_WIDTH;
Eric Petit's avatar
Eric Petit committed
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
	
	// layout time slider and info view
    float width, height;
    fPositionInfo->GetBigPreferredSize( &width, &height );
    float ratio = width / height;
    width = r.Height() * ratio;
    if (frame.Width() - minWidth - MIN_SPACE >= width
              && frame.Height() >= height)
    {
        r.right = r.left + width;
        fPositionInfo->SetMode(PositionInfoView::MODE_BIG);
        _LayoutControl(fPositionInfo, r, true, true);
        frame.left = r.right + MIN_SPACE;
        r.left = frame.left;
        r.right = frame.right;
    //    r.bottom = r.top + r.Height() / 2.0 - MIN_SPACE / 2.0;
        r.bottom = r.top + fSeekSlider->Bounds().Height();
        _LayoutControl(fSeekSlider, r, true);
    }
    else
    {
        fPositionInfo->GetPreferredSize( &width, &height );
        fPositionInfo->SetMode(PositionInfoView::MODE_SMALL);
        fPositionInfo->ResizeTo(width, height);
        r.bottom = r.top + r.Height() / 2.0 - MIN_SPACE / 2.0;
        r.right = r.left + fPositionInfo->Bounds().Width();
        _LayoutControl(fPositionInfo, r, true );
        r.left = r.right + MIN_SPACE;
        r.right = frame.right;
        _LayoutControl(fSeekSlider, r, true);
    }
438 439 440 441 442
	float currentWidth = frame.Width();
	float space = (currentWidth - minWidth) / 6.0;//8.0;
	// apply weighting
	space = MIN_SPACE + (space - MIN_SPACE) / VOLUME_SLIDER_LAYOUT_WEIGHT;
	// layout controls with "space" inbetween
Eric Petit's avatar
Eric Petit committed
443
	r.left = frame.left;
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
	r.top = r.bottom + MIN_SPACE + 1.0;
	r.bottom = frame.bottom;
	// skip back
	r.right = r.left + fSkipBack->Bounds().Width();
	_LayoutControl(fSkipBack, r);
	// rewind
//	r.left = r.right + space;
//	r.right = r.left + fRewind->Bounds().Width();
//	_LayoutControl(fRewind, r);
	// stop
	r.left = r.right + space;
	r.right = r.left + fStop->Bounds().Width();
	_LayoutControl(fStop, r);
	// play/pause
	r.left = r.right + space;
	r.right = r.left + fPlayPause->Bounds().Width();
	_LayoutControl(fPlayPause, r);
	// forward
//	r.left = r.right + space;
//	r.right = r.left + fForward->Bounds().Width();
//	_LayoutControl(fForward, r);
	// skip forward
	r.left = r.right + space;
	r.right = r.left + fSkipForward->Bounds().Width();
	_LayoutControl(fSkipForward, r);
	// speaker icon
	r.left = r.right + space + space;
	r.right = r.left + fMute->Bounds().Width();
	_LayoutControl(fMute, r);
	// volume slider
	r.left = r.right + SPEAKER_SLIDER_DIST; // keep speaker icon and volume slider attached
	r.right = frame.right;
	_LayoutControl(fVolumeSlider, r, true);
477 478
}

479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
// _MinFrame
BRect           
MediaControlView::_MinFrame() const
{
	// add up width of controls along bottom (seek slider will likely adopt)
	float minWidth = 2 * BORDER_INSET;
	minWidth += fSkipBack->Bounds().Width() + MIN_SPACE;
//	minWidth += fRewind->Bounds().Width() + MIN_SPACE;
	minWidth += fStop->Bounds().Width() + MIN_SPACE;
	minWidth += fPlayPause->Bounds().Width() + MIN_SPACE;
//	minWidth += fForward->Bounds().Width() + MIN_SPACE;
	minWidth += fSkipForward->Bounds().Width() + MIN_SPACE + MIN_SPACE;
	minWidth += fMute->Bounds().Width() + SPEAKER_SLIDER_DIST;
	minWidth += VOLUME_MIN_WIDTH;

	// add up height of seek slider and heighest control on bottom
	float minHeight = 2 * BORDER_INSET;
	minHeight += fSeekSlider->Bounds().Height() + MIN_SPACE + MIN_SPACE / 2.0;
	minHeight += fBottomControlHeight;
	return BRect(0.0, 0.0, minWidth - 1.0, minHeight - 1.0);
}

// _LayoutControl
void
Eric Petit's avatar
Eric Petit committed
503 504
MediaControlView::_LayoutControl(BView* view, BRect frame,
                                 bool resizeWidth, bool resizeHeight) const
505
{
Eric Petit's avatar
Eric Petit committed
506 507 508 509 510
    if (!resizeHeight)
	    // center vertically
	    frame.top = (frame.top + frame.bottom) / 2.0 - view->Bounds().Height() / 2.0;
	if (!resizeWidth)
	    //center horizontally
511 512
		frame.left = (frame.left + frame.right) / 2.0 - view->Bounds().Width() / 2.0;
	view->MoveTo(frame.LeftTop());
Eric Petit's avatar
Eric Petit committed
513 514 515 516
	float width = resizeWidth ? frame.Width() : view->Bounds().Width();
	float height = resizeHeight ? frame.Height() : view->Bounds().Height();
    if (resizeWidth || resizeHeight)
        view->ResizeTo(width, height);
517 518 519
}


520 521

/*****************************************************************************
522
 * SeekSlider
523
 *****************************************************************************/
Eric Petit's avatar
Eric Petit committed
524 525
SeekSlider::SeekSlider( intf_thread_t * _p_intf,
                        BRect frame, const char* name, MediaControlView *owner )
526 527
	: BControl(frame, name, NULL, NULL, B_FOLLOW_NONE,
			   B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
Eric Petit's avatar
Eric Petit committed
528
	  p_intf(_p_intf),
529
	  fOwner(owner),
Eric Petit's avatar
Eric Petit committed
530
	  fTracking(false)
531
{
532 533 534 535
	BFont font(be_plain_font);
	font.SetSize(9.0);
	SetFont(&font);
}
536

537 538
SeekSlider::~SeekSlider()
{
539 540
}

541 542 543 544 545
/*****************************************************************************
 * VolumeSlider::AttachedToWindow
 *****************************************************************************/
void
SeekSlider::AttachedToWindow()
546
{
547 548 549
	BControl::AttachedToWindow();
	SetViewColor(B_TRANSPARENT_32_BIT);
}
550

551 552 553 554 555 556 557 558 559 560 561
/*****************************************************************************
 * VolumeSlider::Draw
 *****************************************************************************/
void
SeekSlider::Draw(BRect updateRect)
{
	BRect r(Bounds());
	float knobWidth2 = SEEK_SLIDER_KNOB_WIDTH / 2.0;
	float sliderStart = (r.left + knobWidth2);
	float sliderEnd = (r.right - knobWidth2);
	float knobPos = sliderStart
Eric Petit's avatar
Eric Petit committed
562 563
					+ floorf((sliderEnd - sliderStart - 1.0) * Value()
					/ SEEKSLIDER_RANGE);
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
	// draw both sides (the original from Be doesn't seem
	// to make a difference for enabled/disabled state)
//	DrawBitmapAsync(fLeftSideBits, r.LeftTop());
//	DrawBitmapAsync(fRightSideBits, BPoint(sliderEnd + 1.0, r.top));
	// colors for the slider area between the two bitmaps
	rgb_color background = kBackground;//ui_color(B_PANEL_BACKGROUND_COLOR);
	rgb_color shadow = tint_color(background, B_DARKEN_2_TINT);
	rgb_color softShadow = tint_color(background, B_DARKEN_1_TINT);
	rgb_color darkShadow = tint_color(background, B_DARKEN_4_TINT);
	rgb_color midShadow = tint_color(background, B_DARKEN_3_TINT);
	rgb_color light = tint_color(background, B_LIGHTEN_MAX_TINT);
	rgb_color softLight = tint_color(background, B_LIGHTEN_1_TINT);
	rgb_color green = kSeekGreen;
	rgb_color greenShadow = kSeekGreenShadow;
	rgb_color black = kBlack;
	rgb_color dotGrey = midShadow;
	rgb_color dotGreen = greenShadow;
	// draw frame
	_StrokeFrame(r, softShadow, softShadow, softLight, softLight);
	r.InsetBy(1.0, 1.0);
	_StrokeFrame(r, black, black, light, light);
	if (IsEnabled())
	{
		r.InsetBy(1.0, 1.0);
		// inner shadow
		_StrokeFrame(r, greenShadow, greenShadow, green, green);
		r.top++;
		r.left++;
		_StrokeFrame(r, greenShadow, greenShadow, green, green);
		// inside area
		r.InsetBy(1.0, 1.0);
		SetHighColor(green);
		FillRect(r);
		// dots
		int32 dotCount = (int32)(r.Width() / 6.0);
		BPoint dotPos;
		dotPos.y = r.top + 2.0;
		SetHighColor(dotGreen);
		for (int32 i = 0; i < dotCount; i++)
		{
			dotPos.x = sliderStart + i * 6.0 + 5.0;
			StrokeLine(dotPos, BPoint(dotPos.x, dotPos.y + 6.0));
		}
		// slider handle
		r.top -= 4.0;
		r.bottom += 3.0;
		r.left = knobPos - knobWidth2;
		r.right = knobPos + knobWidth2;
		// black outline
		float handleBottomSize = 2.0;
		float handleArrowSize = 6.0;
		BeginLineArray(10);
			// upper handle
			AddLine(BPoint(r.left, r.top + handleBottomSize),
					BPoint(r.left, r.top), black);
			AddLine(BPoint(r.left + 1.0, r.top),
					BPoint(r.right, r.top), black);
			AddLine(BPoint(r.right, r.top + 1.0),
					BPoint(r.right, r.top + handleBottomSize), black);
			AddLine(BPoint(r.right - 1.0, r.top + handleBottomSize + 1.0),
					BPoint(knobPos, r.top + handleArrowSize), black);
			AddLine(BPoint(knobPos - 1.0, r.top + handleArrowSize - 1.0),
					BPoint(r.left + 1.0, r.top + handleBottomSize + 1.0), black);
			// lower handle
			AddLine(BPoint(r.left, r.bottom),
					BPoint(r.left, r.bottom - handleBottomSize), black);
			AddLine(BPoint(r.left + 1.0, r.bottom - handleBottomSize - 1.0),
					BPoint(knobPos, r.bottom - handleArrowSize), black);
			AddLine(BPoint(knobPos + 1.0, r.bottom - handleArrowSize + 1.0),
					BPoint(r.right, r.bottom - handleBottomSize), black);
			AddLine(BPoint(r.right, r.bottom - handleBottomSize + 1.0),
					BPoint(r.right, r.bottom), black);
			AddLine(BPoint(r.right - 1.0, r.bottom),
					BPoint(r.left + 1.0, r.bottom), black);
		EndLineArray();
		// inner red light and shadow lines
		r.InsetBy(1.0, 1.0);
		handleBottomSize--;
		handleArrowSize -= 2.0;
		BeginLineArray(10);
			// upper handle
			AddLine(BPoint(r.left, r.top + handleBottomSize),
					BPoint(r.left, r.top), kSeekRedLight);
			AddLine(BPoint(r.left + 1.0, r.top),
					BPoint(r.right, r.top), kSeekRedLight);
			AddLine(BPoint(r.right, r.top + 1.0),
					BPoint(r.right, r.top + handleBottomSize), kSeekRedShadow);
			AddLine(BPoint(r.right - 1.0, r.top + handleBottomSize + 1.0),
					BPoint(knobPos, r.top + handleArrowSize), kSeekRedShadow);
			AddLine(BPoint(knobPos - 1.0, r.top + handleArrowSize - 1.0),
					BPoint(r.left + 1.0, r.top + handleBottomSize + 1.0), kSeekRedLight);
			// lower handle
			AddLine(BPoint(r.left, r.bottom),
					BPoint(r.left, r.bottom - handleBottomSize), kSeekRedLight);
			AddLine(BPoint(r.left + 1.0, r.bottom - handleBottomSize - 1.0),
					BPoint(knobPos, r.bottom - handleArrowSize), kSeekRedLight);
			AddLine(BPoint(knobPos + 1.0, r.bottom - handleArrowSize + 1.0),
					BPoint(r.right, r.bottom - handleBottomSize), kSeekRedShadow);
			AddLine(BPoint(r.right, r.bottom - handleBottomSize + 1.0),
					BPoint(r.right, r.bottom), kSeekRedShadow);
			AddLine(BPoint(r.right - 1.0, r.bottom),
					BPoint(r.left + 1.0, r.bottom), kSeekRedShadow);
		EndLineArray();
		// fill rest of handles with red
		SetHighColor(kSeekRed);
		r.InsetBy(1.0, 1.0);
		handleArrowSize -= 2.0;
		BPoint arrow[3];
		// upper handle arrow
		arrow[0].x = r.left;
		arrow[0].y = r.top;
		arrow[1].x = r.right;
		arrow[1].y = r.top;
		arrow[2].x = knobPos;
		arrow[2].y = r.top + handleArrowSize;
		FillPolygon(arrow, 3);
		// lower handle arrow
		arrow[0].x = r.left;
		arrow[0].y = r.bottom;
		arrow[1].x = r.right;
		arrow[1].y = r.bottom;
		arrow[2].x = knobPos;
		arrow[2].y = r.bottom - handleArrowSize;
		FillPolygon(arrow, 3);
	}
	else
	{
		r.InsetBy(1.0, 1.0);
		_StrokeFrame(r, darkShadow, darkShadow, darkShadow, darkShadow);
		r.InsetBy(1.0, 1.0);
		_StrokeFrame(r, darkShadow, darkShadow, darkShadow, darkShadow);
		r.InsetBy(1.0, 1.0);
		SetHighColor(darkShadow);
		SetLowColor(shadow);
		// stripes
699
		float width = floorf(StringWidth(DISABLED_SEEK_MESSAGE));
700
		float textPos = r.left + r.Width() / 2.0 - width / 2.0;
Eric Petit's avatar
Eric Petit committed
701
		pattern stripes = {{ 0xc7, 0x8f, 0x1f, 0x3e, 0x7c, 0xf8, 0xf1, 0xe3 }};
702 703 704 705 706 707 708 709 710 711 712 713 714 715
		BRect stripesRect(r);
		stripesRect.right = textPos - 5.0;
		FillRect(stripesRect, stripes);
		stripesRect.left = textPos + width + 3.0;
		stripesRect.right = r.right;
		FillRect(stripesRect, stripes);
		// info text
		r.left = textPos - 4.0;
		r.right = textPos + width + 2.0;
		FillRect(r);
		SetHighColor(shadow);
		SetLowColor(darkShadow);
		font_height fh;
		GetFontHeight(&fh);
716
		DrawString(DISABLED_SEEK_MESSAGE, BPoint(textPos, r.top + ceilf(fh.ascent) - 1.0));
717
	}
718 719
}

720 721 722 723 724
/*****************************************************************************
 * SeekSlider::MouseDown
 *****************************************************************************/
void
SeekSlider::MouseDown(BPoint where)
725
{
726 727 728 729 730 731 732
	if (IsEnabled() && Bounds().Contains(where))
	{
		SetValue(_ValueFor(where.x));
		fTracking = true;
		SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
	}
}
733

734 735 736 737 738 739 740 741 742 743 744
/*****************************************************************************
 * SeekSlider::MouseMoved
 *****************************************************************************/
void
SeekSlider::MouseMoved(BPoint where, uint32 code, const BMessage* dragMessage)
{
	if (fTracking)
	{
		SetValue(_ValueFor(where.x));
	}
}
745

746 747 748 749 750 751 752 753 754
/*****************************************************************************
 * SeekSlider::MouseUp
 *****************************************************************************/
void
SeekSlider::MouseUp(BPoint where)
{
	if (fTracking)
	{
		fTracking = false;
Eric Petit's avatar
Eric Petit committed
755 756 757 758 759 760 761 762 763 764
		input_thread_t * p_input;
		p_input = (input_thread_t *)
            vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_ANYWHERE );

        if( p_input )
        {
		    var_SetFloat( p_input, "position",
		                  (float) Value() / SEEKSLIDER_RANGE );
		    vlc_object_release( p_input );
		}
765 766
	}
}
767

768 769 770 771 772 773
/*****************************************************************************
 * SeekSlider::ResizeToPreferred
 *****************************************************************************/
void
SeekSlider::ResizeToPreferred()
{
774
	float width = 15.0 + StringWidth(DISABLED_SEEK_MESSAGE) + 15.0;
775 776
	ResizeTo(width, 17.0);
}
777

778 779 780 781 782 783
/*****************************************************************************
 * SeekSlider::SetPosition
 *****************************************************************************/
void
SeekSlider::SetPosition(float position)
{
784 785
	if ( LockLooper() )
	{
Eric Petit's avatar
Eric Petit committed
786 787 788 789
	    if( !fTracking )
	    {
		    SetValue( SEEKSLIDER_RANGE * position );
		}
790 791
		UnlockLooper();
	}
792
}
793

794 795 796 797 798 799 800 801 802 803
/*****************************************************************************
 * SeekSlider::_ValueFor
 *****************************************************************************/
int32
SeekSlider::_ValueFor(float xPos) const
{
	BRect r(Bounds());
	float knobWidth2 = SEEK_SLIDER_KNOB_WIDTH / 2.0;
	float sliderStart = (r.left + knobWidth2);
	float sliderEnd = (r.right - knobWidth2);
Eric Petit's avatar
Eric Petit committed
804
	int32 value =  (int32)(((xPos - sliderStart) * SEEKSLIDER_RANGE)
805
				  / (sliderEnd - sliderStart - 1.0));
Eric Petit's avatar
Eric Petit committed
806 807 808 809
	if (value < 0)
		value = 0;
	if (value > SEEKSLIDER_RANGE)
		value = SEEKSLIDER_RANGE;
810
	return value;
811 812 813
}

/*****************************************************************************
814
 * SeekSlider::_StrokeFrame
815
 *****************************************************************************/
816 817 818
void
SeekSlider::_StrokeFrame(BRect r, rgb_color left, rgb_color top,
						 rgb_color right, rgb_color bottom)
819
{
820 821 822 823 824 825
	BeginLineArray(4);
		AddLine(BPoint(r.left, r.bottom), BPoint(r.left, r.top), left);
		AddLine(BPoint(r.left + 1.0, r.top), BPoint(r.right, r.top), top);
		AddLine(BPoint(r.right, r.top + 1.0), BPoint(r.right, r.bottom), right);
		AddLine(BPoint(r.right - 1.0, r.bottom), BPoint(r.left + 1.0, r.bottom), bottom);
	EndLineArray();
826 827 828
}

/*****************************************************************************
829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
 * VolumeSlider
 *****************************************************************************/
VolumeSlider::VolumeSlider(BRect frame, const char* name, int32 minValue, int32 maxValue,
						   BMessage* message, BHandler* target)
	: BControl(frame, name, NULL, message, B_FOLLOW_NONE,
			   B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
	  fLeftSideBits(NULL),
	  fRightSideBits(NULL),
	  fKnobBits(NULL),
	  fTracking(false),
	  fMuted(false),
	  fMinValue(minValue),
	  fMaxValue(maxValue)
{
	SetTarget(target);

	// create bitmaps
	BRect r(BPoint(0.0, 0.0), kVolumeSliderBitmapSize);
	fLeftSideBits = new BBitmap(r, B_CMAP8);
	fRightSideBits = new BBitmap(r, B_CMAP8);
	r.Set(0.0, 0.0, kVolumeSliderKnobBitmapSize.x, kVolumeSliderKnobBitmapSize.y);
	fKnobBits = new BBitmap(r, B_CMAP8);

	_MakeBitmaps();
}

/*****************************************************************************
 * VolumeSlider destructor
 *****************************************************************************/
VolumeSlider::~VolumeSlider()
{
	delete fLeftSideBits;
	delete fRightSideBits;
	delete fKnobBits;
}

/*****************************************************************************
 * VolumeSlider::AttachedToWindow
 *****************************************************************************/
void
VolumeSlider::AttachedToWindow()
{
	BControl::AttachedToWindow();
	SetViewColor(B_TRANSPARENT_32_BIT);
}

/*****************************************************************************
 * VolumeSlider::SetValue
 *****************************************************************************/
void
VolumeSlider::SetValue(int32 value)
{
	if (value != Value())
	{
		BControl::SetValue(value);
		Invoke();
	}
}

/*****************************************************************************
 * VolumeSlider::SetEnabled
 *****************************************************************************/
void
VolumeSlider::SetEnabled(bool enable)
{
	if (enable != IsEnabled())
	{
		BControl::SetEnabled(enable);
		_MakeBitmaps();
		Invalidate();
	}
}

/*****************************************************************************
 * VolumeSlider::Draw
 *****************************************************************************/
void
VolumeSlider::Draw(BRect updateRect)
{
	if (IsValid())
	{
		BRect r(Bounds());
		float sliderSideWidth = kVolumeSliderBitmapWidth;
		float sliderStart = (r.left + sliderSideWidth);
		float sliderEnd = (r.right - sliderSideWidth);
		float knobPos = sliderStart
						+ (sliderEnd - sliderStart - 1.0) * (Value() - fMinValue)
						/ (fMaxValue - fMinValue);
		// draw both sides (the original from Be doesn't seem
		// to make a difference for enabled/disabled state)
		DrawBitmapAsync(fLeftSideBits, r.LeftTop());
		DrawBitmapAsync(fRightSideBits, BPoint(sliderEnd + 1.0, r.top));
		// colors for the slider area between the two bitmaps
		rgb_color background = kBackground;//ui_color(B_PANEL_BACKGROUND_COLOR);
		rgb_color shadow = tint_color(background, B_DARKEN_2_TINT);
		rgb_color softShadow = tint_color(background, B_DARKEN_1_TINT);
		rgb_color darkShadow = tint_color(background, B_DARKEN_4_TINT);
		rgb_color midShadow = tint_color(background, B_DARKEN_3_TINT);
		rgb_color light = tint_color(background, B_LIGHTEN_MAX_TINT);
		rgb_color softLight = tint_color(background, B_LIGHTEN_1_TINT);
		rgb_color green = kGreen;
		rgb_color greenShadow = kGreenShadow;
		rgb_color black = kBlack;
		rgb_color dotGrey = midShadow;
		rgb_color dotGreen = greenShadow;
		// make dimmed version of colors if we're disabled
		if (!IsEnabled())
		{
			shadow = (rgb_color){ 200, 200, 200, 255 };
			softShadow = dimmed_color_cmap8(softShadow, background, DIM_LEVEL);
			darkShadow = dimmed_color_cmap8(darkShadow, background, DIM_LEVEL);
			midShadow = shadow;
			light = dimmed_color_cmap8(light, background, DIM_LEVEL);
			softLight = dimmed_color_cmap8(softLight, background, DIM_LEVEL);
			green = dimmed_color_cmap8(green, background, DIM_LEVEL);
			greenShadow = dimmed_color_cmap8(greenShadow, background, DIM_LEVEL);
			black = dimmed_color_cmap8(black, background, DIM_LEVEL);
			dotGreen = dotGrey;
		}
		else if (fMuted)
		{
			green = tint_color(kBackground, B_DARKEN_3_TINT);
			greenShadow = tint_color(kBackground, B_DARKEN_4_TINT);
			dotGreen = greenShadow;
		}
		// draw slider edges between bitmaps
		BeginLineArray(7);
			AddLine(BPoint(sliderStart, r.top),
					BPoint(sliderEnd, r.top), softShadow);
			AddLine(BPoint(sliderStart, r.bottom),
					BPoint(sliderEnd, r.bottom), softLight);
			r.InsetBy(0.0, 1.0);
			AddLine(BPoint(sliderStart, r.top),
					BPoint(sliderEnd, r.top), black);
			AddLine(BPoint(sliderStart, r.bottom),
					BPoint(sliderEnd, r.bottom), light);
			r.top++;
			AddLine(BPoint(sliderStart, r.top),
					BPoint(knobPos, r.top), greenShadow);
			AddLine(BPoint(knobPos, r.top),
					BPoint(sliderEnd, r.top), midShadow);
			r.top++;
			AddLine(BPoint(sliderStart, r.top),
					BPoint(knobPos, r.top), greenShadow);
		EndLineArray();
		// fill rest inside of slider
		r.InsetBy(0.0, 1.0);
		r.left = sliderStart;
		r.right = knobPos;
		SetHighColor(green);
		FillRect(r, B_SOLID_HIGH);
		r.left = knobPos + 1.0;
		r.right = sliderEnd;
		r.top -= 1.0;
		SetHighColor(shadow);
		FillRect(r, B_SOLID_HIGH);
		// draw little dots inside
		int32 dotCount = (int32)((sliderEnd - sliderStart) / 5.0);
		BPoint dotPos;
		dotPos.y = r.top + 4.0;
		for (int32 i = 0; i < dotCount; i++)
		{
			dotPos.x = sliderStart + i * 5.0 + 4.0;
			SetHighColor(dotPos.x < knobPos ? dotGreen : dotGrey);
			StrokeLine(dotPos, BPoint(dotPos.x, dotPos.y + 1.0));
		}
		// draw knob
		r.top -= 1.0;
		SetDrawingMode(B_OP_OVER); // part of knob is transparent
		DrawBitmapAsync(fKnobBits, BPoint(knobPos - kVolumeSliderKnobWidth / 2, r.top));
	}
}

/*****************************************************************************
 * VolumeSlider::MouseDown
 *****************************************************************************/
void
VolumeSlider::MouseDown(BPoint where)
{
	if (Bounds().Contains(where) && IsEnabled())
	{
		fTracking = true;
		SetValue(_ValueFor(where.x));
		SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
	}
}

/*****************************************************************************
 * VolumeSlider::MouseMoved
 *****************************************************************************/
void
VolumeSlider::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
{
	if (fTracking)
		SetValue(_ValueFor(where.x));
}

/*****************************************************************************
 * VolumeSlider::MouseUp
 *****************************************************************************/
void
VolumeSlider::MouseUp(BPoint where)
{
	fTracking = false;
}


/*****************************************************************************
 * VolumeSlider::IsValid
1038
 *****************************************************************************/
1039 1040
bool
VolumeSlider::IsValid() const
1041
{
1042 1043 1044
	return (fLeftSideBits && fLeftSideBits->IsValid()
			&& fRightSideBits && fRightSideBits->IsValid()
			&& fKnobBits && fKnobBits->IsValid());
1045
}
1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134

/*****************************************************************************
 * VolumeSlider::SetMuted
 *****************************************************************************/
void
VolumeSlider::SetMuted(bool mute)
{
	if (mute != fMuted)
	{
		fMuted = mute;
		_MakeBitmaps();
		Invalidate();
	}
}

/*****************************************************************************
 * VolumeSlider::_MakeBitmaps
 *****************************************************************************/
void
VolumeSlider::_MakeBitmaps()
{
	if (IsValid())
	{
		// left side of slider
		memcpy(fLeftSideBits->Bits(), kVolumeSliderLeftBitmapBits,
			   fLeftSideBits->BitsLength());
		// right side of slider
		memcpy(fRightSideBits->Bits(), kVolumeSliderRightBits,
			   fRightSideBits->BitsLength());
		// slider knob
		int32 length = fKnobBits->BitsLength();
		memcpy(fKnobBits->Bits(), kVolumeSliderKnobBits, length);
		uint8* bits = (uint8*)fKnobBits->Bits();
		// black was used in the knob to represent transparency
		// use screen to get index for the "transarent" color used in the bitmap
		BScreen screen(B_MAIN_SCREEN_ID);
		uint8 blackIndex = screen.IndexForColor(kBlack);
		// replace black index with transparent index
		for (int32 i = 0; i < length; i++)
			if (bits[i] == blackIndex)
				bits[i] = B_TRANSPARENT_MAGIC_CMAP8;

		if (!IsEnabled())
		{
			// make ghosted versions of the bitmaps
			dim_bitmap(fLeftSideBits, kBackground, DIM_LEVEL);
			dim_bitmap(fRightSideBits, kBackground, DIM_LEVEL);
			dim_bitmap(fKnobBits, kBackground, DIM_LEVEL);
		}
		else if (fMuted)
		{
			// replace green color (and shadow) in left slider side
			bits = (uint8*)fLeftSideBits->Bits();
			length = fLeftSideBits->BitsLength();
			uint8 greenIndex = screen.IndexForColor(kGreen);
			uint8 greenShadowIndex = screen.IndexForColor(kGreenShadow);
			rgb_color shadow = tint_color(kBackground, B_DARKEN_3_TINT);
			rgb_color midShadow = tint_color(kBackground, B_DARKEN_4_TINT);
			uint8 replaceIndex = screen.IndexForColor(shadow);
			uint8 replaceShadowIndex = screen.IndexForColor(midShadow);
			for (int32 i = 0; i < length; i++)
			{
				if (bits[i] == greenIndex)
					bits[i] = replaceIndex;
				else if (bits[i] == greenShadowIndex)
					bits[i] = replaceShadowIndex;
			}
		}
	}
}

/*****************************************************************************
 * VolumeSlider::_ValueFor
 *****************************************************************************/
int32
VolumeSlider::_ValueFor(float xPos) const
{
	BRect r(Bounds());
	float sliderStart = (r.left + kVolumeSliderBitmapWidth);
	float sliderEnd = (r.right - kVolumeSliderBitmapWidth);
	int32 value =  fMinValue + (int32)(((xPos - sliderStart) * (fMaxValue - fMinValue))
				  / (sliderEnd - sliderStart - 1.0));
	if (value < fMinValue)
		value = fMinValue;
	if (value > fMaxValue)
		value = fMaxValue;
	return value;
}

Eric Petit's avatar
Eric Petit committed
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231
/*****************************************************************************
 * PositionInfoView::PositionInfoView
 *****************************************************************************/
PositionInfoView::PositionInfoView( BRect frame, const char* name,
                                    intf_thread_t * p_interface )
	: BView( frame, name, B_FOLLOW_NONE,
			 B_WILL_DRAW | B_PULSE_NEEDED | B_FULL_UPDATE_ON_RESIZE ),
	  fMode( MODE_SMALL ),
	  fCurrentFileIndex( -1 ),
	  fCurrentFileSize( -1 ),
	  fCurrentTitleIndex( -1 ),
	  fCurrentTitleSize( -1 ),
	  fCurrentChapterIndex( -1 ),
	  fCurrentChapterSize( -1 ),
	  fSeconds( -1 ),
	  fTimeString( "-:--:--" ),
	  fLastPulseUpdate( system_time() ),
	  fStackedWidthCache( 0.0 ),
	  fStackedHeightCache( 0.0 )
{
    p_intf = p_interface;

	SetViewColor( B_TRANSPARENT_32_BIT );
	SetLowColor( kBlack );
	SetHighColor( 0, 255, 0, 255 );
	SetFontSize( 11.0 );
}

/*****************************************************************************
 * PositionInfoView::~PositionInfoView
 *****************************************************************************/
PositionInfoView::~PositionInfoView()
{
}

/*****************************************************************************
 * PositionInfoView::Draw
 *****************************************************************************/
void
PositionInfoView::Draw( BRect updateRect )
{
	rgb_color background = ui_color( B_PANEL_BACKGROUND_COLOR );
	rgb_color shadow = tint_color( background, B_DARKEN_1_TINT );
	rgb_color darkShadow = tint_color( background, B_DARKEN_4_TINT );
	rgb_color light = tint_color( background, B_LIGHTEN_MAX_TINT );
	rgb_color softLight = tint_color( background, B_LIGHTEN_1_TINT );
	// frame
	BRect r( Bounds() );
	BeginLineArray( 8 );
		AddLine( BPoint( r.left, r.bottom ),
				 BPoint( r.left, r.top ), shadow );
		AddLine( BPoint( r.left + 1.0, r.top ),
				 BPoint( r.right, r.top ), shadow );
		AddLine( BPoint( r.right, r.top + 1.0 ),
				 BPoint( r.right, r.bottom ), softLight );
		AddLine( BPoint( r.right - 1.0, r.bottom ),
				 BPoint( r.left + 1.0, r.bottom ), softLight );
		r.InsetBy( 1.0, 1.0 );
		AddLine( BPoint( r.left, r.bottom ),
				 BPoint( r.left, r.top ), darkShadow );
		AddLine( BPoint( r.left + 1.0, r.top ),
				 BPoint( r.right, r.top ), darkShadow );
		AddLine( BPoint( r.right, r.top + 1.0 ),
				 BPoint( r.right, r.bottom ), light );
		AddLine( BPoint( r.right - 1.0, r.bottom ),
				 BPoint( r.left + 1.0, r.bottom ), light );
	EndLineArray();
	// background
	r.InsetBy( 1.0, 1.0 );
	FillRect( r, B_SOLID_LOW );
	// contents
	font_height fh;
	GetFontHeight( &fh );
	switch ( fMode )
	{
		case MODE_SMALL:
		{
			float width = StringWidth( fTimeString.String() );
			DrawString( fTimeString.String(),
						BPoint( r.left + r.Width() / 2.0 - width / 2.0,
								r.top + r.Height() / 2.0 + fh.ascent / 2.0 - 1.0 ) );
			break;
		}
		case MODE_BIG:
		{
			BFont font;
			GetFont( &font );
			BFont smallFont = font;
			BFont bigFont = font;
			BFont tinyFont = font;
			smallFont.SetSize( r.Height() / 5.0 );
			bigFont.SetSize( r.Height() / 3.0 );
			tinyFont.SetSize( r.Height() / 7.0 );
			float timeHeight = r.Height() / 2.5;
			float height = ( r.Height() - timeHeight ) / 3.0;
			SetFont( &tinyFont );
			SetHighColor( 0, 180, 0, 255 );
1232 1233 1234
			DrawString( _("File"), BPoint( r.left + 3.0, r.top + height ) );
			DrawString( _("Title"), BPoint( r.left + 3.0, r.top + 2.0 * height ) );
			DrawString( _("Chapter"), BPoint( r.left + 3.0, r.top + 3.0 * height ) );
Eric Petit's avatar
Eric Petit committed
1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298
			SetFont( &smallFont );
			BString helper;
			SetHighColor( 0, 255, 0, 255 );
			// file
			_MakeString( helper, fCurrentFileIndex, fCurrentFileSize );
			float width = StringWidth( helper.String() );
			DrawString( helper.String(), BPoint( r.right - 3.0 - width, r.top + height ) );
			// title
			_MakeString( helper, fCurrentTitleIndex, fCurrentTitleSize );
			width = StringWidth( helper.String() );
			DrawString( helper.String(), BPoint( r.right - 3.0 - width, r.top + 2.0 * height ) );
			// chapter
			_MakeString( helper, fCurrentChapterIndex, fCurrentChapterSize );
			width = StringWidth( helper.String() );
			DrawString( helper.String(), BPoint( r.right - 3.0 - width, r.top + 3.0 * height ) );
			// time
			SetFont( &bigFont );
			width = StringWidth( fTimeString.String() );
			DrawString( fTimeString.String(),
						BPoint( r.left + r.Width() / 2.0 - width / 2.0,
								r.bottom - 3.0 ) );
			break;
		}
	}
}

/*****************************************************************************
 * PositionInfoView::ResizeToPreferred
 *****************************************************************************/
void
PositionInfoView::ResizeToPreferred()
{
	float width, height;
	GetPreferredSize( &width, &height );
	ResizeTo( width, height );
}

/*****************************************************************************
 * PositionInfoView::GetPreferredSize
 *****************************************************************************/
void
PositionInfoView::GetPreferredSize( float* width, float* height )
{
	if ( width && height )
	{
		*width = 5.0 + ceilf( StringWidth( "0:00:00" ) ) + 5.0;
		font_height fh;
		GetFontHeight( &fh );
		*height = 3.0 + ceilf( fh.ascent ) + 3.0;
		fStackedWidthCache = *width * 1.2;
		fStackedHeightCache = *height * 2.7;
	}
}

/*****************************************************************************
 * PositionInfoView::Pulse
 *****************************************************************************/
void
PositionInfoView::Pulse()
{
	// allow for Pulse frequency to be higher, MediaControlView needs it
	bigtime_t now = system_time();
	if ( now - fLastPulseUpdate > 900000 )
	{
1299
#if 0
Eric Petit's avatar
Eric Petit committed
1300
		int32 index, size;
Eric Petit's avatar
Eric Petit committed
1301
		p_intf->p_sys->p_wrapper->GetPlaylistInfo( index, size );
1302
		SetFile( index + 1, size );
1303
		p_intf->p_sys->p_wrapper->TitleInfo( index, size );
Eric Petit's avatar
Eric Petit committed
1304
		SetTitle( index, size );
1305
		p_intf->p_sys->p_wrapper->ChapterInfo( index, size );
Eric Petit's avatar
Eric Petit committed
1306
		SetChapter( index, size );
Eric Petit's avatar
Eric Petit committed
1307
		SetTime( p_intf->p_sys->p_wrapper->GetTimeAsString() );
Eric Petit's avatar
Eric Petit committed
1308
		fLastPulseUpdate = now;
1309
#endif
Eric Petit's avatar
Eric Petit committed
1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337
	}
}

/*****************************************************************************
 * PositionInfoView::GetBigPreferredSize
 *****************************************************************************/
void
PositionInfoView::GetBigPreferredSize( float* width, float* height )
{
	if ( width && height )
	{
		*width = fStackedWidthCache;
		*height = fStackedHeightCache;
	}
}

/*****************************************************************************
 * PositionInfoView::SetMode
 *****************************************************************************/
void
PositionInfoView::SetMode( uint32 mode )
{
	if ( fMode != mode )
	{
		fMode = mode;
		_InvalidateContents();
	}
}
1338

Eric Petit's avatar
Eric Petit committed
1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351
/*****************************************************************************
 * PositionInfoView::SetFile
 *****************************************************************************/
void
PositionInfoView::SetFile( int32 index, int32 size )
{
	if ( fCurrentFileIndex != index || fCurrentFileSize != size )
	{
		fCurrentFileIndex = index;
		fCurrentFileSize = size;
		_InvalidateContents();
	}
}
1352

Eric Petit's avatar
Eric Petit committed
1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365
/*****************************************************************************
 * PositionInfoView::SetTitle
 *****************************************************************************/
void
PositionInfoView::SetTitle( int32 index, int32 size )
{
	if ( fCurrentTitleIndex != index || fCurrentFileSize != size )
	{
		fCurrentTitleIndex = index;
		fCurrentTitleSize = size;
		_InvalidateContents();
	}
}
1366

Eric Petit's avatar
Eric Petit committed
1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379
/*****************************************************************************
 * PositionInfoView::SetChapter
 *****************************************************************************/
void
PositionInfoView::SetChapter( int32 index, int32 size )
{
	if ( fCurrentChapterIndex != index || fCurrentFileSize != size )
	{
		fCurrentChapterIndex = index;
		fCurrentChapterSize = size;
		_InvalidateContents();
	}
}
1380

Eric Petit's avatar
Eric Petit committed
1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433
/*****************************************************************************
 * PositionInfoView::SetTime
 *****************************************************************************/
void
PositionInfoView::SetTime( int32 seconds )
{
	if ( fSeconds != seconds )
	{
		if ( seconds >= 0 )
		{
			int32 minutes = seconds / 60;
			int32 hours = minutes / 60;
			seconds -= minutes * 60 - hours * 60 * 60;
			minutes -= hours * 60;
			fTimeString.SetTo( "" );
			fTimeString << hours << ":" << minutes << ":" << seconds;
		}
		else
			fTimeString.SetTo( "-:--:--" );

		fSeconds = seconds;
		_InvalidateContents();
	}
}

/*****************************************************************************
 * PositionInfoView::SetTime
 *****************************************************************************/
void
PositionInfoView::SetTime( const char* string )
{
	fTimeString.SetTo( string );
	_InvalidateContents();
}

/*****************************************************************************
 * PositionInfoView::_InvalidateContents
 *****************************************************************************/
void
PositionInfoView::_InvalidateContents( uint32 which )
{
	BRect r( Bounds() );
	r.InsetBy( 2.0, 2.0 );
	Invalidate( r );
}

/*****************************************************************************
 * PositionInfoView::_InvalidateContents
 *****************************************************************************/
void
PositionInfoView::_MakeString( BString& into, int32 index, int32 maxIndex ) const
{
	into = "";