Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

vgui_text_tableau.cxx

Go to the documentation of this file.
00001 // This is core/vgui/vgui_text_tableau.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \brief  See vgui_text_tableau.h for a description of this file.
00008 // \author Philip C. Pritchett, RRG, University of Oxford
00009 // \date   19 Oct 99
00010 //
00011 // \verbatim
00012 //  Modifications
00013 //   19-OCT-1999 P.Pritchett - Initial version.
00014 // \endverbatim
00015 
00016 #include "vgui_text_tableau.h"
00017 #include <vgui/vgui_text_put.h>
00018 #include <vgui/vgui_event.h>
00019 #include <vgui/vgui_gl.h>
00020 #include <vcl_cassert.h>
00021 
00022 vgui_text_tableau::vgui_text_tableau()
00023   : cur_r_( 1 ), cur_g_( 0 ), cur_b_( 0 ),
00024     cur_sz_( 24 ),
00025     first_empty(0)
00026 {
00027   // Default text colour is red:
00028   cur_r_ = 1; cur_g_ = 0; cur_b_ = 0;
00029 }
00030 
00031 vcl_string vgui_text_tableau::type_name() const { return "vgui_text_tableau"; }
00032 
00033 unsigned vgui_text_tableau::size() const {
00034   unsigned N=xs.size();
00035 //assert(N == ys.size()); // just to
00036 //assert(N == ts.size()); // make sure.
00037   return N;
00038 }
00039 
00040 void vgui_text_tableau::clear() {
00041   if (size() > 0) {
00042     xs.clear();
00043     ys.clear();
00044     ts.clear();
00045     post_redraw();
00046     first_empty = 0;
00047   }
00048 }
00049 
00050 int vgui_text_tableau::add(float x, float y, char const *text) {
00051   int return_val = first_empty;
00052   if (first_empty < size()) {
00053     xs[first_empty] = x;
00054     ys[first_empty] = y;
00055     ts[first_empty] = text;
00056     r_[first_empty] = cur_r_;
00057     g_[first_empty] = cur_g_;
00058     b_[first_empty] = cur_b_;
00059     sz_[first_empty] = cur_sz_;
00060     // Find next empty slot:
00061     while (first_empty < size()  &&  r_[first_empty] != -1)
00062       first_empty++;
00063   }
00064   else {
00065     xs.push_back(x);
00066     ys.push_back(y);
00067     ts.push_back(text);
00068     r_.push_back(cur_r_);
00069     g_.push_back(cur_g_);
00070     b_.push_back(cur_b_);
00071     sz_.push_back(cur_sz_);
00072     first_empty++;
00073   }
00074   post_redraw();
00075   return return_val;
00076 }
00077 
00078 void vgui_text_tableau::move(int handle, float nx, float ny) {
00079   assert(handle >= 0);
00080   assert((unsigned int)handle < size());
00081   xs[handle] = nx;
00082   ys[handle] = ny;
00083   post_redraw();
00084 }
00085 
00086 void vgui_text_tableau::set_colour(float r, float g, float b) {
00087   if (0 <= r && r <= 1 && 0 <= g && g <= 1 && 0 <= b && b <= 1)
00088   {
00089     cur_r_ = r;
00090     cur_g_ = g;
00091     cur_b_ = b;
00092   }
00093 }
00094 
00095 void vgui_text_tableau::set_size( unsigned s ) {
00096   cur_sz_ = s;
00097 }
00098 
00099 float vgui_text_tableau::get_posx(int handle) const {
00100   assert(handle >= 0);
00101   assert((unsigned int)handle < size());
00102   return xs[handle];
00103 }
00104 
00105 float vgui_text_tableau::get_posy(int handle) const {
00106   assert(handle >= 0);
00107   assert((unsigned int)handle < size());
00108   return ys[handle];
00109 }
00110 
00111 vcl_string const &vgui_text_tableau::get_text(int handle) const {
00112   assert(handle >= 0);
00113   assert((unsigned int)handle < size());
00114   return ts[handle];
00115 }
00116 
00117 void vgui_text_tableau::remove(int handle) {
00118   assert(handle >= 0);
00119   assert((unsigned int)handle < size());
00120   // Using r_ to indicate empty is okay because valid values for r are in [0,1].
00121   r_[handle] = -1;
00122 
00123   // kym - don't do this because it changes handles of values remaining in list:
00124   //xs.erase(xs.begin() + handle);
00125   //ys.erase(ys.begin() + handle);
00126   //ts.erase(ts.begin() + handle);
00127 
00128   post_redraw();
00129   if ((unsigned int)handle < first_empty)
00130     first_empty = handle;
00131 }
00132 
00133 void vgui_text_tableau::change(int handle, char const *ntext) {
00134   assert(handle >= 0);
00135   assert((unsigned int)handle < size());
00136   ts[handle] = ntext;
00137   post_redraw();
00138 }
00139 
00140 bool vgui_text_tableau::handle(vgui_event const &e) {
00141   if (e.type != vgui_DRAW)
00142     return false;
00143 
00144   // set OpenGL state suitable for rendering 2D bitmap fonts :
00145   glDisable(GL_CULL_FACE);
00146   glDisable(GL_DEPTH_TEST);
00147   glDisable(GL_TEXTURE_2D);
00148   glDisable(GL_LIGHTING);
00149   glShadeModel(GL_FLAT);
00150 
00151   for (unsigned i=0; i<size(); ++i) {
00152     if (r_[i] != -1) {
00153       glColor3f(r_[i],g_[i],b_[i]);
00154       glRasterPos2f(xs[i], ys[i]);
00155       ::vgui_text_put(ts[i].c_str(),sz_[i]);
00156     }
00157   }
00158   return true;
00159 }

Generated on Thu Jan 10 14:42:07 2008 for core/vgui by  doxygen 1.4.4