	    				 /*---------------------------------------------------------+
						  |					vip2Interface.cpp						|
						  |															|
						  |	   la boite de dialog pour gérer les options rentrées	|
						  |		 par le tout joli gentil utilisateur				|
						  |															|
						  | 	U2^PoPsy TeAm 2000									|
						  +---------------------------------------------------------*/

#include "stdafx.h"
#include "vip2.h"
#include "Vip2Interface.h"
#include "vip2Dlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//----------------------------------------------------------------------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
// CVip2Interface dialog
//----------------------------------------------------------------------------------------------------------------------------------------


CVip2Interface::CVip2Interface(CWnd* pParent /*=NULL*/)
	: CDialog(CVip2Interface::IDD, pParent)
{
	//{{AFX_DATA_INIT(CVip2Interface)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}


void CVip2Interface::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CVip2Interface)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CVip2Interface, CDialog)
	//{{AFX_MSG_MAP(CVip2Interface)
	ON_WM_PAINT()
	ON_WM_DESTROY()
	ON_WM_MOUSEMOVE()
	ON_WM_ERASEBKGND()
	ON_WM_ACTIVATE()
	ON_WM_LBUTTONDOWN()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

//----------------------------------------------------------------------------------------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////
// CVip2Interface message handlers
//----------------------------------------------------------------------------------------------------------------------------------------

BOOL CVip2Interface::OnInitDialog() 
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);		// Set big icon
	SetIcon(m_hIcon, FALSE);	// Set small icon

	DIBRender::Initialise( m_hWnd )	;
	DIBRender::GetDim( x, y )		;

	GetDesktopWindow()->GetClientRect( &rect )	;
	GetClientRect( &rect1 )						;
	xs = rect.Width()/2 -rect1.Width()/2		;
	ys = rect.Height()/2 -rect1.Height()/2		;
//	SetWindowRgn( DIBRender::MakeRegion(), TRUE );
//	SetWindowPos( &wndTop, xs, ys, x, y,
	SetWindowPos( &wndTopMost, xs, ys, x, y,
				  SWP_SHOWWINDOW )			;
	SetWindowText( "Vip2" )					;

	IniAllBouton()	;

	FirstPaint = TRUE	;
	Active = TRUE		;
	IsHide = FALSE		;
	TimeWait = 500		;

	LastTime = clock()	;

	bpp32	= TRUE	;
	stereo	= TRUE	;
	resol	= 0		;
	
	DIBRender::GetBouton( ID_640BUTTONA )->SetHighLight( TRUE )						;

	return TRUE;  // return TRUE  unless you set the focus to a control	              // EXCEPTION: OCX Property Pages should return FALSE
}

//----------------------------------------------------------------------------------------------------------------------------------------

