From 04ab8b6ddfa26fbabeadad36966a21a42fe649b1 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Wed, 2 May 2007 11:05:45 +0000 Subject: [PATCH] Moved all the coordinate system calculation to wxDCBase and thus removed all the duplicated code in all wxDC classes. Problematic is that wxSVGFileDC and wxPostscriptDC inherit from wxDC and therefore include platform specific code (also before this change) so I chose to override all SetLogicalOrigin() etc. methods in these classes and call their wxDCBase methods thereby circumventing the platform dependent code. I'm afraid the Mac code will require updating, too. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45752 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dc.h | 106 ++++++++++------------- include/wx/dcsvg.h | 40 ++++----- include/wx/dfb/dc.h | 65 +++----------- include/wx/generic/dcpsg.h | 80 +++++++++-------- include/wx/gtk/dc.h | 88 ++----------------- include/wx/gtk1/dc.h | 94 +++----------------- include/wx/mac/carbon/dc.h | 71 +++------------- include/wx/mgl/dc.h | 48 ++--------- include/wx/motif/dc.h | 102 +++------------------- include/wx/msw/dc.h | 12 +-- include/wx/os2/dc.h | 12 --- include/wx/x11/dc.h | 74 ++-------------- src/common/dcbase.cpp | 161 +++++++++++++++++++++++++++++++++++ src/common/dcsvg.cpp | 102 +++------------------- src/dfb/dc.cpp | 130 +--------------------------- src/generic/dcpsg.cpp | 39 +++++++-- src/gtk/dc.cpp | 131 ---------------------------- src/gtk1/dc.cpp | 165 ------------------------------------ src/mac/carbon/dc.cpp | 109 +----------------------- src/mac/carbon/dcclient.cpp | 18 ++-- src/mac/carbon/dcprint.cpp | 3 +- src/mac/carbon/dcscreen.cpp | 6 +- src/mgl/dc.cpp | 109 ------------------------ src/motif/dc.cpp | 115 ------------------------- src/msw/dc.cpp | 148 ++++++++------------------------ src/os2/dc.cpp | 62 +------------- src/x11/dc.cpp | 129 ---------------------------- 27 files changed, 439 insertions(+), 1780 deletions(-) diff --git a/include/wx/dc.h b/include/wx/dc.h index e0ace2828f..a5577528a6 100644 --- a/include/wx/dc.h +++ b/include/wx/dc.h @@ -101,40 +101,9 @@ protected: class WXDLLEXPORT wxDCBase : public wxObject { public: - wxDCBase() - : m_colour(wxColourDisplay()) - , m_ok(true) - , m_clipping(false) - , m_isInteractive(0) - , m_isBBoxValid(false) - , m_logicalOriginX(0), m_logicalOriginY(0) - , m_deviceOriginX(0), m_deviceOriginY(0) - , m_logicalScaleX(1.0), m_logicalScaleY(1.0) - , m_userScaleX(1.0), m_userScaleY(1.0) - , m_scaleX(1.0), m_scaleY(1.0) - , m_signX(1), m_signY(1) - , m_minX(0), m_minY(0), m_maxX(0), m_maxY(0) - , m_clipX1(0), m_clipY1(0), m_clipX2(0), m_clipY2(0) - , m_logicalFunction(wxCOPY) - , m_backgroundMode(wxTRANSPARENT) - , m_mappingMode(wxMM_TEXT) - , m_pen() - , m_brush() - , m_backgroundBrush(*wxTRANSPARENT_BRUSH) - , m_textForegroundColour(*wxBLACK) - , m_textBackgroundColour(*wxWHITE) - , m_font() -#if wxUSE_PALETTE - , m_palette() - , m_hasCustomPalette(false) -#endif // wxUSE_PALETTE - { - ResetBoundingBox(); - ResetClipping(); - } - - virtual ~wxDCBase() { } - + wxDCBase(); + virtual ~wxDCBase(); + // graphic primitives // ------------------ @@ -511,20 +480,6 @@ public: return wxSize(w, h); } - // coordinates conversions - // ----------------------- - - // This group of functions does actual conversion of the input, as you'd - // expect. - virtual wxCoord DeviceToLogicalX(wxCoord x) const = 0; - virtual wxCoord DeviceToLogicalY(wxCoord y) const = 0; - virtual wxCoord DeviceToLogicalXRel(wxCoord x) const = 0; - virtual wxCoord DeviceToLogicalYRel(wxCoord y) const = 0; - virtual wxCoord LogicalToDeviceX(wxCoord x) const = 0; - virtual wxCoord LogicalToDeviceY(wxCoord y) const = 0; - virtual wxCoord LogicalToDeviceXRel(wxCoord x) const = 0; - virtual wxCoord LogicalToDeviceYRel(wxCoord y) const = 0; - // query DC capabilities // --------------------- @@ -556,43 +511,60 @@ public: virtual void SetTextBackground(const wxColour& colour) { m_textBackgroundColour = colour; } + + // coordinates conversions and transforms + // -------------------------------------- + + virtual wxCoord DeviceToLogicalX(wxCoord x) const; + virtual wxCoord DeviceToLogicalY(wxCoord y) const; + virtual wxCoord DeviceToLogicalXRel(wxCoord x) const; + virtual wxCoord DeviceToLogicalYRel(wxCoord y) const; + virtual wxCoord LogicalToDeviceX(wxCoord x) const; + virtual wxCoord LogicalToDeviceY(wxCoord y) const; + virtual wxCoord LogicalToDeviceXRel(wxCoord x) const; + virtual wxCoord LogicalToDeviceYRel(wxCoord y) const; + + virtual void SetMapMode(int mode); virtual int GetMapMode() const { return m_mappingMode; } - virtual void SetMapMode(int mode) = 0; + virtual void SetUserScale(double x, double y); virtual void GetUserScale(double *x, double *y) const { if ( x ) *x = m_userScaleX; if ( y ) *y = m_userScaleY; } - virtual void SetUserScale(double x, double y) = 0; + virtual void SetLogicalScale(double x, double y); virtual void GetLogicalScale(double *x, double *y) { if ( x ) *x = m_logicalScaleX; if ( y ) *y = m_logicalScaleY; } - virtual void SetLogicalScale(double x, double y) - { - m_logicalScaleX = x; - m_logicalScaleY = y; - } + virtual void SetLogicalOrigin(wxCoord x, wxCoord y); void GetLogicalOrigin(wxCoord *x, wxCoord *y) const { DoGetLogicalOrigin(x, y); } wxPoint GetLogicalOrigin() const { wxCoord x, y; DoGetLogicalOrigin(&x, &y); return wxPoint(x, y); } - virtual void SetLogicalOrigin(wxCoord x, wxCoord y) = 0; + virtual void SetDeviceOrigin(wxCoord x, wxCoord y); void GetDeviceOrigin(wxCoord *x, wxCoord *y) const { DoGetDeviceOrigin(x, y); } wxPoint GetDeviceOrigin() const { wxCoord x, y; DoGetDeviceOrigin(&x, &y); return wxPoint(x, y); } - virtual void SetDeviceOrigin(wxCoord x, wxCoord y) = 0; + + virtual void SetDeviceLocalOrigin( wxCoord x, wxCoord y ); - virtual void ComputeScaleAndOrigin() {} + virtual void ComputeScaleAndOrigin(); - virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp) = 0; + // this needs to overidden if the axis is inverted (such + // as when using Postscript, where 0,0 is the lower left + // corner, not the upper left). + virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); + // logical functions + // --------------------------- + virtual int GetLogicalFunction() const { return m_logicalFunction; } virtual void SetLogicalFunction(int function) = 0; @@ -836,15 +808,25 @@ protected: // TODO short descriptions of what exactly they are would be nice... wxCoord m_logicalOriginX, m_logicalOriginY; - wxCoord m_deviceOriginX, m_deviceOriginY; - + wxCoord m_deviceOriginX, m_deviceOriginY; // Usually 0,0, can be change by user + + wxCoord m_deviceLocalOriginX, m_deviceLocalOriginY; // non-zero if native top-left corner + // is not at 0,0. This was the case under + // Mac's GrafPorts (coordinate system + // used toplevel window's origin) and + // e.g. for Postscript, where the native + // origin in the bottom left corner. double m_logicalScaleX, m_logicalScaleY; double m_userScaleX, m_userScaleY; - double m_scaleX, m_scaleY; + double m_scaleX, m_scaleY; // calculated from logical scale and user scale // Used by SetAxisOrientation() to invert the axes int m_signX, m_signY; + // what is a mm on a screen you don't know the size of? + double m_mm_to_pix_x, + m_mm_to_pix_y; + // bounding and clipping boxes wxCoord m_minX, m_minY, m_maxX, m_maxY; wxCoord m_clipX1, m_clipY1, m_clipX2, m_clipY2; diff --git a/include/wx/dcsvg.h b/include/wx/dcsvg.h index 14d922409c..a14a1ee31c 100644 --- a/include/wx/dcsvg.h +++ b/include/wx/dcsvg.h @@ -46,47 +46,38 @@ public: wxCoord GetCharHeight() const; wxCoord GetCharWidth() const; - void SetClippingRegion(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxCoord WXUNUSED(width), wxCoord WXUNUSED(height)) + void SetClippingRegion(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), wxCoord WXUNUSED(width), wxCoord WXUNUSED(height)) { wxASSERT_MSG (false, wxT("wxSVGFILEDC::SetClippingRegion not implemented")); return ; } - void SetPalette(const wxPalette& WXUNUSED(palette)) + void SetPalette(const wxPalette& WXUNUSED(palette)) { wxASSERT_MSG (false, wxT("wxSVGFILEDC::SetPalette not implemented")); return ; } - void GetClippingBox(wxCoord *WXUNUSED(x), wxCoord *WXUNUSED(y), wxCoord * WXUNUSED(width), wxCoord * WXUNUSED(height)) + void GetClippingBox(wxCoord *WXUNUSED(x), wxCoord *WXUNUSED(y), wxCoord * WXUNUSED(width), wxCoord * WXUNUSED(height)) { wxASSERT_MSG (false, wxT("wxSVGFILEDC::GetClippingBox not implemented")); return ; } - void SetLogicalFunction(int WXUNUSED(function)) + void SetLogicalFunction(int WXUNUSED(function)) { wxASSERT_MSG (false, wxT("wxSVGFILEDC::SetLogicalFunction Call not implemented")); return ; } - int GetLogicalFunction() const + int GetLogicalFunction() const { wxASSERT_MSG (false, wxT("wxSVGFILEDC::GetLogicalFunction() not implemented")); return wxCOPY ; } - void SetBackground( const wxBrush &brush ) ; - void SetBackgroundMode( int mode ) ; - void SetBrush(const wxBrush& brush) ; - void SetFont(const wxFont& font) ; - void SetPen(const wxPen& pen) ; + void SetBackground( const wxBrush &brush ) ; + void SetBackgroundMode( int mode ) ; + void SetBrush(const wxBrush& brush) ; + void SetFont(const wxFont& font) ; + void SetPen(const wxPen& pen) ; - bool IsOk() const {return m_OK;} - - virtual wxCoord DeviceToLogicalX(wxCoord x) const; - virtual wxCoord DeviceToLogicalY(wxCoord y) const; - virtual wxCoord DeviceToLogicalXRel(wxCoord x) const; - virtual wxCoord DeviceToLogicalYRel(wxCoord y) const; - virtual wxCoord LogicalToDeviceX(wxCoord x) const; - virtual wxCoord LogicalToDeviceY(wxCoord y) const; - virtual wxCoord LogicalToDeviceXRel(wxCoord x) const; - virtual wxCoord LogicalToDeviceYRel(wxCoord y) const ; + bool IsOk() const {return m_OK;} + // these need to be overridden as wxPostscriptDC inherits + // from the platform dependent wxDC and this we'd call + // e.g. wxMSW specific code here. virtual void SetMapMode( int mode ); virtual void SetUserScale( double x, double y ); virtual void SetLogicalScale( double x, double y ); virtual void SetLogicalOrigin( wxCoord x, wxCoord y ); virtual void SetDeviceOrigin( wxCoord x, wxCoord y ); - - virtual void SetAxisOrientation( bool xLeftRight, bool yBottomUp ); - - virtual void ComputeScaleAndOrigin(); + void SetAxisOrientation( bool xLeftRight, bool yBottomUp ); private: bool DoGetPixel(wxCoord, wxCoord, class wxColour *) const @@ -150,7 +141,6 @@ private: bool m_OK; bool m_graphics_changed; int m_width, m_height; - double m_mm_to_pix_x, m_mm_to_pix_y; private: DECLARE_ABSTRACT_CLASS(wxSVGFileDC) diff --git a/include/wx/dfb/dc.h b/include/wx/dfb/dc.h index 5bfed574b7..717be0a844 100644 --- a/include/wx/dfb/dc.h +++ b/include/wx/dfb/dc.h @@ -65,65 +65,20 @@ public: virtual int GetDepth() const; virtual wxSize GetPPI() const; - virtual void SetMapMode(int mode); - virtual void SetUserScale(double x, double y); - virtual void SetLogicalScale(double x, double y); - virtual void SetLogicalOrigin(wxCoord x, wxCoord y); - virtual void SetDeviceOrigin(wxCoord x, wxCoord y); - virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); - virtual void SetLogicalFunction(int function); - - virtual wxCoord DeviceToLogicalX(wxCoord x) const; - virtual wxCoord DeviceToLogicalY(wxCoord y) const; - virtual wxCoord DeviceToLogicalXRel(wxCoord x) const; - virtual wxCoord DeviceToLogicalYRel(wxCoord y) const; - virtual wxCoord LogicalToDeviceX(wxCoord x) const; - virtual wxCoord LogicalToDeviceY(wxCoord y) const; - virtual wxCoord LogicalToDeviceXRel(wxCoord x) const; - virtual wxCoord LogicalToDeviceYRel(wxCoord y) const ; - - // implementation from now on - // -------------------------- - - virtual void ComputeScaleAndOrigin(); - - wxCoord XDEV2LOG(wxCoord x) const - { - return wxRound((double)(x - m_deviceOriginX) / m_scaleX) * m_signX + m_logicalOriginX; - } - wxCoord XDEV2LOGREL(wxCoord x) const - { - return wxRound((double)(x) / m_scaleX); - } - wxCoord YDEV2LOG(wxCoord y) const - { - return wxRound((double)(y - m_deviceOriginY) / m_scaleY) * m_signY + m_logicalOriginY; - } - wxCoord YDEV2LOGREL(wxCoord y) const - { - return wxRound((double)(y) / m_scaleY); - } - wxCoord XLOG2DEV(wxCoord x) const - { - return wxRound((double)(x - m_logicalOriginX) * m_scaleX) * m_signX + m_deviceOriginX; - } - wxCoord XLOG2DEVREL(wxCoord x) const - { - return wxRound((double)(x) * m_scaleX); - } - wxCoord YLOG2DEV(wxCoord y) const - { - return wxRound((double)(y - m_logicalOriginY) * m_scaleY) * m_signY + m_deviceOriginY; - } - wxCoord YLOG2DEVREL(wxCoord y) const - { - return wxRound((double)(y) * m_scaleY); - } - // Returns the surface (and increases its ref count) wxIDirectFBSurfacePtr GetDirectFBSurface() const { return m_surface; } protected: + // implementation + wxCoord XDEV2LOG(wxCoord x) const { return DeviceToLogicalX(x); } + wxCoord XDEV2LOGREL(wxCoord x) const { return DeviceToLogicalXRel(x); } + wxCoord YDEV2LOG(wxCoord y) const { return DeviceToLogicalY(y); } + wxCoord YDEV2LOGREL(wxCoord y) const { return DeviceToLogicalYRel(y); } + wxCoord XLOG2DEV(wxCoord x) const { return LogicalToDeviceX(x); } + wxCoord XLOG2DEVREL(wxCoord x) const { return LogicalToDeviceXRel(x); } + wxCoord YLOG2DEV(wxCoord y) const { return LogicalToDeviceY(y); } + wxCoord YLOG2DEVREL(wxCoord y) const { return LogicalToDeviceYRel(y); } + // initializes the DC from a surface, must be called if default ctor // was used void DFBInit(const wxIDirectFBSurfacePtr& surface); diff --git a/include/wx/generic/dcpsg.h b/include/wx/generic/dcpsg.h index f1932134d8..2d6fa5955a 100644 --- a/include/wx/generic/dcpsg.h +++ b/include/wx/generic/dcpsg.h @@ -42,59 +42,67 @@ public: // Recommended constructor wxPostScriptDC(const wxPrintData& printData); - - // Recommended destructor :-) + virtual ~wxPostScriptDC(); - virtual bool Ok() const { return IsOk(); } - virtual bool IsOk() const; + virtual bool Ok() const { return IsOk(); } + virtual bool IsOk() const; - bool CanDrawBitmap() const { return true; } + bool CanDrawBitmap() const { return true; } - void Clear(); - void SetFont( const wxFont& font ); - void SetPen( const wxPen& pen ); - void SetBrush( const wxBrush& brush ); - void SetLogicalFunction( int function ); - void SetBackground( const wxBrush& brush ); + void Clear(); + void SetFont( const wxFont& font ); + void SetPen( const wxPen& pen ); + void SetBrush( const wxBrush& brush ); + void SetLogicalFunction( int function ); + void SetBackground( const wxBrush& brush ); - void DestroyClippingRegion(); + void DestroyClippingRegion(); - bool StartDoc(const wxString& message); - void EndDoc(); - void StartPage(); - void EndPage(); + bool StartDoc(const wxString& message); + void EndDoc(); + void StartPage(); + void EndPage(); - wxCoord GetCharHeight() const; - wxCoord GetCharWidth() const; - bool CanGetTextExtent() const { return true; } + wxCoord GetCharHeight() const; + wxCoord GetCharWidth() const; + bool CanGetTextExtent() const { return true; } - // Resolution in pixels per logical inch - wxSize GetPPI() const; + // Resolution in pixels per logical inch + wxSize GetPPI() const; - void SetAxisOrientation( bool xLeftRight, bool yBottomUp ); - void SetDeviceOrigin( wxCoord x, wxCoord y ); + // overridden because origin is bottom left and + // axes are inverted + void SetAxisOrientation( bool xLeftRight, bool yBottomUp ); + + // these need to be overridden as wxPostscriptDC inherits + // from the platform dependent wxDC and this we'd call + // e.g. wxMSW specific code here. + virtual void SetMapMode(int mode); + virtual void SetUserScale(double x, double y); + virtual void SetLogicalScale(double x, double y); + virtual void SetLogicalOrigin(wxCoord x, wxCoord y); + virtual void SetDeviceOrigin(wxCoord x, wxCoord y); - void SetBackgroundMode(int WXUNUSED(mode)) { } - void SetPalette(const wxPalette& WXUNUSED(palette)) { } + void SetBackgroundMode(int WXUNUSED(mode)) { } + void SetPalette(const wxPalette& WXUNUSED(palette)) { } - wxPrintData& GetPrintData() { return m_printData; } - void SetPrintData(const wxPrintData& data) { m_printData = data; } + void SetPrintData(const wxPrintData& data); + wxPrintData& GetPrintData() { return m_printData; } - virtual int GetDepth() const { return 24; } + virtual int GetDepth() const { return 24; } - static void SetResolution(int ppi); - static int GetResolution(); + static void SetResolution(int ppi); + static int GetResolution(); - WX_DEFINE_VARARG_FUNC_VOID(PsPrintf, 1, (const wxString&), DoPsPrintfFormat) + WX_DEFINE_VARARG_FUNC_VOID(PsPrintf, 1, (const wxString&), DoPsPrintfFormat) #ifdef __WATCOMC__ // workaround for http://bugzilla.openwatcom.org/show_bug.cgi?id=351 - WX_DEFINE_VARARG_FUNC_VOID(PsPrintf, 1, (const char*), DoPsPrintfFormat) - WX_DEFINE_VARARG_FUNC_VOID(PsPrintf, 1, (const wchar_t*), DoPsPrintfFormat) + WX_DEFINE_VARARG_FUNC_VOID(PsPrintf, 1, (const char*), DoPsPrintfFormat) + WX_DEFINE_VARARG_FUNC_VOID(PsPrintf, 1, (const wchar_t*), DoPsPrintfFormat) #endif - - void PsPrint( const wxString& psdata ); - void PsPrint( int ch ); + void PsPrint( const wxString& psdata ); + void PsPrint( int ch ); private: void DoPsPrintfFormat(const wxString& fmt, ... ); diff --git a/include/wx/gtk/dc.h b/include/wx/gtk/dc.h index 3faf7252e2..48503572df 100644 --- a/include/wx/gtk/dc.h +++ b/include/wx/gtk/dc.h @@ -10,21 +10,6 @@ #ifndef __GTKDCH__ #define __GTKDCH__ -//----------------------------------------------------------------------------- -// constants -//----------------------------------------------------------------------------- - -#ifndef MM_TEXT -#define MM_TEXT 0 -#define MM_ISOTROPIC 1 -#define MM_ANISOTROPIC 2 -#define MM_LOMETRIC 3 -#define MM_HIMETRIC 4 -#define MM_TWIPS 5 -#define MM_POINTS 6 -#define MM_METRIC 7 -#endif - //----------------------------------------------------------------------------- // wxDC //----------------------------------------------------------------------------- @@ -47,80 +32,23 @@ public: virtual void StartPage() { } virtual void EndPage() { } - virtual wxCoord DeviceToLogicalX(wxCoord x) const; - virtual wxCoord DeviceToLogicalY(wxCoord y) const; - virtual wxCoord DeviceToLogicalXRel(wxCoord x) const; - virtual wxCoord DeviceToLogicalYRel(wxCoord y) const; - virtual wxCoord LogicalToDeviceX(wxCoord x) const; - virtual wxCoord LogicalToDeviceY(wxCoord y) const; - virtual wxCoord LogicalToDeviceXRel(wxCoord x) const; - virtual wxCoord LogicalToDeviceYRel(wxCoord y) const ; - - virtual void SetMapMode( int mode ); - virtual void SetUserScale( double x, double y ); - virtual void SetLogicalScale( double x, double y ); - virtual void SetLogicalOrigin( wxCoord x, wxCoord y ); - virtual void SetDeviceOrigin( wxCoord x, wxCoord y ); - - virtual void SetAxisOrientation( bool xLeftRight, bool yBottomUp ); - - virtual void ComputeScaleAndOrigin(); - virtual GdkWindow* GetGDKWindow() const { return NULL; } protected: // implementation - // -------------- - - wxCoord XDEV2LOG(wxCoord x) const - { - return DeviceToLogicalX(x); - } - wxCoord XDEV2LOGREL(wxCoord x) const - { - return DeviceToLogicalXRel(x); - } - wxCoord YDEV2LOG(wxCoord y) const - { - return DeviceToLogicalY(y); - } - wxCoord YDEV2LOGREL(wxCoord y) const - { - return DeviceToLogicalYRel(y); - } - wxCoord XLOG2DEV(wxCoord x) const - { - return LogicalToDeviceX(x); - } - wxCoord XLOG2DEVREL(wxCoord x) const - { - return LogicalToDeviceXRel(x); - } - wxCoord YLOG2DEV(wxCoord y) const - { - return LogicalToDeviceY(y); - } - wxCoord YLOG2DEVREL(wxCoord y) const - { - return LogicalToDeviceYRel(y); - } + wxCoord XDEV2LOG(wxCoord x) const { return DeviceToLogicalX(x); } + wxCoord XDEV2LOGREL(wxCoord x) const { return DeviceToLogicalXRel(x); } + wxCoord YDEV2LOG(wxCoord y) const { return DeviceToLogicalY(y); } + wxCoord YDEV2LOGREL(wxCoord y) const { return DeviceToLogicalYRel(y); } + wxCoord XLOG2DEV(wxCoord x) const { return LogicalToDeviceX(x); } + wxCoord XLOG2DEVREL(wxCoord x) const { return LogicalToDeviceXRel(x); } + wxCoord YLOG2DEV(wxCoord y) const { return LogicalToDeviceY(y); } + wxCoord YLOG2DEVREL(wxCoord y) const { return LogicalToDeviceYRel(y); } // base class pure virtuals implemented here virtual void DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height); virtual void DoGetSizeMM(int* width, int* height) const; -public: - // GTK-specific member variables - - // not sure what for, but what is a mm on a screen you don't know the size - // of? - double m_mm_to_pix_x, - m_mm_to_pix_y; - - bool m_needComputeScaleX, - m_needComputeScaleY; // not yet used - - private: DECLARE_ABSTRACT_CLASS(wxDC) }; diff --git a/include/wx/gtk1/dc.h b/include/wx/gtk1/dc.h index dcd541b5a8..33c6663eb9 100644 --- a/include/wx/gtk1/dc.h +++ b/include/wx/gtk1/dc.h @@ -16,21 +16,6 @@ class WXDLLIMPEXP_CORE wxDC; -//----------------------------------------------------------------------------- -// constants -//----------------------------------------------------------------------------- - -#ifndef MM_TEXT -#define MM_TEXT 0 -#define MM_ISOTROPIC 1 -#define MM_ANISOTROPIC 2 -#define MM_LOMETRIC 3 -#define MM_HIMETRIC 4 -#define MM_TWIPS 5 -#define MM_POINTS 6 -#define MM_METRIC 7 -#endif - //----------------------------------------------------------------------------- // wxDC //----------------------------------------------------------------------------- @@ -53,80 +38,21 @@ public: virtual void StartPage() { } virtual void EndPage() { } - virtual wxCoord DeviceToLogicalX(wxCoord x) const; - virtual wxCoord DeviceToLogicalY(wxCoord y) const; - virtual wxCoord DeviceToLogicalXRel(wxCoord x) const; - virtual wxCoord DeviceToLogicalYRel(wxCoord y) const; - virtual wxCoord LogicalToDeviceX(wxCoord x) const; - virtual wxCoord LogicalToDeviceY(wxCoord y) const; - virtual wxCoord LogicalToDeviceXRel(wxCoord x) const; - virtual wxCoord LogicalToDeviceYRel(wxCoord y) const ; - - virtual void SetMapMode( int mode ); - virtual void SetUserScale( double x, double y ); - virtual void SetLogicalScale( double x, double y ); - virtual void SetLogicalOrigin( wxCoord x, wxCoord y ); - virtual void SetDeviceOrigin( wxCoord x, wxCoord y ); - - virtual void SetAxisOrientation( bool xLeftRight, bool yBottomUp ); - - // implementation - // -------------- - - virtual void ComputeScaleAndOrigin(); - - virtual GdkWindow* GetGDKWindow() const { return NULL; } - - wxCoord XDEV2LOG(wxCoord x) const - { - return wxRound((double)(x - m_deviceOriginX) / m_scaleX) * m_signX + m_logicalOriginX; - } - wxCoord XDEV2LOGREL(wxCoord x) const - { - return wxRound((double)(x) / m_scaleX); - } - wxCoord YDEV2LOG(wxCoord y) const - { - return wxRound((double)(y - m_deviceOriginY) / m_scaleY) * m_signY + m_logicalOriginY; - } - wxCoord YDEV2LOGREL(wxCoord y) const - { - return wxRound((double)(y) / m_scaleY); - } - wxCoord XLOG2DEV(wxCoord x) const - { - return wxRound((double)(x - m_logicalOriginX) * m_scaleX) * m_signX + m_deviceOriginX; - } - wxCoord XLOG2DEVREL(wxCoord x) const - { - return wxRound((double)(x) * m_scaleX); - } - wxCoord YLOG2DEV(wxCoord y) const - { - return wxRound((double)(y - m_logicalOriginY) * m_scaleY) * m_signY + m_deviceOriginY; - } - wxCoord YLOG2DEVREL(wxCoord y) const - { - return wxRound((double)(y) * m_scaleY); - } - protected: + // implementation + wxCoord XDEV2LOG(wxCoord x) const { return DeviceToLogicalX(x); } + wxCoord XDEV2LOGREL(wxCoord x) const { return DeviceToLogicalXRel(x); } + wxCoord YDEV2LOG(wxCoord y) const { return DeviceToLogicalY(y); } + wxCoord YDEV2LOGREL(wxCoord y) const { return DeviceToLogicalYRel(y); } + wxCoord XLOG2DEV(wxCoord x) const { return LogicalToDeviceX(x); } + wxCoord XLOG2DEVREL(wxCoord x) const { return LogicalToDeviceXRel(x); } + wxCoord YLOG2DEV(wxCoord y) const { return LogicalToDeviceY(y); } + wxCoord YLOG2DEVREL(wxCoord y) const { return LogicalToDeviceYRel(y); } + // base class pure virtuals implemented here virtual void DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height); virtual void DoGetSizeMM(int* width, int* height) const; -public: - // GTK-specific member variables - - // not sure what for, but what is a mm on a screen you don't know the size - // of? - double m_mm_to_pix_x, - m_mm_to_pix_y; - - bool m_needComputeScaleX, - m_needComputeScaleY; // not yet used - - private: DECLARE_ABSTRACT_CLASS(wxDC) }; diff --git a/include/wx/mac/carbon/dc.h b/include/wx/mac/carbon/dc.h index 0996cabe44..8f1831c0d2 100644 --- a/include/wx/mac/carbon/dc.h +++ b/include/wx/mac/carbon/dc.h @@ -141,72 +141,23 @@ public: virtual int GetDepth() const; virtual wxSize GetPPI() const; - virtual void SetMapMode(int mode); - virtual void SetUserScale(double x, double y); - - virtual void SetLogicalScale(double x, double y); - virtual void SetLogicalOrigin(wxCoord x, wxCoord y); - virtual void SetDeviceOrigin(wxCoord x, wxCoord y); - virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); virtual void SetLogicalFunction(int function); virtual void SetTextForeground(const wxColour& colour); virtual void SetTextBackground(const wxColour& colour); - virtual void ComputeScaleAndOrigin(); - - virtual wxCoord DeviceToLogicalX(wxCoord x) const; - virtual wxCoord DeviceToLogicalY(wxCoord y) const; - virtual wxCoord DeviceToLogicalXRel(wxCoord x) const; - virtual wxCoord DeviceToLogicalYRel(wxCoord y) const; - virtual wxCoord LogicalToDeviceX(wxCoord x) const; - virtual wxCoord LogicalToDeviceY(wxCoord y) const; - virtual wxCoord LogicalToDeviceXRel(wxCoord x) const; - virtual wxCoord LogicalToDeviceYRel(wxCoord y) const ; - public: - wxCoord XDEV2LOG(wxCoord x) const - { - return wxRound((double)(x - m_deviceOriginX) / m_scaleX) * m_signX + m_logicalOriginX; - } - wxCoord XDEV2LOGREL(wxCoord x) const - { - return wxRound((double)(x) / m_scaleX); - } - wxCoord YDEV2LOG(wxCoord y) const - { - return wxRound((double)(y - m_deviceOriginY) / m_scaleY) * m_signY + m_logicalOriginY; - } - wxCoord YDEV2LOGREL(wxCoord y) const - { - return wxRound((double)(y) / m_scaleY); - } - wxCoord XLOG2DEV(wxCoord x) const - { - return wxRound((double)(x - m_logicalOriginX) * m_scaleX) * m_signX + m_deviceOriginX; - } - wxCoord XLOG2DEVREL(wxCoord x) const - { - return wxRound((double)(x) * m_scaleX); - } - wxCoord YLOG2DEV(wxCoord y) const - { - return wxRound((double)(y - m_logicalOriginY) * m_scaleY) * m_signY + m_deviceOriginY; - } - wxCoord YLOG2DEVREL(wxCoord y) const - { - return wxRound((double)(y) * m_scaleY); - } - - wxCoord XLOG2DEVMAC(wxCoord x) const - { - return wxRound((double)(x - m_logicalOriginX) * m_scaleX) * m_signX + m_deviceOriginX + m_macLocalOrigin.x; - } - - wxCoord YLOG2DEVMAC(wxCoord y) const - { - return wxRound((double)(y - m_logicalOriginY) * m_scaleY) * m_signY + m_deviceOriginY + m_macLocalOrigin.y; - } + wxCoord XDEV2LOG(wxCoord x) const { return DeviceToLogicalX( x ); } + wxCoord XDEV2LOGREL(wxCoord x) const { return DeviceToLogicalXRel( x ); } + wxCoord YDEV2LOG(wxCoord y) const { return DeviceToLogicalY( y ); } + wxCoord YDEV2LOGREL(wxCoord y) const { return DeviceToLogicalYRel( y ); } + wxCoord XLOG2DEV(wxCoord x) const { return LogicalToDeviceX( x ); } + wxCoord XLOG2DEVREL(wxCoord x) const { return LogicalToDeviceXRel( x ); } + wxCoord YLOG2DEV(wxCoord y) const { return LogicalToDeviceY( y ); } + wxCoord YLOG2DEVREL(wxCoord y) const { return LogicalToDeviceYRel( y ); } + // probably no longer needed + wxCoord XLOG2DEVMAC(wxCoord x) const { return LogicalToDeviceX( x ); } + wxCoord YLOG2DEVMAC(wxCoord y) const { return LogicalToDeviceY( y ); } #if wxMAC_USE_CORE_GRAPHICS wxGraphicsContext* GetGraphicsContext() { return m_graphicContext; } diff --git a/include/wx/mgl/dc.h b/include/wx/mgl/dc.h index 94bd65c9f6..8c6ae8549e 100644 --- a/include/wx/mgl/dc.h +++ b/include/wx/mgl/dc.h @@ -86,51 +86,21 @@ public: virtual int GetDepth() const; virtual wxSize GetPPI() const; - virtual void SetMapMode(int mode); - virtual void SetUserScale(double x, double y); - virtual void SetLogicalScale(double x, double y); - virtual void SetLogicalOrigin(wxCoord x, wxCoord y); - virtual void SetDeviceOrigin(wxCoord x, wxCoord y); - virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); virtual void SetLogicalFunction(int function); // implementation from now on // -------------------------- virtual void ComputeScaleAndOrigin(); - - wxCoord XDEV2LOG(wxCoord x) const - { - return wxRound((double)(x - m_deviceOriginX) / m_scaleX) * m_signX + m_logicalOriginX; - } - wxCoord XDEV2LOGREL(wxCoord x) const - { - return wxRound((double)(x) / m_scaleX); - } - wxCoord YDEV2LOG(wxCoord y) const - { - return wxRound((double)(y - m_deviceOriginY) / m_scaleY) * m_signY + m_logicalOriginY; - } - wxCoord YDEV2LOGREL(wxCoord y) const - { - return wxRound((double)(y) / m_scaleY); - } - wxCoord XLOG2DEV(wxCoord x) const - { - return wxRound((double)(x - m_logicalOriginX) * m_scaleX) * m_signX + m_deviceOriginX; - } - wxCoord XLOG2DEVREL(wxCoord x) const - { - return wxRound((double)(x) * m_scaleX); - } - wxCoord YLOG2DEV(wxCoord y) const - { - return wxRound((double)(y - m_logicalOriginY) * m_scaleY) * m_signY + m_deviceOriginY; - } - wxCoord YLOG2DEVREL(wxCoord y) const - { - return wxRound((double)(y) * m_scaleY); - } + + wxCoord XDEV2LOG(wxCoord x) const { return DeviceToLogicalX(x); } + wxCoord XDEV2LOGREL(wxCoord x) const { return DeviceToLogicalXRel(x); } + wxCoord YDEV2LOG(wxCoord y) const { return DeviceToLogicalY(y); } + wxCoord YDEV2LOGREL(wxCoord y) const { return DeviceToLogicalYRel(y); } + wxCoord XLOG2DEV(wxCoord x) const { return LogicalToDeviceX(x); } + wxCoord XLOG2DEVREL(wxCoord x) const { return LogicalToDeviceXRel(x); } + wxCoord YLOG2DEV(wxCoord y) const { return LogicalToDeviceY(y); } + wxCoord YLOG2DEVREL(wxCoord y) const { return LogicalToDeviceYRel(y); } MGLDevCtx *GetMGLDC() const { return m_MGLDC; } void SetMGLDC(MGLDevCtx *mgldc, bool OwnsMGLDC = false); diff --git a/include/wx/motif/dc.h b/include/wx/motif/dc.h index 8d60b16414..22f35f8896 100644 --- a/include/wx/motif/dc.h +++ b/include/wx/motif/dc.h @@ -45,18 +45,8 @@ public: wxDC(); virtual ~wxDC() { } - // implement base class pure virtuals - // ---------------------------------- - virtual wxSize GetPPI() const; - virtual void SetMapMode(int mode); - virtual void SetUserScale(double x, double y); - virtual void SetLogicalScale(double x, double y); - virtual void SetLogicalOrigin(wxCoord x, wxCoord y); - virtual void SetDeviceOrigin(wxCoord x, wxCoord y); - virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); - protected: virtual void DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y); virtual void DoDrawBitmap(const wxBitmap &bmp, wxCoord x, wxCoord y, @@ -68,93 +58,25 @@ protected: virtual void DoGetSizeMM(int* width, int* height) const; public: - virtual void ComputeScaleAndOrigin(); - - wxCoord XDEV2LOG(wxCoord x) const - { - wxCoord new_x = x - m_deviceOriginX; - if (new_x > 0) - return (wxCoord)((double)(new_x) / m_scaleX + 0.5) * m_signX + m_logicalOriginX; - else - return (wxCoord)((double)(new_x) / m_scaleX - 0.5) * m_signX + m_logicalOriginX; - } - wxCoord XDEV2LOGREL(wxCoord x) const - { - if (x > 0) - return (wxCoord)((double)(x) / m_scaleX + 0.5); - else - return (wxCoord)((double)(x) / m_scaleX - 0.5); - } - wxCoord YDEV2LOG(wxCoord y) const - { - wxCoord new_y = y - m_deviceOriginY; - if (new_y > 0) - return (wxCoord)((double)(new_y) / m_scaleY + 0.5) * m_signY + m_logicalOriginY; - else - return (wxCoord)((double)(new_y) / m_scaleY - 0.5) * m_signY + m_logicalOriginY; - } - wxCoord YDEV2LOGREL(wxCoord y) const - { - if (y > 0) - return (wxCoord)((double)(y) / m_scaleY + 0.5); - else - return (wxCoord)((double)(y) / m_scaleY - 0.5); - } - wxCoord XLOG2DEV(wxCoord x) const - { - wxCoord new_x = x - m_logicalOriginX; - if (new_x > 0) - return (wxCoord)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX; - else - return (wxCoord)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX; - } + // implementation + wxCoord XDEV2LOG(wxCoord x) const { return DeviceToLogicalX(x); } + wxCoord XDEV2LOGREL(wxCoord x) const { return DeviceToLogicalXRel(x); } + wxCoord YDEV2LOG(wxCoord y) const { return DeviceToLogicalY(y); } + wxCoord YDEV2LOGREL(wxCoord y) const { return DeviceToLogicalYRel(y); } + wxCoord XLOG2DEV(wxCoord x) const { return LogicalToDeviceX(x); } + wxCoord XLOG2DEVREL(wxCoord x) const { return LogicalToDeviceXRel(x); } + wxCoord YLOG2DEV(wxCoord y) const { return LogicalToDeviceY(y); } + wxCoord YLOG2DEVREL(wxCoord y) const { return LogicalToDeviceYRel(y); } + // Without device translation, for backing pixmap purposes wxCoord XLOG2DEV_2(wxCoord x) const { - wxCoord new_x = x - m_logicalOriginX; - if (new_x > 0) - return (wxCoord)((double)(new_x) * m_scaleX + 0.5) * m_signX; - else - return (wxCoord)((double)(new_x) * m_scaleX - 0.5) * m_signX; - } - wxCoord XLOG2DEVREL(wxCoord x) const - { - if (x > 0) - return (wxCoord)((double)(x) * m_scaleX + 0.5); - else - return (wxCoord)((double)(x) * m_scaleX - 0.5); + return wxRound((double)(x - m_logicalOriginX) * m_scaleX) * m_signX; } - wxCoord YLOG2DEV(wxCoord y) const - { - wxCoord new_y = y - m_logicalOriginY; - if (new_y > 0) - return (wxCoord)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY; - else - return (wxCoord)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY; - } - // Without device translation, for backing pixmap purposes wxCoord YLOG2DEV_2(wxCoord y) const { - wxCoord new_y = y - m_logicalOriginY; - if (new_y > 0) - return (wxCoord)((double)(new_y) * m_scaleY + 0.5) * m_signY; - else - return (wxCoord)((double)(new_y) * m_scaleY - 0.5) * m_signY; + return wxRound((double)(y - m_logicalOriginY) * m_scaleY) * m_signY; } - wxCoord YLOG2DEVREL(wxCoord y) const - { - if (y > 0) - return (wxCoord)((double)(y) * m_scaleY + 0.5); - else - return (wxCoord)((double)(y) * m_scaleY - 0.5); - } - -public: - // not sure what for, but what is a mm on a screen you don't know the size of? - double m_mm_to_pix_x,m_mm_to_pix_y; - - // recompute scale? - bool m_needComputeScaleX, m_needComputeScaleY; }; diff --git a/include/wx/msw/dc.h b/include/wx/msw/dc.h index a1e235225f..7f2abb4bf6 100644 --- a/include/wx/msw/dc.h +++ b/include/wx/msw/dc.h @@ -78,22 +78,14 @@ public: virtual int GetDepth() const; virtual wxSize GetPPI() const; - virtual wxCoord DeviceToLogicalX(wxCoord x) const; - virtual wxCoord DeviceToLogicalY(wxCoord y) const; - virtual wxCoord DeviceToLogicalXRel(wxCoord x) const; - virtual wxCoord DeviceToLogicalYRel(wxCoord y) const; - virtual wxCoord LogicalToDeviceX(wxCoord x) const; - virtual wxCoord LogicalToDeviceY(wxCoord y) const; - virtual wxCoord LogicalToDeviceXRel(wxCoord x) const; - virtual wxCoord LogicalToDeviceYRel(wxCoord y) const ; virtual void SetMapMode(int mode); virtual void SetUserScale(double x, double y); - virtual void SetSystemScale(double x, double y); virtual void SetLogicalScale(double x, double y); virtual void SetLogicalOrigin(wxCoord x, wxCoord y); virtual void SetDeviceOrigin(wxCoord x, wxCoord y); virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); + virtual void SetLogicalFunction(int function); // implementation from now on @@ -171,6 +163,8 @@ protected: // classes wxDC() { Init(); } + void RealizeScaleAndOrigin(); + virtual void DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y, wxCoord *descent = NULL, diff --git a/include/wx/os2/dc.h b/include/wx/os2/dc.h index f9d51c9798..e3f48e3710 100644 --- a/include/wx/os2/dc.h +++ b/include/wx/os2/dc.h @@ -140,9 +140,6 @@ public: virtual void SetUserScale( double dX ,double dY ); - virtual void SetSystemScale( double dX - ,double dY - ); virtual void SetLogicalScale( double dX ,double dY ); @@ -157,15 +154,6 @@ public: ); virtual void SetLogicalFunction(int nFunction); - virtual wxCoord DeviceToLogicalX(wxCoord x) const; - virtual wxCoord DeviceToLogicalY(wxCoord y) const; - virtual wxCoord DeviceToLogicalXRel(wxCoord x) const; - virtual wxCoord DeviceToLogicalYRel(wxCoord y) const; - virtual wxCoord LogicalToDeviceX(wxCoord x) const; - virtual wxCoord LogicalToDeviceY(wxCoord y) const; - virtual wxCoord LogicalToDeviceXRel(wxCoord x) const; - virtual wxCoord LogicalToDeviceYRel(wxCoord y) const ; - // implementation from now on // -------------------------- diff --git a/include/wx/x11/dc.h b/include/wx/x11/dc.h index f00e79e833..595126236c 100644 --- a/include/wx/x11/dc.h +++ b/include/wx/x11/dc.h @@ -18,21 +18,6 @@ #include "wx/font.h" #include "wx/gdicmn.h" -//----------------------------------------------------------------------------- -// constants -//----------------------------------------------------------------------------- - -#ifndef MM_TEXT -#define MM_TEXT 0 -#define MM_ISOTROPIC 1 -#define MM_ANISOTROPIC 2 -#define MM_LOMETRIC 3 -#define MM_HIMETRIC 4 -#define MM_TWIPS 5 -#define MM_POINTS 6 -#define MM_METRIC 7 -#endif - //----------------------------------------------------------------------------- // wxDC //----------------------------------------------------------------------------- @@ -48,61 +33,20 @@ public: virtual wxSize GetPPI() const; - virtual void SetMapMode(int mode); - virtual void SetUserScale(double x, double y); - virtual void SetLogicalScale(double x, double y); - virtual void SetLogicalOrigin(wxCoord x, wxCoord y); - virtual void SetDeviceOrigin(wxCoord x, wxCoord y); - virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); - protected: virtual void DoSetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height); virtual void DoGetSizeMM(int* width, int* height) const; -public: - virtual void ComputeScaleAndOrigin(); - - wxCoord XDEV2LOG(wxCoord x) const - { - return wxRound((double)(x - m_deviceOriginX) / m_scaleX) * m_signX + m_logicalOriginX; - } - wxCoord XDEV2LOGREL(wxCoord x) const - { - return wxRound((double)(x) / m_scaleX); - } - wxCoord YDEV2LOG(wxCoord y) const - { - return wxRound((double)(y - m_deviceOriginY) / m_scaleY) * m_signY + m_logicalOriginY; - } - wxCoord YDEV2LOGREL(wxCoord y) const - { - return wxRound((double)(y) / m_scaleY); - } - wxCoord XLOG2DEV(wxCoord x) const - { - return wxRound((double)(x - m_logicalOriginX) * m_scaleX) * m_signX + m_deviceOriginX; - } - wxCoord XLOG2DEVREL(wxCoord x) const - { - return wxRound((double)(x) * m_scaleX); - } - wxCoord YLOG2DEV(wxCoord y) const - { - return wxRound((double)(y - m_logicalOriginY) * m_scaleY) * m_signY + m_deviceOriginY; - } - wxCoord YLOG2DEVREL(wxCoord y) const - { - return wxRound((double)(y) * m_scaleY); - } - -public: - // not sure what for, but what is a mm on a screen you don't know the size of? - double m_mm_to_pix_x,m_mm_to_pix_y; - - // recompute scale? - bool m_needComputeScaleX, m_needComputeScaleY; - + // implementation + wxCoord XDEV2LOG(wxCoord x) const { return DeviceToLogicalX(x); } + wxCoord XDEV2LOGREL(wxCoord x) const { return DeviceToLogicalXRel(x); } + wxCoord YDEV2LOG(wxCoord y) const { return DeviceToLogicalY(y); } + wxCoord YDEV2LOGREL(wxCoord y) const { return DeviceToLogicalYRel(y); } + wxCoord XLOG2DEV(wxCoord x) const { return LogicalToDeviceX(x); } + wxCoord XLOG2DEVREL(wxCoord x) const { return LogicalToDeviceXRel(x); } + wxCoord YLOG2DEV(wxCoord y) const { return LogicalToDeviceY(y); } + wxCoord YLOG2DEVREL(wxCoord y) const { return LogicalToDeviceYRel(y); } private: DECLARE_ABSTRACT_CLASS(wxDC) diff --git a/src/common/dcbase.cpp b/src/common/dcbase.cpp index 8f08d60562..628b7be0df 100644 --- a/src/common/dcbase.cpp +++ b/src/common/dcbase.cpp @@ -42,6 +42,48 @@ IMPLEMENT_ABSTRACT_CLASS(wxDCBase, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxBufferedDC, wxMemoryDC) IMPLEMENT_ABSTRACT_CLASS(wxBufferedPaintDC, wxBufferedDC) +wxDCBase::wxDCBase() + : m_colour(wxColourDisplay()) + , m_ok(true) + , m_clipping(false) + , m_isInteractive(0) + , m_isBBoxValid(false) + , m_logicalOriginX(0), m_logicalOriginY(0) + , m_deviceOriginX(0), m_deviceOriginY(0) + , m_deviceLocalOriginX(0), m_deviceLocalOriginY(0) + , m_logicalScaleX(1.0), m_logicalScaleY(1.0) + , m_userScaleX(1.0), m_userScaleY(1.0) + , m_scaleX(1.0), m_scaleY(1.0) + , m_signX(1), m_signY(1) + , m_minX(0), m_minY(0), m_maxX(0), m_maxY(0) + , m_clipX1(0), m_clipY1(0), m_clipX2(0), m_clipY2(0) + , m_logicalFunction(wxCOPY) + , m_backgroundMode(wxTRANSPARENT) + , m_mappingMode(wxMM_TEXT) + , m_pen() + , m_brush() + , m_backgroundBrush(*wxTRANSPARENT_BRUSH) + , m_textForegroundColour(*wxBLACK) + , m_textBackgroundColour(*wxWHITE) + , m_font() +#if wxUSE_PALETTE + , m_palette() + , m_hasCustomPalette(false) +#endif // wxUSE_PALETTE +{ + m_mm_to_pix_x = (double)wxGetDisplaySize().GetWidth() / + (double)wxGetDisplaySizeMM().GetWidth(); + m_mm_to_pix_y = (double)wxGetDisplaySize().GetHeight() / + (double)wxGetDisplaySizeMM().GetHeight(); + + ResetBoundingBox(); + ResetClipping(); +} + +wxDCBase::~wxDCBase() +{ +} + #if WXWIN_COMPATIBILITY_2_6 void wxDCBase::BeginDrawing() { @@ -52,6 +94,125 @@ void wxDCBase::EndDrawing() } #endif // WXWIN_COMPATIBILITY_2_6 +// ---------------------------------------------------------------------------- +// coordinate conversions and transforms +// ---------------------------------------------------------------------------- + +wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const +{ + return wxRound((double)(x - m_deviceOriginX - m_deviceLocalOriginX) / m_scaleX) * m_signX + m_logicalOriginX; +} + +wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const +{ + return wxRound((double)(y - m_deviceOriginY - m_deviceLocalOriginY) / m_scaleY) * m_signY + m_logicalOriginY; +} + +wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const +{ + return wxRound((double)(x) / m_scaleX); +} + +wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const +{ + return wxRound((double)(y) / m_scaleY); +} + +wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const +{ + return wxRound((double)(x - m_logicalOriginX) * m_scaleX) * m_signX + m_deviceOriginX + m_deviceLocalOriginX; +} + +wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const +{ + return wxRound((double)(y - m_logicalOriginY) * m_scaleY) * m_signY + m_deviceOriginY + m_deviceLocalOriginY; +} + +wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const +{ + return wxRound((double)(x) * m_scaleX); +} + +wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const +{ + return wxRound((double)(y) * m_scaleY); +} + +void wxDCBase::ComputeScaleAndOrigin() +{ + m_scaleX = m_logicalScaleX * m_userScaleX; + m_scaleY = m_logicalScaleY * m_userScaleY; +} + +void wxDCBase::SetMapMode( int mode ) +{ + switch (mode) + { + case wxMM_TWIPS: + SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y ); + break; + case wxMM_POINTS: + SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y ); + break; + case wxMM_METRIC: + SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y ); + break; + case wxMM_LOMETRIC: + SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 ); + break; + default: + case wxMM_TEXT: + SetLogicalScale( 1.0, 1.0 ); + break; + } + m_mappingMode = mode; +} + +void wxDCBase::SetUserScale( double x, double y ) +{ + // allow negative ? -> no + m_userScaleX = x; + m_userScaleY = y; + ComputeScaleAndOrigin(); +} + +void wxDCBase::SetLogicalScale( double x, double y ) +{ + // allow negative ? + m_logicalScaleX = x; + m_logicalScaleY = y; + ComputeScaleAndOrigin(); +} + +void wxDCBase::SetLogicalOrigin( wxCoord x, wxCoord y ) +{ + m_logicalOriginX = x * m_signX; + m_logicalOriginY = y * m_signY; + ComputeScaleAndOrigin(); +} + +void wxDCBase::SetDeviceOrigin( wxCoord x, wxCoord y ) +{ + m_deviceOriginX = x; + m_deviceOriginY = y; + ComputeScaleAndOrigin(); +} + +void wxDCBase::SetDeviceLocalOrigin( wxCoord x, wxCoord y ) +{ + m_deviceLocalOriginX = x; + m_deviceLocalOriginY = y; + ComputeScaleAndOrigin(); +} + +void wxDCBase::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) +{ + // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there + m_signX = (xLeftRight ? 1 : -1); + m_signY = (yBottomUp ? -1 : 1); + ComputeScaleAndOrigin(); +} + // ---------------------------------------------------------------------------- // special symbols // ---------------------------------------------------------------------------- diff --git a/src/common/dcsvg.cpp b/src/common/dcsvg.cpp index ebc4e74c6f..92f539abaf 100644 --- a/src/common/dcsvg.cpp +++ b/src/common/dcsvg.cpp @@ -675,114 +675,36 @@ void wxSVGFileDC::write(const wxString &s) // coordinates transformations // --------------------------------------------------------------------------- -wxCoord wxSVGFileDC::DeviceToLogicalX(wxCoord x) const -{ - return wxRound((x - m_deviceOriginX) / m_scaleX) * m_signX + m_logicalOriginX; -} - -wxCoord wxSVGFileDC::DeviceToLogicalY(wxCoord y) const -{ - return wxRound((y - m_deviceOriginY) / m_scaleY) * m_signY + m_logicalOriginY; -} - -wxCoord wxSVGFileDC::DeviceToLogicalXRel(wxCoord x) const -{ - return wxRound(x / m_scaleX); -} - -wxCoord wxSVGFileDC::DeviceToLogicalYRel(wxCoord y) const -{ - return wxRound(y / m_scaleY); -} - -wxCoord wxSVGFileDC::LogicalToDeviceX(wxCoord x) const -{ - return wxRound((x - m_logicalOriginX) * m_scaleX) * m_signX + m_deviceOriginX; -} - -wxCoord wxSVGFileDC::LogicalToDeviceY(wxCoord y) const -{ - return wxRound((y - m_logicalOriginY) * m_scaleY) * m_signY + m_deviceOriginY; -} - -wxCoord wxSVGFileDC::LogicalToDeviceXRel(wxCoord x) const -{ - return wxRound(x * m_scaleX); -} - -wxCoord wxSVGFileDC::LogicalToDeviceYRel(wxCoord y) const -{ - return wxRound(y * m_scaleY); -} - -void wxSVGFileDC::ComputeScaleAndOrigin() +void wxSVGFileDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) { - m_scaleX = m_logicalScaleX * m_userScaleX; - m_scaleY = m_logicalScaleY * m_userScaleY; + wxDCBase::SetAxisOrientation( xLeftRight, yBottomUp ); } -void wxSVGFileDC::SetMapMode( int mode ) +void wxSVGFileDC::SetMapMode(int mode) { - switch (mode) - { - case wxMM_TWIPS: - SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y ); - break; - case wxMM_POINTS: - SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y ); - break; - case wxMM_METRIC: - SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y ); - break; - case wxMM_LOMETRIC: - SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 ); - break; - default: - case wxMM_TEXT: - SetLogicalScale( 1.0, 1.0 ); - break; - } - m_mappingMode = mode; + wxDCBase::SetMapMode(mode); } -void wxSVGFileDC::SetUserScale( double x, double y ) +void wxSVGFileDC::SetUserScale(double x, double y) { - // allow negative ? -> no - m_userScaleX = x; - m_userScaleY = y; - ComputeScaleAndOrigin(); + wxDCBase::SetUserScale(x,y); } -void wxSVGFileDC::SetLogicalScale( double x, double y ) +void wxSVGFileDC::SetLogicalScale(double x, double y) { - // allow negative ? - m_logicalScaleX = x; - m_logicalScaleY = y; - ComputeScaleAndOrigin(); + wxDCBase::SetLogicalScale(x,y); } -void wxSVGFileDC::SetLogicalOrigin( wxCoord x, wxCoord y ) +void wxSVGFileDC::SetLogicalOrigin(wxCoord x, wxCoord y) { - m_logicalOriginX = x * m_signX; // is this still correct ? - m_logicalOriginY = y * m_signY; - ComputeScaleAndOrigin(); + wxDCBase::SetLogicalOrigin(x,y); } -void wxSVGFileDC::SetDeviceOrigin( wxCoord x, wxCoord y ) +void wxSVGFileDC::SetDeviceOrigin(wxCoord x, wxCoord y) { - // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there - m_deviceOriginX = x; - m_deviceOriginY = y; - ComputeScaleAndOrigin(); + wxDCBase::SetDeviceOrigin(x,y); } -void wxSVGFileDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) -{ - // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there - m_signX = (xLeftRight ? 1 : -1); - m_signY = (yBottomUp ? -1 : 1); - ComputeScaleAndOrigin(); -} #ifdef __BORLANDC__ diff --git a/src/dfb/dc.cpp b/src/dfb/dc.cpp index acfa1eb5b7..004c88c969 100644 --- a/src/dfb/dc.cpp +++ b/src/dfb/dc.cpp @@ -528,132 +528,10 @@ void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y, // mapping modes // --------------------------------------------------------------------------- -void wxDC::ComputeScaleAndOrigin() -{ - m_scaleX = m_logicalScaleX * m_userScaleX; - m_scaleY = m_logicalScaleY * m_userScaleY; - - // FIXME_DFB: scaling affects pixel size of font, pens, brushes, which - // is not currently implemented here; probably makes sense to - // switch to Cairo instead of implementing everything for DFB - wxASSERT_MSG( m_scaleX == 1.0 && m_scaleY == 1.0, - _T("scaling is not implemented in wxDFB") ); -} - -void wxDC::SetMapMode(int mode) -{ - #warning "move this to common code, it's shared by almost all ports!" - switch (mode) - { - case wxMM_TWIPS: - SetLogicalScale(twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y); - break; - case wxMM_POINTS: - SetLogicalScale(pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y); - break; - case wxMM_METRIC: - SetLogicalScale(m_mm_to_pix_x, m_mm_to_pix_y); - break; - case wxMM_LOMETRIC: - SetLogicalScale(m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0); - break; - default: - case wxMM_TEXT: - SetLogicalScale(1.0, 1.0); - break; - } - m_mappingMode = mode; -} - -void wxDC::SetUserScale(double x, double y) -{ - #warning "move this to common code?" - // allow negative ? -> no - m_userScaleX = x; - m_userScaleY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetLogicalScale(double x, double y) -{ - #warning "move this to common code?" - // allow negative ? - m_logicalScaleX = x; - m_logicalScaleY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y ) -{ - #warning "move this to common code?" - m_logicalOriginX = x * m_signX; // is this still correct ? - m_logicalOriginY = y * m_signY; - ComputeScaleAndOrigin(); -} - -void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) -{ - #warning "move this to common code?" - // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there - m_deviceOriginX = x; - m_deviceOriginY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) -{ - #warning "move this to common code?" - // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there - m_signX = (xLeftRight ? 1 : -1); - m_signY = (yBottomUp ? -1 : 1); - ComputeScaleAndOrigin(); -} - -// --------------------------------------------------------------------------- -// coordinates transformations -// --------------------------------------------------------------------------- - -wxCoord wxDC::DeviceToLogicalX(wxCoord x) const -{ - return XDEV2LOG(x); -} - -wxCoord wxDC::DeviceToLogicalY(wxCoord y) const -{ - return YDEV2LOG(y); -} - -wxCoord wxDC::DeviceToLogicalXRel(wxCoord x) const -{ - return XDEV2LOGREL(x); -} - -wxCoord wxDC::DeviceToLogicalYRel(wxCoord y) const -{ - return YDEV2LOGREL(y); -} - -wxCoord wxDC::LogicalToDeviceX(wxCoord x) const -{ - return XLOG2DEV(x); -} - -wxCoord wxDC::LogicalToDeviceY(wxCoord y) const -{ - return YLOG2DEV(y); -} - -wxCoord wxDC::LogicalToDeviceXRel(wxCoord x) const -{ - return XLOG2DEVREL(x); -} - -wxCoord wxDC::LogicalToDeviceYRel(wxCoord y) const -{ - return YLOG2DEVREL(y); -} - - +// FIXME_DFB: scaling affects pixel size of font, pens, brushes, which +// is not currently implemented here; probably makes sense to +// switch to Cairo instead of implementing everything for DFB + void wxDC::DoGetSize(int *w, int *h) const { wxCHECK_RET( Ok(), wxT("invalid dc") ); diff --git a/src/generic/dcpsg.cpp b/src/generic/dcpsg.cpp index 805fe0fd82..a157c1c46c 100644 --- a/src/generic/dcpsg.cpp +++ b/src/generic/dcpsg.cpp @@ -270,6 +270,7 @@ wxPostScriptDC::wxPostScriptDC () m_signX = 1; // default x-axis left to right m_signY = -1; // default y-axis bottom up -> top down + } wxPostScriptDC::wxPostScriptDC (const wxPrintData& printData) @@ -292,6 +293,10 @@ wxPostScriptDC::wxPostScriptDC (const wxPrintData& printData) m_printData = printData; + int h = 0; + GetSize( NULL, &h ); + SetDeviceLocalOrigin( 0, h ); + m_ok = true; } @@ -1480,6 +1485,14 @@ wxCoord wxPostScriptDC::GetCharWidth() const return (wxCoord) (GetCharHeight() * 72.0 / 120.0); } +void wxPostScriptDC::SetPrintData(const wxPrintData& data) +{ + m_printData = data; + + int h = 0; + GetSize( NULL, &h ); + SetDeviceLocalOrigin( 0, h ); +} void wxPostScriptDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) { @@ -1491,15 +1504,29 @@ void wxPostScriptDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) ComputeScaleAndOrigin(); } -void wxPostScriptDC::SetDeviceOrigin( wxCoord x, wxCoord y ) +void wxPostScriptDC::SetMapMode(int mode) { - wxCHECK_RET( m_ok, wxT("invalid postscript dc") ); + wxDCBase::SetMapMode(mode); +} - int h = 0; - int w = 0; - GetSize( &w, &h ); +void wxPostScriptDC::SetUserScale(double x, double y) +{ + wxDCBase::SetUserScale(x,y); +} - wxDC::SetDeviceOrigin( x, h-y ); +void wxPostScriptDC::SetLogicalScale(double x, double y) +{ + wxDCBase::SetLogicalScale(x,y); +} + +void wxPostScriptDC::SetLogicalOrigin(wxCoord x, wxCoord y) +{ + wxDCBase::SetLogicalOrigin(x,y); +} + +void wxPostScriptDC::SetDeviceOrigin(wxCoord x, wxCoord y) +{ + wxDCBase::SetDeviceOrigin(x,y); } void wxPostScriptDC::DoGetSize(int* width, int* height) const diff --git a/src/gtk/dc.cpp b/src/gtk/dc.cpp index 8264117512..be84d8994e 100644 --- a/src/gtk/dc.cpp +++ b/src/gtk/dc.cpp @@ -22,16 +22,6 @@ wxDC::wxDC() { m_ok = FALSE; - m_mm_to_pix_x = (double)wxGetDisplaySize().GetWidth() / - (double)wxGetDisplaySizeMM().GetWidth(); - m_mm_to_pix_y = (double)wxGetDisplaySize().GetHeight() / - (double)wxGetDisplaySizeMM().GetHeight(); - - m_needComputeScaleX = FALSE; /* not used yet */ - m_needComputeScaleY = FALSE; /* not used yet */ - - m_logicalFunction = wxCOPY; - m_pen = *wxBLACK_PEN; m_font = *wxNORMAL_FONT; m_brush = *wxWHITE_BRUSH; @@ -65,124 +55,3 @@ wxSize wxDC::GetPPI() const // TODO (should probably be pure virtual) return wxSize(0, 0); } - -// --------------------------------------------------------------------------- -// set various DC parameters -// --------------------------------------------------------------------------- - -wxCoord wxDC::DeviceToLogicalX(wxCoord x) const -{ - return wxRound((x - m_deviceOriginX) / m_scaleX) * m_signX + m_logicalOriginX; -} - -wxCoord wxDC::DeviceToLogicalY(wxCoord y) const -{ - return wxRound((y - m_deviceOriginY) / m_scaleY) * m_signY + m_logicalOriginY; -} - -wxCoord wxDC::DeviceToLogicalXRel(wxCoord x) const -{ - return wxRound(x / m_scaleX); -} - -wxCoord wxDC::DeviceToLogicalYRel(wxCoord y) const -{ - return wxRound(y / m_scaleY); -} - -wxCoord wxDC::LogicalToDeviceX(wxCoord x) const -{ - return wxRound((x - m_logicalOriginX) * m_scaleX) * m_signX + m_deviceOriginX; -} - -wxCoord wxDC::LogicalToDeviceY(wxCoord y) const -{ - return wxRound((y - m_logicalOriginY) * m_scaleY) * m_signY + m_deviceOriginY; -} - -wxCoord wxDC::LogicalToDeviceXRel(wxCoord x) const -{ - return wxRound(x * m_scaleX); -} - -wxCoord wxDC::LogicalToDeviceYRel(wxCoord y) const -{ - return wxRound(y * m_scaleY); -} - -void wxDC::ComputeScaleAndOrigin() -{ - m_scaleX = m_logicalScaleX * m_userScaleX; - m_scaleY = m_logicalScaleY * m_userScaleY; -} - -void wxDC::SetMapMode( int mode ) -{ - switch (mode) - { - case wxMM_TWIPS: - SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y ); - break; - case wxMM_POINTS: - SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y ); - break; - case wxMM_METRIC: - SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y ); - break; - case wxMM_LOMETRIC: - SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 ); - break; - default: - case wxMM_TEXT: - SetLogicalScale( 1.0, 1.0 ); - break; - } - m_mappingMode = mode; - -/* we don't do this mega optimisation - if (mode != wxMM_TEXT) - { - m_needComputeScaleX = TRUE; - m_needComputeScaleY = TRUE; - } -*/ -} - -void wxDC::SetUserScale( double x, double y ) -{ - // allow negative ? -> no - m_userScaleX = x; - m_userScaleY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetLogicalScale( double x, double y ) -{ - // allow negative ? - m_logicalScaleX = x; - m_logicalScaleY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y ) -{ - m_logicalOriginX = x * m_signX; // is this still correct ? - m_logicalOriginY = y * m_signY; - ComputeScaleAndOrigin(); -} - -void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) -{ - // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there - m_deviceOriginX = x; - m_deviceOriginY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) -{ - // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there - m_signX = (xLeftRight ? 1 : -1); - m_signY = (yBottomUp ? -1 : 1); - ComputeScaleAndOrigin(); -} diff --git a/src/gtk1/dc.cpp b/src/gtk1/dc.cpp index 7247e564c3..53b451a8f3 100644 --- a/src/gtk1/dc.cpp +++ b/src/gtk1/dc.cpp @@ -69,168 +69,3 @@ wxSize wxDC::GetPPI() const return wxSize(0, 0); } -// --------------------------------------------------------------------------- -// set various DC parameters -// --------------------------------------------------------------------------- - -wxCoord wxDC::DeviceToLogicalX(wxCoord x) const -{ - return wxRound((x - m_deviceOriginX) / m_scaleX) * m_signX + m_logicalOriginX; -} - -wxCoord wxDC::DeviceToLogicalY(wxCoord y) const -{ - return wxRound((y - m_deviceOriginY) / m_scaleY) * m_signY + m_logicalOriginY; -} - -wxCoord wxDC::DeviceToLogicalXRel(wxCoord x) const -{ - return wxRound(x / m_scaleX); -} - -wxCoord wxDC::DeviceToLogicalYRel(wxCoord y) const -{ - return wxRound(y / m_scaleY); -} - -wxCoord wxDC::LogicalToDeviceX(wxCoord x) const -{ - return wxRound((x - m_logicalOriginX) * m_scaleX) * m_signX + m_deviceOriginX; -} - -wxCoord wxDC::LogicalToDeviceY(wxCoord y) const -{ - return wxRound((y - m_logicalOriginY) * m_scaleY) * m_signY + m_deviceOriginY; -} - -wxCoord wxDC::LogicalToDeviceXRel(wxCoord x) const -{ - return wxRound(x * m_scaleX); -} - -wxCoord wxDC::LogicalToDeviceYRel(wxCoord y) const -{ - return wxRound(y * m_scaleY); -} - -void wxDC::ComputeScaleAndOrigin() -{ - m_scaleX = m_logicalScaleX * m_userScaleX; - m_scaleY = m_logicalScaleY * m_userScaleY; -} - -void wxDC::SetMapMode( int mode ) -{ - switch (mode) - { - case wxMM_TWIPS: - SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y ); - break; - case wxMM_POINTS: - SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y ); - break; - case wxMM_METRIC: - SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y ); - break; - case wxMM_LOMETRIC: - SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 ); - break; - default: - case wxMM_TEXT: - SetLogicalScale( 1.0, 1.0 ); - break; - } - m_mappingMode = mode; - -/* we don't do this mega optimisation - if (mode != wxMM_TEXT) - { - m_needComputeScaleX = TRUE; - m_needComputeScaleY = TRUE; - } -*/ -} - -void wxDC::SetUserScale( double x, double y ) -{ - // allow negative ? -> no - m_userScaleX = x; - m_userScaleY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetLogicalScale( double x, double y ) -{ - // allow negative ? - m_logicalScaleX = x; - m_logicalScaleY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y ) -{ - m_logicalOriginX = x * m_signX; // is this still correct ? - m_logicalOriginY = y * m_signY; - ComputeScaleAndOrigin(); -} - -void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) -{ - // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there - m_deviceOriginX = x; - m_deviceOriginY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) -{ - // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there - m_signX = (xLeftRight ? 1 : -1); - m_signY = (yBottomUp ? -1 : 1); - ComputeScaleAndOrigin(); -} - -// --------------------------------------------------------------------------- -// coordinates transformations -// --------------------------------------------------------------------------- - -wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const -{ - return ((wxDC *)this)->XDEV2LOG(x); -} - -wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const -{ - return ((wxDC *)this)->YDEV2LOG(y); -} - -wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const -{ - return ((wxDC *)this)->XDEV2LOGREL(x); -} - -wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const -{ - return ((wxDC *)this)->YDEV2LOGREL(y); -} - -wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const -{ - return ((wxDC *)this)->XLOG2DEV(x); -} - -wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const -{ - return ((wxDC *)this)->YLOG2DEV(y); -} - -wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const -{ - return ((wxDC *)this)->XLOG2DEVREL(x); -} - -wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const -{ - return ((wxDC *)this)->YLOG2DEVREL(y); -} - diff --git a/src/mac/carbon/dc.cpp b/src/mac/carbon/dc.cpp index 45d060c38a..79195c147d 100644 --- a/src/mac/carbon/dc.cpp +++ b/src/mac/carbon/dc.cpp @@ -262,26 +262,11 @@ wxDC::wxDC() { m_ok = false; m_colour = true; - m_mm_to_pix_x = mm2pt; - m_mm_to_pix_y = mm2pt; - m_internalDeviceOriginX = 0; - m_internalDeviceOriginY = 0; - m_externalDeviceOriginX = 0; - m_externalDeviceOriginY = 0; - m_logicalScaleX = 1.0; - m_logicalScaleY = 1.0; - m_userScaleX = 1.0; - m_userScaleY = 1.0; - m_scaleX = 1.0; - m_scaleY = 1.0; - m_needComputeScaleX = false; - m_needComputeScaleY = false; m_macPort = NULL ; m_macMask = NULL ; m_macFontInstalled = false ; m_macBrushInstalled = false ; m_macPenInstalled = false ; - m_macLocalOrigin.x = m_macLocalOrigin.y = 0 ; m_macBoundaryClipRgn = NewRgn() ; m_macCurrentClipRgn = NewRgn() ; SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , -32000 , -32000 , 32000 , 32000 ) ; @@ -567,77 +552,6 @@ void wxDC::SetTextBackground( const wxColour &col ) m_macFontInstalled = false ; } -void wxDC::SetMapMode( int mode ) -{ - switch (mode) - { - case wxMM_TWIPS: - SetLogicalScale( twips2mm * m_mm_to_pix_x, twips2mm * m_mm_to_pix_y ); - break; - - case wxMM_POINTS: - SetLogicalScale( pt2mm * m_mm_to_pix_x, pt2mm * m_mm_to_pix_y ); - break; - - case wxMM_METRIC: - SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y ); - break; - - case wxMM_LOMETRIC: - SetLogicalScale( m_mm_to_pix_x / 10.0, m_mm_to_pix_y / 10.0 ); - break; - - default: - case wxMM_TEXT: - SetLogicalScale( 1.0, 1.0 ); - break; - } - - if (mode != wxMM_TEXT) - { - m_needComputeScaleX = true; - m_needComputeScaleY = true; - } -} - -void wxDC::SetUserScale( double x, double y ) -{ - // allow negative ? -> no - m_userScaleX = x; - m_userScaleY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetLogicalScale( double x, double y ) -{ - // allow negative ? - m_logicalScaleX = x; - m_logicalScaleY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y ) -{ - // is this still correct ? - m_logicalOriginX = x * m_signX; - m_logicalOriginY = y * m_signY; - ComputeScaleAndOrigin(); -} - -void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) -{ - m_externalDeviceOriginX = x; - m_externalDeviceOriginY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) -{ - m_signX = (xLeftRight ? 1 : -1); - m_signY = (yBottomUp ? -1 : 1); - ComputeScaleAndOrigin(); -} - wxSize wxDC::GetPPI() const { return wxSize(72, 72); @@ -651,27 +565,6 @@ int wxDC::GetDepth() const return 1 ; } -void wxDC::ComputeScaleAndOrigin() -{ - // CMB: copy scale to see if it changes - double origScaleX = m_scaleX; - double origScaleY = m_scaleY; - m_scaleX = m_logicalScaleX * m_userScaleX; - m_scaleY = m_logicalScaleY * m_userScaleY; - m_deviceOriginX = m_internalDeviceOriginX + m_externalDeviceOriginX; - m_deviceOriginY = m_internalDeviceOriginY + m_externalDeviceOriginY; - - // CMB: if scale has changed call SetPen to recalulate the line width - if (m_scaleX != origScaleX || m_scaleY != origScaleY) - { - // this is a bit artificial, but we need to force wxDC to think - // the pen has changed - wxPen pen(GetPen()); - m_pen = wxNullPen; - SetPen(pen); - } -} - void wxDC::SetPalette( const wxPalette& palette ) { } @@ -1580,7 +1473,7 @@ void wxDC::DoDrawRotatedText(const wxString& str, wxCoord x, wxCoord y, IntToFixed(drawX) , IntToFixed(drawY) , &rect ); wxASSERT_MSG( status == noErr , wxT("couldn't measure the rotated text") ); - OffsetRect( &rect , -m_macLocalOrigin.x , -m_macLocalOrigin.y ) ; + OffsetRect( &rect , -m_deviceLocalOriginX , -m_deviceLocalOriginY ) ; CalcBoundingBox(XDEV2LOG(rect.left), YDEV2LOG(rect.top) ); CalcBoundingBox(XDEV2LOG(rect.right), YDEV2LOG(rect.bottom) ); ::ATSUDisposeTextLayout(atsuLayout); diff --git a/src/mac/carbon/dcclient.cpp b/src/mac/carbon/dcclient.cpp index 27164c2c9e..880d184926 100644 --- a/src/mac/carbon/dcclient.cpp +++ b/src/mac/carbon/dcclient.cpp @@ -150,12 +150,12 @@ wxWindowDC::wxWindowDC(wxWindow *window) int x , y ; x = y = 0 ; window->MacWindowToRootWindow( &x , &y ) ; - m_macLocalOrigin.x = x ; - m_macLocalOrigin.y = y ; + m_deviceLocalOriginX = x; + m_deviceLocalOriginY = y; m_macPort = UMAGetWindowPort( (WindowRef) rootwindow->MacGetWindowRef() ) ; CopyRgn( (RgnHandle) window->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; - OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; + OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_deviceLocalOriginX , m_deviceLocalOriginY ) ; CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; #endif SetBackground(MacGetBackgroundBrush(window)); @@ -281,12 +281,12 @@ wxClientDC::wxClientDC(wxWindow *window) m_macPort = UMAGetWindowPort( windowref ) ; m_ok = true ; - m_macLocalOrigin.x = x ; - m_macLocalOrigin.y = y ; + m_deviceLocalOriginX = x ; + m_deviceLocalOriginY = y ; SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ; SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ; - OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; + OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_deviceLocalOriginX , m_deviceLocalOriginY ) ; CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ; SetBackground(MacGetBackgroundBrush(window)); @@ -356,13 +356,13 @@ wxPaintDC::wxPaintDC(wxWindow *window) } // there is no out-of-order drawing on OSX #else - m_macLocalOrigin.x = x ; - m_macLocalOrigin.y = y ; + m_deviceLocalOriginX = x ; + m_deviceLocalOriginY = y ; SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ; SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ; SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->GetUpdateRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; - OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; + OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_deviceLocalOriginX , m_deviceLocalOriginY ) ; CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; SetBackground(MacGetBackgroundBrush(window)); #endif diff --git a/src/mac/carbon/dcprint.cpp b/src/mac/carbon/dcprint.cpp index 58b2eb7a13..93102ac245 100644 --- a/src/mac/carbon/dcprint.cpp +++ b/src/mac/carbon/dcprint.cpp @@ -224,8 +224,7 @@ void wxMacCarbonPrinterDC::StartPage( wxPrinterDC* dc ) CGContextTranslateCTM( pageContext , -paperRect.left , paperRect.bottom ) ; CGContextScaleCTM( pageContext , 1 , -1 ) ; #else - dc->m_macLocalOrigin.x = (int) rPage.left; - dc->m_macLocalOrigin.y = (int) rPage.top; + dc->SetDeviceLocalOrigin( (wxCoord) rPage.left, (wxCoord) rPage.top ); #endif } // since this is a non-critical error, we set the flag back diff --git a/src/mac/carbon/dcscreen.cpp b/src/mac/carbon/dcscreen.cpp index 4c985b910f..07e8218b4b 100644 --- a/src/mac/carbon/dcscreen.cpp +++ b/src/mac/carbon/dcscreen.cpp @@ -43,8 +43,8 @@ wxScreenDC::wxScreenDC() Point pt = { 0,0 } ; LocalToGlobal( &pt ) ; SetPort( port ) ; - m_macLocalOrigin.x = -pt.h ; - m_macLocalOrigin.y = -pt.v ; + m_deviceLocalOriginX = -pt.h ; + m_deviceLocalOriginY = -pt.v ; BitMap screenBits; GetQDGlobalsScreenBits( &screenBits ); @@ -58,7 +58,7 @@ wxScreenDC::wxScreenDC() m_maxY = screenBits.bounds.bottom ; MacSetRectRgn( (RgnHandle) m_macBoundaryClipRgn , m_minX , m_minY , m_maxX , m_maxY ) ; - OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; + OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_deviceLocalOriginX , m_deviceLocalOriginY ) ; CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; #endif m_ok = true ; diff --git a/src/mgl/dc.cpp b/src/mgl/dc.cpp index 08c78c6a1d..7ec1cb6030 100644 --- a/src/mgl/dc.cpp +++ b/src/mgl/dc.cpp @@ -1250,7 +1250,6 @@ void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y, } - // --------------------------------------------------------------------------- // mapping modes // --------------------------------------------------------------------------- @@ -1270,114 +1269,6 @@ void wxDC::ComputeScaleAndOrigin() m_scaleX = newX, m_scaleY = newY; } -void wxDC::SetMapMode(int mode) -{ - switch (mode) - { - case wxMM_TWIPS: - SetLogicalScale(twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y); - break; - case wxMM_POINTS: - SetLogicalScale(pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y); - break; - case wxMM_METRIC: - SetLogicalScale(m_mm_to_pix_x, m_mm_to_pix_y); - break; - case wxMM_LOMETRIC: - SetLogicalScale(m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0); - break; - default: - case wxMM_TEXT: - SetLogicalScale(1.0, 1.0); - break; - } - m_mappingMode = mode; -} - -void wxDC::SetUserScale( double x, double y ) -{ - // allow negative ? -> no - m_userScaleX = x; - m_userScaleY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetLogicalScale( double x, double y ) -{ - // allow negative ? - m_logicalScaleX = x; - m_logicalScaleY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y ) -{ - m_logicalOriginX = x * m_signX; // is this still correct ? - m_logicalOriginY = y * m_signY; - ComputeScaleAndOrigin(); -} - -void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) -{ - // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there - m_deviceOriginX = x; - m_deviceOriginY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) -{ - // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there - m_signX = (xLeftRight ? 1 : -1); - m_signY = (yBottomUp ? -1 : 1); - ComputeScaleAndOrigin(); -} - -// --------------------------------------------------------------------------- -// coordinates transformations -// --------------------------------------------------------------------------- - -wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const -{ - return ((wxDC *)this)->XDEV2LOG(x); -} - -wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const -{ - return ((wxDC *)this)->YDEV2LOG(y); -} - -wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const -{ - return ((wxDC *)this)->XDEV2LOGREL(x); -} - -wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const -{ - return ((wxDC *)this)->YDEV2LOGREL(y); -} - -wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const -{ - return ((wxDC *)this)->XLOG2DEV(x); -} - -wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const -{ - return ((wxDC *)this)->YLOG2DEV(y); -} - -wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const -{ - return ((wxDC *)this)->XLOG2DEVREL(x); -} - -wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const -{ - return ((wxDC *)this)->YLOG2DEVREL(y); -} - - void wxDC::DoGetSize(int *w, int *h) const { if (w) *w = m_MGLDC->sizex()+1; diff --git a/src/motif/dc.cpp b/src/motif/dc.cpp index 939442bd32..042d25d8c7 100644 --- a/src/motif/dc.cpp +++ b/src/motif/dc.cpp @@ -28,9 +28,6 @@ wxDC::wxDC() { m_ok = false; - m_mm_to_pix_x = 1.0; - m_mm_to_pix_y = 1.0; - m_backgroundMode = wxTRANSPARENT; m_isInteractive = false; @@ -102,115 +99,3 @@ wxSize wxDC::GetPPI() const // TODO (should probably be pure virtual) return wxSize(0, 0); } - -void wxDC::SetMapMode( int mode ) -{ - switch (mode) - { - case wxMM_TWIPS: - SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y ); - break; - case wxMM_POINTS: - SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y ); - break; - case wxMM_METRIC: - SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y ); - break; - case wxMM_LOMETRIC: - SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 ); - break; - default: - case wxMM_TEXT: - SetLogicalScale( 1.0, 1.0 ); - break; - } - if (mode != wxMM_TEXT) - { - m_needComputeScaleX = true; - m_needComputeScaleY = true; - } -} - -void wxDC::SetUserScale( double x, double y ) -{ - // allow negative ? -> no - m_userScaleX = x; - m_userScaleY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetLogicalScale( double x, double y ) -{ - // allow negative ? - m_logicalScaleX = x; - m_logicalScaleY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y ) -{ - m_logicalOriginX = x * m_signX; // is this still correct ? - m_logicalOriginY = y * m_signY; - ComputeScaleAndOrigin(); -} - -void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) -{ - // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there - m_deviceOriginX = x; - m_deviceOriginY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) -{ - m_signX = xLeftRight ? 1 : -1; - m_signY = yBottomUp ? -1 : 1; - ComputeScaleAndOrigin(); -} - -wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const -{ - return ((wxDC *)this)->XDEV2LOG(x); -} - -wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const -{ - return ((wxDC *)this)->YDEV2LOG(y); -} - -wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const -{ - return ((wxDC *)this)->XDEV2LOGREL(x); -} - -wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const -{ - return ((wxDC *)this)->YDEV2LOGREL(y); -} - -wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const -{ - return ((wxDC *)this)->XLOG2DEV(x); -} - -wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const -{ - return ((wxDC *)this)->YLOG2DEV(y); -} - -wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const -{ - return ((wxDC *)this)->XLOG2DEVREL(x); -} - -wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const -{ - return ((wxDC *)this)->YLOG2DEVREL(y); -} - -void wxDC::ComputeScaleAndOrigin() -{ - m_scaleX = m_logicalScaleX * m_userScaleX; - m_scaleY = m_logicalScaleY * m_userScaleY; -} diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index d13264eec0..2a205d5f01 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -585,17 +585,7 @@ void wxDC::Clear() ::FillRect(GetHdc(), &rect, brush); ::DeleteObject(brush); -#ifndef __WXWINCE__ - int width = DeviceToLogicalXRel(VIEWPORT_EXTENT)*m_signX, - height = DeviceToLogicalYRel(VIEWPORT_EXTENT)*m_signY; - - ::SetMapMode(GetHdc(), MM_ANISOTROPIC); - - ::SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT, VIEWPORT_EXTENT, NULL); - ::SetWindowExtEx(GetHdc(), width, height, NULL); - ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX, (int)m_deviceOriginY, NULL); - ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); -#endif + RealizeScaleAndOrigin(); } bool wxDC::DoFloodFill(wxCoord WXUNUSED_IN_WINCE(x), @@ -1851,8 +1841,25 @@ bool wxDC::DoGetPartialTextExtents(const wxString& text, wxArrayInt& widths) con return true; } +void wxDC::RealizeScaleAndOrigin() +{ + // VZ: it seems very wasteful to always use MM_ANISOTROPIC when in 99% of + // cases we could do with MM_TEXT and in the remaining 0.9% with + // MM_ISOTROPIC (TODO!) +#ifndef __WXWINCE__ + ::SetMapMode(GetHdc(), MM_ANISOTROPIC); + int width = DeviceToLogicalXRel(VIEWPORT_EXTENT)*m_signX, + height = DeviceToLogicalYRel(VIEWPORT_EXTENT)*m_signY; + ::SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT, VIEWPORT_EXTENT, NULL); + ::SetWindowExtEx(GetHdc(), width, height, NULL); + + ::SetViewportOrgEx(GetHdc(), m_deviceOriginX, m_deviceOriginY, NULL); + ::SetWindowOrgEx(GetHdc(), m_logicalOriginX, m_logicalOriginY, NULL); +#endif + +} void wxDC::SetMapMode(int mode) { @@ -1907,22 +1914,10 @@ void wxDC::SetMapMode(int mode) wxFAIL_MSG( _T("unknown mapping mode in SetMapMode") ); } } - - // VZ: it seems very wasteful to always use MM_ANISOTROPIC when in 99% of - // cases we could do with MM_TEXT and in the remaining 0.9% with - // MM_ISOTROPIC (TODO!) -#ifndef __WXWINCE__ - ::SetMapMode(GetHdc(), MM_ANISOTROPIC); - - int width = DeviceToLogicalXRel(VIEWPORT_EXTENT)*m_signX, - height = DeviceToLogicalYRel(VIEWPORT_EXTENT)*m_signY; - - ::SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT, VIEWPORT_EXTENT, NULL); - ::SetWindowExtEx(GetHdc(), width, height, NULL); - - ::SetViewportOrgEx(GetHdc(), m_deviceOriginX, m_deviceOriginY, NULL); - ::SetWindowOrgEx(GetHdc(), m_logicalOriginX, m_logicalOriginY, NULL); -#endif + + ComputeScaleAndOrigin(); + + RealizeScaleAndOrigin(); } void wxDC::SetUserScale(double x, double y) @@ -1932,44 +1927,25 @@ void wxDC::SetUserScale(double x, double y) if ( x == m_userScaleX && y == m_userScaleY ) return; - m_userScaleX = x; - m_userScaleY = y; - - this->SetMapMode(m_mappingMode); + wxDCBase::SetUserScale(x,y); + + RealizeScaleAndOrigin(); } -void wxDC::SetAxisOrientation(bool WXUNUSED_IN_WINCE(xLeftRight), - bool WXUNUSED_IN_WINCE(yBottomUp)) +void wxDC::SetAxisOrientation(bool xLeftRight, + bool yBottomUp) { WXMICROWIN_CHECK_HDC -#ifndef __WXWINCE__ int signX = xLeftRight ? 1 : -1, signY = yBottomUp ? -1 : 1; - - if ( signX != m_signX || signY != m_signY ) - { - m_signX = signX; - m_signY = signY; - - SetMapMode(m_mappingMode); - } -#endif -} - -void wxDC::SetSystemScale(double x, double y) -{ - WXMICROWIN_CHECK_HDC - - if ( x == m_scaleX && y == m_scaleY ) + + if (signX == m_signX && signY == m_signY) return; + + wxDCBase::SetAxisOrientation( xLeftRight, yBottomUp ); - m_scaleX = x; - m_scaleY = y; - -#ifndef __WXWINCE__ - SetMapMode(m_mappingMode); -#endif + RealizeScaleAndOrigin(); } void wxDC::SetLogicalOrigin(wxCoord x, wxCoord y) @@ -1979,8 +1955,7 @@ void wxDC::SetLogicalOrigin(wxCoord x, wxCoord y) if ( x == m_logicalOriginX && y == m_logicalOriginY ) return; - m_logicalOriginX = x; - m_logicalOriginY = y; + wxDCBase::SetLogicalOrigin( x, y ); #ifndef __WXWINCE__ ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); @@ -1993,64 +1968,16 @@ void wxDC::SetDeviceOrigin(wxCoord x, wxCoord y) if ( x == m_deviceOriginX && y == m_deviceOriginY ) return; - - m_deviceOriginX = x; - m_deviceOriginY = y; + + wxDCBase::SetDeviceOrigin( x, y ); ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX, (int)m_deviceOriginY, NULL); } -// --------------------------------------------------------------------------- -// coordinates transformations -// --------------------------------------------------------------------------- - -wxCoord wxDC::DeviceToLogicalX(wxCoord x) const -{ - return DeviceToLogicalXRel(x - m_deviceOriginX)*m_signX + m_logicalOriginX; -} - -wxCoord wxDC::DeviceToLogicalXRel(wxCoord x) const -{ - // axis orientation is not taken into account for conversion of a distance - return (wxCoord)(x / (m_logicalScaleX*m_userScaleX*m_scaleX)); -} - -wxCoord wxDC::DeviceToLogicalY(wxCoord y) const -{ - return DeviceToLogicalYRel(y - m_deviceOriginY)*m_signY + m_logicalOriginY; -} - -wxCoord wxDC::DeviceToLogicalYRel(wxCoord y) const -{ - // axis orientation is not taken into account for conversion of a distance - return (wxCoord)( y / (m_logicalScaleY*m_userScaleY*m_scaleY)); -} - -wxCoord wxDC::LogicalToDeviceX(wxCoord x) const -{ - return LogicalToDeviceXRel(x - m_logicalOriginX)*m_signX + m_deviceOriginX; -} - -wxCoord wxDC::LogicalToDeviceXRel(wxCoord x) const -{ - // axis orientation is not taken into account for conversion of a distance - return (wxCoord) (x*m_logicalScaleX*m_userScaleX*m_scaleX); -} - -wxCoord wxDC::LogicalToDeviceY(wxCoord y) const -{ - return LogicalToDeviceYRel(y - m_logicalOriginY)*m_signY + m_deviceOriginY; -} - -wxCoord wxDC::LogicalToDeviceYRel(wxCoord y) const -{ - // axis orientation is not taken into account for conversion of a distance - return (wxCoord) (y*m_logicalScaleY*m_userScaleY*m_scaleY); -} - // --------------------------------------------------------------------------- // bit blit // --------------------------------------------------------------------------- + bool wxDC::DoBlit(wxCoord dstX, wxCoord dstY, wxCoord dstWidth, wxCoord dstHeight, wxDC *source, @@ -2417,8 +2344,7 @@ void wxDC::SetLogicalScale(double x, double y) { WXMICROWIN_CHECK_HDC - m_logicalScaleX = x; - m_logicalScaleY = y; + wxDCBase::SetLogicalScale(x,y); } // ---------------------------------------------------------------------------- diff --git a/src/os2/dc.cpp b/src/os2/dc.cpp index ab694e6a95..3e6e349b6a 100644 --- a/src/os2/dc.cpp +++ b/src/os2/dc.cpp @@ -2294,6 +2294,9 @@ void wxDC::SetMapMode( m_nWindowExtX = (int)MS_XDEV2LOG(VIEWPORT_EXTENT); m_nWindowExtY = (int)MS_YDEV2LOG(VIEWPORT_EXTENT); // ???? + + ComputeScaleAndOrigin(); + }; // end of wxDC::SetMapMode void wxDC::SetUserScale( double dX, @@ -2314,17 +2317,6 @@ void wxDC::SetAxisOrientation( bool bXLeftRight, SetMapMode(m_mappingMode); } // end of wxDC::SetAxisOrientation -void wxDC::SetSystemScale( - double dX -, double dY -) -{ - m_scaleX = dX; - m_scaleY = dY; - - SetMapMode(m_mappingMode); -} // end of wxDC::SetSystemScale - void wxDC::SetLogicalOrigin( wxCoord vX , wxCoord vY @@ -2365,54 +2357,6 @@ void wxDC::SetDeviceOrigin( ); }; // end of wxDC::SetDeviceOrigin -// --------------------------------------------------------------------------- -// coordinates transformations -// --------------------------------------------------------------------------- - -wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const -{ - return (wxCoord) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX) - m_logicalOriginX); -} - -wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const -{ - // axis orientation is not taken into account for conversion of a distance - return (wxCoord) ((x)/(m_logicalScaleX*m_userScaleX*m_scaleX)); -} - -wxCoord wxDC::DeviceToLogicalY(wxCoord y) const -{ - return (wxCoord) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY) - m_logicalOriginY); -} - -wxCoord wxDC::DeviceToLogicalYRel(wxCoord y) const -{ - // axis orientation is not taken into account for conversion of a distance - return (wxCoord) ((y)/(m_logicalScaleY*m_userScaleY*m_scaleY)); -} - -wxCoord wxDC::LogicalToDeviceX(wxCoord x) const -{ - return (wxCoord) ((x - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX + m_deviceOriginX); -} - -wxCoord wxDC::LogicalToDeviceXRel(wxCoord x) const -{ - // axis orientation is not taken into account for conversion of a distance - return (wxCoord) (x*m_logicalScaleX*m_userScaleX*m_scaleX); -} - -wxCoord wxDC::LogicalToDeviceY(wxCoord y) const -{ - return (wxCoord) ((y - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY + m_deviceOriginY); -} - -wxCoord wxDC::LogicalToDeviceYRel(wxCoord y) const -{ - // axis orientation is not taken into account for conversion of a distance - return (wxCoord) (y*m_logicalScaleY*m_userScaleY*m_scaleY); -} - // --------------------------------------------------------------------------- // bit blit // --------------------------------------------------------------------------- diff --git a/src/x11/dc.cpp b/src/x11/dc.cpp index 6d81131809..1433d94f4a 100644 --- a/src/x11/dc.cpp +++ b/src/x11/dc.cpp @@ -28,28 +28,11 @@ wxDC::wxDC() { m_ok = false; -#if 1 - m_mm_to_pix_x = 1.0; - m_mm_to_pix_y = 1.0; -#else - m_mm_to_pix_x = (double)wxGetDisplaySize().GetWidth() / - (double)wxGetDisplaySizeMM().GetWidth(); - m_mm_to_pix_y = (double)wxGetDisplaySize().GetHeight() / - (double)wxGetDisplaySizeMM().GetHeight(); -#endif - - m_needComputeScaleX = false; /* not used yet */ - m_needComputeScaleY = false; /* not used yet */ - - m_logicalFunction = wxCOPY; - m_pen = *wxBLACK_PEN; m_font = *wxNORMAL_FONT; m_brush = *wxWHITE_BRUSH; m_backgroundMode = wxTRANSPARENT; - - m_isInteractive = false; // ??? } void wxDC::DoSetClippingRegion( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) @@ -78,115 +61,3 @@ wxSize wxDC::GetPPI() const // TODO (should probably be pure virtual) return wxSize(0, 0); } - -void wxDC::SetMapMode( int mode ) -{ - switch (mode) - { - case wxMM_TWIPS: - SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y ); - break; - case wxMM_POINTS: - SetLogicalScale( pt2mm*m_mm_to_pix_x, pt2mm*m_mm_to_pix_y ); - break; - case wxMM_METRIC: - SetLogicalScale( m_mm_to_pix_x, m_mm_to_pix_y ); - break; - case wxMM_LOMETRIC: - SetLogicalScale( m_mm_to_pix_x/10.0, m_mm_to_pix_y/10.0 ); - break; - default: - case wxMM_TEXT: - SetLogicalScale( 1.0, 1.0 ); - break; - } - if (mode != wxMM_TEXT) - { - m_needComputeScaleX = true; - m_needComputeScaleY = true; - } -} - -void wxDC::SetUserScale( double x, double y ) -{ - // allow negative ? -> no - m_userScaleX = x; - m_userScaleY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetLogicalScale( double x, double y ) -{ - // allow negative ? - m_logicalScaleX = x; - m_logicalScaleY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y ) -{ - m_logicalOriginX = x * m_signX; // is this still correct ? - m_logicalOriginY = y * m_signY; - ComputeScaleAndOrigin(); -} - -void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) -{ - // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there - m_deviceOriginX = x; - m_deviceOriginY = y; - ComputeScaleAndOrigin(); -} - -void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) -{ - m_signX = xLeftRight ? 1 : -1; - m_signY = yBottomUp ? -1 : 1; - ComputeScaleAndOrigin(); -} - -wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const -{ - return ((wxDC *)this)->XDEV2LOG(x); -} - -wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const -{ - return ((wxDC *)this)->YDEV2LOG(y); -} - -wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const -{ - return ((wxDC *)this)->XDEV2LOGREL(x); -} - -wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const -{ - return ((wxDC *)this)->YDEV2LOGREL(y); -} - -wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const -{ - return ((wxDC *)this)->XLOG2DEV(x); -} - -wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const -{ - return ((wxDC *)this)->YLOG2DEV(y); -} - -wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const -{ - return ((wxDC *)this)->XLOG2DEVREL(x); -} - -wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const -{ - return ((wxDC *)this)->YLOG2DEVREL(y); -} - -void wxDC::ComputeScaleAndOrigin() -{ - m_scaleX = m_logicalScaleX * m_userScaleX; - m_scaleY = m_logicalScaleY * m_userScaleY; -} -- 2.45.2