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 {
43 OpenGLBinding *m_pQglTable;
46 CControlPointsManager()
52 virtual ~CControlPointsManager()
55 void Init(C2DView *p2DView, OpenGLBinding *pQglTable)
57 m_pQglTable = pQglTable;
61 virtual bool OnLButtonDown(int x, int y) = 0;
63 virtual bool OnMouseMove(int x, int y) = 0;
65 virtual bool OnLButtonUp(int x, int y) = 0;
67 virtual void render() = 0;
69 virtual void Commit() = 0;
73 class CControlPointsManagerBFace : public CControlPointsManager {
74 enum EManagerState { Idle, Drag } ManagerState;
80 // transform matrix ( 2DView is Window <-> ST )
82 // texture size for ST <-> XY
84 // used when translating
85 float m_TransOffset[2];
86 // dragged point index
88 // do we have an anchor ?
92 // coordinates of Anchor
95 _QERFaceData *m_pFaceData;
98 // construction / init -------------------------------------------------
99 CControlPointsManagerBFace()
100 { ManagerState = Idle; }
102 virtual ~CControlPointsManagerBFace()
105 // NOTE: pQglTable is sent to CControlPointsManager::Init
107 Init(int iPts, CtrlPts_t *Pts, C2DView *p2DView, int TexSize[2], _QERFaceData *pFaceData, OpenGLBinding *pQglTable);
108 // CControlPointsManager interface -------------------------------------
110 virtual bool OnLButtonDown(int x, int y);
112 virtual bool OnMouseMove(int x, int y);
114 virtual bool OnLButtonUp(int x, int y);
116 virtual void render();
118 virtual void Commit();
122 void UpdateCtrlPts();
124 void ComputeTransOffset(int i);
126 void XYSpaceForSTSpace(float xy[2], const float st[2]);
130 class CControlPointsManagerPatch : public CControlPointsManager {
131 enum EManagerState { Idle, Drag } ManagerState;
132 // reference data, used for commits
133 patchMesh_t *m_pPatch;
134 // work patch, holds current data
135 patchMesh_t *m_pWorkPatch;
139 // construction / init -------------------------------------------------
140 CControlPointsManagerPatch()
141 { ManagerState = Idle; }
143 virtual ~CControlPointsManagerPatch()
146 // NOTE: pQglTable is sent to CControlPointsManager::Init
147 void Init(patchMesh_t *pWorkPatch, C2DView *p2DView, OpenGLBinding *pQglTable, patchMesh_t *pPatch);
148 // CControlPointsManager interface -------------------------------------
150 virtual bool OnLButtonDown(int x, int y);
152 virtual bool OnMouseMove(int x, int y);
154 virtual bool OnLButtonUp(int x, int y);
156 virtual void render();
158 virtual void Commit();