00001 // This is core/vgui/vgui_style.h 00002 #ifndef vgui_style_h_ 00003 #define vgui_style_h_ 00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE 00005 #pragma interface 00006 #endif 00007 //: 00008 // \file 00009 // \brief Style (colour, line width, point radius) of a geometric object. 00010 // \author Philip C. Pritchett, Robotics Research Group, University of Oxford 00011 // \date 18 Oct 99 00012 // 00013 // Contains classes vgui_style, vgui_style_equal 00014 // 00015 // \verbatim 00016 // Modifications 00017 // 18-OCT-1999 P.Pritchett - Initial version. 00018 // 07-AUG-2002 K.Y.McGaul - Changed to and added Doxygen style comments. 00019 // 06-APR-2004 M.Leotta - Updated for use with smart pointers and no style factory 00020 // 2004/09/10 Peter Vanroose - Added explicit copy constructor (ref_count !) 00021 // 07-AUG-2006 M.Leotta - Enabled alpha channel for transparency 00022 // \endverbatim 00023 00024 #include <vbl/vbl_ref_count.h> 00025 #include <vgui/vgui_style_sptr.h> 00026 00027 //: Style (colour, line width, point radius) of a geometric object. 00028 // vgui_style objects are dynamic only and should be accessed via smart pointer only. 00029 // The static new_style member function is the only way to produce new styles. 00030 // You should call 00031 // \code 00032 // vgui_style::new_style(...); 00033 // \endcode 00034 // instead of 00035 // \code 00036 // new vgui_style(...); 00037 // \endcode 00038 class vgui_style : public vbl_ref_count 00039 { 00040 public: 00041 00042 //: Create a new style object 00043 static vgui_style_sptr new_style(); 00044 00045 //: Create a new style object 00046 static vgui_style_sptr new_style(float r, float g, float b, 00047 float point_size, float line_width, 00048 float alpha = 1.0f); 00049 00050 //: Create a new style object from an existing one; 00051 static vgui_style_sptr new_style(const vgui_style_sptr& style); 00052 00053 //: Sets the GL colour to this style's value 00054 // 00055 // Does nothing if the colour is invalid. 00056 void apply_color() const; 00057 00058 //: Sets the GL line width to this style's value 00059 // 00060 // Does nothing if the width is invalid (e.g. <= 0.0) 00061 void apply_line_width() const; 00062 00063 //: Sets the GL point size to this style's value 00064 // 00065 // Does nothing if the point size is invalid (e.g. <= 0.0) 00066 void apply_point_size() const; 00067 00068 //: Sets all the GL style parameters (colour, size, width). 00069 void apply_all() const; 00070 00071 //: Style colour. 00072 float rgba[4]; 00073 00074 //: Style point radius. 00075 float point_size; 00076 00077 //: Style line width. 00078 float line_width; 00079 00080 protected: 00081 //: Constructor - creates a style with default values. 00082 vgui_style(); 00083 00084 //: Constructor - creates a style and initializes the values 00085 vgui_style(float r, float g, float b, float point_size, float line_width, float alpha); 00086 00087 // Copy constructor 00088 vgui_style(vgui_style const& s) 00089 : vbl_ref_count(), point_size(s.point_size), line_width(s.line_width) 00090 { rgba[0]=s.rgba[0]; rgba[1]=s.rgba[1]; rgba[2]=s.rgba[2]; rgba[3]=s.rgba[3]; } 00091 00092 // Destructor - only the smart pointer should use this 00093 ~vgui_style(); 00094 00095 friend class vbl_smart_ptr<vgui_style>; 00096 }; 00097 00098 //: Finds out whether two vgui_styles are equal. 00099 class vgui_style_equal 00100 { 00101 public: 00102 //: Constructor - takes one of the styles to be compared. 00103 vgui_style_equal(vgui_style_sptr s1); 00104 00105 //: Returns true if the given style is identical to the stored style. 00106 bool operator() (vgui_style_sptr s2); 00107 00108 vgui_style_sptr s_; 00109 }; 00110 00111 #endif // vgui_style_h_