// DUiButton.cpp: implementation of the CDUiButton class.
//
//////////////////////////////////////////////////////////////////////

#include "DUiMan.h"
#include "DirectXHelpers.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CDUiButton::CDUiButton()
{
    SetObjectType(DUI_BUTTON);
    m_bUseGraphic = FALSE;
}

CDUiButton::~CDUiButton()
{

}

DWORD CDUiButton::Display(BOOL bRefresh)
{
    DWORD       dwRetVal = 0;
    HRESULT     hr;
    DDBLTFX     ddbltfx;
    RECT        rSource;
    rSource.left = m_xPos;
    rSource.top = m_yPos;
    rSource.right = m_xPos + m_dwWidth;
    rSource.bottom = m_yPos + m_dwHeight;

    if (m_bUseGraphic)
    {

    }
    else
    {
        memset(&ddbltfx,0,sizeof(DDBLTFX));
        ddbltfx.dwSize = sizeof(DDBLTFX);
        //draw the outline in a color between the color of the background 
        //and either white or black depending on which is furthest
        ddbltfx.dwFillColor = GetFadeColor(m_dwBackgroundColor,5);
        hr = m_pddsMain->Blt(&rSource, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
        
        rSource.left += 1;
        rSource.top += 1;
        rSource.right -= 1;
        rSource.bottom -= 1;
        
        //draw the background
        ddbltfx.dwFillColor = m_dwBackgroundColor;
        hr = m_pddsMain->Blt(&rSource, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx);
    }

    return dwRetVal;
}

DWORD CDUiButton::DisplayText(BOOL bRefresh)
{
    DWORD dwRetVal = 0;

    if (m_bUseGraphic)
    {

    }
    else
    {
        dwRetVal = CDUiText::DisplayText(bRefresh);
    }
    return dwRetVal;
}

DWORD CDUiButton::Initialize()
{
    DWORD dwRetVal = 0;

    return dwRetVal;
}

DWORD CDUiButton::OnKey(UINT nChar, UINT nFlags)
{
    switch (nChar)
    {
    case VK_RETURN:
        PostMessage(g_pDUiManager->GetAppHWnd(),DUIM_ENTER,(WPARAM)this,0);
        break;
    }
    return 0;
}

