tahoma2d/toonz/sources/include/tw/button.h

116 lines
2.6 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef TNZ_BUTTON_INCLUDED
#define TNZ_BUTTON_INCLUDED
#include "tw/tw.h"
#include "tw/action.h"
#include "traster.h"
#undef DVAPI
#undef DVVAR
#ifdef TWIN_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
class TButtonSet;
2016-06-15 18:43:10 +12:00
class DVAPI TButton : public TWidget, public TCommandSource {
2016-03-19 06:57:51 +13:00
protected:
2016-06-15 18:43:10 +12:00
bool m_pressed, m_active;
int m_border;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
vector<TButtonSet *> *m_buttonSets;
friend class TButtonSet;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TButton(TWidget *parent, string name = "button");
~TButton();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void repaint();
void enter(const TPoint &p);
void leave(const TPoint &p);
void leftButtonDown(const TMouseEvent &);
void leftButtonUp(const TMouseEvent &);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
virtual void setTitle(string title) { m_name = title; }
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
class DVAPI TIconButton : public TButton {
TRaster32P m_rasterUp, m_rasterDown;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TIconButton(TWidget *parent, TRaster32P raster, string name = "button");
TIconButton(TWidget *parent, TRaster32P rasterUp, TRaster32P rasterDown,
string name = "button");
void repaint();
void leftButtonDown(const TMouseEvent &);
void leftButtonUp(const TMouseEvent &);
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
class DVAPI TIconToggle : public TButton {
TRaster32P m_up, m_down;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TIconToggle(TWidget *parent, TRaster32P up, TRaster32P down,
string name = "button");
void repaint();
void setStatus(bool v);
bool getStatus();
void leftButtonDown(const TMouseEvent &e);
void leftButtonUp(const TMouseEvent &e);
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
class TButtonSetAction {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TButtonSetAction(){};
virtual ~TButtonSetAction(){};
virtual void sendCommand(string value) = 0;
2016-03-19 06:57:51 +13:00
};
template <class T>
2016-06-15 18:43:10 +12:00
class TButtonSetActionT : public TButtonSetAction {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
typedef void (T::*CommandMethod)(string);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
T *m_target;
CommandMethod m_method;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TButtonSetActionT<T>(T *target, CommandMethod method)
: m_target(target), m_method(method){};
void sendCommand(string value) { (m_target->*m_method)(value); };
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
class DVAPI TButtonSet {
std::map<TButton *, string> *m_buttons;
string m_currentValue;
TButtonSetAction *m_action;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TButtonSet();
~TButtonSet();
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
// not implemented
TButtonSet(const TButtonSet &);
TButtonSet &operator=(const TButtonSet &);
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
void addButton(TButton *button, string value);
void removeButton(TButton *button);
void setValue(string value);
void setValue(TButton *value);
// Note: setValue fires the buttons actions as well as the buttonset action
string getValue() { return m_currentValue; };
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setAction(TButtonSetAction *action);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void enable(bool on);
2016-03-19 06:57:51 +13:00
};
#endif