X-Git-Url: http://git.tdb.fi/?p=netvis.git;a=blobdiff_plain;f=source%2Fport.cpp;fp=source%2Fport.cpp;h=d4be82ce182b0c7d195557741d114cafbc8896f9;hp=11ccfe0331674ebe05a1fc37a332c7216e7e02aa;hb=42bd2e83d66a98584540dd8cc5b47ee2349fe844;hpb=c147c9caaf9bc2f6323baf188a438ced9f0f5894 diff --git a/source/port.cpp b/source/port.cpp index 11ccfe0..d4be82c 100644 --- a/source/port.cpp +++ b/source/port.cpp @@ -5,14 +5,24 @@ Copyright @ 2008 Mikko Rasa, Mikkosoft Productions Distributed unter the GPL */ +#include #include #include +#include +#include +#include +#include #include #include "port.h" +#include "netvis.h" -Port::Port(unsigned n, const Msp::GL::Color &c): +using namespace std; +using namespace Msp; + +Port::Port(NetVis &v, unsigned n): + netvis(v), number(n), - color(c) + mesh((GL::COLOR4_UBYTE, GL::VERTEX2)) { char buf[128]; sockaddr_in addr; @@ -24,4 +34,62 @@ Port::Port(unsigned n, const Msp::GL::Color &c): name = buf; else name = Msp::lexical_cast(number); + + float best_score = 0; + for(unsigned i=0; (i<100 && best_score<1); ++i) + { + GL::Color c; + c.r = rand()*1.0/RAND_MAX; + c.g = rand()*1.0/RAND_MAX; + c.b = rand()*1.0/RAND_MAX; + float high = max(max(c.r, c.g), c.b); + c = c*(1.0/high); + if(number<1024) + { + float low = min(min(c.r, c.g), c.b); + c = (c+-low)*(1/(1-low)); + } + else + c = c*0.6+0.4; + + float score = 2; + const map &ports = netvis.get_ports(); + for(map::const_iterator j=ports.begin(); j!=ports.end(); ++j) + { + const GL::Color &other = j->second->get_color(); + float dr = c.r-other.r; + float dg = c.g-other.g; + float db = c.b-other.b; + score = min(score, dr*dr+dg*dg+db*db); + } + if(score>best_score) + { + best_score = score; + color = c; + } + } + color.a = 0.4f; + + GL::MeshBuilder bld(mesh); + bld.begin(GL::QUADS); + bld.color(color.r, color.g, color.b, color.a); + for(unsigned x=0; x<=4; x+=2) + { + bld.vertex(x+0, 0); + bld.vertex(x+10, 0); + bld.vertex(x+10, 10); + bld.vertex(x+0, 10); + } + bld.end(); +} + +void Port::render() const +{ + GL::PushMatrix push_; + mesh.draw(); + GL::translate(16, 1, 0); + GL::scale_uniform(10); + GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2)); + netvis.get_font().draw_string(name, imm); + GL::Texture::unbind(); }