Ejemplo n.º 1
0
		void draw_image(ImageData* img, const Rect* r)
		{
			if(img->get_image() == NULL) return;
			graphics->DrawImage((Gdiplus::Image*)img->get_image(), TO_RECT(r));
		}
Ejemplo n.º 2
0
void Chart::Draw(Gdiplus::Graphics &graph)
{
	g = &graph;
	graph.FillRectangle(&SolidBrush(Color(0xffaaaaaa)), rect.left, rect.top, rect.right, rect.bottom);
}
Ejemplo n.º 3
0
	void InitTextStyles(Gdiplus::Graphics& gfx, Gdiplus::StringFormat& format, const Style& style)
	{
		gfx.SetTextRenderingHint(AntialiasingFromStyleString(style.Get(L"antialiasing", L"default")));
		format.SetTrimming(StringTrimmingFromStyleString(style.Get(L"trimming", L"default")));
	}
Ejemplo n.º 4
0
void CBtnRoundImg::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
   CDC dc;
   dc.Attach(lpDrawItemStruct->hDC);       //°´Å¥¿Ø¼þDC  

   COLORREF clrBK = RGB(255,255,255);
   switch(m_nCtrlState)  
   {  
   case CTRL_NOFOCUS:  
      clrBK = m_clrBKUnfocus;
      break;  
   case CTRL_FOCUS:  
      clrBK = m_clrBKFocus;
      break;  
   case CTRL_SELECTED:  
      clrBK = m_clrBKSelected;
      break;  
   default:  
      break;  
   }  

   if (IsWindowEnabled()==FALSE)
   {
      clrBK = m_clrBKDisable;
   }

   //draw background
   CRect rect(lpDrawItemStruct->rcItem);
   //dc.FillSolidRect(&rect,clrBK);
   DrawRoundRect(dc, 5,rect,clrBK);

   //draw image
   if (m_strPngPath != _T(""))
   {
      Gdiplus::Image  imageBtn(m_strPngPath);
      if (imageBtn.GetLastStatus() != Ok)
      {
         ASSERT(FALSE);
      }
      ;
      HRGN hRgnOld = (HRGN)::SelectObject(lpDrawItemStruct->hDC, m_hRgnBtn);

      Gdiplus::Graphics * pGrp = Graphics::FromHDC(lpDrawItemStruct->hDC);
      pGrp->Clear(Color::White);

      CRect rectBtn;
      GetClientRect(&rectBtn);
      int startX = (rectBtn.Width() - imageBtn.GetWidth())/2;
      int startY = (rectBtn.Height() - imageBtn.GetHeight())/2;
      startX = 0;
      startY = 0;
      if (lpDrawItemStruct->itemState & ODS_SELECTED)	//Ñ¡ÖÐ״̬£¬Í¼Æ¬Æ«ÒÆÒ»¸öÏñËØ
      {
         pGrp->DrawImage(&imageBtn, startX+1, startY+1, startX+imageBtn.GetWidth(), startY+imageBtn.GetHeight());
      }
      else	//ĬÈÏ״̬
      {
         pGrp->DrawImage(&imageBtn, startX, startY, startX+imageBtn.GetWidth(), startY+imageBtn.GetHeight());
      }

      delete pGrp;
      pGrp = NULL;
      ::SelectObject(lpDrawItemStruct->hDC, hRgnOld);
   }


   CFont* pOldFont;
   if (m_pFont)
   {
      pOldFont = dc.SelectObject(m_pFont); 
   }
   COLORREF clrOld = dc.SetTextColor(m_clrFont);
   CString strText;
   GetWindowText(strText);
   if (strText != _T(""))
   {
      int test = 1;
   }
   int oldMode = dc.SetBkMode(TRANSPARENT);
   dc.DrawText(strText, -1, &lpDrawItemStruct->rcItem, DT_CENTER|DT_SINGLELINE|DT_VCENTER);  
   dc.SetBkMode(oldMode);
   dc.SetTextColor(clrOld);
   if (m_pFont)
   {
      dc.SelectObject(pOldFont);  
   }

   dc.Detach();
}
Ejemplo n.º 5
0
//-----------------------------------------------------------------------------
void GdiplusDrawContext::drawBitmap (CBitmap* cbitmap, const CRect& dest, const CPoint& offset, float alpha)
{
	alpha *= currentState.globalAlpha;
	if (alpha == 0.f || pGraphics == 0)
		return;
	IPlatformBitmap* platformBitmap = cbitmap ? cbitmap->getPlatformBitmap () : 0;
	GdiplusBitmap* gpb = platformBitmap ? dynamic_cast<GdiplusBitmap*> (platformBitmap) : 0;
	Gdiplus::Bitmap* bitmap = gpb ? gpb->getBitmap () : 0;
	if (bitmap)
	{
		GdiplusDrawScope drawScope (pGraphics, currentState.clipRect, getCurrentTransform ());

		Gdiplus::ImageAttributes imageAtt;
		if (alpha != 1.f)
		{
			// introducing the alpha blend matrix
			Gdiplus::ColorMatrix colorMatrix =
			{
				1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
				0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
				0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
				0.0f, 0.0f, 0.0f, alpha, 0.0f,
				0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
			};
			// create the imageattribute modifier
			imageAtt.SetColorMatrix (&colorMatrix, Gdiplus::ColorMatrixFlagsDefault,
				Gdiplus::ColorAdjustTypeBitmap);
#if 1
			Gdiplus::Rect	myDestRect(
				(INT)dest.left,
				(INT)dest.top,
				(INT)dest.getWidth (),
				(INT)dest.getHeight ());
			pGraphics->DrawImage (
				bitmap,
				myDestRect,
				(INT)offset.x,
				(INT)offset.y,
				(INT)dest.getWidth (),
				(INT)dest.getHeight (),
				Gdiplus::UnitPixel,
				&imageAtt);
#else
			// create a temporary bitmap to prevent OutOfMemory errors
			Gdiplus::Bitmap myBitmapBuffer ((INT)dest.getWidth (), (INT)dest.getHeight (),PixelFormat32bppARGB);
			// create a graphics context for the temporary bitmap
			Gdiplus::Graphics* myGraphicsBuffer = Gdiplus::Graphics::FromImage (&myBitmapBuffer);
			// copy the rectangle we want to paint to the temporary bitmap
			Gdiplus::Rect myTransRect(
				0,
				0,
				(INT)dest.getWidth (),
				(INT)dest.getHeight ());
			// transfer the bitmap (without modification by imageattr!)
			myGraphicsBuffer->DrawImage (
				bitmap,myTransRect,
				(INT)offset.x,
				(INT)offset.y,
				(INT)dest.getWidth (),
				(INT)dest.getHeight (),
				Gdiplus::UnitPixel,
				0);
			// now transfer the temporary to the real context at the advised location
			Gdiplus::Rect myDestRect (
				(INT)dest.left,
				(INT)dest.top,
				(INT)dest.getWidth (),
				(INT)dest.getHeight ());
			// transfer from temporary bitmap to real context (with imageattr)
			pGraphics->DrawImage (
				&myBitmapBuffer,
				myDestRect,
				(INT)0,
				(INT)0,
				(INT)dest.getWidth (),
				(INT)dest.getHeight (),
				Gdiplus::UnitPixel,
				&imageAtt);
			// delete the temporary context of the temporary bitmap
			delete myGraphicsBuffer;
#endif
		}
		else
		{
			Gdiplus::Rect	myDestRect(
				(INT)dest.left,
				(INT)dest.top,
				(INT)dest.getWidth (),
				(INT)dest.getHeight ());
			pGraphics->DrawImage (
				bitmap,
				myDestRect,
				(INT)offset.x,
				(INT)offset.y,
				(INT)dest.getWidth (),
				(INT)dest.getHeight (),
				Gdiplus::UnitPixel,
				0);
		}
	}
}
Ejemplo n.º 6
0
void CLine::Draw(Gdiplus::Graphics& graphics)
{
	Pen pen(Color::Red);
	graphics.DrawLine(&pen, _point1, _point2);
}
Ejemplo n.º 7
0
//
//	Draw overlay
//
PLUGIN_EXPORT void PluginUpdateOverlay()
{

    if (!pRenderHelper)
        return;

    // lock overlay image
    auto pLock = pRenderHelper->BeginFrame();
    if (!pLock)
        return;

    int w = pLock->dwWidth;
    int h = pLock->dwHeight;

    Gdiplus::Graphics *pGraphics = pRenderHelper->GetGraphics();

    //-----------------------------------------
    // draw Text Overlay

    // set options
    pGraphics->SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);

    // clear back
    pGraphics->Clear(Gdiplus::Color(0, 0, 0, 0));
    WCHAR s[128];
    _itow_s(PC_GetConfirmedProcessID(), s, 10);

    if (PathFileExists(pFileName)) {
        string textContents = "";
        WIN32_FILE_ATTRIBUTE_DATA       attribs;
        GetFileAttributesExW(pFileName, GetFileExInfoStandard, &attribs);

        FILETIME modifyTime = attribs.ftLastWriteTime;
        if (CompareFileTime(&modifyTime, &oldModifyTime) > 0) {
            oldModifyTime = modifyTime;
            string line;
            ifstream myfile;
            myfile.open(pFileName);
            if (myfile.is_open())
            {
                while (getline(myfile, line))
                {
                    textContents += line;
                }
                myfile.close();
            }
            textLength = textContents.length();
            wcTextContents[textLength] = 0;
            std::copy(textContents.begin(), textContents.end(), wcTextContents);
        }
    }
    // draw back if required
    if (bShowBackground)
    {
        Gdiplus::RectF bound;
        pRenderHelper->GetTextExtent(wcTextContents, pFont, &bound);
        pGraphics->FillRectangle(pBackBrush, bound);
    }

    // draw text

    Gdiplus::RectF bound;
    pRenderHelper->GetTextExtent(wcTextContents, pFont, &bound);

    if (bound.Width > w) {
        wchar_t wcNewTextContents[256];
        wcNewTextContents[textLength * 2 + 5] = 0;
        swprintf_s(wcNewTextContents, L"%s     %s", wcTextContents, wcTextContents);
        Gdiplus::RectF newbound;
        pRenderHelper->GetTextExtent(wcNewTextContents, pFont, &newbound);
        pRenderHelper->DrawString(wcNewTextContents, pFont, Gdiplus::Point(0 - scroll, 0), pTextBrush, pBackBrush);
        scroll += 2;
        if (scroll > newbound.Width - bound.Width)
            scroll = 0;
    }
    else {
        pRenderHelper->DrawString(wcTextContents, pFont, Gdiplus::Point(0, 0), pTextBrush, pBackBrush);
    }
    // fill overlay image
    pRenderHelper->EndFrame();

}
Ejemplo n.º 8
0
void GameManager::Render(Gdiplus::Graphics& canvas, const CRect& clientRect)
{
	////////////////////////////////////////////////////////////////////////////////
	// Begin example code

	// Save the current transformation of the scene
	Gdiplus::Matrix transform;
	canvas.GetTransform(&transform);
	
	// Offset by the negative of the player direction
	canvas.TranslateTransform(-(Gdiplus::REAL)playerPtr->location.X, -(Gdiplus::REAL)playerPtr->location.Y);
	
	int numRows = clientRect.Height() / CellSize;
	int numCols = clientRect.Width() / CellSize;

	// draw horizontal lines for grid
	for (int row = 0; row < numRows; ++row)
	{
		Vector2i start = Vector2i(0, row * CellSize);
		Vector2i end = Vector2i(clientRect.Width(), row * CellSize);
		GameFrameworkInstance.DrawLine(canvas,
			start,
			end,
			Gdiplus::Color::White);
	}

	// draw vertical lines for grid
	for (int col = 0; col < numCols; ++col)
	{
		Vector2i start = Vector2i(col * CellSize, 0);
		Vector2i end = Vector2i(col * CellSize, clientRect.Height());
		GameFrameworkInstance.DrawLine(canvas,
			start,
			end,
			Gdiplus::Color::White);
	}

	// Draw all of the objects
	for (GameObject* objectPtr : gameObjects)
	{
		objectPtr->Render(canvas);
	}

	// Render method demonstration (You can remove all of this code)
	GameFrameworkInstance.DrawLine(canvas, Vector2i(200, 200), Vector2i(400, 200), Gdiplus::Color::White);

	GameFrameworkInstance.DrawRectangle(canvas, AABBi(Vector2i(10, 110), Vector2i(100, 200)), false, Gdiplus::Color::White);
	GameFrameworkInstance.DrawRectangle(canvas, AABBi(Vector2i(200, 110), Vector2i(300, 200)), true, Gdiplus::Color::White);

	//// restore the transform
	//canvas.SetTransform(&transform);

	GameFrameworkInstance.DrawCircle(canvas, Vector2i(200, 200), 50, false, Gdiplus::Color::White);
	GameFrameworkInstance.DrawCircle(canvas, Vector2i(400, 200), 50, true, Gdiplus::Color::White);

	GameFrameworkInstance.DrawText(canvas, Vector2i(10, 300), 12, "Arial", "Hello World!", Gdiplus::Color::White);

	// Load the image file Untitled.png from the Images folder. Give it the unique name of Image1
	ImageWrapper* image1 = GameFrameworkInstance.GetLoadedImage(Image1);
	GameFrameworkInstance.DrawImage(canvas, Vector2i(400, 400), image1);

	// Restore the transformation of the scene
	canvas.SetTransform(&transform);

	// End example code
	////////////////////////////////////////////////////////////////////////////////

	// Build Menu
	Vector2i dimensions = GameManagerInstance.GetScreenDimensions();
	Vector2i centrePoint = dimensions * 0.1f;
	GameFrameworkInstance.DrawRectangle(canvas,
		AABBi(Vector2i(0, 0) + centrePoint,
			Vector2i(150, 500) + centrePoint),
		true, Gdiplus::Color::Gray);
	GameFrameworkInstance.DrawText(canvas, Vector2i(10, 10) + centrePoint, 12, "Arial", "[1] Wall", Gdiplus::Color::White);
	GameFrameworkInstance.DrawText(canvas, Vector2i(10, 35) + centrePoint, 12, "Arial", "[2] Damage Zone", Gdiplus::Color::White);
	GameFrameworkInstance.DrawText(canvas, Vector2i(10, 60) + centrePoint, 12, "Arial", "[3] Healing Zone", Gdiplus::Color::White);
}
 GdiplusGfx(HDC dc) {
     g = Gdiplus::Graphics::FromHDC(dc);
     InitGraphicsMode(g);
     PixelOffsetMode pm = g->GetPixelOffsetMode();
     plogf("pm = %d", (int)pm);
 }
