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
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_
17
18#include "network_stats_widget.h"
19#include "network_monitor.h"
20
21#include "multi_type.h"
22
23#include "shell_command.h"
24
25#include "loading/resource_manager.h"
26
27// this fcuk does not work!
28// SHELL_COMMAND(gui, NetworkStatsWidget, toggleGUI)
29// ->setAlias("ProxyGui");
30
31
32HostWidget::HostWidget(const std::string& name, const IP& ip)
33    : GLGuiBox(OrxGui::Horizontal)
34{
35  this->setName(name);
36  this->setIP(ip);
37
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);
42
43  this->pack(&this->_name);
44  this->pack(&this->_ip);
45}
46
47void HostWidget::showing()
48{
49  this->_name.show();
50  this->_ip.show();
51}
52
53void HostWidget::hiding()
54{
55  this->_name.hide();
56  this->_ip.hide();
57}
58
59
60
61//======================================================//
62
63
64NodeWidget::NodeWidget(const std::string& proxyName, const IP& ip)
65    : _proxyWidget(proxyName, ip)
66{
67  this->_clientNameWidth = 100.0f;
68  this->pack(&_proxyWidget);
69}
70
71NodeWidget::NodeWidget(const NetworkNode* node)
72    : _proxyWidget("node", node->getPeerInfo()->ip)
73{
74  this->_clientNameWidth = 100.0f;
75  this->pack(&_proxyWidget);
76}
77
78
79void NodeWidget::addClient(const std::string& name, const IP& ip)
80{
81  HostWidget* newClient = new HostWidget(name, ip);
82  newClient->setNameWidth(this->_clientNameWidth);
83
84  this->pack(newClient);
85
86  if (this->isVisible())
87    newClient->show();
88}
89
90bool NodeWidget::removeClient(const IP& ip)
91{
92  std::vector<HostWidget*>::iterator rmIt;
93  for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)
94  {
95    if (*(*rmIt) == ip)
96    {
97      delete (*rmIt);
98      this->_clients.erase(rmIt);
99      return true;
100    }
101  }
102  return false;
103}
104
105bool NodeWidget::removeClient(const std::string& name)
106{
107  std::vector<HostWidget*>::iterator rmIt;
108  for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)
109  {
110    if (*(*rmIt) == name)
111    {
112      delete (*rmIt);
113      this->_clients.erase(rmIt);
114      return true;
115    }
116  }
117  return false;
118
119}
120
121bool NodeWidget::removeClient(const std::string& name, const IP& ip)
122{
123  std::vector<HostWidget*>::iterator rmIt;
124  for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)
125  {
126    if (*(*rmIt) == ip && *(*rmIt) == name)
127    {
128      delete (*rmIt);
129      this->_clients.erase(rmIt);
130      return true;
131    }
132  }
133  return false;
134}
135
136
137void NodeWidget::setClientNameWidths(float width)
138{
139  this->_clientNameWidth = width;
140  for (unsigned int i = 0; i < this->_clients.size(); ++i)
141    this->_clients[i]->setNameWidth(width);
142}
143
144void NodeWidget::hiding()
145{
146  this->_proxyWidget.hide();
147  for (unsigned int i = 0; i < this->_clients.size(); ++i)
148    this->_clients[i]->hide();
149}
150
151void NodeWidget::showing()
152{
153  this->_proxyWidget.show();
154  for (unsigned int i = 0; i < this->_clients.size(); ++i)
155    this->_clients[i]->show();
156}
157
158
159//======================================================//
160
161/**
162 * @brief standard constructor
163 */
164NetworkStatsWidget::NetworkStatsWidget(const NetworkMonitor* monitor)
165    : OrxGui::GLGuiFixedpositionBox(OrxGui::Center, OrxGui::Vertical), _thisHost("myName", IP(127, 0, 0 , 1))
166{
167  this->_monitor = monitor;
168
169  /*
170  this->_bar.setSize2D(100, 30);
171  this->pack(&this->_valueText);
172  this->_bar.setParent2D(&this->_valueText);
173
174  this->_valueText.setChangedTextColor(Color::white);
175
176  //this->setBackgroundTexture("maps/gui_element_background_2.png");
177  this->setBackgroundColor(Color(.5,.5,.5,1));
178
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);
186  */
187  this->_thisHostIs.setText(std::string("I am ") + _monitor->getLocalNode()->getPeerInfo()->getNodeTypeString());
188
189  this->pack(&this->_thisHostIs);
190
191  this->pack(&this->_thisHost);
192
193  this->pack(&this->_upstreamText);
194  this->pack(&this->_downstreamText);
195
196
197  this->pack(&this->_serverBox);
198
199
200  this->_refreshButton.setLabel("refresh");
201  this->_refreshButton.released.connect(this, &NetworkStatsWidget::rebuild);
202  this->pack(&this->_refreshButton);
203
204  this->rebuild();
205}
206
207
208/**
209 * @brief standard deconstructor
210 */
211NetworkStatsWidget::~NetworkStatsWidget ()
212{}
213
214
215void NetworkStatsWidget::addNode(const NetworkNode* node)
216{
217  this->_proxies.push_back(new NodeWidget(node));
218  this->pack(this->_proxies.back(), &this->_refreshButton);
219  this->_proxies.back()->show();
220}
221
222
223
224
225NetworkStatsWidget* NetworkStatsWidget::_statsWidget = NULL;
226
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
249void NetworkStatsWidget::setMaximum(float max)
250{
251  // this->_bar.setMaximum(max);
252}
253
254void NetworkStatsWidget::setValue(float value)
255{
256  MultiType val(value);
257  val.setType(MT_INT);
258  /*
259
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());
264  */
265}
266
267
268void NetworkStatsWidget::addProxy(const std::string& name, const IP& proxy)
269{}
270
271void clearProxies();
272
273
274void NetworkStatsWidget::rebuild()
275{
276  while (!this->_proxies.empty())
277  {
278    delete this->_proxies.back();
279    this->_proxies.pop_back();
280  }
281
282
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  }
288
289
290
291}
292
293
294
295void NetworkStatsWidget::tick(float dt)
296{
297  assert (this->_monitor->getLocalNode() != NULL);
298  assert(this->_monitor->getLocalNode()->getPeerInfo() != NULL);
299
300  if(this->_monitor->getLocalNode()->getPeerInfo()->connectionMonitor != NULL)
301  {
302    ConnectionMonitor* mon = this->_monitor->getLocalNode()->getPeerInfo()->connectionMonitor;
303
304    this->_upstreamText.setText(MultiType(mon->getOutgoingZippedBandWidth()).getString());
305    this->_downstreamText.setText(MultiType(mon->getIncomingZippedBandWidth()).getString());
306  }
307}
308
309void NetworkStatsWidget::resize()
310{
311  GLGuiFixedpositionBox::resize();
312}
313
314
315void NetworkStatsWidget::showing()
316{}
317
318void NetworkStatsWidget::hiding()
319{}
Note: See TracBrowser for help on using the repository browser.