diff --git a/docs/doxygen/mainpages/const_cpp.h b/docs/doxygen/mainpages/const_cpp.h index 0c9fdd9b8b..cf3bacf7ab 100644 --- a/docs/doxygen/mainpages/const_cpp.h +++ b/docs/doxygen/mainpages/const_cpp.h @@ -167,6 +167,9 @@ Currently the following symbols exist: have an efficient (CPU-specific) implementation. Notice that the functions themselves are always available but can be prohibitively slow to use when implemented in a generic way, using a critical section.} +@itemdef{wxHAS_BITMAP_SCALE_FACTOR, Defined in @c wx/bitmap.h if bitmaps + actually use scale factor under the current platform, see + wxBitmap::SetScaleFactor().} @itemdef{wxHAS_BITMAPTOGGLEBUTTON, Defined in @c wx/tglbtn.h if wxBitmapToggleButton class is available in addition to wxToggleButton.} @itemdef{wxHAS_CONFIG_TEMPLATE_RW, Defined if the currently used compiler diff --git a/include/wx/bitmap.h b/include/wx/bitmap.h index e4cb25302f..68e49a03ea 100644 --- a/include/wx/bitmap.h +++ b/include/wx/bitmap.h @@ -188,6 +188,7 @@ public: { return wxSize(GetWidth(), GetHeight()); } // support for scaled bitmaps + virtual void SetScaleFactor(double WXUNUSED(scale)) { } virtual double GetScaleFactor() const { return 1.0; } virtual double GetScaledWidth() const { return GetWidth() / GetScaleFactor(); } virtual double GetScaledHeight() const { return GetHeight() / GetScaleFactor(); } diff --git a/include/wx/gtk/bitmap.h b/include/wx/gtk/bitmap.h index 2f17a24e5c..2a6f9c62f5 100644 --- a/include/wx/gtk/bitmap.h +++ b/include/wx/gtk/bitmap.h @@ -17,6 +17,10 @@ typedef struct _GdkPixbuf GdkPixbuf; class WXDLLIMPEXP_FWD_CORE wxPixelDataBase; class WXDLLIMPEXP_FWD_CORE wxCursor; +#ifdef __WXGTK3__ + #define wxHAS_BITMAP_SCALE_FACTOR +#endif + //----------------------------------------------------------------------------- // wxMask //----------------------------------------------------------------------------- @@ -85,8 +89,9 @@ public: { return Create(sz.GetWidth(), sz.GetHeight(), depth); } bool Create(int width, int height, const wxDC& WXUNUSED(dc)) { return Create(width,height); } -#ifdef __WXGTK3__ +#ifdef wxHAS_BITMAP_SCALE_FACTOR virtual bool CreateScaled(int w, int h, int depth, double scale) wxOVERRIDE; + virtual void SetScaleFactor(double scale) wxOVERRIDE; virtual double GetScaleFactor() const wxOVERRIDE; #endif diff --git a/include/wx/msw/bitmap.h b/include/wx/msw/bitmap.h index 260ec080de..9672fc437d 100644 --- a/include/wx/msw/bitmap.h +++ b/include/wx/msw/bitmap.h @@ -186,6 +186,7 @@ public: void ResetAlpha() { UseAlpha(false); } // support for scaled bitmaps + virtual void SetScaleFactor(double WXUNUSED(scale)) { } virtual double GetScaleFactor() const { return 1.0; } virtual double GetScaledWidth() const { return GetWidth(); } virtual double GetScaledHeight() const { return GetHeight(); } diff --git a/include/wx/osx/bitmap.h b/include/wx/osx/bitmap.h index bae0e68537..4f85b77fcb 100644 --- a/include/wx/osx/bitmap.h +++ b/include/wx/osx/bitmap.h @@ -13,6 +13,8 @@ #include "wx/palette.h" +#define wxHAS_BITMAP_SCALE_FACTOR + // Bitmap class WXDLLIMPEXP_FWD_CORE wxBitmap; class wxBitmapRefData ; @@ -239,6 +241,7 @@ public: void EndRawAccess(); #endif + void SetScaleFactor(double scale) wxOVERRIDE; double GetScaleFactor() const wxOVERRIDE; void SetSelectedInto(wxDC *dc); diff --git a/interface/wx/bitmap.h b/interface/wx/bitmap.h index 0456114c2b..c45a34a583 100644 --- a/interface/wx/bitmap.h +++ b/interface/wx/bitmap.h @@ -469,7 +469,7 @@ public: @param depth The number of bits used to represent each bitmap pixel. @param logicalScale - Scale factor used by the bitmap + Scale factor used by the bitmap, see SetScaleFactor(). @return @true if the creation was successful. @@ -586,9 +586,10 @@ public: 1 must be used in high DPI to appear sharp on the screen. Note that the scale factor is only used in the ports where logical - pixels are not the same as physical ones, such as wxOSX or wxGTK3. + pixels are not the same as physical ones, such as wxOSX or wxGTK3, and + this function always returns 1 under the other platforms. - @see GetScaledWidth(), GetScaledHeight(), GetScaledSize() + @see SetScaleFactor(), GetScaledWidth(), GetScaledHeight(), GetScaledSize() @since 2.9.5 */ @@ -796,6 +797,38 @@ public: */ virtual void SetHeight(int height); + /** + Sets the bitmap scale factor. + + This doesn't change the bitmap actual size or its contents, but changes + its scale factor, so that it appears in a smaller size when it is drawn + on screen: e.g. setting @a scale to 2 means that the bitmap will be + twice smaller (in each direction) when drawn on screen in the ports in + which logical and physical pixels differ (i.e. wxOSX and wxGTK3, but + not wxMSW). + + When creating a new bitmap, CreateScaled() can be used to specify the + correct scale factor from the beginning. + + Note that this method exists in all ports, but simply does nothing in + those of them that don't use logical pixel scaling. The preprocessor + symbol @c wxHAS_BITMAP_SCALE_FACTOR can be tested to determine whether + the scale factor is really supported, e.g. + + @code + bitmap.SetScaleFactor(2); + + // In the other ports scale factor is always 1, so the assert would + // fail there. + #ifdef wxHAS_BITMAP_SCALE_FACTOR + wxASSERT( bitmap.GetScaleFactor() == 2 ); + #endif + @endcode + + @since 3.1.6 + */ + virtual void SetScaleFactor(double scale); + /** Sets the mask for this bitmap. diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index 658480e5ff..c6b229e211 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -1002,6 +1002,13 @@ bool wxBitmap::CreateScaled(int w, int h, int depth, double scale) return true; } +void wxBitmap::SetScaleFactor(double scale) +{ + wxCHECK_RET(m_refData, "invalid bitmap"); + + M_BMPDATA->m_scaleFactor = scale; +} + double wxBitmap::GetScaleFactor() const { wxCHECK_MSG(m_refData, -1, "invalid bitmap"); diff --git a/src/osx/core/bitmap.cpp b/src/osx/core/bitmap.cpp index d7211a50e4..2f82e5d9a2 100644 --- a/src/osx/core/bitmap.cpp +++ b/src/osx/core/bitmap.cpp @@ -75,6 +75,8 @@ public: int GetBytesPerRow() const; bool HasAlpha() const; WXImage GetImage() const; + + void SetScaleFactor(double scale) { m_scaleFactor = scale; } double GetScaleFactor() const { return m_scaleFactor; } const void *GetRawAccess() const; @@ -1389,6 +1391,13 @@ int wxBitmap::GetWidth() const return GetBitmapData()->GetWidth() ; } +void wxBitmap::SetScaleFactor(double scale) +{ + wxCHECK_RET( IsOk(), wxT("invalid bitmap") ); + + return GetBitmapData()->SetScaleFactor(scale) ; +} + double wxBitmap::GetScaleFactor() const { wxCHECK_MSG( IsOk(), -1, wxT("invalid bitmap") );