Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TNZ_VALUEFIELD_INCLUDED
Toshihiro Shimizu 890ddd
#define TNZ_VALUEFIELD_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tw/tw.h"
Toshihiro Shimizu 890ddd
#include "ttimer.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TWIN_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TTextField;
Toshihiro Shimizu 890ddd
class TNumField;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TValueFieldActionInterface;
Toshihiro Shimizu 890ddd
class TValuePairFieldActionInterface;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef WIN32
Toshihiro Shimizu 890ddd
#pragma warning(push)
Toshihiro Shimizu 890ddd
#pragma warning(disable : 4251)
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TValueField : public TWidget
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	wstring m_labelText;
Toshihiro Shimizu 890ddd
	int m_labelWidth, m_fieldWidth;
Toshihiro Shimizu 890ddd
	double m_value, m_minValue, m_maxValue;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// serve nel drag
Toshihiro Shimizu 890ddd
	int m_deltaPos;
Toshihiro Shimizu 890ddd
	TPoint m_lastPos;
Toshihiro Shimizu 890ddd
	bool m_draggingArrow;
Toshihiro Shimizu 890ddd
	bool m_draggingSlider;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRect m_sliderRect;
Toshihiro Shimizu 890ddd
	TRect m_arrowRect;
Toshihiro Shimizu 890ddd
	TNumField *m_textField;
Toshihiro Shimizu 890ddd
	bool m_arrowEnabled, m_sliderEnabled;
Toshihiro Shimizu 890ddd
	vector<tvaluefieldactioninterface *=""> m_actions;</tvaluefieldactioninterface>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double posToValue(int x) const;
Toshihiro Shimizu 890ddd
	int valueToPos(double v) const;
Toshihiro Shimizu 890ddd
	int m_precision;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void sendCommand(bool dragging);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TValueField(TWidget *parent, string name = "floatfield", bool withField = true);
Toshihiro Shimizu 890ddd
	~TValueField();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void enableSlider(bool on);
Toshihiro Shimizu 890ddd
	void enableArrow(bool on);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void repaint();
