Esempio n. 1
0
//重画消息
void CButtonBar::OnPaint()
{
    CPaintDC dc(this);

    //获取位置
    CRect rcRect;
    GetClientRect(&rcRect);

    //加载资源
    CImageHandle ImageHotHandle(&m_ImageHot);
    CImageHandle ImageActiveHandle(&m_ImageActive);
    CImageHandle ImageNormalHandle(&m_ImageNormal);
    CImageHandle m_ImageBackGroundHandle(&m_ImageBackGround);

    //建立缓冲
    CDC BufferDC;
    CBitmap BufferBmp;
    BufferDC.CreateCompatibleDC(&dc);
    BufferBmp.CreateCompatibleBitmap(&dc,rcRect.Width(),rcRect.Height());
    BufferDC.SelectObject(&BufferBmp);

    //绘画背景
    CBrush BackBrush(TITLE_GROUND_COLOR);
    CPen BorderPen(PS_SOLID,1,CSkinWndObject::m_SkinAttribute.m_crInsideBorder);
    CPen * pOldPen=BufferDC.SelectObject(&BorderPen);
    CBrush * pOldBrush=BufferDC.SelectObject(&BackBrush);
    BufferDC.FillSolidRect(&rcRect,CSkinWndObject::m_SkinAttribute.m_crBackGround);
    BufferDC.RoundRect(&rcRect,CPoint(10,10));
    m_ImageBackGround.BitBlt(BufferDC,1,rcRect.Height()-m_ImageBackGround.GetHeight()-3);
    BufferDC.SelectObject(pOldPen);
    BufferDC.SelectObject(pOldBrush);
    BackBrush.DeleteObject();
    BorderPen.DeleteObject();

    //绘画按钮
    BufferDC.SetBkMode(TRANSPARENT);
    BufferDC.SelectObject(&CSkinAttribute::m_DefaultFont);

    //绘画按钮
    CRect rcButton;
    CSkinImage * pSkinImage=NULL;
    for (INT_PTR i=0; i<m_OptionsItemPtr.GetCount(); i++)
    {
        LPCTSTR pszButtonText=m_OptionsItemPtr[i]->GetButtonText();
        rcButton.SetRect(1,(int)(ITEM_HEIGHT*i+10+2*i),rcRect.Width(),(int)(ITEM_HEIGHT*(i+1)+10+2*i));
        if (i==m_nActiveItem)
        {
            pSkinImage=&m_ImageActive;
            BufferDC.SetTextColor(RGB(0,0,0));
        }
        else if (i==m_nHotItem)
        {
            pSkinImage=&m_ImageHot;
            BufferDC.SetTextColor(RGB(0,0,0));
        }
        else
        {
            pSkinImage=&m_ImageNormal;
            BufferDC.SetTextColor(RGB(0,0,0));
        }
        pSkinImage->BitBlt(BufferDC,rcButton.left,rcButton.top,ITEM_WIDTH,ITEM_HEIGHT,0,0,SRCCOPY);
        BufferDC.DrawText(pszButtonText,lstrlen(pszButtonText),rcButton,DT_END_ELLIPSIS|DT_VCENTER|DT_CENTER|DT_SINGLELINE);
    }

    //绘画界面
    dc.BitBlt(0,0,rcRect.Width(),rcRect.Height(),&BufferDC,0,0,SRCCOPY);

    //清理资源
    BufferDC.DeleteDC();
    BufferBmp.DeleteObject();

    return;
}
Esempio n. 2
0
//重画函数
void CControlWnd::OnPaint()
{
	CPaintDC dc(this);

	//获取位置
	CRect rcClient;
	GetClientRect(&rcClient);

	//创建缓冲
	CDC BufferDC;
	CBitmap BufferImage;
	BufferDC.CreateCompatibleDC(&dc);
	BufferImage.CreateCompatibleBitmap(&dc,rcClient.Width(),rcClient.Height());
	BufferDC.SelectObject(&BufferImage);

	//加载资源
	CImageHandle HandleControlTop(&m_ImageControlTop);
	CImageHandle HandleControlMid(&m_ImageControlMid);
	CImageHandle HandleControlButtom(&m_ImageControlButtom);
	CImageHandle HandleActionExplain(&m_ImageActionExplain);

	//绘画背景
	m_ImageControlTop.BitBlt(BufferDC,0,0);
	for (int nImageYPos=m_ImageControlTop.GetHeight();nImageYPos<rcClient.Height();nImageYPos+=m_ImageControlMid.GetHeight())
	{
		m_ImageControlMid.BitBlt(BufferDC,0,nImageYPos);
	}
	m_ImageControlButtom.BitBlt(BufferDC,0,rcClient.Height()-m_ImageControlButtom.GetHeight());

	//变量定义
	int nYPos=5;
	BYTE cbCurrentItem=0;
	BYTE cbExcursion[3]={0,1,2};
	BYTE cbItemKind[4]={WIK_LEFT,WIK_CENTER,WIK_RIGHT,WIK_PENG};

	//绘画扑克
	for (BYTE i=0;i<CountArray(cbItemKind);i++)
	{
		if ((m_cbActionMask&cbItemKind[i])!=0)
		{
			//绘画扑克
			for (BYTE j=0;j<3;j++)
			{
				BYTE cbCardData=m_cbCenterCard;
				if (i<CountArray(cbExcursion))
					cbCardData=m_cbCenterCard+j-cbExcursion[i];
				g_CardResource.m_ImageTableBottom.DrawCardItem(&BufferDC,cbCardData,j*26+12,nYPos+5);
			}

			//计算位置
			int nXImagePos=0;
			int nItemWidth=m_ImageActionExplain.GetWidth()/7;
			if ((m_cbActionMask&cbItemKind[i])&WIK_PENG)
				nXImagePos=nItemWidth;

			//绘画标志
			int nItemHeight=m_ImageActionExplain.GetHeight();
			m_ImageActionExplain.BitBlt(BufferDC,126,nYPos+5,nItemWidth,nItemHeight,nXImagePos,0);

			//绘画边框
			if (cbCurrentItem==m_cbCurrentItem)
			{
				BufferDC.Draw3dRect(7,nYPos,rcClient.Width()-14,ITEM_HEIGHT,RGB(255,255,0),RGB(255,255,0));
			}

			//设置变量
			++cbCurrentItem;
			nYPos+=ITEM_HEIGHT;
		}
	}

	//杠牌扑克
	for (BYTE i=0;i<CountArray(m_cbGangCard);i++)
	{
		if (m_cbGangCard[i]!=0)
		{
			//绘画扑克
			for (BYTE j=0;j<4;j++)
			{
				g_CardResource.m_ImageTableBottom.DrawCardItem(&BufferDC,m_cbGangCard[i],j*26+12,nYPos+5);
			}

			//绘画边框
			if (cbCurrentItem==m_cbCurrentItem)
			{
				BufferDC.Draw3dRect(7,nYPos,rcClient.Width()-14,ITEM_HEIGHT,RGB(255,255,0),RGB(255,255,0));
			}

			//绘画标志
			int nItemWidth=m_ImageActionExplain.GetWidth()/7;
			int nItemHeight=m_ImageActionExplain.GetHeight();
			m_ImageActionExplain.BitBlt(BufferDC,126,nYPos+5,nItemWidth,nItemHeight,nItemWidth*3,0);

			//设置变量
			cbCurrentItem++;
			nYPos+=ITEM_HEIGHT;
		}
		else
			break;
	}

	//绘画界面
	dc.BitBlt(0,0,rcClient.Width(),rcClient.Height(),&BufferDC,0,0,SRCCOPY);

	//清理资源
	BufferDC.DeleteDC();
	BufferImage.DeleteObject();

	return;
}
Esempio n. 3
0
/*
	Attach()

	Collega la toolbar al controllo.

	UINT	nID					l'id del controllo
	const CSize& sizeButton		dimensione (in pixel) del bottone (+2 rispetto al bitmap)
	const CSize& sizeBitmap		dimensione (in pixel) del bitmap usato per il bottone (-2 rispetto al bottone)
*/
BOOL CToolBarCtrlEx::Attach(const CSize& sizeButton,const CSize& sizeBitmap,UINT nID/*=(UINT)-1L*/,UINT nIDCold/*=(UINT)-1L*/,UINT nIDHot/*=(UINT)-1L*/)
{
	BOOL bAttached = FALSE;

	if(m_pToolBarButtonsList)
	{
		int nButtonsCount = m_pToolBarButtonsList->Count();

		if(nButtonsCount > 0)
		{
			m_pTbArray = new TBBUTTON[nButtonsCount];
			
			if(m_pTbArray)
			{
				TOOLBARBUTTON* t;
				char szResourceString[32];
				int nOfs = 0;
				int n;

				memset(m_szToolBarTextStrings,'\0',sizeof(m_szToolBarTextStrings));

				for(int i = 0; i < nButtonsCount; i++)
				{
					if((t = (TOOLBARBUTTON*)m_pToolBarButtonsList->GetAt(i))!=(TOOLBARBUTTON*)NULL)
					{
						memcpy((void*)&m_pTbArray[i],(void*)&t->button,sizeof(TBBUTTON));
						if(t->text!=0L)
						{
							if((n = ::LoadString(NULL,t->text,szResourceString,sizeof(szResourceString)-1))!=0)
							{
								if(nOfs+n < sizeof(m_szToolBarTextStrings)-2)
								{
									memcpy(m_szToolBarTextStrings+nOfs,szResourceString,n);
									nOfs += n+1;
								}
							}
						}
					}
					else
						memset((void*)&m_pTbArray[i],'\0',sizeof(TBBUTTON));
				}

				if(nIDCold!=(UINT)-1L && nIDHot!=(UINT)-1L)
				{
					CImageList imageList;
					CBitmap bitmap;

					// lista immagini standard
					bitmap.LoadBitmap(nIDCold);
					imageList.Create(sizeBitmap.cx,sizeBitmap.cy,ILC_COLORDDB|ILC_MASK,nButtonsCount,1);
					imageList.Add(&bitmap,RGB(255,0,255));
					this->SendMessage(TB_SETIMAGELIST,0,(LPARAM)imageList.m_hImageList);
					imageList.Detach();
					bitmap.Detach();

					// lista immagini 'hot'
					bitmap.LoadBitmap(nIDHot);
					imageList.Create(sizeBitmap.cx,sizeBitmap.cy,ILC_COLORDDB|ILC_MASK,nButtonsCount,1);
					imageList.Add(&bitmap,RGB(255,0,255));
					this->SendMessage(TB_SETHOTIMAGELIST,0,(LPARAM)imageList.m_hImageList);
					imageList.Detach();
					bitmap.Detach();
					bAttached = TRUE;
				}
				else if(nID!=(UINT)-1L)
				{
					CToolBarCtrl::SetBitmapSize(sizeButton);
					CToolBarCtrl::SetBitmapSize(sizeBitmap);
					CToolBarCtrl::AddBitmap(nButtonsCount,nID);
					bAttached = TRUE;
				}

				if(bAttached)
				{
					if(m_szToolBarTextStrings[0]!='\0')
						CToolBarCtrl::AddStrings(m_szToolBarTextStrings);
					CToolBarCtrl::AddButtons(nButtonsCount,m_pTbArray);
					CToolBarCtrl::AutoSize();
				}
			}
		}
	}

	return(bAttached);
}
void CTreeOptionsCtrlEx::OnCreateImageList()
{
	CDC* pDCScreen = GetDC();
	if (pDCScreen)
	{
		const int iBmpWidth = 16;
		const int iBmpHeight = 17;
		const int iBitmaps = 13;
		CBitmap bmpControls;
		if (bmpControls.CreateCompatibleBitmap(pDCScreen, iBmpWidth*iBitmaps, iBmpHeight))
		{
			if (m_ilTree.Create(iBmpWidth, iBmpHeight, m_uImageListColorFlags | ILC_MASK, 0, 1))
			{
				CDC dcMem;
				if (dcMem.CreateCompatibleDC(pDCScreen))
				{
					HTHEME hTheme = (g_xpStyle.IsThemeActive() && g_xpStyle.IsAppThemed()) ? g_xpStyle.OpenThemeData(NULL, L"BUTTON") : NULL;
					CBitmap* pOldBmp = dcMem.SelectObject(&bmpControls);
					dcMem.FillSolidRect(0, 0, iBmpWidth*iBitmaps, iBmpHeight, GetSysColor(COLOR_WINDOW));

					//int iCtrlWidth = iBmpWidth - 2;
					//int iCtrlHeight = iBmpHeight - 2;
					int iCtrlWidth = 16 - 3;
					int iCtrlHeight = 16 - 3;
					int iCtrlLeft = (iBmpWidth - iCtrlWidth) / 2;
					int iCtrlTop = (iBmpHeight - iCtrlHeight) / 2;

					// checkbox
					CRect rcBmp(0, 0, 0+iBmpWidth, 0+iBmpHeight);
					CRect rcCtrl(iCtrlLeft, iCtrlTop, iCtrlLeft+iCtrlWidth, iCtrlTop+iCtrlHeight);
					if (hTheme){
						g_xpStyle.DrawThemeBackground(hTheme, dcMem, BP_CHECKBOX, CBS_UNCHECKEDNORMAL, &rcCtrl, NULL);
						g_xpStyle.DrawThemeEdge(hTheme, dcMem, BP_CHECKBOX, CBS_UNCHECKEDNORMAL, &rcCtrl, 0, 0, NULL);
					}
					else
						dcMem.DrawFrameControl(&rcCtrl, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_FLAT);

					// checkbox checked
					rcCtrl.MoveToX(iCtrlLeft+iBmpWidth*1);
					if (hTheme){
						g_xpStyle.DrawThemeBackground(hTheme, dcMem, BP_CHECKBOX, CBS_CHECKEDNORMAL, &rcCtrl, NULL);
						g_xpStyle.DrawThemeEdge(hTheme, dcMem, BP_CHECKBOX, CBS_CHECKEDNORMAL, &rcCtrl, 0, 0, NULL);
					}
					else
						dcMem.DrawFrameControl(&rcCtrl, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_CHECKED | DFCS_FLAT);

					// radio
					rcCtrl.MoveToX(iCtrlLeft+iBmpWidth*2);
					if (hTheme){
						g_xpStyle.DrawThemeBackground(hTheme, dcMem, BP_RADIOBUTTON, RBS_UNCHECKEDNORMAL, &rcCtrl, NULL);
						g_xpStyle.DrawThemeEdge(hTheme, dcMem, BP_CHECKBOX, RBS_UNCHECKEDNORMAL, &rcCtrl, 0, 0, NULL);
					} else
						dcMem.DrawFrameControl(&rcCtrl, DFC_BUTTON, DFCS_BUTTONRADIO | DFCS_FLAT);

					// radio checked
					rcCtrl.MoveToX(iCtrlLeft+iBmpWidth*3);
					if (hTheme){
						g_xpStyle.DrawThemeBackground(hTheme, dcMem, BP_RADIOBUTTON, RBS_CHECKEDNORMAL, &rcCtrl, NULL);
						g_xpStyle.DrawThemeEdge(hTheme, dcMem, BP_CHECKBOX, RBS_CHECKEDNORMAL, &rcCtrl, 0, 0, NULL);
					} else
						dcMem.DrawFrameControl(&rcCtrl, DFC_BUTTON, DFCS_BUTTONRADIO | DFCS_CHECKED | DFCS_FLAT);

					// checkbox disabled
					rcCtrl.MoveToX(iCtrlLeft+iBmpWidth*4);
					if (hTheme){
						g_xpStyle.DrawThemeBackground(hTheme, dcMem, BP_CHECKBOX, CBS_UNCHECKEDDISABLED, &rcCtrl, NULL);
						g_xpStyle.DrawThemeEdge(hTheme, dcMem, BP_CHECKBOX, CBS_UNCHECKEDDISABLED, &rcCtrl, 0, 0, NULL);
					} else
						dcMem.DrawFrameControl(&rcCtrl, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_INACTIVE | DFCS_FLAT);

					// checkbox checked disabled
					rcCtrl.MoveToX(iCtrlLeft+iBmpWidth*5);
					if (hTheme){
						g_xpStyle.DrawThemeBackground(hTheme, dcMem, BP_CHECKBOX, CBS_CHECKEDDISABLED, &rcCtrl, NULL);
						g_xpStyle.DrawThemeEdge(hTheme, dcMem, BP_CHECKBOX, CBS_CHECKEDDISABLED, &rcCtrl, 0, 0, NULL);
					} else
						dcMem.DrawFrameControl(&rcCtrl, DFC_BUTTON, DFCS_BUTTONCHECK | DFCS_CHECKED | DFCS_INACTIVE | DFCS_FLAT);

					// radio disabled
					rcCtrl.MoveToX(iCtrlLeft+iBmpWidth*6);
					if (hTheme){
						g_xpStyle.DrawThemeBackground(hTheme, dcMem, BP_RADIOBUTTON, RBS_UNCHECKEDDISABLED, &rcCtrl, NULL);
						g_xpStyle.DrawThemeEdge(hTheme, dcMem, BP_CHECKBOX, RBS_UNCHECKEDDISABLED, &rcCtrl, 0, 0, NULL);
					} else
						dcMem.DrawFrameControl(&rcCtrl, DFC_BUTTON, DFCS_BUTTONRADIO | DFCS_INACTIVE | DFCS_FLAT);

					// radio checked disabled
					rcCtrl.MoveToX(iCtrlLeft+iBmpWidth*7);
					if (hTheme){
						g_xpStyle.DrawThemeBackground(hTheme, dcMem, BP_RADIOBUTTON, RBS_CHECKEDDISABLED, &rcCtrl, NULL);
						g_xpStyle.DrawThemeEdge(hTheme, dcMem, BP_CHECKBOX, RBS_CHECKEDDISABLED, &rcCtrl, 0, 0, NULL);
					} else
						dcMem.DrawFrameControl(&rcCtrl, DFC_BUTTON, DFCS_BUTTONRADIO | DFCS_CHECKED | DFCS_INACTIVE | DFCS_FLAT);

					// checkbox checked tri-state
					rcCtrl.MoveToX(iCtrlLeft+iBmpWidth*8);
					if (hTheme){
						g_xpStyle.DrawThemeBackground(hTheme, dcMem, BP_CHECKBOX, CBS_MIXEDNORMAL, &rcCtrl, NULL);
						g_xpStyle.DrawThemeEdge(hTheme, dcMem, BP_CHECKBOX, CBS_MIXEDNORMAL, &rcCtrl, 0, 0, NULL);
					} else
						dcMem.DrawFrameControl(&rcCtrl, DFC_BUTTON, DFCS_BUTTON3STATE | DFCS_CHECKED | DFCS_FLAT);

					// checkbox checked tri-state disabled 
					rcCtrl.MoveToX(iCtrlLeft+iBmpWidth*9);
					if (hTheme){
						g_xpStyle.DrawThemeBackground(hTheme, dcMem, BP_CHECKBOX, CBS_MIXEDDISABLED, &rcCtrl, NULL);
						g_xpStyle.DrawThemeEdge(hTheme, dcMem, BP_CHECKBOX, CBS_MIXEDDISABLED, &rcCtrl, 0, 0, NULL);
					} else
						dcMem.DrawFrameControl(&rcCtrl, DFC_BUTTON, DFCS_BUTTON3STATE | DFCS_CHECKED | DFCS_INACTIVE | DFCS_FLAT);

					ASSERT( TREEOPTSCTRLIMG_EDIT == 11 );
					rcBmp.MoveToX(iBmpWidth*11);
					rcCtrl.MoveToX(iCtrlLeft+iBmpWidth*11);
					CFont font;
					font.CreatePointFont(10, _T("Courier"));
					CFont* pOldFont = dcMem.SelectObject(&font);
					dcMem.TextOut(rcCtrl.left+2, rcCtrl.top, _T("I"));
					dcMem.SelectObject(pOldFont);
					CRect rcEdge(rcBmp);
					rcEdge.top += 1;
					rcEdge.bottom -= 1;
					dcMem.DrawEdge(&rcEdge, EDGE_ETCHED, BF_RECT);

					if (hTheme){
						g_xpStyle.CloseThemeData(hTheme);
						hTheme = NULL;
					}

					hTheme = (g_xpStyle.IsThemeActive() && g_xpStyle.IsAppThemed()) ? g_xpStyle.OpenThemeData(NULL, L"COMBOBOX") : NULL;
					rcCtrl.MoveToX(iCtrlLeft+iBmpWidth*12);
					if (hTheme){
						g_xpStyle.DrawThemeBackground(hTheme, dcMem, CP_DROPDOWNBUTTON, CBXS_NORMAL, &rcCtrl, NULL);
						g_xpStyle.DrawThemeEdge(hTheme, dcMem, CP_DROPDOWNBUTTON, CBXS_NORMAL, &rcCtrl, 0, 0, NULL);
					} else
						dcMem.DrawFrameControl(&rcCtrl, DFC_SCROLL, DFCS_SCROLLCOMBOBOX | DFCS_FLAT);

					dcMem.SelectObject(pOldBmp);
					m_ilTree.Add(&bmpControls, RGB(255,0,255));
					if (hTheme)
						g_xpStyle.CloseThemeData(hTheme);
				}
			}
		}
		ReleaseDC(pDCScreen);
	}
}
Esempio n. 5
0
void CSkinListBox::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
	//没有节点就不用继续执行了
	if( GetCount()==0 ) return;

	//变量定义
	CRect rcItem=lpDrawItemStruct->rcItem;
	CDC * pDCControl=CDC::FromHandle(lpDrawItemStruct->hDC);

 	//创建缓冲
 	CDC BufferDC;
 	CBitmap ImageBuffer;
 	BufferDC.CreateCompatibleDC(pDCControl);
 	ImageBuffer.CreateCompatibleBitmap(pDCControl,rcItem.Width(),rcItem.Height());
 
 	//设置环境
 	BufferDC.SelectObject(&ImageBuffer);
	BufferDC.SelectObject(GetCtrlFont());

	//获取字符
	CString strString;
	GetText(lpDrawItemStruct->itemID,strString);

	//计算位置
	CRect rcString;
	rcString.SetRect(4,0,rcItem.Width()-8,rcItem.Height());

	//颜色定义
	COLORREF crTextColor=((lpDrawItemStruct->itemState&ODS_SELECTED)!=0)?m_colSelectText:m_colNormalText;

	//绘画背景
	BufferDC.FillSolidRect(0,0,rcItem.Width(),rcItem.Height(),m_colBack);

	//节点选中
	if ( (lpDrawItemStruct->itemState&ODS_SELECTED) != 0 )
	{
		if ( m_pSelectImg!= NULL && !m_pSelectImg->IsNull() )
		{
			m_pSelectImg->Draw(&BufferDC,CRect(0,0,rcItem.Width(),rcItem.Height()));
		}
	}

	//节点高亮
	else if ( m_nHovenItem == lpDrawItemStruct->itemID )
	{
		if ( m_pBackImgH!= NULL && !m_pBackImgH->IsNull() )
		{
			m_pBackImgH->Draw(&BufferDC,CRect(0,0,rcItem.Width(),rcItem.Height()));
		}
	}

	//绘画字符
	BufferDC.SetBkMode(TRANSPARENT);
	BufferDC.SetTextColor(crTextColor);
	BufferDC.DrawText(strString,&rcString,DT_VCENTER|DT_SINGLELINE);

	//绘画界面
	pDCControl->BitBlt(rcItem.left,rcItem.top,rcItem.Width(),rcItem.Height(),&BufferDC,0,0,SRCCOPY);

 	//清理资源
 	BufferDC.DeleteDC();
 	ImageBuffer.DeleteObject();
}
Esempio n. 6
0
CSmfReadMap::CSmfReadMap(std::string mapname)
	: file(mapname)
{
	PrintLoadMsg("Opening map file");

	ConfigureAnisotropy();
	usePBO = !!configHandler->Get("UsePBO", 1);

	for(int a=0;a<1024;++a){
		for(int b=0;b<3;++b){
			float c=max(mapInfo->water.minColor[b],mapInfo->water.baseColor[b]-mapInfo->water.absorb[b]*a);
			waterHeightColors[a*4+b]=(unsigned char)(c*210);
		}
		waterHeightColors[a*4+3]=1;
	}

	const SMFHeader& header = file.GetHeader();

	width=header.mapx;
	height=header.mapy;
	gs->mapx=header.mapx;
	gs->mapy=header.mapy;
	gs->mapSquares = gs->mapx*gs->mapy;
	gs->hmapx=gs->mapx/2;
	gs->hmapy=gs->mapy/2;
	gs->pwr2mapx=next_power_of_2(gs->mapx);
	gs->pwr2mapy=next_power_of_2(gs->mapy);

//	logOutput.Print("%i %i",gs->mapx,gs->mapy);
	float3::maxxpos=gs->mapx*SQUARE_SIZE-1;
	float3::maxzpos=gs->mapy*SQUARE_SIZE-1;

	heightmap=new float[(gs->mapx+1)*(gs->mapy+1)];

	const CMapInfo::smf_t& smf = mapInfo->smf;
	const float minH = smf.minHeightOverride ? smf.minHeight : header.minHeight;
	const float maxH = smf.maxHeightOverride ? smf.maxHeight : header.maxHeight;

	const float base = minH;
	const float mod = (maxH - minH) / 65536.0f;

	file.ReadHeightmap(heightmap, base, mod);

	CReadMap::Initialize();

	for (unsigned int a = 0; a < mapname.size(); ++a) {
		mapChecksum += mapname[a];
		mapChecksum *= mapname[a];
	}

	PrintLoadMsg("Loading detail textures");

	detailTexName = mapInfo->smf.detailTexName;

	CBitmap bm;
	if (!bm.Load(detailTexName)) {
		throw content_error("Could not load detail texture from file " + detailTexName);
	}
	glGenTextures(1, &detailTex);
	glBindTexture(GL_TEXTURE_2D, detailTex);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
	glBuildMipmaps(GL_TEXTURE_2D, GL_RGBA8, bm.xsize, bm.ysize, GL_RGBA, GL_UNSIGNED_BYTE, bm.mem);
	if (anisotropy != 0.0f) {
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy);
	}

	PrintLoadMsg("Creating overhead texture");

	unsigned char* buf=new unsigned char[MINIMAP_SIZE];
	file.ReadMinimap(buf);

	glGenTextures(1, &minimapTex);
	glBindTexture(GL_TEXTURE_2D, minimapTex);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
	//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 512, 512, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf);
	int offset=0;
	for (unsigned int i = 0; i < MINIMAP_NUM_MIPMAP; i++) {
		int mipsize = 1024>>i;

		int size = ((mipsize+3)/4)*((mipsize+3)/4)*8;

		glCompressedTexImage2DARB(GL_TEXTURE_2D, i, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, mipsize, mipsize, 0, size, buf + offset);

		offset += size;
	}
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, MINIMAP_NUM_MIPMAP-1 );

	delete[] buf;

	PrintLoadMsg("Creating ground shading");

	unsigned char* bufZero = new unsigned char[gs->pwr2mapx * gs->pwr2mapy * 4];
	memset(bufZero, 0, gs->pwr2mapx * gs->pwr2mapy * 4);

	glGenTextures(1, &shadowTex);
	glBindTexture(GL_TEXTURE_2D, shadowTex);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, gs->pwr2mapx, gs->pwr2mapy, 0, GL_RGBA, GL_UNSIGNED_BYTE, bufZero);

	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
	if (anisotropy != 0.0f) {
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy);
	}

	delete[] bufZero;

	HeightmapUpdated(0, gs->mapx, 0, gs->mapy);

	groundDrawer=new CBFGroundDrawer(this);

	file.ReadFeatureInfo ();
}
void CBCGPHeaderCtrl::OnDrawItem (CDC* pDC, int iItem, CRect rect, BOOL bIsPressed,
                                  BOOL bIsHighlighted)
{
    ASSERT_VALID (this);
    ASSERT_VALID (pDC);

    const int nTextMargin = 5;

    //-------------
    // Draw border:
    //-------------
    CBCGPVisualManager::GetInstance ()->OnDrawHeaderCtrlBorder (this, pDC,
            rect, bIsPressed, bIsHighlighted);

    if (iItem < 0)
    {
        return;
    }

    int nSortVal = 0;
    if (m_mapColumnsStatus.Lookup (iItem, nSortVal) &&
            nSortVal != 0)
    {
        //-----------------
        // Draw sort arrow:
        //-----------------
        CRect rectArrow = rect;
        rectArrow.DeflateRect (5, 5);
        rectArrow.left = rectArrow.right - rectArrow.Height ();

        if (bIsPressed)
        {
            rectArrow.right++;
            rectArrow.bottom++;
        }

        rect.right = rectArrow.left - 1;

        int dy2 = (int) (.134 * rectArrow.Width ());
        rectArrow.DeflateRect (0, dy2);

        m_bAscending = nSortVal > 0;
        OnDrawSortArrow (pDC, rectArrow);
    }

    HD_ITEM hdItem;
    memset (&hdItem, 0, sizeof (hdItem));
    hdItem.mask = HDI_FORMAT | HDI_BITMAP | HDI_TEXT | HDI_IMAGE;

    TCHAR szText [256];
    hdItem.pszText = szText;
    hdItem.cchTextMax = 255;

    if (!GetItem (iItem, &hdItem))
    {
        return;
    }

    //-----------------------
    // Draw bitmap and image:
    //-----------------------
    if ((hdItem.fmt & HDF_IMAGE) && hdItem.iImage >= 0)
    {
        // By Max Khiszinsky:

        //---------------------------------------
        // The column has a image from imagelist:
        //---------------------------------------
        CImageList* pImageList = GetImageList ();
        if (pImageList != NULL)
        {
            int cx = 0;
            int cy = 0;

            VERIFY (::ImageList_GetIconSize (*pImageList, &cx, &cy));

            CPoint pt = rect.TopLeft ();
            pt.x ++;
            pt.y = (rect.top + rect.bottom - cy) / 2;

            VERIFY (pImageList->Draw (pDC, hdItem.iImage, pt, ILD_NORMAL));

            rect.left += cx;
        }
    }

    if ((hdItem.fmt & (HDF_BITMAP | HDF_BITMAP_ON_RIGHT)) && hdItem.hbm != NULL)
    {
        CBitmap* pBmp = CBitmap::FromHandle (hdItem.hbm);
        ASSERT_VALID (pBmp);

        BITMAP bmp;
        pBmp->GetBitmap (&bmp);

        CRect rectBitmap = rect;
        if (hdItem.fmt & HDF_BITMAP_ON_RIGHT)
        {
            rectBitmap.right--;
            rect.right = rectBitmap.left = rectBitmap.right - bmp.bmWidth;
        }
        else
        {
            rectBitmap.left++;
            rect.left = rectBitmap.right = rectBitmap.left + bmp.bmWidth;
        }

        rectBitmap.top += max (0, (rectBitmap.Height () - bmp.bmHeight) / 2);
        rectBitmap.bottom = rectBitmap.top + bmp.bmHeight;

        pDC->DrawState (rectBitmap.TopLeft (), rectBitmap.Size (), pBmp, DSS_NORMAL);
    }

    //-----------
    // Draw text:
    //-----------
    if (hdItem.fmt & HDF_STRING)
    {
        COLORREF clrText = 	CBCGPVisualManager::GetInstance ()->GetHeaderCtrlTextColor (this, bIsPressed, bIsHighlighted);
        COLORREF clrTextOld = (COLORREF)-1;
        if (clrText != (COLORREF)-1)
        {
            clrTextOld = pDC->SetTextColor (clrText);
        }

        CRect rectLabel = rect;
        rectLabel.DeflateRect (nTextMargin, 0);

        CString strLabel = hdItem.pszText;

        UINT uiTextFlags = DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX;
        if (hdItem.fmt & HDF_CENTER)
        {
            uiTextFlags |= DT_CENTER;
        }
        else if (hdItem.fmt & HDF_RIGHT)
        {
            uiTextFlags |= DT_RIGHT;
        }

        pDC->DrawText (strLabel, rectLabel, uiTextFlags);

        if (clrText != (COLORREF)-1)
        {
            pDC->SetTextColor (clrTextOld);
        }
    }
}
Esempio n. 8
0
void CDisplayView::drawofl(void)
{
  CFrame *parentframe = getParent();
  if(!parentframe) return;

  CDrawContext *srccon;
  long dsplw,dsplh;

#if 1     // quantise near-grey to grey for transparent-draw
          // could be removed if q'ed bitmap is compiled to resource
  if(stConverted==false)
  {
    stConverted = true;

    srccon = new CDrawContext(parentframe,0);
    COffscreenContext *charcon;
    CColor pcl;
    int w,h;

    for(int nf=0; nf<kNumFtTypes; nf++)
    {
      dsplw = stFonts[nf].font->getWidth();
      dsplh = stFonts[nf].font->getHeight();
      charcon = new COffscreenContext(srccon,stFonts[nf].font,true);
      CPoint cp = CPoint(0,0);
      CRect  cr = CRect(0,0, dsplw,dsplh);
      stFonts[nf].font->draw(charcon, cr, cp );
      for(w=0; w<dsplw; w++)
      {
        for(h=0; h<dsplh; h++)
        {
          #define RNG 14

          pcl = charcon->getPoint(CPoint(w,h));
          if( pcl.red==128 && pcl.green==128 && pcl.blue==128 ) continue;
          if(pcl.red<(128-RNG)   || pcl.red>128+RNG)   continue;
          if(pcl.green<(128-RNG) || pcl.green>128+RNG) continue;
          if(pcl.blue<(128-RNG)  || pcl.blue>128+RNG)  continue;
          pcl.red=pcl.green=pcl.blue = 128;
          charcon->drawPoint(CPoint(w,h), pcl);
        }
      }
      delete charcon;
    }
    delete srccon;
  }
#endif

#if 0   // 0=PixelDrawing, else transparent drawing

  COffscreenContext *charcon;
  CPoint cp;
  CRect  cr;
  char c;
  dsplw = mDsplBmp->getWidth();
  dsplh = mDsplBmp->getHeight();
  CBitmap *bgnd = parentframe->getBackground();
  
  // get fresh background image
  cp = CPoint(size.left+mXAlign,size.top+mYAlign);
  cr = CRect(0,0,dsplw,dsplh);
  srccon = new CDrawContext(parentframe,0);
  COffscreenContext *dspcon = new COffscreenContext(srccon,mDsplBmp,true);
  bgnd->draw(dspcon, cr, cp);

  // get fresh font image
  cp = CPoint(0,0);
  cr = CRect(0,0, mFontBmp->getWidth(),mFontBmp->getHeight());
  charcon = new COffscreenContext(parentframe,mFontBmp->getWidth(),mFontBmp->getHeight());

  CColor scl,dcl;
  mFontBmp->draw(charcon, cr, cp );

  for(int i=0; i<mCharsfit && (c = mText[i]); i++)
  {
    int h,w,wd = i*mPaintWidth;
    int ws = (c - 33) * mCharWidth; // left position in font

    if(ws < 0)
    {
      continue;
    }

    for(w=0,ws+=mCharOfs; w<(mCharWidth-mCharOfs); w++,ws++,wd++)
    {
      for(h=0; h<dsplh; h++)
      {
        scl = charcon->getPoint(CPoint(ws,h));
        if( scl.red==128 && scl.green==128 && scl.blue==128 ) continue;
        dcl = dspcon->getPoint(CPoint(wd,h));
        dcl.red   = stClip[scl.red + (scl.red>>1) + dcl.red];
        dcl.green = stClip[scl.green + (scl.green>>1) + dcl.green];
        dcl.blue  = stClip[scl.blue + (scl.blue>>1) + dcl.blue];
        dspcon->drawPoint(CPoint(wd,h), dcl);
      }
    }
  }

  delete srccon;
  delete dspcon;
  delete charcon;

#else

  CPoint cp;
  CRect  cr;
  char c;
  dsplw = mDsplBmp->getWidth();
  dsplh = mDsplBmp->getHeight();

  // get fresh background image
  CBitmap *bgnd = parentframe->getBackground();
  cp = CPoint(size.left+mXAlign,size.top+mYAlign);
  cr = CRect(0,0,dsplw,dsplh);
  srccon = new CDrawContext(parentframe,0);
  COffscreenContext *dspcon = new COffscreenContext(srccon,mDsplBmp,true);
  bgnd->draw(dspcon, cr, cp);

  for(int i=0; i<mCharsfit && (c = mText[i]); i++)
  {
    int ws = (c - 33) * mCharWidth; // left position in font

    if(ws < 0)
    {
      continue;
    }

    CPoint dp = CPoint(ws+mCharOfs,0);
    CRect  dr = CRect(i*mPaintWidth,0, i*mPaintWidth+mCharWidth,dsplh);
    mFontBmp->drawTransparent(dspcon, dr, dp);
  }

  delete srccon;
  delete dspcon;

#endif

  m1stSight = false;
  setDirty(true);
}
Esempio n. 9
0
void CSm3ReadMap::Initialize (const char *mapname)
{
	try {
		string lmsg = "Loading " + string(mapname);
		PrintLoadMsg(lmsg.c_str());
		GLint tu;
		glGetIntegerv(GL_MAX_TEXTURE_UNITS, &tu);

		renderer = SAFE_NEW terrain::Terrain;

		renderer->config.cacheTextures=false;

		renderer->config.forceFallbackTexturing = !!configHandler.GetInt("SM3ForceFallbackTex", 0);

		if (!renderer->config.forceFallbackTexturing && GLEW_ARB_fragment_shader && GLEW_ARB_shading_language_100) {
			renderer->config.useBumpMaps = true;
			renderer->config.anisotropicFiltering = 0.0f;
		}

		renderer->config.useStaticShadow = false;

		renderer->config.terrainNormalMaps = false;
		renderer->config.normalMapLevel = 3;

		if (shadowHandler->drawShadows)
			renderer->config.useShadowMaps = true;

		if (!mapInfo->sm3.minimap.empty()) {
			CBitmap bmp;
			if(bmp.Load(mapInfo->sm3.minimap))
				minimapTexture=bmp.CreateTexture(true);
		}

/*		int numStages=atoi(mapDefParser.SGetValueDef("0", "map\\terrain\\numtexturestages").c_str());
		int maxStages=configHandler.GetInt("SM3MaxTextureStages", 10);
		if (numStages > maxStages) {
			renderer->config.cacheTextures = true;
			renderer->config.cacheTextureSize = 256;
		//	renderer->config.detailMod
		}
*/
		Sm3LoadCB loadcb;
		terrain::LightingInfo lightInfo;
		lightInfo.ambient = mapInfo->light.groundAmbientColor;
		terrain::StaticLight light;
		light.color = mapInfo->light.groundSunColor;
		light.directional = false;
		light.position = mapInfo->light.sunDir *1000000;
		lightInfo.staticLights.push_back (light);
		renderer->Load (GetMapDefParser(), &lightInfo, &loadcb);

		height = width = renderer->GetHeightmapWidth ()-1;

		// Set global map info
		gs->mapx=width;
		gs->mapy=height;
		gs->mapSquares = width*height;
		gs->hmapx=width/2;
		gs->hmapy=height/2;
		gs->pwr2mapx=next_power_of_2(width);
		gs->pwr2mapy=next_power_of_2(height);

		float3::maxxpos=width*SQUARE_SIZE-1;
		float3::maxzpos=height*SQUARE_SIZE-1;

		CReadMap::Initialize();

		const TdfParser& mapDefParser = GetMapDefParser();
		if (mapDefParser.SectionExist("map\\featuretypes")) {
			int numTypes = atoi(mapDefParser.SGetValueDef("0", "map\\featuretypes\\numtypes").c_str());
			for (int a=0;a<numTypes;a++) {
				char loc[100];
				SNPRINTF(loc, 100, "map\\featuretypes\\type%d", a);
				featureTypes.push_back (SAFE_NEW std::string(mapDefParser.SGetValueDef("TreeType0", loc)));
			}
		}
		LoadFeatureData();

		groundDrawer = SAFE_NEW CSm3GroundDrawer (this);
	}
	catch(content_error& e)
	{
		ErrorMessageBox(e.what(), "Error:", MBF_OK);
	}
}
Esempio n. 10
0
void CIMMain::OnPaint()
{
	CPaintDC   dc(this); 

	//   Create   a   memory   DC   compatible   with   the   paint   DC 
	CDC   memDC; 
	memDC.CreateCompatibleDC(&dc); 

	CRect   rcClip,   rcClient; 
	dc.GetClipBox(   &rcClip   ); 
	GetClientRect(&rcClient); 

	//   Select   a   compatible   bitmap   into   the   memory   DC 
	CBitmap   bitmap; 
	bitmap.CreateCompatibleBitmap(   &dc,   rcClient.Width(),   rcClient.Height()   ); 
	memDC.SelectObject(   &bitmap   ); 

	//dc.SetBkMode(TRANSPARENT);

	//   Set   clip   region   to   be   same   as   that   in   paint   DC 
	CRgn   rgn; 
	rgn.CreateRectRgnIndirect(   &rcClip   ); 
	memDC.SelectClipRgn(&rgn); 
	rgn.DeleteObject(); 

	//   First   let   the   control   do   its   default   drawing. 
	CWnd::DefWindowProc(WM_PAINT,   (WPARAM)memDC.m_hDC,   0); 

	HTREEITEM   hItem   =   GetFirstVisibleItem(); 

	int   iItemCount   =   GetVisibleCount()   +   1; 
	while(hItem   &&   iItemCount--) 
	{ 
		CRect   rect; 

		//   Do   not   meddle   with   selected   items   or   drop   highlighted   items 
		UINT   selflag   =   TVIS_DROPHILITED   |   TVIS_SELECTED; 
		Color_Font   cf; 


		if   ((GetItemState(hItem,   selflag)   &   selflag)   
			&&   ::GetFocus()   ==   m_hWnd) 
			; 
		else   if   (m_mapColorFont.Lookup(hItem,   cf)) 
		{ 
			CFont   *pFontDC; 
			CFont   fontDC; 
			LOGFONT   logfont; 

			if(cf.logfont.lfFaceName[0]   !=   '\0 ')   
				logfont   =   cf.logfont; 
			else   { 
				//   No   font   specified,   so   use   window   font 
				CFont   *pFont   =   GetFont();
				pFont-> GetLogFont(   &logfont   ); 
			} 

			if(GetItemBold(hItem)) 
				logfont.lfWeight   =   700; 

			fontDC.CreateFontIndirect(&logfont); 
			pFontDC   =   memDC.SelectObject(&fontDC   ); 

			if(cf.color   !=   (COLORREF)   -   1) 
				memDC.SetTextColor(cf.color); 
			else 
				memDC.SetTextColor(GetSysColor(COLOR_WINDOWTEXT)); 


			CString   sItem   =   GetItemText(hItem); 

			GetItemRect(hItem,   &rect,   TRUE); 
			//memDC.SetBkColor( GetSysColor(COLOR_WINDOW )); 
			memDC.SetBkMode(TRANSPARENT);
			memDC.TextOut(rect.left   +   2,   rect.top   +   5,   sItem); 

			memDC.SelectObject(pFontDC); 
		} 

		hItem   =   GetNextVisibleItem(hItem); 
	} 


	dc.BitBlt(rcClip.left,   rcClip.top,   rcClip.Width(),   rcClip.Height(),   &memDC,   
		rcClip.left,   rcClip.top,   SRCCOPY); 

	memDC.DeleteDC(); 
}
Esempio n. 11
0
BOOL CDrawMandelbrotDlg::Draw()
{
	CRect rect;
	GetWindowRect(&rect);
	int width = rect.Width();
	int height = rect.Height();

	m_top  = m_bottom + (m_right - m_left) * height / width;

	CClientDC dc(this);
	CDC memDC;
	memDC.CreateCompatibleDC(&dc);

	CBitmap bmp;
	bmp.CreateCompatibleBitmap(&dc, width, height);
	memDC.SelectObject(&bmp);

	BITMAPINFO bmpInfo; 
	bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);  
	bmpInfo.bmiHeader.biWidth = width; 
	bmpInfo.bmiHeader.biHeight = -height;
	bmpInfo.bmiHeader.biPlanes = 1;  
	bmpInfo.bmiHeader.biBitCount = 24;  
	bmpInfo.bmiHeader.biCompression = BI_RGB;  
	bmpInfo.bmiHeader.biSizeImage = 0;  
	bmpInfo.bmiHeader.biXPelsPerMeter = 3000;  
	bmpInfo.bmiHeader.biYPelsPerMeter = 3000;  
	bmpInfo.bmiHeader.biClrUsed = 0;  
	bmpInfo.bmiHeader.biClrImportant = 0;  

	long bytesPerLine = (bmpInfo.bmiHeader.biWidth * 3 + 3) / 4 * 4;
	long bufferSize = bytesPerLine * height;

	BYTE *buffer = new BYTE[bufferSize];
	memset(buffer, 0, bufferSize);

	int maxLoop = 1500;

	double w = m_right - m_left;
	double h = m_top - m_bottom;

	int iTmp = -1;
	int index = -1;
	#pragma omp parallel for
	for (int i = 0; i < width; ++i)
	{
		for (int j = 0; j < height; ++j)
		{
			ComplexNum z;
			ComplexNum c;
			double dTmp;

			int loopCount = 0;
			c.real = w * (i + 1) / width + m_left;
			c.imag = h * (j + 1) / height + m_bottom;
			
			do
			{
				dTmp = z.real * z.real - z.imag * z.imag + c.real;
				z.imag = 2 * z.real * z.imag + c.imag;
				z.real = dTmp;
				++loopCount;
			} while((z.real * z.real + z.imag * z.imag) < 4 && loopCount < maxLoop);

			if (loopCount != maxLoop)
			{
				int iTmp = loopCount  % 255;
				index = j * bytesPerLine + i * 3;
				buffer[index] = iTmp;
				buffer[index + 1] = iTmp * 5;
				buffer[index + 2] = iTmp * 10;
			}
		}
	}

	SetDIBits(dc.m_hDC, bmp, 0, height, buffer, &bmpInfo, DIB_RGB_COLORS);
	delete []buffer;

	dc.BitBlt(0, 0, bmpInfo.bmiHeader.biWidth, height, &memDC, 0, 0, SRCCOPY);

	return true;
}
Esempio n. 12
0
void CIMTree::OnPaint() 
{
	CPaintDC dc(this); // device context for painting

	CRect rcClip, rcClient;
	dc.GetClipBox( &rcClip );
	GetClientRect(&rcClient);

	// Create a compatible memory DC 
	CDC memDC;
	memDC.CreateCompatibleDC( &dc );
	
	// Select a compatible bitmap into the memory DC
	CBitmap bitmap, bmpImage;
	bitmap.CreateCompatibleBitmap( &dc, rcClient.Width(), rcClient.Height() );
	CBitmap *OldBitmap = memDC.SelectObject( &bitmap );

	// First let the control do its default drawing.
	CTreeCtrl::DefWindowProc( WM_PAINT, (WPARAM)memDC.m_hDC, 0 );


/*
	// create the font
	CFont *pFontDC;
	CFont fontDC, boldFontDC;
	LOGFONT logfont;

	CFont *pFont = GetFont();
	pFont->GetLogFont( &logfont );

	fontDC.CreateFontIndirect( &logfont );		//普通字体
	pFontDC = memDC.SelectObject( &fontDC );

	logfont.lfWeight = 700;
	boldFontDC.CreateFontIndirect( &logfont );	//粗体字

	// and now let's get to the painting itself
	HTREEITEM hItem = GetFirstVisibleItem();

	int n = GetVisibleCount();

	hItem = GetFirstVisibleItem();
	n = GetVisibleCount();

	while(hItem!=NULL && n>=0)
	{
		CRect rect;
		CRect m_labelRect;

		UINT selflag = TVIS_SELECTED ; // |TVIS_DROPHILITED;
	
		CString ItemText = GetItemText(hItem);

		GetItemRect( hItem, &m_labelRect, TRUE );	//文字
		GetItemRect( hItem, &rect, FALSE );

		if ( !(GetItemState( hItem, selflag ) & selflag )) //选中状态
		{
			memDC.SetBkMode(TRANSPARENT);

			memDC.SetTextColor(::GetSysColor (COLOR_WINDOWTEXT ));

			DrawItemText(&memDC,ItemText,m_labelRect,LVCFMT_LEFT);
		}
		else
		{
			COLORREF m_highlightColor = ::GetSysColor (COLOR_HIGHLIGHT);

			CBrush brush(m_highlightColor);

			memDC.FillRect (m_labelRect, &brush);
			// draw a dotted focus rectangle
			memDC.DrawFocusRect (m_labelRect);

			memDC.SetBkColor(m_highlightColor);

			memDC.SetTextColor(::GetSysColor (COLOR_HIGHLIGHTTEXT));

			memDC.SelectObject( &boldFontDC );

			DrawItemText(&memDC,ItemText,m_labelRect,LVCFMT_LEFT);

			memDC.SelectObject( &pFontDC );
		}

		hItem = GetNextVisibleItem( hItem );
		n--;
	}

	memDC.SelectObject( pFontDC );

*/

	// Draw bitmap in the background if one has been set
	if( m_bitmap.m_hObject != NULL )
	{
		// Now create a mask
		CDC maskDC;
		maskDC.CreateCompatibleDC(&dc);
		CBitmap maskBitmap;

		// Create monochrome bitmap for the mask
		maskBitmap.CreateBitmap( rcClient.Width(), rcClient.Height(), 
					1, 1, NULL );

		CBitmap *OldMask = maskDC.SelectObject( &maskBitmap );
		memDC.SetBkColor( ::GetSysColor( COLOR_WINDOW ) );

		// Create the mask from the memory DC
		maskDC.BitBlt( 0, 0, 
			rcClient.Width(), rcClient.Height(), 
			&memDC, 
			rcClient.left, rcClient.top, 
			SRCCOPY );

		
		CDC tempDC;
		tempDC.CreateCompatibleDC(&dc);
		CBitmap *Oldtemp = tempDC.SelectObject( &m_bitmap );

		CDC imageDC;
		CBitmap bmpImage;
		imageDC.CreateCompatibleDC( &dc );

		bmpImage.CreateCompatibleBitmap( &dc, rcClient.Width(), 
						rcClient.Height() );
		CBitmap *OldImage = imageDC.SelectObject( &bmpImage );

		if( dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE && m_pal.m_hObject != NULL )
		{
			dc.SelectPalette( &m_pal, FALSE );
			dc.RealizePalette();

			imageDC.SelectPalette( &m_pal, FALSE );
		}

		// Get x and y offset
		CRect rcRoot;
		GetItemRect( GetRootItem(), rcRoot, FALSE );
		rcRoot.left = -GetScrollPos( SB_HORZ );

		imageDC.FillSolidRect(CRect(0,0,rcClient.right,rcClient.bottom),BgColor);

		if( m_bBgStretch )
		{
			imageDC.SetStretchBltMode(COLORONCOLOR);
			imageDC.StretchBlt(
				0,0,rcClient.right,rcClient.bottom,
				&tempDC,
				0,0,m_cxBitmap,m_cyBitmap,
				SRCCOPY
			);
		}
		else
		{	
			imageDC.BitBlt( 
				rcClient.right-m_cxBitmap,rcClient.bottom-m_cyBitmap,
				m_cxBitmap,m_cyBitmap,
				&tempDC,
				0, 0, 
				SRCCOPY );
			/*
			// Draw bitmap in tiled manner to imageDC
			for( int i = rcRoot.left; i < rcClient.right; i += m_cxBitmap )
			for( int j = rcRoot.top; j < rcClient.bottom; j += m_cyBitmap )
			{
				imageDC.BitBlt( i, j, m_cxBitmap, m_cyBitmap, 
					&tempDC,0, 0, SRCCOPY );
			}
			*/
		}
		
		// Set the background in memDC to black. Using SRCPAINT with black and any other
		// color results in the other color, thus making black the transparent color
		memDC.SetBkColor(RGB(0,0,0));        
		memDC.SetTextColor(RGB(255,255,255));

		memDC.BitBlt(	rcClip.left, rcClip.top, 
				rcClip.Width(), rcClip.Height(), 
				&maskDC, 
				rcClip.left, rcClip.top, 
				SRCAND);

		// Set the foreground to black. See comment above.
		imageDC.SetBkColor(RGB(255,255,255));
		imageDC.SetTextColor(RGB(0,0,0));

		imageDC.BitBlt(	rcClip.left, rcClip.top, 
				rcClip.Width(), rcClip.Height(), 
				&maskDC, 
				rcClip.left, rcClip.top, 
				SRCAND);

		// Combine the foreground with the background
		imageDC.BitBlt(	rcClip.left, rcClip.top, 
				rcClip.Width(), rcClip.Height(), 
				&memDC, 
				rcClip.left, rcClip.top,
				SRCPAINT);
		
		// Draw the final image to the screen		
		dc.BitBlt(	rcClip.left, rcClip.top, 
				rcClip.Width(), rcClip.Height(), 
				&imageDC, 
				rcClip.left, rcClip.top, SRCCOPY );

		//释放对象
		maskDC.SelectObject(OldMask);
		imageDC.SelectObject(OldImage);
		tempDC.SelectObject(Oldtemp);

		maskBitmap.DeleteObject();
		bmpImage.DeleteObject();

		maskDC.DeleteDC();
		imageDC.DeleteDC();
		tempDC.DeleteDC();
	}
	else
	{
		dc.BitBlt(	rcClip.left, rcClip.top, 
				rcClip.Width(), 
				rcClip.Height(), 
				&memDC, 
				rcClip.left, rcClip.top, SRCCOPY );
	}

	memDC.SelectObject(OldBitmap);
	bitmap.DeleteObject();
	memDC.DeleteDC();
}
Esempio n. 13
0
void CSkinVerticleScrollbar::Draw()
{

	CClientDC dc(this);
	CRect clientRect;
	GetClientRect(&clientRect);
	CMyMemDC memDC(&dc, &clientRect);
	memDC.FillSolidRect(&clientRect,  RGB(74,82,107));
	CDC bitmapDC;
	bitmapDC.CreateCompatibleDC(&dc);

	CBitmap bitmap;
	bitmap.LoadBitmap(IDB_VERTICLE_SCROLLBAR_TOP);
	CBitmap* pOldBitmap = bitmapDC.SelectObject(&bitmap);
	memDC.BitBlt(clientRect.left,clientRect.top,20,17,&bitmapDC,0,0,SRCCOPY);
	bitmapDC.SelectObject(pOldBitmap);
	bitmap.DeleteObject();
	pOldBitmap = NULL;

	bitmap.LoadBitmap(IDB_VERTICLE_SCROLLBAR_UPARROW);
	pOldBitmap = bitmapDC.SelectObject(&bitmap);
	memDC.BitBlt(clientRect.left,clientRect.top+17,20,19,&bitmapDC,0,0,SRCCOPY);
	bitmapDC.SelectObject(pOldBitmap);
	bitmap.DeleteObject();
	pOldBitmap = NULL;
	
	//draw the background (span)
	bitmap.LoadBitmap(IDB_VERTICLE_SCROLLBAR_SPAN);
	pOldBitmap = bitmapDC.SelectObject(&bitmap);
	int nHeight = clientRect.Height() - 37;

	memDC.StretchBlt(clientRect.left, clientRect.top+37, 20,nHeight,&bitmapDC, 0,0, 20, 1, SRCCOPY);

	bitmapDC.SelectObject(pOldBitmap);
	bitmap.DeleteObject();
	pOldBitmap = NULL;
	
	//draw the down arrow of the scrollbar
	bitmap.LoadBitmap(IDB_VERTICLE_SCROLLBAR_DOWNARROW);
	pOldBitmap = bitmapDC.SelectObject(&bitmap);
	memDC.BitBlt(clientRect.left,nHeight,20,16,&bitmapDC,0,0,SRCCOPY);
	bitmapDC.SelectObject(pOldBitmap);
	bitmap.DeleteObject();
	pOldBitmap = NULL;

		//draw the down arrow of the scrollbar
	bitmap.LoadBitmap(IDB_VERTICLE_SCROLLBAR_BOTTOM);
	pOldBitmap = bitmapDC.SelectObject(&bitmap);
	memDC.BitBlt(clientRect.left+1,nHeight+26,20,22,&bitmapDC,0,0,SRCCOPY);
	bitmapDC.SelectObject(pOldBitmap);
	bitmap.DeleteObject();
	pOldBitmap = NULL;

	//If there is nothing to scroll then don't
	//show the thumb control otherwise show it
	if(pList->GetScrollLimit(SB_VERT) != 0)
	{
		//draw the thumb control
		bitmap.LoadBitmap(IDB_VERTICLE_SCROLLBAR_THUMB);
		pOldBitmap = bitmapDC.SelectObject(&bitmap);
		memDC.BitBlt(clientRect.left,clientRect.top+nThumbTop,20,26,&bitmapDC,0,0,SRCCOPY);
		bitmapDC.SelectObject(pOldBitmap);
		bitmap.DeleteObject();
		pOldBitmap = NULL;
	}
}
Esempio n. 14
0
void CViewSockTrackerImage::OnDraw(CDC* pDC)
{
	CDocument* pDoc = GetDocument();
	// 這邊畫 圖片
	/////////////////////////////////////////////////////////////////////
	CRect RectImage;
	GetClientRect( &RectImage );
	if(m_pBitmap != NULL && csInfomation == "" )  
	{  
		CBitmap   bmp;  
		if(bmp.Attach(m_pBitmap))  
		{  
			CString csW = _T("");
			
			BITMAP   bmpInfo;  
			bmp.GetBitmap(&bmpInfo);  
			
			CDC   dcMemory;  
			dcMemory.CreateCompatibleDC(pDC);  
			dcMemory.SelectObject(&bmp);  
			pDC->SetStretchBltMode(HALFTONE);  
			pDC->StretchBlt(RectImage.left,RectImage.top,RectImage.Width(),RectImage.Height(),&dcMemory,0,0,
				bmpInfo.bmWidth,bmpInfo.bmHeight,SRCCOPY);  
			bmp.Detach();

			//
			m_w = bmpInfo.bmWidth;
			m_h = bmpInfo.bmHeight;
		}  
	}  
	//

	// 這邊畫 Pattern ROI 
	/////////////////////////////////////////////////////////////////////
	if(m_pBitmap != NULL && csInfomation == "" )  
	{
		CRect rect;	
		COLORREF color = RGB(255, 255, 0);
		m_AlignRectTracker.SetRectColor( color );
		m_AlignRectTracker.GetTrueRect(&rect); 
		if( m_bLoadRect )
		{
			m_bLoadRect = false;
			m_AlignRectTracker.m_rect = m_LoadRect;
			m_AlignRectTracker.Draw( pDC, m_LoadRect );
		}
		else
			m_AlignRectTracker.Draw( pDC );
	}
	/////////////////////////////////////////////////////////////////////

	if( csInfomation != "" )
	{
		CRect RectText;
		GetClientRect( &RectText );
		int x = 0;
		int y = 0;		

		x = 20;
		y = RectText.Height() / 2;

		pDC->TextOut( x, y, csInfomation );
		pDC->TextOut( x, y + 15 , "Image is lost" );
		csInfomation = "";
	}

	// 
	m_pBitmap = NULL;
}
Esempio n. 15
0
LRESULT CEXMLDocumentStyleSheetsView::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	CBitmap bmIcons;
	bmIcons.LoadBitmap(MAKEINTRESOURCE(IDB_CSSSTYLESHEETS));

	m_icons.Create(16, 16, ILC_COLOR8 | ILC_MASK, 1, 5);
	m_icons.Add(bmIcons, RGB(255, 255, 255));

	IUnknown* p;

	CRect rc(0,0,0,0);
	m_axtreeCtl.Create(m_hWnd, rc, NULL, WS_CHILD | WS_VISIBLE);
	m_axtreeCtl.AttachControl(m_treeCtl, &p);
	IDispEventImpl<4, CEXMLDocumentStyleSheetsView, &DIID__IUITreeControlEvents, &LIBID_UILib, 1, 0>::DispEventAdvise(m_treeCtl);

	m_treeCtl->put_hImageList((long)(HIMAGELIST)m_icons);

	CComPtr<IEXMLDocument> document;
	m_viewGroup->get_eXMLDocument(&document);

	CComPtr<ILDOMDocument> domdocument;
	document->get_DOMDocument(&domdocument);

	PopulateStyleSheetElements(NULL, domdocument);

