Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef _EDITTOOLGADGETS_H_
Toshihiro Shimizu 890ddd
#define _EDITTOOLGADGETS_H_
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzCore includes
Toshihiro Shimizu 890ddd
#include "tgeometry.h"
Toshihiro Shimizu 890ddd
#include "tgl.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzBase includes
Toshihiro Shimizu 890ddd
#include "tparamchange.h"
Toshihiro Shimizu 890ddd
#include "tdoubleparam.h"
Toshihiro Shimizu 890ddd
#include "tparamset.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// Qt includes
Toshihiro Shimizu 890ddd
#include <qobject></qobject>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//    Forward declarations
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class TMouseEvent;
Toshihiro Shimizu 890ddd
class TFxHandle;
Toshihiro Shimizu 890ddd
class TTool;
Toshihiro Shimizu 890ddd
class FxParamsGraphicEditor;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class FxGadgetController;
Toshihiro Shimizu 890ddd
class TUndo;
Toshihiro Shimizu 890ddd
class TParamUIConcept;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class FxGadget : public TParamObserver
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	GLuint m_id;
Toshihiro Shimizu 890ddd
	bool m_selected;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	std::vector<tdoubleparamp> m_params;</tdoubleparamp>
Toshihiro Shimizu 890ddd
	double m_pixelSize;
Toshihiro Shimizu 890ddd
	std::string m_label;
Toshihiro Shimizu 890ddd
	TUndo *m_undo;
Toshihiro Shimizu 890ddd
	double m_scaleFactor;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	FxGadgetController *m_controller;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	static GLdouble m_selectedColor[3]; //rgb
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	FxGadget(FxGadgetController *controller);
Toshihiro Shimizu 890ddd
	virtual ~FxGadget();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setLabel(std::string label) { m_label = label; }
Toshihiro Shimizu 890ddd
	std::string getLabel() const { return m_label; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	FxGadgetController *getController() const { return m_controller; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void addParam(const TDoubleParamP ¶m);
Toshihiro Shimizu 890ddd
	double getValue(const TDoubleParamP ¶m) const;
Toshihiro Shimizu 890ddd
	void setValue(const TDoubleParamP ¶m, double value);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPointD getValue(const TPointParamP ¶m) const;
Toshihiro Shimizu 890ddd
	void setValue(const TPointParamP ¶m, const TPointD &pos);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setId(GLuint id) { m_id = id; }
Toshihiro Shimizu 890ddd
	GLuint getId() const { return m_id; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void select(bool selected) { m_selected = selected; }
Toshihiro Shimizu 890ddd
	bool isSelected() const { return m_selected; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setPixelSize(); // uses tglGetPixelSize2()
Toshihiro Shimizu 890ddd
	void setPixelSize(double pixelSize) { m_pixelSize = pixelSize; }
Toshihiro Shimizu 890ddd
	inline double getPixelSize() const { return m_pixelSize; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void drawDot(const TPointD &pos);
Toshihiro Shimizu 890ddd
	void drawDot(double x, double y) { drawDot(TPointD(x, y)); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void drawTooltip(const TPointD &tooltipPos, std::string tooltipPosText);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void draw(bool picking) = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void leftButtonDown(const TPointD &pos, const TMouseEvent &) {}
Toshihiro Shimizu 890ddd
	virtual void leftButtonDrag(const TPointD &pos, const TMouseEvent &) {}
Toshihiro Shimizu 890ddd
	virtual void leftButtonUp(const TPointD &pos, const TMouseEvent &) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void onChange(const TParamChange &);
Toshihiro Shimizu 890ddd
	void createUndo();
Toshihiro Shimizu 890ddd
	void commitUndo();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void setScaleFactor(double s) { m_scaleFactor = s; }
Toshihiro Shimizu 890ddd
	double getScaleFactor() const { return m_scaleFactor; }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
namespace EditToolGadgets
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// DragTool
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class DragTool
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	virtual void leftButtonDown(const TPointD &pos, const TMouseEvent &) = 0;
Toshihiro Shimizu 890ddd
	virtual void leftButtonDrag(const TPointD &pos, const TMouseEvent &) = 0;
Toshihiro Shimizu 890ddd
	virtual void leftButtonUp(const TPointD &pos, const TMouseEvent &) = 0;
Toshihiro Shimizu 890ddd
	virtual ~DragTool() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	virtual void enableGlobalKeyframes(bool enabled) {}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
} // EditToolGadgets namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class FxGadgetController : public QObject
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	Q_OBJECT
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TTool *m_tool;
Toshihiro Shimizu 890ddd
	TFxHandle *m_fxHandle;
Toshihiro Shimizu 890ddd
	std::vector<fxgadget *=""> m_gadgets;</fxgadget>
Toshihiro Shimizu 890ddd
	unsigned long m_idBase, m_nextId;
Toshihiro Shimizu 890ddd
	std::map<gluint, *="" fxgadget=""> m_idTable;</gluint,>
Toshihiro Shimizu 890ddd
	FxGadget *m_selectedGadget;
Toshihiro Shimizu 890ddd
	bool m_editingNonZeraryFx;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	FxGadgetController(TTool *tool);
Toshihiro Shimizu 890ddd
	~FxGadgetController();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void clearGadgets();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TAffine getMatrix();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void draw(bool picking = false);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void selectById(unsigned int id);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	EditToolGadgets::DragTool *createDragTool(int gadgetId);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void assignId(FxGadget *gadget);
Toshihiro Shimizu 890ddd
	void addGadget(FxGadget *gadget);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	int getCurrentFrame() const;
Toshihiro Shimizu 890ddd
	void invalidateViewer();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool isEditingNonZeraryFx() const { return m_editingNonZeraryFx; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool hasGadget() { return m_gadgets.size() != 0; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public slots:
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void onFxSwitched();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
private:
Toshihiro Shimizu 890ddd
	FxGadget *allocateGadget(const TParamUIConcept &uiConcept);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif