Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gl/glgui_table.cc @ 8626

Last change on this file since 8626 was 8619, checked in by bensch, 18 years ago

trunk: merged the gui-branche back.
merged with command:
svn merge -r8520:HEAD https://svn.orxonox.net/orxonox/branches/gui
no conflicts

File size: 6.4 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI
17
18#include "glgui_table.h"
19#include "debug.h"
20
21namespace OrxGui
22{
23  /**
24   * @brief standard constructor
25   */
26  GLGuiTable::GLGuiTable (unsigned int rows, unsigned int columns)
27  {
28    this->init();
29    this->setRowCount(rows);
30    this->setColumnCount(columns);
31  }
32
33
34  /**
35   * @brief standard deconstructor
36   */
37  GLGuiTable::~GLGuiTable()
38  {}
39
40  /**
41   * @brief initializes the GUI-element
42   */
43  void GLGuiTable::init()
44  {
45    this->setClassID(CL_GLGUI_TABLE, "GLGuiTable");
46
47    this->setFocusable(true);
48    this->setClickable(true);
49
50    this->resize();
51  }
52
53
54  void GLGuiTable::setRowCount(unsigned int rowCount)
55  {
56
57    unsigned int currentRowCount = this->rowCount();
58    this->_entries.resize(rowCount);
59    for (unsigned int i = currentRowCount; i < this->rowCount(); ++i)
60    {
61      this->_entries[i].resize(columnCount(), LimitedWidthText("fonts/final_frontier.ttf", 20));
62      for (unsigned int j = 0; j < columnCount(); ++j)
63        this->applyTextSettings(i, j, &this->_entries[i][j]);
64    }
65
66    assert(this->checkIntegrity());
67    this->debug();
68
69    if (!this->isVisible())
70      this->hiding();
71  }
72
73  void GLGuiTable::setColumnCount(unsigned int columnCount)
74  {
75    unsigned int i;
76    unsigned int currentColumnCount = this->columnCount();
77
78    // setup Headers.
79    this->_headers.resize(columnCount, LimitedWidthText("fonts/final_frontier.ttf", 20));
80    for (i = currentColumnCount; i < columnCount; ++i)
81      this->applyTextSettings(0, i, &this->_headers[i]);
82
83    for (i = 0; i < rowCount(); i++)
84    {
85      this->_entries[i].resize(columnCount, LimitedWidthText("fonts/final_frontier.ttf", 20));
86      for (unsigned int j = currentColumnCount; j < columnCount; ++j)
87        this->applyTextSettings(i, j, &this->_entries[i][j]);
88
89    }
90    assert(this->checkIntegrity());
91    this->debug();
92
93    if (!this->isVisible())
94      this->hiding();
95  }
96
97
98
99
100  void GLGuiTable::setHeader(unsigned int number, const std::string& headerName)
101  {
102    if (number >= this->columnCount())
103      this->setColumnCount(number + 1);
104    this->_headers[number].setText(headerName);
105  }
106
107  void GLGuiTable::setHeader(const std::vector<std::string>& headerNames)
108  {
109    for (unsigned int i = 0; i < headerNames.size(); ++i)
110      this->setHeader(i, headerNames[i]);
111  }
112
113  void GLGuiTable::setEntry(unsigned int column, unsigned int row, const std::string& name)
114  {
115    if (column >= this->columnCount() )
116      this->setColumnCount(column + 1);
117    if (row >= this->rowCount() )
118      this->setRowCount(row + 1);
119    this->_entries[row][column].setText(name);
120  }
121
122  void GLGuiTable::setColumnWidth(unsigned int column, float size)
123  {
124    this->_headers[column].setLineWidth(size);
125    for (unsigned int i = 0; i < this->rowCount(); ++i)
126      this->_entries[i][column].setLineWidth(size);
127
128  }
129
130  /// TODO.
131  void GLGuiTable::setRowHeight(unsigned int row, unsigned int size)
132{}
133
134
135
136
137  /**
138   * removes the focus from this Widget.
139   */
140  void GLGuiTable::removedFocus()
141  {
142    GLGuiWidget::removedFocus();
143  }
144
145
146
147  /**
148   * @brief Processes an Event.
149   * @param event The event to be processed
150   * @return true if the event was catched.
151   */
152  bool GLGuiTable::processEvent(const Event& event)
153  {
154    return false;
155  }
156
157
158  /**
159   * @brief Resizes the Widget to the new Size-constraints.
160   */
161  void GLGuiTable::resize()
162  {
163    GLGuiWidget::resize();
164  }
165
166  void GLGuiTable::updateFrontColor()
167  {
168    for (unsigned int i = 0; i < this->columnCount(); ++i)
169    {
170      this->_headers[i].setColor(this->foregroundColor());
171      for (unsigned int j = 0; j < this->rowCount(); ++j)
172        this->_entries[j][i].setColor(this->foregroundColor());
173    }
174  }
175
176  void GLGuiTable::hiding()
177  {
178    for (unsigned int i = 0; i < this->columnCount(); ++i)
179    {
180      this->_headers[i].setVisibility(false);
181      for (unsigned int j = 0; j < this->rowCount(); ++j)
182        this->_entries[j][i].setVisibility(false);
183    }
184  }
185
186  void GLGuiTable::showing()
187  {
188    for (unsigned int i = 0; i < this->columnCount(); ++i)
189    {
190      this->_headers[i].setVisibility(true);
191      for (unsigned int j = 0; j < this->rowCount(); ++j)
192        this->_entries[j][i].setVisibility(true);
193    }
194  }
195
196
197  /**
198   * @brief ticks the Table
199   * @param dt the time passed.
200   */
201  void GLGuiTable::tick(float dt)
202{}
203
204  /**
205   * @brief draws the GLGuiTable
206   */
207  void GLGuiTable::draw() const
208  {
209    this->beginDraw();
210    GLGuiWidget::draw();
211
212    //     this->frontMaterial().select();
213    //     GLGuiWidget::drawRect(this->frontRect());
214
215    this->endDraw();
216  }
217
218
219  /**
220   * @brief applies the GLGuiNotifiers Settings to a single Text of the GLGuiNotifier.
221   * @param text the Text to apply the settings to.
222   */
223  void GLGuiTable::applyTextSettings(unsigned int row, unsigned int column, LimitedWidthText* text)
224  {
225    text->setSize(this->textSize());
226    //text->setLineWidth(  );
227    text->setFont("fonts/final_frontier.ttf", (int)this->textSize());
228
229    text->setColor(this->foregroundColor());
230    if (text->getParent2D() != this)
231      text->setParent2D(this);
232  }
233
234
235  void GLGuiTable::debug() const
236  {
237    PRINT(0)("Table: Size = %dx%d\n", this->rowCount(), this->columnCount());
238
239    for (unsigned int i = 0; i < this->rowCount(); ++i)
240      PRINT(0)("line %d: columns %d\n", i, this->_entries[i].size());
241  }
242
243
244  bool GLGuiTable::checkIntegrity() const
245  {
246    bool retVal = true;
247    if (rowCount() != this->_entries.size())
248    {
249      PRINTF(1)("ROW COUNT WRONG (is %d should be %d)\n", rowCount(), this->_entries.size());
250      retVal = false;
251    }
252    if (columnCount() != this->_headers.size())
253    {
254      PRINTF(1)("COLUMN COUNT WRONG (is %d should be %d)\n", columnCount(), this->_headers.size());
255      retVal = false;
256    }
257    for (unsigned int i = 0; i < this->rowCount(); ++i)
258      if (this->_entries[i].size() != this->columnCount())
259    {
260      PRINTF(1)("COLUMN-COUNT OF ROW %d WRONG (is %d should be %d)\n", i, this->_entries[i].size(), this->columnCount());
261      retVal = false;
262    }
263    return retVal;
264  }
265
266}
Note: See TracBrowser for help on using the repository browser.