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

📄 gesturetool.cpp

📁 hl2 source code. Do not use it illegal.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
			}
		}
		break;
	}
	return iret;
}

void GestureTool::ApplyBounds( int& mx, int& my )
{
	if ( !m_bUseBounds )
		return;

	mx = clamp( mx, m_nMinX, m_nMaxX );
}

int GestureTool::GetTagTypeForTag( CEventAbsoluteTag const *tag )
{
	CChoreoEvent *e = GetSafeEvent();
	if ( !e )
		return -1;

	for ( int t = 0; t < CChoreoEvent::NUM_ABS_TAG_TYPES; t++ )
	{
		CChoreoEvent::AbsTagType tagtype = (CChoreoEvent::AbsTagType)t;

		for ( int i = 0; i < e->GetNumAbsoluteTags( tagtype ); i++ )
		{
			CEventAbsoluteTag *ptag = e->GetAbsoluteTag( tagtype, i );
			Assert( ptag );
			if ( ptag == tag )
				return t;
		}
	}

	return -1;
}

void GestureTool::CalcBounds( int movetype )
{
	switch ( movetype )
	{
	default:
	case DRAGTYPE_NONE:
		{
			m_bUseBounds = false;
			m_nMinX = 0;
			m_nMaxX = 0;
		}
		break;
	case DRAGTYPE_SCRUBBER:
		{
			m_bUseBounds = true;
			m_nMinX = 0;
			m_nMaxX = w2();
		}
		break;
	case DRAGTYPE_ABSOLUTE_TIMING_TAG:
		{
			m_bUseBounds = true;
			m_nMinX = 0;
			m_nMaxX = w2();

			CChoreoEvent *e = GetSafeEvent();
			CEventAbsoluteTag *tag = IsMouseOverTag( m_nClickedX, m_nClickedY );
			if ( tag && e && e->GetDuration() )
			{
				m_nMinX = GetPixelForTimeValue( 0 );
				m_nMaxX = max( w2(), GetPixelForTimeValue( e->GetDuration() ) );

				int t = GetTagTypeForTag( tag );
				if ( t != -1 )
				{
					CChoreoEvent::AbsTagType tagtype = (CChoreoEvent::AbsTagType)t;

					CEventAbsoluteTag *prevTag = NULL, *nextTag = NULL;
					int c = e->GetNumAbsoluteTags( tagtype );
					int i;
					for ( i = 0; i < c; i++ )
					{
						CEventAbsoluteTag *t = e->GetAbsoluteTag( tagtype, i );
						Assert( t );

						if ( t == tag )
						{
							prevTag = i > 0 ?  e->GetAbsoluteTag( tagtype, i-1 ) : NULL;
							nextTag = i < c - 1 ? e->GetAbsoluteTag( tagtype, i+1 ) : NULL;
							break;
						}
					}

					if ( i < c )
					{
						if ( prevTag )
						{
							m_nMinX = GetPixelForTimeValue( prevTag->GetTime() * e->GetDuration() ) + 1;
						}
						if ( nextTag )
						{
							m_nMaxX = GetPixelForTimeValue( nextTag->GetTime() * e->GetDuration() ) - 1;
						}
						else
						{
							if ( tagtype == CChoreoEvent::SHIFTED )
							{
								float sequence_duration;
								e->GetGestureSequenceDuration( sequence_duration );
								m_nMaxX = GetPixelForTimeValue( sequence_duration );
							}
						}
					}
					else
					{
						Assert( 0 );
					}
				}
			}
		}
		break;
	}
}

bool GestureTool::PaintBackground()
{
	redraw();
	return false;
}

void GestureTool::OnUndo( void )
{
	g_pChoreoView->Undo();
}

void GestureTool::OnRedo( void )
{
	g_pChoreoView->Redo();
}

void GestureTool::ForceScrubPositionFromSceneTime( float scenetime )
{
	CChoreoEvent *e = GetSafeEvent();
	if ( !e || !e->GetDuration() )
		return;

	float t = scenetime - e->GetStartTime();
	m_flScrub = t;
	m_flScrubTarget = t;
	DrawScrubHandles();
}

void GestureTool::ForceScrubPosition( float t )
{
	m_flScrub = t;
	m_flScrubTarget = t;
	
	CChoreoEvent *e = GetSafeEvent();
	if ( e && e->GetDuration() )
	{
		float realtime = e->GetStartTime() + t;

		g_pChoreoView->SetScrubTime( realtime );
		g_pChoreoView->SetScrubTargetTime( realtime );

		g_pChoreoView->DrawScrubHandle();
	}

	DrawScrubHandles();
}

void GestureTool::SetMouseOverPos( int x, int y )
{
	m_nMousePos[ 0 ] = x;
	m_nMousePos[ 1 ] = y;
}

