core/vgui/vgui_displaybase_tableau.h
Go to the documentation of this file.
00001 // This is core/vgui/vgui_displaybase_tableau.h
00002 #ifndef vgui_displaybase_tableau_h_
00003 #define vgui_displaybase_tableau_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief  Tableau with display list functionality, can use any type of soview.
00010 // \author Philip C. Pritchett, Robotics Research Group, University of Oxford
00011 // \date   14 Sep 1999
00012 //
00013 //  Contains classes  vgui_displaybase_tableau  vgui_displaybase_tableau_new
00014 //                    vgui_displaybase_tableau_selection_callback
00015 //
00016 // \verbatim
00017 //  Modifications
00018 //   14-SEP-1999 P.Pritchett - Initial version.
00019 //   01-OCT-2002 K.Y.McGaul - Moved displaybase to displaybase_tableau.
00020 //   25-AUG-2003 M.Johnson - Altered to allow named groupings of soviews
00021 //   06-OCT-2009 Ricardo Fabbri - add soview doesn't check for duplicates anymore
00022 // \endverbatim
00023 
00024 #include <vcl_vector.h>
00025 #include <vcl_map.h>
00026 
00027 #include <vgui/vgui_gl.h>
00028 #include <vgui/vgui_tableau.h>
00029 #include <vgui/vgui_style_sptr.h>
00030 
00031 class vgui_soview;
00032 class vgui_event;
00033 
00034 //: Implement one of these to be told about picking etc.
00035 struct vgui_displaybase_tableau_selection_callback
00036 {
00037   virtual ~vgui_displaybase_tableau_selection_callback() {}
00038   virtual bool select(unsigned iden);
00039   virtual bool deselect(unsigned iden);
00040   virtual bool deselect_all();
00041 };
00042 
00043 //: Struct to maintain grouping information for soviews
00044 struct vgui_displaybase_tableau_grouping
00045 {
00046   // list of objects belonging to this group
00047   // duplicates entry in main objects list
00048   vcl_vector<vgui_soview*> objects;
00049 
00050   // style that will be used for override features
00051   vgui_style_sptr style;
00052 
00053   // used to hide or show this group of soviews
00054   bool hide;
00055 
00056   // applies a new temporary color to all soviews in this grouping
00057   bool color_override;
00058 
00059   // applies a new temporary point size to all soviews in this grouping
00060   bool point_size_override;
00061 
00062   // applies a new temporary line width to all soviews in this grouping
00063   bool line_width_override;
00064 };
00065 
00066 #include "vgui_displaybase_tableau_sptr.h"
00067 
00068 //: Tableau with display list functionality, can use any type of soview.
00069 class vgui_displaybase_tableau : public vgui_tableau
00070 {
00071  public:
00072 
00073   //: Constructor - don't use this, use vgui_displaybase_tableau_new.
00074   vgui_displaybase_tableau();
00075  ~vgui_displaybase_tableau();
00076 
00077   // vgui_tableau methods
00078   virtual bool handle(const vgui_event&);
00079 
00080   // vgui_displaybase_tableau methods/data
00081   GLenum gl_mode;
00082 
00083   void draw_soviews_render();
00084   void draw_soviews_select();
00085 
00086   // selections
00087   bool is_selected(unsigned iden);
00088   vcl_vector<unsigned> const & get_selected() const { return selections; }
00089   vcl_vector<vgui_soview*>     get_selected_soviews() const;
00090   bool select(unsigned iden);
00091   bool deselect(unsigned iden);
00092   bool deselect_all();
00093 
00094   // highlighting
00095   bool is_highlighted(unsigned iden) const { return iden == highlighted; }
00096   unsigned get_highlighted() const { return highlighted; }
00097   vgui_soview* get_highlighted_soview();
00098   bool highlight(unsigned iden) { highlighted = iden; return true; }
00099 
00100   // Add soview. The user is responsible for avoiding duplicates.
00101   // In a Debug mode build, a warning is issued when the soview has already been
00102   // added in a previous call.
00103   virtual void add(vgui_soview*);
00104 
00105   // remove soview (deletes the soview and sets the pointer to null)
00106   virtual void remove(vgui_soview*&);
00107 
00108   // removes all soviews from the display and deletes them
00109   virtual void clear();
00110 
00111   // grouping
00112   void set_current_grouping(vcl_string t_name) { current_grouping = t_name; }
00113   vcl_string get_current_grouping() const { return current_grouping; }
00114   vgui_displaybase_tableau_grouping* get_grouping_ptr( vcl_string t_name );
00115   vcl_vector< vcl_string > get_grouping_names();
00116 
00117   //: Attach your own selection callback.
00118   // You are in charge of deleting it later.
00119   void set_selection_callback(vgui_displaybase_tableau_selection_callback* cb);
00120 
00121   vcl_vector<vgui_soview*> const &get_all() const { return objects; }
00122   vcl_vector<unsigned>            get_all_ids() const;
00123 
00124   vgui_soview* contains_hit(vcl_vector<unsigned> hit);
00125 
00126   unsigned get_id() const { return id; }
00127 
00128  protected:
00129   vcl_vector<vgui_soview*> objects;
00130 
00131   vcl_map< vcl_string , vgui_displaybase_tableau_grouping > groupings;
00132 
00133   vcl_string current_grouping;
00134 
00135   vcl_vector<unsigned> selections;
00136   unsigned highlighted;
00137 
00138   int gl_display_list;
00139 
00140   vgui_displaybase_tableau_selection_callback* cb_;
00141 
00142  private:
00143   unsigned id;
00144 };
00145 
00146 //: Create a smart-pointer to a vgui_displaybase_tableau tableau.
00147 struct vgui_displaybase_tableau_new : public vgui_displaybase_tableau_sptr
00148 {
00149   typedef vgui_displaybase_tableau_sptr base;
00150   vgui_displaybase_tableau_new() : base(new vgui_displaybase_tableau()) {}
00151 };
00152 
00153 #endif // vgui_displaybase_tableau_h_