X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/32b8ec418aee4e38877d4cb79e2984c766dcc358..7d1f4c3ff01b09105c07d5e176a14428c834975e:/src/mgl/dc.cpp diff --git a/src/mgl/dc.cpp b/src/mgl/dc.cpp index edbfd13c3b..aab6d8f990 100644 --- a/src/mgl/dc.cpp +++ b/src/mgl/dc.cpp @@ -4,7 +4,7 @@ // Author: Vaclav Slavik // Created: 2001/03/09 // RCS-ID: $Id$ -// Copyright: (c) Vaclav Slavik +// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com) // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -47,6 +47,10 @@ // constants //----------------------------------------------------------------------------- +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + const double mm2inches = 0.0393700787402; const double inches2mm = 25.4; const double mm2twips = 56.6929133859; @@ -152,16 +156,10 @@ wxDC::wxDC() m_OwnsMGLDC = FALSE; m_ok = FALSE; // must call SetMGLDevCtx() before using it -#if 0 m_mm_to_pix_x = (double)wxGetDisplaySize().GetWidth() / (double)wxGetDisplaySizeMM().GetWidth(); m_mm_to_pix_y = (double)wxGetDisplaySize().GetHeight() / (double)wxGetDisplaySizeMM().GetHeight(); -#endif - // FIXME_MGL -- not in wxUniversal branch (and not implementend anyway, - // hardcode it for 75dpi for now) - m_mm_to_pix_x = ((double)wxGetDisplaySize().GetWidth() / 75) * inches2mm; - m_mm_to_pix_y = ((double)wxGetDisplaySize().GetHeight() / 75) * inches2mm; m_pen = *wxBLACK_PEN; m_font = *wxNORMAL_FONT; @@ -188,6 +186,10 @@ void wxDC::SetMGLDC(MGLDevCtx *mgldc, bool OwnsMGLDC) m_MGLDC = mgldc; m_OwnsMGLDC = OwnsMGLDC; m_ok = TRUE; + + if ( !m_globalClippingRegion.IsNull() ) + SetClippingRegion(m_globalClippingRegion); + InitializeMGLDC(); } @@ -236,7 +238,7 @@ void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region) { wxCHECK_RET( Ok(), wxT("invalid dc") ); - if ( region.Empty() ) + if ( region.IsEmpty() ) { DestroyClippingRegion(); return; @@ -275,9 +277,18 @@ void wxDC::DestroyClippingRegion() { wxCHECK_RET( Ok(), wxT("invalid dc") ); - m_MGLDC->setClipRect(MGLRect(0, 0, m_MGLDC->sizex(), m_MGLDC->sizey())); - m_clipping = FALSE; - m_currentClippingRegion.Clear(); + if ( !m_globalClippingRegion.IsNull() ) + { + m_MGLDC->setClipRegion(m_globalClippingRegion.GetMGLRegion()); + m_currentClippingRegion = m_globalClippingRegion; + m_clipping = TRUE; + } + else + { + m_MGLDC->setClipRect(MGLRect(0, 0, m_MGLDC->sizex()+1, m_MGLDC->sizey()+1)); + m_clipping = FALSE; + m_currentClippingRegion.Clear(); + } } // --------------------------------------------------------------------------- @@ -308,16 +319,14 @@ void wxDC::Clear() wxCHECK_RET( Ok(), wxT("invalid dc") ); m_MGLDC->makeCurrent(); // will go away with MGL6.0 - m_MGLDC->clearDevice(); - if ( m_backgroundBrush.GetStyle() != wxSOLID && - m_backgroundBrush.GetStyle() != wxTRANSPARENT ) + if ( m_backgroundBrush.GetStyle() != wxTRANSPARENT ) { int w, h; wxBrush oldb = m_brush; SetBrush(m_backgroundBrush); SelectBrush(); GetSize(&w, &h); - m_MGLDC->fillRect(0, 0, w-1, h-1); + m_MGLDC->fillRect(0, 0, w, h); SetBrush(oldb); } } @@ -332,7 +341,7 @@ bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const wxCHECK_MSG( col, FALSE, _T("NULL colour parameter in wxDC::GetPixel")); uchar r, g, b; - m_MGLDC->unpackColorFast(m_MGLDC->getPixel(XLOG2DEV(x), XLOG2DEV(y)), + m_MGLDC->unpackColorFast(m_MGLDC->getPixel(XLOG2DEV(x), YLOG2DEV(y)), r, g, b); col->Set(r, g, b); return TRUE; @@ -368,8 +377,8 @@ void wxDC::DoDrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2) m_MGLDC->makeCurrent(); // will go away with MGL6.0 if ( !m_penSelected ) SelectPen(); - m_MGLDC->line(XLOG2DEV(x1) + m_penOfsX, XLOG2DEV(y1) + m_penOfsY, - XLOG2DEV(x2) + m_penOfsX, XLOG2DEV(y2) + m_penOfsY); + m_MGLDC->lineExt(XLOG2DEV(x1) + m_penOfsX, YLOG2DEV(y1) + m_penOfsY, + XLOG2DEV(x2) + m_penOfsX, YLOG2DEV(y2) + m_penOfsY,FALSE); CalcBoundingBox(x1, y1); CalcBoundingBox(x2, y2); } @@ -548,6 +557,7 @@ void wxDC::DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { if ( !m_penSelected ) SelectPen(); + m_MGLDC->rect(xx + m_penOfsX, yy + m_penOfsY, xx + ww + m_penOfsX, yy + hh + m_penOfsY); } @@ -691,7 +701,6 @@ void wxDC::DoDrawEllipticArc(wxCoord x,wxCoord y,wxCoord w,wxCoord h,double sa,d void wxDC::DoDrawText(const wxString& text, wxCoord x, wxCoord y) { - if ( m_pen.GetStyle() == wxTRANSPARENT ) return; m_MGLDC->makeCurrent(); // will go away with MGL6.0 DrawAnyText(text, x, y); @@ -740,32 +749,49 @@ void wxDC::DrawAnyText(const wxString& text, wxCoord x, wxCoord y) SelectMGLFont(); - m_MGLDC->setColor(m_MGLDC->packColorFast(m_textForegroundColour.Red(), - m_textForegroundColour.Green(), m_textForegroundColour.Blue())); - m_MGLDC->setBackColor(m_MGLDC->packColorFast(m_textBackgroundColour.Red(), - m_textBackgroundColour.Green(), m_textBackgroundColour.Blue())); - // Render the text: wxCoord xx = XLOG2DEV(x); wxCoord yy = YLOG2DEV(y); - + m_MGLDC->setLineStyle(MGL_LINE_STIPPLE); m_MGLDC->setLineStipple(0xFFFF); m_MGLDC->setPenSize(1, 1); m_MGLDC->setPenStyle(MGL_BITMAP_SOLID); - + #if wxUSE_UNICODE const wchar_t *c_text = text.c_str(); #else const char *c_text = text.c_str(); #endif + +#if 1 + // FIXME_MGL - this is a temporary hack in absence of proper + // implementation of solid text background in MGL. Once + // the bug in MGL is fixed, this code should be nuked + // immediately. Note that the code is not 100% correct; + // it only works with wxCOPY logical function + if ( m_backgroundMode == wxSOLID ) + { + int w = m_MGLDC->textWidth(c_text); + int h = m_MGLDC->textHeight(); + m_MGLDC->setColor(m_MGLDC->packColorFast(m_textBackgroundColour.Red(), + m_textBackgroundColour.Green(), m_textBackgroundColour.Blue())); + m_MGLDC->fillRect(xx, yy, xx+w, yy+h); + } +#endif + + m_MGLDC->setColor(m_MGLDC->packColorFast(m_textForegroundColour.Red(), + m_textForegroundColour.Green(), m_textForegroundColour.Blue())); + m_MGLDC->setBackColor(m_MGLDC->packColorFast(m_textBackgroundColour.Red(), + m_textBackgroundColour.Green(), m_textBackgroundColour.Blue())); + m_MGLDC->drawStr(xx, yy, c_text); // Render underline: if ( m_font.GetUnderlined() ) { int x1 = xx, y1 = yy; - int x2, y2; + int x2 = 0 , y2 = 0; int w = m_MGLDC->textWidth(c_text); m_MGLDC->underScoreLocation(x1, y1, c_text); switch (m_MGLDC->getTextDirection()) @@ -785,7 +811,6 @@ void wxDC::DoDrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle) { - if ( m_pen.GetStyle() == wxTRANSPARENT ) return; m_MGLDC->makeCurrent(); // will go away with MGL6.0 if ( angle == 0 ) @@ -1077,7 +1102,8 @@ void wxDC::SetPalette(const wxPalette& palette) if ( palette == wxNullPalette ) { - SetPalette(m_oldPalette); + if ( m_oldPalette.Ok() ) + SetPalette(m_oldPalette); return; } @@ -1094,9 +1120,11 @@ void wxDC::SetPalette(const wxPalette& palette) void wxDC::SetFont(const wxFont& font) { - wxCHECK_RET( font.Ok(), wxT("invalid font") ); - m_font = font; - m_mglFont = NULL; + if ( font.Ok() ) + { + m_font = font; + m_mglFont = NULL; + } } void wxDC::SetBackground(const wxBrush& brush) @@ -1224,7 +1252,7 @@ void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y, *descent = YDEV2LOGREL(m_mglFont->descent); if ( externalLeading ) *externalLeading = YDEV2LOGREL(m_mglFont->leading); - + if ( theFont != NULL ) wxConstCast(this, wxDC)->SetFont(oldFont); } @@ -1360,8 +1388,8 @@ wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const void wxDC::DoGetSize(int *w, int *h) const { - if (w) *w = m_MGLDC->sizex(); - if (h) *h = m_MGLDC->sizey(); + if (w) *w = m_MGLDC->sizex()+1; + if (h) *h = m_MGLDC->sizey()+1; } void wxDC::DoGetSizeMM(int *width, int *height) const @@ -1387,7 +1415,8 @@ wxSize wxDC::GetPPI() const bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, wxDC *source, wxCoord xsrc, wxCoord ysrc, - int rop, bool useMask) + int rop, bool useMask, + wxCoord xsrcMask, wxCoord ysrcMask) { wxCHECK_MSG( Ok(), FALSE, wxT("invalid dc") ); wxCHECK_MSG( source, FALSE, wxT("invalid source dc") ); @@ -1396,6 +1425,17 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest, xsrc = source->LogicalToDeviceX(xsrc); ysrc = source->LogicalToDeviceY(ysrc); + /* FIXME_MGL: use the mask origin when drawing transparently */ + if (xsrcMask == -1 && ysrcMask == -1) + { + xsrcMask = xsrc; ysrcMask = ysrc; + } + else + { + xsrcMask = source->LogicalToDeviceX(xsrcMask); + ysrcMask = source->LogicalToDeviceY(ysrcMask); + } + CalcBoundingBox(xdest, ydest); CalcBoundingBox(xdest + width, ydest + height);