Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/lib/network/monitor/network_stats_widget.cc @ 9624

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

orxonox/proxy: gui with a better font

File size: 7.2 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:
[9014]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[3955]16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
[1853]17
[9330]18#include "network_stats_widget.h"
[9442]19#include "network_monitor.h"
[1853]20
[9369]21#include "multi_type.h"
22
[9444]23#include "shell_command.h"
24
[9623]25#include "loading/resource_manager.h"
26
[9607]27// this fcuk does not work!
28// SHELL_COMMAND(gui, NetworkStatsWidget, toggleGUI)
29// ->setAlias("ProxyGui");
[9444]30
31
[9437]32HostWidget::HostWidget(const std::string& name, const IP& ip)
[9442]33    : GLGuiBox(OrxGui::Horizontal)
[9437]34{
35  this->setName(name);
36  this->setIP(ip);
[9383]37
[9624]38  this->_name.setFont(Font(ResourceManager::getInstance()->getDataDir() + "/fonts/arial.ttf", 20));
39  this->_name.setTextSize(15);
40  this->_ip.setFont(Font(ResourceManager::getInstance()->getDataDir() + "fonts/arial.ttf", 20));
41  this->_ip.setTextSize(15);
[9622]42
[9437]43  this->pack(&this->_name);
44  this->pack(&this->_ip);
45}
[9383]46
[9437]47void HostWidget::showing()
48{
49  this->_name.show();
50  this->_ip.show();
51}
[9383]52
[9437]53void HostWidget::hiding()
54{
55  this->_name.hide();
56  this->_ip.hide();
57}
[9383]58
59
60
[9437]61//======================================================//
[9383]62
63
[9618]64NodeWidget::NodeWidget(const std::string& proxyName, const IP& ip)
[9437]65    : _proxyWidget(proxyName, ip)
66{
67  this->_clientNameWidth = 100.0f;
68  this->pack(&_proxyWidget);
69}
[9383]70
[9618]71NodeWidget::NodeWidget(const NetworkNode* node)
[9622]72    : _proxyWidget("node", node->getPeerInfo()->ip)
[9437]73{
[9618]74  this->_clientNameWidth = 100.0f;
75  this->pack(&_proxyWidget);
76}
77
78
79void NodeWidget::addClient(const std::string& name, const IP& ip)
80{
[9437]81  HostWidget* newClient = new HostWidget(name, ip);
82  newClient->setNameWidth(this->_clientNameWidth);
[9383]83
[9437]84  this->pack(newClient);
[9383]85
[9437]86  if (this->isVisible())
87    newClient->show();
88}
[9383]89
[9618]90bool NodeWidget::removeClient(const IP& ip)
[9437]91{
92  std::vector<HostWidget*>::iterator rmIt;
93  for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)
[9383]94  {
[9437]95    if (*(*rmIt) == ip)
[9383]96    {
[9437]97      delete (*rmIt);
98      this->_clients.erase(rmIt);
99      return true;
[9383]100    }
101  }
[9437]102  return false;
103}
[9383]104
[9618]105bool NodeWidget::removeClient(const std::string& name)
[9437]106{
107  std::vector<HostWidget*>::iterator rmIt;
108  for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)
[9383]109  {
[9437]110    if (*(*rmIt) == name)
[9383]111    {
[9437]112      delete (*rmIt);
113      this->_clients.erase(rmIt);
114      return true;
[9383]115    }
116  }
[9437]117  return false;
[9383]118
[9437]119}
120
[9618]121bool NodeWidget::removeClient(const std::string& name, const IP& ip)
[9437]122{
123  std::vector<HostWidget*>::iterator rmIt;
124  for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)
[9383]125  {
[9437]126    if (*(*rmIt) == ip && *(*rmIt) == name)
[9383]127    {
[9437]128      delete (*rmIt);
129      this->_clients.erase(rmIt);
130      return true;
[9383]131    }
132  }
[9437]133  return false;
134}
[9383]135
136
[9618]137void NodeWidget::setClientNameWidths(float width)
[9437]138{
139  this->_clientNameWidth = width;
140  for (unsigned int i = 0; i < this->_clients.size(); ++i)
141    this->_clients[i]->setNameWidth(width);
142}
[9385]143
[9618]144void NodeWidget::hiding()
[9437]145{
146  this->_proxyWidget.hide();
147  for (unsigned int i = 0; i < this->_clients.size(); ++i)
148    this->_clients[i]->hide();
149}
[9383]150
[9618]151void NodeWidget::showing()
[9437]152{
153  this->_proxyWidget.show();
154  for (unsigned int i = 0; i < this->_clients.size(); ++i)
155    this->_clients[i]->show();
156}
[9383]157
158
[9437]159//======================================================//
[9383]160
[9437]161/**
162 * @brief standard constructor
163 */
[9439]164NetworkStatsWidget::NetworkStatsWidget(const NetworkMonitor* monitor)
[9577]165    : OrxGui::GLGuiFixedpositionBox(OrxGui::Center, OrxGui::Vertical), _thisHost("myName", IP(127, 0, 0 , 1))
[9437]166{
[9439]167  this->_monitor = monitor;
[8983]168
[9438]169  /*
[9437]170  this->_bar.setSize2D(100, 30);
171  this->pack(&this->_valueText);
172  this->_bar.setParent2D(&this->_valueText);
[8973]173
[9437]174  this->_valueText.setChangedTextColor(Color::white);
[8991]175
[9437]176  //this->setBackgroundTexture("maps/gui_element_background_2.png");
177  this->setBackgroundColor(Color(.5,.5,.5,1));
[8980]178
[9437]179  //this->_name.setBackgroundTexture(Texture());
180  //this->_valueText.setBackgroundTexture("maps/gui_element_background_2.png");
181  this->_bar.setBackgroundTexture(Texture());
182  this->_bar.setBackgroundColor(Color(0,0,0,0));
183  this->_bar.setForegroundTexture("maps/gui_element_background_faded.png");
184  this->_bar.setForegroundColor(Color(.5, .5, .5, 1));
185  this->_bar.setChangedValueColor(Color::black);
[9438]186  */
[9546]187  this->_thisHostIs.setText(std::string("I am ") + _monitor->getLocalNode()->getPeerInfo()->getNodeTypeString());
[9438]188
[9546]189  this->pack(&this->_thisHostIs);
190
[9577]191  this->pack(&this->_thisHost);
[9546]192
[9438]193  this->pack(&this->_upstreamText);
194  this->pack(&this->_downstreamText);
195
[9567]196
[9569]197  this->pack(&this->_serverBox);
[9567]198
199
200  this->_refreshButton.setLabel("refresh");
201  this->_refreshButton.released.connect(this, &NetworkStatsWidget::rebuild);
202  this->pack(&this->_refreshButton);
[9618]203
204  this->rebuild();
[9437]205}
[4320]206
207
[9437]208/**
209 * @brief standard deconstructor
210 */
211NetworkStatsWidget::~NetworkStatsWidget ()
212{}
[8974]213
[9618]214
215void NetworkStatsWidget::addNode(const NetworkNode* node)
216{
217  this->_proxies.push_back(new NodeWidget(node));
[9622]218  this->pack(this->_proxies.back(), &this->_refreshButton);
[9618]219  this->_proxies.back()->show();
220}
221
222
223
224
[9577]225NetworkStatsWidget* NetworkStatsWidget::_statsWidget = NULL;
[8974]226
[9577]227#include "class_list.h"
228
229void NetworkStatsWidget::toggleGUI()
230{
231  BaseObject* bo = NULL;
232  const std::list<BaseObject*>* ls = ClassList::getList(CL_NETWORK_MONITOR);
233  if (ls != NULL && !ls->empty())
234    bo = ls->front();
235
236  if (bo != NULL && NetworkStatsWidget::_statsWidget == NULL)
237  {
238    NetworkStatsWidget::_statsWidget = new NetworkStatsWidget(dynamic_cast<NetworkMonitor*> (bo));
239    NetworkStatsWidget::_statsWidget->showAll();
240  }
241  else
242  {
243    delete NetworkStatsWidget::_statsWidget;
244    NetworkStatsWidget::_statsWidget = NULL;
245  }
246}
247
248
[9437]249void NetworkStatsWidget::setMaximum(float max)
250{
[9442]251  // this->_bar.setMaximum(max);
[9437]252}
[8974]253
[9437]254void NetworkStatsWidget::setValue(float value)
255{
256  MultiType val(value);
257  val.setType(MT_INT);
[9438]258  /*
[8974]259
[9437]260  this->_bar.setValue(value);
261  this->_bar.setForegroundColor(Color::slerpHSVColor(Color::red, Color::green, value/this->_bar.maximum()));
262  this->_bar.setFrontColor(Color(1,1,1,1), true);
263  this->_valueText.setText(val.getString());
[9438]264  */
[9437]265}
[8974]266
[9569]267
268void NetworkStatsWidget::addProxy(const std::string& name, const IP& proxy)
[9577]269{}
[9569]270
271void clearProxies();
272
273
[9567]274void NetworkStatsWidget::rebuild()
275{
[9569]276  while (!this->_proxies.empty())
277  {
278    delete this->_proxies.back();
279    this->_proxies.pop_back();
280  }
[9439]281
[9569]282
[9618]283  std::list<NetworkNode*>::const_iterator it = this->_monitor->getNodeList().begin();
284  for(; it != this->_monitor->getNodeList().end(); it++)
285  {
286    this->addNode(*it);
287  }
[9569]288
[9618]289
290
[9567]291}
292
293
294
[9439]295void NetworkStatsWidget::tick(float dt)
296{
[9442]297  assert (this->_monitor->getLocalNode() != NULL);
298  assert(this->_monitor->getLocalNode()->getPeerInfo() != NULL);
[9439]299
[9442]300  if(this->_monitor->getLocalNode()->getPeerInfo()->connectionMonitor != NULL)
301  {
302    ConnectionMonitor* mon = this->_monitor->getLocalNode()->getPeerInfo()->connectionMonitor;
[9439]303
[9442]304    this->_upstreamText.setText(MultiType(mon->getOutgoingZippedBandWidth()).getString());
305    this->_downstreamText.setText(MultiType(mon->getIncomingZippedBandWidth()).getString());
306  }
[9439]307}
308
[9437]309void NetworkStatsWidget::resize()
310{
[9556]311  GLGuiFixedpositionBox::resize();
[9437]312}
[8974]313
[8981]314
[9437]315void NetworkStatsWidget::showing()
[9442]316{}
[8974]317
[9437]318void NetworkStatsWidget::hiding()
[9442]319{}
Note: See TracBrowser for help on using the repository browser.