Ejemplo n.º 10
0
		void draw_rect(const Rect* r)
		{
			Gdiplus::Pen* pen = new Gdiplus::Pen(*color, (Gdiplus::REAL)width);
			graphics->DrawRectangle(pen, (Gdiplus::REAL)r->x, (Gdiplus::REAL)r->y, (Gdiplus::REAL)r->w, (Gdiplus::REAL)r->h);
			delete pen;
		}
Ejemplo n.º 11
0
		void fill_ellipse(ft x, ft y, ft w, ft h)
		{
			Gdiplus::SolidBrush* brush = new Gdiplus::SolidBrush(*color);
			graphics->FillEllipse(brush, Gdiplus::Rect((st)x, (st)y, (st)w, (st)h));
			delete brush;
		}
Ejemplo n.º 12
0
		virtual void fill_rect(ft x, ft y, ft w, ft h)
		{
			Gdiplus::SolidBrush* brush = new Gdiplus::SolidBrush(*color);
			graphics->FillRectangle(brush, Gdiplus::Rect((st)x, (st)y, (st)w, (st)h));
			delete brush;
		}
Ejemplo n.º 13
0
		void draw_line(Point* p1, Point* p2)
		{
			Gdiplus::Pen* pen = new Gdiplus::Pen(*color, (Gdiplus::REAL)width);
			graphics->DrawLine(pen, TO_POINT(p1), TO_POINT(p2));
			delete pen;
		}
Ejemplo n.º 14
0
		void fill_gradient_rect(const Rect* r, const Color* c1, const Color* c2, const Point* p1, const Point* p2)
		{ 
			Gdiplus::LinearGradientBrush* brush = new Gdiplus::LinearGradientBrush(TO_POINT(p1), TO_POINT(p2), TO_COLOR(c1), TO_COLOR(c2));
			graphics->FillRectangle(brush, TO_RECT(r));
			delete brush;
		}
