From de2d2cdc86590c07642994e58051b94ab356256d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 24 Jan 2000 15:58:33 +0000 Subject: [PATCH] patches for wxSTIPPLE_MASK_OPAQUE from Klass Holwerda git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5634 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/defs.h | 2 ++ src/gtk/brush.cpp | 17 ++++++++++++- src/gtk/dcclient.cpp | 37 +++++++++++++++++++++------ src/gtk1/brush.cpp | 17 ++++++++++++- src/gtk1/dcclient.cpp | 37 +++++++++++++++++++++------ src/msw/brush.cpp | 18 ++++++++++++-- src/msw/dc.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 168 insertions(+), 18 deletions(-) diff --git a/include/wx/defs.h b/include/wx/defs.h index 537a400f88..e717c38ff2 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -1316,6 +1316,8 @@ enum { // Brush & Pen Stippling. Note that a stippled pen cannot be dashed!! // Note also that stippling a Pen IS meaningfull, because a Line is + wxSTIPPLE_MASK_OPAQUE, //mask is used for blitting monochrome using text fore and back ground colors + wxSTIPPLE_MASK, //mask is used for masking areas in the stipple bitmap (TO DO) // drawn with a Pen, and without any Brush -- and it can be stippled. wxSTIPPLE = 110, wxBDIAGONAL_HATCH, diff --git a/src/gtk/brush.cpp b/src/gtk/brush.cpp index 2f945402ce..ca0987080c 100644 --- a/src/gtk/brush.cpp +++ b/src/gtk/brush.cpp @@ -65,9 +65,16 @@ wxBrush::wxBrush( const wxColour &colour, int style ) wxBrush::wxBrush( const wxBitmap &stippleBitmap ) { m_refData = new wxBrushRefData(); - M_BRUSHDATA->m_style = wxSTIPPLE; M_BRUSHDATA->m_colour = *wxBLACK; M_BRUSHDATA->m_stipple = stippleBitmap; + if (M_BRUSHDATA->m_stipple.GetMask()) + { + M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE; + } + else + { + M_BRUSHDATA->m_style = wxSTIPPLE; + } if (wxTheBrushList) wxTheBrushList->AddBrush( this ); } @@ -161,6 +168,14 @@ void wxBrush::SetStipple( const wxBitmap& stipple ) { Unshare(); M_BRUSHDATA->m_stipple = stipple; + if (M_BRUSHDATA->m_stipple.GetMask()) + { + M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE; + } + else + { + M_BRUSHDATA->m_style = wxSTIPPLE; + } } void wxBrush::Unshare() diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index 5b39956468..383dc186bd 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -339,8 +339,16 @@ void wxWindowDC::DoDrawPolygon( int n, wxPoint points[], wxCoord xoffset, wxCoor CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset ); } - if ((m_brush.GetStyle() != wxTRANSPARENT) && m_window) - gdk_draw_polygon (m_window, m_brushGC, TRUE, gdkpoints, n); + if (m_window) + { + if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) + gdk_draw_polygon (m_window, m_textGC, TRUE, gdkpoints, n); + else + { + if ((m_brush.GetStyle() != wxTRANSPARENT)) + gdk_draw_polygon (m_window, m_brushGC, TRUE, gdkpoints, n); + } + } // To do: Fillstyle @@ -377,11 +385,19 @@ void wxWindowDC::DoDrawRectangle( wxCoord x, wxCoord y, wxCoord width, wxCoord h if (m_window) { - if (m_brush.GetStyle() != wxTRANSPARENT) - gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy, ww, hh ); - - if (m_pen.GetStyle() != wxTRANSPARENT) - gdk_draw_rectangle( m_window, m_penGC, FALSE, xx, yy, ww-1, hh-1 ); + if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) + { + gdk_draw_rectangle( m_window, m_textGC, TRUE, xx, yy, ww, hh ); + gdk_draw_rectangle( m_window, m_penGC, FALSE, xx, yy, ww-1, hh-1 ); + } + else + { + if (m_brush.GetStyle() != wxTRANSPARENT) + gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy, ww, hh ); + + if (m_pen.GetStyle() != wxTRANSPARENT) + gdk_draw_rectangle( m_window, m_penGC, FALSE, xx, yy, ww-1, hh-1 ); + } } CalcBoundingBox( x, y ); @@ -1083,6 +1099,7 @@ void wxWindowDC::SetPen( const wxPen &pen ) } case wxTRANSPARENT: + case wxSTIPPLE_MASK_OPAQUE: case wxSTIPPLE: case wxSOLID: default: @@ -1166,6 +1183,12 @@ void wxWindowDC::SetBrush( const wxBrush &brush ) } } + if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) + { + gdk_gc_set_fill( m_textGC, GDK_OPAQUE_STIPPLED); + gdk_gc_set_stipple( m_textGC, m_brush.GetStipple()->GetMask()->GetBitmap() ); + } + if (IS_HATCH(m_brush.GetStyle())) { gdk_gc_set_fill( m_brushGC, GDK_STIPPLED ); diff --git a/src/gtk1/brush.cpp b/src/gtk1/brush.cpp index 2f945402ce..ca0987080c 100644 --- a/src/gtk1/brush.cpp +++ b/src/gtk1/brush.cpp @@ -65,9 +65,16 @@ wxBrush::wxBrush( const wxColour &colour, int style ) wxBrush::wxBrush( const wxBitmap &stippleBitmap ) { m_refData = new wxBrushRefData(); - M_BRUSHDATA->m_style = wxSTIPPLE; M_BRUSHDATA->m_colour = *wxBLACK; M_BRUSHDATA->m_stipple = stippleBitmap; + if (M_BRUSHDATA->m_stipple.GetMask()) + { + M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE; + } + else + { + M_BRUSHDATA->m_style = wxSTIPPLE; + } if (wxTheBrushList) wxTheBrushList->AddBrush( this ); } @@ -161,6 +168,14 @@ void wxBrush::SetStipple( const wxBitmap& stipple ) { Unshare(); M_BRUSHDATA->m_stipple = stipple; + if (M_BRUSHDATA->m_stipple.GetMask()) + { + M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE; + } + else + { + M_BRUSHDATA->m_style = wxSTIPPLE; + } } void wxBrush::Unshare() diff --git a/src/gtk1/dcclient.cpp b/src/gtk1/dcclient.cpp index 5b39956468..383dc186bd 100644 --- a/src/gtk1/dcclient.cpp +++ b/src/gtk1/dcclient.cpp @@ -339,8 +339,16 @@ void wxWindowDC::DoDrawPolygon( int n, wxPoint points[], wxCoord xoffset, wxCoor CalcBoundingBox( points[i].x + xoffset, points[i].y + yoffset ); } - if ((m_brush.GetStyle() != wxTRANSPARENT) && m_window) - gdk_draw_polygon (m_window, m_brushGC, TRUE, gdkpoints, n); + if (m_window) + { + if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) + gdk_draw_polygon (m_window, m_textGC, TRUE, gdkpoints, n); + else + { + if ((m_brush.GetStyle() != wxTRANSPARENT)) + gdk_draw_polygon (m_window, m_brushGC, TRUE, gdkpoints, n); + } + } // To do: Fillstyle @@ -377,11 +385,19 @@ void wxWindowDC::DoDrawRectangle( wxCoord x, wxCoord y, wxCoord width, wxCoord h if (m_window) { - if (m_brush.GetStyle() != wxTRANSPARENT) - gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy, ww, hh ); - - if (m_pen.GetStyle() != wxTRANSPARENT) - gdk_draw_rectangle( m_window, m_penGC, FALSE, xx, yy, ww-1, hh-1 ); + if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) + { + gdk_draw_rectangle( m_window, m_textGC, TRUE, xx, yy, ww, hh ); + gdk_draw_rectangle( m_window, m_penGC, FALSE, xx, yy, ww-1, hh-1 ); + } + else + { + if (m_brush.GetStyle() != wxTRANSPARENT) + gdk_draw_rectangle( m_window, m_brushGC, TRUE, xx, yy, ww, hh ); + + if (m_pen.GetStyle() != wxTRANSPARENT) + gdk_draw_rectangle( m_window, m_penGC, FALSE, xx, yy, ww-1, hh-1 ); + } } CalcBoundingBox( x, y ); @@ -1083,6 +1099,7 @@ void wxWindowDC::SetPen( const wxPen &pen ) } case wxTRANSPARENT: + case wxSTIPPLE_MASK_OPAQUE: case wxSTIPPLE: case wxSOLID: default: @@ -1166,6 +1183,12 @@ void wxWindowDC::SetBrush( const wxBrush &brush ) } } + if ((m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) && (m_brush.GetStipple()->GetMask())) + { + gdk_gc_set_fill( m_textGC, GDK_OPAQUE_STIPPLED); + gdk_gc_set_stipple( m_textGC, m_brush.GetStipple()->GetMask()->GetBitmap() ); + } + if (IS_HATCH(m_brush.GetStyle())) { gdk_gc_set_fill( m_brushGC, GDK_STIPPLED ); diff --git a/src/msw/brush.cpp b/src/msw/brush.cpp index 7e107855c9..825410a28b 100644 --- a/src/msw/brush.cpp +++ b/src/msw/brush.cpp @@ -86,8 +86,12 @@ wxBrush::wxBrush(const wxBitmap& stipple) { m_refData = new wxBrushRefData; - M_BRUSHDATA->m_style = wxSTIPPLE; M_BRUSHDATA->m_stipple = stipple; + if (M_BRUSHDATA->m_stipple.GetMask()) + M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE; + else + M_BRUSHDATA->m_style = wxSTIPPLE; + M_BRUSHDATA->m_hBrush = 0; RealizeResource(); @@ -96,7 +100,7 @@ wxBrush::wxBrush(const wxBitmap& stipple) wxTheBrushList->AddBrush(this); } -bool wxBrush::RealizeResource(void) +bool wxBrush::RealizeResource(void) { if (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush == 0)) { @@ -147,6 +151,12 @@ bool wxBrush::RealizeResource(void) else M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateSolidBrush(ms_colour) ; break ; + case wxSTIPPLE_MASK_OPAQUE: + if (M_BRUSHDATA->m_stipple.Ok() && M_BRUSHDATA->m_stipple.GetMask()) + M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreatePatternBrush((HBITMAP) M_BRUSHDATA->m_stipple.GetMask()->GetMaskBitmap()); + else + M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateSolidBrush(ms_colour) ; + break ; case wxSOLID: default: M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateSolidBrush(ms_colour) ; @@ -230,6 +240,10 @@ void wxBrush::SetStipple(const wxBitmap& Stipple) Unshare(); M_BRUSHDATA->m_stipple = Stipple; + if (M_BRUSHDATA->m_stipple.GetMask()) + M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE; + else + M_BRUSHDATA->m_style = wxSTIPPLE; RealizeResource(); } diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index c280a0573a..0a325c7bdd 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -405,6 +405,28 @@ void wxDC::DoDrawPoint(wxCoord x, wxCoord y) void wxDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset,int fillStyle) { + COLORREF old_textground = ::GetTextColor(GetHdc()); + COLORREF old_background = ::GetBkColor(GetHdc()); + if (m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) + { + + if (m_textForegroundColour.Ok()) + { //just the oposite from what is expected see help on pattern brush + // 1 in mask becomes bk color + ::SetBkColor(GetHdc(), m_textForegroundColour.GetPixel() ); + } + if (m_textBackgroundColour.Ok()) + { //just the oposite from what is expected + // 0 in mask becomes text color + ::SetTextColor(GetHdc(), m_textBackgroundColour.GetPixel() ); + } + + if (m_backgroundMode == wxTRANSPARENT) + SetBkMode(GetHdc(), TRANSPARENT); + else + SetBkMode(GetHdc(), OPAQUE); + } + // Do things less efficiently if we have offsets if (xoffset != 0 || yoffset != 0) { @@ -432,6 +454,13 @@ void wxDC::DoDrawPolygon(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffs (void)Polygon(GetHdc(), (POINT*) points, n); SetPolyFillMode(GetHdc(),prev); } + + if (m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) + { + ::SetBkMode(GetHdc(), TRANSPARENT); + ::SetTextColor(GetHdc(), old_textground); + ::SetBkColor(GetHdc(), old_background); + } } void wxDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset) @@ -463,6 +492,28 @@ void wxDC::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { + COLORREF old_textground = ::GetTextColor(GetHdc()); + COLORREF old_background = ::GetBkColor(GetHdc()); + if (m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) + { + + if (m_textForegroundColour.Ok()) + { //just the oposite from what is expected see help on pattern brush + // 1 in mask becomes bk color + ::SetBkColor(GetHdc(), m_textForegroundColour.GetPixel() ); + } + if (m_textBackgroundColour.Ok()) + { //just the oposite from what is expected + // 0 in mask becomes text color + ::SetTextColor(GetHdc(), m_textBackgroundColour.GetPixel() ); + } + + if (m_backgroundMode == wxTRANSPARENT) + SetBkMode(GetHdc(), TRANSPARENT); + else + SetBkMode(GetHdc(), OPAQUE); + } + wxCoord x2 = x + width; wxCoord y2 = y + height; @@ -503,6 +554,13 @@ void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) CalcBoundingBox(x, y); CalcBoundingBox(x2, y2); + + if (m_brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE) + { + ::SetBkMode(GetHdc(), TRANSPARENT); + ::SetTextColor(GetHdc(), old_textground); + ::SetBkColor(GetHdc(), old_background); + } } void wxDC::DoDrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius) -- 2.45.2