#if !defined(AFX_CURVEEDITOR_H__C1749ED7_BBE2_445B_9862_5F21486104CE__INCLUDED_)
#define AFX_CURVEEDITOR_H__C1749ED7_BBE2_445B_9862_5F21486104CE__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// CurveEditor.h : header file
//
#include <Stuff\Stuff.hpp>
#include <gosFX\gosFX.hpp>
#define MAXCURVES 128


class CurveSet;
/////////////////////////////////////////////////////////////////////////////
// CCurveEditor frame

class CCurveEditor : public CWnd
{
//	DECLARE_DYNCREATE(CCurveEditor)
protected:

// Attributes
public:
	CCurveEditor();           // protected constructor used by dynamic creation
	virtual ~CCurveEditor();
// Operations
public:
	void ReDraw() {InvalidateRect(NULL);}
	void ReDrawInternal();
	void DrawTicks(CDC *dc);
	void FixCurve(gosFX::Curve *Curve);
	void UpdateCurveList(HTREEITEM itm=TVI_ROOT);
	void DrawCurve(CDC *dc,gosFX::Curve *curve,bool DrawKeys=false);
	void DrawHandles(CDC *dc,gosFX::Curve *curve);
	void Refresh();
	int GetClosestKey(CPoint &pnt);
	CPen InactivePen,EditablePen,VarPen,SelVertPen,TickPen,BlackPen,HandlePen,ZeroPen;
	CBrush BGBrush;

	gosFX::Curve *Curves[MAXCURVES],*DCurve,*VCurve;
	CurveSet *CurrentCSet;
	
	int NumCurves,SelectedKey;
	float StartY,EndY;
	CPoint OldPoint;

	int CurveToClient(float h,int whgt) 
	{
		return whgt-(int)(((h-StartY)/(EndY-StartY))*whgt);
	}

	float ClientToCurve(int h,int w) 
	{
		return (EndY-StartY)*(1.0f-(float)h/w)+StartY;
	}

	enum EditMode {MOVE,INSERT,ZOOM,PAN,SCALE};

	EditMode CurrentEditMode;
	bool EditVar,EditHan;
	CPoint H1Pos,H2Pos;
	CBitmap BackBuffer;

	void BuildBackBuffer();
	// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CCurveEditor)
	public:
	virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);
	//}}AFX_VIRTUAL

// Implementation
protected:

	// Generated message map functions
	//{{AFX_MSG(CCurveEditor)
	afx_msg void OnClose();
	afx_msg void OnPaint();
	afx_msg void OnEditInsertmode();
	afx_msg void OnEditMovemode();
	afx_msg void OnEditPanmode();
	afx_msg void OnEditScalemode();
	afx_msg void OnEditZoommode();
	afx_msg void OnUpdateEditInsertmode(CCmdUI* pCmdUI);
	afx_msg void OnUpdateEditMovemode(CCmdUI* pCmdUI);
	afx_msg void OnUpdateEditPanmode(CCmdUI* pCmdUI);
	afx_msg void OnUpdateEditScalemode(CCmdUI* pCmdUI);
	afx_msg void OnUpdateEditZoommode(CCmdUI* pCmdUI);
	afx_msg void OnEditEditvaraincecurve();
	afx_msg void OnUpdateEditEditvaraincecurve(CCmdUI* pCmdUI);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnEditDeletevertex();
	afx_msg void OnViewZoomtocurve();
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_CURVEEDITOR_H__C1749ED7_BBE2_445B_9862_5F21486104CE__INCLUDED_)
