Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

movements

File size: 4.6 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
20#include "multi_type.h"
21
22#include "shell_command.h"
23//#include "network_monitor.h"
24
25SHELL_COMMAND(gui, NetworkStatsWidget, gui);
26
27
28HostWidget::HostWidget(const std::string& name, const IP& ip)
29  : GLGuiBox(OrxGui::Horizontal)
30{
31  this->setName(name);
32  this->setIP(ip);
33
34  this->pack(&this->_name);
35  this->pack(&this->_ip);
36}
37
38void HostWidget::showing()
39{
40  this->_name.show();
41  this->_ip.show();
42}
43
44void HostWidget::hiding()
45{
46  this->_name.hide();
47  this->_ip.hide();
48}
49
50
51
52//======================================================//
53
54
55ProxyWidget::ProxyWidget(const std::string& proxyName, const IP& ip)
56    : _proxyWidget(proxyName, ip)
57{
58  this->_clientNameWidth = 100.0f;
59  this->pack(&_proxyWidget);
60}
61
62void ProxyWidget::addClient(const std::string& name, const IP& ip)
63{
64  HostWidget* newClient = new HostWidget(name, ip);
65  newClient->setNameWidth(this->_clientNameWidth);
66
67  this->pack(newClient);
68
69  if (this->isVisible())
70    newClient->show();
71}
72
73bool ProxyWidget::removeClient(const IP& ip)
74{
75  std::vector<HostWidget*>::iterator rmIt;
76  for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)
77  {
78    if (*(*rmIt) == ip)
79    {
80      delete (*rmIt);
81      this->_clients.erase(rmIt);
82      return true;
83    }
84  }
85  return false;
86}
87
88bool ProxyWidget::removeClient(const std::string& name)
89{
90  std::vector<HostWidget*>::iterator rmIt;
91  for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)
92  {
93    if (*(*rmIt) == name)
94    {
95      delete (*rmIt);
96      this->_clients.erase(rmIt);
97      return true;
98    }
99  }
100  return false;
101
102}
103
104bool ProxyWidget::removeClient(const std::string& name, const IP& ip)
105{
106  std::vector<HostWidget*>::iterator rmIt;
107  for(rmIt = this->_clients.begin(); rmIt != this->_clients.end(); ++rmIt)
108  {
109    if (*(*rmIt) == ip && *(*rmIt) == name)
110    {
111      delete (*rmIt);
112      this->_clients.erase(rmIt);
113      return true;
114    }
115  }
116  return false;
117}
118
119
120void ProxyWidget::setClientNameWidths(float width)
121{
122  this->_clientNameWidth = width;
123  for (unsigned int i = 0; i < this->_clients.size(); ++i)
124    this->_clients[i]->setNameWidth(width);
125}
126
127void ProxyWidget::hiding()
128{
129  this->_proxyWidget.hide();
130  for (unsigned int i = 0; i < this->_clients.size(); ++i)
131    this->_clients[i]->hide();
132}
133
134void ProxyWidget::showing()
135{
136  this->_proxyWidget.show();
137  for (unsigned int i = 0; i < this->_clients.size(); ++i)
138    this->_clients[i]->show();
139}
140
141
142//======================================================//
143
144
145void NetworkStatsWidget::gui()
146{
147  printf("YEAH\n");
148}
149
150
151/**
152 * @brief standard constructor
153 */
154NetworkStatsWidget::NetworkStatsWidget ()
155  : GLGuiBox(OrxGui::Vertical), _thisHost("myName", IP(127, 0, 0 , 0))
156{
157  //   this->setClassID(CL_PROTO_ID, "NetworkStatsWidget");
158
159  this->_bar.setSize2D(100, 30);
160  this->pack(&this->_valueText);
161  this->_bar.setParent2D(&this->_valueText);
162
163  this->_valueText.setChangedTextColor(Color::white);
164
165  //this->setBackgroundTexture("maps/gui_element_background_2.png");
166  this->setBackgroundColor(Color(.5,.5,.5,1));
167
168  //this->_name.setBackgroundTexture(Texture());
169  //this->_valueText.setBackgroundTexture("maps/gui_element_background_2.png");
170  this->_bar.setBackgroundTexture(Texture());
171  this->_bar.setBackgroundColor(Color(0,0,0,0));
172  this->_bar.setForegroundTexture("maps/gui_element_background_faded.png");
173  this->_bar.setForegroundColor(Color(.5, .5, .5, 1));
174  this->_bar.setChangedValueColor(Color::black);
175}
176
177
178/**
179 * @brief standard deconstructor
180 */
181NetworkStatsWidget::~NetworkStatsWidget ()
182{}
183
184
185void NetworkStatsWidget::setMaximum(float max)
186{
187  this->_bar.setMaximum(max);
188}
189
190void NetworkStatsWidget::setValue(float value)
191{
192  MultiType val(value);
193  val.setType(MT_INT);
194
195
196  this->_bar.setValue(value);
197  this->_bar.setForegroundColor(Color::slerpHSVColor(Color::red, Color::green, value/this->_bar.maximum()));
198  this->_bar.setFrontColor(Color(1,1,1,1), true);
199  this->_valueText.setText(val.getString());
200}
201
202void NetworkStatsWidget::resize()
203{
204  GLGuiBox::resize();
205}
206
207
208void NetworkStatsWidget::showing()
209{
210  this->_valueText.show();
211  this->_bar.show();
212}
213
214void NetworkStatsWidget::hiding()
215{
216  this->_valueText.hide();
217  this->_bar.hide();
218}
Note: See TracBrowser for help on using the repository browser.