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

217 lines
5.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_VALUEFIELD_INCLUDED
#define TNZ_VALUEFIELD_INCLUDED
#include "tw/tw.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 TTextField;
class TNumField;
class TValueFieldActionInterface;
class TValuePairFieldActionInterface;
#ifdef WIN32
#pragma warning(push)
#pragma warning(disable : 4251)
#endif
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI TValueField : public TWidget {
2016-03-19 06:57:51 +13:00
protected:
2016-06-15 18:43:10 +12:00
wstring m_labelText;
int m_labelWidth, m_fieldWidth;
double m_value, m_minValue, m_maxValue;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// serve nel drag
int m_deltaPos;
TPoint m_lastPos;
bool m_draggingArrow;
bool m_draggingSlider;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TRect m_sliderRect;
TRect m_arrowRect;
TNumField *m_textField;
bool m_arrowEnabled, m_sliderEnabled;
vector<TValueFieldActionInterface *> m_actions;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
double posToValue(int x) const;
int valueToPos(double v) const;
int m_precision;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void sendCommand(bool dragging);
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TValueField(TWidget *parent, string name = "floatfield",
bool withField = true);
~TValueField();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void enableSlider(bool on);
void enableArrow(bool on);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void repaint();
void configureNotify(const TDimension &d);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void leftButtonDown(const TMouseEvent &e);
void leftButtonDrag(const TMouseEvent &e);
void leftButtonUp(const TMouseEvent &e);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void addAction(TValueFieldActionInterface *action);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
double getValue() const { return m_value; }
void setValue(double value, bool sendCommand = true);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void onTextFieldChange();
void onTextFieldChange(bool dragging);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void getValueRange(double &min, double &max) const {
min = m_minValue;
max = m_maxValue;
};
void setValueRange(double min, double max);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setLabel(string text);
void setLabelWidth(int lx);
void setFieldWidth(int lx);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setPrecision(int d);
int getPrecision() const { return m_precision; }
2016-03-19 06:57:51 +13:00
};
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI TValueFieldActionInterface {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TValueFieldActionInterface() {}
virtual ~TValueFieldActionInterface() {}
virtual void triggerAction(TValueField *vf, double value, bool dragging) = 0;
2016-03-19 06:57:51 +13:00
};
template <class T>
2016-06-15 18:43:10 +12:00
class TValueFieldAction : public TValueFieldActionInterface {
typedef void (T::*Method)(TValueField *vf, double value, bool dragging);
T *m_target;
Method m_method;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TValueFieldAction(T *target, Method method)
: m_target(target), m_method(method) {}
void triggerAction(TValueField *vf, double value, bool dragging) {
(m_target->*m_method)(vf, value, dragging);
}
2016-03-19 06:57:51 +13:00
};
template <class T>
2016-06-15 18:43:10 +12:00
inline void tconnect(TValueField &src, T *target,
void (T::*method)(TValueField *vf, double value,
bool dragging)) {
src.addAction(new TValueFieldAction<T>(target, method));
2016-03-19 06:57:51 +13:00
}
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI TValuePairField : public TWidget {
2016-03-19 06:57:51 +13:00
protected:
2016-06-15 18:43:10 +12:00
wstring m_labelText;
int m_labelWidth;
double m_value0, m_value1, m_minValue, m_maxValue;
double m_newValue0, m_newValue1;
bool m_first;
// servono nel drag
int m_deltaPos;
int m_flags;
TRect m_sliderRect, m_arrow0Rect, m_arrow1Rect;
TNumField *m_textField0, *m_textField1;
bool m_arrowEnabled, m_sliderEnabled;
vector<TValuePairFieldActionInterface *> m_actions;
double posToValue(int x) const;
int valueToPos(double v) const;
void sendCommand(bool dragging);
void onMMTimer(TUINT64 tick);
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TValuePairField(TWidget *parent, string name = "valuepairfield");
~TValuePairField();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void enableSlider(bool on);
void enableArrow(bool on);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void repaint();
void configureNotify(const TDimension &d);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void leftButtonDown(const TMouseEvent &e);
void leftButtonDrag(const TMouseEvent &e);
void leftButtonUp(const TMouseEvent &e);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void addAction(TValuePairFieldActionInterface *action);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
double getValue0() const { return m_value0; }
double getValue1() const { return m_value1; }
void setValue0(double value, bool dragging = true);
void setValue1(double value, bool dragging = true);
void setValues(double value0, double value1, bool dragging = true);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void getValueRange(double &min, double &max) const {
min = m_minValue;
max = m_maxValue;
};
void setValueRange(double min, double max);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setLabel(string text);
void setLabelWidth(int width);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void onTextFieldChange(bool first);
2016-03-19 06:57:51 +13:00
};
//-------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
class DVAPI TValuePairFieldActionInterface {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TValuePairFieldActionInterface() {}
virtual ~TValuePairFieldActionInterface() {}
virtual void triggerAction(TValuePairField *vf, double value0, double value1,
bool dragging) = 0;
2016-03-19 06:57:51 +13:00
};
template <class T>
2016-06-15 18:43:10 +12:00
class TValuePairFieldAction : public TValuePairFieldActionInterface {
typedef void (T::*Method)(TValuePairField *vf, double value0, double value1,
bool dragging);
T *m_target;
Method m_method;
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
TValuePairFieldAction(T *target, Method method)
: m_target(target), m_method(method) {}
void triggerAction(TValuePairField *vf, double value0, double value1,
bool dragging) {
(m_target->*m_method)(vf, value0, value1, dragging);
}
2016-03-19 06:57:51 +13:00
};
template <class T>
inline void tconnect(TValuePairField &src, T *target,
2016-06-15 18:43:10 +12:00
void (T::*method)(TValuePairField *vf, double value0,
double value1, bool dragging)) {
src.addAction(new TValuePairFieldAction<T>(target, method));
2016-03-19 06:57:51 +13:00
}
#ifdef WIN32
#pragma warning(pop)
#endif
#endif