#include "list.h"
#include "panel.h"
#include "part.h"
+#include "progressbar.h"
#include "row.h"
#include "slider.h"
#include "stack.h"
register_child_type<Label>("label");
register_child_type<List>("list");
register_child_type<Panel>("panel");
+ register_child_type<ProgressBar>("progressbar");
register_child_type<Toggle>("toggle");
register_child_type<VSlider>("vslider");
}
--- /dev/null
+#include <msp/gl/meshbuilder.h>
+#include "graphic.h"
+#include "part.h"
+#include "progressbar.h"
+
+using namespace std;
+
+namespace Msp {
+namespace GLtk {
+
+ProgressBar::ProgressBar():
+ range(1),
+ fraction(0)
+{ }
+
+void ProgressBar::set_range(float r)
+{
+ if(r<=0)
+ throw invalid_argument("ProgressBar::set_range");
+
+ range = r;
+ mark_rebuild();
+}
+
+void ProgressBar::set_value(float v)
+{
+ if(v<0 || v>range)
+ throw invalid_argument("ProgressBar::set_value");
+
+ fraction = v/range;
+ mark_rebuild();
+}
+
+void ProgressBar::autosize_special(const Part &part, Geometry &ageom) const
+{
+ const Geometry &pgeom = part.get_geometry();
+ const Sides &pmargin = part.get_margin();
+ ageom.w = max(ageom.w, pgeom.w+pmargin.left+pmargin.right);
+ ageom.h = max(ageom.h, pgeom.h+pmargin.top+pmargin.bottom);
+}
+
+void ProgressBar::rebuild_special(const Part &part)
+{
+ if(part.get_name()=="bar")
+ {
+ const Graphic *graphic = part.get_graphic(state);
+ if(!graphic || !graphic->get_texture())
+ return;
+
+ Geometry rgeom = part.get_geometry();
+ Alignment align = part.get_alignment();
+ align.w += (1-align.w)*fraction;
+ align.h += (1-align.h)*fraction;
+ align.apply(rgeom, geom, part.get_margin());
+
+ GL::MeshBuilder bld(part_cache.create_mesh(part, *graphic->get_texture()));
+ bld.matrix() *= GL::Matrix::translation(rgeom.x, rgeom.y, 0);
+ graphic->build(rgeom.w, rgeom.h, bld);
+ }
+}
+
+} // namespace GLtk
+} // namespace Msp
--- /dev/null
+#ifndef MSP_GLTK_PROGRESSBAR_H_
+#define MSP_GLTK_PROGRESSBAR_H_
+
+#include "widget.h"
+
+namespace Msp {
+namespace GLtk {
+
+class ProgressBar: public Widget
+{
+private:
+ float range;
+ float fraction;
+
+public:
+ ProgressBar();
+
+ virtual const char *get_class() const { return "progressbar"; }
+
+ void set_range(float);
+ void set_value(float);
+
+private:
+ virtual void autosize_special(const Part &, Geometry &) const;
+ virtual void rebuild_special(const Part &);
+};
+
+} // namespace GLtk
+} // namespace Msp
+
+#endif