Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 9383 was 9383, checked in by bensch, 19 years ago

much more elaborate host and proxy widgets

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