Beispiel #1
0
QLineF
XmlUnmarshaller::lineF(QDomElement const& el)
{
	QPointF const p1(pointF(el.namedItem("p1").toElement()));
	QPointF const p2(pointF(el.namedItem("p2").toElement()));
	return QLineF(p1, p2);
}
std::vector< const AntWorldTile* > GraphicsAntWorldScene::neighbours( const AntPosition& position ) const
{
  QPointF pointF( qreal( position.x() ), qreal( position.y() ) );

  /* Since we're working in a 2D grid, we can get all 4 neighbour tiles by offsetting
   * the relevant coordinate with the amount equal to the square edge of a tile (which
   * should place us roughly near the centre of whichever neighbour we're searching for. */
  QPointF northNeighbour( pointF + QPointF( 0.0, AntConfig::TileSize ) );
  QPointF southNeighbour( pointF - QPointF( 0.0, AntConfig::TileSize ) );
  QPointF westNeighbour( pointF + QPointF( AntConfig::TileSize, 0.0 ) );
  QPointF eastNeighbour( pointF - QPointF( AntConfig::TileSize, 0.0 ) );

  QList< QPointF > neighboursPoints = QList< QPointF >() << northNeighbour << southNeighbour << westNeighbour << eastNeighbour;
  std::vector< const AntWorldTile* > neighbours;

  for( int i = 0; i < neighboursPoints.size(); ++i )
  {
    QList< QGraphicsItem* > itemList = items( neighboursPoints.at( i ) );

    for( int j = 0; j < itemList.size(); ++j )
    {
      GraphicsWorldTile* tile = dynamic_cast< GraphicsWorldTile* >( itemList.at( j ) );
      if( tile ) neighbours.push_back( tile );
    }
  }

  return neighbours;
}
void MyPrimitive::GeneratePlane(float a_fSize, vector3 a_v3Color)
{
	if (a_fSize < 0.01f)
		a_fSize = 0.01f;

	Release();
	Init();

	float fValue = 0.5f * a_fSize;

	vector3 pointA(-fValue, -fValue, 0.0f); //0
	vector3 pointB(fValue, -fValue, 0.0f); //1
	vector3 pointC(fValue, fValue, 0.0f); //2
	vector3 pointD(-fValue, fValue, 0.0f); //3

	vector3 pointE(fValue, -fValue, -0.001f); //1
	vector3 pointF(-fValue, -fValue, -0.001f); //0
	vector3 pointG(fValue, fValue, -0.001f); //2
	vector3 pointH(-fValue, fValue, -0.001f); //3

											  //F
	AddQuad(pointA, pointB, pointD, pointC);
	//Double sided
	AddQuad(pointE, pointF, pointG, pointH);

	CompileObject(a_v3Color);
}
Beispiel #4
0
//////////////////////////
///  Handlers For TabButtons 
/////////////////////////////////
void TrackingButtonPaintHandler()
{
	HDC hdc;
	PAINTSTRUCT ps;
	hdc = BeginPaint(hTrackingButton, &ps);

	Gdiplus::Graphics graphics(hdc);
	Gdiplus::SolidBrush solidBrush1(Gdiplus::Color(255, 0, 0, 0));
	graphics.FillRectangle(&solidBrush1, 0, 0, 60, 40);


	Gdiplus::FontFamily  fontFamily(L"Microsoft YaHei");
	Gdiplus::Font        font(&fontFamily, 24, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
	Gdiplus::PointF      pointF(0.0f, 4.0f);
	
	Gdiplus::SolidBrush  solidBrush2(Gdiplus::Color(255, 225, 225, 225));
	Gdiplus::SolidBrush  solidBrush3(Gdiplus::Color(255, 96, 96, 96));
	if (TabState == 0) 
	{
		graphics.DrawString(L"¸ú×Ù", -1, &font, pointF, &solidBrush2);
	}
	else 
	{
		graphics.DrawString(L"¸ú×Ù", -1, &font, pointF, &solidBrush3);
	}
	graphics.ReleaseHDC(hdc);
	EndPaint(hTrackingButton, &ps);
}
Beispiel #5
0
void PauseButtonPaintHandler()
{
	HDC hdc;
	PAINTSTRUCT ps;
	hdc = BeginPaint(hPauseButton, &ps);

	Gdiplus::Graphics graphics(hdc);
	Gdiplus::SolidBrush solidBrush1(Gdiplus::Color(255, 0, 0, 0));
	graphics.FillRectangle(&solidBrush1, 0, 0, 35, 20);

	Gdiplus::FontFamily  fontFamily(L"Microsoft YaHei");
	Gdiplus::Font        font(&fontFamily, 12, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
	Gdiplus::PointF      pointF(0.0f, 2.0f);
	Gdiplus::SolidBrush  solidBrush2(Gdiplus::Color(255, 255, 255, 255));
	if (TabState == 0) 
	{
		if (paused) 
		{
			graphics.DrawString(L"²¥·Å", -1, &font, pointF, &solidBrush2);
		}
		else
		{
			graphics.DrawString(L"ÔÝÍ£", -1, &font, pointF, &solidBrush2);
		}	
	}
	graphics.ReleaseHDC(hdc);

	EndPaint(hPauseButton, &ps);
}
Beispiel #6
0
void Label::onDraw(Gdiplus::Graphics& g, int x, int y)
{
	Gdiplus::FontFamily  fontFamily(fontFamily_.c_str());
	Gdiplus::Font        font(&fontFamily, fontSize_, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
	Gdiplus::PointF      pointF(float(x+x_), float(y+y_));
	Gdiplus::SolidBrush  solidBrush(fontColor_);

	g.DrawString(text_.c_str(), text_.length(), &font, pointF, &solidBrush);
}
Beispiel #7
0
void TextComponent::paint(Gdiplus::Graphics& graphics)
{
  Gdiplus::SolidBrush brush(Gdiplus::Color(m_r, m_g, m_b));
  Gdiplus::FontFamily fontFamily(L"Helvetica");
  Gdiplus::Font font(&fontFamily, (Gdiplus::REAL) m_fontSize, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
  Gdiplus::PointF pointF(m_x, m_y);
  Gdiplus::RectF boundingBox;
  graphics.MeasureString(m_text.c_str(), -1, &font, pointF, &boundingBox);
  m_width = boundingBox.Width;
  m_height = boundingBox.Height;
  graphics.DrawString(m_text.c_str(), -1, &font, pointF, &brush);
}
Beispiel #8
0
void CToastDlg::DrawPromptMsg(Graphics * g, LPCTSTR msg)
{
	SolidBrush brush(Color(0, 0, 255));
	FontFamily fontFamily(L"微软雅黑");
	Gdiplus::Font font(&fontFamily, 0.2f, FontStyleRegular, UnitInch);
	PointF pointF(50, 220);
	RectF layoutRect(30, 220, 700, 0);
	RectF boundRect;
	INT codePointsFitted = 0;
	INT linesFitted = 0;
	g->MeasureString(msg, -1, &font, layoutRect, NULL, &boundRect, &codePointsFitted, &linesFitted);
	g->DrawString(msg, -1, &font, boundRect, NULL, &brush);
}
Beispiel #9
0
void PngButton::DrawBtn()
{
    common::ui::ImageEx* drawImage = GetDrawImage();
    if (drawImage == NULL || m_rcWnd.IsRectEmpty())
    {
        return;
    }

    CRect rect(&m_rcWnd);
    ClientToScreen(&rect);
    //GetWindowRect(&rect);
    CDC *pCDC = GetDC();
    HDC hdcTemp = pCDC->GetSafeHdc();
    HDC hdcMemory = CreateCompatibleDC( hdcTemp );
    HBITMAP hBitMap = CreateCompatibleBitmap( hdcTemp , rect.Width(), rect.Height() );
    HBITMAP hOld = (HBITMAP)SelectObject( hdcMemory , hBitMap );
    Graphics graph( hdcMemory );
    graph.DrawImage(drawImage, 0, 0, rect.Width(), rect.Height());

    if (m_strContent != L"")//有文字内容
    {
        Color conColor;
        conColor.SetFromCOLORREF(m_colCon);
        SolidBrush  brush(conColor);
        FontFamily  fontFamily(m_strConFont.GetBuffer(0));
        Font        font(&fontFamily, m_fontSize, FontStyleBold, UnitPixel);
        PointF      pointF( 0.0f , 0.0f );
        RectF boundRect;
        graph.MeasureString( m_strContent , m_strContent.GetLength() ,&font ,pointF , &boundRect );
        pointF.X = m_rcWnd.left + (m_rcWnd.Width() - boundRect.Width)/2;
        pointF.Y = m_rcWnd.top + (m_rcWnd.Height() - boundRect.Height)/2;
        graph.DrawString( m_strContent , m_strContent.GetLength(), &font, pointF, &brush );
    }

    BOOL bResult = BitBlt( hdcTemp , rect.left , rect.top , rect.Width() , rect.Height() , hdcMemory , 0 , 0 , SRCCOPY );

    POINT ptWinPos = { rect.left,rect.top };
    POINT ptSrc= {0,0};
    SIZE sizeWindow = {rect.Width(), rect.Height() };
    ::UpdateLayeredWindow(m_hWnd, hdcTemp, &ptWinPos, &sizeWindow, hdcMemory, &ptSrc, 0, &m_blend, ULW_ALPHA);
    graph.ReleaseHDC(hdcMemory);
    SelectObject(hdcMemory, hOld);
    DeleteObject(hBitMap);
    DeleteDC(hdcMemory);
    ReleaseDC(pCDC);
}
Beispiel #10
0
QPolygonF
XmlUnmarshaller::polygonF(QDomElement const& el)
{
	QPolygonF poly;
	
	QString const point_tag_name("point");
	QDomNode node(el.firstChild());
	for (; !node.isNull(); node = node.nextSibling()) {
		if (!node.isElement()) {
			continue;
		}
		if (node.nodeName() != point_tag_name) {
			continue;
		}
		poly.push_back(pointF(node.toElement()));
	}
	
	return poly;
}
Beispiel #11
0
void SubPlotWnd::DrawString(Graphics * g)
{
	Color fontColor;
	
	COLORREF color;
	bool succ = this->StrategyGetColor.Call(this, 0, color);
	ASSERT(succ);

	fontColor.SetFromCOLORREF(color);

	SolidBrush fontBrush(fontColor);
	
	StringFormat format;
	format.SetAlignment(StringAlignmentNear);
	Gdiplus::Font font(L"Arial", 10);
	PointF pointF(5, 2);
	CRect rect;
	this->GetClientRect(&rect);
	RectF boundRect(
		(Gdiplus::REAL)rect.left,
		(Gdiplus::REAL)rect.top,
		(Gdiplus::REAL)rect.right,
		(Gdiplus::REAL)rect.bottom
		);

	//int frameCount = 1;

	//int stringLen = 0;

	//int validFrameCount = 0;
	//int frameIdx = plotWndProp->replayReadPos;

	//while( (frameIdx > 0) && (validFrameCount < frameCount) )
	//{
	//	frameIdx--;
	//	int frameDataCount = seriesProp->replayBuffer[frameIdx].len / sizeof(char);
	//	if (frameDataCount > 0)
	//	{
	//		validFrameCount++;
	//	}
	//	stringLen += frameDataCount;
	//	if (stringLen > 4*1024)
	//		break;
	//}

	//char * string = new char[stringLen+1];
	//char * dstPtr = string;


	//while( frameIdx < plotWndProp->replayReadPos )
	//{
	//	int frameDataCount = seriesProp->replayBuffer[frameIdx].len / sizeof(char);
	//	if (frameDataCount > 0)
	//	{
	//		memcpy(dstPtr, seriesProp->replayBuffer[frameIdx].data, frameDataCount * sizeof(char));
	//		dstPtr += frameDataCount;
	//	}
	//	frameIdx++;
	//}

	//*dstPtr = 0;

	CString stringToDraw(string);
	g->DrawString(stringToDraw, -1, &font, boundRect, &format, &fontBrush);

	//delete [] string;

}
Beispiel #12
0
//=============================================================================
//
//	The framework calls this member function when a child control is about to 
//	be drawn.  All the bitmaps are created here on the first call. Every thing
//	is done with a memory DC except the background, which get's it's information 
//	from the parent. The background is needed for transparent portions of PNG 
//	images. An always on top app (such as Task Manager) that is in the way can 
//	cause it to get an incorrect background.  To avoid this, the parent should 
//	call the SetBkGnd function with a memory DC when it creates the background.
//				
//=============================================================================
HBRUSH CGdipButtonTile::CtlColor(CDC* pScreenDC, UINT nCtlColor) 
{
	if(!m_bHaveBitmaps)
	{
		if(!m_pStdLeftImage || !m_pStdCenterImage || !m_pStdRightImage)
		{
			return NULL; // Load the standard image with LoadStdImage()
		}

		CBitmap bmp, *pOldBitmap;

		CRect rect;
		GetClientRect(rect);

		// do everything with mem dc
		CMemDCEx pDC(pScreenDC, rect);


		Gdiplus::Graphics graphics(pDC->m_hDC);

		// background
		if (m_dcBk.m_hDC == NULL)
		{
			CRect rect1;
			CClientDC clDC(GetParent());
			GetWindowRect(rect1);
			GetParent()->ScreenToClient(rect1);

			m_dcBk.CreateCompatibleDC(&clDC);
			bmp.CreateCompatibleBitmap(&clDC, rect.Width(), rect.Height());
			pOldBitmap = m_dcBk.SelectObject(&bmp);
			m_dcBk.BitBlt(0, 0, rect.Width(), rect.Height(), &clDC, rect1.left, rect1.top, SRCCOPY);
			bmp.DeleteObject();
		}

		// standard image
		if (m_dcStd.m_hDC == NULL)
		{
			PaintBk(pDC);

			InterpolationMode  interMode = graphics.GetInterpolationMode();
			graphics.SetInterpolationMode(InterpolationModeNearestNeighbor);

			int		nCalPos = 0;
			int		nWidthLeft = m_pStdLeftImage->m_pBitmap->GetWidth();
			int		nWidthRight = m_pStdRightImage->m_pBitmap->GetWidth();
			graphics.DrawImage(*m_pStdLeftImage, 0, 0, nWidthLeft, m_pStdLeftImage->m_pBitmap->GetHeight());
			nCalPos += nWidthLeft;
			graphics.DrawImage(*m_pStdCenterImage, nCalPos, 0, (m_nButtonWidth-nWidthLeft-nWidthRight)*2, m_pStdCenterImage->m_pBitmap->GetHeight());
			nCalPos += m_nButtonWidth-nWidthLeft-nWidthRight;
			graphics.DrawImage(*m_pStdRightImage, nCalPos, 0, nWidthRight, m_pStdRightImage->m_pBitmap->GetHeight());
			graphics.SetInterpolationMode(interMode);

			// 글자!
			FontFamily fontFamily(L"나눔고딕");
		    Gdiplus::Font font(&fontFamily, 22, FontStyleBold, UnitPixel);
			SolidBrush brush(Color(255, 72, 72, 72));
			StringFormat stringFormat;
			stringFormat.SetAlignment(StringAlignmentCenter);
			stringFormat.SetLineAlignment(StringAlignmentCenter);
			PointF pointF((float)m_nButtonWidth/2, (float)m_nButtonHeight/2);
			graphics.SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);
			graphics.DrawString(m_strText, (INT)wcslen(m_strText), &font, pointF, &stringFormat, &brush);


			m_dcStd.CreateCompatibleDC(pDC);
			bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
			pOldBitmap = m_dcStd.SelectObject(&bmp);
			m_dcStd.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
			//m_dcStd.TransparentBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, rect.Width(), rect.Height(), RGB(255,255,255));
			bmp.DeleteObject();

			// standard image pressed
			if (m_dcStdP.m_hDC == NULL)
			{
				PaintBk(pDC);

				interMode = graphics.GetInterpolationMode();
				graphics.SetInterpolationMode(InterpolationModeNearestNeighbor);

				nCalPos = 1;
				graphics.DrawImage(*m_pStdLeftImage, nCalPos, 1, nWidthLeft, m_pStdLeftImage->m_pBitmap->GetHeight());
				nCalPos += nWidthLeft;
				graphics.DrawImage(*m_pStdCenterImage, nCalPos, 1, 2*(m_nButtonWidth-nWidthLeft-nWidthRight), m_pStdCenterImage->m_pBitmap->GetHeight());
				nCalPos += m_nButtonWidth-nWidthLeft-nWidthRight;
				graphics.DrawImage(*m_pStdRightImage, nCalPos, 1, nWidthRight, m_pStdRightImage->m_pBitmap->GetHeight());
				graphics.SetInterpolationMode(interMode);

				// 글자!
				FontFamily fontFamily(L"나눔고딕");
				Gdiplus::Font font(&fontFamily, 22, FontStyleBold, UnitPixel);
				SolidBrush brush(Color(255, 0, 0, 255));
				StringFormat stringFormat;
				stringFormat.SetAlignment(StringAlignmentCenter);
				stringFormat.SetLineAlignment(StringAlignmentCenter);
				PointF pointF((float)m_nButtonWidth/2, (float)m_nButtonHeight/2);
				graphics.DrawString(m_strText, (INT)wcslen(m_strText), &font, pointF, &stringFormat, &brush);

				m_dcStdP.CreateCompatibleDC(pDC);
				bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
				pOldBitmap = m_dcStdP.SelectObject(&bmp);
				m_dcStdP.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
				bmp.DeleteObject();
			}

			// standard image hot
			if(m_dcStdH.m_hDC == NULL)
			{
				PaintBk(pDC);

				ColorMatrix HotMat = {	1.05f, 0.00f, 0.00f, 0.00f, 0.00f,
										0.00f, 1.05f, 0.00f, 0.00f, 0.00f,
										0.00f, 0.00f, 1.05f, 0.00f, 0.00f,
										0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
										0.05f, 0.05f, 0.05f, 0.00f, 1.00f	};

				ImageAttributes ia;
				ia.SetColorMatrix(&HotMat);

				float width = (float)m_nButtonWidth;
				float height = (float)m_nButtonHeight;

				RectF grect; grect.X=0, grect.Y=0; grect.Width = width; grect.Height = height;

				interMode = graphics.GetInterpolationMode();
				graphics.SetInterpolationMode(InterpolationModeNearestNeighbor);

				nCalPos = 0;
				grect.Width = (float)nWidthLeft;
				graphics.DrawImage(*m_pStdLeftImage, grect, 0, 0, (float)nWidthLeft, height, UnitPixel, &ia);
				nCalPos += nWidthLeft;
				grect.X = (float)nCalPos;
				grect.Width = (float)((m_nButtonWidth-nWidthLeft-nWidthRight)*2);
				graphics.DrawImage(*m_pStdCenterImage, grect, 0, 0, 1, height, UnitPixel, &ia);
				nCalPos += m_nButtonWidth-nWidthLeft-nWidthRight;
				grect.X = (float)nCalPos;
				grect.Width = (float)nWidthRight;
				graphics.DrawImage(*m_pStdRightImage, grect, 0, 0, (float)nWidthRight, height, UnitPixel, &ia);
				graphics.SetInterpolationMode(interMode);

				// 글자!
				FontFamily fontFamily(L"나눔고딕");
				Gdiplus::Font font(&fontFamily, 22, FontStyleBold, UnitPixel);
				SolidBrush brush(Color(255, 72, 72, 72));
				StringFormat stringFormat;
				stringFormat.SetAlignment(StringAlignmentCenter);
				stringFormat.SetLineAlignment(StringAlignmentCenter);
				PointF pointF((float)m_nButtonWidth/2, (float)m_nButtonHeight/2);
				graphics.DrawString(m_strText, (INT)wcslen(m_strText), &font, pointF, &stringFormat, &brush);

				m_dcStdH.CreateCompatibleDC(pDC);
				bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
				pOldBitmap = m_dcStdH.SelectObject(&bmp);
				m_dcStdH.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
				bmp.DeleteObject();
			}

			// grayscale image
			if(m_dcGS.m_hDC == NULL && m_bHaveAltImage)
			{
				int		nWidthLeft = m_pAltLeftImage->m_pBitmap->GetWidth();
				int		nWidthRight = m_pAltRightImage->m_pBitmap->GetWidth();

				PaintBk(pDC);

				interMode = graphics.GetInterpolationMode();
				graphics.SetInterpolationMode(InterpolationModeNearestNeighbor);

				nCalPos = 1;
				graphics.DrawImage(*m_pAltLeftImage, nCalPos, 1, nWidthLeft, m_pAltLeftImage->m_pBitmap->GetHeight());
				nCalPos += nWidthLeft;
				graphics.DrawImage(*m_pAltCenterImage, nCalPos, 1, 2*(m_nButtonWidth-nWidthLeft-nWidthRight), m_pAltCenterImage->m_pBitmap->GetHeight());
				nCalPos += m_nButtonWidth-nWidthLeft-nWidthRight;
				graphics.DrawImage(*m_pAltRightImage, nCalPos, 1, nWidthRight, m_pAltRightImage->m_pBitmap->GetHeight());
				graphics.SetInterpolationMode(interMode);

				// 글자!
				FontFamily fontFamily(L"나눔고딕");
				Gdiplus::Font font(&fontFamily, 22, FontStyleBold, UnitPixel);
				SolidBrush brush(Color(255, 0, 0, 255));
				StringFormat stringFormat;
				stringFormat.SetAlignment(StringAlignmentCenter);
				stringFormat.SetLineAlignment(StringAlignmentCenter);
				PointF pointF((float)m_nButtonWidth/2, (float)m_nButtonHeight/2);
				graphics.DrawString(m_strText, (INT)wcslen(m_strText), &font, pointF, &stringFormat, &brush);

				m_dcGS.CreateCompatibleDC(pDC);
				bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
				pOldBitmap = m_dcGS.SelectObject(&bmp);
				m_dcGS.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
				bmp.DeleteObject();
			}
		}

#if 0
		// alternate image
		if( (m_dcAlt.m_hDC == NULL) && m_bHaveAltImage )
		{
			PaintBk(pDC);

		//	graphics.DrawImage(*m_pAltImage, 0, 0);
			graphics.DrawImage(*m_pAltImage, 0, 0, m_pAltImage->m_pBitmap->GetWidth(), m_pAltImage->m_pBitmap->GetHeight());
		
			m_dcAlt.CreateCompatibleDC(pDC);
			bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
			pOldBitmap = m_dcAlt.SelectObject(&bmp);
			m_dcAlt.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
			bmp.DeleteObject();

			// alternate image pressed
			if( (m_dcAltP.m_hDC == NULL) && m_bHaveAltImage )
			{
				PaintBk(pDC);

				// 2012.02.24 frino - Alt 영상이 커지는 문제가 발생하여 수정함
//				graphics.DrawImage(*m_pAltImage, 1, 1);
				graphics.DrawImage(*m_pAltImage, 1, 1, m_pAltImage->m_pBitmap->GetWidth(), m_pAltImage->m_pBitmap->GetHeight());
			
				m_dcAltP.CreateCompatibleDC(pDC);
				bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
				pOldBitmap = m_dcAltP.SelectObject(&bmp);
				m_dcAltP.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
				bmp.DeleteObject();
			}

			// alternate image hot
			if(m_dcAltH.m_hDC == NULL)
			{
				PaintBk(pDC);

				ColorMatrix HotMat = {	1.05f, 0.00f, 0.00f, 0.00f, 0.00f,
										0.00f, 1.05f, 0.00f, 0.00f, 0.00f,
										0.00f, 0.00f, 1.05f, 0.00f, 0.00f,
										0.00f, 0.00f, 0.00f, 1.00f, 0.00f,
										0.05f, 0.05f, 0.05f, 0.00f, 1.00f	};

				ImageAttributes ia;
				ia.SetColorMatrix(&HotMat);

				float width = (float)m_pAltImage->m_pBitmap->GetWidth();
				float height = (float)m_pAltImage->m_pBitmap->GetHeight();

				RectF grect; grect.X=0, grect.Y=0; grect.Width = width; grect.Height = height;

				graphics.DrawImage(*m_pAltImage, grect, 0, 0, width, height, UnitPixel, &ia);

				m_dcAltH.CreateCompatibleDC(pDC);
				bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
				pOldBitmap = m_dcAltH.SelectObject(&bmp);
				m_dcAltH.BitBlt(0, 0, rect.Width(), rect.Height(), pDC, 0, 0, SRCCOPY);
				bmp.DeleteObject();
			}
		}
#endif

		if (m_pCurBtn == NULL)
		{
			m_pCurBtn = &m_dcStd;
		}

		m_bHaveBitmaps = TRUE;
	}

	return NULL;
}
Beispiel #13
0
// 把DispTextBuf的内容输出到屏幕上去
// 对于属性相同的连续的字符,是以字符串而不是字符的形式TextOut的
int TextBufOut()
{
	PAINTSTRUCT ps;	
	HDC hdc = BeginPaint(hMyWnd, &ps);
	Graphics    rgraphics(hdc);
	SolidBrush  brush(Color(255, 255, 255, 255));	
	FontFamily  fontFamily(L"Courier New");
#ifdef _GDIP_
	double		WHscale=0.54112554;									//Courier New字体的宽高比
#else
	double		WHscale=0.5;
#endif	
	Gdiplus::Font        font(&fontFamily, (float)rect.bottom/TextSolutionY*0.882759, FontStyleBold, UnitPixel);			//0.882759=font.GetSize()/font.GetHeight(0.0);  这是对应于Courier New字体的值。	
	SolidBrush	CurBrush(Color(255, 255, 255, 255));

	Bitmap		bmpBuf(rect.right,rect.bottom);							//双缓冲
	Graphics	graphics(&bmpBuf);	

	PointF      pointF(0.0f, 0.0f);
	float		tempFX;
	float		CurX,CurY;

	wchar_t		ws[100];
	int			lao;
	
//////////////////////////////////////////////////////////////////////////
	HFONT   hFont;
	hFont=CreateFont((float)rect.bottom/TextSolutionY,0,0,0,FW_MEDIUM,   
		FALSE,FALSE,FALSE,DEFAULT_CHARSET,   
		OUT_RASTER_PRECIS,CLIP_DEFAULT_PRECIS,   
		VARIABLE_PITCH|PROOF_QUALITY,FF_DONTCARE,"Lucida Console");
	SelectObject(hdc,hFont);   
//////////////////////////////////////////////////////////////////////////
	
	
	//下面被注释掉的语句都是用GDI+时使用的。
	//graphics.Clear(Color(0,0,0));									//清除原先的内容。
	
	int pTextBufCur=0;
#ifdef _GDIP_
	unsigned short Txt[80*25+1]={L"石维康"};
#else
	char Txt[80*25+1]={"石维康"};
#endif
	pointF.Y=0;
	int j;
	for (int i=0;i<TextSolutionY;i++)
	{		
		int TxtLen=0;
		int PTxtLen=0;		
		char CurCharAttr=DispTextBuf[i*(*TextSolutionX)*2+1];	//第一个字符的属性
		pointF.X=0;
		for (j=0;j<(*TextSolutionX);j++)
		{
			if (CurCharAttr!=DispTextBuf[pTextBufCur+1])			//遇到不同属性,要输出字符串了
																									//不在串开关的LowAscii将不得不输出,所以每遇到LowAscii都要重起一串
			{
#ifdef _GDIP_
				pointF.X=(float)(PTxtLen)*font.GetHeight(0.0)*WHscale;//(rect.right/(*TextSolutionX));
				pointF.Y=font.GetHeight(0.0)*(i);
#else				
				GetCharWidthFloat(hdc,'A','A',&tempFX);
				pointF.X+=(float)(PTxtLen)*16*tempFX;
#endif
				PTxtLen=TxtLen;
				
#ifdef _GDIP_
				brush.SetColor(AttrToColorP(CurCharAttr&0x0f),CurCharAttr&0x80);
				graphics.DrawString(Txt,TxtLen,&font,pointF,&brush);
#else
				SetTextColor(hdc,AttrToColor(CurCharAttr&0x0f,CurCharAttr&0x80));
				SetBkColor(hdc,AttrToColor(((CurCharAttr&0xf0)>>4)&0x07,false)&0xffffff);				
// 				if (Txt[0]>=0xa9 && Txt[0]<=0xdf)					//只输出扩展Ascii里面的制表符。其实MyVM里应该有一个地方来设定是否可以输出中文
// 					OutHighAscii(hdc,&pointF.X,&pointF.Y,Txt,&TxtLen,(float)16*tempFX);				
// 				if ((unsigned char)Txt[0]<0x20 && Txt[0]!=0x00)									//输出箭头和心形等
// 				{
// 					lao=OutLowAscii(hdc,&pointF.X,&pointF.Y,(unsigned char *)Txt,&TxtLen,(float)16*tempFX);
// 					//pTextBufCur+=lao*2;
// 				}
// 				else
// 					lao=0;
				MultiByteToWideChar(437,0,Txt,TxtLen,ws,100);
				TextOutW(hdc,pointF.X,pointF.Y,ws,TxtLen);
#endif								
				TxtLen=0;
				CurCharAttr=DispTextBuf[pTextBufCur+1];
			}
			//else													//遇到相同属性,把它加到Txt后面就可以了
			{
#ifdef _GDIP_
				if (DispTextBuf[pTextBufCur+1]>0 && DispTextBuf[pTextBufCur+1]<0x80)	//ASCII码
#endif
				{				
					Txt[TxtLen]=DispTextBuf[pTextBufCur];
					Txt[++TxtLen]=0;
					pTextBufCur+=2;
				}
#ifdef _GDIP_
				else																//Unicode字符
				{
					Txt[TxtLen]=(unsigned char)DispTextBuf[pTextBufCur];
					Txt[TxtLen]<<=8;
					pTextBufCur+=2;
					j++;
					Txt[TxtLen]+=(unsigned char)DispTextBuf[pTextBufCur];
					Txt[++TxtLen]=0;
					pTextBufCur+=2;
				}
#endif
			}	
		}

#ifdef _GDIP_
		pointF.X=(float)(j-TxtLen)*font.GetHeight(0.0)*WHscale;
		pointF.Y=font.GetHeight(0.0)*(i);
#else
		GetCharWidthFloat(hdc,'A','A',&tempFX);
		pointF.X=(float)(j-TxtLen)*16*tempFX;
#endif
		
#ifdef _GDIP_
		brush.SetColor(AttrToColorP(CurCharAttr&0x0f,CurCharAttr&0x80));
		graphics.DrawString(Txt,TxtLen,&font,pointF,&brush);		
#else
		SetTextColor(hdc,AttrToColor(CurCharAttr&0x0f,CurCharAttr&0x80));
		SetBkColor(hdc,AttrToColor(((CurCharAttr&0xf0)>>4)&0x07,false)&0xffffff);		
// 		if (Txt[0]>=0xa9 && Txt[0]<=0xdf)					//只输出扩展Ascii里面的制表符。其实MyVM里应该有一个地方来设定是否可以输出中文
// 			OutHighAscii(hdc,&pointF.X,&pointF.Y,Txt,&TxtLen,(float)16*tempFX);
// 		if ((unsigned char)Txt[0]<0x20 && Txt[0]!=0x00)									//输出箭头和心形等
// 		{
// 			lao=OutLowAscii(hdc,&pointF.X,&pointF.Y,(unsigned char *)Txt,&TxtLen,(float)16*tempFX);
// 			//pTextBufCur+=lao*2;
// 		}
// 		else
// 			lao=0;
		MultiByteToWideChar(437,0,Txt,TxtLen,ws,100);
		TextOutW(hdc,pointF.X,pointF.Y,ws,TxtLen);
		pointF.Y+=(int)font.GetHeight(0.0);							//pointF.Y是浮点,TextOut的参数是整形,浮点误差的积累会产生黑线
#endif
	}
void doHough(std::vector<payload> readings, int lineThresh, int pointThresh)
{
    std::vector<float> maxVal(2), res(2);
    std::vector<float> minVal(2);
    std::vector<float> vote(2);

    /**
     * LINE SPACE
     * RHO: The perpendicular distance of the line from origin
     * THETA: Angle the perpendicular from the origin to the line
     *        makes with +X axis
     *
     * beta: Angular error of ultrasonic sensor, -15deg < beta < 15deg
     */
    maxVal[RHO] = 15000.0F; // in millimetres
    maxVal[THETA] = (float) 2 * M_PI; // in radians
    res[RHO] = 100;
    res[THETA] = M_PI / 180 * 5;

    houghSpace linespace (res, maxVal);

    for (auto &p: readings) {
        for (float beta = -M_PI/12; beta <= M_PI/12; beta += M_PI/180) {
            // Refer to the paper for the derivation
            vote[THETA] = p.loc.theta + beta;
            vote[THETA] = fmod(vote[THETA], 2 * M_PI);
            if (vote[THETA] < 0) {
                vote[THETA] += 2 * M_PI;
            }
            vote[RHO] = std::abs(p.reading + (p.loc.x * cosf(vote[THETA]))
                                  + (p.loc.y * sinf(vote[THETA])));
            assert(vote[RHO] <= maxVal[RHO]);
            assert(vote[THETA] <= maxVal[THETA]);
            PPRINT(vote[RHO]);
            PPRINT(vote[THETA]);
            linespace.addVote(vote);
        }
    }
    std::vector< std::vector<float> > lineF (linespace.getMaxima(lineThresh));
    std::ofstream lout ("lines.txt");
    for (auto &p: lineF) {
        for (auto &q: p) {
            lout << q << " ";
        }
        lout << std::endl;
    }
    //std::cout << linespace;
    /**
     * POINT SPACE
     * X: X-coordinate of point
     * Y: Y-coordinate of point
     *
     * beta: Angular error of ultrasonic sensor, -15deg < beta < 15deg
     */
    maxVal[X] = 15000.0F; // in millimetres
    maxVal[Y] = 15000.0F; // in millimetres
    minVal[X] = -15000.0F;
    minVal[Y] = -15000.0F;
    res[X] = 10;
    res[Y] = 10;

    houghSpace pointspace (res, maxVal, minVal);

    for (auto &p: readings) {
        for (float beta = -M_PI/12; beta <= M_PI/12; beta += M_PI/180) {
            vote[X] = p.loc.x + (p.reading * cosf(p.loc.theta + beta));
            vote[Y] = p.loc.y + (p.reading * sinf(p.loc.theta + beta));
            assert(vote[X] <= maxVal[X]);
            assert(vote[Y] <= maxVal[Y]);
            PPRINT(vote[X]);
            PPRINT(vote[Y]);
            pointspace.addVote(vote);
        }
    }
    std::vector< std::vector<float> > pointF (pointspace.getMaxima(pointThresh));
    std::ofstream pout ("points.txt");
    for (auto &p: pointF) {
        for (auto &q: p) {
            pout << q << " ";
        }
        pout << std::endl;
    }
  //std::cout << pointspace;
}
Beispiel #15
0
void CSkinDialog::DrawTitleBar(void){
	//获取窗体大小
	CRect rtWindow;
	GetWindowRect(&rtWindow);
	
	UINT btnHeight = m_bpBtnExt->GetHeight();
	UINT btnWidth = m_bpBtnExt->GetWidth();
	UINT border = GetSystemMetrics(SM_CXSIZEFRAME);

	//确定按钮位置
	m_rtBtnExt.right	= rtWindow.Width() - 5 - border;
	m_rtBtnExt.top		= (m_bpTitleBar->GetHeight() - btnHeight)/2 + border;
	m_rtBtnExt.left		= m_rtBtnExt.right - btnWidth;
	m_rtBtnExt.bottom	= m_rtBtnExt.top + btnHeight;

	m_rtBtnMax.right	= m_rtBtnExt.left - 2;
	m_rtBtnMax.top		= m_rtBtnExt.top;
	m_rtBtnMax.left		= m_rtBtnMax.right - btnWidth;
	m_rtBtnMax.bottom	= m_rtBtnExt.bottom;

	m_rtBtnMin.right	= m_rtBtnMax.left - 2;
	m_rtBtnMin.top		= m_rtBtnMax.top;
	m_rtBtnMin.left		= m_rtBtnMin.right - btnWidth;
	m_rtBtnMin.bottom	= m_rtBtnExt.bottom;

	//获取窗体DC
	CWindowDC WndDc(this);
	//创建Graphics对象
	Graphics graph(WndDc.m_hDC);

	//绘制边框
	TextureBrush Hbrush(m_bpHBorder); 
	Rect destTRect(0,0,rtWindow.Width(),border);
	graph.FillRectangle(&Hbrush,destTRect);
	Rect destBRect(0,rtWindow.Height()-border,rtWindow.Width(),border);
	graph.FillRectangle(&Hbrush,destBRect);

	TextureBrush Vbrush(m_bpVBorder);
	Rect destLRect(0,0,border,rtWindow.Height());
	graph.FillRectangle(&Vbrush,destLRect);
	Rect destRRect(rtWindow.Width()-border,0,border,rtWindow.Height());
	graph.FillRectangle(&Vbrush,destRRect);


	//绘制标题栏背景	
	graph.DrawImage(m_bpTitleBar,
					border,
					border,
					(int)(rtWindow.Width()-border),
					m_bpTitleBar->GetHeight());
	

	//!ToDo绘制程序图标
	WndDc.DrawIcon(2, 2, m_hIcon);

	//!ToDo绘制标题栏文字
	//设置字体
	FontFamily fontFamily(L"Arial");
	Font font(&fontFamily, 12, FontStyleBold, UnitPixel);
	//设置文字颜色
	SolidBrush solidBrush(Color(58, 58, 60));
	//位置
	PointF pointF(35.0f, 8.0f);
	//绘制文字
	graph.DrawString(m_strTitle,m_strTitle.GetLength(),&font,pointF,&solidBrush);

	//绘制退出按钮
	graph.DrawImage(m_bpBtnExt,m_rtBtnExt.left,m_rtBtnExt.top,m_bpBtnExt->GetWidth(),m_bpBtnExt->GetHeight());
	//绘制最大化/恢复按钮
	if(this->IsZoomed()){
		graph.DrawImage(m_bpBtnRes,m_rtBtnMax.left,m_rtBtnMax.top,m_bpBtnRes->GetWidth(),m_bpBtnRes->GetHeight());
	}else{
		graph.DrawImage(m_bpBtnMax,m_rtBtnMax.left,m_rtBtnMax.top,m_bpBtnMax->GetWidth(),m_bpBtnMax->GetHeight());
	}
	//绘制最小化按钮
	graph.DrawImage(m_bpBtnMin,m_rtBtnMin.left,m_rtBtnMin.top,m_bpBtnMin->GetWidth(),m_bpBtnMin->GetHeight());

}