3 This file is part of NetVis
4 Copyright @ 2008 Mikko Rasa, Mikkosoft Productions
5 Distributed unter the GPL
8 #include <msp/gl/immediate.h>
9 #include <msp/gl/matrix.h>
10 #include <msp/gl/meshbuilder.h>
11 #include <msp/gl/misc.h>
12 #include <msp/strings/formatter.h>
13 #include <msp/time/units.h>
20 History::History(NetVis &n, unsigned w, unsigned h):
26 mesh((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2))
28 texture.storage(GL::RGBA, height, width, 0);
29 texture.set_min_filter(GL::LINEAR);
30 GL::MeshBuilder bld(mesh);
31 bld.color(1.0f, 1.0f, 1.0f);
38 bld.vertex(width, height);
40 bld.vertex(0, height);
44 void History::activity(unsigned down, unsigned up)
50 void History::tick(const Time::TimeStamp &t)
56 next_push += Time::sec;
58 next_push = t+Time::sec;
61 for(unsigned i=0; i<width; ++i)
63 const Bandwidth &bw = buffer.get(i);
64 m = max(m, max(bw.down, bw.up));
80 void History::render() const
86 unsigned value = scale;
98 GL::translate(width+5, height-10, 0);
99 GL::scale_uniform(10);
100 GL::Immediate imm((GL::COLOR4_UBYTE, GL::TEXCOORD2, GL::VERTEX2));
101 imm.color(1.0f, 1.0f, 1.0f);
102 netvis.get_font().draw_string(format("%d%c", value, suffix), imm);
103 GL::translate(0, (height-12)*-0.05, 0);
104 netvis.get_font().draw_string(format("%g%c", value*0.5, suffix), imm);
105 GL::translate(0, (height-12)*-0.05, 0);
106 netvis.get_font().draw_string(format("0%c", suffix), imm);
107 GL::Texture::unbind();
110 void History::create_texture()
112 vector<unsigned> data(width*height);
113 for(unsigned y=0; y<width; ++y)
115 const Bandwidth &bw = buffer.get(y);
116 unsigned down = bw.down*height/scale;
117 unsigned up = bw.up*height/scale;
118 unsigned up_min = up;
119 unsigned up_max = up;
122 unsigned value = (up+buffer.get(y-1).up*height/scale)/2;
123 up_min = min(value+1, up_min);
124 up_max = max(value, up_max);
128 unsigned value = (up+buffer.get(y+1).up*height/scale)/2;
129 up_min = min(value+1, up_min);
130 up_max = max(value, up_max);
132 unsigned *row = &data[y*100];
133 for(unsigned x=0; x<100; ++x)
135 if(x>=up_min && x<=up_max)
139 else if(x%25==24 || y%60==0)
145 texture.image(0, GL::RGBA, GL::UNSIGNED_BYTE, data.data());
149 History::Bandwidth::Bandwidth():