From 068eb463a4a5ec031d559172897257f4743d570b Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Sat, 4 Nov 2006 17:41:41 +0000 Subject: [PATCH] adding text with background brush git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43046 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/graphics.h | 4 ++++ src/common/dcgraph.cpp | 10 ++++++++-- src/common/graphcmn.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/include/wx/graphics.h b/include/wx/graphics.h index 41cd7f95fc..1d8fcd3c17 100755 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -494,6 +494,10 @@ public: virtual void DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle ); + virtual void DrawText( const wxString &str, wxDouble x, wxDouble y, const wxGraphicsBrush& backgroundBrush ) ; + + virtual void DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle, const wxGraphicsBrush& backgroundBrush ); + virtual void GetTextExtent( const wxString &text, wxDouble *width, wxDouble *height, wxDouble *descent, wxDouble *externalLeading ) const = 0; diff --git a/src/common/dcgraph.cpp b/src/common/dcgraph.cpp index d5da1bb58b..6a8bfab989 100644 --- a/src/common/dcgraph.cpp +++ b/src/common/dcgraph.cpp @@ -762,7 +762,10 @@ void wxGCDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, if ( m_logicalFunction != wxCOPY ) return; - m_graphicContext->DrawText( str, x ,y , DegToRad(angle )); + if ( m_backgroundMode == wxTRANSPARENT ) + m_graphicContext->DrawText( str, x ,y , DegToRad(angle )); + else + m_graphicContext->DrawText( str, x ,y , DegToRad(angle ), m_graphicContext->CreateBrush( wxBrush(m_textBackgroundColour,wxSOLID) ) ); } void wxGCDC::DoDrawText(const wxString& str, wxCoord x, wxCoord y) @@ -774,7 +777,10 @@ void wxGCDC::DoDrawText(const wxString& str, wxCoord x, wxCoord y) if ( m_logicalFunction != wxCOPY ) return; - m_graphicContext->DrawText( str, x ,y); + if ( m_backgroundMode == wxTRANSPARENT ) + m_graphicContext->DrawText( str, x ,y); + else + m_graphicContext->DrawText( str, x ,y , m_graphicContext->CreateBrush( wxBrush(m_textBackgroundColour,wxSOLID) ) ); } bool wxGCDC::CanGetTextExtent() const diff --git a/src/common/graphcmn.cpp b/src/common/graphcmn.cpp index ec0987225e..91894232e4 100644 --- a/src/common/graphcmn.cpp +++ b/src/common/graphcmn.cpp @@ -558,6 +558,47 @@ void wxGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDouble y, w Translate(-x,-y); } +void wxGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDouble y, const wxGraphicsBrush& backgroundBrush ) +{ + wxGraphicsBrush formerBrush = m_brush; + wxDouble width; + wxDouble height; + wxDouble descent; + wxDouble externalLeading; + GetTextExtent( str , &width, &height, &descent, &externalLeading ); + SetBrush( backgroundBrush ); + + wxGraphicsPath path = CreatePath(); + path.AddRectangle( x , y, width, height ); + FillPath( path ); + + DrawText( str, x ,y); + SetBrush( formerBrush ); +} + +void wxGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle, const wxGraphicsBrush& backgroundBrush ) +{ + wxGraphicsBrush formerBrush = m_brush; + + wxDouble width; + wxDouble height; + wxDouble descent; + wxDouble externalLeading; + GetTextExtent( str , &width, &height, &descent, &externalLeading ); + SetBrush( backgroundBrush ); + + wxGraphicsPath path = CreatePath(); + path.MoveToPoint( x , y ); + path.AddLineToPoint( (int) (x + sin(angle) * height) , (int) (y + cos(angle) * height) ); + path.AddLineToPoint( + (int) (x + sin(angle) * height + cos(angle) * width) , + (int) (y + cos(angle) * height - sin(angle) * width)); + path.AddLineToPoint((int) (x + cos(angle) * width) , (int) (y - sin(angle) * width) ); + FillPath( path ); + DrawText( str, x ,y, angle); + SetBrush( formerBrush ); +} + void wxGraphicsContext::StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2) { wxGraphicsPath path = CreatePath(); -- 2.45.2