00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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.);
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
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