Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef TNZ_SCROLLBAR_INCLUDED
Toshihiro Shimizu 890ddd
#define TNZ_SCROLLBAR_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//#include "tw/action.h"
Toshihiro Shimizu 890ddd
//#include "traster.h"
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 TScrollbarGenericAction
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TScrollbarGenericAction() {}
Toshihiro Shimizu 890ddd
	virtual ~TScrollbarGenericAction() {}
Toshihiro Shimizu 890ddd
	virtual void notify(int value) = 0;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <class t=""></class>
Toshihiro Shimizu 890ddd
class TScrollbarAction : public TScrollbarGenericAction
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	typedef void (T::*CommandMethod)(int value);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	T *m_target;
Toshihiro Shimizu 890ddd
	CommandMethod m_method;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TScrollbarAction<t>(T *target, CommandMethod method) : m_target(target), m_method(method){};</t>
Toshihiro Shimizu 890ddd
	void notify(int value) { (m_target->*m_method)(value); };
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DVAPI TScrollbar : public TWidget
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int m_oldPos;
Toshihiro Shimizu 890ddd
	int m_gPos, m_gMinPos, m_gMaxPos, m_gSize;
Toshihiro Shimizu 890ddd
	int m_value, m_minValue, m_maxValue, m_cursorSize;
Toshihiro Shimizu 890ddd
	const int m_buttonAreaSize;
Toshihiro Shimizu 890ddd
	TScrollbarGenericAction *m_action;
Toshihiro Shimizu 890ddd
	bool m_firstButtonPressed, m_secondButtonPressed;
Toshihiro Shimizu 890ddd
	bool m_horizontal;
Toshihiro Shimizu 890ddd
	bool m_minOverflowEnabled;
Toshihiro Shimizu 890ddd
	bool m_maxOverflowEnabled;
Toshihiro Shimizu 890ddd
	int m_buttonIncrement;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	void updatePositions();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void drawHCursor(int x0, int x1);
Toshihiro Shimizu 890ddd
	void drawVCursor(int y0, int y1);
Toshihiro Shimizu 890ddd
	enum ButtonId { FIRST_BUTTON,
Toshihiro Shimizu 890ddd
					SECOND_BUTTON };
Toshihiro Shimizu 890ddd
	void drawButton(ButtonId id);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	TScrollbar(TWidget *parent, string name = "scrollbar");
Toshihiro Shimizu 890ddd
	~TScrollbar();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void repaint();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void leftButtonDown(const TMouseEvent &);
Toshihiro Shimizu 890ddd
	void leftButtonDrag(const TMouseEvent &);
Toshihiro Shimizu 890ddd
	void leftButtonUp(const TMouseEvent &);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void configureNotify(const TDimension &d);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setValue(int value, int min, int max, int size);
Toshihiro Shimizu 890ddd
	int getValue() const { return m_value; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// min <= value <= max
Toshihiro Shimizu 890ddd
	// il cursore occupa almeno size/(max-min+size) dell'area disponibile
Toshihiro Shimizu 890ddd
	// se size = 0 non c'e' cursore e lo slider e' disabilitato
Toshihiro Shimizu 890ddd
	// se size>=max-min il cursore occupa tutto lo spazio e lo slider e' disabilitato
Toshihiro Shimizu 890ddd
	//
Toshihiro Shimizu 890ddd
	// value == min quando il cursore e' in alto
Toshihiro Shimizu 890ddd
	// value == max quando il cursore e' in basso
Toshihiro Shimizu 890ddd
	//
Toshihiro Shimizu 890ddd
	// quando vengono premuti i bottoni value viene incrementato/decrementato di uno
Toshihiro Shimizu 890ddd
	//
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// abilita/disabilita la possibilita' di agire sui bottoni anche
Toshihiro Shimizu 890ddd
	// quando lo slider e' gia' sul massimo/minimo
Toshihiro Shimizu 890ddd
	// default: false/false
Toshihiro Shimizu 890ddd
	void enableButtonOverflow(bool min, bool max);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// default: 4
Toshihiro Shimizu 890ddd
	void setButtonIncrement(int d);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setAction(TScrollbarGenericAction *action);
Toshihiro Shimizu 890ddd
	void onTimer(int v);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif