1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: plotdraw.h 3 // Purpose: wxPlotDrawer and friends 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_PLOTDRAW_H_ 12 #define _WX_PLOTDRAW_H_ 13 14 #include "wx/defs.h" 15 #include "wx/geometry.h" 16 #include "wx/bitmap.h" 17 #include "wx/plotctrl/plotdefs.h" 18 #include "wx/plotctrl/plotcurv.h" 19 #include "wx/plotctrl/plotdata.h" 20 #include "wx/plotctrl/plotfunc.h" 21 #include "wx/wxthings/range.h" 22 23 class WXDLLEXPORT wxDC; 24 25 class WXDLLIMPEXP_THINGS wxRangeIntSelection; 26 class WXDLLIMPEXP_THINGS wxRangeDoubleSelection; 27 class WXDLLIMPEXP_THINGS wxArrayRangeIntSelection; 28 class WXDLLIMPEXP_THINGS wxArrayRangeDoubleSelection; 29 30 class WXDLLIMPEXP_PLOTCTRL wxPlotCtrl; 31 32 class WXDLLIMPEXP_PLOTCTRL wxPlotCurve; 33 class WXDLLIMPEXP_PLOTCTRL wxPlotData; 34 class WXDLLIMPEXP_PLOTCTRL wxPlotFunction; 35 class WXDLLIMPEXP_PLOTCTRL wxPlotMarker; 36 37 //----------------------------------------------------------------------------- 38 // wxPlotDrawerBase 39 //----------------------------------------------------------------------------- 40 41 class wxPlotDrawerBase : public wxObject 42 { 43 public: wxPlotDrawerBase(wxPlotCtrl * owner)44 wxPlotDrawerBase(wxPlotCtrl* owner) : wxObject(), 45 m_owner(owner), m_pen_scale(1), m_font_scale(1) {} 46 47 virtual void Draw(wxDC* dc, bool refresh) = 0; 48 49 // Get/Set the owner plotctrl GetOwner()50 wxPlotCtrl* GetOwner() const { return m_owner; } SetOwner(wxPlotCtrl * owner)51 void SetOwner(wxPlotCtrl* owner) { m_owner = owner; } 52 53 // Get/Get the rect in the DC to draw on SetDCRect(const wxRect & rect)54 void SetDCRect(const wxRect& rect) { m_dcRect = rect; } GetDCRect()55 const wxRect& GetDCRect() const { return m_dcRect; } 56 57 // Get/Set the rect of the visible area in the plot window SetPlotViewRect(const wxRect2DDouble & rect)58 void SetPlotViewRect(const wxRect2DDouble& rect) { m_plotViewRect = rect; } GetPlotViewRect()59 const wxRect2DDouble& GetPlotViewRect() const { return m_plotViewRect; } 60 61 // Get/Set the scaling for drawing, fonts, pens, etc are scaled SetPenScale(double scale)62 void SetPenScale(double scale) { m_pen_scale = scale; } GetPenScale()63 double GetPenScale() const { return m_pen_scale; } SetFontScale(double scale)64 void SetFontScale(double scale) { m_font_scale = scale; } GetFontScale()65 double GetFontScale() const { return m_font_scale; } 66 67 protected: 68 wxPlotCtrl* m_owner; 69 wxRect m_dcRect; 70 wxRect2DDouble m_plotViewRect; 71 double m_pen_scale; // width scaling factor for pens 72 double m_font_scale; // scaling factor for font sizes 73 74 private: 75 DECLARE_ABSTRACT_CLASS(wxPlotDrawerBase); 76 }; 77 78 //----------------------------------------------------------------------------- 79 // wxPlotDrawerArea 80 //----------------------------------------------------------------------------- 81 82 class wxPlotDrawerArea : public wxPlotDrawerBase 83 { 84 public: wxPlotDrawerArea(wxPlotCtrl * owner)85 wxPlotDrawerArea(wxPlotCtrl* owner) : wxPlotDrawerBase(owner) {} 86 87 virtual void Draw(wxDC *dc, bool refresh); 88 89 private: 90 DECLARE_ABSTRACT_CLASS(wxPlotDrawerArea); 91 }; 92 93 //----------------------------------------------------------------------------- 94 // wxPlotDrawerAxisBase 95 //----------------------------------------------------------------------------- 96 97 class wxPlotDrawerAxisBase : public wxPlotDrawerBase 98 { 99 public: 100 wxPlotDrawerAxisBase(wxPlotCtrl* owner); 101 102 virtual void Draw(wxDC *dc, bool refresh) = 0; 103 SetTickFont(const wxFont & font)104 void SetTickFont( const wxFont& font ) { m_tickFont = font; } SetLabelFont(const wxFont & font)105 void SetLabelFont( const wxFont& font ) { m_labelFont = font; } 106 SetTickColour(const wxGenericColour & colour)107 void SetTickColour( const wxGenericColour& colour ) { m_tickColour = colour; } SetLabelColour(const wxGenericColour & colour)108 void SetLabelColour( const wxGenericColour& colour ) { m_labelColour = colour; } 109 SetTickPen(const wxGenericPen & pen)110 void SetTickPen( const wxGenericPen& pen ) { m_tickPen = pen; } SetBackgroundBrush(const wxGenericBrush & brush)111 void SetBackgroundBrush( const wxGenericBrush& brush ) { m_backgroundBrush = brush; } 112 SetTickPositions(const wxArrayInt & pos)113 void SetTickPositions( const wxArrayInt& pos ) { m_tickPositions = pos; } SetTickLabels(const wxArrayString & labels)114 void SetTickLabels( const wxArrayString& labels ) { m_tickLabels = labels; } 115 SetLabel(const wxString & label)116 void SetLabel( const wxString& label ) { m_label = label; } 117 118 // implementation 119 wxArrayInt m_tickPositions; 120 wxArrayString m_tickLabels; 121 122 wxString m_label; 123 124 wxFont m_tickFont; 125 wxFont m_labelFont; 126 wxGenericColour m_tickColour; 127 wxGenericColour m_labelColour; 128 129 wxGenericPen m_tickPen; 130 wxGenericBrush m_backgroundBrush; 131 132 private: 133 DECLARE_ABSTRACT_CLASS(wxPlotDrawerAxisBase); 134 }; 135 136 //----------------------------------------------------------------------------- 137 // wxPlotDrawerXAxis 138 //----------------------------------------------------------------------------- 139 140 class wxPlotDrawerXAxis : public wxPlotDrawerAxisBase 141 { 142 public: wxPlotDrawerXAxis(wxPlotCtrl * owner)143 wxPlotDrawerXAxis(wxPlotCtrl* owner) : wxPlotDrawerAxisBase(owner) {} 144 145 virtual void Draw(wxDC *dc, bool refresh); 146 147 private: 148 DECLARE_ABSTRACT_CLASS(wxPlotDrawerXAxis); 149 }; 150 151 //----------------------------------------------------------------------------- 152 // wxPlotDrawerYAxis 153 //----------------------------------------------------------------------------- 154 155 class wxPlotDrawerYAxis : public wxPlotDrawerAxisBase 156 { 157 public: wxPlotDrawerYAxis(wxPlotCtrl * owner)158 wxPlotDrawerYAxis(wxPlotCtrl* owner) : wxPlotDrawerAxisBase(owner) {} 159 160 virtual void Draw(wxDC *dc, bool refresh); 161 162 private: 163 DECLARE_ABSTRACT_CLASS(wxPlotDrawerYAxis); 164 }; 165 166 //----------------------------------------------------------------------------- 167 // wxPlotDrawerKey 168 //----------------------------------------------------------------------------- 169 170 class wxPlotDrawerKey : public wxPlotDrawerBase 171 { 172 public: 173 wxPlotDrawerKey(wxPlotCtrl* owner); 174 Draw(wxDC * WXUNUSED (dc),bool WXUNUSED (refresh))175 virtual void Draw(wxDC *WXUNUSED(dc), bool WXUNUSED(refresh)) {} // unused 176 virtual void Draw(wxDC *dc, const wxString& keyString); 177 SetFont(const wxFont & font)178 void SetFont(const wxFont& font) { m_font = font; } SetFontColour(const wxGenericColour & colour)179 void SetFontColour(const wxGenericColour& colour) { m_fontColour = colour; } 180 SetKeyPosition(const wxPoint & pos)181 void SetKeyPosition(const wxPoint& pos) { m_keyPosition = pos; } 182 183 // implementation 184 wxFont m_font; 185 wxGenericColour m_fontColour; 186 187 wxPoint m_keyPosition; 188 bool m_key_inside; 189 int m_border; 190 int m_key_line_width; // length of line to draw for curve 191 int m_key_line_margin; // margin between line and key text 192 193 private: 194 DECLARE_ABSTRACT_CLASS(wxPlotDrawerKey); 195 }; 196 197 //----------------------------------------------------------------------------- 198 // wxPlotDrawerCurve 199 //----------------------------------------------------------------------------- 200 201 class wxPlotDrawerCurve : public wxPlotDrawerBase 202 { 203 public: wxPlotDrawerCurve(wxPlotCtrl * owner)204 wxPlotDrawerCurve(wxPlotCtrl* owner) : wxPlotDrawerBase(owner) {} 205 Draw(wxDC * WXUNUSED (dc),bool WXUNUSED (refresh))206 virtual void Draw(wxDC *WXUNUSED(dc), bool WXUNUSED(refresh)) {} // unused 207 virtual void Draw(wxDC *dc, wxPlotCurve *curve, int curve_index); 208 209 private: 210 DECLARE_ABSTRACT_CLASS(wxPlotDrawerCurve); 211 }; 212 213 //----------------------------------------------------------------------------- 214 // wxPlotDrawerDataCurve 215 //----------------------------------------------------------------------------- 216 217 class wxPlotDrawerDataCurve : public wxPlotDrawerBase 218 { 219 public: wxPlotDrawerDataCurve(wxPlotCtrl * owner)220 wxPlotDrawerDataCurve(wxPlotCtrl* owner) : wxPlotDrawerBase(owner) {} 221 Draw(wxDC * WXUNUSED (dc),bool WXUNUSED (refresh))222 virtual void Draw(wxDC *WXUNUSED(dc), bool WXUNUSED(refresh)) {} // unused 223 virtual void Draw(wxDC *dc, wxPlotData* plotData, int curve_index); 224 225 private: 226 DECLARE_ABSTRACT_CLASS(wxPlotDrawerDataCurve); 227 }; 228 229 //----------------------------------------------------------------------------- 230 // wxPlotDrawerMarkers 231 //----------------------------------------------------------------------------- 232 233 class wxPlotDrawerMarker : public wxPlotDrawerBase 234 { 235 public: wxPlotDrawerMarker(wxPlotCtrl * owner)236 wxPlotDrawerMarker(wxPlotCtrl* owner) : wxPlotDrawerBase(owner) {} 237 Draw(wxDC * WXUNUSED (dc),bool WXUNUSED (refresh))238 virtual void Draw(wxDC *WXUNUSED(dc), bool WXUNUSED(refresh)) {} // unused 239 virtual void Draw(wxDC *dc, const wxArrayPlotMarker& markers); 240 virtual void Draw(wxDC *dc, const wxPlotMarker& marker); 241 242 private: 243 DECLARE_ABSTRACT_CLASS(wxPlotDrawerMarker); 244 }; 245 246 #endif // _WX_PLOTDRAW_H_ 247