Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/util/network_stats_widget.cc @ 9426

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

orxonox/trunk: merged the proxy back

merged with commandsvn merge -r9346:HEAD https://svn.orxonox.net/orxonox/branches/proxy .

no conflicts

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