From 41fbc84101e7fc1a3e658f1d3f01664289637f01 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sat, 15 Jan 2000 10:39:27 +0000 Subject: [PATCH 1/1] black now denotes 0 on mono-bitmaps. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5419 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/dc.tex | 5 ++++ docs/latex/wx/memorydc.tex | 5 +++- include/wx/gtk/dcmemory.h | 9 ++++++ include/wx/gtk1/dcmemory.h | 9 ++++++ samples/image/image.cpp | 15 ++++++---- src/gtk/dcmemory.cpp | 60 ++++++++++++++++++++++++++++++++++++++ src/gtk1/dcmemory.cpp | 60 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 156 insertions(+), 7 deletions(-) diff --git a/docs/latex/wx/dc.tex b/docs/latex/wx/dc.tex index 761c1d24f1..3e7e236341 100644 --- a/docs/latex/wx/dc.tex +++ b/docs/latex/wx/dc.tex @@ -174,6 +174,11 @@ The arc is drawn in an anticlockwise direction from the start point to the end p Draw a bitmap on the device context at the specified point. If {\it transparent} is TRUE and the bitmap has a transparency mask, the bitmap will be drawn transparently. +When drawing a mono-bitmap, the current text foreground colour will be used to draw the foreground +of the bitmap (all bit set to 1), and the current text background colour to draw the background +(all bits set 0). See also \helpref{SetTextForeground}{wxwindowsettextforeground}, + \helpref{SetTextForeground}{wxwindowsettextforeground} and \helpref{wxMemoryDC}{wxmemorydc}. + \membersection{wxDC::DrawEllipse}\label{wxdcdrawellipse} \func{void}{DrawEllipse}{\param{wxCoord}{ x}, \param{wxCoord}{ y}, \param{wxCoord}{ width}, \param{wxCoord}{ height}} diff --git a/docs/latex/wx/memorydc.tex b/docs/latex/wx/memorydc.tex index 9ae8c50927..fe12b8ce0c 100644 --- a/docs/latex/wx/memorydc.tex +++ b/docs/latex/wx/memorydc.tex @@ -1,6 +1,9 @@ \section{\class{wxMemoryDC}}\label{wxmemorydc} -A memory device context provides a means to draw graphics onto a bitmap. +A memory device context provides a means to draw graphics onto a bitmap. When +drawing in to a mono-bitmap, using {\tt wxWHITE}, {\tt wxWHITE_PEN} and {\tt wxWHITE_BRUSH} +will draw the background colour (i.e. 0) whereas all other colours will draw the +foreground colour (i.e. 1). \wxheading{Derived from} diff --git a/include/wx/gtk/dcmemory.h b/include/wx/gtk/dcmemory.h index 213b7e4eed..12f106dac6 100644 --- a/include/wx/gtk/dcmemory.h +++ b/include/wx/gtk/dcmemory.h @@ -37,6 +37,15 @@ public: virtual void SelectObject( const wxBitmap& bitmap ); void DoGetSize( int *width, int *height ) const; + // these get reimplemented for mono-bitmaps to behave + // more like their Win32 couterparts. They now interpret + // wxWHITE, wxWHITE_BRUSH and wxWHITE_PEN as drawing 0 + // and everything else as drawing 1. + virtual void SetPen( const wxPen &pen ); + virtual void SetBrush( const wxBrush &brush ); + virtual void SetTextForeground( const wxColour &col ); + virtual void SetTextBackground( const wxColour &col ); + // implementation wxBitmap m_selected; diff --git a/include/wx/gtk1/dcmemory.h b/include/wx/gtk1/dcmemory.h index 213b7e4eed..12f106dac6 100644 --- a/include/wx/gtk1/dcmemory.h +++ b/include/wx/gtk1/dcmemory.h @@ -37,6 +37,15 @@ public: virtual void SelectObject( const wxBitmap& bitmap ); void DoGetSize( int *width, int *height ) const; + // these get reimplemented for mono-bitmaps to behave + // more like their Win32 couterparts. They now interpret + // wxWHITE, wxWHITE_BRUSH and wxWHITE_PEN as drawing 0 + // and everything else as drawing 1. + virtual void SetPen( const wxPen &pen ); + virtual void SetBrush( const wxBrush &brush ); + virtual void SetTextForeground( const wxColour &col ); + virtual void SetTextBackground( const wxColour &col ); + // implementation wxBitmap m_selected; diff --git a/samples/image/image.cpp b/samples/image/image.cpp index 0684031d57..705797f043 100644 --- a/samples/image/image.cpp +++ b/samples/image/image.cpp @@ -271,14 +271,18 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) } dc.SetTextForeground( "BLACK" ); - wxBitmap mono( 30,30,1 ); + wxBitmap mono( 60,50,1 ); wxMemoryDC memdc; memdc.SelectObject( mono ); memdc.SetPen( *wxTRANSPARENT_PEN ); - memdc.SetBrush( *wxBLACK_BRUSH ); - memdc.DrawRectangle( 0,0,30,30 ); memdc.SetBrush( *wxWHITE_BRUSH ); - memdc.DrawRectangle( 5,5,20,20 ); + memdc.DrawRectangle( 0,0,60,50 ); + memdc.SetTextForeground( *wxBLACK ); + memdc.DrawText( "Hi!", 5, 5 ); + memdc.SetBrush( *wxBLACK_BRUSH ); + memdc.DrawRectangle( 33,5,20,20 ); + memdc.SetPen( *wxRED_PEN ); + memdc.DrawLine( 5, 42, 50, 42 ); memdc.SelectObject( wxNullBitmap ); if (mono.Ok()) { @@ -390,8 +394,7 @@ void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) ) void MyFrame::OnAbout( wxCommandEvent &WXUNUSED(event) ) { (void)wxMessageBox( "wxImage demo\n" - "\n" - "Robert Roebling (c) 1998", + "Robert Roebling (c) 1998,2000", "About wxImage Demo", wxICON_INFORMATION | wxOK ); } diff --git a/src/gtk/dcmemory.cpp b/src/gtk/dcmemory.cpp index 5e81a54933..27dd0e8e9d 100644 --- a/src/gtk/dcmemory.cpp +++ b/src/gtk/dcmemory.cpp @@ -66,6 +66,66 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap ) } } +void wxMemoryDC::SetPen( const wxPen &pen ) +{ + if (m_selected.Ok() && m_selected.GetBitmap() && (*wxTRANSPARENT_PEN != pen)) + { + if (*wxWHITE_PEN == pen) + wxWindowDC::SetPen( *wxBLACK_PEN ); + else + wxWindowDC::SetPen( *wxWHITE_PEN ); + } + else + { + wxWindowDC::SetPen( pen ); + } +} + +void wxMemoryDC::SetBrush( const wxBrush &brush ) +{ + if (m_selected.Ok() && m_selected.GetBitmap() && (*wxTRANSPARENT_BRUSH != brush)) + { + if (*wxWHITE_BRUSH == brush) + wxWindowDC::SetBrush( *wxBLACK_BRUSH ); + else + wxWindowDC::SetBrush( *wxWHITE_BRUSH ); + } + else + { + wxWindowDC::SetBrush( brush ); + } +} + +void wxMemoryDC::SetTextForeground( const wxColour &col ) +{ + if (m_selected.Ok() && m_selected.GetBitmap()) + { + if (col == *wxWHITE) + wxWindowDC::SetTextForeground( *wxBLACK ); + else + wxWindowDC::SetTextForeground( *wxWHITE ); + } + else + { + wxWindowDC::SetTextForeground( col ); + } +} + +void wxMemoryDC::SetTextBackground( const wxColour &col ) +{ + if (m_selected.Ok() && m_selected.GetBitmap()) + { + if (col == *wxWHITE) + wxWindowDC::SetTextBackground( *wxBLACK ); + else + wxWindowDC::SetTextBackground( *wxWHITE ); + } + else + { + wxWindowDC::SetTextBackground( col ); + } +} + void wxMemoryDC::DoGetSize( int *width, int *height ) const { if (m_selected.Ok()) diff --git a/src/gtk1/dcmemory.cpp b/src/gtk1/dcmemory.cpp index 5e81a54933..27dd0e8e9d 100644 --- a/src/gtk1/dcmemory.cpp +++ b/src/gtk1/dcmemory.cpp @@ -66,6 +66,66 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap ) } } +void wxMemoryDC::SetPen( const wxPen &pen ) +{ + if (m_selected.Ok() && m_selected.GetBitmap() && (*wxTRANSPARENT_PEN != pen)) + { + if (*wxWHITE_PEN == pen) + wxWindowDC::SetPen( *wxBLACK_PEN ); + else + wxWindowDC::SetPen( *wxWHITE_PEN ); + } + else + { + wxWindowDC::SetPen( pen ); + } +} + +void wxMemoryDC::SetBrush( const wxBrush &brush ) +{ + if (m_selected.Ok() && m_selected.GetBitmap() && (*wxTRANSPARENT_BRUSH != brush)) + { + if (*wxWHITE_BRUSH == brush) + wxWindowDC::SetBrush( *wxBLACK_BRUSH ); + else + wxWindowDC::SetBrush( *wxWHITE_BRUSH ); + } + else + { + wxWindowDC::SetBrush( brush ); + } +} + +void wxMemoryDC::SetTextForeground( const wxColour &col ) +{ + if (m_selected.Ok() && m_selected.GetBitmap()) + { + if (col == *wxWHITE) + wxWindowDC::SetTextForeground( *wxBLACK ); + else + wxWindowDC::SetTextForeground( *wxWHITE ); + } + else + { + wxWindowDC::SetTextForeground( col ); + } +} + +void wxMemoryDC::SetTextBackground( const wxColour &col ) +{ + if (m_selected.Ok() && m_selected.GetBitmap()) + { + if (col == *wxWHITE) + wxWindowDC::SetTextBackground( *wxBLACK ); + else + wxWindowDC::SetTextBackground( *wxWHITE ); + } + else + { + wxWindowDC::SetTextBackground( col ); + } +} + void wxMemoryDC::DoGetSize( int *width, int *height ) const { if (m_selected.Ok()) -- 2.45.2