/*************************************************************************\
* "$RCSfile: CDlgApp1.cpp,v $"                                            *
***************************************************************************
* Information by CVS or VSS:                                              *
*     Last check in on: $Date: 2011-10-20 06:52:30 $                      *
*     by                $Author: schluckebier $
*     Revision        : $Revision: 1.9 $                                 *
\*************************************************************************/
/*! \file CDlgApp.cpp
*	\brief Implementation CDlgApp Class (Example 1)
**************************************************************************/

#include "VIC_PS.h"
#include "CRegion.h"
#include "CLog.hpp"
#include "CPSApp.hpp"
#include "CDlg.hpp"
#include "CDlgApp1.hpp"

/*************************************************************************/
CDlgApp::CDlgApp(int x, int y, int Width, int Height)
		: CDlg(x, y, Width, Height)
/*************************************************************************/
/*! @brief Constructor of CDlgApp.
	@param x Horizontal position of dialog
	@param y Vertical position of dialog
	@param Width Width of dialog
	@param Height Height of dialog
**************************************************************************/
{
	SetID(DialogId::APP);
	GUI_DlgSetTitle(&m_Dlg, "Example 1");
	m_pApp->SetApplicationName("Example 1");

	// Add cancel button
	int iHeight = m_pApp->m_Icon[IconId::BACK].Height;
	GUI_DlgAddIconButton(&m_Dlg, 110, Height - (iHeight + 8),
		98, 98, "_Back", m_pApp->GetIcon(IconId::BACK), DLG_ABORT);
}

/*************************************************************************/
CDlgApp::~CDlgApp()
/*************************************************************************/
/*! @brief Destructor.
**************************************************************************/
{
}

/*************************************************************************/
int CDlgApp::OnUserIO(int nKey)
/*************************************************************************/
/*! @brief Function processes the user inputs.
	@param nKey Last key code the user entered
	@return \p m_Activity (!= \p DLG_EOF if the user has made an input)
**************************************************************************/
{
	m_Activity = 0;

	if (m_pApp->IsDlgInFocus(m_ID))
	{
		m_Activity = GUI_DlgWork(&m_Dlg, nKey); // m_Activity contains an event ID of the last user input
		switch (m_Activity)
		{
		case DLG_ABORT:	// Return to main dialog
			m_pApp->SetDlgNewFocus(DialogId::MAIN);
			m_pApp->RestoreView();
			m_bIsVisible = 0;
			break;
		case DLG_MOUSE_PRESSED:	// Handle mouse clicks in info and graph windows
			m_pApp->ChangeInfoArea(&m_Dlg);
			break;
		}
		if (m_Activity)
			GUI_DlgRefresh(&m_Dlg);
	}
	return m_Activity;
}

/******************************************************************************/
int CDlgApp::OnImage(YIMAGE *pSrc, CIMAGE *pDst)
/******************************************************************************/
/*! @brief Application process function

	The function is called from the grab task for every grabbed image. The
	function runs simultaneous to the grabbing of the next image. The image
	\p pDst is displayed by the main task by Ethernet.\n
	The priority of the grab task is higher than of the main task, so a slow
	network connection will not slow down the grab task. If the main task
	becomes to slow to display all it will drop images.
	@param pSrc Pointer to source image (Grabbed)
	@param pDst Pointer to display image (Displayed)
	@return Error code 
*******************************************************************************/
{
	if (!m_pApp->IsAppView())	// Application window is not active
		return -1;

	// Copy the image from pSrc to pDst
/*	GUI_CopyYArea2RGB(pSrc, pDst, 0, 0, pSrc->Width, pSrc->Height, 0, 0);
	return CAM_COLOR;*/

	YIMAGE yImage = GUI_YImage(pDst->pR, pDst->Width, pDst->Height);
	GUI_CopyYArea(pSrc, &yImage, 0, 0, pSrc->Width, pSrc->Height, 0, 0);
	return AppImageType::GRAY;
}

/******************************************************************************/
