1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: plotmark.h 3 // Purpose: wxPlotMarker 4 // Author: John Labenski 5 // Modified by: 6 // Created: 6/5/2002 7 // Copyright: (c) John Labenski 8 // Licence: wxWindows licence 9 ///////////////////////////////////////////////////////////////////////////// 10 11 #ifndef _WX_PLOTMARK_H_ 12 #define _WX_PLOTMARK_H_ 13 14 #include "wx/bitmap.h" 15 #include "wx/geometry.h" 16 #include "wx/plotctrl/plotdefs.h" 17 #include "wx/wxthings/genergdi.h" 18 19 class WXDLLIMPEXP_PLOTCTRL wxPlotCtrl; 20 class WXDLLIMPEXP_PLOTCTRL wxPlotMarker; 21 22 WX_DECLARE_OBJARRAY_WITH_DECL(wxPlotMarker, wxArrayPlotMarker, class WXDLLIMPEXP_PLOTCTRL); 23 24 //----------------------------------------------------------------------------- 25 // wxPlotMarker - a marker to draw in the plot window 26 // This is a catch all class, containing info to draw various marker types. 27 // Therefore, some parts may not be used for some markers. 28 // Use a two part construction to ensure it's created properly 29 // wxPlotMarker marker; marker.CreateXXX(...) 30 //----------------------------------------------------------------------------- 31 32 enum wxPlotMarkerType 33 { 34 wxPLOTMARKER_NONE, // invalid, don't draw it 35 wxPLOTMARKER_POINT, // single pixel point, only position & pen used 36 // size, brush, bitmap unused 37 wxPLOTMARKER_LINE, // line from upper left to lower right of rect 38 // rect may be inverted to draw at any angle 39 // size, brush, bitmap unused 40 wxPLOTMARKER_HORIZ_LINE,// horizontal line, full width 41 // only vert position and pen used 42 // size, brush, bitmap unused 43 wxPLOTMARKER_VERT_LINE, // vertical line, full height 44 // only horiz position and pen used 45 // size, brush, bitmap unused 46 wxPLOTMARKER_CROSS, // vertical and horizontal line, full height & width 47 // position used for center of cross 48 // size, brush, bitmap unused 49 wxPLOTMARKER_RECT, // rectangle - see plot rect conditions 50 // pen draws outline and brush fills (if set) 51 // bitmap unused 52 // rect drawn centered on position 53 // size is size of the rect 54 wxPLOTMARKER_ELLIPSE, // ellipse - see plot rect conditions 55 wxPLOTMARKER_BITMAP // the bitmap is drawn at the position 56 }; 57 58 class WXDLLIMPEXP_PLOTCTRL wxPlotMarker : public wxObject 59 { 60 public: wxPlotMarker()61 wxPlotMarker() : wxObject() {} 62 // Create a full marker (see CreateXXX functions) 63 wxPlotMarker(int marker_type, 64 const wxRect2DDouble& rect, 65 const wxSize& size, 66 const wxGenericPen& pen, 67 const wxGenericBrush& brush = wxNullGenericBrush, wxObject()68 const wxBitmap& bitmap = wxNullBitmap) : wxObject() 69 { Create(marker_type, rect, size, pen, brush, bitmap); } 70 // Create a shape marker to be drawn at the point with the given size 71 // in pixels 72 wxPlotMarker(int marker_type, 73 const wxPoint2DDouble& pt, 74 const wxSize& size, 75 const wxGenericPen& pen, wxObject()76 const wxGenericBrush& brush = wxNullGenericBrush) : wxObject() 77 { Create(marker_type, wxRect2DDouble(pt.m_x, pt.m_y, 0, 0), size, pen, brush); } 78 // Create a bitmap marker wxPlotMarker(const wxPoint2DDouble & pt,const wxBitmap & bitmap)79 wxPlotMarker(const wxPoint2DDouble& pt, 80 const wxBitmap& bitmap) : wxObject() 81 { CreateBitmapMarker(pt, bitmap); } 82 ~wxPlotMarker()83 virtual ~wxPlotMarker() {} 84 85 // is the marker created Ok()86 bool Ok() const { return m_refData != NULL; } 87 88 // Generic create function 89 void Create(int marker_type, const wxRect2DDouble& rect, 90 const wxSize& size, const wxGenericPen& pen, 91 const wxGenericBrush& brush = wxNullGenericBrush, 92 const wxBitmap& bitmap = wxNullBitmap); 93 94 // Simplified methods (use these) CreatePointMarker(const wxPoint2DDouble & pt,const wxGenericPen & pen)95 void CreatePointMarker(const wxPoint2DDouble& pt, 96 const wxGenericPen& pen) 97 { Create(wxPLOTMARKER_POINT, wxRect2DDouble(pt.m_x, pt.m_y, 0, 0), wxSize(-1, -1), pen); } CreateLineMarker(const wxRect2DDouble & rect,const wxGenericPen & pen)98 void CreateLineMarker(const wxRect2DDouble& rect, const wxGenericPen& pen) 99 { Create(wxPLOTMARKER_LINE, rect, wxSize(-1, -1), pen); } CreateHorizLineMarker(double y,const wxGenericPen & pen)100 void CreateHorizLineMarker(double y, const wxGenericPen& pen) 101 { Create(wxPLOTMARKER_HORIZ_LINE, wxRect2DDouble(0, y, -1, 0), wxSize(-1, -1), pen); } CreateVertLineMarker(double x,const wxGenericPen & pen)102 void CreateVertLineMarker(double x, const wxGenericPen& pen) 103 { Create(wxPLOTMARKER_VERT_LINE, wxRect2DDouble(x, 0, 0, -1), wxSize(-1, -1), pen); } 104 void CreateRectMarker(const wxRect2DDouble& rect, 105 const wxGenericPen& pen, 106 const wxGenericBrush& brush = wxNullGenericBrush) 107 { Create(wxPLOTMARKER_RECT, rect, wxSize(-1, -1), pen, brush); } 108 void CreateRectMarker(const wxPoint2DDouble& pt, 109 const wxSize& size, 110 const wxGenericPen& pen, 111 const wxGenericBrush& brush = wxNullGenericBrush) 112 { Create(wxPLOTMARKER_RECT, wxRect2DDouble(pt.m_x, pt.m_y, 0, 0), size, pen, brush); } 113 // void CreateEllipseMarker(const wxRect2DDouble& rect, 114 // const wxGenericPen& pen, 115 // const wxGenericBrush& brush = wxNullGenericBrush) 116 // { Create(wxPLOTMARKER_ELLIPSE, rect, wxSize(-1, -1), pen, brush); } 117 void CreateEllipseMarker(const wxPoint2DDouble& pt, 118 const wxSize& size, 119 const wxGenericPen& pen, 120 const wxGenericBrush& brush = wxNullGenericBrush) 121 { Create(wxPLOTMARKER_ELLIPSE, wxRect2DDouble(pt.m_x, pt.m_y, 0, 0), size, pen, brush); } CreateBitmapMarker(const wxPoint2DDouble & pt,const wxBitmap & bitmap)122 void CreateBitmapMarker(const wxPoint2DDouble& pt, 123 const wxBitmap& bitmap) 124 { Create(wxPLOTMARKER_BITMAP, wxRect2DDouble(pt.m_x, pt.m_y, 0, 0), wxSize(-1, -1), wxNullGenericPen, wxNullGenericBrush, bitmap); } 125 126 // Get/Set the marker type 127 int GetMarkerType() const; 128 void SetMarkerType(int type); 129 130 // Get/Set the rect to draw the marker into 131 // The meaning of the rect is different for each marker type 132 // 133 // Bitmap markers 134 // Drawn centered at upper left if width = height = 0 135 // Drawn into the rect and scaled if width & height != 0 136 // 137 // Shape markers 138 // Draws a full rect/ellipse if width & height > 0 139 // Draws a point if width & height = 0 140 // Draws a vertical line if width = 0 & height != 0 141 // Draws a horizontal line if height = 0 & width != 0 142 // Draws the full width if width < 0 143 // Draws the full height if height < 0 144 wxRect2DDouble GetPlotRect() const; 145 wxRect2DDouble& GetPlotRect(); 146 void SetPlotRect(const wxRect2DDouble& rect); 147 148 wxPoint2DDouble GetPlotPosition() const; 149 void SetPlotPosition(const wxPoint2DDouble& pos); 150 151 // for rect/ellipse markers you can set the size in pixels 152 wxSize GetSize() const; 153 void SetSize(const wxSize& size); 154 155 // Get/Set the pen to draw the lines with 156 wxGenericPen GetPen() const; 157 void SetPen(const wxGenericPen& pen); 158 // Get/Set the brush to fill the area with (null for none) 159 wxGenericBrush GetBrush() const; 160 void SetBrush(const wxGenericBrush& brush); 161 // Get/Set the bitmap to draw (null for none, ignored if not wxPLOTMARKER_BITMAP) 162 wxBitmap GetBitmap() const; 163 void SetBitmap(const wxBitmap& bitmap); 164 165 // operators 166 bool operator == (const wxPlotMarker& pm) const 167 { return m_refData == pm.m_refData; } 168 bool operator != (const wxPlotMarker& pm) const 169 { return m_refData != pm.m_refData; } 170 171 wxPlotMarker& operator = (const wxPlotMarker& pm) 172 { 173 if ( (*this) != pm ) 174 Ref(pm); 175 return *this; 176 } 177 178 private: 179 // ref counting code 180 virtual wxObjectRefData *CreateRefData() const; 181 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; 182 183 DECLARE_DYNAMIC_CLASS(wxPlotMarker); 184 }; 185 186 #endif // _WX_PLOTMARK_H_ 187