#include "list.h"
#include "panel.h"
#include "part.h"
+#include "toggle.h"
#include "vslider.h"
using namespace std;
pnl(p),
wdg_map(m)
{
- add("button", &Loader::child<Button>);
- add("entry", &Loader::child<Entry>);
- add("hslider", &Loader::child<HSlider>);
+ add("button", &Loader::child<Button>);
+ add("entry", &Loader::child<Entry>);
+ add("hslider", &Loader::child<HSlider>);
add("indicator", &Loader::child<Indicator>);
- add("label", &Loader::child<Label>);
- add("list", &Loader::child<List>);
- add("panel", &Loader::panel);
- add("vslider", &Loader::child<VSlider>);
+ add("label", &Loader::child<Label>);
+ add("list", &Loader::child<List>);
+ add("panel", &Loader::panel);
+ add("toggle", &Loader::child<Toggle>);
+ add("vslider", &Loader::child<VSlider>);
}
template<typename T>
window.signal_button_press.connect(sigc::mem_fun(this, &Root::button_press_event));
window.signal_button_release.connect(sigc::mem_fun(this, &Root::button_release_event));
window.signal_pointer_motion.connect(sigc::mem_fun(this, &Root::pointer_motion_event));
- window.signal_key_press.connect(sigc::mem_fun(this, &Root::key_press));
- window.signal_key_release.connect(sigc::mem_fun(this, &Root::key_release));
+ window.signal_key_press.connect(sigc::mem_fun(this, &Root::key_press_event));
+ window.signal_key_release.connect(sigc::mem_fun(this, &Root::key_release_event));
}
void Root::button_press_event(int x, int y, unsigned btn, unsigned)
{
- translate_coords(x, y);
- button_press(x, y, btn);
+ if(visible)
+ {
+ translate_coords(x, y);
+ button_press(x, y, btn);
+ }
}
void Root::button_release_event(int x, int y, unsigned btn, unsigned)
{
- translate_coords(x, y);
- button_release(x, y, btn);
+ if(visible)
+ {
+ translate_coords(x, y);
+ button_release(x, y, btn);
+ }
}
void Root::pointer_motion_event(int x, int y)
{
- translate_coords(x, y);
- pointer_motion(x, y);
+ if(visible)
+ {
+ translate_coords(x, y);
+ pointer_motion(x, y);
+ }
+}
+
+void Root::key_press_event(unsigned key, unsigned mod, wchar_t ch)
+{
+ if(visible)
+ key_press(key, mod, ch);
+}
+
+void Root::key_release_event(unsigned key, unsigned mod)
+{
+ if(visible)
+ key_release(key, mod);
}
void Root::translate_coords(int &x, int &y)
--- /dev/null
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#include "part.h"
+#include "toggle.h"
+
+namespace Msp {
+namespace GLtk {
+
+Toggle::Toggle(const Resources &r):
+ Widget(r),
+ value(false)
+{
+ update_style();
+}
+
+void Toggle::button_release(int x, int y, unsigned btn)
+{
+ if(btn==1)
+ {
+ if(geom.is_inside_relative(x, y))
+ {
+ value=!value;
+ state=(value ? ACTIVE : HOVER);
+ signal_toggled.emit(value);
+ }
+ else
+ state=NORMAL;
+ }
+}
+
+void Toggle::pointer_enter()
+{
+ if(!value)
+ state=HOVER;
+}
+
+void Toggle::pointer_leave()
+{
+ if(!value)
+ state=NORMAL;
+}
+
+void Toggle::render_special(const Part &part) const
+{
+ if(part.get_name()=="text")
+ render_text(part, text);
+}
+
+
+Toggle::Loader::Loader(Toggle &t):
+ Widget::Loader(t)
+{
+ add("text", &Toggle::text);
+ add("value", &Toggle::value);
+}
+
+Toggle &Toggle::Loader::get_object() const
+{
+ return static_cast<Toggle &>(wdg);
+}
+
+} // namespace GLtk
+} // namespace Msp
--- /dev/null
+/* $Id$
+
+This file is part of libmspgltk
+Copyright © 2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#ifndef MSP_GLTK_TOGGLE_H_
+#define MSP_GLTK_TOGGLE_H_
+
+#include <sigc++/signal.h>
+#include "widget.h"
+
+namespace Msp {
+namespace GLtk {
+
+/**
+Allows toggling a value between two states.
+*/
+class Toggle: public Widget
+{
+public:
+ class Loader: public Widget::Loader
+ {
+ public:
+ Loader(Toggle &);
+ Toggle &get_object() const;
+ };
+
+private:
+ std::string text;
+ bool value;
+
+public:
+ sigc::signal<void, bool> signal_toggled;
+
+ Toggle(const Resources &);
+
+ bool get_value() const { return value; }
+
+ virtual void button_release(int, int, unsigned);
+ virtual void pointer_enter();
+ virtual void pointer_leave();
+private:
+ virtual const char *get_class() const { return "toggle"; }
+ virtual void render_special(const Part &) const;
+};
+
+} // namespace GLtk
+} // namespace Msp
+
+#endif
#include <msp/gl/matrix.h>
#include <msp/gl/transform.h>
+#include <msp/strings/formatter.h>
#include "panel.h"
#include "resources.h"
#include "widget.h"
void Widget::render() const
{
if(!style)
- throw InvalidState("Attempt to render a widget without a style");
+ throw InvalidState(format("Attempt to render a widget without a style (class=\"%s\")", get_class()));
GL::push_matrix();
GL::translate(geom.x, geom.y, 0);