⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mediacontrolview.cpp

📁 VLC媒体播放程序
💻 CPP
📖 第 1 页 / 共 4 页
字号:
		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 *****************************************************************************/int32VolumeSlider::_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;}/***************************************************************************** * 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 *****************************************************************************/voidPositionInfoView::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 );			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 ) );			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 *****************************************************************************/voidPositionInfoView::ResizeToPreferred(){	float width, height;	GetPreferredSize( &width, &height );	ResizeTo( width, height );}/***************************************************************************** * PositionInfoView::GetPreferredSize *****************************************************************************/voidPositionInfoView::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 *****************************************************************************/voidPositionInfoView::Pulse(){	// allow for Pulse frequency to be higher, MediaControlView needs it	bigtime_t now = system_time();	if ( now - fLastPulseUpdate > 900000 )	{		int32 index, size;		p_intf->p_sys->p_wrapper->GetPlaylistInfo( index, size );		SetFile( index + 1, size );		p_intf->p_sys->p_wrapper->TitleInfo( index, size );		SetTitle( index, size );		p_intf->p_sys->p_wrapper->ChapterInfo( index, size );		SetChapter( index, size );		SetTime( p_intf->p_sys->p_wrapper->GetTimeAsString() );		fLastPulseUpdate = now;	}}/***************************************************************************** * PositionInfoView::GetBigPreferredSize *****************************************************************************/voidPositionInfoView::GetBigPreferredSize( float* width, float* height ){	if ( width && height )	{		*width = fStackedWidthCache;		*height = fStackedHeightCache;	}}/***************************************************************************** * PositionInfoView::SetMode *****************************************************************************/voidPositionInfoView::SetMode( uint32 mode ){	if ( fMode != mode )	{		fMode = mode;		_InvalidateContents();	}}/***************************************************************************** * PositionInfoView::SetFile *****************************************************************************/voidPositionInfoView::SetFile( int32 index, int32 size ){	if ( fCurrentFileIndex != index || fCurrentFileSize != size )	{		fCurrentFileIndex = index;		fCurrentFileSize = size;		_InvalidateContents();	}}/***************************************************************************** * PositionInfoView::SetTitle *****************************************************************************/voidPositionInfoView::SetTitle( int32 index, int32 size ){	if ( fCurrentTitleIndex != index || fCurrentFileSize != size )	{		fCurrentTitleIndex = index;		fCurrentTitleSize = size;		_InvalidateContents();	}}/***************************************************************************** * PositionInfoView::SetChapter *****************************************************************************/voidPositionInfoView::SetChapter( int32 index, int32 size ){	if ( fCurrentChapterIndex != index || fCurrentFileSize != size )	{		fCurrentChapterIndex = index;		fCurrentChapterSize = size;		_InvalidateContents();	}}/***************************************************************************** * PositionInfoView::SetTime *****************************************************************************/voidPositionInfoView::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 *****************************************************************************/voidPositionInfoView::SetTime( const char* string ){	fTimeString.SetTo( string );	_InvalidateContents();}/***************************************************************************** * PositionInfoView::_InvalidateContents *****************************************************************************/voidPositionInfoView::_InvalidateContents( uint32 which ){	BRect r( Bounds() );	r.InsetBy( 2.0, 2.0 );	Invalidate( r );}/***************************************************************************** * PositionInfoView::_InvalidateContents *****************************************************************************/voidPositionInfoView::_MakeString( BString& into, int32 index, int32 maxIndex ) const{	into = "";	if ( index >= 0 && maxIndex >= 0 )		into << index;	else		into << "-";	into << "/";	if ( maxIndex >= 0 )		into << maxIndex;	else		into << "-";}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -