SPH
CurveDialog.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "gui/objects/Color.h"
4 #include "gui/objects/Point.h"
5 #include "math/Curve.h"
9 #include <algorithm>
10 #include <wx/dcclient.h>
11 #include <wx/frame.h>
12 #include <wx/panel.h>
13 #include <wx/propgrid/editors.h>
14 #include <wx/propgrid/propgrid.h>
15 #include <wx/sizer.h>
16 
18 
19 class CurvePanel : public wxPanel {
20 private:
21  Curve curve;
22 
23  wxPoint mousePosition = wxDefaultPosition;
24  Optional<Size> lockedIdx;
25  Optional<Size> highlightIdx;
26  Optional<Size> highlightSegment;
27 
28 public:
29  CurvePanel(wxWindow* parent);
30 
31  void setCurve(const Curve& newCurve) {
32  curve = newCurve;
33  }
34 
35  Curve getCurve() const {
36  return curve;
37  }
38 
39 private:
40  void onPaint(wxPaintEvent& evt);
41 
42  void onLeftDown(wxMouseEvent& evt);
43 
44  void onLeftUp(wxMouseEvent& evt);
45 
46  void onRightUp(wxMouseEvent& evt);
47 
48  void onMouseMotion(wxMouseEvent& evt);
49 
50  const static int padding = 30;
51 
52  template <typename TPoint, typename T = int>
53  TPoint curveToWindow(const CurvePoint& p) const;
54 
55  CurvePoint windowToCurve(const wxPoint2DDouble p) const;
56 
57  Optional<Size> getIdx(const wxPoint mousePos) const;
58 
59  Optional<Size> getSegment(const wxPoint mousePos) const;
60 };
61 
62 class CurveEditor : public wxPGEditor {
63 public:
64  virtual wxPGWindowList CreateControls(wxPropertyGrid* propgrid,
65  wxPGProperty* property,
66  const wxPoint& pos,
67  const wxSize& size) const override;
68 
69  virtual void UpdateControl(wxPGProperty* property, wxWindow* ctrl) const override;
70 
71  virtual void DrawValue(wxDC& dc,
72  const wxRect& rect,
73  wxPGProperty* property,
74  const wxString& text) const override;
75 
76  virtual bool OnEvent(wxPropertyGrid* propgrid,
77  wxPGProperty* property,
78  wxWindow* wnd_primary,
79  wxEvent& event) const override;
80 };
81 
82 class CurveProperty : public wxStringProperty {
83 private:
84  Curve curve;
85 
86 public:
87  CurveProperty(const wxString& label, const Curve& curve)
88  : wxStringProperty(label, "curve")
89  , curve(curve) {}
90 
91  virtual const wxPGEditor* DoGetEditorClass() const override {
92  static wxPGEditor* editor = wxPropertyGrid::RegisterEditorClass(new CurveEditor(), "MyEditor");
93  return editor;
94  }
95 
96  void setCurve(const Curve& newCurve) {
97  curve = newCurve;
98  }
99 
100  const Curve& getCurve() const {
101  return curve;
102  }
103 };
104 
105 
106 class CurveDialog : public wxFrame {
107 private:
108  Function<void(const Curve&)> curveChanged;
109 
110 public:
111  CurveDialog(wxWindow* parent, const Curve& curve, Function<void(const Curve&)> curveChanged);
112 };
113 
Generic dynamically allocated resizable storage.
NAMESPACE_SPH_BEGIN
Definition: BarnesHut.cpp:13
Generic wrappers of lambdas, functors and other callables.
#define NAMESPACE_SPH_END
Definition: Object.h:12
Wrapper of type value of which may or may not be present.
CurveDialog(wxWindow *parent, const Curve &curve, Function< void(const Curve &)> curveChanged)
virtual wxPGWindowList CreateControls(wxPropertyGrid *propgrid, wxPGProperty *property, const wxPoint &pos, const wxSize &size) const override
virtual void DrawValue(wxDC &dc, const wxRect &rect, wxPGProperty *property, const wxString &text) const override
virtual void UpdateControl(wxPGProperty *property, wxWindow *ctrl) const override
virtual bool OnEvent(wxPropertyGrid *propgrid, wxPGProperty *property, wxWindow *wnd_primary, wxEvent &event) const override
void setCurve(const Curve &newCurve)
Definition: CurveDialog.h:31
Curve getCurve() const
Definition: CurveDialog.h:35
CurvePanel(wxWindow *parent)
Definition: CurveDialog.cpp:9
CurveProperty(const wxString &label, const Curve &curve)
Definition: CurveDialog.h:87
void setCurve(const Curve &newCurve)
Definition: CurveDialog.h:96
virtual const wxPGEditor * DoGetEditorClass() const override
Definition: CurveDialog.h:91
const Curve & getCurve() const
Definition: CurveDialog.h:100
Represents a user-defined function, defined by a set of points interpolated by either piecewise linea...
Definition: Curve.h:19
Simple 2D vector with integer coordinates. Provides conversion from and to wxPoint.