]> git.tdb.fi Git - r2c2.git/commitdiff
Better graphics for the clock
authorMikko Rasa <tdb@tdb.fi>
Sat, 4 Apr 2015 13:52:05 +0000 (16:52 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 4 Apr 2015 13:52:05 +0000 (16:52 +0300)
data/clock.png [new file with mode: 0644]
data/r2c2.res
gui.blend
source/engineer/clockwidget.cpp
source/engineer/clockwidget.h

diff --git a/data/clock.png b/data/clock.png
new file mode 100644 (file)
index 0000000..009bda4
Binary files /dev/null and b/data/clock.png differ
index fb673210f2a49ec69e23ef93ce876c7198ded5fd..9a00dd6c253f6e08182e438418bde92d1b623d87 100644 (file)
@@ -752,8 +752,42 @@ style "toggle-lever"
        };
 };
 
+graphic "clock_face"
+{
+       texture "clock.png";
+       slice 0 0 200 200;
+};
+
+graphic "clock_hour"
+{
+       texture "clock.png";
+       slice 202 0 10 63;
+};
+
+graphic "clock_minute"
+{
+       texture "clock.png";
+       slice 204 65 6 99;
+};
+
 style "clock"
 {
-       part "hourhand";
-       part "minutehand";
+       part
+       {
+               graphic NORMAL "clock_face";
+               align 0.5 0.5;
+               fill 0.0 0.0;
+       };
+
+       part "hourhand"
+       {
+               graphic NORMAL "clock_hour";
+               align 0.5 0.159;
+       };
+
+       part "minutehand"
+       {
+               graphic NORMAL "clock_minute";
+               align 0.5 0.101;
+       };
 };
index 0755f2ec4f40c489ae650de8868c66e047b78e2c..b6efd69dfb0f440452956b0093b5c91279176fc9 100644 (file)
Binary files a/gui.blend and b/gui.blend differ
index 31f5c3988a33a41954579d536fa651b2e65cbef6..5e00591e6bbc88b8d56b823622c8bcd1d70b85e4 100644 (file)
@@ -1,5 +1,6 @@
 #include <msp/gl/meshbuilder.h>
 #include <msp/gl/renderer.h>
+#include <msp/gltk/graphic.h>
 #include <msp/gltk/part.h>
 #include "clockwidget.h"
 
@@ -8,32 +9,24 @@ using namespace Msp;
 
 ClockWidget::ClockWidget(R2C2::Clock &c):
        clock(c),
-       hour_hand((GL::VERTEX2, GL::COLOR4_UBYTE)),
-       minute_hand((GL::VERTEX2, GL::COLOR4_UBYTE))
+       hour_hand((GL::VERTEX2, GL::TEXCOORD2, GL::COLOR4_UBYTE)),
+       minute_hand((GL::VERTEX2, GL::TEXCOORD2, GL::COLOR4_UBYTE))
 { }
 
-void ClockWidget::autosize_special(const GLtk::Part &, GLtk::Geometry &ageom) const
-{
-       ageom.w = max(ageom.w, 200U);
-       ageom.h = max(ageom.h, 200U);
-}
-
 void ClockWidget::rebuild_special(const GLtk::Part &part)
 {
        if(part.get_name()=="hourhand" || part.get_name()=="minutehand")
        {
                bool minute = (part.get_name()=="minutehand");
                GL::Mesh &mesh = (minute ? minute_hand : hour_hand);
-               float length = min(geom.w, geom.h)*(minute ? 0.5f : 0.35f);
-               float width = length*(minute ? 0.05f : 0.1f);
+
+               const GLtk::Graphic *graphic = part.get_graphic(state);
+               const GLtk::Alignment &align = part.get_alignment();
+
                mesh.clear();
                GL::MeshBuilder bld(mesh);
-               bld.color(0.0f, 0.0f, 0.0f);
-               bld.begin(GL::TRIANGLES);
-               bld.vertex(width, -width);
-               bld.vertex(0.0f, length);
-               bld.vertex(-width, -width);
-               bld.end();
+               bld.matrix() *= GL::Matrix::translation(GL::Vector3(graphic->get_width()*-align.x, graphic->get_height()*-align.y, 0));
+               graphic->build(graphic->get_width(), graphic->get_height(), bld);
 
                part_cache.insert_special(part);
        }
@@ -50,7 +43,6 @@ void ClockWidget::render_special(const GLtk::Part &part, GL::Renderer &renderer)
                Geometry::Angle<float> angle = Geometry::Angle<float>::from_turns(orientation);
 
                GL::Renderer::Push push(renderer);
-               renderer.set_texture(0);
                renderer.matrix_stack() *= GL::Matrix::translation(GL::Vector3(geom.w*0.5f, geom.h*0.5f, 0.0f));
                renderer.matrix_stack() *= GL::Matrix::rotation(angle, GL::Vector3(0, 0, -1));
                mesh.draw(renderer);
index 10c62bc9237a7df89e8977c8dfdefaba2245b8d5..e822b89cf56452b2b3fe1614e3bf9ced2343c711 100644 (file)
@@ -17,7 +17,6 @@ public:
        virtual const char *get_class() const { return "clock"; }
 
 private:
-       virtual void autosize_special(const Msp::GLtk::Part &, Msp::GLtk::Geometry &) const;
        virtual void rebuild_special(const Msp::GLtk::Part &);
        virtual void render_special(const Msp::GLtk::Part &, Msp::GL::Renderer &) const;
 };