Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/proxy: better proxy-width approximation

File size: 4.7 KB
RevLine 
[4744]1/*
[1853]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.
[1855]10
11   ### File Specific:
[9014]12   main-programmer: Benjamin Grauer
[1855]13   co-programmer: ...
[1853]14*/
15
[3955]16//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
[1853]17
[9330]18#include "network_stats_widget.h"
[1853]19
[9369]20#include "multi_type.h"
21
[8972]22namespace OrxGui
[3365]23{
[9383]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  {
[9385]54    this->_clientNameWidth = 100.0f;
[9383]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);
[9385]61    newClient->setNameWidth(this->_clientNameWidth);
[9383]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
[9385]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
[9383]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
[8972]142  /**
143   * @brief standard constructor
[8981]144   */
[9330]145  NetworkStatsWidget::NetworkStatsWidget ()
[9385]146  : GLGuiBox(Vertical), _thisHost("myName", IP(127, 0, 0 , 0))
[8972]147  {
[9330]148    //   this->setClassID(CL_PROTO_ID, "NetworkStatsWidget");
[8983]149
150    this->_bar.setSize2D(100, 30);
[8980]151    this->pack(&this->_valueText);
[8988]152    this->_bar.setParent2D(&this->_valueText);
[8973]153
[8991]154    this->_valueText.setChangedTextColor(Color::white);
155
156    //this->setBackgroundTexture("maps/gui_element_background_2.png");
[8980]157    this->setBackgroundColor(Color(.5,.5,.5,1));
158
[8991]159    //this->_name.setBackgroundTexture(Texture());
160    //this->_valueText.setBackgroundTexture("maps/gui_element_background_2.png");
[8980]161    this->_bar.setBackgroundTexture(Texture());
[8983]162    this->_bar.setBackgroundColor(Color(0,0,0,0));
[8990]163    this->_bar.setForegroundTexture("maps/gui_element_background_faded.png");
[8984]164    this->_bar.setForegroundColor(Color(.5, .5, .5, 1));
[8991]165    this->_bar.setChangedValueColor(Color::black);
[8972]166  }
[4320]167
168
[8972]169  /**
170   * @brief standard deconstructor
[4320]171   */
[9330]172  NetworkStatsWidget::~NetworkStatsWidget ()
[9383]173  {}
[8974]174
175
[9330]176  void NetworkStatsWidget::setMaximum(float max)
[8977]177  {
[8980]178    this->_bar.setMaximum(max);
[8974]179  }
180
[9330]181  void NetworkStatsWidget::setValue(float value)
[8974]182  {
[8976]183    MultiType val(value);
184    val.setType(MT_INT);
[8974]185
[8984]186
[8980]187    this->_bar.setValue(value);
[8986]188    this->_bar.setForegroundColor(Color::slerpHSVColor(Color::red, Color::green, value/this->_bar.maximum()));
[8985]189    this->_bar.setFrontColor(Color(1,1,1,1), true);
[8980]190    this->_valueText.setText(val.getString());
[8974]191  }
192
[9330]193  void NetworkStatsWidget::resize()
[8981]194  {
195    GLGuiBox::resize();
196  }
[8974]197
[8981]198
[9330]199  void NetworkStatsWidget::showing()
[8975]200  {
[8980]201    this->_valueText.show();
202    this->_bar.show();
[8975]203  }
[8974]204
[9330]205  void NetworkStatsWidget::hiding()
[8975]206  {
[8980]207    this->_valueText.hide();
208    this->_bar.hide();
[8975]209  }
[3365]210}
Note: See TracBrowser for help on using the repository browser.