core/vgui/wx/wxSliderPanel.h
Go to the documentation of this file.
00001 // This is core/vgui/wx/wxSliderPanel.h
00002 #ifndef wxSliderPanel_h_
00003 #define wxSliderPanel_h_
00004 //:
00005 // \file
00006 // \brief  A wxPanel with a bank of sliders and text fields.
00007 // \author Matt Leotta
00008 // \date   August 6, 2008
00009 //
00010 
00011 #include <wx/scrolwin.h>
00012 #include <vgui/vgui_observable.h>
00013 #include <vcl_vector.h>
00014 
00015 // forward declarations
00016 class wxSlider;
00017 class wxTextCtrl;
00018 
00019 //: A wxPanel with a bank of sliders and text fields
00020 // This is useful for adjusting a point in N-D parameter space
00021 // Each dimension has a min and max (for the slider)
00022 class wxSliderPanel: public wxScrolledWindow, public vgui_observable
00023 {
00024   DECLARE_DYNAMIC_CLASS( wxSliderPanel )
00025   DECLARE_EVENT_TABLE()
00026 
00027  public:
00028   // Constructors
00029   wxSliderPanel();
00030   wxSliderPanel(wxWindow* parent,
00031                 wxWindowID id = wxID_ANY,
00032                 wxWindowID base_id = 10100,
00033                 const wxPoint& pos = wxDefaultPosition,
00034                 const wxSize& size = wxDefaultSize,
00035                 long style = wxVSCROLL|wxSUNKEN_BORDER|wxTAB_TRAVERSAL,
00036                 const wxString& name = wxT("wxSliderPanel"));
00037 
00038   //: Creation
00039   bool Create(wxWindow* parent,
00040               wxWindowID id = wxID_ANY,
00041               wxWindowID base_id = 10100,
00042               const wxPoint& pos = wxDefaultPosition,
00043               const wxSize& size = wxDefaultSize,
00044               long style = wxVSCROLL|wxSUNKEN_BORDER|wxTAB_TRAVERSAL,
00045               const wxString& name = wxT("wxSliderPanel"));
00046 
00047   // Destructor
00048   ~wxSliderPanel();
00049 
00050   //: Initialises member variables
00051   void Init();
00052 
00053   //: Creates the controls and sizers
00054   void CreateControls();
00055 
00056   //: Create new sliders with these bounds and initial values
00057   void CreateSliders(const vcl_vector<double>& init_vals,
00058                      const vcl_vector<double>& min_vals,
00059                      const vcl_vector<double>& max_vals);
00060 
00061   //: Event handler
00062   void OnSliderTrack( wxScrollEvent& event );
00063   //: Event handler
00064   void OnSliderChange( wxScrollEvent& event );
00065   //: Event handler
00066   void OnChangeText( wxCommandEvent& event );
00067   //: Event handler
00068   void OnEnterText( wxCommandEvent& event );
00069 
00070   //: Used by event handles to validate and lookup widgets
00071   int GetWidgets(const wxEvent& event, wxSlider*& slider, wxTextCtrl*& text);
00072 
00073   //: Return the vector of data
00074   const vcl_vector<double>& data() const { return vals_; }
00075 
00076   //: Update the data
00077   void update_data(vcl_vector<double>& data,
00078                    bool send_messages = true);
00079   //: Update the data
00080   void update_data(unsigned int i, double val,
00081                    bool send_messages = true);
00082 
00083   //: Return the number of sliders
00084   unsigned int size() const { return vals_.size(); }
00085 
00086   //: Convert a slider position to a double value
00087   double sp_to_val(unsigned int idx, int sp) const;
00088   //: Convert a double value to a slider position
00089   int val_to_sp(unsigned int idx, double val) const;
00090 
00091   //: Should we show tooltips?
00092   static bool ShowToolTips();
00093 
00094   //: These static memory address are used to identify vgui_message types
00095   static const char update[];
00096   static const char enter[];
00097 
00098  private:
00099   wxWindowID base_id_;
00100   vcl_vector<double> vals_;
00101   vcl_vector<double> min_vals_;
00102   vcl_vector<double> max_vals_;
00103 
00104   //: used to disable sending of message
00105   bool send_messages_;
00106 };
00107 
00108 
00109 #endif // wxSliderPanel_h_