void GestureTool::GetMouseOverPos( int &x, int& y )
{
	x = m_nMousePos[ 0 ];
	y = m_nMousePos[ 1 ];
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : rcPos - 
//-----------------------------------------------------------------------------
void GestureTool::GetMouseOverPosRect( RECT& rcPos )
{
	rcPos.top = GetCaptionHeight() + 12;
	rcPos.left = w2() - 200;
	rcPos.right = w2() - 5;
	rcPos.bottom = rcPos.top + 13;
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : drawHelper - 
//			rcPos - 
//-----------------------------------------------------------------------------
void GestureTool::DrawMouseOverPos( CChoreoWidgetDrawHelper& drawHelper, RECT& rcPos )
{
	// Compute time for pixel x
	float t = GetTimeValueForMouse( m_nMousePos[ 0 ] );
	CChoreoEvent *e = GetSafeEvent();
	if ( !e )
		return;

	t += e->GetStartTime();
	float snapped = FacePoser_SnapTime( t );

	// Found it, write out description
	// 
	char sz[ 128 ];
	if ( t != snapped )
	{
		Q_snprintf( sz, sizeof( sz ), "%s", FacePoser_DescribeSnappedTime( t ) );
	}
	else
	{
		Q_snprintf( sz, sizeof( sz ), "%.3f", t );
	}

	int len = drawHelper.CalcTextWidth( "Arial", 11, 900, sz );

	RECT rcText = rcPos;
	rcText.left = max( rcPos.left, rcPos.right - len );

	drawHelper.DrawColoredText( "Arial", 11, 900, RGB( 255, 50, 70 ), rcText, sz );
}

//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void GestureTool::DrawMouseOverPos()
{
	RECT rcPos;
	GetMouseOverPosRect( rcPos );

	CChoreoWidgetDrawHelper drawHelper( this, rcPos );
	DrawMouseOverPos( drawHelper, rcPos );
}

void GestureTool::AddFocusRect( RECT& rc )
{
	RECT rcFocus = rc;

	POINT offset;
	offset.x = 0;
	offset.y = 0;
	ClientToScreen( (HWND)getHandle(), &offset );
	OffsetRect( &rcFocus, offset.x, offset.y );

	// Convert to screen space?
	CFocusRect fr;
	fr.m_rcFocus = rcFocus;
	fr.m_rcOrig = rcFocus;

	m_FocusRects.AddToTail( fr );
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : &rcClient - 
//			tagtype - 
//			rcTray - 
//-----------------------------------------------------------------------------
void GestureTool::GetTagTrayRect( RECT &rcClient, int tagtype, RECT& rcTray )
{
	rcTray = rcClient;

	rcTray.top += ( GetCaptionHeight() + 110 );

	rcTray.bottom	= rcTray.top + 6;

	if ( tagtype == CChoreoEvent::SHIFTED )
	{
		OffsetRect( &rcTray, 0, 45 );
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : rcClient - 
//			*event - 
//			tagtype - 
//			*tag - 
//			rcTag - 
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool GestureTool::GetAbsTagRect( RECT& rcClient, CChoreoEvent *event, 
	int tagtype, CEventAbsoluteTag *tag, RECT& rcTag )
{
	bool bret = false;

	rcTag = rcClient;

	GetTagTrayRect( rcClient, tagtype, rcTag );

	bool clipped = false;
	float t = tag->GetTime() * event->GetDuration();
	int tagx = GetPixelForTimeValue( t, &clipped );

	rcTag.left		= tagx - 3;
	rcTag.right		= tagx + 3;

	if ( clipped )
		return false;

	return true;
}

void GestureTool::DrawAbsoluteTags( CChoreoWidgetDrawHelper& drawHelper )
{
	CChoreoEvent *event = GetSafeEvent();
	if ( !event )
		return;

	RECT rcClient;
	drawHelper.GetClientRect( rcClient );

	bool showDots = true;
	if ( event->GetNumAbsoluteTags( (CChoreoEvent::AbsTagType)0 ) !=
		 event->GetNumAbsoluteTags( (CChoreoEvent::AbsTagType)1 ) )
	{
		showDots = false;
	}

	int t;
	for ( t = 0; t < CChoreoEvent::NUM_ABS_TAG_TYPES; t++ )
	{
		CChoreoEvent::AbsTagType tagtype = ( CChoreoEvent::AbsTagType )t;

		RECT rcTray;
		GetTagTrayRect( rcClient, tagtype, rcTray );

		drawHelper.DrawColoredLine( RGB( 220, 220, 220 ), PS_SOLID, 1, rcTray.left, rcTray.top, rcTray.right, rcTray.top );
		drawHelper.DrawColoredLine( RGB( 220, 220, 220 ), PS_SOLID, 1, rcTray.left, rcTray.bottom, rcTray.right, rcTray.bottom );

		RECT rcText;
		rcText = rcTray;

		InflateRect( &rcText, 0, 4 );
		OffsetRect( &rcText, 0, t == 0 ? -10 : 10 );

		rcText.left = 2;

		drawHelper.DrawColoredText( "Arial", 9, 500, RGB( 150, 150, 150 ), rcText, "%s", 
			t == 0 ? "Playback Time" : "Original Time" );

		for ( int i = 0; i < event->GetNumAbsoluteTags( tagtype ); i++ )
		{
			CEventAbsoluteTag *tag = event->GetAbsoluteTag( tagtype, i );
			if ( !tag )
				continue;

			RECT rcMark;

			bool visible = GetAbsTagRect( rcClient, event, tagtype, tag, rcMark );

			if ( showDots && t == 1 )
			{
				CChoreoEvent::AbsTagType tagtypeOther = (CChoreoEvent::AbsTagType)0;

				RECT rcMark2;
				CEventAbsoluteTag *otherTag = event->GetAbsoluteTag( tagtypeOther, i );
				if ( otherTag )
				{
					GetAbsTagRect( rcClient, event, tagtypeOther, otherTag, rcMark2 );
					{
						int midx1 = ( rcMark.left + rcMark.right ) / 2;
						int midx2 = ( rcMark2.left + rcMark2.right ) / 2;

						int y1 = rcMark.top;
						int y2 = rcMark2.bottom;

						drawHelper.DrawColoredLine(
							RGB( 200, 200, 200 ), PS_SOLID, 1,
							midx1, y1, midx2, y2 );
					}
				}
			}

			if ( !visible )
				continue;

			drawHelper.DrawTriangleMarker( rcMark, RGB( 200, 0, 30 ), tagtype != CChoreoEvent::PLAYBACK );
			
			RECT rcText;
			rcText = rcMark;

			if ( tagtype == CChoreoEvent::PLAYBACK )
			{
				rcText.top -= 15;
			}
			else
			{
				rcText.top += 10;
			}
			
			char text[ 256 ];
			sprintf( text, "%s", tag->GetName() );

			int len = drawHelper.CalcTextWidth( "Arial", 9, FW_NORMAL, text );
			rcText.left = ( rcMark.left + rcMark.right ) / 2 - len / 2;
			rcText.right = rcText.left + len + 2;
			
			rcText.bottom = rcText.top + 10;
			
			drawHelper.DrawColoredText( "Arial", 9, FW_NORMAL, RGB( 200, 100, 100 ), rcText, text );
			
			if ( tagtype == CChoreoEvent::PLAYBACK )
			{
				rcText.top -= 10;
			}
			else
			{
				rcText.top += 10;
			}
			
			sprintf( text, "%.3f", tag->GetTime() * event->GetDuration() + event->GetStartTime() );

			len = drawHelper.CalcTextWidth( "Arial", 9, FW_NORMAL, text );
			rcText.left = ( rcMark.left + rcMark.right ) / 2 - len / 2;
			rcText.right = rcText.left + len + 2;
			
			rcText.bottom = rcText.top + 10;
			
			drawHelper.DrawColoredText( "Arial", 9, FW_NORMAL, RGB( 200, 100, 100 ), rcText, text );
		}	
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : drawHelper - 
//			rc - 
//			left - 
//			right - 
//-----------------------------------------------------------------------------
void GestureTool::DrawTimeLine( CChoreoWidgetDrawHelper& drawHelper, RECT& rc, float left, float right )
{
	RECT rcLabel;
	float granularity = 0.5f;

	drawHelper.DrawColoredLine( RGB( 150, 150, 200 ), PS_SOLID, 1, rc.left, rc.top + 2, rc.right, rc.top + 2 );

	float f = SnapTime( left, granularity );
	while ( f < right )
	{
		float frac = ( f - left ) / ( right - left );
		if ( frac >= 0.0f && frac <= 1.0f )
		{
			rcLabel.left = GetPixelForTimeValue( f );
			rcLabel.top = rc.top + 5;
			rcLabel.bottom = rcLabel.top + 10;

			if ( f != left )
			{
				drawHelper.DrawColoredLine( RGB( 220, 220, 240 ), PS_DOT,  1, 
					rcLabel.left, rc.top, rcLabel.left, h2() );
			}

			char sz[ 32 ];
			sprintf( sz, "%.2f", f );

			int textWidth = drawHelper.CalcTextWidth( "Arial", 9, FW_NORMAL, sz );

			rcLabel.right = rcLabel.left + textWidth;

			OffsetRect( &rcLabel, -textWidth / 2, 0 );

			RECT rcOut = rcLabel;
			if ( rcOut.left <= 0 )
			{
				OffsetRect( &rcOut, -rcOut.left + 2, 0 );
			}

			drawHelper.DrawColoredText( "Arial", 9, FW_NORMAL, RGB( 0, 50, 150 ), rcOut, sz );

		}
		f += granularity;
	}
}

//-----------------------------------------------------------------------------
// Purpose: 
// Input  : mx - 
//			my - 
// Output : CFlexTimingTag
//-----------------------------------------------------------------------------
CEventAbsoluteTag *GestureTool::IsMouseOverTag( int mx, int my )
{
	CChoreoEvent *event = GetSafeEvent();

⌨️ 快捷键说明

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