Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

more gui work

File size: 5.7 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// SHELL_COMMAND(gui, NetworkMonitor, toggleGUI)
26//  ->setAlias("ProxyGui");
27
28
29HostWidget::HostWidget(const std::string& name, const IP& ip)
30    : GLGuiBox(OrxGui::Horizontal)
31{
32  this->setName(name);
33  this->setIP(ip);
34
35  this->pack(&this->_name);
36  this->pack(&this->_ip);
37}
38
39void HostWidget::showing()
40{
41  this->_name.show();
42  this->_ip.show();
43}
44
45void HostWidget::hiding()
46{
47  this->_name.hide();
48  this->_ip.hide();
49}
50
51
52
53//======================================================//
54
55
56ProxyWidget::ProxyWidget(const std::string& proxyName, const IP& ip)
57    : _proxyWidget(proxyName, ip)
58{
59  this->_clientNameWidth = 100.0f;
60  this->pack(&_proxyWidget);
61}
62
63void ProxyWidget::addClient(const std::string& name, const IP& ip)
64{
65  HostWidget* newClient = new HostWidget(name, ip);
66  newClient->setNameWidth(this->_clientNameWidth);
67
68  this->pack(newClient);
69
70  if (this->isVisible())
71    newClient->show();
72}
73
74bool ProxyWidget::removeClient(const IP& ip)
75{
76  std::vector<HostWidget*>::iterator rmIt;
77  for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)
78  {
79    if (*(*rmIt) == ip)
80    {
81      delete (*rmIt);
82      this->_clients.erase(rmIt);
83      return true;
84    }
85  }
86  return false;
87}
88
89bool ProxyWidget::removeClient(const std::string& name)
90{
91  std::vector<HostWidget*>::iterator rmIt;
92  for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)
93  {
94    if (*(*rmIt) == name)
95    {
96      delete (*rmIt);
97      this->_clients.erase(rmIt);
98      return true;
99    }
100  }
101  return false;
102
103}
104
105bool ProxyWidget::removeClient(const std::string& name, const IP& ip)
106{
107  std::vector<HostWidget*>::iterator rmIt;
108  for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)
109  {
110    if (*(*rmIt) == ip && *(*rmIt) == name)
111    {
112      delete (*rmIt);
113      this->_clients.erase(rmIt);
114      return true;
115    }
116  }
117  return false;
118}
119
120
121void ProxyWidget::setClientNameWidths(float width)
122{
123  this->_clientNameWidth = width;
124  for (unsigned int i = 0; i < this->_clients.size(); ++i)
125    this->_clients[i]->setNameWidth(width);
126}
127
128void ProxyWidget::hiding()
129{
130  this->_proxyWidget.hide();
131  for (unsigned int i = 0; i < this->_clients.size(); ++i)
132    this->_clients[i]->hide();
133}
134
135void ProxyWidget::showing()
136{
137  this->_proxyWidget.show();
138  for (unsigned int i = 0; i < this->_clients.size(); ++i)
139    this->_clients[i]->show();
140}
141
142
143//======================================================//
144
145/**
146 * @brief standard constructor
147 */
148NetworkStatsWidget::NetworkStatsWidget(const NetworkMonitor* monitor)
149  : OrxGui::GLGuiFixedpositionBox(OrxGui::Center, OrxGui::Vertical), _thisHost("myName", IP(127, 0, 0 , 1))
150{
151  this->_monitor = monitor;
152
153  /*
154  this->_bar.setSize2D(100, 30);
155  this->pack(&this->_valueText);
156  this->_bar.setParent2D(&this->_valueText);
157
158  this->_valueText.setChangedTextColor(Color::white);
159
160  //this->setBackgroundTexture("maps/gui_element_background_2.png");
161  this->setBackgroundColor(Color(.5,.5,.5,1));
162
163  //this->_name.setBackgroundTexture(Texture());
164  //this->_valueText.setBackgroundTexture("maps/gui_element_background_2.png");
165  this->_bar.setBackgroundTexture(Texture());
166  this->_bar.setBackgroundColor(Color(0,0,0,0));
167  this->_bar.setForegroundTexture("maps/gui_element_background_faded.png");
168  this->_bar.setForegroundColor(Color(.5, .5, .5, 1));
169  this->_bar.setChangedValueColor(Color::black);
170  */
171  this->_thisHostIs.setText(std::string("I am ") + _monitor->getLocalNode()->getPeerInfo()->getNodeTypeString());
172
173  this->pack(&this->_thisHostIs);
174
175this->pack(&this->_thisHost);
176
177  this->pack(&this->_upstreamText);
178  this->pack(&this->_downstreamText);
179
180
181  this->pack(&this->_serverBox);
182
183
184  this->_refreshButton.setLabel("refresh");
185  this->_refreshButton.released.connect(this, &NetworkStatsWidget::rebuild);
186  this->pack(&this->_refreshButton);
187}
188
189
190/**
191 * @brief standard deconstructor
192 */
193NetworkStatsWidget::~NetworkStatsWidget ()
194{}
195
196
197void NetworkStatsWidget::setMaximum(float max)
198{
199  // this->_bar.setMaximum(max);
200}
201
202void NetworkStatsWidget::setValue(float value)
203{
204  MultiType val(value);
205  val.setType(MT_INT);
206  /*
207
208  this->_bar.setValue(value);
209  this->_bar.setForegroundColor(Color::slerpHSVColor(Color::red, Color::green, value/this->_bar.maximum()));
210  this->_bar.setFrontColor(Color(1,1,1,1), true);
211  this->_valueText.setText(val.getString());
212  */
213}
214
215
216void NetworkStatsWidget::addProxy(const std::string& name, const IP& proxy)
217{
218}
219
220void clearProxies();
221
222
223void NetworkStatsWidget::rebuild()
224{
225  while (!this->_proxies.empty())
226  {
227    delete this->_proxies.back();
228    this->_proxies.pop_back();
229  }
230
231
232
233}
234
235
236
237void NetworkStatsWidget::tick(float dt)
238{
239  assert (this->_monitor->getLocalNode() != NULL);
240  assert(this->_monitor->getLocalNode()->getPeerInfo() != NULL);
241
242  if(this->_monitor->getLocalNode()->getPeerInfo()->connectionMonitor != NULL)
243  {
244    ConnectionMonitor* mon = this->_monitor->getLocalNode()->getPeerInfo()->connectionMonitor;
245
246    this->_upstreamText.setText(MultiType(mon->getOutgoingZippedBandWidth()).getString());
247    this->_downstreamText.setText(MultiType(mon->getIncomingZippedBandWidth()).getString());
248  }
249}
250
251void NetworkStatsWidget::resize()
252{
253  GLGuiFixedpositionBox::resize();
254}
255
256
257void NetworkStatsWidget::showing()
258{}
259
260void NetworkStatsWidget::hiding()
261{}
Note: See TracBrowser for help on using the repository browser.