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