Toshihiro Shimizu 890ddd
	void configureNotify(const TDimension &d);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDown(const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	void leftButtonDrag(const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	void leftButtonUp(const TMouseEvent &e);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void addAction(TValueFieldActionInterface *action);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double getValue() const { return m_value; }
Toshihiro Shimizu 890ddd
	void setValue(double value, bool sendCommand = true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void onTextFieldChange();
Toshihiro Shimizu 890ddd
	void onTextFieldChange(bool dragging);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void getValueRange(double &min, double &max) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		min = m_minValue;
Toshihiro Shimizu 890ddd
		max = m_maxValue;
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
	void setValueRange(double min, double max);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setLabel(string text);
Toshihiro Shimizu 890ddd
	void setLabelWidth(int lx);
Toshihiro Shimizu 890ddd
	void setFieldWidth(int lx);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setPrecision(int d);
Toshihiro Shimizu 890ddd
	int getPrecision() const { return m_precision; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TValueFieldActionInterface
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TValueFieldActionInterface() {}
Toshihiro Shimizu 890ddd
	virtual ~TValueFieldActionInterface() {}
Toshihiro Shimizu 890ddd
	virtual void triggerAction(TValueField *vf, double value, bool dragging) = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
class TValueFieldAction : public TValueFieldActionInterface
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	typedef void (T::*Method)(TValueField *vf, double value, bool dragging);
Toshihiro Shimizu 890ddd
	T *m_target;
Toshihiro Shimizu 890ddd
	Method m_method;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TValueFieldAction(T *target, Method method) : m_target(target), m_method(method) {}
Toshihiro Shimizu 890ddd
	void triggerAction(TValueField *vf, double value, bool dragging)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		(m_target->*m_method)(vf, value, dragging);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
inline void tconnect(TValueField &src, T *target, void (T::*method)(TValueField *vf, double value, bool dragging))
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	src.addAction(new TValueFieldAction<t>(target, method));</t>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TValuePairField : public TWidget
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	wstring m_labelText;
Toshihiro Shimizu 890ddd
	int m_labelWidth;
Toshihiro Shimizu 890ddd
	double m_value0, m_value1, m_minValue, m_maxValue;
Toshihiro Shimizu 890ddd
	double m_newValue0, m_newValue1;
Toshihiro Shimizu 890ddd
	bool m_first;
Toshihiro Shimizu 890ddd
	// servono nel drag
Toshihiro Shimizu 890ddd
	int m_deltaPos;
Toshihiro Shimizu 890ddd
	int m_flags;
Toshihiro Shimizu 890ddd
	TTimer m_timer;
Toshihiro Shimizu 890ddd
	TRect m_sliderRect, m_arrow0Rect, m_arrow1Rect;
Toshihiro Shimizu 890ddd
	TNumField *m_textField0, *m_textField1;
Toshihiro Shimizu 890ddd
	bool m_arrowEnabled, m_sliderEnabled;
Toshihiro Shimizu 890ddd
	vector<tvaluepairfieldactioninterface *=""> m_actions;</tvaluepairfieldactioninterface>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double posToValue(int x) const;
Toshihiro Shimizu 890ddd
	int valueToPos(double v) const;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void sendCommand(bool dragging);
Toshihiro Shimizu 890ddd
	void onMMTimer(TUINT64 tick);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TValuePairField(TWidget *parent, string name = "valuepairfield");
Toshihiro Shimizu 890ddd
	~TValuePairField();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void enableSlider(bool on);
Toshihiro Shimizu 890ddd
	void enableArrow(bool on);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void repaint();
Toshihiro Shimizu 890ddd
	void configureNotify(const TDimension &d);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDown(const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	void leftButtonDrag(const TMouseEvent &e);
Toshihiro Shimizu 890ddd
	void leftButtonUp(const TMouseEvent &e);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void addAction(TValuePairFieldActionInterface *action);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double getValue0() const { return m_value0; }
Toshihiro Shimizu 890ddd
	double getValue1() const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		return m_value1;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	void setValue0(double value, bool dragging = true);
Toshihiro Shimizu 890ddd
	void setValue1(double value, bool dragging = true);
Toshihiro Shimizu 890ddd
	void setValues(double value0, double value1, bool dragging = true);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void getValueRange(double &min, double &max) const
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		min = m_minValue;
Toshihiro Shimizu 890ddd
		max = m_maxValue;
Toshihiro Shimizu 890ddd
	};
Toshihiro Shimizu 890ddd
	void setValueRange(double min, double max);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setLabel(string text);
Toshihiro Shimizu 890ddd
	void setLabelWidth(int width);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void onTextFieldChange(bool first);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TValuePairFieldActionInterface
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TValuePairFieldActionInterface() {}
Toshihiro Shimizu 890ddd
	virtual ~TValuePairFieldActionInterface() {}
Toshihiro Shimizu 890ddd
	virtual void triggerAction(TValuePairField *vf, double value0, double value1, bool dragging) = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
class TValuePairFieldAction : public TValuePairFieldActionInterface
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	typedef void (T::*Method)(TValuePairField *vf, double value0, double value1, bool dragging);
Toshihiro Shimizu 890ddd
	T *m_target;
Toshihiro Shimizu 890ddd
	Method m_method;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TValuePairFieldAction(T *target, Method method) : m_target(target), m_method(method) {}
Toshihiro Shimizu 890ddd
	void triggerAction(TValuePairField *vf, double value0, double value1, bool dragging)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		(m_target->*m_method)(vf, value0, value1, dragging);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
inline void tconnect(TValuePairField &src, T *target,
Toshihiro Shimizu 890ddd
					 void (T::*method)(TValuePairField *vf, double value0, double value1, bool dragging))
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	src.addAction(new TValuePairFieldAction<t>(target, method));</t>
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef WIN32
Toshihiro Shimizu 890ddd
#pragma warning(pop)
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif