src/tron/cockpit/cLabel.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023 
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #include "cockpit/cLabel.h"
00029 
00030 #ifndef DEDICATED
00031 
00032 #include "rFont.h"
00033 #include <numeric>
00034 
00035 namespace cWidget {
00036 
00037 bool Label::Process(tXmlParser::node cur) {
00038     if (
00039         WithTable       ::Process(cur) ||
00040         WithCoordinates ::Process(cur) ||
00041         WithCaption     ::Process(cur))
00042         return true;
00043     else {
00044         DisplayError(cur);
00045         return false;
00046     }
00047 }
00048 
00049 void Label::Render()
00050 {
00051     std::deque<std::deque<tString> > contents;
00052     unsigned maxlen = 0;
00053     {
00054         for(std::deque<std::deque<std::deque<tValue::Set> > >::iterator i(m_table.begin()); i!=m_table.end(); ++i) {
00055             if(i->size() > maxlen) maxlen = i->size();
00056         }
00057     }
00058     std::deque<float> coloumns(maxlen, 0.); //max widths
00059     {
00060         for(std::deque<std::deque<std::deque<tValue::Set> > >::iterator i(m_table.begin()); i!=m_table.end(); ++i) {
00061             contents.push_back(std::deque<tString>());
00062             std::deque<float>::iterator m(coloumns.begin());
00063             for(std::deque<std::deque<tValue::Set> >::iterator j(i->begin()); j!=i->end(); ++j, ++m) {
00064                 tColoredString result;
00065                 for(std::deque<tValue::Set>::iterator k(j->begin()); k!=j->end(); ++k) {
00066                     result += k->GetVal().GetString();
00067                 }
00068                 float size = rTextField::GetTextLength(result, m_size.y, true);
00069                 if(size > *m) {
00070                     *m = size;
00071                 }
00072                 contents.back().push_back(result);
00073             }
00074         }
00075     }
00076     if(m_captionloc != off) {
00077         int height = m_table.size();
00078         float width = std::accumulate(coloumns.begin(), coloumns.end(), float()) + (maxlen - 1)*m_size.x;
00079 
00080         tCoord captionloc(m_position.x + (width-rTextField::GetTextLength(m_caption, m_size.y))/2., 0);
00081         if(m_captionloc == top) {
00082             captionloc.y = m_position.y + m_size.y;
00083         } else if(m_captionloc) {
00084             captionloc.y = m_position.y - height*m_size.y;
00085         }
00086         rTextField c(captionloc.x,captionloc.y,m_size.y,sr_fontCockpit);
00087         c<<m_caption;
00088     }
00089 
00090     tCoord pos(0.,m_position.y);
00091     //now displaying the results
00092     {
00093         for(std::deque<std::deque<tString> >::iterator i(contents.begin()); i != contents.end(); ++i) {
00094             pos.x = m_position.x;
00095             std::deque<float>::iterator m(coloumns.begin());
00096             for(std::deque<tString>::iterator j(i->begin()); j != i->end(); ++j, ++m) {
00097                 rTextField c(pos.x,pos.y,m_size.y, sr_fontCockpit);
00098                 c<<*j;
00099                 pos.x += *m+m_size.x;
00100             }
00101             pos.y -= m_size.y;
00102         }
00103     }
00104 }
00105 
00106 }
00107 
00108 #endif

Generated on Sat Mar 15 22:56:05 2008 for Armagetron Advanced by  doxygen 1.5.4