3 This file is part of NetVis
4 Copyright @ 2008 Mikko Rasa, Mikkosoft Productions
5 Distributed unter the GPL
9 #include <netinet/in.h>
11 #include <msp/gl/immediate.h>
12 #include <msp/gl/matrix.h>
13 #include <msp/gl/meshbuilder.h>
14 #include <msp/gl/texture.h>
15 #include <msp/strings/lexicalcast.h>
22 Port::Port(NetVis &v, unsigned n):
25 mesh((GL::COLOR4_UBYTE, GL::VERTEX2))
29 addr.sin_family = AF_INET;
30 addr.sin_port = ntohs(number);
31 addr.sin_addr.s_addr = 0;
32 int err = getnameinfo(reinterpret_cast<sockaddr *>(&addr), sizeof(sockaddr_in), 0, 0, buf, sizeof(buf), 0);
36 name = Msp::lexical_cast(number);
38 const map<unsigned, Port *> &ports = netvis.get_ports();
40 if(ports.size()>100 && number>=1024)
41 tries = 10000/ports.size()+1;
43 for(unsigned i=0; (i<tries && best_score<1); ++i)
46 c.r = rand()*1.0/RAND_MAX;
47 c.g = rand()*1.0/RAND_MAX;
48 c.b = rand()*1.0/RAND_MAX;
49 float high = max(max(c.r, c.g), c.b);
53 float low = min(min(c.r, c.g), c.b);
54 c = (c+-low)*(1/(1-low));
60 for(map<unsigned, Port *>::const_iterator j=ports.begin(); j!=ports.end(); ++j)
62 if(number<1024 && j->first>1024)
64 const GL::Color &other = j->second->get_color();
65 float dr = c.r-other.r;
66 float dg = c.g-other.g;
67 float db = c.b-other.b;
68 score = min(score, dr*dr+dg*dg+db*db);
78 GL::MeshBuilder bld(mesh);
80 bld.color(color.r, color.g, color.b, color.a);
81 for(unsigned x=0; x<=4; x+=2)
91 void Port::render() const
95 GL::translate(16, 1, 0);
96 GL::scale_uniform(10);
97 GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
98 netvis.get_font().draw_string(name, imm);
99 GL::Texture::unbind();