core/vgui/vgui_style.cxx
Go to the documentation of this file.
00001 // This is core/vgui/vgui_style.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \brief  See vgui_style.h for a description of this file.
00008 // \author Philip C. Pritchett, RRG, University of Oxford
00009 // \date   18 Oct 99
00010 //
00011 // \verbatim
00012 //  Modifications
00013 //   18-OCT-1999 P.Pritchett - Initial version.
00014 // \endverbatim
00015 
00016 #include "vgui_style.h"
00017 #include "vgui_macro.h"
00018 #include "vgui_gl.h"
00019 
00020 
00021 //: Create a new style object
00022 vgui_style_sptr
00023 vgui_style::new_style()
00024 {
00025   return vgui_style_sptr(new vgui_style());
00026 }
00027 
00028 //: Create a new style object
00029 vgui_style_sptr
00030 vgui_style::new_style(float r, float g, float b, float point_size, float line_width, float alpha)
00031 {
00032   return vgui_style_sptr(new vgui_style(r, g, b, point_size, line_width, alpha));
00033 }
00034 
00035 //: Create a new style object from an existing one;
00036 vgui_style_sptr
00037 vgui_style::new_style(const vgui_style_sptr& s)
00038 {
00039   return vgui_style_sptr( new vgui_style( s->rgba[0],s->rgba[1],s->rgba[2],
00040                                           s->point_size,s->line_width,s->rgba[3] ) );
00041 }
00042 
00043 
00044 vgui_style::vgui_style()
00045 {
00046   rgba[0] = 1;
00047   rgba[1] = 1;
00048   rgba[2] = 1;
00049   rgba[3] = 1;
00050   line_width = 1;
00051   point_size = 1;
00052 }
00053 
00054 
00055 //: Constructor - creates a style and initializes the values
00056 vgui_style::vgui_style(float r, float g, float b, float ps, float lw, float alpha)
00057  : point_size(ps), line_width(lw)
00058 {
00059   rgba[0] = r;
00060   rgba[1] = g;
00061   rgba[2] = b;
00062   rgba[3] = alpha;
00063 }
00064 
00065 
00066 vgui_style::~vgui_style() {
00067   // to aid in debugging destroyed styles
00068   rgba[0] = -1.0f;
00069   rgba[1] = -1.0f;
00070   rgba[2] = -1.0f;
00071   rgba[3] = -1.0f;
00072   line_width = -1.0f;
00073   point_size = -1.0f;
00074 }
00075 
00076 void
00077 vgui_style::apply_color() const
00078 {
00079   glColor4f( rgba[0], rgba[1], rgba[2], rgba[3] );
00080 }
00081 
00082 void
00083 vgui_style::apply_line_width() const
00084 {
00085   if ( line_width > 0.0 )
00086     glLineWidth( line_width );
00087 }
00088 
00089 void
00090 vgui_style::apply_point_size() const
00091 {
00092   if ( point_size > 0.0 )
00093     glPointSize( point_size );
00094 }
00095 
00096 void
00097 vgui_style::apply_all() const
00098 {
00099   apply_color();
00100   apply_point_size();
00101   apply_line_width();
00102 }
00103 
00104 
00105 // DO NOT inline in header file - that may cause "instantiation before
00106 // specialisation" compile error when instantiating vbl_smart_ptr<vgui_style>
00107 vgui_style_equal::vgui_style_equal(vgui_style_sptr s1) : s_(s1) {}
00108 
00109 // DO NOT inline in header file - that may cause "instantiation before
00110 // specialisation" compile error when instantiating vbl_smart_ptr<vgui_style>
00111 bool vgui_style_equal::operator() (vgui_style_sptr s2)
00112 {
00113   return s_->rgba[0] == s2->rgba[0] &&
00114          s_->rgba[1] == s2->rgba[1] &&
00115          s_->rgba[2] == s2->rgba[2] &&
00116          s_->rgba[3] == s2->rgba[3] &&
00117          s_->point_size == s2->point_size &&
00118          s_->line_width == s2->line_width;
00119 }