+++ /dev/null
-#include <msp/core/maputils.h>
-#include "connector.h"
-#include "logic.h"
-
-using namespace std;
-
-namespace Msp {
-namespace GLtk {
-
-Connector::~Connector()
-{
- for(map<string, ConnAction *>::iterator i=actions.begin(); i!=actions.end(); ++i)
- delete i->second;
-}
-
-void Connector::connect(const Logic &logic)
-{
- const list<Logic::WidgetBinding> &logic_binds = logic.get_bindings();
-
- for(list<Logic::WidgetBinding>::const_iterator i=logic_binds.begin(); i!=logic_binds.end(); ++i)
- {
- ConnAction *action = get_item(actions, i->type);
- action->connect(*this, *i->wdg, i->data);
- }
-}
-
-void Connector::add(const string &type, ConnAction *act)
-{
- map<string, ConnAction *>::iterator i = actions.find(type);
- if(i!=actions.end())
- {
- delete i->second;
- i->second = act;
- }
- else
- actions[type] = act;
-}
-
-} // namespace GLtk
-} // namespace Msp
+++ /dev/null
-#ifndef MSP_GLTK_CONNECTOR_H_
-#define MSP_GLTK_CONNECTOR_H_
-
-#include <map>
-#include <string>
-#include <sigc++/functors/mem_fun.h>
-
-namespace Msp {
-namespace GLtk {
-
-class Connector;
-class Logic;
-class Widget;
-
-class ConnAction
-{
-public:
- virtual void connect(Connector &conn, Widget &wdg, const std::string &data) const =0;
- virtual ~ConnAction() { }
-};
-
-template<typename C, typename W>
-class ConnFunc0: public ConnAction
-{
-public:
- typedef void (C::*FuncType)(W &);
-
- ConnFunc0(FuncType f): func(f) { }
- virtual void connect(Connector &conn, Widget &wdg, const std::string &) const
- {
- (dynamic_cast<C &>(conn).*func)(dynamic_cast<W &>(wdg));
- }
-
-private:
- FuncType func;
-};
-
-template<typename C, typename W>
-class ConnFunc1: public ConnAction
-{
-public:
- typedef void (C::*FuncType)(W &, const std::string &);
-
- ConnFunc1(FuncType f): func(f) { }
- virtual void connect(Connector &conn, Widget &wdg, const std::string &data) const
- {
- (dynamic_cast<C &>(conn).*func)(dynamic_cast<W &>(wdg), data);
- }
-
-private:
- FuncType func;
-};
-
-template<typename C, typename W, typename S, typename F>
-class ConnSignal: public ConnAction
-{
-public:
- ConnSignal(S W::*s, F f): signal(s), func(f) { }
- virtual void connect(Connector &conn, Widget &wdg, const std::string &) const
- {
- (dynamic_cast<W &>(wdg).*signal).connect(sigc::mem_fun(&dynamic_cast<C &>(conn).get_object(), func));
- }
-
-private:
- S W::*signal;
- F func;
-};
-
-/**
-Provides an interface for associating the bindings stored in a Logic object
-with actual code. Derive a class from this and use the add functions to
-specify handlers for each binding type.
-
-Bindings are normally handled by member functions of the Connector class. The
-function must take a reference to a widget (of any type) as its first parameter.
-If it takes a second parameter, the binding data is passed in as well.
-
-As a shortcut for simple connections, signals of widgets can be connected
-directly to a handler object. For this to work, the Connector class must be a
-public inner class of the handler class and it must have a get_object() member
-function returning a reference to the handler object.
-
-TODO: lexical_cast the binding data (requires working around references)
-*/
-class Connector
-{
-private:
- std::map<std::string, ConnAction *> actions;
-
-protected:
- Connector() { }
-public:
- virtual ~Connector();
-
- /**
- Processes all bindings in the Logic object and calls appropriate handlers.
- */
- void connect(const Logic &);
-
-protected:
- /**
- Adds a handler function for a binding.
- */
- template<typename C, typename W>
- void add(const std::string &type, void (C::*func)(W &))
- { add(type, new ConnFunc0<C, W>(func)); }
-
- /**
- Adds a handler function for a binding. The binding data is passed in the
- second parameter.
- */
- template<typename C, typename W>
- void add(const std::string &type, void (C::*func)(W &, const std::string &))
- { add(type, new ConnFunc1<C, W>(func)); }
-
- /**
- Adds a signal connector for a binding.
- */
- template<typename W, typename S, typename H, typename F>
- void add(const std::string &type, S W::*signal, F H::*func)
- { add(type, new ConnSignal<typename H::Connector, W, S, F H::*>(signal, func)); }
-
-private:
- void add(const std::string &, ConnAction *);
-};
-
-} // namespace GLtk
-} // namespace Msp
-
-#endif
{
if(nav==NAV_LEFT || nav==NAV_RIGHT || ((nav==NAV_DOWN || nav==NAV_UP) && multiline))
move_edit_position(nav, false);
- else if(nav==NAV_ACCEPT && !signal_enter.empty())
- signal_enter.emit();
else
return false;
sigc::signal<void, unsigned, unsigned> signal_selection_changed;
sigc::signal<void, const std::string &> signal_text_changed;
- // Deprecated
- sigc::signal<void> signal_enter;
-
private:
Text text;
bool multiline;
+++ /dev/null
-// Deprecated, use slider.h instead
-#include "slider.h"
+++ /dev/null
-#include <msp/core/maputils.h>
-#include "logic.h"
-
-using namespace std;
-
-namespace Msp {
-namespace GLtk {
-
-Logic::Loader::Loader(Logic &l, const map<string, Widget *> &w):
- DataFile::ObjectLoader<Logic>(l),
- widgets(w)
-{
- add("bind", &Loader::bind);
-}
-
-void Logic::Loader::bind(const string &wdg, const string &data)
-{
- WidgetBinding act;
- act.wdg = get_item(widgets, wdg);
-
- string::size_type colon = data.find(':');
- act.type = data.substr(0, colon);
- if(colon!=string::npos)
- act.data = data.substr(colon+1);
- obj.bindings.push_back(act);
-}
-
-} // namespace GLtk
-} // namespace Msp
+++ /dev/null
-#ifndef MSP_GLTK_LOGIC_H_
-#define MSP_GLTK_LOGIC_H_
-
-#include <list>
-#include <map>
-#include <string>
-#include <sigc++/slot.h>
-#include <msp/datafile/objectloader.h>
-
-namespace Msp {
-namespace GLtk {
-
-class Widget;
-
-/**
-Stores use interface logic. This is represented as widget bindings. Each
-binding has type and data.
-
-See also class Connector.
-*/
-class Logic
-{
-public:
- class Loader: public DataFile::ObjectLoader<Logic>
- {
- private:
- const std::map<std::string, Widget *> &widgets;
-
- public:
- Loader(Logic &, const std::map<std::string, Widget *> &);
- private:
- void bind(const std::string &, const std::string &);
- };
-
- struct WidgetBinding
- {
- Widget *wdg;
- std::string type;
- std::string data;
- };
-
-private:
- std::list<WidgetBinding> bindings;
-
-public:
- const std::list<WidgetBinding> &get_bindings() const { return bindings; }
-};
-
-} // namespace GLtk
-} // namespace Msp
-
-#endif
+++ /dev/null
-#include "userinterface.h"
-
-namespace Msp {
-namespace GLtk {
-
-UserInterface::UserInterface(Resources &r, Graphics::Window &w):
- root(r, w)
-{ }
-
-
-UserInterface::Loader::Loader(UserInterface &u):
- ui(u)
-{
- add("logic", &Loader::logic);
- add("root", &Loader::root);
-}
-
-void UserInterface::Loader::logic()
-{
- load_sub(ui.logic, ui.widgets);
-}
-
-void UserInterface::Loader::root()
-{
- load_sub(ui.root, ui.widgets);
-}
-
-} // namespace GLtk
-} // namespace Msp
+++ /dev/null
-#ifndef MSP_GLTK_USERINTERFACE_H_
-#define MSP_GLTK_USERINTERFACE_H_
-
-#include <msp/core/maputils.h>
-#include "logic.h"
-#include "root.h"
-
-namespace Msp {
-namespace GLtk {
-
-/**
-Encapsulates a Root widget and Logic associated with it. Allows looking up
-widgets by name.
-*/
-class UserInterface
-{
-public:
- class Loader: public DataFile::Loader
- {
- private:
- UserInterface &ui;
-
- public:
- Loader(UserInterface &);
- private:
- void logic();
- void root();
- };
-
- typedef std::map<std::string, Widget *> WidgetMap;
-
-private:
- WidgetMap widgets;
- Root root;
- Logic logic;
-
-public:
- UserInterface(Resources &, Graphics::Window &);
- Root &get_root() { return root; }
- const Logic &get_logic() const { return logic; }
-
- template<typename W>
- W &get_widget(const std::string &n) const
- {
- return dynamic_cast<W &>(*get_item(widgets, n));
- }
-
- template<typename W>
- void get_widget(const std::string &n, W *&w) const
- {
- w = &get_widget<W>(n);
- }
-};
-
-} // namespace GLtk
-} // namespace Msp
-
-#endif
+++ /dev/null
-// Deprecated, use slider.h instead
-#include "slider.h"
signal_visibility_changed.emit(visible);
}
-void Widget::set_focusable(bool f)
-{
- input_type = (f ? INPUT_TEXT : INPUT_NONE);
-}
-
void Widget::set_focus()
{
if(!parent)
void set_enabled(bool);
bool is_enabled() const { return !(state&DISABLED); }
- // Deprecated
- void set_focusable(bool);
-
protected:
void set_state(State s) { set_state(s, s); }
void clear_state(State s) { set_state(s, NORMAL); }
virtual bool navigate(Navigation) { return false; }
virtual void animate(const Time::TimeDelta &) { }
protected:
- virtual void on_size_change() { on_geometry_change(); }
+ virtual void on_size_change() { }
virtual void on_style_change() { }
virtual void on_reparent() { }
-
- // Deprecated
- virtual void on_geometry_change() { }
};
} // namespace GLtk