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