]> git.tdb.fi Git - netvis.git/blobdiff - source/port.cpp
Track and display the activity of ports
[netvis.git] / source / port.cpp
index 1e4219da1025fbff77823a4aebd949178a851bce..5c0bfa62435634892f970f282887e8ef006b41a8 100644 (file)
@@ -92,13 +92,36 @@ Port::Port(NetVis &v, unsigned n):
        bld.end();
 }
 
+void Port::add_activity(unsigned bytes)
+{
+       activity.add_bytes(bytes);
+}
+
+void Port::tick(const Time::TimeDelta &dt)
+{
+       activity.tick(dt);
+}
+
 void Port::render() const
 {
        GL::PushMatrix push_;
        mesh.draw();
+       {
+               GL::Immediate imm((GL::COLOR4_UBYTE, GL::VERTEX2));
+               imm.begin(GL::QUADS);
+               imm.color(color.r, color.g, color.b, color.a);
+               unsigned x = static_cast<unsigned>(activity.get_average()/4096);
+               imm.vertex(14, 0);
+               imm.vertex(14+x, 0);
+               imm.vertex(14+x, 10);
+               imm.vertex(14, 10);
+               imm.end();
+       }
        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::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
+               netvis.get_font().draw_string(name, imm);
+       }
        GL::Texture::unbind();
 }