Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

more about the widget

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