void CStartupView::DrawSeparator(Gdiplus::Graphics &graphics) { Gdiplus::Rect gdipRcLogoRegion; Gdiplus::Rect gdipRcButtonRegion; Gdiplus::Rect gdipRcBottomRegion; CalculateRegions(gdipRcLogoRegion, gdipRcButtonRegion, gdipRcBottomRegion); Gdiplus::Pen greyPen(Gdiplus::Color(255, 190, 190, 190), 1); // horizontal separator on the left side Gdiplus::Rect gdipRcLeftButtons; CalculateLeftButtonsRegion(gdipRcLeftButtons); int x1 = gdipRcLeftButtons.X + SEPARATOR_SPACE; int y1 = gdipRcLeftButtons.Y + BUTTON_TITLE_HEIGHT + BUTTON_SUBTITLE_HEIGHT + 2 * BUTTON_HEIGHT + SEPARATOR_HEIGHT/2.0; int x2 = gdipRcLeftButtons.X + gdipRcLeftButtons.Width - SEPARATOR_SPACE; int y2 = y1; graphics.DrawLine(&greyPen, x1, y1, x2, y2); // vertical separator in the middle of the page x1 = gdipRcButtonRegion.X + gdipRcButtonRegion.Width / 2.0; y1 = gdipRcLeftButtons.Y + SEPARATOR_SPACE; x2 = x1; y2 = gdipRcLeftButtons.Y + gdipRcLeftButtons.Height - SEPARATOR_SPACE; graphics.DrawLine(&greyPen, x1, y1, x2, y2); }
void DrawGame(Gdiplus::Graphics &graphics, Game ¤tGame) { // Draw background. graphics.FillRectangle(MY_WHITE_BRUSH, 0, 0, MAIN_WINDOW_WIDTH, MAIN_WINDOW_HEIGHT); // Draw end. const MazeState ¤tMazeState = currentGame.CurrentState(); graphics.FillRectangle( WEAK_BLACK_BRUSH, static_cast<INT>(currentMazeState.end[0] * MAZE_GRID_CELL_SIZE + 2), static_cast<INT>(currentMazeState.end[1] * MAZE_GRID_CELL_SIZE + 2), static_cast<INT>(MAZE_GRID_CELL_SIZE - 5), static_cast<INT>(MAZE_GRID_CELL_SIZE - 5)); // Draw player. graphics.FillEllipse( MY_RED_BRUSH, static_cast<INT>(currentMazeState.currentPosition[0] * MAZE_GRID_CELL_SIZE + 2), static_cast<INT>(currentMazeState.currentPosition[1] * MAZE_GRID_CELL_SIZE + 2), static_cast<INT>(MAZE_GRID_CELL_SIZE - 4), static_cast<INT>(MAZE_GRID_CELL_SIZE - 4)); // Draw maze jumps. int numJumps = currentMazeState.jumps.size(); for (int i = 0; i < numJumps; ++i) { graphics.FillEllipse( MY_BLUE_BRUSH, static_cast<INT>(currentMazeState.jumps[i].array[0] * MAZE_GRID_CELL_SIZE + 3), static_cast<INT>(currentMazeState.jumps[i].array[1] * MAZE_GRID_CELL_SIZE + 3), static_cast<INT>(MAZE_GRID_CELL_SIZE - 5), static_cast<INT>(MAZE_GRID_CELL_SIZE - 5)); } // Draw maze. graphics.DrawRectangle( MY_BLACK_PEN, 0, 0, MAZE_GRID_CELL_SIZE * MAZE_GRID_WIDTH, MAZE_GRID_CELL_SIZE * MAZE_GRID_HEIGHT); for (int j = 0; j < MAZE_GRID_HEIGHT; ++j) { for (int i = 0; i < MAZE_GRID_WIDTH; ++i) { if (currentMazeState.cellFlags[j][i] & CELL_WALL_UP) { graphics.DrawLine( MY_BLACK_PEN, static_cast<INT>(MAZE_GRID_CELL_SIZE * i), static_cast<INT>(MAZE_GRID_CELL_SIZE * j), static_cast<INT>(MAZE_GRID_CELL_SIZE * (i+1)), static_cast<INT>(MAZE_GRID_CELL_SIZE * j)); } if (currentMazeState.cellFlags[j][i] & CELL_WALL_LEFT) { graphics.DrawLine( MY_BLACK_PEN, static_cast<INT>(MAZE_GRID_CELL_SIZE * i), static_cast<INT>(MAZE_GRID_CELL_SIZE * j), static_cast<INT>(MAZE_GRID_CELL_SIZE * i), static_cast<INT>(MAZE_GRID_CELL_SIZE * (j+1))); } } } }
void CanvasGdiplus::DrawLineInt(const Color& color, int x1, int y1, int x2, int y2) { Gdiplus::Pen pen(color.GetNativeColor()); Gdiplus::Graphics* current = GetCurrentGraphics(); current->DrawLine(&pen, x1, y1, x2, y2); }
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( }
void CLine::Draw(Gdiplus::Graphics& graphics) { Pen pen(Color::Red); graphics.DrawLine(&pen, _point1, _point2); }
// 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); }
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; }
void Graphics::DrawLine(Pen* pen, int xa, int ya, int xb, int yb) { Gdiplus::Graphics* g = reinterpret_cast<Gdiplus::Graphics*>(_private); Gdiplus::Pen* gdiPen = reinterpret_cast<Gdiplus::Pen*>(pen->_private); g->DrawLine(gdiPen, xa, ya, xb, yb); }