#if 0
	if (m_styleSheetList)
	{
		ASSERT(m_viewGroup);

		CComPtr<IEXMLDocument> eDocument;
		m_viewGroup->get_eXMLDocument(&eDocument);

		CComPtr<ILDOMDocument> domDocument;
		eDocument->get_DOMDocument(&domDocument);

	//	CComPtr<ILDOMElement> documentElement;
	//	domDocument->get_documentElement(&documentElement);

		PopulateStyleSheetElements(NULL, domDocument);
		/*
		PopulateStyleSheets(NULL, m_styleSheetList);
		*/

		{

			CComQIPtr<ILDOMEventTarget> eventTarget = domDocument;
			eventTarget->addEventListener(L"DOMNodeInserted", (ILDOMEventListener*)this, VARIANT_TRUE);
			eventTarget->addEventListener(L"DOMNodeRemovedFromDocument", (ILDOMEventListener*)this, VARIANT_TRUE);
		}

		IDispEventImpl<1, CEXMLDocumentStyleSheetsView, &DIID__IEXMLViewGroupEvents, &LIBID_LXMLEDITORLib, 1, 0>::DispEventAdvise(m_viewGroup->GetUnknown());
	}
	else if (m_styleSheet)
	{
		CComPtr<ILCSSRuleList> ruleList;
		m_styleSheet->get_cssRules(&ruleList);

		PopulateRules(NULL, ruleList);
	}

