1 #pragma once 2 3 #include "gui/objects/Color.h" 4 #include "gui/objects/Point.h" 5 #include "math/Curve.h" 6 #include "objects/containers/Array.h" 7 #include "objects/containers/String.h" 8 #include "objects/wrappers/Function.h" 9 #include "objects/wrappers/Optional.h" 10 #include <algorithm> 11 #include <wx/dcclient.h> 12 #include <wx/frame.h> 13 #include <wx/panel.h> 14 #include <wx/propgrid/editors.h> 15 #include <wx/propgrid/propgrid.h> 16 #include <wx/sizer.h> 17 18 NAMESPACE_SPH_BEGIN 19 20 class CurvePanel : public wxPanel { 21 private: 22 Curve curve; 23 24 wxPoint mousePosition = wxDefaultPosition; 25 Optional<Size> lockedIdx; 26 Optional<Size> highlightIdx; 27 Optional<Size> highlightSegment; 28 29 public: 30 CurvePanel(wxWindow* parent); 31 setCurve(const Curve & newCurve)32 void setCurve(const Curve& newCurve) { 33 curve = newCurve; 34 } 35 getCurve()36 Curve getCurve() const { 37 return curve; 38 } 39 40 private: 41 void onPaint(wxPaintEvent& evt); 42 43 void onLeftDown(wxMouseEvent& evt); 44 45 void onLeftUp(wxMouseEvent& evt); 46 47 void onRightUp(wxMouseEvent& evt); 48 49 void onMouseMotion(wxMouseEvent& evt); 50 51 const static int padding = 30; 52 53 template <typename TPoint, typename T = int> 54 TPoint curveToWindow(const CurvePoint& p) const; 55 56 CurvePoint windowToCurve(const wxPoint2DDouble p) const; 57 58 Optional<Size> getIdx(const wxPoint mousePos) const; 59 60 Optional<Size> getSegment(const wxPoint mousePos) const; 61 }; 62 63 class CurveEditor : public wxPGEditor { 64 public: 65 virtual wxPGWindowList CreateControls(wxPropertyGrid* propgrid, 66 wxPGProperty* property, 67 const wxPoint& pos, 68 const wxSize& size) const override; 69 70 virtual void UpdateControl(wxPGProperty* property, wxWindow* ctrl) const override; 71 72 virtual void DrawValue(wxDC& dc, 73 const wxRect& rect, 74 wxPGProperty* property, 75 const wxString& text) const override; 76 77 virtual bool OnEvent(wxPropertyGrid* propgrid, 78 wxPGProperty* property, 79 wxWindow* wnd_primary, 80 wxEvent& event) const override; 81 }; 82 83 class CurveProperty : public wxStringProperty { 84 private: 85 Curve curve; 86 87 public: CurveProperty(const String & label,const Curve & curve)88 CurveProperty(const String& label, const Curve& curve) 89 : wxStringProperty(label.toUnicode(), "curve") 90 , curve(curve) {} 91 DoGetEditorClass()92 virtual const wxPGEditor* DoGetEditorClass() const override { 93 static wxPGEditor* editor = wxPropertyGrid::RegisterEditorClass(new CurveEditor(), "MyEditor"); 94 return editor; 95 } 96 setCurve(const Curve & newCurve)97 void setCurve(const Curve& newCurve) { 98 curve = newCurve; 99 } 100 getCurve()101 const Curve& getCurve() const { 102 return curve; 103 } 104 }; 105 106 107 class CurveDialog : public wxFrame { 108 private: 109 Function<void(const Curve&)> curveChanged; 110 111 public: 112 CurveDialog(wxWindow* parent, const Curve& curve, Function<void(const Curve&)> curveChanged); 113 }; 114 115 NAMESPACE_SPH_END 116