2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
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.
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.
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
22 //-----------------------------------------------------------------------------
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
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 ?
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
37 #ifndef _CONTROLPOINTSMANAGER_H_
38 #define _CONTROLPOINTSMANAGER_H_
40 class CControlPointsManager
44 OpenGLBinding *m_pQglTable;
47 CControlPointsManager() { m_pQglTable = NULL; m_p2DView = NULL; }
48 virtual ~CControlPointsManager() { }
49 void Init( C2DView *p2DView, OpenGLBinding *pQglTable ) { m_pQglTable = pQglTable; m_p2DView = p2DView; }
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;
55 virtual void render() = 0;
56 virtual void Commit() = 0;
60 class CControlPointsManagerBFace : public CControlPointsManager
62 enum EManagerState { Idle, Drag } ManagerState;
68 // transform matrix ( 2DView is Window <-> ST )
70 // texture size for ST <-> XY
72 // used when translating
73 float m_TransOffset[2];
74 // dragged point index
76 // do we have an anchor ?
80 // coordinates of Anchor
83 _QERFaceData *m_pFaceData;
86 // construction / init -------------------------------------------------
87 CControlPointsManagerBFace() { ManagerState = Idle; }
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 -------------------------------------
93 virtual bool OnLButtonDown (int x, int y);
94 virtual bool OnMouseMove (int x, int y);
95 virtual bool OnLButtonUp (int x, int y);
97 virtual void render();
98 virtual void Commit();
102 void UpdateCtrlPts();
103 void ComputeTransOffset(int i);
104 void XYSpaceForSTSpace( float xy[2], const float st[2] );
108 class CControlPointsManagerPatch : public CControlPointsManager
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;
118 // construction / init -------------------------------------------------
119 CControlPointsManagerPatch() { ManagerState = Idle; }
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 -------------------------------------
125 virtual bool OnLButtonDown (int x, int y);
126 virtual bool OnMouseMove (int x, int y);
127 virtual bool OnLButtonUp (int x, int y);
129 virtual void render();
130 virtual void Commit();