#endif

//	CComQIPtr<IUIActiveManager> uiActiveManager = m_app;
//	uiActiveManager->AddEventHandler(this);

	return 0;
}
Esempio n. 16
0
void CDConsoleDlg::AddImage(CImageList& imageList, UINT id)
{
	CBitmap bm;
	bm.LoadBitmap(id);
	imageList.Add(&bm, RGB(0, 0, 0));
}
Esempio n. 17
0
BOOL CFileUploaderDialog::OnInitDialog (void)
{
    CDialog::OnInitDialog ();

    // Initialize FlickrClient
    o_FlickrClient.SetPhotoSetInfo (&map_PhotoSetInfoByName);

    // Add Items to the System Menu
    CMenu* pSysMenu = GetSystemMenu (FALSE);
    if (pSysMenu != NULL)
    {
        pSysMenu->AppendMenu (MF_SEPARATOR);
        pSysMenu->AppendMenu (MF_STRING, IDM_SETTINGS, _T("&Settings ..."));
    }

    // Set System Icons
    SetIcon (hico_FlickrPal16, FALSE);
    SetIcon (hico_FlickrPal32, TRUE);

    // Create Wait Animation
    CRect oWaitAnimationRect;
    GetDlgItem (IDC_WAIT_ANIMATION_RECT)->GetWindowRect (oWaitAnimationRect);
    ScreenToClient (oWaitAnimationRect);

    m_WaitAnimation.Create (NULL,
                            _T("WaitAnimation"),
                            WS_CHILD,
                            oWaitAnimationRect,
                            this,
                            IDC_WAIT_ANIMATION_RECT);

    // Create Username Ctrl
    CRect oUsernameTextRect;
    GetDlgItem (IDC_USERNAME_RECT)->GetWindowRect (oUsernameTextRect);
    ScreenToClient (oUsernameTextRect);

    m_UsenameText.Create (NULL,
                          _T("UsernameText"),
                          WS_CHILD,
                          oUsernameTextRect,
                          this,
                          IDC_USERNAME_RECT);

    m_UsenameText.Init (RGB (0, 200, 0));

    // Create User Photos URL
    CRect oUserPhotosURLRect;
    GetDlgItem (IDC_USER_PHOTOS_URL_RECT)->GetWindowRect (oUserPhotosURLRect);
    ScreenToClient (oUserPhotosURLRect);

    m_UserPhotosURLCtrl.Create (NULL,
                                _T("UserPhotosURL"),
                                WS_CHILD,
                                oUserPhotosURLRect,
                                this,
                                IDC_USER_PHOTOS_URL_RECT);

    // Create User Profile URL
    CRect oUserProfileURLRect;
    GetDlgItem (IDC_USER_PROFILE_URL_RECT)->GetWindowRect (oUserProfileURLRect);
    ScreenToClient (oUserProfileURLRect);

    m_UserProfileURLCtrl.Create (NULL,
                                 _T("UserProfileURL"),
                                 WS_CHILD,
                                 oUserProfileURLRect,
                                 this,
                                 IDC_USER_PROFILE_URL_RECT);

    // Create Available Quota Ctrl
    CRect oAvailableQuotaRect;
    GetDlgItem (IDC_AVAILABLE_QUOTA_RECT)->GetWindowRect (oAvailableQuotaRect);
    ScreenToClient (oAvailableQuotaRect);

    m_AvailableQuotaText.Create (NULL,
                                 _T("AvailableQuotaText"),
                                 WS_CHILD,
                                 oAvailableQuotaRect,
                                 this,
                                 IDC_AVAILABLE_QUOTA_RECT);

    m_AvailableQuotaText.Init (RGB (0, 100, 50), true);

    // Create Image Thumbnail List View
    CRect rect;
    CWnd* pListCtrlRef = GetDlgItem (IDC_IMAGE_THUMBNAIL_LC_REF);
    pListCtrlRef->GetWindowRect (rect);
    ScreenToClient (rect);

    m_ImageListCtrl.Create (WS_CHILD | WS_VSCROLL | LVS_ICON | WS_VISIBLE | LVS_SINGLESEL, rect, this, IDC_IMAGE_THUMBNAIL_LC_REF);

    // Show Thumbnails
    m_ImageListCtrl.ShowImageThumbnails (lst_FileName);

    // Store Image Data
    int iItemIndex = 0;
    while (lst_FileName.empty () == false)
    {
        CString sFileName = lst_FileName.front ();

        CImageDetails* pImageDetails = new CImageDetails;

        // Set File Name
        pImageDetails->s_FileName = sFileName;
        // Set File Name as the Title
        CString sTitle = sFileName.Right (sFileName.GetLength() - sFileName.ReverseFind ('\\') - 1); // With the extension
        pImageDetails->s_Title = sTitle.Left (sTitle.Find ('.')); // Without the extension
        // Set File Size
        pImageDetails->s_FileSize = GetFileSize (sFileName);

        map_ImageDetailsByItemIndex.insert (make_pair (iItemIndex++, pImageDetails));

        lst_FileName.pop_front ();
    }

    // Initialize Only Me Radio Button
    m_OnlyMeRadioButton.SetEnable (true);
    m_OnlyMeRadioButton.SetFamilyCheckBox (&m_FamilyCheckBox);
    m_OnlyMeRadioButton.SetFriendsCheckBox (&m_FriendsCheckBox);

    // Initialize Anyone Radio Button
    m_AnyoneRadioButton.SetEnable (false);
    m_AnyoneRadioButton.SetFamilyCheckBox (&m_FamilyCheckBox);
    m_AnyoneRadioButton.SetFriendsCheckBox (&m_FriendsCheckBox);

    // Initialize Sets Lists
    m_SetsImageList.Create (16, 16, ILC_COLOR32 | ILC_MASK, 0, 4);
    CBitmap bmListItem; // Existing Item
    bmListItem.LoadBitmap (IDB_BITMAP_SET_LIST_ITEM);
    m_SetsImageList.Add (&bmListItem, RGB(0, 0, 0));

    CBitmap bmListItemNew; // New Item
    bmListItemNew.LoadBitmap (IDB_BITMAP_SET_LIST_ITEM_NEW);
    m_SetsImageList.Add (&bmListItemNew, RGB(0, 0, 0));

    m_AvailableSetsListCtrl.SetImageList (&m_SetsImageList, LVSIL_SMALL);
    m_AvailableSetsListCtrl.InsertColumn (0, _T(""), 0, 150);
    m_AvailableSetsListCtrl.SetButton ((CButton*)GetDlgItem (IDC_BUTTON_ADD_SET));
    m_AvailableSetsListCtrl.SetPhotoSetInfo (&map_PhotoSetInfoByName);

    m_SelectedSetsListCtrl.SetImageList (&m_SetsImageList, LVSIL_SMALL);
    m_SelectedSetsListCtrl.InsertColumn (0, _T(""), 0, 150);
    m_SelectedSetsListCtrl.SetButton ((CButton*)GetDlgItem (IDC_BUTTON_REMOVE_SET));

    // Initialize Animate Control
    TCHAR zWindowsDirectory [MAX_PATH];
    GetWindowsDirectory (zWindowsDirectory, MAX_PATH);

    CString sAnimationFileName = zWindowsDirectory;
    if (sAnimationFileName[sAnimationFileName.GetLength () - 1] != '\\')
        sAnimationFileName+= '\\';
    sAnimationFileName+= "upload.avi";

    m_AnimateCtrl.Open (sAnimationFileName);

    // Show Offline Message
    ShowOfflineMessage ();

    // Set Default Values
    m_OnlyMeRadioButton.SetCheck (TRUE);
    m_SafetyLevelCombo.SetCurSel (0);
    m_HiddenCombo.SetCurSel (0);
    m_ContentTypeCombo.SetCurSel (0);

    // Disable Image Controls by Default
    EnableImageControls (FALSE);

    // Show Initial Help Message
    ShowHelpText ();

    // Create User Profile Restore Timer
    SetTimer (TID_USER_PROFILE_RESTORE, 10, NULL);

    return TRUE;
}
Esempio n. 18
0
CMiniMap::CMiniMap()
: CInputReceiver(BACK),
  fullProxy(false),
  proxyMode(false),
  selecting(false),
  maxspect(false),
  maximized(false),
  minimized(false),
  mouseLook(false),
  mouseMove(false),
  mouseResize(false),
  slaveDrawMode(false),
  showButtons(false),
  useIcons(true)
 {
	lastWindowSizeX = globalRendering->viewSizeX;
	lastWindowSizeY = globalRendering->viewSizeY;

	if (globalRendering->dualScreenMode) {
		width = globalRendering->viewSizeX;
		height = globalRendering->viewSizeY;
		xpos = (globalRendering->viewSizeX - globalRendering->viewPosX);
		ypos = 0;
	}
	else {
		const std::string geo = configHandler->GetString("MiniMapGeometry");
		ParseGeometry(geo);
	}

	fullProxy = configHandler->GetBool("MiniMapFullProxy");
	buttonSize = configHandler->GetInt("MiniMapButtonSize");

	unitBaseSize = configHandler->GetFloat("MiniMapUnitSize");
	unitExponent = configHandler->GetFloat("MiniMapUnitExp");

	cursorScale = configHandler->GetFloat("MiniMapCursorScale");
	useIcons = configHandler->GetBool("MiniMapIcons");
	drawCommands = configHandler->GetInt("MiniMapDrawCommands");
	drawProjectiles = configHandler->GetBool("MiniMapDrawProjectiles");
	simpleColors = configHandler->GetBool("SimpleMiniMapColors");

	myColor[0]    = (unsigned char)(0.2f * 255);
	myColor[1]    = (unsigned char)(0.9f * 255);
	myColor[2]    = (unsigned char)(0.2f * 255);
	myColor[3]    = (unsigned char)(1.0f * 255);
	allyColor[0]  = (unsigned char)(0.3f * 255);
	allyColor[1]  = (unsigned char)(0.3f * 255);
	allyColor[2]  = (unsigned char)(0.9f * 255);
	allyColor[3]  = (unsigned char)(1.0f * 255);
	enemyColor[0] = (unsigned char)(0.9f * 255);
	enemyColor[1] = (unsigned char)(0.2f * 255);
	enemyColor[2] = (unsigned char)(0.2f * 255);
	enemyColor[3] = (unsigned char)(1.0f * 255);

	UpdateGeometry();

	circleLists = glGenLists(circleListsCount);
	for (int cl = 0; cl < circleListsCount; cl++) {
		glNewList(circleLists + cl, GL_COMPILE);
		glBegin(GL_LINE_LOOP);
		const int divs = (1 << (cl + 3));
		for (int d = 0; d < divs; d++) {
			const float rads = float(2.0 * PI) * float(d) / float(divs);
			glVertex3f(math::sin(rads), 0.0f, math::cos(rads));
		}
		glEnd();
		glEndList();
	}

	// setup the buttons' texture and texture coordinates
	buttonsTexture = 0;
	CBitmap bitmap;
	bool unfiltered = false;
	if (bitmap.Load("bitmaps/minimapbuttons.png")) {
		if ((bitmap.ysize == buttonSize) && (bitmap.xsize == (buttonSize * 4))) {
			unfiltered = true;
		}
		glGenTextures(1, &buttonsTexture);
		glBindTexture(GL_TEXTURE_2D, buttonsTexture);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,
								 bitmap.xsize, bitmap.ysize, 0,
								 GL_RGBA, GL_UNSIGNED_BYTE, bitmap.mem);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
		if (unfiltered) {
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		} else {
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		}
		glBindTexture(GL_TEXTURE_2D, 0);
	}
	const float xshift = unfiltered ? 0.0f : (0.5f / bitmap.xsize);
	const float yshift = unfiltered ? 0.0f : (0.5f / bitmap.ysize);
	    moveBox.xminTx = 0.50f + xshift;
	    moveBox.xmaxTx = 0.75f - xshift;
	  resizeBox.xminTx = 0.75f + xshift;
	  resizeBox.xmaxTx = 1.00f - xshift;
	minimizeBox.xminTx = 0.00f + xshift;
	minimizeBox.xmaxTx = 0.25f - xshift;
	maximizeBox.xminTx = 0.25f + xshift;
	maximizeBox.xmaxTx = 0.50f - xshift;
	    moveBox.yminTx = 1.00f - yshift;
	  resizeBox.yminTx = 1.00f - yshift;
	minimizeBox.yminTx = 1.00f - yshift;
	maximizeBox.yminTx = 1.00f - yshift;
	    moveBox.ymaxTx = 0.00f + yshift;
	  resizeBox.ymaxTx = 0.00f + yshift;
	minimizeBox.ymaxTx = 0.00f + yshift;
	maximizeBox.ymaxTx = 0.00f + yshift;
}
Esempio n. 19
0
void CMenuItem::DrawHotKeyString (int bIsCurrent, int bTiny, int bCreateTextBms, int nDepth)
{
	CBitmap	*bmP = m_bmText [bIsCurrent];

if (!*m_text)
	return;
if (m_color)
	fontManager.SetColorRGBi (m_color, 1, 0, 0);
else
	SetColor (bIsCurrent, bTiny);
if (bCreateTextBms && FAST_MENUS && 
	 (bmP || (bmP = CreateStringBitmap (m_text, MENU_KEY (m_nKey, - 1), gameData.menu.keyColor, nTabs, m_bCentered, m_w, 0)))) {
	bmP->Render (CCanvas::Current (), m_x, m_y, bmP->Width (), bmP->Height (), 0, 0, bmP->Width (), bmP->Height (), 1, 0);
	m_bmText [bIsCurrent] = bmP;
	}
else {

		int	w, h, aw, l, i, 
				x = m_x, 
				y = m_y;
		char	*t, *ps = m_text, s [MENU_MAX_TEXTLEN], ch = 0, ch2;

	if ((t = strchr (ps, '\n'))) {
		strncpy (s, ps, sizeof (s));
		SetText (s);
		fontManager.Current ()->StringSize (s, w, h, aw);
		do {
			if ((t = strchr (m_text, '\n')))
				*t = '\0';
			DrawHotKeyString (0, bTiny, 0, nDepth + 1);
			if (!t)
				break;
			SetText (t + 1);
			m_y += h / 2;
			m_x = m_xSave;
			nTabIndex = -1;
			} while (*(m_text));
		}
	else if ((t = strchr (ps, '\t'))) {
		strncpy (s, ps, sizeof (s));
		SetText (s);
		fontManager.Current ()->StringSize (s, w, h, aw);
		do {
			if ((t = strchr (m_text, '\t')))
				*t = '\0';
			DrawHotKeyString (0, bTiny, 0, nDepth + 1);
			if (!t)
				break;
			SetText (t + 1);
			nTabIndex++;
		} while (*(m_text));
		nTabIndex = -1;
		SetText (ps);
		m_y = y;
		}
	else {
		l = (int) strlen (m_text);
		if (bIsCurrent || !m_nKey)
			i = l;
		else {
			ch = MENU_KEY (m_nKey, *ps);
			for (i = 0; ps [i]; i++)
				if (ps [i] == ch)
					break;
			}
		strncpy (s, ps, sizeof (s));
		s [i] = '\0';
		fontManager.Current ()->StringSize (s, w, h, aw);
		if (nTabIndex >= 0) {
			x += LHX (nTabs [nTabIndex]);
			if (!gameStates.multi.bSurfingNet)
				x += m_w - w;
			}
		//m_x = x + w;
		if (i) {
			GrString (x, y, s, NULL);
	#if DBG
			//GrUpdate (0);
	#endif
			}
		if (i < l) {	// print the hotkey
			x += w;
			s [i] = ch;
			ch2 = s [++i];
			s [i] = '\0';
			SetColor (1, bTiny);
			GrString (x, y, s + i - 1, NULL);
	#if DBG
			//GrUpdate (0);
	#endif
			SetColor (0, bTiny);
			if (i < l) { // print text following the hotkey
				fontManager.Current ()->StringSize (s + i - 1, w, h, aw);
				x += w;
				s [i] = ch2;
				GrString (x, y, s + i, NULL);
				}
			}
		}
	}
}
void CUnitDefHandler::ParseTAUnit(std::string file, int id)
{
	CSunParser sunparser;
	sunparser.LoadFile(file);

	UnitDef& ud=unitDefs[id];

	ud.name = sunparser.SGetValueMSG("UNITINFO\\UnitName");
	ud.humanName = sunparser.SGetValueMSG("UNITINFO\\name");

	sunparser.GetDef(ud.extractsMetal, "0", "UNITINFO\\ExtractsMetal");
	sunparser.GetDef(ud.windGenerator, "0", "UNITINFO\\WindGenerator");
	sunparser.GetDef(ud.tidalGenerator, "0", "UNITINFO\\TidalGenerator");

	ud.health=atof(sunparser.SGetValueDef("0", "UNITINFO\\MaxDamage").c_str());
	ud.metalUpkeep=atof(sunparser.SGetValueDef("0", "UNITINFO\\MetalUse").c_str());
	ud.energyUpkeep=atof(sunparser.SGetValueDef("0", "UNITINFO\\EnergyUse").c_str());
	ud.metalMake=atof(sunparser.SGetValueDef("0", "UNITINFO\\MetalMake").c_str());
	ud.makesMetal=atof(sunparser.SGetValueDef("0", "UNITINFO\\MakesMetal").c_str());
	ud.energyMake=atof(sunparser.SGetValueDef("0", "UNITINFO\\EnergyMake").c_str());
	ud.metalStorage=atof(sunparser.SGetValueDef("0", "UNITINFO\\MetalStorage").c_str());
	ud.energyStorage=atof(sunparser.SGetValueDef("0", "UNITINFO\\EnergyStorage").c_str());

	ud.isMetalMaker=(ud.makesMetal>=1 && ud.energyUpkeep>ud.makesMetal*40);

	ud.controlRadius=32;
	ud.losHeight=20;
	ud.metalCost=atof(sunparser.SGetValueDef("0", "UNITINFO\\BuildCostMetal").c_str());
	if(ud.metalCost<1)		//avoid some nasty divide by 0 etc
		ud.metalCost=1;
	ud.mass=atof(sunparser.SGetValueDef("0", "UNITINFO\\Mass").c_str());
	if(ud.mass<=0)
		ud.mass=ud.metalCost;
	ud.energyCost=atof(sunparser.SGetValueDef("0", "UNITINFO\\BuildCostEnergy").c_str());
	ud.buildTime=atof(sunparser.SGetValueDef("0", "UNITINFO\\BuildTime").c_str());
	if(ud.buildTime<1)		//avoid some nasty divide by 0 etc
		ud.buildTime=1;
	ud.aihint=id;		//fix
	ud.losRadius=atof(sunparser.SGetValueDef("0", "UNITINFO\\SightDistance").c_str());
	ud.airLosRadius=atof(sunparser.SGetValueDef("0", "UNITINFO\\SightDistance").c_str())*1.5;
	ud.tooltip=sunparser.SGetValueDef(ud.name,"UNITINFO\\Description");
	ud.moveType=0;
	
	sunparser.GetDef(ud.canfly, "0", "UNITINFO\\canfly");
	sunparser.GetDef(ud.canmove, "0", "UNITINFO\\canmove");
	sunparser.GetDef(ud.builder, "0", "UNITINFO\\Builder");
	sunparser.GetDef(ud.upright, "0", "UNITINFO\\Upright");
	sunparser.GetDef(ud.onoffable, "0", "UNITINFO\\onoffable");

	sunparser.GetDef(ud.maxSlope, "0", "UNITINFO\\MaxSlope");
	ud.maxHeightDif=40*tan(ud.maxSlope*(PI/180));
	ud.maxSlope = cos(ud.maxSlope*(PI/180));
	sunparser.GetDef(ud.minWaterDepth, "-10e6", "UNITINFO\\MinWaterDepth");
	sunparser.GetDef(ud.maxWaterDepth, "10e6", "UNITINFO\\MaxWaterDepth");
	std::string value;
	ud.floater = sunparser.SGetValue(value, "UNITINFO\\Waterline");
	sunparser.GetDef(ud.waterline, "0", "UNITINFO\\Waterline");
	if(ud.waterline>8 && ud.canmove)
		ud.waterline+=5;		//make subs travel at somewhat larger depths to reduce vulnerability to surface weapons

	sunparser.GetDef(ud.selfDCountdown, "5", "UNITINFO\\selfdestructcountdown");

	ud.speed=atof(sunparser.SGetValueDef("0", "UNITINFO\\MaxVelocity").c_str())*30;
	ud.maxAcc=atof(sunparser.SGetValueDef("0.5", "UNITINFO\\acceleration").c_str());
	ud.maxDec=atof(sunparser.SGetValueDef("0.5", "UNITINFO\\BrakeRate").c_str())*0.1;
	ud.turnRate=atof(sunparser.SGetValueDef("0", "UNITINFO\\TurnRate").c_str());
	ud.buildSpeed=atof(sunparser.SGetValueDef("0", "UNITINFO\\WorkerTime").c_str());
	ud.buildDistance=atof(sunparser.SGetValueDef("64", "UNITINFO\\Builddistance").c_str());
	ud.buildDistance=max(128,ud.buildDistance);
	ud.armoredMultiple=atof(sunparser.SGetValueDef("1", "UNITINFO\\DamageModifier").c_str());
	ud.armorType=damageArrayHandler->GetTypeFromName(ud.name);
//	info->AddLine("unit %s has armor %i",ud.name.c_str(),ud.armorType);

	ud.radarRadius=atoi(sunparser.SGetValueDef("0", "UNITINFO\\RadarDistance").c_str());
	ud.sonarRadius=atoi(sunparser.SGetValueDef("0", "UNITINFO\\SonarDistance").c_str());
	ud.jammerRadius=atoi(sunparser.SGetValueDef("0", "UNITINFO\\RadarDistanceJam").c_str());
	ud.sonarJamRadius=atoi(sunparser.SGetValueDef("0", "UNITINFO\\SonarDistanceJam").c_str());
	ud.stealth=!!atoi(sunparser.SGetValueDef("0", "UNITINFO\\Stealth").c_str());
	ud.targfac=!!atoi(sunparser.SGetValueDef("0", "UNITINFO\\istargetingupgrade").c_str());
	ud.isFeature=!!atoi(sunparser.SGetValueDef("0", "UNITINFO\\IsFeature").c_str());
	ud.canResurrect=!!atoi(sunparser.SGetValueDef("0", "UNITINFO\\canResurrect").c_str());
	ud.canCapture=!!atoi(sunparser.SGetValueDef("0", "UNITINFO\\canCapture").c_str());
	ud.hideDamage=!!atoi(sunparser.SGetValueDef("0", "UNITINFO\\HideDamage").c_str());
	ud.isCommander=!!atoi(sunparser.SGetValueDef("0", "UNITINFO\\commander").c_str());

	ud.cloakCost=atof(sunparser.SGetValueDef("-1", "UNITINFO\\CloakCost").c_str());
	ud.cloakCostMoving=atof(sunparser.SGetValueDef("-1", "UNITINFO\\CloakCostMoving").c_str());
	if(ud.cloakCostMoving<0)
		ud.cloakCostMoving=ud.cloakCost;
	if(ud.cloakCost>=0)
		ud.canCloak=true;
	else
		ud.canCloak=false;
	ud.startCloaked=!!atoi(sunparser.SGetValueDef("0", "UNITINFO\\init_cloaked").c_str());
	ud.decloakDistance=atof(sunparser.SGetValueDef("-1", "UNITINFO\\mincloakdistance").c_str());
	
	ud.highTrajectoryType=atoi(sunparser.SGetValueDef("0", "UNITINFO\\HighTrajectory").c_str());

	ud.canKamikaze=!!atoi(sunparser.SGetValueDef("0", "UNITINFO\\kamikaze").c_str());
	ud.kamikazeDist=atof(sunparser.SGetValueDef("-25", "UNITINFO\\kamikazedistance").c_str())+25; //we count 3d distance while ta count 2d distance so increase slightly

	sunparser.GetDef(ud.canfly, "0", "UNITINFO\\canfly");
	sunparser.GetDef(ud.canmove, "0", "UNITINFO\\canmove");
	sunparser.GetDef(ud.canhover, "0", "UNITINFO\\canhover");
	if(sunparser.SGetValue(value, "UNITINFO\\floater"))
		sunparser.GetDef(ud.floater, "0", "UNITINFO\\floater");
	sunparser.GetDef(ud.builder, "0", "UNITINFO\\Builder");

	if(ud.builder && !ud.buildSpeed)		//core anti is flagged as builder for some reason
		ud.builder=false;

	ud.wantedHeight=atof(sunparser.SGetValueDef("0", "UNITINFO\\cruisealt").c_str())*1.5;
	ud.hoverAttack = !!atoi(sunparser.SGetValueDef("0", "UNITINFO\\hoverattack").c_str());

	sunparser.GetDef(ud.transportSize, "0", "UNITINFO\\transportsize");
	sunparser.GetDef(ud.transportCapacity, "0", "UNITINFO\\transportcapacity");
	ud.isAirBase=!!atoi(sunparser.SGetValueDef("0", "UNITINFO\\isAirBase").c_str());
	ud.stunnedCargo=!ud.isAirBase;
	ud.loadingRadius=220;
	sunparser.GetDef(ud.transportMass, "100000", "UNITINFO\\TransportMass");

	sunparser.GetDef(ud.wingDrag, "0.07", "UNITINFO\\WingDrag");				//drag caused by wings
	sunparser.GetDef(ud.wingAngle, "0.08", "UNITINFO\\WingAngle");			//angle between front and the wing plane
	sunparser.GetDef(ud.drag, "0.005", "UNITINFO\\Drag");								//how fast the aircraft loses speed (see also below)
	sunparser.GetDef(ud.frontToSpeed, "0.1", "UNITINFO\\frontToSpeed");	//fudge factor for lining up speed and front of plane
	sunparser.GetDef(ud.speedToFront, "0.07", "UNITINFO\\speedToFront");//fudge factor for lining up speed and front of plane
	sunparser.GetDef(ud.myGravity, "0.4", "UNITINFO\\myGravity");				//planes are slower than real airplanes so lower gravity to compensate

	sunparser.GetDef(ud.maxBank, "0.8", "UNITINFO\\maxBank");						//max roll
	sunparser.GetDef(ud.maxPitch, "0.45", "UNITINFO\\maxPitch");				//max pitch this plane tries to keep
	sunparser.GetDef(ud.turnRadius, "500", "UNITINFO\\turnRadius");			//hint to the ai about how large turn radius this plane needs

	sunparser.GetDef(ud.maxAileron, "0.015", "UNITINFO\\maxAileron");		//turn speed around roll axis
	sunparser.GetDef(ud.maxElevator, "0.01", "UNITINFO\\maxElevator");	//turn speed around pitch axis
	sunparser.GetDef(ud.maxRudder, "0.004", "UNITINFO\\maxRudder");			//turn speed around yaw axis


	ud.categoryString=sunparser.SGetValueDef("", "UNITINFO\\Category");
	ud.category=CCategoryHandler::Instance()->GetCategories(sunparser.SGetValueDef("", "UNITINFO\\Category"));
	ud.noChaseCategory=CCategoryHandler::Instance()->GetCategories(sunparser.SGetValueDef("", "UNITINFO\\NoChaseCategory"));
//	info->AddLine("Unit %s has cat %i",ud.humanName.c_str(),ud.category);

	for(int a=0;a<16;++a){
		char c[50];
		sprintf(c,"%i",a+1);

		string name;
		sunparser.GetDef(name, "", std::string("UNITINFO\\")+"weapon"+c);
		WeaponDef *wd = weaponDefHandler->GetWeapon(name);

		if(!wd){
			if(a>2)	//allow empty weapons among the first 3
				break;
			else
				continue;
		}

		while(ud.weapons.size()<a){
			if(!weaponDefHandler->GetWeapon("NOWEAPON")) {
				info->AddLine("Error: Spring requires a NOWEAPON weapon type to be present as a placeholder for missing weapons");
				break;
			} else
				ud.weapons.push_back(UnitDef::UnitDefWeapon("NOWEAPON",weaponDefHandler->GetWeapon("NOWEAPON"),0,float3(0,0,1),-1,0,0));
		}

		string badTarget;
		sunparser.GetDef(badTarget, "", std::string("UNITINFO\\") + "badTargetCategory"+c);
		unsigned int btc=CCategoryHandler::Instance()->GetCategories(badTarget);
		if(a<3){
			switch(a){
				case 0:
					sunparser.GetDef(badTarget, "", std::string("UNITINFO\\") + "wpri_badTargetCategory");
					break;
				case 1:
					sunparser.GetDef(badTarget, "", std::string("UNITINFO\\") + "wsec_badTargetCategory");
					break;
				case 2:
					sunparser.GetDef(badTarget, "", std::string("UNITINFO\\") + "wspe_badTargetCategory");
					break;
			}
			btc|=CCategoryHandler::Instance()->GetCategories(badTarget);
		}

		string onlyTarget;
		sunparser.GetDef(onlyTarget, "", std::string("UNITINFO\\") + "onlyTargetCategory"+c);
		unsigned int otc;
		if(!onlyTarget.empty())
			otc=CCategoryHandler::Instance()->GetCategories(onlyTarget);
		else
			otc=0xffffffff;

		unsigned int slaveTo=atoi(sunparser.SGetValueDef("0", string("UNITINFO\\WeaponSlaveTo")+c).c_str());

		float3 mainDir=sunparser.GetFloat3(float3(1,0,0),string("UNITINFO\\WeaponMainDir")+c);
		mainDir.Normalize();

		float angleDif=cos(atof(sunparser.SGetValueDef("360", string("UNITINFO\\MaxAngleDif")+c).c_str())*PI/360);

		ud.weapons.push_back(UnitDef::UnitDefWeapon(name,wd,slaveTo,mainDir,angleDif,btc,otc));
	}
	sunparser.GetDef(ud.canDGun, "0", "UNITINFO\\candgun");

	string TEDClass=sunparser.SGetValueDef("0", "UNITINFO\\TEDClass").c_str();
	ud.TEDClassString=TEDClass;

	if(ud.extractsMetal) {
		ud.extractRange = readmap->extractorRadius;
		ud.type = "MetalExtractor";
	}
	else if(ud.transportCapacity)
	{
		ud.type = "Transport";	
	}
	else if(ud.builder)
	{
		if(TEDClass!="PLANT")
			ud.type = "Builder";
		else
			ud.type = "Factory";

	}
	else if(ud.canfly && !ud.hoverAttack)
	{
		if(!ud.weapons.empty() && ud.weapons[0].def!=0 && (ud.weapons[0].def->type=="AircraftBomb" || ud.weapons[0].def->type=="TorpedoLauncher")){
			ud.type = "Bomber";
			if(ud.turnRadius==500)	//only reset it if user hasnt set it explicitly
				ud.turnRadius=800;			//hint to the ai about how large turn radius this plane needs

		} else {
			ud.type = "Fighter";
		}
		sunparser.GetDef(ud.maxAcc, "0.065", "UNITINFO\\maxAcc");						//engine power
	}
	else if(ud.canmove)
	{
		ud.type = "GroundUnit";
	}
	else
	{
		ud.type = "Building";
	}

	ud.movedata=0;
	if(ud.canmove && !ud.canfly && ud.type!="Factory"){
		string moveclass=sunparser.SGetValueDef("", "UNITINFO\\MovementClass");
		ud.movedata=moveinfo->GetMoveDataFromName(moveclass);
		if(ud.movedata->moveType==MoveData::Hover_Move || ud.movedata->moveType==MoveData::Ship_Move){
			ud.upright=true;
		}
		if(ud.canhover){
			if(ud.movedata->moveType!=MoveData::Hover_Move){
				info->AddLine("Inconsistant move data hover %i %s %s",ud.movedata->pathType,ud.humanName.c_str(),moveclass.c_str());
			}
		} else if(ud.floater){
			if(ud.movedata->moveType!=MoveData::Ship_Move){
				info->AddLine("Inconsistant move data ship %i %s %s",ud.movedata->pathType,ud.humanName.c_str(),moveclass.c_str());
			}
		} else {
			if(ud.movedata->moveType!=MoveData::Ground_Move){
				info->AddLine("Inconsistant move data ground %i %s %s",ud.movedata->pathType,ud.humanName.c_str(),moveclass.c_str());
			}
		}
//		info->AddLine("%s uses movetype %i",ud.humanName.c_str(),ud.movedata->pathType);
	}

	if(ud.maxAcc!=0 && ud.speed!=0)
		ud.drag=1.0/(ud.speed/GAME_SPEED*1.1/ud.maxAcc)-ud.wingAngle*ud.wingAngle*ud.wingDrag;		//meant to set the drag such that the maxspeed becomes what it should be

	std::string objectname;
	sunparser.GetDef(objectname, "", "UNITINFO\\Objectname");
	ud.model.modelpath = "objects3d\\" + objectname + ".3do";
	ud.model.modelname = objectname;

	sunparser.GetDef(ud.wreckName, "", "UNITINFO\\Corpse");
	sunparser.GetDef(ud.deathExplosion, "", "UNITINFO\\ExplodeAs");
	sunparser.GetDef(ud.selfDExplosion, "", "UNITINFO\\SelfDestructAs");

	string buildpic;
	sunparser.GetDef(buildpic, "", "UNITINFO\\BuildPic");
	if(buildpic.empty())
	{
		//try pcx first and then bmp if no pcx exist
		CFileHandler bfile("unitpics\\" + ud.name + ".pcx");
		if(bfile.FileExists())
		{
			CBitmap bitmap("unitpics\\" + ud.name + ".pcx");
			ud.unitimage = bitmap.CreateTexture(false);
		}
		else
		{
			CFileHandler bfile("unitpics\\" + ud.name + ".bmp");
			if(bfile.FileExists()){
				CBitmap bitmap("unitpics\\" + ud.name + ".bmp");
				ud.unitimage = bitmap.CreateTexture(false);
			} else {
				CBitmap bitmap;
				ud.unitimage = bitmap.CreateTexture(false);
			}
		}

	}
	else
	{
		CBitmap bitmap("unitpics\\" + buildpic);
		ud.unitimage = bitmap.CreateTexture(false);
	}


	ud.power = (ud.metalCost + ud.energyCost/60.0f);

	sunparser.GetDef(ud.activateWhenBuilt, "0", "UNITINFO\\ActivateWhenBuilt");
	
	ud.xsize=atoi(sunparser.SGetValueDef("1", "UNITINFO\\FootprintX").c_str())*2;//ta has only half our res so multiply size with 2
	ud.ysize=atoi(sunparser.SGetValueDef("1", "UNITINFO\\FootprintZ").c_str())*2;

	ud.needGeo=false;
	if(ud.type=="Building" || ud.type=="Factory"){
		CreateYardMap(&ud, sunparser.SGetValueDef("c", "UNITINFO\\YardMap"));
	} else {
		ud.yardmap = 0;
	}

	ud.leaveTracks=!!atoi(sunparser.SGetValueDef("0", "UNITINFO\\LeaveTracks").c_str());
	ud.trackWidth=atof(sunparser.SGetValueDef("32", "UNITINFO\\TrackWidth").c_str());
	ud.trackOffset=atof(sunparser.SGetValueDef("0", "UNITINFO\\TrackOffset").c_str());
	ud.trackStrength=atof(sunparser.SGetValueDef("0", "UNITINFO\\TrackStrength").c_str());
	ud.trackStretch=atof(sunparser.SGetValueDef("1", "UNITINFO\\TrackStretch").c_str());
	if(ud.leaveTracks && groundDecals)
		ud.trackType=groundDecals->GetTrackType(sunparser.SGetValueDef("StdTank", "UNITINFO\\TrackType"));

	ud.canDropFlare=!!atoi(sunparser.SGetValueDef("0", "UNITINFO\\CanDropFlare").c_str());
	ud.flareReloadTime=atof(sunparser.SGetValueDef("5", "UNITINFO\\FlareReload").c_str());
	ud.flareEfficieny=atof(sunparser.SGetValueDef("0.5", "UNITINFO\\FlareEfficiency").c_str());
	ud.flareDelay=atof(sunparser.SGetValueDef("0.3", "UNITINFO\\FlareDelay").c_str());
	ud.flareDropVector=sunparser.GetFloat3(ZeroVector,"UNITINFO\\FlareDropVector");
	ud.flareTime=atof(sunparser.SGetValueDef("3", "UNITINFO\\FlareTime").c_str())*30;
	ud.flareSalvoSize=atoi(sunparser.SGetValueDef("4", "UNITINFO\\FlareSalvoSize").c_str());
	ud.flareSalvoDelay=atof(sunparser.SGetValueDef("0.1", "UNITINFO\\FlareSalvoDelay").c_str())*30;

	ud.smoothAnim = !!atoi(sunparser.SGetValueDef("0", "UNITINFO\\SmoothAnim").c_str());

	LoadSound(sunparser, ud.sounds.ok, "ok1");
	LoadSound(sunparser, ud.sounds.select, "select1");
	LoadSound(sunparser, ud.sounds.arrived, "arrived1");
	LoadSound(sunparser, ud.sounds.build, "build");
	LoadSound(sunparser, ud.sounds.activate, "activate");
	LoadSound(sunparser, ud.sounds.deactivate, "deactivate");
	LoadSound(sunparser, ud.sounds.cant, "cant");
	LoadSound(sunparser, ud.sounds.underattack, "underattack");
}
Esempio n. 21
0
///////////////////////////////////////////////////////////////////////////////
// Name:		SetLed
// Description:	This method will draw the LED to the specified DC.
//
// Entry:
//				CDC *pDC - DC to draw to
//
//				int iLedColor - Where color is defined by:
//			 		LED_COLOR_RED
//					LED_COLOR_GREEN
//					LED_COLOR_YELLOW
//					LED_COLOR_BLUE
//
//				int iMode - where mode is defined by:
//					LED_ON
//					LED_OFF
//					LED_DISABLED
//
//				int iShape - where shape is defined by:
//					LED_ROUND
//					LED_SQUARE
///////////////////////////////////////////////////////////////////////////////
void CLed::DrawLed(CDC *pDC,int nLEDColor, int nMode, int nShape)
{
	CRect rect;
	GetClientRect(&rect);

	//
	// Center led within an oversized window
	//
	if(rect.Width() >= LED_SIZE && rect.Height() >= LED_SIZE)
	{
		int nWidth = rect.Width();
		int nHeight = rect.Height();
		rect.left += (nWidth - LED_SIZE)/2;
		rect.right -= (nWidth - LED_SIZE)/2;
		rect.top += (nHeight - LED_SIZE)/2;
		rect.bottom -= (nHeight - LED_SIZE)/2;
	}

	//
	// Prepare temporary DCs and bitmaps
	//
	CBitmap TransBitmap;
	TransBitmap.CreateBitmap(LED_SIZE,LED_SIZE,1,1,NULL);
	CBitmap bitmapTemp;
	CBitmap* pBitmap = &m_LedBitmap;
	CDC srcDC;
	CDC dcMask;
	CDC TempDC;
	TempDC.CreateCompatibleDC(pDC);
	srcDC.CreateCompatibleDC(pDC);
	dcMask.CreateCompatibleDC(pDC);

	CBitmap* pOldBitmap = srcDC.SelectObject(pBitmap);
	CBitmap* pOldMaskbitmap = dcMask.SelectObject(&TransBitmap);
	bitmapTemp.CreateCompatibleBitmap(pDC,LED_SIZE,LED_SIZE);

	//
	// Work with tempDC and bitmapTemp to reduce flickering
	//
	CBitmap *pOldBitmapTemp = TempDC.SelectObject(&bitmapTemp);
	TempDC.BitBlt(0, 0, LED_SIZE, LED_SIZE, pDC, rect.left, rect.top, SRCCOPY); 

	//
	// Create mask
	//
	COLORREF OldBkColor = srcDC.SetBkColor(RGB(255,0,255));
	dcMask.BitBlt(0, 0, LED_SIZE, LED_SIZE,&srcDC, nMode*LED_SIZE, nLEDColor+nShape, SRCCOPY); 
	TempDC.SetBkColor(OldBkColor);

	//
	// Using the IDB_LEDS bitmap, index into the bitmap for the appropriate
	// LED. By using the mask color (RGB(255,0,255)) a mask has been created
	// so the bitmap will appear transparent.
	//
	TempDC.BitBlt(0, 0, LED_SIZE, LED_SIZE, &srcDC, nMode*LED_SIZE, nLEDColor+nShape, SRCINVERT); 
	TempDC.BitBlt(0, 0, LED_SIZE, LED_SIZE,&dcMask, 0, 0, SRCAND); 
	TempDC.BitBlt(0, 0, LED_SIZE, LED_SIZE, &srcDC, nMode*LED_SIZE, nLEDColor+nShape, SRCINVERT); 

	//
	// Since the actual minipulation is done to tempDC so there is minimal
	// flicker, it is now time to draw the result to the screen.
	//
	pDC->BitBlt(rect.left, rect.top, LED_SIZE, LED_SIZE, &TempDC, 0, 0, SRCCOPY); 
	
	//
	// House cleaning
	//
	srcDC.SelectObject(pOldBitmap);
	dcMask.SelectObject(pOldMaskbitmap);
	TempDC.SelectObject(pOldBitmapTemp);
	VERIFY(srcDC.DeleteDC());
	VERIFY(dcMask.DeleteDC());
	VERIFY(TempDC.DeleteDC());
	VERIFY(TransBitmap.DeleteObject());
	VERIFY(bitmapTemp.DeleteObject());
}
Esempio n. 22
0
void AFX_GLOBAL_DATA::UpdateSysColors()
{
	m_bIsBlackHighContrast = ::GetSysColor(COLOR_3DLIGHT) == RGB(255, 255, 255) && ::GetSysColor(COLOR_3DFACE) == RGB(0, 0, 0);
	m_bIsWhiteHighContrast = ::GetSysColor(COLOR_3DDKSHADOW) == RGB(0, 0, 0) && ::GetSysColor(COLOR_3DFACE) == RGB(255, 255, 255);

	CWindowDC dc(NULL);
	m_nBitsPerPixel = dc.GetDeviceCaps(BITSPIXEL);

	clrBarFace = clrBtnFace = ::GetSysColor(COLOR_BTNFACE);
	clrBarShadow = clrBtnShadow = ::GetSysColor(COLOR_BTNSHADOW);
	clrBarDkShadow = clrBtnDkShadow = ::GetSysColor(COLOR_3DDKSHADOW);
	clrBarLight = clrBtnLight = ::GetSysColor(COLOR_3DLIGHT);
	clrBarHilite = clrBtnHilite = ::GetSysColor(COLOR_BTNHIGHLIGHT);
	clrBarText = clrBtnText = ::GetSysColor(COLOR_BTNTEXT);
	clrGrayedText = ::GetSysColor(COLOR_GRAYTEXT);
	clrWindowFrame = ::GetSysColor(COLOR_WINDOWFRAME);

	clrHilite = ::GetSysColor(COLOR_HIGHLIGHT);
	clrTextHilite = ::GetSysColor(COLOR_HIGHLIGHTTEXT);

	clrBarWindow = clrWindow = ::GetSysColor(COLOR_WINDOW);
	clrWindowText = ::GetSysColor(COLOR_WINDOWTEXT);

	clrCaptionText = ::GetSysColor(COLOR_CAPTIONTEXT);
	clrMenuText = ::GetSysColor(COLOR_MENUTEXT);

	clrActiveCaption = ::GetSysColor(COLOR_ACTIVECAPTION);
	clrInactiveCaption = ::GetSysColor(COLOR_INACTIVECAPTION);

	clrActiveCaptionGradient = ::GetSysColor(COLOR_GRADIENTACTIVECAPTION);
	clrInactiveCaptionGradient = ::GetSysColor(COLOR_GRADIENTINACTIVECAPTION);

	clrActiveBorder = ::GetSysColor(COLOR_ACTIVEBORDER);
	clrInactiveBorder = ::GetSysColor(COLOR_INACTIVEBORDER);

	clrInactiveCaptionText = ::GetSysColor(COLOR_INACTIVECAPTIONTEXT);

	if (m_bIsBlackHighContrast)
	{
		clrHotLinkNormalText = clrWindowText;
		clrHotLinkHoveredText = clrWindowText;
		clrHotLinkVisitedText = clrWindowText;
	}
	else
	{
		clrHotLinkNormalText = ::GetSysColor(COLOR_HOTLIGHT);
		clrHotLinkHoveredText = RGB(0, 0, 255);   // Bright blue
		clrHotLinkVisitedText = RGB(128, 0, 128); // Violet
	}

	hbrBtnShadow = ::GetSysColorBrush(COLOR_BTNSHADOW);
	ENSURE(hbrBtnShadow != NULL);

	hbrBtnHilite = ::GetSysColorBrush(COLOR_BTNHIGHLIGHT);
	ENSURE(hbrBtnHilite != NULL);

	hbrWindow = ::GetSysColorBrush(COLOR_WINDOW);
	ENSURE(hbrWindow != NULL);

	brBtnFace.DeleteObject();
	brBtnFace.CreateSolidBrush(clrBtnFace);

	brBarFace.DeleteObject();
	brBarFace.CreateSolidBrush(clrBarFace);

	brActiveCaption.DeleteObject();
	brActiveCaption.CreateSolidBrush(clrActiveCaption);

	brInactiveCaption.DeleteObject();
	brInactiveCaption.CreateSolidBrush(clrInactiveCaption);

	brHilite.DeleteObject();
	brHilite.CreateSolidBrush(clrHilite);

	brBlack.DeleteObject();
	brBlack.CreateSolidBrush(clrBtnDkShadow);

	brWindow.DeleteObject();
	brWindow.CreateSolidBrush(clrWindow);

	penHilite.DeleteObject();
	penHilite.CreatePen(PS_SOLID, 1, afxGlobalData.clrHilite);

	penBarFace.DeleteObject();
	penBarFace.CreatePen(PS_SOLID, 1, afxGlobalData.clrBarFace);

	penBarShadow.DeleteObject();
	penBarShadow.CreatePen(PS_SOLID, 1, afxGlobalData.clrBarShadow);

	if (brLight.GetSafeHandle())
	{
		brLight.DeleteObject();
	}

	if (m_nBitsPerPixel > 8)
	{
		COLORREF clrLight = RGB(GetRValue(clrBtnFace) +((GetRValue(clrBtnHilite) - GetRValue(clrBtnFace)) / 2 ),
			GetGValue(clrBtnFace) +((GetGValue(clrBtnHilite) - GetGValue(clrBtnFace)) / 2),
			GetBValue(clrBtnFace) +((GetBValue(clrBtnHilite) - GetBValue(clrBtnFace)) / 2));

		brLight.CreateSolidBrush(clrLight);
	}
	else
	{
		HBITMAP hbmGray = CreateDitherBitmap(dc.GetSafeHdc());
		ENSURE(hbmGray != NULL);

		CBitmap bmp;
		bmp.Attach(hbmGray);

		brLight.CreatePatternBrush(&bmp);
	}

//	CMenuImages::CleanUp();
//	CDockingManager::m_bSDParamsModified = TRUE;
}
void ColorPicker::OnPaint()
{
    // Setup a backbuffer:
    CPaintDC dcPaint(this);
    CDC dc;
    dc.CreateCompatibleDC(&dcPaint);
    CRect rectClient;
    GetClientRect(rectClient);
    CBitmap bitmap;
    bitmap.CreateCompatibleBitmap(&dcPaint, rectClient.Width(), rectClient.Height());
    CBitmap *oldBitmap = dc.SelectObject(&bitmap);

    // Fill background first
    CBrush bgBrush(GetSysColor(COLOR_BTNFACE));
    dc.FillRect(&rectClient, &bgBrush);

    // Draw a border:
    dc.Draw3dRect
    (
        0,
        0,
        rectClient.Width(),
        rectClient.Height(),
        RGB(0, 0, 0),
        RGB(0, 0, 0)
    );

    if (hueBarDirty_)
        generateHueBar();

    if (alphaBarDirty_ || (!alphaSelection_ && slGraphDirty_))
        generateAlphaBar();

    if (slGraphDirty_)
        generatePicker();

    if (slPickerDirty_)
        setPicker(false);

    dc.BitBlt
    (
        slGraphRect_.left,
        slGraphRect_.top,
        slGraphRect_.Width(),
        slGraphRect_.Height(),
        pickerDC_,
        0,
        0,
        SRCCOPY
    );
    dc.BitBlt
    (
        hueBarRect_.left,
        hueBarRect_.top,
        hueBarRect_.Width(),
        hueBarRect_.Height(),
        hueBarDC_,
        0,
        0,
        SRCCOPY
    );
    dc.BitBlt
    (
        alphaBarRect_.left,
        alphaBarRect_.top,
        alphaBarRect_.Width(),
        alphaBarRect_.Height(),
        alphaBarDC_,
        0,
        0,
        SRCCOPY
    );

    // Draw sl picker:
    CSize sz(6, 6);
    drawCrossAt
    (
        slPickerPosition_,
        dc,
        sz
    );

    // Draw hue indicator:
    sz.cx = hueBarRect_.Width();
    sz.cy = 6;
    CPoint
    pt
    (
        slGraphRect_.Width() + c_spacer_ + hueBarRect_.Width()/2 + c_borderSpace_,
        (int)(currentHue_*hueBarRect_.Height()) + c_borderSpace_
    );
    drawCrossAt(pt, dc, sz);

    if (alphaSelection_)
    {
        // Draw alpha indicator:
        sz.cx = 6;
        sz.cy = alphaBarRect_.Height();
        pt =
            CPoint
            (
                (int)(currentAlpha_ * alphaBarRect_.Width()) + c_borderSpace_,
                (int)(slGraphRect_.Height() + c_spacer_ + alphaBarRect_.Height()/2) + c_borderSpace_
            );
        drawCrossAt(pt, dc, sz);
    }

    // Draw the backbuffer:
    dcPaint.BitBlt
    (
        rectClient.left,
        rectClient.top,
        rectClient.Width(),
        rectClient.Height(),
        &dc,
        0,
        0,
        SRCCOPY
    );
    dc.SelectObject(oldBitmap);
    dc.DeleteDC();
    bitmap.DeleteObject();
}
Esempio n. 24
0
void CTipDlg::OnPaint()
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		if( cxIcon == 16 && cyIcon == 16 )
		{
			dc.DrawIcon( x, y, theApp.hMainIconSmall );
		}
		else
		{
			dc.DrawIcon( x, y, theApp.hMainIconBig );
		}
		return;
	}

	CPaintDC dc(this); // device context for painting

	// Get paint area for the big static control
	CWnd* pStatic = GetDlgItem(IDC_FRAME_INTERNAL);
	CRect rect;
	pStatic->GetWindowRect(&rect);
	ScreenToClient(&rect);

	// Paint the background white.
	CBrush brush;
	brush.CreateStockObject(WHITE_BRUSH);
	dc.FillRect(rect, &brush);

	// Load bitmap and get dimensions of the bitmap
	CBitmap bmp;
	bmp.LoadBitmap(IDB_LIGHTBULB);
	BITMAP bmpInfo;
	ZeroMemory( &bmpInfo, sizeof(bmpInfo) );
	bmp.GetBitmap(&bmpInfo);

	// Draw bitmap in top corner and validate only top portion of window
	CDC dcTmp;
	dcTmp.CreateCompatibleDC(&dc);
	dcTmp.SelectObject(&bmp);
	rect.bottom = bmpInfo.bmHeight + rect.top;
	dc.BitBlt(rect.left, rect.top, rect.Width(), rect.Height(), 
		&dcTmp, 0, 0, SRCCOPY);

	// Draw out "Did you know..." message next to the bitmap
	CString strMessage;
	strMessage = LocLoadString(IDS_TIPS_DIDYOUKNOW);
	rect.left += bmpInfo.bmWidth;
	dc.SetBkMode( TRANSPARENT );
	dc.DrawText(strMessage, rect, DT_VCENTER | DT_SINGLELINE);

	// Do not call CDialog::OnPaint() for painting messages
}