1 #include <msp/gl/meshbuilder.h>
2 #include <msp/gl/renderer.h>
3 #include <msp/gltk/part.h>
4 #include "clockwidget.h"
9 ClockWidget::ClockWidget(R2C2::Clock &c):
11 hour_hand((GL::VERTEX2, GL::COLOR4_UBYTE)),
12 minute_hand((GL::VERTEX2, GL::COLOR4_UBYTE))
15 void ClockWidget::autosize_special(const GLtk::Part &, GLtk::Geometry &ageom) const
17 ageom.w = max(ageom.w, 200U);
18 ageom.h = max(ageom.h, 200U);
21 void ClockWidget::rebuild_special(const GLtk::Part &part)
23 if(part.get_name()=="hourhand" || part.get_name()=="minutehand")
25 bool minute = (part.get_name()=="minutehand");
26 GL::Mesh &mesh = (minute ? minute_hand : hour_hand);
27 float length = min(geom.w, geom.h)*(minute ? 0.5f : 0.35f);
28 float width = length*(minute ? 0.05f : 0.1f);
30 GL::MeshBuilder bld(mesh);
31 bld.color(0.0f, 0.0f, 0.0f);
32 bld.begin(GL::TRIANGLES);
33 bld.vertex(width, -width);
34 bld.vertex(0.0f, length);
35 bld.vertex(-width, -width);
38 part_cache.insert_special(part);
42 void ClockWidget::render_special(const GLtk::Part &part, GL::Renderer &renderer) const
44 if(part.get_name()=="hourhand" || part.get_name()=="minutehand")
46 bool minute = (part.get_name()=="minutehand");
47 const GL::Mesh &mesh = (minute ? minute_hand : hour_hand);
49 float orientation = clock.get_current_time()/((minute ? 1 : 12)*Time::hour);
50 Geometry::Angle<float> angle = Geometry::Angle<float>::from_turns(orientation);
52 GL::Renderer::Push push(renderer);
53 renderer.set_texture(0);
54 renderer.matrix_stack() *= GL::Matrix::translation(GL::Vector3(geom.w*0.5f, geom.h*0.5f, 0.0f));
55 renderer.matrix_stack() *= GL::Matrix::rotation(angle, GL::Vector3(0, 0, -1));