1 #include <msp/gl/meshbuilder.h>
2 #include <msp/gl/renderer.h>
3 #include <msp/gltk/graphic.h>
4 #include <msp/gltk/part.h>
5 #include "clockwidget.h"
10 ClockWidget::ClockWidget(R2C2::Clock &c):
12 hour_hand((GL::VERTEX2, GL::TEXCOORD2, GL::COLOR4_UBYTE)),
13 minute_hand((GL::VERTEX2, GL::TEXCOORD2, GL::COLOR4_UBYTE))
16 void ClockWidget::rebuild_special(const GLtk::Part &part)
18 if(part.get_name()=="hourhand" || part.get_name()=="minutehand")
20 bool minute = (part.get_name()=="minutehand");
21 GL::Mesh &mesh = (minute ? minute_hand : hour_hand);
23 const GLtk::Graphic *graphic = part.get_graphic(state);
24 const GLtk::Alignment &align = part.get_alignment();
27 GL::MeshBuilder bld(mesh);
28 bld.matrix() *= GL::Matrix::translation(GL::Vector3(graphic->get_width()*-align.x, graphic->get_height()*-align.y, 0));
29 graphic->build(graphic->get_width(), graphic->get_height(), bld);
31 part_cache.insert_special(part);
35 void ClockWidget::render_special(const GLtk::Part &part, GL::Renderer &renderer) const
37 if(part.get_name()=="hourhand" || part.get_name()=="minutehand")
39 bool minute = (part.get_name()=="minutehand");
40 const GL::Mesh &mesh = (minute ? minute_hand : hour_hand);
42 float orientation = clock.get_current_time()/((minute ? 1 : 12)*Time::hour);
43 Geometry::Angle<float> angle = Geometry::Angle<float>::from_turns(orientation);
45 GL::Renderer::Push push(renderer);
46 renderer.matrix_stack() *= GL::Matrix::translation(GL::Vector3(geom.w*0.5f, geom.h*0.5f, 0.0f));
47 renderer.matrix_stack() *= GL::Matrix::rotation(angle, GL::Vector3(0, 0, -1));