void CVip2Interface::OnPaint() 
{
//	CPaintDC dc(this); // device context for painting	
}
//----------------------------------------------------------------------------------------------------------------------------------------
void CVip2Interface::OnDestroy() 
{
	CDialog::OnDestroy();

	DIBRender::Release();
}
//----------------------------------------------------------------------------------------------------------------------------------------
HCURSOR CVip2Interface::OnQueryDragIcon() 
{
	return (HCURSOR) m_hIcon;
}
//----------------------------------------------------------------------------------------------------------------------------------------
void CVip2Interface::OnMouseMove(UINT nFlags, CPoint point) 
{
	int resop = -1;
	if (nFlags&MK_LBUTTON)
	{
		switch (DIBRender::OuEstTu(point.x, point.y))
		{
			case DANS_SKIN :{
								SendMessage(WM_SYSCOMMAND, SC_MOVE | HTCLIENT, 0);
								break;
							}

			case ID_LAUNCHBUTTON:{
									break;
								 }
		}
	}
	else
	{
		switch (DIBRender::OuEstTu(point.x, point.y))
		{
			case ID_LAUNCHBUTTON:{
									DIBRender::ClearAllState()										;
									DIBRender::GetBouton( ID_LAUNCHBUTTON )->SetHighLight( TRUE )		;
									break;
								 }
			case ID_640BUTTONA:{
									DIBRender::ClearAllState()														;
									DIBRender::GetBouton( ID_640BUTTONA )->SetHighLight( TRUE )						;
									DIBRender::GetMultiAff(0)->SetActuaBitmap(ID_640BUTTON)							;
									if (resol != 1)	 DIBRender::GetMultiAff(1)->SetActuaBitmap(ID_640BUTTONA)			;
									else				 DIBRender::GetMultiAff(1)->SetActuaBitmap(ID_6408BUTTON)			;
									break;
							}

			case ID_800BUTTONA:{
									resop = 1																	;
									DIBRender::ClearAllState()														;
									DIBRender::GetBouton( ID_800BUTTONA )->SetHighLight( TRUE )						;
									DIBRender::GetMultiAff(0)->SetActuaBitmap(ID_800BUTTON)							;
									if (resol != 2)	 DIBRender::GetMultiAff(2)->SetActuaBitmap(ID_800BUTTONA)			;
									else				 DIBRender::GetMultiAff(2)->SetActuaBitmap(ID_8001BUTTON)			;
									break;
							}

			case ID_1024BUTTONA:{
									resop = 2;
									DIBRender::ClearAllState()										;
									DIBRender::GetBouton( ID_1024BUTTONA )->SetHighLight( TRUE )		;
									DIBRender::GetMultiAff(0)->SetActuaBitmap(ID_1024BUTTON)			;
									break;
							}

			case ID_VURLBUTTONA:{
									DIBRender::ClearAllState()										;
									DIBRender::GetBouton( ID_VURLBUTTONA )->SetHighLight( TRUE )		;
									DIBRender::GetMultiAff(0)->SetActuaBitmap(ID_VURLBUTTON)			;
									break;
							}

			case ID_VTXTBUTTONA:{
									DIBRender::ClearAllState()										;
									DIBRender::GetBouton( ID_VTXTBUTTONA )->SetHighLight( TRUE )		;
									DIBRender::GetMultiAff(0)->SetActuaBitmap(ID_VTXTBUTTON)			;
									break;
							}

			case ID_PURLBUTTONA:{
									DIBRender::ClearAllState()										;
									DIBRender::GetBouton( ID_PURLBUTTONA )->SetHighLight( TRUE )		;
									DIBRender::GetMultiAff(0)->SetActuaBitmap(ID_PURLBUTTON)			;
									break;
							}

			case ID_QUITBUTTONA:{
									DIBRender::ClearAllState()										;
									DIBRender::GetBouton( ID_QUITBUTTONA )->SetHighLight( TRUE )		;
									DIBRender::GetMultiAff(0)->SetActuaBitmap(ID_QUITBUTTON)			;
									break;
							}

			case ID_NFOBUTTONA:{
									DIBRender::ClearAllState()										;
									DIBRender::GetBouton( ID_NFOBUTTONA )->SetHighLight( TRUE )		;
									DIBRender::GetMultiAff(0)->SetActuaBitmap(ID_NFOBUTTON)			;
									break;
							}

			case ID_MONOBUTTONA:{
									DIBRender::ClearAllState()											;
									DIBRender::GetBouton( ID_MONOBUTTONA )->SetHighLight( TRUE )			;
									if (stereo)	DIBRender::GetMultiAff(0)->SetActuaBitmap(ID_STERBUTTON)	;
									else			DIBRender::GetMultiAff(0)->SetActuaBitmap(ID_MONOBUTTON)	;
									break;
							}

			case ID_NBPPBUTTONA:{
									DIBRender::ClearAllState()											;
									DIBRender::GetBouton( ID_NBPPBUTTONA )->SetHighLight( TRUE )			;
									if (bpp32)	DIBRender::GetMultiAff(0)->SetActuaBitmap(ID_NBPPBUTTON32)	;
									else			DIBRender::GetMultiAff(0)->SetActuaBitmap(ID_NBPPBUTTON16)	;
									break;
							}

			default:{						
						DIBRender::ClearAllState()		;
						break;
					}

		}
		switch (resol)
		{
			case 0:{
					DIBRender::GetBouton( ID_640BUTTONA )->SetHighLight( TRUE )						;
					if (resop != 1)	 DIBRender::GetMultiAff(1)->SetActuaBitmap(ID_640BUTTONA)			;
					else				 DIBRender::GetMultiAff(1)->SetActuaBitmap(ID_6408BUTTON)			;
					Invalidate()																	;
					break;
			}
			case 1:{
					DIBRender::GetBouton( ID_800BUTTONA )->SetHighLight( TRUE )						;
					if (resop != 2)	 DIBRender::GetMultiAff(2)->SetActuaBitmap(ID_800BUTTONA)			;
					else				 DIBRender::GetMultiAff(2)->SetActuaBitmap(ID_8001BUTTON)			;
					Invalidate()																	;
					break;
			}
			case 2:{
					DIBRender::GetBouton( ID_1024BUTTONA )->SetHighLight( TRUE )		;
					Invalidate()													;
					break;
			}
		}
	}

	CDialog::OnMouseMove(nFlags, point);
}
//----------------------------------------------------------------------------------------------------------------------------------------
void CVip2Interface::OnLButtonDown(UINT nFlags, CPoint point)
{
	switch (DIBRender::OuEstTu(point.x, point.y))
	{
		case ID_LAUNCHBUTTON:{
								if( nFlags&MK_SHIFT )	CVip2Dlg::m_Hiddenpart1 = TRUE	;	// lance le shit si shit appuyé

								LaunchDemo()	;
								break;
							 }
		case ID_QUITBUTTONA:{
								OnCancel()	;
								break;
							 }
		case ID_VURLBUTTONA:{
								ShellExecute(m_hWnd, "open", "http://www.popsyteam.org/VIP2/index.html", "", NULL, SW_MAXIMIZE );
								break;
							 }
		case ID_VTXTBUTTONA:{
								ShellExecute(m_hWnd, "open", "vip_en.txt", NULL, NULL, SW_SHOW );
								break;
							 }
		case ID_PURLBUTTONA:{
								ShellExecute(m_hWnd, "open", "http://www.popsyteam.org/index.html", "", NULL, SW_MAXIMIZE );
								break;
							 }
		case ID_NFOBUTTONA:{
								ShellExecute(m_hWnd, "open", "pouet.txt", NULL, NULL, SW_SHOW );
//								ShellExecute(m_hWnd, "open", "vip_en.txt", NULL, NULL, SW_SHOW );
								break;
							 }
		case ID_640BUTTONA:{
								DIBRender::ClearAllState()											;
								resol = 0;
								break;
							 }
		case ID_800BUTTONA:{
								DIBRender::ClearAllState()											;
								resol = 1;
								break;
							 }
		case ID_1024BUTTONA:{
								DIBRender::ClearAllState()											;
								resol = 2;
								break;
							 }
		case ID_NBPPBUTTONA:{
								bpp32 = 1 - bpp32;
								DIBRender::ClearAllState()											;
								DIBRender::GetBouton( ID_NBPPBUTTONA )->SetHighLight( TRUE )			;
								if (bpp32)	DIBRender::GetMultiAff(0)->SetActuaBitmap(ID_NBPPBUTTON32)	;
								else			DIBRender::GetMultiAff(0)->SetActuaBitmap(ID_NBPPBUTTON16)	;
								break;
							 }
		case ID_MONOBUTTONA:{
								stereo = 1 - stereo;
								DIBRender::ClearAllState()											;
								DIBRender::GetBouton( ID_MONOBUTTONA )->SetHighLight( TRUE )			;
								if (stereo)	DIBRender::GetMultiAff(0)->SetActuaBitmap(ID_STERBUTTON)	;
								else			DIBRender::GetMultiAff(0)->SetActuaBitmap(ID_MONOBUTTON)	;
								break;
							 }
		default:{						
					break;
				}

	}
	switch (resol)
	{
		case 0:{
				DIBRender::GetBouton( ID_640BUTTONA )->SetHighLight( TRUE )		;
				Invalidate()													;
				break;
		}
		case 1:{
				DIBRender::GetBouton( ID_800BUTTONA )->SetHighLight( TRUE )		;
				Invalidate()													;
				break;
		}
		case 2:{
				DIBRender::GetBouton( ID_1024BUTTONA )->SetHighLight( TRUE )		;
				Invalidate()													;
				break;
		}
	}
	
	CDialog::OnLButtonDown(nFlags, point);
}
//----------------------------------------------------------------------------------------------------------------------------------------
LRESULT CVip2Interface::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	if (message == WM_DESTROY) Active = FALSE;
	if (message == WM_QUIT) Active = FALSE;
	if (message == WM_CLOSE) Active = FALSE;
	if (message == WM_KEYUP)
	{
		switch (wParam)
		{
			case VK_ESCAPE : {
								OnCancel()		;
								break			;
							}

		}
	}
	
	if( message == WM_MOVE )
	{
		IsHide = TRUE	;
	}

	TimeWait -= clock() - LastTime	;
	LastTime = clock()				;

	return CDialog::DefWindowProc(message, wParam, lParam);
}
//----------------------------------------------------------------------------------------------------------------------------------------
BOOL CVip2Interface::OnEraseBkgnd(CDC* pDC)
{
	if (FirstPaint)
	{
//		if( TimeWait< 0)
		{
			FirstPaint = FALSE			;
			DIBRender::GetBackGround()	;
			Invalidate()				;
			ModifyStyleEx( 0, 0 )		;
		}
	}
	else
	{
		RECT	 windowrect;
		GetWindowRect(&windowrect);
		DIBRender::AffiSkinGen(pDC, m_hWnd, windowrect.left, windowrect.top )	;
	}

	//return CDialog::OnEraseBkgnd(pDC);
	return FALSE	;
}
//----------------------------------------------------------------------------------------------------------------------------------------
void CVip2Interface::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized) 
{
	CDialog::OnActivate(nState, pWndOther, bMinimized);

	if( nState==WA_INACTIVE )
	{
		ShowWindow( SW_MINIMIZE )	;
	}
	else
	{
		TimeWait = 500				;
		LastTime = clock()			;
		FirstPaint = TRUE			;
		ShowWindow( SW_SHOWNORMAL )	;
	}
}
//----------------------------------------------------------------------------------------------------------------------------------------
void CVip2Interface::IniAllBouton()
{
	DIBRender::AddBitmap( ID_LAUNCHBUTTON, "Datas\\Front\\txt_Gorange.jpg" )							;
	DIBRender::AddBouton( ID_LAUNCHBUTTON, 190, 152, GO_COLOR_SKIN, DIBRender::GetBitmap(ID_LAUNCHBUTTON) )	;

	DIBRender::AddBitmap( ID_640BUTTON, "Datas\\Front\\txt_640.jpg" )									;
	DIBRender::AddBitmap( ID_640BUTTONA, "Datas\\Front\\ecl_640.jpg" )									;
	DIBRender::AddBitmap( ID_6408BUTTON, "Datas\\Front\\ecl_640_800.jpg" )								;
	DIBRender::AddMultiAff(0, 190, 152)																;
	DIBRender::GetMultiAff(0)->AddBitmap(DIBRender::GetBitmap(ID_640BUTTON))							;
	DIBRender::AddMultiAff(1, 73, 52)																;
	DIBRender::GetMultiAff(1)->AddBitmap(DIBRender::GetBitmap(ID_6408BUTTON))							;
	DIBRender::GetMultiAff(1)->AddBitmap(DIBRender::GetBitmap(ID_640BUTTONA))							;
	DIBRender::AddBouton( ID_640BUTTONA, 73, 52, R640_COLOR_SKIN, DIBRender::GetBitmap(ID_640BUTTONA) )	;

	DIBRender::AddBitmap( ID_800BUTTON, "Datas\\Front\\txt_800.jpg" )									;
	DIBRender::AddBitmap( ID_800BUTTONA, "Datas\\Front\\ecl_800.jpg" )									;
	DIBRender::AddBitmap( ID_8001BUTTON, "Datas\\Front\\ecl_800_1024.jpg" )								;
	DIBRender::AddMultiAff(2, 33, 72)																;
	DIBRender::GetMultiAff(2)->AddBitmap(DIBRender::GetBitmap(ID_8001BUTTON))							;
	DIBRender::GetMultiAff(2)->AddBitmap(DIBRender::GetBitmap(ID_800BUTTONA))							;
	DIBRender::GetMultiAff(0)->AddBitmap(DIBRender::GetBitmap(ID_800BUTTON))							;
	DIBRender::AddBouton( ID_800BUTTONA, 33, 72, R800_COLOR_SKIN, DIBRender::GetBitmap(ID_800BUTTONA) )	;

	DIBRender::AddBitmap( ID_1024BUTTON, "Datas\\Front\\txt_1024.jpg" )									;
	DIBRender::GetMultiAff(0)->AddBitmap(DIBRender::GetBitmap(ID_1024BUTTON))							;
	DIBRender::AddBitmap( ID_1024BUTTONA, "Datas\\Front\\ecl_1024.jpg" )								;
	DIBRender::AddBouton( ID_1024BUTTONA, 22, 113, R1024_COLOR_SKIN, DIBRender::GetBitmap(ID_1024BUTTONA) )	;

	DIBRender::AddBitmap( ID_VURLBUTTON, "Datas\\Front\\txt_vip2.jpg" )									;
	DIBRender::GetMultiAff(0)->AddBitmap(DIBRender::GetBitmap(ID_VURLBUTTON))							;
	DIBRender::AddBitmap( ID_VURLBUTTONA, "Datas\\Front\\ecl_vip2.jpg" )								;
	DIBRender::AddBouton( ID_VURLBUTTONA, 421, 189, VURL_COLOR_SKIN, DIBRender::GetBitmap(ID_VURLBUTTONA) )	;

	DIBRender::AddBitmap( ID_VTXTBUTTON, "Datas\\Front\\txt_txt.jpg" )									;
	DIBRender::GetMultiAff(0)->AddBitmap(DIBRender::GetBitmap(ID_VTXTBUTTON))							;
	DIBRender::AddBitmap( ID_VTXTBUTTONA, "Datas\\Front\\ecl_txt.jpg" )									;
	DIBRender::AddBouton( ID_VTXTBUTTONA, 384, 238, VTXT_COLOR_SKIN, DIBRender::GetBitmap(ID_VTXTBUTTONA) )	;

	DIBRender::AddBitmap( ID_PURLBUTTON, "Datas\\Front\\txt_popsy.jpg" )								;
	DIBRender::GetMultiAff(0)->AddBitmap(DIBRender::GetBitmap(ID_PURLBUTTON))							;
	DIBRender::AddBitmap( ID_PURLBUTTONA, "Datas\\Front\\ecl_popsy.jpg" )								;
	DIBRender::AddBouton( ID_PURLBUTTONA, 344, 275, PURL_COLOR_SKIN, DIBRender::GetBitmap(ID_PURLBUTTONA) )	;

	DIBRender::AddBitmap( ID_QUITBUTTON, "Datas\\Front\\txt_quit.jpg" )									;
	DIBRender::GetMultiAff(0)->AddBitmap(DIBRender::GetBitmap(ID_QUITBUTTON))							;
	DIBRender::AddBitmap( ID_QUITBUTTONA, "Datas\\Front\\ecl_quit.jpg" )								;
	DIBRender::AddBouton( ID_QUITBUTTONA, 350, 140, QUIT_COLOR_SKIN, DIBRender::GetBitmap(ID_QUITBUTTONA) )	;

	DIBRender::AddBitmap( ID_NFOBUTTON, "Datas\\Front\\txt_nfo.jpg" )									;
	DIBRender::GetMultiAff(0)->AddBitmap(DIBRender::GetBitmap(ID_NFOBUTTON))							;
	DIBRender::AddBitmap( ID_NFOBUTTONA, "Datas\\Front\\ecl_nfo.jpg" )									;
	DIBRender::AddBouton( ID_NFOBUTTONA, 346, 110, NFO_COLOR_SKIN, DIBRender::GetBitmap(ID_NFOBUTTONA) )	;

	DIBRender::AddBitmap( ID_MONOBUTTON, "Datas\\Front\\txt_mono.jpg" )									;
	DIBRender::GetMultiAff(0)->AddBitmap(DIBRender::GetBitmap(ID_MONOBUTTON))							;
	DIBRender::AddBitmap( ID_STERBUTTON, "Datas\\Front\\txt_stereo.jpg" )									;
	DIBRender::GetMultiAff(0)->AddBitmap(DIBRender::GetBitmap(ID_STERBUTTON))							;
	DIBRender::AddBitmap( ID_MONOBUTTONA, "Datas\\Front\\ecl_mono.jpg" )								;
	DIBRender::AddBouton( ID_MONOBUTTONA, 330, 85, MONO_COLOR_SKIN, DIBRender::GetBitmap(ID_MONOBUTTONA) )	;

	DIBRender::AddBitmap( ID_NBPPBUTTON32, "Datas\\Front\\txt_32bpp.jpg" )								;
	DIBRender::GetMultiAff(0)->AddBitmap(DIBRender::GetBitmap(ID_NBPPBUTTON32))							;
	DIBRender::AddBitmap( ID_NBPPBUTTON16, "Datas\\Front\\txt_16bpp.jpg" )								;
	DIBRender::GetMultiAff(0)->AddBitmap(DIBRender::GetBitmap(ID_NBPPBUTTON16))							;
	DIBRender::AddBitmap( ID_NBPPBUTTONA, "Datas\\Front\\ecl_bpp.jpg")									;
	DIBRender::AddBouton( ID_NBPPBUTTONA, 310, 65, NBPP_COLOR_SKIN, DIBRender::GetBitmap(ID_NBPPBUTTONA) )	;
}
//----------------------------------------------------------------------------------------------------------------------------------------
void CVip2Interface::LaunchDemo()
{
	switch( resol )
	{
		case 0:
			CVip2Dlg::m_Resx = 640	;
			CVip2Dlg::m_Resy = 480	;
			break;
		case 1:
			CVip2Dlg::m_Resx = 800	;
			CVip2Dlg::m_Resy = 600	;
			break;
		case 2:
			CVip2Dlg::m_Resx = 1024	;
			CVip2Dlg::m_Resy = 768	;
			break;
	}

	CVip2Dlg::m_TrueColor = bpp32	;	// est-ce ke l'on veux du 32 bit
	CVip2Dlg::m_Stereo = stereo		;
//	CVip2Dlg::m_Hiddenpart1	= FALSE	;	// est-ce ke ya la partie cachée 1 ?
	OnOK()							;
}
//----------------------------------------------------------------------------------------------------------------------------------------