Ejemplo n.º 15
0
void CSkyODL::OnDrawTop(Gdiplus::Graphics& gcDrawer, float fScale)
{
	CBaseODL::OnDrawTop(gcDrawer, fScale);
	
	Gdiplus::Pen Dot( m_clDotColor, static_cast<Gdiplus::REAL>(1.0 / fScale));
	CArray<Gdiplus::Point> st;
	CArray<Gdiplus::Point> stMoving;
	CArray<BYTE> stBytes;

	for (auto& curItem : m_arrTopPoint)
	{
		Gdiplus::Point pt;
		pt.X = static_cast<INT>(curItem.X());
		pt.Y = static_cast<INT>(curItem.Z());
		st.Add(pt);
	}
	if (IsTopMoving())
	{
		for ( auto& curMoving : m_arrMovingTopPoint )
		{
			Gdiplus::Point pt;
			pt.X = static_cast<INT>(curMoving.X());
			pt.Y = static_cast<INT>(curMoving.Z());
			stMoving.Add(pt);
		}
	}
	if(st.GetSize()<=0)
	{
		return;
	}
	for (int i=0; i<st.GetSize(); ++i)
	{
		st[i].X = static_cast<INT>(st[i].X);
		st[i].Y = static_cast<INT>(st[i].Y);
	}
	for (int i=0; i<stMoving.GetSize(); ++i)
	{
		stMoving[i].X = static_cast<INT>(stMoving[i].X);
		stMoving[i].Y = static_cast<INT>(stMoving[i].Y);
	}
	Gdiplus::Pen pen( m_clPenColor, static_cast<Gdiplus::REAL>(1.0 / fScale));
	pen.SetDashStyle(Gdiplus::DashStyleSolid);

	if (!IsTopCreating())
	{
		Gdiplus::HatchBrush brush( Gdiplus::HatchStyle(Gdiplus::HatchStyle::HatchStyleCross ), m_clPenColor, Gdiplus::Color(0,255,255,255) );
		//画皮肤
		gcDrawer.FillPolygon(&brush, st.GetData(), st.GetSize(), Gdiplus::FillMode::FillModeAlternate);
	}

	gcDrawer.DrawLines(&pen, st.GetData(), st.GetSize());

	if (IsTopMoving())
	{
		Gdiplus::Pen penMoving( m_clDotColor, static_cast<Gdiplus::REAL>(1.0 / fScale));
		penMoving.SetDashStyle( Gdiplus::DashStyleSolid);
		gcDrawer.DrawLines(&penMoving, stMoving.GetData(), stMoving.GetSize());
	}
	if (IsTopSelected())
	{
		//每个转角画一个点
		for (int x=0; x<st.GetSize(); x++)
		{
			gcDrawer.DrawRectangle(&Dot, (st[x].X) - 3.0f/fScale, (st[x].Y ) - 3.0f/fScale, 6.0f/fScale, 6.0f/fScale);
		}
	}
}
Ejemplo n.º 16
0
void CStartupView::DrawBackground(Gdiplus::Graphics &graphics)
{
   CSize siTotal = GetTotalSize();
   CRect rcClient(0, 0, siTotal.cx, siTotal.cy);
   CRect rc;
   GetClientRect(&rc);

  /* int iLeft = 6;
   int iRight = 13;
   int iMiddle = rcClient.Width() - iLeft - iRight;*/
   Gdiplus::Rect gdipRcClient(rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height());
   Gdiplus::SolidBrush bgBrush(Gdiplus::Color(255, 238, 238, 238));
   graphics.FillRectangle(&bgBrush, gdipRcClient);

   Gdiplus::REAL offsetY = (Gdiplus::REAL)OFFSET_Y;
   Gdiplus::REAL y = offsetY;
   float fHeight = (Gdiplus::REAL)TOP_HEIGHT;
   Gdiplus::RectF gdipRcLeft;
   Gdiplus::RectF gdipRcMiddle;
   Gdiplus::RectF gdipRcRight;

   
   CalculateBkgRects(gdipRcLeft, gdipRcMiddle, gdipRcRight, y, fHeight);

   
   graphics.DrawImage(m_pBmpTopLeft, gdipRcLeft);
   graphics.DrawImage(m_pBmpTopMiddle, gdipRcMiddle, 0.0, 0.0, 1.0, (Gdiplus::REAL)fHeight, Gdiplus::UnitPixel);
   graphics.DrawImage(m_pBmpTopRight, gdipRcRight);

   fHeight = (Gdiplus::REAL)BLUE_HEIGHT;
   CalculateBkgRects(gdipRcLeft, gdipRcMiddle, gdipRcRight, y, fHeight);
   graphics.DrawImage(m_pBmpBlueLeft, gdipRcLeft);
   graphics.DrawImage(m_pBmpBlueMiddle, gdipRcMiddle, 0.0, 0.0, 1.0, (Gdiplus::REAL)fHeight, Gdiplus::UnitPixel);
   graphics.DrawImage(m_pBmpBlueRight, gdipRcRight);

   fHeight =(Gdiplus::REAL)( rcClient.Height()  - OFFSET_Y  - TOP_HEIGHT - BLUE_HEIGHT - LIGHT_BLUE_HEIGHT - FOOT_HEIGHT); 
   CalculateBkgRects(gdipRcLeft, gdipRcMiddle, gdipRcRight, y, fHeight);
   graphics.DrawImage(m_pBmpWhiteLeft, gdipRcLeft/*, 0.0, 0.0, 1.0, (Gdiplus::REAL)296, Gdiplus::UnitPixel*/);
   graphics.DrawImage(m_pBmpWhiteMiddle, gdipRcMiddle, 0.0, 0.0, 1.0, (Gdiplus::REAL)296, Gdiplus::UnitPixel);
   graphics.DrawImage(m_pBmpWhiteRight, gdipRcRight/*, 0.0, 0.0, 1.0, (Gdiplus::REAL)296, Gdiplus::UnitPixel*/);

   fHeight = (Gdiplus::REAL)LIGHT_BLUE_HEIGHT;
   y--;
   CalculateBkgRects(gdipRcLeft, gdipRcMiddle, gdipRcRight, y , fHeight);
   graphics.DrawImage(m_pBmpLightBlueLeft, gdipRcLeft);
   graphics.DrawImage(m_pBmpLightBlueMiddle, gdipRcMiddle, 0.0, 0.0, 1.0, (Gdiplus::REAL)fHeight, Gdiplus::UnitPixel);
   graphics.DrawImage(m_pBmpLightBlueRight, gdipRcRight);

   fHeight = (Gdiplus::REAL)FOOT_HEIGHT;
   CalculateBkgRects(gdipRcLeft, gdipRcMiddle, gdipRcRight, y, fHeight);
   graphics.DrawImage(m_pBmpFootLeft, gdipRcLeft);
   graphics.DrawImage(m_pBmpFootMiddle, gdipRcMiddle, 0.0, 0.0, 1.0, (Gdiplus::REAL)fHeight, Gdiplus::UnitPixel);
   graphics.DrawImage(m_pBmpFootRight, gdipRcRight);

   Gdiplus::Color colorFrom[] = {Gdiplus::Color(255, 220, 223, 224),
      Gdiplus::Color(255, 215, 215, 215),
      Gdiplus::Color(255, 216, 216, 216),
      Gdiplus::Color(255, 219, 219, 219),
      Gdiplus::Color(255, 223, 223, 223),
      Gdiplus::Color(255, 226, 226, 226),
      Gdiplus::Color(255, 229, 229, 229),
      Gdiplus::Color(255, 231, 231, 231),
   };
   Gdiplus::Color colorTo[] = {Gdiplus::Color(255, 198, 199, 201),
      Gdiplus::Color(255, 185, 185, 185),
      Gdiplus::Color(255, 190, 190, 190),
      Gdiplus::Color(255, 197, 197, 197),
      Gdiplus::Color(255, 203, 203, 203),
      Gdiplus::Color(255, 213, 213, 213),
      Gdiplus::Color(255, 218, 218, 218),
      Gdiplus::Color(255, 226, 226, 226),
   };
   Gdiplus::RectF gdipRcM2;
   for(int i = 0; i < 8; i++)
   {
      gdipRcM2.X = gdipRcMiddle.X + gdipRcMiddle.Width - 30.0;
      gdipRcM2.Y = gdipRcMiddle.Y + gdipRcMiddle.Height - 8 + i;
      gdipRcM2.Width = 30.0;
      gdipRcM2.Height = 1.0;

      Gdiplus::LinearGradientBrush gradientBrush(gdipRcM2, 
      colorFrom[i], 
      colorTo[i], 
      Gdiplus::LinearGradientModeHorizontal);
      graphics.FillRectangle(&gradientBrush, gdipRcM2);
   }
}
Ejemplo n.º 17
0
void TrackListCtrl::DrawItem(Gdiplus::Graphics& g, INT nItem, Gdiplus::Rect& itemRC)
{
	HDC hdc = g.GetHDC();
	if (hdc == 0)
	{
		TRACE(_T("@1 TrackListCtrl::DrawItem. Cant get HDC\r\n"));
		return;		
	}
	CDC* pDC = CDC::FromHandle(hdc);
	PrgAPI* pAPI = PRGAPI();
	//Calculate Colors
	BOOL bSelected = IsItemSelected(nItem);
	COLORREF clrText = m_colors[COL_Text];
	COLORREF clrBk = m_colors[COL_Bk];
	if (bSelected)
	{
		clrText =  m_colors[COL_TextSel];
		clrBk = m_colors[COL_TextSelBk];
	}

	CRect rcSubItem(itemRC.X, itemRC.Y, itemRC.GetRight(), itemRC.GetBottom());
	pDC->SetTextColor(clrText);
	pDC->FillSolidRect(rcSubItem, clrBk);

	const INT cMargin = 2;

	FullTrackRecordSP& rec = (*m_pCollection)[nItem];

	pDC->SetBkMode(TRANSPARENT);

	INT curx = cMargin;


	CRect rcFirstLine(rcSubItem);
	rcFirstLine.bottom = rcFirstLine.top + 20;
	rcFirstLine.left = cMargin;
	rcFirstLine.right -= cMargin;
	CRect rcSecondLine(rcSubItem);
	rcSecondLine.top = rcFirstLine.bottom;
	rcSecondLine.left = cMargin;
	rcSecondLine.right -= cMargin;


	if (m_bDrawPictures)
	{
		INT imgHeight = 32;//rcSubItem.Height() - 2 * cMargin;
		INT cury = rcSubItem.top + cMargin;
		LocalPictureManager* pLM = PRGAPI()->GetLocalPictureManager();
		Gdiplus::Rect rcImage(curx, cury, imgHeight, imgHeight);
		Graphics g2(hdc);
		BOOL bRet = pLM->DrawAlbumThumbnail(rec->artist.name.c_str(), rec->album.name.c_str(), g2, rcImage);
		if (!bRet)
			bRet = pLM->DrawArtistThumbnail(rec->artist.name.c_str(), g2, rcImage);
		if (!bRet)
			bRet = pLM->DrawDefaultThumbnail(IIT_AlbumPicture, g2, rcImage);

		curx += 32 + cMargin ;

	}

	rcSecondLine.left = curx;
	//=== Draw the icon
	INT cury = rcFirstLine.top + (rcFirstLine.Height() - 16) / 2;
	pDC->SetTextColor(clrText);
	DrawIconEx(pDC->m_hDC, curx, cury, pAPI->GetIconForTrackType(rec->track.trackType), 16, 16, 0, 0, DI_NORMAL);
	curx += 16 + cMargin;


	//=== Draw the title
	CRect rcTitle(rcFirstLine);
	rcTitle.left = curx;
	CFont* pOldFont = pDC->SelectObject(m_pBoldFont);
	pDC->DrawText(rec->track.name.c_str(), rec->track.name.size(), &rcTitle, DT_END_ELLIPSIS | DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);
	pDC->DrawText(rec->track.name.c_str(), rec->track.name.size(), &rcTitle, DT_END_ELLIPSIS | DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX | DT_CALCRECT);

	//=== Draw the artist
	CRect rcArtist(rcFirstLine);
	rcArtist.left = rcTitle.right + cMargin;
	pDC->DrawText(rec->artist.name.c_str(), rec->artist.name.size(), &rcArtist, DT_END_ELLIPSIS | DT_RIGHT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);

	pDC->SelectObject(m_pNormalFont);

	//=== Next line
	//=== Draw the rating (if exists)
	if (rec->track.rating > 0 && rec->track.rating < 256)
	{
		FLOAT fStars = Rating2Stars(rec->track.rating);
		if (fStars > 0.0f && fStars <=1.0f)
		{
			DrawIconEx(hdc, rcSecondLine.left, rcSecondLine.top, pAPI->GetIcon(ICO_StarBad16), 16, 16, 0, 0, DI_NORMAL);
			rcSecondLine.left += 17;
		}
		while (fStars > 1.0f)
		{
			DrawIconEx(hdc, rcSecondLine.left, rcSecondLine.top, pAPI->GetIcon(ICO_StarGold16), 16, 16, 0, 0, DI_NORMAL);
			fStars -= 1.0f;
			rcSecondLine.left += 17;
		}
	}

	TCHAR time[500];
	UINT len = _sntprintf(time, 500, _T("%d:%02d | %s: %s | %s: %s"), 
		INT (rec->track.duration / 60), INT(rec->track.duration) % 60,
		pAPI->GetString(IDS_ALBUM), rec->album.name.c_str(),
		pAPI->GetString(IDS_LOCATION), rec->track.location.c_str()
		);
	pDC->DrawText(time, len, &rcSecondLine, DT_END_ELLIPSIS | DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);

	pDC->SelectObject(pOldFont);

	g.ReleaseHDC(pDC->m_hDC);
}
Ejemplo n.º 18
0
Surface	TextLayout::render( bool useAlpha, bool premultiplied )
{
	Surface result;
	
	// determine the extents for all the lines and the result surface
	float totalHeight = 0, maxWidth = 0;
	for( deque<shared_ptr<Line> >::iterator lineIt = mLines.begin(); lineIt != mLines.end(); ++lineIt ) {
		(*lineIt)->calcExtents();
		totalHeight = std::max( totalHeight, totalHeight + (*lineIt)->mHeight + (*lineIt)->mLeadingOffset );
		if( (*lineIt)->mWidth > maxWidth )
			maxWidth = (*lineIt)->mWidth;
	}
	// for the last line, instead of using the font info, we'll use the true height
/*	if( ! mLines.empty() ) {
		totalHeight = currentY - (mLines.back()->mAscent - mLines.back()->mDescent - mLines.back()->mLeadingOffset - mLines.back()->mLeading );
		totalHeight += mLines.back()->mHeight;
	}*/

	// round up from the floating point sizes to get the number of pixels we'll need
	int pixelWidth = (int)math<float>::ceil( maxWidth ) + mHorizontalBorder * 2;
	int pixelHeight = (int)math<float>::ceil( totalHeight ) + mVerticalBorder * 2;

	// Odd failure - return a NULL Surface
	if( ( pixelWidth < 0 ) || ( pixelHeight < 0 ) )
		return Surface();

	// allocate the surface based on our collective extents
#if defined( CINDER_MAC )
	result = Surface( pixelWidth, pixelHeight, useAlpha, (useAlpha)?SurfaceChannelOrder::RGBA:SurfaceChannelOrder::RGBX );
	CGContextRef cgContext = cocoa::createCgBitmapContext( result );
	ip::fill( &result, mBackgroundColor.premultiplied() );

	float currentY = totalHeight + 1.0f + mVerticalBorder;
	for( deque<shared_ptr<Line> >::iterator lineIt = mLines.begin(); lineIt != mLines.end(); ++lineIt ) {
		// these are negated from Cinder's normal pixel coordinate system
		currentY -= (*lineIt)->mAscent + (*lineIt)->mLeadingOffset;
		(*lineIt)->render( cgContext, currentY, (float)mHorizontalBorder, pixelWidth );
		currentY -= (*lineIt)->mDescent + (*lineIt)->mLeading;
	}

	// force all the rendering to finish and release the context
	CGContextFlush( cgContext );
	CGContextRelease( cgContext );

	// since CGContextBitmaps are always premultiplied, if the caller didn't want that we'll have to undo it
	if( ! premultiplied )
		ip::unpremultiply( &result );
#elif defined( CINDER_MSW )
	// I don't have a great explanation for this other than it seems to be necessary
	pixelHeight += 1;
	// prep our GDI and GDI+ resources
	HDC dc = TextManager::instance()->getDc();
	result = Surface8u( pixelWidth, pixelHeight, useAlpha, SurfaceConstraintsGdiPlus() );
	Gdiplus::Bitmap *offscreenBitmap = msw::createGdiplusBitmap( result, premultiplied );
	//Gdiplus::Bitmap *offscreenBitmap = new Gdiplus::Bitmap( pixelWidth, pixelHeight, (premultiplied) ? PixelFormat32bppPARGB : PixelFormat32bppARGB );
	Gdiplus::Graphics *offscreenGraphics = Gdiplus::Graphics::FromImage( offscreenBitmap );
	// high quality text rendering
	offscreenGraphics->SetTextRenderingHint( Gdiplus::TextRenderingHintAntiAlias );
	// fill the surface with the background color
	offscreenGraphics->Clear( Gdiplus::Color( (BYTE)(mBackgroundColor.a * 255), (BYTE)(mBackgroundColor.r * 255), 
			(BYTE)(mBackgroundColor.g * 255), (BYTE)(mBackgroundColor.b * 255) ) );

	// walk the lines and render them, advancing our Y offset along the way
	float currentY = (float)mVerticalBorder;
	for( deque<shared_ptr<Line> >::iterator lineIt = mLines.begin(); lineIt != mLines.end(); ++lineIt ) {
		//currentY += (*lineIt)->mLeadingOffset + (*lineIt)->mAscent;
		currentY += (*lineIt)->mLeadingOffset + (*lineIt)->mLeading;
		(*lineIt)->render( offscreenGraphics, currentY, (float)mHorizontalBorder, (float)pixelWidth );
		//currentY += (*lineIt)->mDescent + (*lineIt)->mLeading;
		currentY += (*lineIt)->mAscent + (*lineIt)->mDescent;
	}

	GdiFlush();

	delete offscreenBitmap;
	delete offscreenGraphics;		
#endif

	return result;
}
void CTabsControl::DrawItem(CTabControl *item, Gdiplus::Graphics &g)
{
	CRect rect = ItemRect(item);

	g.ResetTransform();
	g.TranslateTransform((REAL)rect.left, (REAL)rect.top);

	RectF rf(0.0f, 0.0f, (REAL)rect.Width(), (REAL)rect.Height());
	RectF rx;

	if(item->selected)
	{
		#define shadowb 10

		CDIB tmp;
		tmp.Resize(rect.Width() + shadowb * 2, rect.Height() + shadowb * 2);
		if(tmp.Ready())
		{
			Graphics gt(tmp.bmp);
			RectF rx(0, 0, (REAL)tmp.Width(), (REAL)tmp.Height());
			
			GraphicsPath *path = new GraphicsPath();
			path->AddLine(rx.X + shadowb, rx.Y + rx.Height - shadowb, rx.X + rx.Width - 2 - shadowb, rx.Y + rx.Height - shadowb);
			path->AddLine(rx.X + rx.Width - 2 - shadowb, rx.Y + rx.Height - shadowb, rx.X + rx.Width - 2, rx.Y);
			path->AddLine(rx.X + rx.Width - 2, rx.Y, rx.X + rx.Width, rx.Y + rx.Height);
			path->AddLine(rx.X + rx.Width, rx.Y + rx.Height, rx.X, rx.Y + rx.Height);
			path->AddLine(rx.X, rx.Y, rx.X + shadowb, rx.Y + rx.Height - shadowb);
			path->CloseFigure();

			SolidBrush brush(0xff000000);
			gt.FillPath(&brush, path);

			tmp.Blur(tmp.Rect(), CRect(0, 0, 0, 0), shadowb);

			g.DrawImage(tmp.bmp, rf, shadowb, shadowb, rf.Width, rf.Height, UnitPixel);

			delete path;
		}
	}

	Font font(L"Arial", item->selected ? 8.0f : 8.0f);
	StringFormat *stringFormat = new StringFormat();
	stringFormat->SetAlignment(StringAlignmentCenter);
	stringFormat->SetLineAlignment(StringAlignmentCenter);
	stringFormat->SetTrimming(StringTrimmingEllipsisCharacter);
	stringFormat->SetFormatFlags(StringFormatFlagsLineLimit);

	if(item->icon->Ready())
	{
		g.SetInterpolationMode(InterpolationModeBicubic);
		rx = rf;
		rx.Y += 6;
		rx.Height -= (20 + rx.Y);
		rx.Width = rx.Height;
		rx.X += (rf.Width - rx.Width) / 2;

		if(item->selected)
		{
			rx.Y++;

			#define shadow 5
			CDIB tmp;
			tmp.Resize(item->icon->Width(), item->icon->Height());
			if(tmp.Ready())
			{
				tmp.Draw(CRect(shadow, shadow, 
					item->icon->Width() - shadow, 
					item->icon->Height() - shadow), 
					item->icon->Rect(), item->icon);
				DIB_ARGB *p = tmp.scan0;
				int size = tmp.Width() * tmp.Height();
				for(int i = 0; i < size; i++, p++)
				{
					p->r = 0;
					p->g = 0;
					p->b = 0;
				}
				tmp.Blur(tmp.Rect(), CRect(0, 0, 0, 0), shadow);
				g.DrawImage(tmp.bmp, RectF(rx.X, rx.Y + shadow, rx.Width, rx.Height));
			}
			tmp.Assign(item->icon);
			/*if(tmp.Ready())
			{
				DIB_ARGB *p = tmp.scan0;
				int size = tmp.Width() * tmp.Height();
				for(int i = 0; i < size; i++, p++)
				{
					p->r = 0x6f;
					p->g = 0xa6;
					p->b = 0xde;
				} 
			}*/
			g.DrawImage(tmp.bmp, rx);
		}
		else
		{
			g.DrawImage(item->icon->bmp, rx);
		}
	}

	SolidBrush brush(0xff000000);
	rx = rf;
	rx.Height = 20;
	rx.Y = rf.Height - rx.Height;

	rx.Y++;
	g.DrawString(item->text.GetBuffer(), item->text.GetLength(), &font, rx, stringFormat, &brush);

	brush.SetColor(item->selected && false ? 0xff6fa6de : 0xfff0f0f0);
	rx.Y--;
	g.DrawString(item->text.GetBuffer(), item->text.GetLength(), &font, rx, stringFormat, &brush);

	delete stringFormat;

	//POSITION p = items.Find(item);
	//items.GetNext(p);
	//if(p)
	{
		RectF rx = rf;
		rx.X += rx.Width - 1;
		rx.Width = 1;
		LinearGradientBrush brush(rx, Color(140, 0x69, 0x69, 0x69), Color(0x69, 0x69, 0x69), LinearGradientModeVertical);
		g.FillRectangle(&brush, rx);
	}
}
Ejemplo n.º 20
0
Surface renderString( const std::string &str, const Font &font, const ColorA &color, float *baselineOffset )
{
	Line line;
	line.addRun( Run( str, font, color ) );
	line.mJustification = Line::LEFT;
	line.mLeadingOffset = 0;	
	line.calcExtents();

	float totalWidth = line.mWidth;
	float totalHeight = line.mHeight;
	int pixelWidth = (int)math<float>::ceil( totalWidth );
	int pixelHeight = (int)math<float>::ceil( totalHeight );

	// Odd failure - return a NULL Surface
	if( ( pixelWidth < 0 ) || ( pixelHeight < 0 ) )
		return Surface();

#if defined( CINDER_MAC )
	Surface result( pixelWidth, pixelHeight, true, SurfaceChannelOrder::RGBA );
	CGContextRef cgContext = cocoa::createCgBitmapContext( result );
	ip::fill( &result, ColorA( 0, 0, 0, 0 ) );

	float currentY = totalHeight + 1.0f;
	currentY -= line.mAscent + line.mLeadingOffset;
	line.render( cgContext, currentY, (float)0, pixelWidth );

	// force all the rendering to finish and release the context
	::CGContextFlush( cgContext );
	::CGContextRelease( cgContext );

	ip::unpremultiply( &result );
#elif defined( CINDER_MSW )
	// I don't have a great explanation for this other than it seems to be necessary
	pixelHeight += 1;
	// prep our GDI and GDI+ resources
	::HDC dc = TextManager::instance()->getDc();
	Surface result( pixelWidth, pixelHeight, true, SurfaceConstraintsGdiPlus() );
	Gdiplus::Bitmap *offscreenBitmap = msw::createGdiplusBitmap( result, false );
	//Gdiplus::Bitmap *offscreenBitmap = new Gdiplus::Bitmap( pixelWidth, pixelHeight, (premultiplied) ? PixelFormat32bppPARGB : PixelFormat32bppARGB );
	Gdiplus::Graphics *offscreenGraphics = Gdiplus::Graphics::FromImage( offscreenBitmap );
	// high quality text rendering
	offscreenGraphics->SetTextRenderingHint( Gdiplus::TextRenderingHintAntiAlias );
	// fill the surface with the background color
	offscreenGraphics->Clear( Gdiplus::Color( (BYTE)(0), (BYTE)(0), 
			(BYTE)(0), (BYTE)(0) ) );

	// walk the lines and render them, advancing our Y offset along the way
	float currentY = 0;
	currentY += line.mLeadingOffset + line.mLeading;
	line.render( offscreenGraphics, currentY, (float)0, (float)pixelWidth );

	::GdiFlush();

	delete offscreenBitmap;
	delete offscreenGraphics;
#elif defined( CINDER_LINUX )
	Surface result( pixelWidth, pixelHeight, true, SurfaceChannelOrder::RGBA );
#endif	

	if( baselineOffset )
		*baselineOffset = line.mDescent;

	return result;
}
//
//	Draw overlay 
//
PLUGIN_EXPORT void PluginUpdateOverlay()
{
	if (!pRenderHelper)
		return;

	//SAFE_DELETE(pFPSNormalBrush);
	//pFPSNormalBrush = new Gdiplus::SolidBrush(Gdiplus::Color(255, 255, 255, 255));
	if (bFirstAttach) {
		bFirstAttach = false;
		PC_StartRecording();
		PC_DebugPrint(L"Triggered");
	}
	else {
		PC_DebugPrint(L"Not Triggered");
	}
	// lock overlay image
	auto pLock = pRenderHelper->BeginFrame();
	if (!pLock)
		return;

	int w = pLock->dwWidth;
	int h = pLock->dwHeight;

	Gdiplus::Graphics *pGraphics = pRenderHelper->GetGraphics();

	//-----------------------------------------
	// draw FPS counter

	// set options
	//pGraphics->SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);

	// clear back
	pGraphics->Clear(Gdiplus::Color(0, 0, 0, 0));




	// draw fps
	{
		Gdiplus::RectF bound;
		//bound.
		int circleSize = 0;
		if (w < h) {
			circleSize = w;
		}
		else {
			circleSize = h;
		}
		if (PC_IsRecording()) {
			pGraphics->FillEllipse(pFPSRecordBrush, 0, 0, circleSize, circleSize);
		}
		else if (bShowWhenNotRecording) {
			pGraphics->FillEllipse(pFPSNormalBrush, 0, 0, circleSize, circleSize);
		}
	}


	//	graphics.Flush(FlushIntentionSync);

	// fill overlay image
	pRenderHelper->EndFrame();
}
Ejemplo n.º 22
0
// overload the pure virtual draw() from base class
void MyLine::draw(Gdiplus::Graphics& graphics) {
	graphics.DrawLine(m_Pen.get(), m_StartPoint.X, m_StartPoint.Y, m_EndPoint.X, m_EndPoint.Y);
}
Ejemplo n.º 23
0
void CSkinButton2::DrawFrame(Gdiplus::Graphics& gdi,CRect& rect)
{
	if( m_enmuDrawType == NO_FRAME )
	{
		Gdiplus::Pen pen1( m_colFrame1 );
		gdi.DrawLine( &pen1, rect.left+1, rect.top, rect.right-2, rect.top );
		gdi.DrawLine( &pen1, rect.left+1, rect.bottom-1, rect.right-2, rect.bottom-1 );
		gdi.DrawLine( &pen1, rect.left, rect.top+1, rect.left, rect.bottom-2 );
		gdi.DrawLine( &pen1, rect.right-1, rect.top+1, rect.right-1, rect.bottom-2 );

		Gdiplus::Color colpix;
		pen1.GetColor( &colpix );
		colpix.SetValue( Gdiplus::Color::MakeARGB(colpix.GetA()/2,colpix.GetR(),colpix.GetG(),colpix.GetB() ) );
		Gdiplus::Pen penPix1( colpix );
		gdi.DrawLine( &penPix1, rect.left, rect.top, rect.left+1, rect.top );
		gdi.DrawLine( &penPix1, rect.right-1, rect.top, rect.right-1, rect.top+1 );
		gdi.DrawLine( &penPix1, rect.right-1, rect.bottom-1, rect.right-2, rect.bottom-1 );
		gdi.DrawLine( &penPix1, rect.left,  rect.bottom-1, rect.left+1,  rect.bottom-1 );

		CRect rect2 = rect;
		::InflateRect( &rect2, -1,-1 );
		if( !m_bMouseDown )
		{
			Gdiplus::Pen pen2(m_colFrame2);
			if( m_bMouseDown )
				pen2.SetColor(m_colFrame1);
			else
				pen2.SetColor(m_colFrame2);

			gdi.DrawLine( &pen2, rect2.left+1, rect2.top, rect2.right-2, rect2.top );
			gdi.DrawLine( &pen2, rect2.left+1, rect2.bottom-1, rect2.right-2, rect2.bottom-1 );
			gdi.DrawLine( &pen2, rect2.left, rect2.top+1, rect2.left, rect2.bottom-2 );
			gdi.DrawLine( &pen2, rect2.right-1, rect2.top+1, rect2.right-1, rect2.bottom-2 );

			Gdiplus::Color colpix2;
			pen2.GetColor( &colpix2 );
			colpix2.SetValue( Gdiplus::Color::MakeARGB(colpix2.GetA()/2,colpix2.GetR(),colpix2.GetG(),colpix2.GetB() ) );
			Gdiplus::Pen penPix2( colpix2 );
			gdi.DrawLine( &penPix2, rect2.left, rect2.top, rect2.left+1, rect2.top );
			gdi.DrawLine( &penPix2, rect2.right-1, rect2.top, rect2.right-1, rect2.top+1 );
			gdi.DrawLine( &penPix2, rect2.right-1, rect2.bottom-1, rect2.right-2, rect2.bottom-1 );
			gdi.DrawLine( &penPix2, rect2.left,  rect2.bottom-1, rect2.left+1,  rect2.bottom-1 );
		}

		if( m_bMouseDown )
		{
			Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/3 );
			Gdiplus::Color colBrush1,colBrush2;
			colBrush1.SetValue( Gdiplus::Color::MakeARGB(15,1,1,1)  );
			colBrush2.SetValue( Gdiplus::Color::MakeARGB(0,1,1,1)  );

			LinearGradientBrush brush( rc, colBrush1, colBrush2,LinearGradientModeVertical );
			gdi.FillRectangle( &brush, rc );
		}
		else
		{
			Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/2 );
			rc.Inflate(-1,-1);
			LinearGradientBrush brush( rc, m_colBrush1, m_colBrush2,LinearGradientModeVertical );
			gdi.FillRectangle( &brush, rc );
		}

		return;
	}
	else if( m_enmuDrawType == NO_FRAME_SELECT )
	{
		Gdiplus::Pen pen1( m_colFrame1 );
		gdi.DrawLine( &pen1, rect.left+1, rect.top, rect.right-2, rect.top );
		gdi.DrawLine( &pen1, rect.left+1, rect.bottom-1, rect.right-2, rect.bottom-1 );
		gdi.DrawLine( &pen1, rect.left, rect.top+1, rect.left, rect.bottom-2 );
		gdi.DrawLine( &pen1, rect.right-1, rect.top+1, rect.right-1, rect.bottom-2 );

		Gdiplus::Color colpix;
		pen1.GetColor( &colpix );
		colpix.SetValue( Gdiplus::Color::MakeARGB(colpix.GetA()/2,colpix.GetR(),colpix.GetG(),colpix.GetB() ) );
		Gdiplus::Pen penPix1( colpix );
		gdi.DrawLine( &penPix1, rect.left, rect.top, rect.left+1, rect.top );
		gdi.DrawLine( &penPix1, rect.right-1, rect.top, rect.right-1, rect.top+1 );
		gdi.DrawLine( &penPix1, rect.right-1, rect.bottom-1, rect.right-2, rect.bottom-1 );
		gdi.DrawLine( &penPix1, rect.left,  rect.bottom-1, rect.left+1,  rect.bottom-1 );

		CRect rect2 = rect;
		::InflateRect( &rect2, -1,-1 );
		if( !m_bMouseDown )
		{
			Gdiplus::Pen pen2(m_colFrame2);
			if( m_bMouseDown )
				pen2.SetColor(m_colFrame1);
			else
				pen2.SetColor(m_colFrame2);

			gdi.DrawLine( &pen2, rect2.left+1, rect2.top, rect2.right-2, rect2.top );
			gdi.DrawLine( &pen2, rect2.left+1, rect2.bottom-1, rect2.right-2, rect2.bottom-1 );
			gdi.DrawLine( &pen2, rect2.left, rect2.top+1, rect2.left, rect2.bottom-2 );
			gdi.DrawLine( &pen2, rect2.right-1, rect2.top+1, rect2.right-1, rect2.bottom-2 );

			Gdiplus::Color colpix2;
			pen2.GetColor( &colpix2 );
			colpix2.SetValue( Gdiplus::Color::MakeARGB(colpix2.GetA()/2,colpix2.GetR(),colpix2.GetG(),colpix2.GetB() ) );
			Gdiplus::Pen penPix2( colpix2 );
			gdi.DrawLine( &penPix2, rect2.left, rect2.top, rect2.left+1, rect2.top );
			gdi.DrawLine( &penPix2, rect2.right-1, rect2.top, rect2.right-1, rect2.top+1 );
			gdi.DrawLine( &penPix2, rect2.right-1, rect2.bottom-1, rect2.right-2, rect2.bottom-1 );
			gdi.DrawLine( &penPix2, rect2.left,  rect2.bottom-1, rect2.left+1,  rect2.bottom-1 );
		}

	/*	if( m_bMouseDown )
		{
			Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/3 );
			Gdiplus::Color colBrush1,colBrush2;
			colBrush1.SetValue( Gdiplus::Color::MakeARGB(15,1,1,1)  );
			colBrush2.SetValue( Gdiplus::Color::MakeARGB(0,1,1,1)  );

			LinearGradientBrush brush( rc, colBrush1, colBrush2,LinearGradientModeVertical );
			gdi.FillRectangle( &brush, rc );
		}
		else
		{
			Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/2 );
			rc.Inflate(-1,-1);
			LinearGradientBrush brush( rc, m_colBrush1, m_colBrush2,LinearGradientModeVertical );
			gdi.FillRectangle( &brush, rc );
		}*/

		CRect rect3 = rect2;
		::InflateRect( &rect3, -1,-1 );
		Gdiplus::RectF rc( rect3.left, rect3.top, rect3.Width(), rect3.Height() );
		LinearGradientBrush brush( rc, m_colBK, m_colBK,LinearGradientModeVertical );
		gdi.FillRectangle( &brush, rc );

		Gdiplus::Color colBlack1 = Gdiplus::Color::MakeARGB(30,50,50,50);
		Gdiplus::Color colBlack2 = Gdiplus::Color::MakeARGB(15,50,50,50);
	    Gdiplus::RectF rc1( rect3.left, rect3.top+rect3.Height()/2, rect3.Width(), rect3.Height()/2 );
		LinearGradientBrush brush2( rc1, colBlack1, colBlack2,LinearGradientModeVertical );
		gdi.FillRectangle( &brush2, rc1 );
		return;
	}
	if( m_enmuDrawType == TOP_ARC )
	{
		Gdiplus::Pen pen1( m_colFrame1 );
		gdi.DrawLine( &pen1, rect.left+5, rect.top, rect.right-7, rect.top );
		gdi.DrawLine( &pen1, rect.left, rect.bottom-1, rect.right, rect.bottom-1 );
		gdi.DrawLine( &pen1, rect.left, rect.top+5, rect.left, rect.bottom-2 );
		gdi.DrawLine( &pen1, rect.right-1, rect.top+5, rect.right-1, rect.bottom-2 );

		CRect rect2 = rect;
		::InflateRect( &rect2, -1,-1 );
		if( !m_bMouseDown )
		{
			Gdiplus::Pen pen2(m_colFrame2);
			gdi.DrawLine( &pen2, rect2.left+4, rect2.top, rect2.right-5, rect2.top );
			gdi.DrawLine( &pen2, rect2.left, rect2.bottom-1, rect2.right-1, rect2.bottom-1 );
			gdi.DrawLine( &pen2, rect2.left, rect2.top+4, rect2.left, rect2.bottom-2 );
			gdi.DrawLine( &pen2, rect2.right-1, rect2.top+4, rect2.right-1, rect2.bottom-2 );

			Gdiplus::RectF rectLeftTop2;
			rectLeftTop2.X = rect2.left;
			rectLeftTop2.Y  = rect2.top;
			rectLeftTop2.Width = 6;
			rectLeftTop2.Height  = 6;
			gdi.DrawArc(  &pen2, rectLeftTop2,180,90 );

			Gdiplus::RectF rectRightTop2;
			rectRightTop2.X = rect2.right-7;
			rectRightTop2.Y  = rect2.top;
			rectRightTop2.Width = 6;
			rectRightTop2.Height  = 6;
			gdi.DrawArc(  &pen2, rectRightTop2,270,90 );
		}

		Gdiplus::RectF rectLeftTop;
		rectLeftTop.X = rect.left;
		rectLeftTop.Y  = rect.top;
		rectLeftTop.Width = 9;
		rectLeftTop.Height  = 9;
		gdi.DrawArc(  &pen1, rectLeftTop,180,90 );

		Gdiplus::RectF rectRightTop;
		rectRightTop.X = rect.right-10;
		rectRightTop.Y  = rect.top;
		rectRightTop.Width = 9;
		rectRightTop.Height  = 9;
		gdi.DrawArc(  &pen1, rectRightTop,270,90 );

		/*Gdiplus::SolidBrush sb( m_colBrush );
		Gdiplus::Brush *pbrush = sb.Clone();*/
		if( m_bMouseDown )
		{
			Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/3 );
			Gdiplus::Color colBrush1,colBrush2;
			colBrush1.SetValue( Gdiplus::Color::MakeARGB(15,1,1,1)  );
			colBrush2.SetValue( Gdiplus::Color::MakeARGB(0,1,1,1)  );

			LinearGradientBrush brush( rc, colBrush1, colBrush2,LinearGradientModeVertical );
			gdi.FillRectangle( &brush, rc );
		}
		else
		{
			Gdiplus::RectF rc( rect2.left, rect2.top, rect2.Width(), rect2.Height()/2 );
			rc.Inflate(-1,-1);
			LinearGradientBrush brush( rc, m_colBrush1, m_colBrush2,LinearGradientModeVertical );
			gdi.FillRectangle( &brush, rc );
		}
	}
	else if( m_enmuDrawType == BOTTON_ARC )
	{
	}
	else if( m_enmuDrawType == RIGHT_ARC )
	{
	}
	else if( m_enmuDrawType == LEFT_ARC )
	{
	}
	else if( m_enmuDrawType & (TOP_ARC|BOTTON_ARC) || m_enmuDrawType & (RIGHT_ARC|LEFT_ARC) )
	{
		// 四角都有弧线
	}

	//gdi.DrawString(
}
Ejemplo n.º 24
0
void CSkinUnitODL::DrawImage(Gdiplus::Graphics& gcDrawer, Gdiplus::GraphicsPath& gcPath, Gdiplus::PointF& ptOffset, Gdiplus::REAL fScale)
{
	if (m_imgSkin)
	{
		if (m_nWrapMode>=4)
		{
			//居中模式
			Gdiplus::RectF rtArea;
			gcPath.GetBounds(&rtArea);
			Gdiplus::GraphicsPath gcDrawPath;
			//图片中间X:(width-imagewidth )/2 + left;
			//Y: (height - imageheight)/2 +top;

			Gdiplus::REAL fX0 = (rtArea.Width - m_fSkinWidth-m_nGroutX) /2.0f + rtArea.X;
			Gdiplus::REAL fY0 = (rtArea.Height - m_fSkinHeight-m_nGroutY) /2.0f + rtArea.Y;
			Gdiplus::REAL fX1 = m_fSkinWidth + m_nGroutX+ fX0;
			Gdiplus::REAL fY1 = m_fSkinHeight +m_nGroutY+ fY0;
			std::vector<Gdiplus::PointF> arrPt;
			arrPt.emplace_back(fX0, fY0);
			arrPt.emplace_back(fX1, fY0);
			arrPt.emplace_back(fX1, fY1);
			arrPt.emplace_back(fX0, fY1);
			Gdiplus::Matrix mx;
			Gdiplus::PointF ptCenter=Gdiplus::PointF((fX1+fX0)/2.0f, (fY1+fY0)/2.0f);
			mx.RotateAt(m_fRotate, ptCenter);
			mx.TransformPoints(arrPt.data(), arrPt.size());
			gcDrawPath.AddPolygon(arrPt.data(),arrPt.size());
			//如果图片的path大于当前区域Path,则居中操作在区域内
			{
				BRepBuilderAPI_MakePolygon ply1;
				for (auto& ptPos:arrPt)
				{
					ply1.Add(gp_Pnt(ptPos.X, 0.0f, ptPos.Y));
				}
				ply1.Close();
				TopoDS_Face face1 = BRepBuilderAPI_MakeFace(ply1.Wire()).Face();
				std::vector<Gdiplus::PointF> arrPic;
				arrPic.resize(gcDrawPath.GetPointCount());
				gcPath.GetPathPoints(arrPic.data(), arrPic.size());

				BRepBuilderAPI_MakePolygon ply2;
				for (auto& ptPos:arrPic)
				{
					ply2.Add(gp_Pnt(ptPos.X, 0.0f, ptPos.Y));
				}
				ply2.Close();
				TopoDS_Face face2 = BRepBuilderAPI_MakeFace(ply2.Wire()).Face();

				BRepAlgoAPI_Common bc(face1, face2);
				auto face = bc.Shape();
				TopExp_Explorer expWire(face, TopAbs_WIRE);
				std::vector<Gdiplus::PointF> arrDraw;
				for ( BRepTools_WireExplorer expVertex(TopoDS::Wire(expWire.Current())); expVertex.More(); expVertex.Next() )
				{
					auto pnt = BRep_Tool::Pnt(expVertex.CurrentVertex());
					arrDraw.emplace_back(static_cast<Gdiplus::REAL>(pnt.X()), static_cast<Gdiplus::REAL>(pnt.Z()));
				}
				gcDrawPath.Reset();
				gcDrawPath.AddPolygon(arrDraw.data(), arrDraw.size());
			}

			Gdiplus::WrapMode wmMode=(Gdiplus::WrapMode)m_nWrapMode;
			if (std::fabs(m_fRotate)<0.001f)
			{
				Gdiplus::TextureBrush brush(m_imgSkin, wmMode);
				mx.Translate(fX0, fY0);
				brush.SetTransform(&mx);
				gcDrawer.FillPath(&brush, &gcDrawPath);
			}
			else
			{
				Gdiplus::TextureBrush brush(m_imgSkin, wmMode);
				mx.Translate(fX0, fY0);
				brush.SetTransform(&mx);
				gcDrawer.FillPath(&brush, &gcDrawPath);
			}
		}
		else
		{
			//铺满模式
			Gdiplus::WrapMode wmMode=(Gdiplus::WrapMode)m_nWrapMode;
			if (std::fabs(m_fRotate)<0.001f)
			{
				Gdiplus::TextureBrush brush(m_imgSkin, wmMode);
				brush.TranslateTransform(ptOffset.X, ptOffset.Y);
				gcDrawer.FillPath(&brush, &gcPath);
			}
			else
			{
				Gdiplus::TextureBrush brush(m_imgSkin, wmMode);
				brush.TranslateTransform(ptOffset.X, ptOffset.Y);
				brush.RotateTransform(m_fRotate);
				gcDrawer.FillPath(&brush, &gcPath);
			}
		}
		
	}
}
Ejemplo n.º 25
0
static Image *ReadEMFImage(const ImageInfo *image_info,
  ExceptionInfo *exception)
{
  Gdiplus::Bitmap
    *bitmap;

  Gdiplus::BitmapData
     bitmap_data;

  Gdiplus::GdiplusStartupInput
    startup_input;

  Gdiplus::Graphics
    *graphics;

  Gdiplus::Image
    *source;

  Gdiplus::Rect
    rect;

  GeometryInfo
    geometry_info;

  Image
    *image;

  MagickStatusType
    flags;

  register Quantum
    *q;

  register ssize_t
    x;

  ssize_t
    y;

  ULONG_PTR
    token;

  unsigned char
    *p;

  wchar_t
    fileName[MagickPathExtent];

  assert(image_info != (const ImageInfo *) NULL);
  assert(image_info->signature == MagickSignature);
  if (image_info->debug != MagickFalse)
    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
      image_info->filename);
  assert(exception != (ExceptionInfo *) NULL);

  image=AcquireImage(image_info,exception);
  if (Gdiplus::GdiplusStartup(&token,&startup_input,NULL) != 
    Gdiplus::Status::Ok)
    ThrowReaderException(CoderError, "GdiplusStartupFailed");
  MultiByteToWideChar(CP_UTF8,0,image->filename,-1,fileName,MagickPathExtent);
  source=Gdiplus::Image::FromFile(fileName);
  if (source == (Gdiplus::Image *) NULL)
    {
      Gdiplus::GdiplusShutdown(token);
      ThrowReaderException(FileOpenError,"UnableToOpenFile");
    }

  image->resolution.x=source->GetHorizontalResolution();
  image->resolution.y=source->GetVerticalResolution();
  image->columns=(size_t) source->GetWidth();
  image->rows=(size_t) source->GetHeight();
  if (image_info->density != (char *) NULL)
    {
      flags=ParseGeometry(image_info->density,&geometry_info);
      image->resolution.x=geometry_info.rho;
      image->resolution.y=geometry_info.sigma;
      if ((flags & SigmaValue) == 0)
        image->resolution.y=image->resolution.x;
      if ((image->resolution.x > 0.0) && (image->resolution.y > 0.0))
        {
          image->columns=(size_t) floor((Gdiplus::REAL) source->GetWidth() /
            source->GetHorizontalResolution() * image->resolution.x + 0.5);
          image->rows=(size_t)floor((Gdiplus::REAL) source->GetHeight() /
            source->GetVerticalResolution() * image->resolution.y + 0.5);
        }
    }

  bitmap=new Gdiplus::Bitmap((INT) image->columns,(INT) image->rows,
    PixelFormat32bppARGB);
  graphics=Gdiplus::Graphics::FromImage(bitmap);
  graphics->SetInterpolationMode(Gdiplus::InterpolationModeHighQualityBicubic);
  graphics->SetSmoothingMode(Gdiplus::SmoothingModeHighQuality);
  graphics->SetTextRenderingHint(Gdiplus::TextRenderingHintClearTypeGridFit);
  graphics->Clear(Gdiplus::Color((BYTE) ScaleQuantumToChar(
    image->background_color.alpha),(BYTE) ScaleQuantumToChar(
    image->background_color.red),(BYTE) ScaleQuantumToChar(
    image->background_color.green),(BYTE) ScaleQuantumToChar(
    image->background_color.blue)));
  graphics->DrawImage(source,0,0,(INT) image->columns,(INT) image->rows);
  delete graphics;
  delete source;

  rect=Gdiplus::Rect(0,0,(INT) image->columns,(INT) image->rows);
  if (bitmap->LockBits(&rect,Gdiplus::ImageLockModeRead,PixelFormat32bppARGB,
    &bitmap_data) != Gdiplus::Ok)
  {
    delete bitmap;
    Gdiplus::GdiplusShutdown(token);
    ThrowReaderException(FileOpenError,"UnableToReadImageData");
  }

  image->alpha_trait=BlendPixelTrait;
  for (y=0; y < (ssize_t) image->rows; y++)
  {
    p=(unsigned char *) bitmap_data.Scan0+(y*abs(bitmap_data.Stride));
    if (bitmap_data.Stride < 0)
      q=GetAuthenticPixels(image,0,image->rows-y-1,image->columns,1,exception);
    else
      q=GetAuthenticPixels(image,0,y,image->columns,1,exception);
    if (q == (Quantum *) NULL)
      break;

    for (x=0; x < (ssize_t) image->columns; x++)
    {
      SetPixelBlue(image,ScaleCharToQuantum(*p++),q);
      SetPixelGreen(image,ScaleCharToQuantum(*p++),q);
      SetPixelRed(image,ScaleCharToQuantum(*p++),q);
      SetPixelAlpha(image,ScaleCharToQuantum(*p++),q);
      q+=GetPixelChannels(image);
    }

    if (SyncAuthenticPixels(image,exception) == MagickFalse)
      break;
  }

  bitmap->UnlockBits(&bitmap_data);
  delete bitmap;
  Gdiplus::GdiplusShutdown(token);
  return(image);
}
Ejemplo n.º 26
0
void CSimplePanelDlg::DrawArrive(Gdiplus::Graphics& gr, vector<BusArrivalInfo>& vecArrival, CRect& rc, CData* pData)
{
	//每次先刷新背景
	Gdiplus::Color cl = Gdiplus::Color::White;
	Gdiplus::SolidBrush brush(cl);
	gr.FillRectangle(&brush, 0, 0, rc.Width(), rc.Height());

	//显示线路号背景
	Gdiplus::PointF pointLineBK(60, 0);
	gr.DrawImage(m_pImLineBK, pointLineBK);

	int nWidth = m_pImLineBK->GetWidth();
	int nHeight = m_pImLineBK->GetHeight();

	//显示线路号
	CString strLineNum = pData->GetLineNumber();
	Gdiplus::SolidBrush brushLineNum(Gdiplus::Color::White);

	WCHAR wcLineNum[6] = {0};
	MultiByteToWideChar(CP_ACP, 0, (char*)(LPCTSTR)strLineNum, strLineNum.GetLength(), wcLineNum, sizeof(wcLineNum));

	Gdiplus::PointF pointLineNum = pointLineBK;
	Gdiplus::RectF rectLineNum(pointLineNum, Gdiplus::SizeF(nWidth, nHeight));
	Gdiplus::Font fontLineNum(L"helvetica", 42 , Gdiplus::FontStyleBold, Gdiplus::UnitPixel);
	Gdiplus::StringFormat stringFormatLineNum;
	stringFormatLineNum.SetAlignment(Gdiplus::StringAlignmentCenter);
	stringFormatLineNum.SetLineAlignment(Gdiplus::StringAlignmentCenter);

	gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
	gr.DrawString(wcLineNum, wcslen(wcLineNum), &fontLineNum, rectLineNum, &stringFormatLineNum, &brushLineNum);

	//显示路
	std::wstring str = L"路";
	Gdiplus::SolidBrush brushLu(Gdiplus::Color::White);

	Gdiplus::PointF pointWord = pointLineBK;
	pointWord.X += 0.75 * nWidth;
	Gdiplus::RectF rectWord(pointWord, Gdiplus::SizeF(40, nHeight - 5));
	Gdiplus::Font fontLu(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
	Gdiplus::StringFormat stringFormatWord;
	stringFormatWord.SetAlignment(Gdiplus::StringAlignmentNear);
	stringFormatWord.SetLineAlignment(Gdiplus::StringAlignmentFar);

	gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
	gr.DrawString(str.c_str(), str.size(), &fontLu, rectWord, &stringFormatWord, &brushLu);

	if(0 < vecArrival.size())
	{
		//显示第一辆车到站
		BusArrivalInfo& stArrive = vecArrival[0];
		if(stArrive.iNum > 0)
		{
			//距离站
			CString strNum;
			strNum.Format("%d", stArrive.iNum);
			Gdiplus::SolidBrush brushNum(Gdiplus::Color(23,117,231));

			WCHAR wcNum[6] = {0};
			MultiByteToWideChar(CP_ACP, 0, (char*)(LPCTSTR)strNum, strNum.GetLength(), wcNum, sizeof(wcNum));

			Gdiplus::PointF pointNum(60 + nWidth, 0);
			Gdiplus::RectF rectNum(pointNum, Gdiplus::SizeF(145, nHeight));
			Gdiplus::Font fontNum(L"helvetica", 42 , Gdiplus::FontStyleBold, Gdiplus::UnitPixel);
			Gdiplus::StringFormat stringFormatNum;
			stringFormatNum.SetAlignment(Gdiplus::StringAlignmentCenter);
			stringFormatNum.SetLineAlignment(Gdiplus::StringAlignmentCenter);

			gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
			gr.DrawString(wcNum, wcslen(wcNum), &fontNum, rectNum, &stringFormatNum, &brushNum);

			std::wstring wstr = L"站";
			Gdiplus::SolidBrush brushZhan(Gdiplus::Color(149,158,168));
			Gdiplus::PointF pointZhan(60 + nWidth + 145 - 32, 0);
			Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(40, nHeight - 5));
			Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
			Gdiplus::StringFormat stringFormatZhan;
			stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentNear);
			stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

			gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
			gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);

		}
		else if(stArrive.iNum == 0)
		{
			if(stArrive.iDistance <= 50)
			{
				std::wstring wstr = L"已经进站";
				Gdiplus::SolidBrush brushZhan(Gdiplus::Color(23,117,231));
				Gdiplus::PointF pointZhan(60 + nWidth, 0);
				Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(145, nHeight - 5));
				Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
				Gdiplus::StringFormat stringFormatZhan;
				stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentFar);
				stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

				gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
				gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);
			}
			else
			{
				std::wstring wstr = L"即将到站";
				Gdiplus::SolidBrush brushZhan(Gdiplus::Color(23,117,231));
				Gdiplus::PointF pointZhan(60 + nWidth, 0);
				Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(145, nHeight - 5));
				Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
				Gdiplus::StringFormat stringFormatZhan;
				stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentFar);
				stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

				gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
				gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);

			}
		}

	}
	else
	{
		std::wstring wstr = L"待发";
		Gdiplus::SolidBrush brushZhan(Gdiplus::Color(23,117,231));
		Gdiplus::PointF pointZhan(60 + nWidth, 0);
		Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(145, nHeight - 5));
		Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
		Gdiplus::StringFormat stringFormatZhan;
		stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentFar);
		stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

		gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
		gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);

	}

	if(1 < vecArrival.size())
	{
		//显示第二辆车到站
		BusArrivalInfo& stArrive = vecArrival[1];
		if(stArrive.iNum > 0)
		{
			//距离站
			CString strNum;
			strNum.Format("%d", stArrive.iNum);
			Gdiplus::SolidBrush brushNum(Gdiplus::Color(23,117,231));

			WCHAR wcNum[6] = {0};
			MultiByteToWideChar(CP_ACP, 0, (char*)(LPCTSTR)strNum, strNum.GetLength(), wcNum, sizeof(wcNum));

			Gdiplus::PointF pointNum(60 + nWidth + 145, 0);
			Gdiplus::RectF rectNum(pointNum, Gdiplus::SizeF(145, nHeight));
			Gdiplus::Font fontNum(L"helvetica", 42 , Gdiplus::FontStyleBold, Gdiplus::UnitPixel);
			Gdiplus::StringFormat stringFormatNum;
			stringFormatNum.SetAlignment(Gdiplus::StringAlignmentCenter);
			stringFormatNum.SetLineAlignment(Gdiplus::StringAlignmentCenter);

			gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
			gr.DrawString(wcNum, wcslen(wcNum), &fontNum, rectNum, &stringFormatNum, &brushNum);

			std::wstring wstr = L"站";
			Gdiplus::SolidBrush brushZhan(Gdiplus::Color(149,158,168));
			Gdiplus::PointF pointZhan(60 + nWidth + 145 + 145 - 32, 0);
			Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(40, nHeight - 5));
			Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
			Gdiplus::StringFormat stringFormatZhan;
			stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentNear);
			stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

			gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
			gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);

		}
		else if(stArrive.iNum == 0)
		{
			if(stArrive.iDistance <= 50)
			{
				std::wstring wstr = L"已经进站";
				Gdiplus::SolidBrush brushZhan(Gdiplus::Color(23,117,231));
				Gdiplus::PointF pointZhan(60 + nWidth + 145, 0);
				Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(145, nHeight - 5));
				Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
				Gdiplus::StringFormat stringFormatZhan;
				stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentFar);
				stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

				gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
				gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);
			}
			else
			{
				std::wstring wstr = L"即将到站";
				Gdiplus::SolidBrush brushZhan(Gdiplus::Color(23,117,231));
				Gdiplus::PointF pointZhan(60 + nWidth + 145, 0);
				Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(145, nHeight - 5));
				Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
				Gdiplus::StringFormat stringFormatZhan;
				stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentFar);
				stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

				gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
				gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);

			}
		}

	}
	else
	{
		std::wstring wstr = L"待发";
		Gdiplus::SolidBrush brushZhan(Gdiplus::Color(23,117,231));
		Gdiplus::PointF pointZhan(60 + nWidth + 145, 0);
		Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(145, nHeight - 5));
		Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
		Gdiplus::StringFormat stringFormatZhan;
		stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentFar);
		stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

		gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
		gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);

	}

}
Ejemplo n.º 27
0
void Button::onDraw(Gdiplus::Graphics& g, int x, int y)
{
	g.DrawImage(bitmaps_[currState_], x+x_, y+y_);
}
Ejemplo n.º 28
0
void CSimplePanelDlg::DrawEmpty(Gdiplus::Graphics& gr, CRect& rc)
{
	//每次先刷新背景
	Gdiplus::Color cl = Gdiplus::Color::White;
	Gdiplus::SolidBrush brush(cl);
	gr.FillRectangle(&brush, 0, 0, rc.Width(), rc.Height());

	//显示线路号背景
	Gdiplus::PointF pointLineBK(60, 0);
	gr.DrawImage(m_pImLineBK, pointLineBK);

	int nWidth = m_pImLineBK->GetWidth();
	int nHeight = m_pImLineBK->GetHeight();

	//显示--
	CString strLineNum = "--";
	Gdiplus::SolidBrush brushLineNum(Gdiplus::Color::White);

	WCHAR wcLineNum[6] = {0};
	MultiByteToWideChar(CP_ACP, 0, (char*)(LPCTSTR)strLineNum, strLineNum.GetLength(), wcLineNum, sizeof(wcLineNum));

	Gdiplus::PointF pointLineNum = pointLineBK;
	Gdiplus::RectF rectLineNum(pointLineNum, Gdiplus::SizeF(nWidth, nHeight));
	Gdiplus::Font fontLineNum(L"helvetica", 42 , Gdiplus::FontStyleBold, Gdiplus::UnitPixel);
	Gdiplus::StringFormat stringFormatLineNum;
	stringFormatLineNum.SetAlignment(Gdiplus::StringAlignmentCenter);
	stringFormatLineNum.SetLineAlignment(Gdiplus::StringAlignmentCenter);

	gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
	gr.DrawString(wcLineNum, wcslen(wcLineNum), &fontLineNum, rectLineNum, &stringFormatLineNum, &brushLineNum);

	//显示路
	std::wstring str = L"路";
	Gdiplus::SolidBrush brushLu(Gdiplus::Color::White);

	Gdiplus::PointF pointWord = pointLineBK;
	pointWord.X += 0.75 * nWidth;
	Gdiplus::RectF rectWord(pointWord, Gdiplus::SizeF(40, nHeight - 5));
	Gdiplus::Font fontLu(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
	Gdiplus::StringFormat stringFormatWord;
	stringFormatWord.SetAlignment(Gdiplus::StringAlignmentNear);
	stringFormatWord.SetLineAlignment(Gdiplus::StringAlignmentFar);

	gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
	gr.DrawString(str.c_str(), str.size(), &fontLu, rectWord, &stringFormatWord, &brushLu);

	//第一辆车距离站
	if(1)
	{
		CString strNum = "- -";
		Gdiplus::SolidBrush brushNum(Gdiplus::Color(149,158,168));

		WCHAR wcNum[6] = {0};
		MultiByteToWideChar(CP_ACP, 0, (char*)(LPCTSTR)strNum, strNum.GetLength(), wcNum, sizeof(wcNum));

		Gdiplus::PointF pointNum(60 + nWidth, 0);
		Gdiplus::RectF rectNum(pointNum, Gdiplus::SizeF(145, nHeight));
		Gdiplus::Font fontNum(L"helvetica", 42 , Gdiplus::FontStyleBold, Gdiplus::UnitPixel);
		Gdiplus::StringFormat stringFormatNum;
		stringFormatNum.SetAlignment(Gdiplus::StringAlignmentCenter);
		stringFormatNum.SetLineAlignment(Gdiplus::StringAlignmentCenter);

		gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
		gr.DrawString(wcNum, wcslen(wcNum), &fontNum, rectNum, &stringFormatNum, &brushNum);

		std::wstring wstr = L"站";
		Gdiplus::SolidBrush brushZhan(Gdiplus::Color(149,158,168));
		Gdiplus::PointF pointZhan(60 + nWidth + 0.7 * 145, 0);
		Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(40, nHeight - 5));
		Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
		Gdiplus::StringFormat stringFormatZhan;
		stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentNear);
		stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

		gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
		gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);	
	}


	if(1)
	{
		//第二辆车距离站
		CString strNum = "- -";
		Gdiplus::SolidBrush brushNum(Gdiplus::Color(149,158,168));

		WCHAR wcNum[6] = {0};
		MultiByteToWideChar(CP_ACP, 0, (char*)(LPCTSTR)strNum, strNum.GetLength(), wcNum, sizeof(wcNum));

		Gdiplus::PointF pointNum(60 + nWidth + 145, 0);
		Gdiplus::RectF rectNum(pointNum, Gdiplus::SizeF(145, nHeight));
		Gdiplus::Font fontNum(L"helvetica", 42 , Gdiplus::FontStyleBold, Gdiplus::UnitPixel);
		Gdiplus::StringFormat stringFormatNum;
		stringFormatNum.SetAlignment(Gdiplus::StringAlignmentCenter);
		stringFormatNum.SetLineAlignment(Gdiplus::StringAlignmentCenter);

		gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
		gr.DrawString(wcNum, wcslen(wcNum), &fontNum, rectNum, &stringFormatNum, &brushNum);

		std::wstring wstr = L"站";
		Gdiplus::SolidBrush brushZhan(Gdiplus::Color(149,158,168));
		Gdiplus::PointF pointZhan(60 + nWidth + 0.7 * 145 + 145, 0);
		Gdiplus::RectF rectZhan(pointZhan, Gdiplus::SizeF(40, nHeight - 5));
		Gdiplus::Font fontZhan(L"方正兰亭黑简体", 24 , Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
		Gdiplus::StringFormat stringFormatZhan;
		stringFormatZhan.SetAlignment(Gdiplus::StringAlignmentNear);
		stringFormatZhan.SetLineAlignment(Gdiplus::StringAlignmentFar);

		gr.SetTextRenderingHint(Gdiplus::TextRenderingHintAntiAlias);
		gr.DrawString(wstr.c_str(), wstr.size(), &fontZhan, rectZhan, &stringFormatZhan, &brushZhan);
	}


}
Ejemplo n.º 29
0
bool PngOutlineText::RenderFontShadow(	
	Gdiplus::Graphics* pGraphicsDrawn, 
	Gdiplus::Graphics* pGraphicsMask,
	Gdiplus::Bitmap* pBitmapDrawn,
	Gdiplus::Bitmap* pBitmapMask,
	Gdiplus::FontFamily* pFontFamily,
	Gdiplus::FontStyle fontStyle,
	int nfontSize,
	const wchar_t*pszText, 
	Gdiplus::Point ptDraw, 
	Gdiplus::StringFormat* pStrFormat)
{
	if(!pGraphicsDrawn||!pGraphicsMask||!pBitmapDrawn||!pBitmapMask) return false;

	Gdiplus::Bitmap* pBitmapShadowMask = 
		m_pPngBitmap->Clone(0, 0, m_pPngBitmap->GetWidth(), m_pPngBitmap->GetHeight(), PixelFormat32bppARGB);

	Gdiplus::Graphics* pGraphicsShadowMask = new Gdiplus::Graphics((Gdiplus::Image*)(pBitmapShadowMask));
	Gdiplus::SolidBrush brushBlack(Gdiplus::Color(0,0,0));
	pGraphicsShadowMask->FillRectangle(&brushBlack, 0, 0, m_pPngBitmap->GetWidth(), m_pPngBitmap->GetHeight() );

	pGraphicsShadowMask->SetCompositingMode(pGraphicsDrawn->GetCompositingMode());
	pGraphicsShadowMask->SetCompositingQuality(pGraphicsDrawn->GetCompositingQuality());
	pGraphicsShadowMask->SetInterpolationMode(pGraphicsDrawn->GetInterpolationMode());
	pGraphicsShadowMask->SetSmoothingMode(pGraphicsDrawn->GetSmoothingMode());
	pGraphicsShadowMask->SetTextRenderingHint(pGraphicsDrawn->GetTextRenderingHint());
	pGraphicsShadowMask->SetPageUnit(pGraphicsDrawn->GetPageUnit());
	pGraphicsShadowMask->SetPageScale(pGraphicsDrawn->GetPageScale());

	bool b = false;

	b = m_pFontBodyShadowMask->DrawString(
			pGraphicsMask, 
			pFontFamily,
			fontStyle,
			nfontSize,
			pszText, 
			ptDraw, 
			pStrFormat);

	if(!b) return false;

	b = m_pShadowStrategyMask->DrawString(		
			pGraphicsShadowMask, 
			pFontFamily,
			fontStyle,
			nfontSize,
			pszText, 
			ptDraw, 
			pStrFormat);

	if(!b) return false;

	b = m_pFontBodyShadow->DrawString(
			pGraphicsDrawn, 
			pFontFamily,
			fontStyle,
			nfontSize,
			pszText, 
			ptDraw, 
			pStrFormat);

	if(!b) return false;

	b = m_pShadowStrategy->DrawString(		
			pGraphicsDrawn, 
			pFontFamily,
			fontStyle,
			nfontSize,
			pszText, 
			ptDraw, 
			pStrFormat);

	if(!b) return false;

	UINT* pixelsDest = NULL;
	UINT* pixelsMask = NULL;
	UINT* pixelsShadowMask = NULL;

	using namespace Gdiplus;

	BitmapData bitmapDataDest;
	BitmapData bitmapDataMask;
	BitmapData bitmapDataShadowMask;
	Rect rect(0, 0, m_pBkgdBitmap->GetWidth(), m_pBkgdBitmap->GetHeight() );

	pBitmapDrawn->LockBits(
		&rect,
		ImageLockModeWrite,
		PixelFormat32bppARGB,
		&bitmapDataDest );

	pBitmapMask->LockBits(
		&rect,
		ImageLockModeWrite,
		PixelFormat32bppARGB,
		&bitmapDataMask );

	pBitmapShadowMask->LockBits(
		&rect,
		ImageLockModeWrite,
		PixelFormat32bppARGB,
		&bitmapDataShadowMask );

	pixelsDest = (UINT*)bitmapDataDest.Scan0;
	pixelsMask = (UINT*)bitmapDataMask.Scan0;
	pixelsShadowMask = (UINT*)bitmapDataShadowMask.Scan0;

	if( !pixelsDest || !pixelsMask || !pixelsShadowMask )
		return false;

	UINT col = 0;
	int stride = bitmapDataDest.Stride >> 2;
	for(UINT row = 0; row < bitmapDataDest.Height; ++row)
	{
		for(col = 0; col < bitmapDataDest.Width; ++col)
		{
			using namespace Gdiplus;
			UINT index = row * stride + col;
			BYTE nAlpha = pixelsMask[index] & 0xff;
			BYTE nAlphaShadow = pixelsShadowMask[index] & 0xff;
			if(nAlpha>0&&nAlpha>nAlphaShadow)
			{
				//pixelsDest[index] = nAlpha << 24 | m_clrShadow.GetR()<<16 | m_clrShadow.GetG()<<8 | m_clrShadow.GetB();
				pixelsDest[index] = 0xff << 24 | m_clrShadow.GetR()<<16 | m_clrShadow.GetG()<<8 | m_clrShadow.GetB();
			}
			else if(nAlphaShadow>0)
			{
				//pixelsDest[index] = nAlphaShadow << 24 | m_clrShadow.GetR()<<16 | m_clrShadow.GetG()<<8 | m_clrShadow.GetB();
				pixelsDest[index] = 0xff << 24 | m_clrShadow.GetR()<<16 | m_clrShadow.GetG()<<8 | m_clrShadow.GetB();
				pixelsMask[index] = pixelsShadowMask[index];
			}
		}
	}

	pBitmapShadowMask->UnlockBits(&bitmapDataShadowMask);
	pBitmapMask->UnlockBits(&bitmapDataMask);
	pBitmapDrawn->UnlockBits(&bitmapDataDest);

	if(pGraphicsShadowMask)
	{
		delete pGraphicsShadowMask;
		pGraphicsShadowMask = NULL;
	}

	if(pBitmapShadowMask)
	{
		delete pBitmapShadowMask;
		pBitmapShadowMask = NULL;
	}

	return true;
}
Ejemplo n.º 30
0
 void CanvasGdiplus::FillRectInt(const Brush& brush,
     int x, int y, int w, int h)
 {
     Gdiplus::Graphics* current = GetCurrentGraphics();
     current->FillRectangle(brush.GetNativeBrush(), x, y, w, h);
 }