]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/graphcmn.cpp
there is no sqrt(int) in standard C++ (although glibc seems to provide it); select...
[wxWidgets.git] / src / common / graphcmn.cpp
index 3d01a387bb5705042901a6b60cc03dfe7555743f..e35981ca6f7146cc5b07130bc4f114d010967edc 100644 (file)
@@ -18,7 +18,7 @@
 
 #if wxUSE_GRAPHICS_CONTEXT
 
-#include "wx/graphics.h"
+#include "wx/private/graphics.h"
 
 #ifndef WX_PRECOMP
     #include "wx/icon.h"
     #include "wx/log.h"
 #endif
 
-#if !defined(wxMAC_USE_CORE_GRAPHICS_BLEND_MODES)
-#define wxMAC_USE_CORE_GRAPHICS_BLEND_MODES 0
-#endif
-
 //-----------------------------------------------------------------------------
 // constants
 //-----------------------------------------------------------------------------
@@ -120,10 +116,12 @@ wxObjectRefData* wxGraphicsObject::CloneRefData(const wxObjectRefData* data) con
 IMPLEMENT_DYNAMIC_CLASS(wxGraphicsPen, wxGraphicsObject)
 IMPLEMENT_DYNAMIC_CLASS(wxGraphicsBrush, wxGraphicsObject)
 IMPLEMENT_DYNAMIC_CLASS(wxGraphicsFont, wxGraphicsObject)
+IMPLEMENT_DYNAMIC_CLASS(wxGraphicsBitmap, wxGraphicsObject)
 
 WXDLLIMPEXP_DATA_CORE(wxGraphicsPen) wxNullGraphicsPen;
 WXDLLIMPEXP_DATA_CORE(wxGraphicsBrush) wxNullGraphicsBrush;
 WXDLLIMPEXP_DATA_CORE(wxGraphicsFont) wxNullGraphicsFont;
+WXDLLIMPEXP_DATA_CORE(wxGraphicsBitmap) wxNullGraphicsBitmap;
 
 //-----------------------------------------------------------------------------
 // matrix
@@ -147,6 +145,13 @@ void wxGraphicsMatrix::Set(wxDouble a, wxDouble b, wxDouble c, wxDouble d,
     GetMatrixData()->Set(a,b,c,d,tx,ty);
 }
 
