From: Robin Dunn Date: Tue, 27 Nov 2001 00:35:36 +0000 (+0000) Subject: Shapes will now draw the right background color when erased if the X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/67d54b58cb92e83364b39c7534079c3699b9b6ea Shapes will now draw the right background color when erased if the canvas is not white. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12715 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/contrib/include/wx/ogl/basic.h b/contrib/include/wx/ogl/basic.h index 9c52020c85..d447693dfa 100644 --- a/contrib/include/wx/ogl/basic.h +++ b/contrib/include/wx/ogl/basic.h @@ -515,6 +515,11 @@ class wxShape: public wxShapeEvtHandler // Clears points from a list of wxRealPoints void ClearPointList(wxList& list); + // Return pen or brush of the right colour for the background + wxPen GetBackgroundPen(); + wxBrush GetBackgroundBrush(); + + private: wxObject* m_clientData; diff --git a/contrib/include/wx/ogl/misc.h b/contrib/include/wx/ogl/misc.h index 4e6abfb6b2..c8096d81bb 100644 --- a/contrib/include/wx/ogl/misc.h +++ b/contrib/include/wx/ogl/misc.h @@ -53,20 +53,20 @@ void oglDrawFormattedText(wxDC& context, wxList *text_list, // Give it a list of points, finds the centre. void oglFindPolylineCentroid(wxList *points, double *x, double *y); -void oglCheckLineIntersection(double x1, double y1, double x2, double y2, +void oglCheckLineIntersection(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double *ratio1, double *ratio2); -void oglFindEndForPolyline(double n, double xvec[], double yvec[], +void oglFindEndForPolyline(double n, double xvec[], double yvec[], double x1, double y1, double x2, double y2, double *x3, double *y3); -void oglFindEndForBox(double width, double height, +void oglFindEndForBox(double width, double height, double x1, double y1, // Centre of box (possibly) double x2, double y2, // other end of line double *x3, double *y3); // End on box edge -void oglFindEndForCircle(double radius, +void oglFindEndForCircle(double radius, double x1, double y1, // Centre of circle double x2, double y2, // Other end of line double *x3, double *y3); @@ -83,7 +83,7 @@ void oglGetArrowPoints(double x1, double y1, double x2, double y2, * This function assumes that the centre of the ellipse is at x1, y1, and the * ellipse has a width of a1 and a height of b1. It also assumes you are * wanting to draw an arc FROM point x2, y2 TOWARDS point x3, y3. - * This function calculates the x,y coordinates of the intersection point of + * This function calculates the x,y coordinates of the intersection point of * the arc with the ellipse. * Author: Ian Harrison */ @@ -99,7 +99,6 @@ extern wxPen* g_oglWhiteBackgroundPen; extern wxPen* g_oglTransparentPen; extern wxBrush* g_oglWhiteBackgroundBrush; extern wxPen* g_oglBlackForegroundPen; -extern wxCursor* g_oglBullseyeCursor; extern wxFont* oglMatchFont(int point_size); diff --git a/contrib/src/ogl/basic.cpp b/contrib/src/ogl/basic.cpp index f5bdab84e5..29e50b9c93 100644 --- a/contrib/src/ogl/basic.cpp +++ b/contrib/src/ogl/basic.cpp @@ -997,8 +997,9 @@ void wxShape::OnEraseContents(wxDC& dc) if (m_pen) penWidth = m_pen->GetWidth(); - dc.SetPen(* g_oglWhiteBackgroundPen); - dc.SetBrush(* g_oglWhiteBackgroundBrush); + dc.SetPen(GetBackgroundPen()); + dc.SetBrush(GetBackgroundBrush()); + dc.DrawRectangle(WXROUND(topLeftX - penWidth), WXROUND(topLeftY - penWidth), WXROUND(maxX + penWidth*2.0 + 4.0), WXROUND(maxY + penWidth*2.0 + 4.0)); } @@ -3281,3 +3282,25 @@ void wxShape::Rotate(double WXUNUSED(x), double WXUNUSED(y), double theta) } } + +wxPen wxShape::GetBackgroundPen() +{ + if (GetCanvas()) + { + wxColour c = GetCanvas()->GetBackgroundColour(); + return wxPen(c, 1, wxSOLID); + } + return * g_oglWhiteBackgroundPen; +} + + +wxBrush wxShape::GetBackgroundBrush() +{ + if (GetCanvas()) + { + wxColour c = GetCanvas()->GetBackgroundColour(); + return wxBrush(c, wxSOLID); + } + return * g_oglWhiteBackgroundBrush; +} + diff --git a/contrib/src/ogl/canvas.cpp b/contrib/src/ogl/canvas.cpp index ac81c3d692..aa04b2d01c 100644 --- a/contrib/src/ogl/canvas.cpp +++ b/contrib/src/ogl/canvas.cpp @@ -61,8 +61,6 @@ #define CONTROL_POINT_ENDPOINT_FROM 5 #define CONTROL_POINT_LINE 6 -extern wxCursor *g_oglBullseyeCursor; - IMPLEMENT_DYNAMIC_CLASS(wxShapeCanvas, wxScrolledWindow) BEGIN_EVENT_TABLE(wxShapeCanvas, wxScrolledWindow) diff --git a/contrib/src/ogl/lines.cpp b/contrib/src/ogl/lines.cpp index 60365d3a2d..fb159d7b83 100644 --- a/contrib/src/ogl/lines.cpp +++ b/contrib/src/ogl/lines.cpp @@ -288,8 +288,8 @@ void wxLineShape::DrawRegion(wxDC& dc, wxShapeRegion *region, double x, double y // First, clear a rectangle for the text IF there is any if (region->GetFormattedText().Number() > 0) { - dc.SetPen(* g_oglWhiteBackgroundPen); - dc.SetBrush(* g_oglWhiteBackgroundBrush); + dc.SetPen(GetBackgroundPen()); + dc.SetBrush(GetBackgroundBrush()); // Now draw the text if (region->GetFont()) dc.SetFont(* region->GetFont()); @@ -300,7 +300,7 @@ void wxLineShape::DrawRegion(wxDC& dc, wxShapeRegion *region, double x, double y dc.SetTextForeground(* region->GetActualColourObject()); #ifdef __WXMSW__ - dc.SetTextBackground(g_oglWhiteBackgroundBrush->GetColour()); + dc.SetTextBackground(GetBackgroundBrush().GetColour()); #endif oglDrawFormattedText(dc, &(region->GetFormattedText()), xp, yp, w, h, region->GetFormatMode()); @@ -324,8 +324,8 @@ void wxLineShape::EraseRegion(wxDC& dc, wxShapeRegion *region, double x, double if (region->GetFormattedText().Number() > 0) { - dc.SetPen(* g_oglWhiteBackgroundPen); - dc.SetBrush(* g_oglWhiteBackgroundBrush); + dc.SetPen(GetBackgroundPen()); + dc.SetBrush(GetBackgroundBrush()); dc.DrawRectangle((long)(xp - w/2.0), (long)(yp - h/2.0), (long)w, (long)h); } @@ -853,8 +853,10 @@ void wxLineShape::OnErase(wxDC& dc) { wxPen *old_pen = m_pen; wxBrush *old_brush = m_brush; - SetPen(g_oglWhiteBackgroundPen); - SetBrush(g_oglWhiteBackgroundBrush); + wxPen bg_pen = GetBackgroundPen(); + wxBrush bg_brush = GetBackgroundBrush(); + SetPen(&bg_pen); + SetBrush(&bg_brush); double bound_x, bound_y; GetBoundingBoxMax(&bound_x, &bound_y); @@ -874,8 +876,8 @@ void wxLineShape::OnErase(wxDC& dc) } // Undraw line - dc.SetPen(* g_oglWhiteBackgroundPen); - dc.SetBrush(* g_oglWhiteBackgroundBrush); + dc.SetPen(GetBackgroundPen()); + dc.SetBrush(GetBackgroundBrush()); // Drawing over the line only seems to work if the line has a thickness // of 1. @@ -1817,7 +1819,7 @@ void wxLineShape::OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, if (lpt->m_type == CONTROL_POINT_ENDPOINT_FROM || lpt->m_type == CONTROL_POINT_ENDPOINT_TO) { - m_canvas->SetCursor(* g_oglBullseyeCursor); + m_canvas->SetCursor(wxCursor(wxCURSOR_BULLSEYE)); lpt->m_oldCursor = wxSTANDARD_CURSOR; } } @@ -1933,7 +1935,7 @@ void wxLineControlPoint::OnBeginDragRight(double x, double y, int keys, int atta lineShape->GetTo()->GetEventHandler()->OnDraw(dc); lineShape->GetTo()->GetEventHandler()->OnDrawContents(dc); } - m_canvas->SetCursor(g_oglBullseyeCursor); + m_canvas->SetCursor(wxCursor(wxCURSOR_BULLSEYE)); m_oldCursor = wxSTANDARD_CURSOR; } } diff --git a/contrib/src/ogl/misc.cpp b/contrib/src/ogl/misc.cpp index a9a466c2da..d98a6eb596 100644 --- a/contrib/src/ogl/misc.cpp +++ b/contrib/src/ogl/misc.cpp @@ -49,11 +49,10 @@ wxFont* g_oglNormalFont; wxPen* g_oglBlackPen; -wxPen* g_oglWhiteBackgroundPen; wxPen* g_oglTransparentPen; -wxBrush* g_oglWhiteBackgroundBrush; wxPen* g_oglBlackForegroundPen; -wxCursor* g_oglBullseyeCursor = NULL; +wxPen* g_oglWhiteBackgroundPen; +wxBrush* g_oglWhiteBackgroundBrush; char* oglBuffer = NULL; @@ -63,16 +62,12 @@ wxList oglObjectCopyMapping(wxKEY_INTEGER); void wxOGLInitialize() { - g_oglBullseyeCursor = new wxCursor(wxCURSOR_BULLSEYE); - - g_oglNormalFont = new wxFont(10, wxSWISS, wxNORMAL, wxNORMAL); - - g_oglBlackPen = new wxPen("BLACK", 1, wxSOLID); - - g_oglWhiteBackgroundPen = new wxPen("WHITE", 1, wxSOLID); - g_oglTransparentPen = new wxPen("WHITE", 1, wxTRANSPARENT); - g_oglWhiteBackgroundBrush = new wxBrush("WHITE", wxSOLID); - g_oglBlackForegroundPen = new wxPen("BLACK", 1, wxSOLID); + g_oglNormalFont = wxTheFontList->FindOrCreateFont(10, wxSWISS, wxNORMAL, wxNORMAL); + g_oglBlackPen = wxThePenList->FindOrCreatePen("BLACK", 1, wxSOLID); + g_oglTransparentPen = wxThePenList->FindOrCreatePen("WHITE", 1, wxTRANSPARENT); + g_oglBlackForegroundPen = wxThePenList->FindOrCreatePen("BLACK", 1, wxSOLID); + g_oglWhiteBackgroundPen = wxThePenList->FindOrCreatePen("WHITE", 1, wxSOLID); + g_oglWhiteBackgroundBrush = wxTheBrushList->FindOrCreateBrush("WHITE", wxSOLID); OGLInitializeConstraintTypes(); @@ -89,42 +84,13 @@ void wxOGLCleanUp() oglBuffer = NULL; } oglBuffer = NULL; - if (g_oglBullseyeCursor) - { - delete g_oglBullseyeCursor; - g_oglBullseyeCursor = NULL; - } - if (g_oglNormalFont) - { - delete g_oglNormalFont; - g_oglNormalFont = NULL; - } - if (g_oglBlackPen) - { - delete g_oglBlackPen; - g_oglBlackPen = NULL; - } - if (g_oglWhiteBackgroundPen) - { - delete g_oglWhiteBackgroundPen; - g_oglWhiteBackgroundPen = NULL; - } - if (g_oglTransparentPen) - { - delete g_oglTransparentPen; - g_oglTransparentPen = NULL; - } - if (g_oglWhiteBackgroundBrush) - { - delete g_oglWhiteBackgroundBrush; - g_oglWhiteBackgroundBrush = NULL; - } - if (g_oglBlackForegroundPen) - { - delete g_oglBlackForegroundPen; - g_oglBlackForegroundPen = NULL; - } + g_oglNormalFont = NULL; // These will be cleaned up by their GDI list + g_oglBlackPen = NULL; + g_oglTransparentPen = NULL; + g_oglBlackForegroundPen = NULL; + g_oglWhiteBackgroundPen = NULL; + g_oglWhiteBackgroundBrush = NULL; OGLCleanUpConstraintTypes(); }