1 /*
2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
4 
5 This file is part of GtkRadiant.
6 
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11 
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21 
22 //-----------------------------------------------------------------------------
23 //
24 // DESCRIPTION:
25 // a class to handle control points in a 2D view
26 // TODO: this one can be placed under an interface, and provided to the editor as service
27 //
28 // NOTE: the C2DView *m_p2DView is the orthogonal mapping between window and ST space
29 // in Drag mode (for rotation) we need an orthonormal XY space
30 // we do ST <-> XY transformations using the texture size
31 // ( for translation-only moves, orthogonal is enough )
32 // FIXME: is there a better way to deal between Window space <-> ST space <-> XY space ?
33 //
34 // NOTE: ControlPointsManagers are a bit different between brush faces and patches
35 // so there's a base virtual class, and we have two versions
36 
37 #ifndef _CONTROLPOINTSMANAGER_H_
38 #define _CONTROLPOINTSMANAGER_H_
39 
40 class CControlPointsManager
41 {
42 protected:
43   // used by Render
44   OpenGLBinding *m_pQglTable;
45   C2DView		*m_p2DView;
46 public:
CControlPointsManager()47   CControlPointsManager() { m_pQglTable = NULL; m_p2DView = NULL; }
~CControlPointsManager()48   virtual ~CControlPointsManager() { }
Init(C2DView * p2DView,OpenGLBinding * pQglTable)49   void Init( C2DView *p2DView, OpenGLBinding *pQglTable ) { m_pQglTable = pQglTable; m_p2DView = p2DView; }
50 
51   virtual bool OnLButtonDown (int x, int y) = 0;
52   virtual bool OnMouseMove (int x, int y) = 0;
53   virtual bool OnLButtonUp (int x, int y) = 0;
54 
55   virtual void render() = 0;
56   virtual void Commit() = 0;
57 };
58 
59 // brush face manager
60 class CControlPointsManagerBFace : public CControlPointsManager
61 {
62   enum		EManagerState { Idle, Drag } ManagerState;
63   int			m_NumPoints;
64   // initial geometry
65   CtrlPts_t	m_RefPts;
66   // current geometry
67   CtrlPts_t	*m_pPts;
68   // transform matrix ( 2DView is Window <-> ST )
69   float		m_TM[2][3];
70   // texture size for ST <-> XY
71   int			m_TexSize[2];
72   // used when translating
73   float		m_TransOffset[2];
74   // dragged point index
75   int			m_iDragPoint;
76   // do we have an anchor ?
77   bool		m_bGotAnchor;
78   // anchor point index
79   int			m_iAnchorPoint;
80   // coordinates of Anchor
81   float		m_Anchor[2];
82   // used for commit
83   _QERFaceData	*m_pFaceData;
84 
85 public:
86   // construction / init -------------------------------------------------
CControlPointsManagerBFace()87   CControlPointsManagerBFace() { ManagerState = Idle; }
~CControlPointsManagerBFace()88   virtual ~CControlPointsManagerBFace() { }
89   // NOTE: pQglTable is sent to CControlPointsManager::Init
90   void Init(int iPts, CtrlPts_t *Pts, C2DView *p2DView, int TexSize[2], _QERFaceData* pFaceData, OpenGLBinding *pQglTable);
91   // CControlPointsManager interface -------------------------------------
92 
93   virtual bool OnLButtonDown (int x, int y);
94   virtual bool OnMouseMove (int x, int y);
95   virtual bool OnLButtonUp (int x, int y);
96 
97   virtual void render();
98   virtual void Commit();
99 
100 private:
101   // internal members
102   void UpdateCtrlPts();
103   void ComputeTransOffset(int i);
104   void XYSpaceForSTSpace( float xy[2], const float st[2] );
105 };
106 
107 // patch manager
108 class CControlPointsManagerPatch : public CControlPointsManager
109 {
110   enum		EManagerState { Idle, Drag } ManagerState;
111   // reference data, used for commits
112   patchMesh_t* m_pPatch;
113   // work patch, holds current data
114   patchMesh_t* m_pWorkPatch;
115   int			m_iDragPoint[2];
116 
117 public:
118   // construction / init -------------------------------------------------
CControlPointsManagerPatch()119   CControlPointsManagerPatch() { ManagerState = Idle; }
~CControlPointsManagerPatch()120   virtual ~CControlPointsManagerPatch() { }
121   // NOTE: pQglTable is sent to CControlPointsManager::Init
122   void Init( patchMesh_t* pWorkPatch, C2DView *p2DView, OpenGLBinding *pQglTable, patchMesh_t* pPatch );
123   // CControlPointsManager interface -------------------------------------
124 
125   virtual bool OnLButtonDown (int x, int y);
126   virtual bool OnMouseMove (int x, int y);
127   virtual bool OnLButtonUp (int x, int y);
128 
129   virtual void render();
130   virtual void Commit();
131 };
132 
133 #endif
134