//-----------------------------------------------------------------------------
// Purpose: 
// Input  : wParam - 
//			lParam - 
// Output : LRESULT
//-----------------------------------------------------------------------------
LRESULT CTextureBrowser::OnTexturewindowSelchange(WPARAM wParam, LPARAM lParam)
{
	IEditorTexture *pTex = g_Textures.FindActiveTexture(m_cTextureWindow.szCurTexture);
	CString str;
	char szName[MAX_PATH];

	if (pTex != NULL)
	{
		// create description of texture
		str.Format("%dx%d", pTex->GetWidth(), pTex->GetHeight());
		pTex->GetShortName(szName);
	}
	else
	{
		szName[0] = '\0';
	}

	m_cCurName.SetWindowText(szName);
	m_cCurDescription.SetWindowText(str);

	return(0);
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : lpDrawItemStruct - 
//-----------------------------------------------------------------------------
void CTextureBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
//	if(!pGD)
//		return;

	CDC dc;
	dc.Attach(lpDrawItemStruct->hDC);
	dc.SaveDC();

	RECT& r = lpDrawItemStruct->rcItem;

	int iFontHeight = dc.GetTextExtent("J", 1).cy;

	if (lpDrawItemStruct->itemID != -1)
	{
		IEditorTexture *pTex = (IEditorTexture *)GetItemDataPtr(lpDrawItemStruct->itemID);
		dc.SetROP2(R2_COPYPEN);
		CPalette *pOldPalette = NULL;

		if (pTex != NULL)
		{
			pTex->Load();

			pOldPalette = dc.SelectPalette(pTex->HasPalette() ? pTex->GetPalette() : g_pGameConfig->Palette, FALSE);
			dc.RealizePalette();
		}

		COLORREF dwBackColor = RGB(255,255,255);
		COLORREF dwForeColor = RGB(0,0,0);

		if (lpDrawItemStruct->itemState & ODS_SELECTED)
		{
			dwBackColor = GetSysColor(COLOR_HIGHLIGHT);
			dwForeColor = GetSysColor(COLOR_HIGHLIGHTTEXT);
		}

		// draw background
		CBrush brush;
		brush.CreateSolidBrush(dwBackColor);
		dc.FillRect(&r, &brush);

		if (pTex == NULL)
		{
			// separator
			dc.SelectStockObject(BLACK_PEN);
			dc.MoveTo(r.left, r.top+5);
			dc.LineTo(r.right, r.top+5);
		}
		else
		{
			char szName[MAX_PATH];
			int iLen = pTex->GetShortName(szName);
			// when we get here, we are drawing a regular graphic. we
			//  check the size of the rectangle - if it's > 32 (just
			//	a nice number), we're drawing an item in the drop list.
			if ((r.bottom - r.top) > 32)
			{
				// draw graphic
				CRect r2(r);
				r2.InflateRect(-4, -4);
				r2.right = r2.left + 64;
				pTex->Draw(&dc, r2, 0, 0);

				// draw name
				dc.SetTextColor(dwForeColor);
				dc.SetBkMode(TRANSPARENT);
				dc.TextOut(r2.right + 4, r2.top + 4, szName, iLen);
				
				// draw size
				sprintf(szName, "%dx%d", pTex->GetWidth(), pTex->GetHeight());
				dc.TextOut(r2.right + 4, r2.top + 4 + iFontHeight, szName, strlen(szName));
			}
			// if it's < 32, we're drawing the item in the "closed"
			//	combo box, so just draw the name of the texture
			else
			{
				// just draw name - 
				dc.SetTextColor(dwForeColor);
				dc.SetBkMode(TRANSPARENT);
				dc.TextOut(r.left + 4, r.top + 2, szName, iLen);
			}
		}

		if (pOldPalette)
		{
			dc.SelectPalette(pOldPalette, FALSE);
		}
	}
	else if (lpDrawItemStruct->itemState & ODS_FOCUS)
	{
		dc.DrawFocusRect(&r);
	}

	dc.RestoreDC(-1);
	dc.Detach();
}