Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cGraphPlot.h
Go to the documentation of this file.
1 //
4 //
5 #ifndef _INC_GraphPlot_H
6 #define _INC_GraphPlot_H
7 #ifndef NO_PRAGMA_ONCE
8 #pragma once
9 #endif
10 
11 #include "../GrayGraph.h"
12 #include "../CGraphCoords.h"
16 
17 #ifdef _MFC_VER
18 namespace GrayGraph
19 {
20 
21  enum GRAPH_CHANGE_TYPE
22  {
24  GRAPH_CHANGED,
25  GRAPH_SCALE,
26  GRAPH_POINT_CHANGED,
27  };
28 
29  class CGraphChange
30  {
33 
34  public:
35 #define WM_USER_GRAPH_NOTIFICATION (WM_USER+1)
36  virtual ~CGraphChange()
37  {} // just to make this polymorphic.
38  };
39 
40  class CGraphChangeScale : public CGraphChange
41  {
44  public:
45  CGraphRect m_rect;
46  };
47 
48  class CGraphChangeData : public CGraphChange
49  {
52  public:
53  ITERATE_t m_iPenNum;
54  ITERATE_t m_index;
55  ITERATE_t m_iQty;
56  };
57 
58  class CGraphWnd;
59  class CGraphPen;
60 
61  class CGraphPlot : public CWnd
62  {
64 
65  protected:
66  DECLARE_DYNCREATE(CGraphPlot)
67 
68  // Attributes
69  private:
70  CGraphWnd* m_pParent;
71 
72  cWndDCSurf m_Image;
73  CRect m_rectImageChanged;
74 
75  bool m_bAutoScale;
76  bool m_bAutoScroll;
77 
78  //zoom stuff
79  bool m_bZoomActive;
80  cNewPtr<cRectTracker> m_pZoomRect;
81  CGraphRect m_rectZoomUndoArray[16];
82  ITERATE_t m_iZoomUndoCount;
83 
84  bool m_bZoomDragging; //on-the-fly zoom rect creation
85  CPoint m_ptZoomNew1;
86  CPoint m_ptZoomNew2;
87 
88  private:
89  void DrawAxis(CDC& DC);
90  void DrawPenPoints(CDC& dc, CGraphPen * pPen, CGraphTime iStartTime, CGraphTime iStopTime);
91  void DrawGraphWindow(CDC* pDC, CRect& rect);
92  void OnZoomDrag(CPoint point);
93  void OnChangeAddPointNow(CGraphChangeData* pChange);
94 
95  void InvalidateGraphRect(const CRect* prect = nullptr);
96 
97  void SetViewBase(const CGraphRect& rect);
98 
99  virtual INT_PTR OnToolHitTest(CPoint point, TOOLINFO* pTI);
100 
101  // Operations
102  public:
103  CGraphPlot(); // protected constructor used by dynamic creation
104  CGraphPlot(CGraphWnd* parentWnd);
105  virtual ~CGraphPlot();
106 
107  void AdjustViewRatio(CGraphRect& rect);
108  bool GetZoomRect(CGraphRect& rectRet);
109  void ApplyZoom();
110  void DoFit(int fitType);
111 
112  void OnChangeAddPoint(ITERATE_t iPen, ITERATE_t index, ITERATE_t iQty);
113 
114  BOOL PostChangeMsg(GRAPH_CHANGE_TYPE wParam, CGraphChange* lParam = nullptr)
115  {
116  // Posted msg to sync up changes to the data and trend graph.
117  // lParam will be deleted.
118  return PostMessage(WM_USER_GRAPH_NOTIFICATION, (WPARAM)wParam, (LPARAM)lParam);
119  }
120 
121  bool get_AutoScale() const
122  {
123  return m_bAutoScale;
124  }
125  bool put_AutoScale(bool fAutoScale);
126  bool get_AutoScroll() const
127  {
128  return m_bAutoScroll;
129  }
130  bool put_AutoScroll(bool fAutoScroll);
131 
132  bool SetZoomPost(const CGraphRect& rect);
133  void SetViewNow(const CGraphRect& rect, bool fForce = false);
134 
135  // Overrides
136  // ClassWizard generated virtual function overrides
137  //{{AFX_VIRTUAL(CGraphPlot)
138  protected:
139  virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
140  //}}AFX_VIRTUAL
141 
142  // Implementation
143  protected:
144 #ifdef _DEBUG
145  virtual void AssertValid() const;
146  virtual void Dump(CDumpContext& dc) const;
147 #endif
148 
149  // Generated message map functions
150  protected:
151  //{{AFX_MSG(CGraphPlot)
152  afx_msg void OnMouseMove(UINT nFlags, CPoint point);
153  afx_msg void OnSize(UINT nType, int cx, int cy);
154  afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
155  afx_msg void OnPaint();
156  afx_msg BOOL OnEraseBkgnd(CDC* pDC);
157  afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
158  afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
159  afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
160  afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
161  afx_msg LRESULT OnChangeMsg(WPARAM wParam, LPARAM lParam);
162  afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
163  afx_msg void OnInitMenu(CMenu* pMenu);
164  //}}AFX_MSG
165  DECLARE_MESSAGE_MAP()
166  };
167 };
168 #endif
169 #endif // _INC_GraphPlot_H
Definition: GrayGraph.cpp:29
cRectT< GraphVal_t > CGraphRect
x/y rect or time/value rect.
Definition: cGraphCfg.h:67
cTimeFile CGraphTime
Definition: cGraphCfg.h:60
cRectI CRect
Compatible with MFC 2d CRect.
Definition: cRectI.h:243
cWndHandle CWnd
Definition: cWndHandle.h:669
interface const RECTQ_t & rect
Definition: cQuadtree.h:44
cPoint2i CPoint
Compatible with MFC 2d CPoint,CRect.
Definition: cPoint2.h:65
int ITERATE_t
like size_t but signed
Definition: Index.h:28
uint16 index
Definition: sample3.cpp:29