Blame | Last modification | View Log | RSS feed
#include "RenderVideo.h"
//#include "DShowTextures.h"
#include "../Hook/MyDirect3DDevice9.h"
CRenderVideo::CRenderVideo () : CRenderObject ()
{
m_pMovie = NULL;
m_pTexture = NULL;
m_iScaleX = 0;
m_iScaleY = 0;
}
CRenderVideo::~CRenderVideo ()
{
if ( m_pMovie )
{
m_pMovie->Stop();
delete m_pMovie;
}
}
bool CRenderVideo::DoReopen ()
{
return true;
/*
if ( m_pMovie )
{
m_pMovie->Stop();
delete m_pMovie;
m_pMovie = NULL;
}
m_bDontRender = true;
CRenderObject::Log ( "Stopping render of video\n" );*/
}
bool CRenderVideo::LoadVideo ( MyDirect3DDevice9 *device, const char *sFilename )
{
m_pMovie = new CMovies ();
bool run = m_pMovie->Initialise ( device, sFilename, m_pTexture );
if ( run )
m_pMovie->Play();
return run;
}
void CRenderVideo::ParseSetting ( COverlay *overlay, Utils::String cmd, Utils::String rest, Utils::String section )
{
if ( section.empty() )
{
if ( cmd == "VIDEO" )
LoadVideo ( m_pDevice, rest.c_str() );
else if ( cmd == "RESCALE" )
{
m_iScaleX = rest.token(",", 1);
m_iScaleY = rest.token(",", 2);
}
else
CRenderObject::ParseSetting ( overlay, cmd, rest, section );
}
else
CRenderObject::ParseSetting ( overlay, cmd, rest, section );
}
void CRenderVideo::render ( MyDirect3DDevice9 *device, int x, int y, LPD3DXSPRITE sprite )
{
if ( m_bDontRender )
return;
if ( !m_pMovie )
return;
CRenderObject::Log ( "Rendering a video stream\n" );
LPDIRECT3DTEXTURE9 texture = m_pMovie->GetTexture();
if ( !texture )
return;
if ( (!m_iScaleX) && (!m_iScaleY) )
{
m_iScaleX = m_pMovie->GetVideoWidth();
m_iScaleY = m_pMovie->GetVideoHeight();
}
// render top left corner
RECT size;
size.top = 0;
size.left = 0;
size.bottom = m_pMovie->GetVideoHeight ();
size.right = m_pMovie->GetVideoWidth ();
D3DXVECTOR2 spriteCentre = D3DXVECTOR2( (float)(m_iScaleX / 2.0f ),(float)(m_iScaleY / 2.0f ) );
D3DXVECTOR2 trans = D3DXVECTOR2( (float)(x + m_iX), (float)(y + m_iY) );
D3DXMATRIX mat;
// SCREEN HEIGHT AND WIDTH HERE
D3DXVECTOR2 scaling( (float)( m_iScaleX / (float)m_pMovie->GetVideoWidth() ), (float)( m_iScaleY / (float)m_pMovie->GetVideoHeight() ) );
// D3DXVECTOR2 scaling( 1.0f, 1.0f );
float m_fRotation = 180.0f;
D3DXMatrixTransformation2D( &mat, NULL, 0.0, &scaling, &spriteCentre, DEGTORAD( m_fRotation ), &trans );
// D3DXMatrixTransformation2D ( &mat, NULL, 0.0, &D3DXVECTOR2(1, 1), NULL, 0, &D3DXVECTOR2 ( (float)(x + m_iX), (float)(y + m_iY)) );
sprite->SetTransform(&mat);
short *c = m_iColour;
if ( m_bMouseOver )
{
for ( SMouseOver *mo = m_lMouseOver.First(); mo; mo = m_lMouseOver.Next() )
{
if ( mo->iType == MO_COLOUR )
c = ((SMOColour *)mo)->iColour;
else if ( mo->iType == MO_TEXTURE )
texture = ((SMOTexture *)mo)->pTexture;
}
}
D3DCOLOR color = D3DCOLOR_RGBA ( c[0], c[1], c[2], m_iAlpha );
sprite->Draw ( texture, &size, NULL, &D3DXVECTOR3( 0.0, 0.0, 0.0), color );
}