Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8649 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
RevLine 
[4744]1/*
[1853]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.
[1855]10
11   ### File Specific:
[5360]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[5360]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI
[1853]17
[8614]18#include "glgui_table.h"
[8616]19#include "debug.h"
[1853]20
[7779]21namespace OrxGui
[3365]22{
[7779]23  /**
[8035]24   * @brief standard constructor
[8448]25   */
[8616]26  GLGuiTable::GLGuiTable (unsigned int rows, unsigned int columns)
[7779]27  {
28    this->init();
[8616]29    this->setRowCount(rows);
30    this->setColumnCount(columns);
[7779]31  }
[1853]32
33
[7779]34  /**
[8035]35   * @brief standard deconstructor
36   */
[8614]37  GLGuiTable::~GLGuiTable()
[7894]38  {}
[5360]39
[7779]40  /**
[8035]41   * @brief initializes the GUI-element
[7779]42   */
[8614]43  void GLGuiTable::init()
[7779]44  {
[8614]45    this->setClassID(CL_GLGUI_TABLE, "GLGuiTable");
[7893]46
47    this->setFocusable(true);
[8614]48    this->setClickable(true);
[7893]49
[8035]50    this->resize();
[7779]51  }
[5360]52
[8035]53
[8614]54  void GLGuiTable::setRowCount(unsigned int rowCount)
[7892]55  {
56
[8616]57    unsigned int currentRowCount = this->rowCount();
58    this->_entries.resize(rowCount);
59    for (unsigned int i = currentRowCount; i < this->rowCount(); ++i)
[8618]60    {
[8616]61      this->_entries[i].resize(columnCount(), LimitedWidthText("fonts/final_frontier.ttf", 20));
[8618]62      for (unsigned int j = 0; j < columnCount(); ++j)
63        this->applyTextSettings(i, j, &this->_entries[i][j]);
64    }
[8616]65
66    assert(this->checkIntegrity());
67    this->debug();
68
[8614]69    if (!this->isVisible())
70      this->hiding();
[7893]71  }
[7892]72
[8614]73  void GLGuiTable::setColumnCount(unsigned int columnCount)
[7893]74  {
[8618]75    unsigned int i;
76    unsigned int currentColumnCount = this->columnCount();
77
78    // setup Headers.
[8616]79    this->_headers.resize(columnCount, LimitedWidthText("fonts/final_frontier.ttf", 20));
[8618]80    for (i = currentColumnCount; i < columnCount; ++i)
81      this->applyTextSettings(0, i, &this->_headers[i]);
82
83    for (i = 0; i < rowCount(); i++)
84    {
[8616]85      this->_entries[i].resize(columnCount, LimitedWidthText("fonts/final_frontier.ttf", 20));
[8618]86      for (unsigned int j = currentColumnCount; j < columnCount; ++j)
87        this->applyTextSettings(i, j, &this->_entries[i][j]);
[8616]88
[8618]89    }
[8616]90    assert(this->checkIntegrity());
91    this->debug();
92
[8614]93    if (!this->isVisible())
94      this->hiding();
[7892]95  }
96
[7893]97
[8618]98
99
[8615]100  void GLGuiTable::setHeader(unsigned int number, const std::string& headerName)
101  {
[8616]102    if (number >= this->columnCount())
[8615]103      this->setColumnCount(number + 1);
104    this->_headers[number].setText(headerName);
105  }
[8448]106
[8615]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  }
[8518]112
[8615]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
[8616]130  /// TODO.
[8615]131  void GLGuiTable::setRowHeight(unsigned int row, unsigned int size)
[8616]132{}
[8615]133
134
135
136
[8448]137  /**
[8035]138   * removes the focus from this Widget.
139   */
[8614]140  void GLGuiTable::removedFocus()
[7896]141  {
142    GLGuiWidget::removedFocus();
143  }
144
145
[8518]146
[8035]147  /**
[8448]148   * @brief Processes an Event.
[8035]149   * @param event The event to be processed
150   * @return true if the event was catched.
151   */
[8614]152  bool GLGuiTable::processEvent(const Event& event)
[7893]153  {
154    return false;
155  }
[7892]156
[7893]157
[8035]158  /**
159   * @brief Resizes the Widget to the new Size-constraints.
160   */
[8614]161  void GLGuiTable::resize()
[7894]162  {
[8035]163    GLGuiWidget::resize();
[7894]164  }
165
[8614]166  void GLGuiTable::updateFrontColor()
[8448]167  {
[8616]168    for (unsigned int i = 0; i < this->columnCount(); ++i)
[8614]169    {
170      this->_headers[i].setColor(this->foregroundColor());
[8616]171      for (unsigned int j = 0; j < this->rowCount(); ++j)
172        this->_entries[j][i].setColor(this->foregroundColor());
[8614]173    }
[8448]174  }
[7894]175
[8614]176  void GLGuiTable::hiding()
[8116]177  {
[8616]178    for (unsigned int i = 0; i < this->columnCount(); ++i)
[8614]179    {
180      this->_headers[i].setVisibility(false);
[8616]181      for (unsigned int j = 0; j < this->rowCount(); ++j)
182        this->_entries[j][i].setVisibility(false);
[8614]183    }
[8116]184  }
185
[8614]186  void GLGuiTable::showing()
[8116]187  {
[8616]188    for (unsigned int i = 0; i < this->columnCount(); ++i)
[8614]189    {
190      this->_headers[i].setVisibility(true);
[8616]191      for (unsigned int j = 0; j < this->rowCount(); ++j)
192        this->_entries[j][i].setVisibility(true);
[8614]193    }
[8116]194  }
195
[8616]196
[8035]197  /**
[8614]198   * @brief ticks the Table
[8035]199   * @param dt the time passed.
200   */
[8614]201  void GLGuiTable::tick(float dt)
[8615]202{}
[7894]203
[7779]204  /**
[8614]205   * @brief draws the GLGuiTable
[7779]206   */
[8614]207  void GLGuiTable::draw() const
[7779]208  {
[8035]209    this->beginDraw();
[7892]210    GLGuiWidget::draw();
211
[8529]212    //     this->frontMaterial().select();
213    //     GLGuiWidget::drawRect(this->frontRect());
[7892]214
215    this->endDraw();
[7779]216  }
[8616]217
[8618]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
[8616]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
[5360]266}
Note: See TracBrowser for help on using the repository browser.