X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/40fcf546f6168f51c070d4ded3c40a75c0780fe8..d0b6c0c52729e737a8d69a61a2f47c24abf18a8c:/include/wx/gdicmn.h diff --git a/include/wx/gdicmn.h b/include/wx/gdicmn.h index 59c52cd1bb..6ce652d49f 100644 --- a/include/wx/gdicmn.h +++ b/include/wx/gdicmn.h @@ -4,7 +4,6 @@ // Author: Julian Smart // Modified by: // Created: 01/02/97 -// RCS-ID: $Id$ // Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -59,8 +58,10 @@ enum wxBitmapType wxBITMAP_TYPE_XBM_DATA, wxBITMAP_TYPE_XPM, wxBITMAP_TYPE_XPM_DATA, - wxBITMAP_TYPE_TIF, - wxBITMAP_TYPE_TIF_RESOURCE, + wxBITMAP_TYPE_TIFF, + wxBITMAP_TYPE_TIF = wxBITMAP_TYPE_TIFF, + wxBITMAP_TYPE_TIFF_RESOURCE, + wxBITMAP_TYPE_TIF_RESOURCE = wxBITMAP_TYPE_TIFF_RESOURCE, wxBITMAP_TYPE_GIF, wxBITMAP_TYPE_GIF_RESOURCE, wxBITMAP_TYPE_PNG, @@ -85,6 +86,13 @@ enum wxBitmapType wxBITMAP_TYPE_ANY = 50 }; +// Polygon filling mode +enum wxPolygonFillMode +{ + wxODDEVEN_RULE = 1, + wxWINDING_RULE +}; + // Standard cursors enum wxStockCursor { @@ -128,39 +136,49 @@ enum wxStockCursor wxCURSOR_BASED_ARROW_UP, wxCURSOR_BASED_ARROW_DOWN, #endif // X11 - wxCURSOR_ARROWWAIT, +#ifdef __WXMAC__ + wxCURSOR_OPEN_HAND, + wxCURSOR_CLOSED_HAND, +#endif wxCURSOR_MAX }; #ifndef __WXGTK__ - #define wxCURSOR_DEFAULT wxCURSOR_ARROW + #define wxCURSOR_DEFAULT wxCURSOR_ARROW +#endif + +#ifndef __WXMAC__ + // TODO CS supply openhand and closedhand cursors + #define wxCURSOR_OPEN_HAND wxCURSOR_HAND + #define wxCURSOR_CLOSED_HAND wxCURSOR_HAND #endif // --------------------------------------------------------------------------- // macros // --------------------------------------------------------------------------- +#if defined(__WINDOWS__) || defined(__WXPM__) + #define wxHAS_IMAGES_IN_RESOURCES +#endif + /* Useful macro for creating icons portably, for example: - wxIcon *icon = new wxICON(mondrian); + wxIcon *icon = new wxICON(sample); expands into: - wxIcon *icon = new wxIcon("mondrian"); // On wxMSW - wxIcon *icon = new wxIcon(mondrian_xpm); // On wxGTK + wxIcon *icon = new wxIcon("sample"); // On Windows + wxIcon *icon = new wxIcon(sample_xpm); // On wxGTK/Linux */ -#ifdef __WXMSW__ +#ifdef __WINDOWS__ // Load from a resource #define wxICON(X) wxIcon(wxT(#X)) #elif defined(__WXPM__) // Load from a resource #define wxICON(X) wxIcon(wxT(#X)) -#elif defined(__WXMGL__) - // Initialize from an included XPM - #define wxICON(X) wxIcon( X##_xpm ) #elif defined(__WXDFB__) // Initialize from an included XPM #define wxICON(X) wxIcon( X##_xpm ) @@ -185,13 +203,12 @@ enum wxStockCursor under Unix bitmaps live in XPMs and under Windows they're in ressources. */ -#if defined(__WXMSW__) || defined(__WXPM__) - #define wxBITMAP(name) wxBitmap(wxT(#name), wxBITMAP_TYPE_RESOURCE) +#if defined(__WINDOWS__) || defined(__WXPM__) + #define wxBITMAP(name) wxBitmap(wxT(#name), wxBITMAP_TYPE_BMP_RESOURCE) #elif defined(__WXGTK__) || \ defined(__WXMOTIF__) || \ defined(__WXX11__) || \ defined(__WXMAC__) || \ - defined(__WXMGL__) || \ defined(__WXDFB__) || \ defined(__WXCOCOA__) // Initialize from an included XPM @@ -200,6 +217,28 @@ enum wxStockCursor #define wxBITMAP(name) wxBitmap(name##_xpm, wxBITMAP_TYPE_XPM) #endif // platform +// Macro for creating wxBitmap from in-memory PNG data. +// +// It reads PNG data from name_png static byte arrays that can be created using +// e.g. misc/scripts/png2c.py. +// +// This macro exists mostly as a helper for wxBITMAP_PNG() below but also +// because it's slightly more convenient to use than NewFromPNGData() directly. +#define wxBITMAP_PNG_FROM_DATA(name) \ + wxBitmap::NewFromPNGData(name##_png, WXSIZEOF(name##_png)) + +// Similar to wxBITMAP but used for the bitmaps in PNG format. +// +// Under Windows they should be embedded into the resource file using RT_RCDATA +// resource type and under OS X the PNG file with the specified name must be +// available in the resource subdirectory of the bundle. Elsewhere, this is +// exactly the same thing as wxBITMAP_PNG_FROM_DATA() described above. +#if defined(__WINDOWS__) || defined(__WXOSX__) + #define wxBITMAP_PNG(name) wxBitmap(wxS(#name), wxBITMAP_TYPE_PNG_RESOURCE) +#else + #define wxBITMAP_PNG(name) wxBITMAP_PNG_FROM_DATA(name) +#endif + // =========================================================================== // classes // =========================================================================== @@ -224,17 +263,34 @@ public: wxSize& operator-=(const wxSize& sz) { x -= sz.x; y -= sz.y; return *this; } wxSize& operator/=(int i) { x /= i; y /= i; return *this; } wxSize& operator*=(int i) { x *= i; y *= i; return *this; } + wxSize& operator/=(unsigned int i) { x /= i; y /= i; return *this; } + wxSize& operator*=(unsigned int i) { x *= i; y *= i; return *this; } + wxSize& operator/=(long i) { x /= i; y /= i; return *this; } + wxSize& operator*=(long i) { x *= i; y *= i; return *this; } + wxSize& operator/=(unsigned long i) { x /= i; y /= i; return *this; } + wxSize& operator*=(unsigned long i) { x *= i; y *= i; return *this; } + wxSize& operator/=(double i) { x = int(x/i); y = int(y/i); return *this; } + wxSize& operator*=(double i) { x = int(x*i); y = int(y*i); return *this; } void IncTo(const wxSize& sz) { if ( sz.x > x ) x = sz.x; if ( sz.y > y ) y = sz.y; } void DecTo(const wxSize& sz) { if ( sz.x < x ) x = sz.x; if ( sz.y < y ) y = sz.y; } + void DecToIfSpecified(const wxSize& sz) + { + if ( sz.x != wxDefaultCoord && sz.x < x ) + x = sz.x; + if ( sz.y != wxDefaultCoord && sz.y < y ) + y = sz.y; + } void IncBy(int dx, int dy) { x += dx; y += dy; } + void IncBy(const wxPoint& pt); void IncBy(const wxSize& sz) { IncBy(sz.x, sz.y); } void IncBy(int d) { IncBy(d, d); } void DecBy(int dx, int dy) { IncBy(-dx, -dy); } + void DecBy(const wxPoint& pt); void DecBy(const wxSize& sz) { DecBy(sz.x, sz.y); } void DecBy(int d) { DecBy(d, d); } @@ -267,7 +323,6 @@ public: int GetY() const { return y; } }; - inline bool operator==(const wxSize& s1, const wxSize& s2) { return s1.x == s2.x && s1.y == s2.y; @@ -278,36 +333,85 @@ inline bool operator!=(const wxSize& s1, const wxSize& s2) return s1.x != s2.x || s1.y != s2.y; } - inline wxSize operator+(const wxSize& s1, const wxSize& s2) { return wxSize(s1.x + s2.x, s1.y + s2.y); } - inline wxSize operator-(const wxSize& s1, const wxSize& s2) { return wxSize(s1.x - s2.x, s1.y - s2.y); } - inline wxSize operator/(const wxSize& s, int i) { return wxSize(s.x / i, s.y / i); } - inline wxSize operator*(const wxSize& s, int i) { return wxSize(s.x * i, s.y * i); } - inline wxSize operator*(int i, const wxSize& s) { return wxSize(s.x * i, s.y * i); } +inline wxSize operator/(const wxSize& s, unsigned int i) +{ + return wxSize(s.x / i, s.y / i); +} + +inline wxSize operator*(const wxSize& s, unsigned int i) +{ + return wxSize(s.x * i, s.y * i); +} + +inline wxSize operator*(unsigned int i, const wxSize& s) +{ + return wxSize(s.x * i, s.y * i); +} + +inline wxSize operator/(const wxSize& s, long i) +{ + return wxSize(s.x / i, s.y / i); +} + +inline wxSize operator*(const wxSize& s, long i) +{ + return wxSize(int(s.x * i), int(s.y * i)); +} + +inline wxSize operator*(long i, const wxSize& s) +{ + return wxSize(int(s.x * i), int(s.y * i)); +} + +inline wxSize operator/(const wxSize& s, unsigned long i) +{ + return wxSize(int(s.x / i), int(s.y / i)); +} + +inline wxSize operator*(const wxSize& s, unsigned long i) +{ + return wxSize(int(s.x * i), int(s.y * i)); +} + +inline wxSize operator*(unsigned long i, const wxSize& s) +{ + return wxSize(int(s.x * i), int(s.y * i)); +} + +inline wxSize operator*(const wxSize& s, double i) +{ + return wxSize(int(s.x * i), int(s.y * i)); +} + +inline wxSize operator*(double i, const wxSize& s) +{ + return wxSize(int(s.x * i), int(s.y * i)); +} @@ -323,6 +427,16 @@ public: wxRealPoint() : x(0.0), y(0.0) { } wxRealPoint(double xx, double yy) : x(xx), y(yy) { } + wxRealPoint(const wxPoint& pt); + + // no copy ctor or assignment operator - the defaults are ok + + //assignment operators + wxRealPoint& operator+=(const wxRealPoint& p) { x += p.x; y += p.y; return *this; } + wxRealPoint& operator-=(const wxRealPoint& p) { x -= p.x; y -= p.y; return *this; } + + wxRealPoint& operator+=(const wxSize& s) { x += s.GetWidth(); y += s.GetHeight(); return *this; } + wxRealPoint& operator-=(const wxSize& s) { x -= s.GetWidth(); y -= s.GetHeight(); return *this; } }; @@ -331,13 +445,11 @@ inline bool operator==(const wxRealPoint& p1, const wxRealPoint& p2) return wxIsSameDouble(p1.x, p2.x) && wxIsSameDouble(p1.y, p2.y); } - inline bool operator!=(const wxRealPoint& p1, const wxRealPoint& p2) { return !(p1 == p2); } - inline wxRealPoint operator+(const wxRealPoint& p1, const wxRealPoint& p2) { return wxRealPoint(p1.x + p2.x, p1.y + p2.y); @@ -350,6 +462,77 @@ inline wxRealPoint operator-(const wxRealPoint& p1, const wxRealPoint& p2) } +inline wxRealPoint operator/(const wxRealPoint& s, int i) +{ + return wxRealPoint(s.x / i, s.y / i); +} + +inline wxRealPoint operator*(const wxRealPoint& s, int i) +{ + return wxRealPoint(s.x * i, s.y * i); +} + +inline wxRealPoint operator*(int i, const wxRealPoint& s) +{ + return wxRealPoint(s.x * i, s.y * i); +} + +inline wxRealPoint operator/(const wxRealPoint& s, unsigned int i) +{ + return wxRealPoint(s.x / i, s.y / i); +} + +inline wxRealPoint operator*(const wxRealPoint& s, unsigned int i) +{ + return wxRealPoint(s.x * i, s.y * i); +} + +inline wxRealPoint operator*(unsigned int i, const wxRealPoint& s) +{ + return wxRealPoint(s.x * i, s.y * i); +} + +inline wxRealPoint operator/(const wxRealPoint& s, long i) +{ + return wxRealPoint(s.x / i, s.y / i); +} + +inline wxRealPoint operator*(const wxRealPoint& s, long i) +{ + return wxRealPoint(s.x * i, s.y * i); +} + +inline wxRealPoint operator*(long i, const wxRealPoint& s) +{ + return wxRealPoint(s.x * i, s.y * i); +} + +inline wxRealPoint operator/(const wxRealPoint& s, unsigned long i) +{ + return wxRealPoint(s.x / i, s.y / i); +} + +inline wxRealPoint operator*(const wxRealPoint& s, unsigned long i) +{ + return wxRealPoint(s.x * i, s.y * i); +} + +inline wxRealPoint operator*(unsigned long i, const wxRealPoint& s) +{ + return wxRealPoint(s.x * i, s.y * i); +} + +inline wxRealPoint operator*(const wxRealPoint& s, double i) +{ + return wxRealPoint(int(s.x * i), int(s.y * i)); +} + +inline wxRealPoint operator*(double i, const wxRealPoint& s) +{ + return wxRealPoint(int(s.x * i), int(s.y * i)); +} + + // ---------------------------------------------------------------------------- // wxPoint: 2D point with integer coordinates // ---------------------------------------------------------------------------- @@ -361,6 +544,7 @@ public: wxPoint() : x(0), y(0) { } wxPoint(int xx, int yy) : x(xx), y(yy) { } + wxPoint(const wxRealPoint& pt) : x(int(pt.x)), y(int(pt.y)) { } // no copy ctor or assignment operator - the defaults are ok @@ -370,6 +554,18 @@ public: wxPoint& operator+=(const wxSize& s) { x += s.GetWidth(); y += s.GetHeight(); return *this; } wxPoint& operator-=(const wxSize& s) { x -= s.GetWidth(); y -= s.GetHeight(); return *this; } + + // check if both components are set/initialized + bool IsFullySpecified() const { return x != wxDefaultCoord && y != wxDefaultCoord; } + + // fill in the unset components with the values from the other point + void SetDefaults(const wxPoint& pt) + { + if ( x == wxDefaultCoord ) + x = pt.x; + if ( y == wxDefaultCoord ) + y = pt.y; + } }; @@ -421,6 +617,76 @@ inline wxPoint operator-(const wxPoint& p) return wxPoint(-p.x, -p.y); } +inline wxPoint operator/(const wxPoint& s, int i) +{ + return wxPoint(s.x / i, s.y / i); +} + +inline wxPoint operator*(const wxPoint& s, int i) +{ + return wxPoint(s.x * i, s.y * i); +} + +inline wxPoint operator*(int i, const wxPoint& s) +{ + return wxPoint(s.x * i, s.y * i); +} + +inline wxPoint operator/(const wxPoint& s, unsigned int i) +{ + return wxPoint(s.x / i, s.y / i); +} + +inline wxPoint operator*(const wxPoint& s, unsigned int i) +{ + return wxPoint(s.x * i, s.y * i); +} + +inline wxPoint operator*(unsigned int i, const wxPoint& s) +{ + return wxPoint(s.x * i, s.y * i); +} + +inline wxPoint operator/(const wxPoint& s, long i) +{ + return wxPoint(s.x / i, s.y / i); +} + +inline wxPoint operator*(const wxPoint& s, long i) +{ + return wxPoint(int(s.x * i), int(s.y * i)); +} + +inline wxPoint operator*(long i, const wxPoint& s) +{ + return wxPoint(int(s.x * i), int(s.y * i)); +} + +inline wxPoint operator/(const wxPoint& s, unsigned long i) +{ + return wxPoint(s.x / i, s.y / i); +} + +inline wxPoint operator*(const wxPoint& s, unsigned long i) +{ + return wxPoint(int(s.x * i), int(s.y * i)); +} + +inline wxPoint operator*(unsigned long i, const wxPoint& s) +{ + return wxPoint(int(s.x * i), int(s.y * i)); +} + +inline wxPoint operator*(const wxPoint& s, double i) +{ + return wxPoint(int(s.x * i), int(s.y * i)); +} + +inline wxPoint operator*(double i, const wxPoint& s) +{ + return wxPoint(int(s.x * i), int(s.y * i)); +} + WX_DECLARE_LIST_WITH_DECL(wxPoint, wxPointList, class WXDLLIMPEXP_CORE); // --------------------------------------------------------------------------- @@ -489,7 +755,7 @@ public: wxPoint GetTopRight() const { return wxPoint(GetRight(), GetTop()); } wxPoint GetRightTop() const { return GetTopRight(); } void SetTopRight(const wxPoint &p) { SetRight(p.x); SetTop(p.y); } - void SetRightTop(const wxPoint &p) { SetTopLeft(p); } + void SetRightTop(const wxPoint &p) { SetTopRight(p); } wxPoint GetBottomLeft() const { return wxPoint(GetLeft(), GetBottom()); } wxPoint GetLeftBottom() const { return GetBottomLeft(); } @@ -605,6 +871,11 @@ inline bool wxRect::Inside(const wxRect& rect) const { return Contains(rect); } #endif // WXWIN_COMPATIBILITY_2_6 +// define functions which couldn't be defined above because of declarations +// order +inline void wxSize::IncBy(const wxPoint& pt) { IncBy(pt.x, pt.y); } +inline void wxSize::DecBy(const wxPoint& pt) { DecBy(pt.x, pt.y); } + // --------------------------------------------------------------------------- // Management of pens, brushes and fonts // --------------------------------------------------------------------------- @@ -659,7 +930,7 @@ class WXDLLIMPEXP_CORE wxResourceCache: public wxList { public: wxResourceCache() { } -#if !wxUSE_STL +#if !wxUSE_STD_CONTAINERS wxResourceCache(const unsigned int keyType) : wxList(keyType) { } #endif virtual ~wxResourceCache(); @@ -688,6 +959,7 @@ public: BRUSH_BLUE, BRUSH_CYAN, BRUSH_GREEN, + BRUSH_YELLOW, BRUSH_GREY, BRUSH_LIGHTGREY, BRUSH_MEDIUMGREY, @@ -698,6 +970,7 @@ public: COLOUR_BLUE, COLOUR_CYAN, COLOUR_GREEN, + COLOUR_YELLOW, COLOUR_LIGHTGREY, COLOUR_RED, COLOUR_WHITE, @@ -710,8 +983,10 @@ public: FONT_SWISS, PEN_BLACK, PEN_BLACKDASHED, + PEN_BLUE, PEN_CYAN, PEN_GREEN, + PEN_YELLOW, PEN_GREY, PEN_LIGHTGREY, PEN_MEDIUMGREY, @@ -739,7 +1014,7 @@ protected: static wxObject* ms_stockObject[ITEMCOUNT]; - DECLARE_NO_COPY_CLASS(wxStockGDI) + wxDECLARE_NO_COPY_CLASS(wxStockGDI); }; #define wxITALIC_FONT wxStockGDI::instance().GetFont(wxStockGDI::FONT_ITALIC) @@ -749,8 +1024,10 @@ protected: #define wxBLACK_DASHED_PEN wxStockGDI::GetPen(wxStockGDI::PEN_BLACKDASHED) #define wxBLACK_PEN wxStockGDI::GetPen(wxStockGDI::PEN_BLACK) +#define wxBLUE_PEN wxStockGDI::GetPen(wxStockGDI::PEN_BLUE) #define wxCYAN_PEN wxStockGDI::GetPen(wxStockGDI::PEN_CYAN) #define wxGREEN_PEN wxStockGDI::GetPen(wxStockGDI::PEN_GREEN) +#define wxYELLOW_PEN wxStockGDI::GetPen(wxStockGDI::PEN_YELLOW) #define wxGREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_GREY) #define wxLIGHT_GREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_LIGHTGREY) #define wxMEDIUM_GREY_PEN wxStockGDI::GetPen(wxStockGDI::PEN_MEDIUMGREY) @@ -762,6 +1039,7 @@ protected: #define wxBLUE_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_BLUE) #define wxCYAN_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_CYAN) #define wxGREEN_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_GREEN) +#define wxYELLOW_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_YELLOW) #define wxGREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_GREY) #define wxLIGHT_GREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_LIGHTGREY) #define wxMEDIUM_GREY_BRUSH wxStockGDI::GetBrush(wxStockGDI::BRUSH_MEDIUMGREY) @@ -773,6 +1051,7 @@ protected: #define wxBLUE wxStockGDI::GetColour(wxStockGDI::COLOUR_BLUE) #define wxCYAN wxStockGDI::GetColour(wxStockGDI::COLOUR_CYAN) #define wxGREEN wxStockGDI::GetColour(wxStockGDI::COLOUR_GREEN) +#define wxYELLOW wxStockGDI::GetColour(wxStockGDI::COLOUR_YELLOW) #define wxLIGHT_GREY wxStockGDI::GetColour(wxStockGDI::COLOUR_LIGHTGREY) #define wxRED wxStockGDI::GetColour(wxStockGDI::COLOUR_RED) #define wxWHITE wxStockGDI::GetColour(wxStockGDI::COLOUR_WHITE)