2 #include <msp/gl/meshbuilder.h>
3 #include <msp/gl/renderer.h>
12 Measure::Measure(Designer &d):
15 mesh((GL::COLOR4_UBYTE, GL::VERTEX3))
24 void Measure::button_press(float gx, float gy, unsigned btn)
31 ssnap.position = Vector(gx, gy, 0);
32 ssnap.rotation = Angle::zero();
33 snap_to_tracks(ssnap);
52 void Measure::pointer_motion(float gx, float gy)
58 sn.position = Vector(gx, gy, 0);
60 pointer = sn.position;
64 Vector delta = rotated_vector(pointer-ssnap.position, -ssnap.rotation);
69 adiff = wrap_balanced(sn.rotation-ssnap.rotation+Angle::half_turn());
73 signal_changed.emit();
77 void Measure::render(GL::Renderer &renderer, const GL::Tag &) const
82 GL::Renderer::Push push(renderer);
83 const Vector &pos = (state==ACTIVE ? ssnap.position : pointer);
84 renderer.matrix_stack() *= GL::Matrix::translation(pos);
89 void Measure::update_mesh()
92 GL::MeshBuilder bld(mesh);
93 bld.color(1.0f, 1.0f, 1.0f, 1.0f);
94 bld.begin(GL::QUAD_STRIP);
95 for(unsigned i=0; i<=16; ++i)
97 float x = cos(i*M_PI/8)*0.005;
98 float y = sin(i*M_PI/8)*0.005;
100 bld.vertex(x, y, 0.01);
106 float c = cos(ssnap.rotation);
107 float s = sin(ssnap.rotation);
108 bld.begin(GL::QUAD_STRIP);
110 bld.vertex(0, 0, 0.01);
111 bld.vertex(c*par_dist, s*par_dist, 0);
112 bld.vertex(c*par_dist, s*par_dist, 0.01);
113 bld.vertex(pointer.x-ssnap.position.x, pointer.y-ssnap.position.y, 0);
114 bld.vertex(pointer.x-ssnap.position.x, pointer.y-ssnap.position.y, 0.01);
116 bld.vertex(0, 0, 0.01);
121 void Measure::snap_to_tracks(Snap &sn)
123 const set<Track *> <racks = designer.get_layout().get_tracks();
124 for(set<Track *>::const_iterator i=ltracks.begin(); i!=ltracks.end(); ++i)
125 if((*i)->snap(sn, 0.01, SNAP_NODE))