+// gets the component valuess of the matrix
+void wxGraphicsMatrix::Get(wxDouble* a, wxDouble* b,  wxDouble* c,
+                           wxDouble* d, wxDouble* tx, wxDouble* ty) const
+{
+    GetMatrixData()->Get(a, b, c, d, tx, ty);
+}
+
 // makes this the inverse matrix
 void wxGraphicsMatrix::Invert()
 {
@@ -214,6 +219,7 @@ void * wxGraphicsMatrix::GetNativeMatrix() const
 //-----------------------------------------------------------------------------
 
 IMPLEMENT_DYNAMIC_CLASS(wxGraphicsPath, wxGraphicsObject)
+WXDLLIMPEXP_DATA_CORE(wxGraphicsPath) wxNullGraphicsPath;
 
 // convenience functions, for using wxPoint2DDouble etc
 
@@ -419,6 +425,9 @@ void wxGraphicsPathData::AddCircle( wxDouble x, wxDouble y, wxDouble r )
 
 void wxGraphicsPathData::AddEllipse( wxDouble x, wxDouble y, wxDouble w, wxDouble h)
 {
+    if (w <= 0. || h <= 0.)
+      return;
+      
     wxDouble rw = w/2;
     wxDouble rh = h/2;
     wxDouble xc = x + rw;
@@ -494,12 +503,58 @@ IMPLEMENT_ABSTRACT_CLASS(wxGraphicsContext, wxObject)
 
 wxGraphicsContext::wxGraphicsContext(wxGraphicsRenderer* renderer) : wxGraphicsObject(renderer) 
 {
+    m_logicalFunction = wxCOPY;
 }
 
 wxGraphicsContext::~wxGraphicsContext() 
 {
 }
 
+bool wxGraphicsContext::StartDoc(const wxString& WXUNUSED(message)) 
+{
+    return true;
+}
+    
+void wxGraphicsContext::EndDoc()
+{
+}
+
+void wxGraphicsContext::StartPage(wxDouble WXUNUSED(width),
+                                  wxDouble WXUNUSED(height))
+{
+}
+    
+void wxGraphicsContext::EndPage()
+{
+}
+
+void wxGraphicsContext::Flush()
+{
+}
+
+#if 0
+void wxGraphicsContext::SetAlpha( wxDouble WXUNUSED(alpha) )
+{
+}
+    
+wxDouble wxGraphicsContext::GetAlpha() const
+{
+    return 1.0;
+}
+#endif
+
+void wxGraphicsContext::GetSize( wxDouble* width, wxDouble* height)
+{
+    *width = 10000.0;
+    *height = 10000.0;
+}
+
+void wxGraphicsContext::GetDPI( wxDouble* dpiX, wxDouble* dpiY)
+{
+    *dpiX = 72.0;
+    *dpiY = 72.0;
+}
+
 // sets the pen
 void wxGraphicsContext::SetPen( const wxGraphicsPen& pen ) 
 {
@@ -508,7 +563,7 @@ void wxGraphicsContext::SetPen( const wxGraphicsPen& pen )
 
 void wxGraphicsContext::SetPen( const wxPen& pen )
 {
-    if ( pen.GetStyle() == wxTRANSPARENT )
+    if ( !pen.Ok() || pen.GetStyle() == wxTRANSPARENT )
         SetPen( wxNullGraphicsPen );
     else
         SetPen( CreatePen( pen ) );
@@ -522,7 +577,7 @@ void wxGraphicsContext::SetBrush( const wxGraphicsBrush& brush )
 
 void wxGraphicsContext::SetBrush( const wxBrush& brush )
 {
-    if ( brush.GetStyle() == wxTRANSPARENT )
+    if ( !brush.Ok() || brush.GetStyle() == wxTRANSPARENT )
         SetBrush( wxNullGraphicsBrush );
     else
         SetBrush( CreateBrush( brush ) );
@@ -534,6 +589,16 @@ void wxGraphicsContext::SetFont( const wxGraphicsFont& font )
     m_font = font;
 }
 
+bool wxGraphicsContext::SetLogicalFunction( int function )
+{
+    if ( function == wxCOPY )
+    {
+        m_logicalFunction = function;
+        return true;
+    }
+    return false;
+}
+
 void wxGraphicsContext::SetFont( const wxFont& font, const wxColour& colour )
 {
     if ( font.Ok() )
@@ -557,6 +622,55 @@ 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;
+       wxGraphicsPen formerPen = m_pen;
+    wxDouble width;
+    wxDouble height;
+    wxDouble descent;
+    wxDouble externalLeading;
+    GetTextExtent( str , &width, &height, &descent, &externalLeading );
+    SetBrush( backgroundBrush );
+       // to make sure our 'OffsetToPixelBoundaries' doesn't move the fill shape
+       SetPen( wxNullGraphicsPen );
+
+    wxGraphicsPath path = CreatePath();
+    path.AddRectangle( x , y, width, height );
+    FillPath( path );
+
+    DrawText( str, x ,y);
+    SetBrush( formerBrush );
+       SetPen( formerPen );
+}
+
+void wxGraphicsContext::DrawText( const wxString &str, wxDouble x, wxDouble y, wxDouble angle, const wxGraphicsBrush& backgroundBrush )
+{
+    wxGraphicsBrush formerBrush = m_brush;
+       wxGraphicsPen formerPen = m_pen;
+
+    wxDouble width;
+    wxDouble height;
+    wxDouble descent;
+    wxDouble externalLeading;
+    GetTextExtent( str , &width, &height, &descent, &externalLeading );
+    SetBrush( backgroundBrush );
+       // to make sure our 'OffsetToPixelBoundaries' doesn't move the fill shape
+       SetPen( wxNullGraphicsPen );
+
+    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 );
+       SetPen( formerPen );
+}
+
 void wxGraphicsContext::StrokeLine( wxDouble x1, wxDouble y1, wxDouble x2, wxDouble y2)
 {
     wxGraphicsPath path = CreatePath();
@@ -661,11 +775,41 @@ wxGraphicsFont wxGraphicsContext::CreateFont( const wxFont &font , const wxColou
     return GetRenderer()->CreateFont(font,col);
 }
 
-wxGraphicsContext* wxGraphicsContext::Create( const wxWindowDC& dc) 
+wxGraphicsBitmap wxGraphicsContext::CreateBitmap( const wxBitmap& bmp ) const
+{
+#ifndef __WXGTK20__
+    return GetRenderer()->CreateBitmap(bmp);
+#else
+    return wxNullGraphicsBitmap;
+#endif
+}
+
+wxGraphicsBitmap wxGraphicsContext::CreateSubBitmap( const wxGraphicsBitmap &bmp, wxDouble x, wxDouble y, wxDouble w, wxDouble h   ) const
+{
+#ifndef __WXGTK20__
+    return GetRenderer()->CreateSubBitmap(bmp,x,y,w,h);
+#else
+    return wxNullGraphicsBitmap;
+#endif
+}
+
+/* static */ wxGraphicsContext* wxGraphicsContext::Create( const wxWindowDC& dc) 
+{
+    return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc);
+}
+
+/* static */ wxGraphicsContext* wxGraphicsContext::Create( const wxMemoryDC& dc) 
 {
     return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc);
 }
 
+#if wxUSE_PRINTING_ARCHITECTURE
+/* static */ wxGraphicsContext* wxGraphicsContext::Create( const wxPrinterDC& dc) 
+{
+    return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc);
+}
+#endif
+
 wxGraphicsContext* wxGraphicsContext::CreateFromNative( void * context )
 {
     return wxGraphicsRenderer::GetDefaultRenderer()->CreateContextFromNativeContext(context);
@@ -681,6 +825,11 @@ wxGraphicsContext* wxGraphicsContext::Create( wxWindow* window )
     return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(window);
 }
 
+wxGraphicsContext* wxGraphicsContext::Create()
+{
+    return wxGraphicsRenderer::GetDefaultRenderer()->CreateMeasuringContext();
+}
+
 //-----------------------------------------------------------------------------
 // wxGraphicsRenderer
 //-----------------------------------------------------------------------------