| 11 | cycrow | 1 | #include "RenderVideo.h"
 | 
        
           |  |  | 2 | //#include "DShowTextures.h"
 | 
        
           |  |  | 3 |   | 
        
           |  |  | 4 | #include "../Hook/MyDirect3DDevice9.h"
 | 
        
           |  |  | 5 |   | 
        
           |  |  | 6 | CRenderVideo::CRenderVideo () : CRenderObject ()
 | 
        
           |  |  | 7 | {
 | 
        
           |  |  | 8 | 	m_pMovie = NULL;
 | 
        
           |  |  | 9 | 	m_pTexture = NULL;
 | 
        
           |  |  | 10 |   | 
        
           |  |  | 11 | 	m_iScaleX = 0;
 | 
        
           |  |  | 12 | 	m_iScaleY = 0;
 | 
        
           |  |  | 13 | }
 | 
        
           |  |  | 14 |   | 
        
           |  |  | 15 | CRenderVideo::~CRenderVideo ()
 | 
        
           |  |  | 16 | {
 | 
        
           |  |  | 17 | 	if ( m_pMovie )
 | 
        
           |  |  | 18 | 	{
 | 
        
           |  |  | 19 | 		m_pMovie->Stop();
 | 
        
           |  |  | 20 | 		delete m_pMovie;
 | 
        
           |  |  | 21 | 	}
 | 
        
           |  |  | 22 | }
 | 
        
           |  |  | 23 |   | 
        
           |  |  | 24 | bool CRenderVideo::DoReopen ()
 | 
        
           |  |  | 25 | {
 | 
        
           |  |  | 26 | 	return true;
 | 
        
           |  |  | 27 | 	/*
 | 
        
           |  |  | 28 | 	if ( m_pMovie )
 | 
        
           |  |  | 29 | 	{
 | 
        
           |  |  | 30 | 		m_pMovie->Stop();
 | 
        
           |  |  | 31 | 		delete m_pMovie;
 | 
        
           |  |  | 32 | 		m_pMovie = NULL;
 | 
        
           |  |  | 33 | 	}
 | 
        
           |  |  | 34 | 	m_bDontRender = true;
 | 
        
           |  |  | 35 |   | 
        
           |  |  | 36 | 	CRenderObject::Log ( "Stopping render of video\n" );*/
 | 
        
           |  |  | 37 | }
 | 
        
           |  |  | 38 |   | 
        
           |  |  | 39 | bool CRenderVideo::LoadVideo ( MyDirect3DDevice9 *device, const char *sFilename )
 | 
        
           |  |  | 40 | {
 | 
        
           |  |  | 41 | 	m_pMovie = new CMovies ();
 | 
        
           |  |  | 42 | 	bool run = m_pMovie->Initialise ( device, sFilename, m_pTexture );
 | 
        
           |  |  | 43 |   | 
        
           |  |  | 44 | 	if ( run )
 | 
        
           |  |  | 45 | 		m_pMovie->Play();
 | 
        
           |  |  | 46 |   | 
        
           |  |  | 47 | 	return run;
 | 
        
           |  |  | 48 | }
 | 
        
           |  |  | 49 |   | 
        
           |  |  | 50 | void CRenderVideo::ParseSetting ( COverlay *overlay, Utils::String cmd, Utils::String rest, Utils::String section )
 | 
        
           |  |  | 51 | {
 | 
        
           |  |  | 52 | 	if ( section.empty() )
 | 
        
           |  |  | 53 | 	{
 | 
        
           |  |  | 54 | 		if ( cmd == "VIDEO" )
 | 
        
           |  |  | 55 | 			LoadVideo ( m_pDevice, rest.c_str() );
 | 
        
           |  |  | 56 | 		else if ( cmd == "RESCALE" )
 | 
        
           |  |  | 57 | 		{
 | 
        
           |  |  | 58 | 			m_iScaleX = rest.token(",", 1);
 | 
        
           |  |  | 59 | 			m_iScaleY = rest.token(",", 2);
 | 
        
           |  |  | 60 | 		}
 | 
        
           |  |  | 61 | 		else
 | 
        
           |  |  | 62 | 			CRenderObject::ParseSetting ( overlay, cmd, rest, section );
 | 
        
           |  |  | 63 | 	}
 | 
        
           |  |  | 64 | 	else
 | 
        
           |  |  | 65 | 		CRenderObject::ParseSetting ( overlay, cmd, rest, section );
 | 
        
           |  |  | 66 | }
 | 
        
           |  |  | 67 |   | 
        
           |  |  | 68 | void CRenderVideo::render ( MyDirect3DDevice9 *device, int x, int y, LPD3DXSPRITE sprite )
 | 
        
           |  |  | 69 | {
 | 
        
           |  |  | 70 | 	if ( m_bDontRender )
 | 
        
           |  |  | 71 | 		return;
 | 
        
           |  |  | 72 |   | 
        
           |  |  | 73 | 	if ( !m_pMovie )
 | 
        
           |  |  | 74 | 		return;
 | 
        
           |  |  | 75 |   | 
        
           |  |  | 76 | 	CRenderObject::Log ( "Rendering a video stream\n" );
 | 
        
           |  |  | 77 |   | 
        
           |  |  | 78 | 	LPDIRECT3DTEXTURE9  texture = m_pMovie->GetTexture();
 | 
        
           |  |  | 79 |   | 
        
           |  |  | 80 | 	if ( !texture )
 | 
        
           |  |  | 81 | 		return;
 | 
        
           |  |  | 82 |   | 
        
           |  |  | 83 | 	if ( (!m_iScaleX) && (!m_iScaleY) )
 | 
        
           |  |  | 84 | 	{
 | 
        
           |  |  | 85 | 		m_iScaleX = m_pMovie->GetVideoWidth();
 | 
        
           |  |  | 86 | 		m_iScaleY = m_pMovie->GetVideoHeight();
 | 
        
           |  |  | 87 | 	}
 | 
        
           |  |  | 88 |   | 
        
           |  |  | 89 | 	// render top left corner
 | 
        
           |  |  | 90 | 	RECT size;
 | 
        
           |  |  | 91 | 	size.top = 0;
 | 
        
           |  |  | 92 | 	size.left = 0;
 | 
        
           |  |  | 93 | 	size.bottom = m_pMovie->GetVideoHeight ();
 | 
        
           |  |  | 94 | 	size.right  = m_pMovie->GetVideoWidth ();
 | 
        
           |  |  | 95 |   | 
        
           |  |  | 96 | 	D3DXVECTOR2 spriteCentre = D3DXVECTOR2( (float)(m_iScaleX / 2.0f ),(float)(m_iScaleY / 2.0f ) );
 | 
        
           |  |  | 97 |   | 
        
           |  |  | 98 | 	D3DXVECTOR2 trans = D3DXVECTOR2( (float)(x + m_iX), (float)(y + m_iY) );
 | 
        
           |  |  | 99 | 	D3DXMATRIX mat;
 | 
        
           |  |  | 100 |   | 
        
           |  |  | 101 | //	SCREEN HEIGHT AND WIDTH HERE
 | 
        
           |  |  | 102 | 	D3DXVECTOR2 scaling( (float)( m_iScaleX / (float)m_pMovie->GetVideoWidth() ), (float)( m_iScaleY / (float)m_pMovie->GetVideoHeight() ) );
 | 
        
           |  |  | 103 | //	D3DXVECTOR2 scaling( 1.0f, 1.0f );
 | 
        
           |  |  | 104 |   | 
        
           |  |  | 105 | 	float m_fRotation = 180.0f;
 | 
        
           |  |  | 106 |   | 
        
           |  |  | 107 | 	D3DXMatrixTransformation2D( &mat, NULL, 0.0, &scaling, &spriteCentre, DEGTORAD( m_fRotation ), &trans );
 | 
        
           |  |  | 108 |   | 
        
           |  |  | 109 | //	D3DXMatrixTransformation2D ( &mat, NULL, 0.0, &D3DXVECTOR2(1, 1), NULL, 0, &D3DXVECTOR2 ( (float)(x + m_iX), (float)(y + m_iY)) );
 | 
        
           |  |  | 110 | 	sprite->SetTransform(&mat);
 | 
        
           |  |  | 111 |   | 
        
           |  |  | 112 | 	short *c = m_iColour;
 | 
        
           |  |  | 113 |   | 
        
           |  |  | 114 | 	if ( m_bMouseOver )
 | 
        
           |  |  | 115 | 	{
 | 
        
           |  |  | 116 | 		for ( SMouseOver *mo = m_lMouseOver.First(); mo; mo = m_lMouseOver.Next() )
 | 
        
           |  |  | 117 | 		{
 | 
        
           |  |  | 118 | 			if ( mo->iType == MO_COLOUR )
 | 
        
           |  |  | 119 | 				c = ((SMOColour *)mo)->iColour;
 | 
        
           |  |  | 120 | 			else if ( mo->iType == MO_TEXTURE )
 | 
        
           |  |  | 121 | 				texture = ((SMOTexture *)mo)->pTexture;
 | 
        
           |  |  | 122 | 		}		
 | 
        
           |  |  | 123 | 	}
 | 
        
           |  |  | 124 |   | 
        
           |  |  | 125 | 	D3DCOLOR color = D3DCOLOR_RGBA ( c[0], c[1], c[2], m_iAlpha );
 | 
        
           |  |  | 126 | 	sprite->Draw ( texture, &size, NULL, &D3DXVECTOR3( 0.0, 0.0, 0.0), color );
 | 
        
           |  |  | 127 | }
 | 
        
           |  |  | 128 |   | 
        
           |  |  | 129 |   |