For drawing stuff, I rely on Gdi+ which is easier to use for advanced graphics rather than Gdi. Transformation and scaling operations are provided with appropriate methods.
#pragma once #include "Element.h" class CDrawingContext { public: // Drawing Attributes are built in the ctor CDrawingContext(std::shared_ptr<CElement> pElement); virtual ~CDrawingContext(void); public: Graphics * GetGraphics() { return m_pGraphics; } // Methods for Drawing Attributes public: Color & GetColorWhite() { return m_gdiColorWhite; } Color & GetColorBlack() { return m_gdiColorBlack; } Color & GetColorLine() { return m_gdiColorLine; } Color & GetColorFill() { return m_gdiColorFill; } Pen & GetPenBlack() { return m_gdiPenBlack; } Pen & GetPenColor() { return m_gdiPenColor; } SolidBrush & GetBrushColor() { return m_gdiBrushColor; } SolidBrush & GetBrushBlack() { return m_gdiBrushBlack; } LinearGradientBrush & GetGradientBrushColor() { return m_gdiGradientBrush; } CPoint GetTopLeft() { return m_pointTopLeft; } CPoint GetBottomRight() { return m_pointBottomRight; } public: Graphics * m_pGraphics; public: // GDI+ Drawing objects Color m_gdiColorWhite; Color m_gdiColorBlack; Color m_gdiColorLine; Color m_gdiColorFill; Pen m_gdiPenBlack; Pen m_gdiPenColor; SolidBrush m_gdiBrushColor; SolidBrush m_gdiBrushBlack; LinearGradientBrush m_gdiGradientBrush; // MFC Drawing objects CPoint m_pointTopLeft; CPoint m_pointBottomRight; }; #include "StdAfx.h" #include "DrawingContext.h" CDrawingContext::CDrawingContext(std::shared_ptr<CElement> pElement) : m_gdiPenBlack(Color(255, 0, 0, 0)), m_gdiPenColor(Color(255, 0, 0, 0)), m_gdiBrushColor(m_gdiColorBlack), m_gdiBrushBlack(m_gdiColorBlack), m_gdiGradientBrush( Point(pElement->m_rect.left, pElement->m_rect.top), Point(pElement->m_rect.right, pElement->m_rect.bottom), m_gdiColorBlack, m_gdiColorBlack) { m_gdiColorWhite.SetFromCOLORREF(Color::White); m_gdiColorBlack.SetFromCOLORREF(Color::Black); m_gdiColorLine.SetValue(Color::MakeARGB(255, GetRValue(pElement->m_colorLine), GetGValue(pElement->m_colorLine), GetBValue(pElement->m_colorLine))); m_gdiColorFill.SetValue(Color::MakeARGB(255, GetRValue(pElement->m_colorFill), GetGValue(pElement->m_colorFill), GetBValue(pElement->m_colorFill))); m_gdiPenBlack.SetColor(m_gdiColorBlack); m_gdiPenColor.SetColor(m_gdiColorLine); m_gdiPenColor.SetWidth(pElement->m_lineWidth); m_pointTopLeft = pElement->m_rect.TopLeft(); m_pointBottomRight = pElement->m_rect.BottomRight(); m_gdiBrushColor.SetColor(m_gdiColorFill); Color color1(255, 241, 247, 255); m_gdiGradientBrush.SetLinearColors(color1, m_gdiColorFill); } CDrawingContext::~CDrawingContext(void) { }
Leave a Reply