core/vgui/vgui_text_tableau.h
Go to the documentation of this file.
00001 // This is core/vgui/vgui_text_tableau.h
00002 #ifndef vgui_text_tableau_h_
00003 #define vgui_text_tableau_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief  Tableau for rendering text.
00010 // \author Philip C. Pritchett, RRG, University of Oxford
00011 // \date   19 Oct 1999
00012 //
00013 //  Contains classes  vgui_text_tableau  vgui_text_tableau_new
00014 //
00015 // \verbatim
00016 //  Modifications
00017 //   19-OCT-1999 P.Pritchett - Initial version.
00018 //   30 Dec 1999 fsm. modified to render arbitrary text.
00019 //   23-FEB-2000 K.Y.McGaul - Handle now remains constant when text is removed,
00020 //                            this means the vector will never get smaller.
00021 //   06-AUG-2002 K.Y.McGaul - Changed to and added Doxygen comments.
00022 // \endverbatim
00023 
00024 
00025 #include <vcl_string.h>
00026 #include <vgui/vgui_tableau.h>
00027 #include <vgui/vgui_text_tableau_sptr.h>
00028 
00029 //: Tableau for rendering text.
00030 //
00031 //  Each piece of text is associated with an integer handle through
00032 //  which it can be retrieved, moved about, changed or removed.
00033 //
00034 //  This tableau will not display any text unless you have
00035 //  compiled with GLUT.
00036 class vgui_text_tableau : public vgui_tableau
00037 {
00038  public:
00039   //: Constructor - don't use this, use vgui_text_tableau_new.
00040   //  Creates empty text tableau.
00041   vgui_text_tableau();
00042 
00043   //: Remove all text from the display.
00044   void clear();
00045 
00046   //: Returns the number of pieces of text displayed in this tableau.
00047   unsigned size() const;
00048 
00049   //: Returns the tableau name ("vgui_text_tableau").
00050   vcl_string type_name() const;
00051 
00052   //: Add the given text to the display at the given x,y position.
00053   int add(float x, float y, char const *text);
00054 
00055   //: Add the given vcl_string to the display at the given x,y position.
00056   int add(float x, float y, vcl_string const &text) { return add(x,y,text.c_str()); }
00057 
00058   //: Set the colour of the text
00059   void set_colour(float r, float g, float b);
00060 
00061   //: Set the size of the text.
00062   //
00063   // This is one of the sizes supported by vgui_text_put.
00064   void set_size( unsigned sz );
00065 
00066   //: Return the x-coordinate of the text associated to given handle.
00067   float get_posx(int hndl) const;
00068 
00069   //: Return the y-coordinate of the text associated to given handle.
00070   float get_posy(int hndl) const;
00071 
00072   //: Return the text associated to the given handle.
00073   vcl_string const &get_text(int hndl) const;
00074 
00075   //: Move text associated to given handle to the given x,y position.
00076   void move(int hndl, float nx, float ny);
00077 
00078   //: Change the text associated to given handle to the given new text.
00079   void change(int hndl, char const *ntext);
00080 
00081   //: Change the text associated to given handle to the given new vcl_string.
00082   void change(int hndl, vcl_string const &ntext) { change(hndl, ntext.c_str()); }
00083 
00084   //: Delete text associated to given handle from the display.
00085   void remove(int hndl);
00086 
00087   //: Handles all events sent to this tableau.
00088   //  In particular, uses draw events to render the text.
00089   bool handle(vgui_event const &);
00090 
00091  protected:
00092   //: Destructor - called by vgui_text_tableau_sptr.
00093   ~vgui_text_tableau() { }
00094 
00095  private:
00096   vcl_vector<float> xs;
00097   vcl_vector<float> ys;
00098   vcl_vector<float> r_, g_, b_;
00099   vcl_vector<vcl_string> ts;
00100   vcl_vector<unsigned> sz_;
00101 
00102   float cur_r_, cur_g_, cur_b_;
00103   unsigned cur_sz_;
00104 
00105   //: Position of the first empty space in the vectors
00106   unsigned first_empty;
00107 };
00108 
00109 //: Create a smart-pointer to a vgui_text_tableau.
00110 struct vgui_text_tableau_new : public vgui_text_tableau_sptr
00111 {
00112   typedef vgui_text_tableau_sptr base;
00113 
00114   //: Constructor - creates a default vgui_text_tableau.
00115   vgui_text_tableau_new() : base(new vgui_text_tableau()) { }
00116 };
00117 
00118 #endif // vgui_text_tableau_h_