]> git.xonotic.org Git - xonotic/netradiant.git/blob - plugins/textool/ControlPointsManager.h
reformat code! now the code is only ugly on the *inside*
[xonotic/netradiant.git] / plugins / textool / ControlPointsManager.h
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 protected:
42 // used by Render
43     OpenGLBinding *m_pQglTable;
44     C2DView *m_p2DView;
45 public:
46     CControlPointsManager()
47     {
48         m_pQglTable = NULL;
49         m_p2DView = NULL;
50     }
51
52     virtual ~CControlPointsManager()
53     {}
54
55     void Init(C2DView *p2DView, OpenGLBinding *pQglTable)
56     {
57         m_pQglTable = pQglTable;
58         m_p2DView = p2DView;
59     }
60
61     virtual bool OnLButtonDown(int x, int y) = 0;
62
63     virtual bool OnMouseMove(int x, int y) = 0;
64
65     virtual bool OnLButtonUp(int x, int y) = 0;
66
67     virtual void render() = 0;
68
69     virtual void Commit() = 0;
70 };
71
72 // brush face manager
73 class CControlPointsManagerBFace : public CControlPointsManager {
74     enum EManagerState { Idle, Drag } ManagerState;
75     int m_NumPoints;
76 // initial geometry
77     CtrlPts_t m_RefPts;
78 // current geometry
79     CtrlPts_t *m_pPts;
80 // transform matrix ( 2DView is Window <-> ST )
81     float m_TM[2][3];
82 // texture size for ST <-> XY
83     int m_TexSize[2];
84 // used when translating
85     float m_TransOffset[2];
86 // dragged point index
87     int m_iDragPoint;
88 // do we have an anchor ?
89     bool m_bGotAnchor;
90 // anchor point index
91     int m_iAnchorPoint;
92 // coordinates of Anchor
93     float m_Anchor[2];
94 // used for commit
95     _QERFaceData *m_pFaceData;
96
97 public:
98 // construction / init -------------------------------------------------
99     CControlPointsManagerBFace()
100     { ManagerState = Idle; }
101
102     virtual ~CControlPointsManagerBFace()
103     {}
104
105 // NOTE: pQglTable is sent to CControlPointsManager::Init
106     void
107     Init(int iPts, CtrlPts_t *Pts, C2DView *p2DView, int TexSize[2], _QERFaceData *pFaceData, OpenGLBinding *pQglTable);
108 // CControlPointsManager interface -------------------------------------
109
110     virtual bool OnLButtonDown(int x, int y);
111
112     virtual bool OnMouseMove(int x, int y);
113
114     virtual bool OnLButtonUp(int x, int y);
115
116     virtual void render();
117
118     virtual void Commit();
119
120 private:
121 // internal members
122     void UpdateCtrlPts();
123
124     void ComputeTransOffset(int i);
125
126     void XYSpaceForSTSpace(float xy[2], const float st[2]);
127 };
128
129 // patch manager
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;
136     int m_iDragPoint[2];
137
138 public:
139 // construction / init -------------------------------------------------
140     CControlPointsManagerPatch()
141     { ManagerState = Idle; }
142
143     virtual ~CControlPointsManagerPatch()
144     {}
145
146 // NOTE: pQglTable is sent to CControlPointsManager::Init
147     void Init(patchMesh_t *pWorkPatch, C2DView *p2DView, OpenGLBinding *pQglTable, patchMesh_t *pPatch);
148 // CControlPointsManager interface -------------------------------------
149
150     virtual bool OnLButtonDown(int x, int y);
151
152     virtual bool OnMouseMove(int x, int y);
153
154     virtual bool OnLButtonUp(int x, int y);
155
156     virtual void render();
157
158     virtual void Commit();
159 };
160
161 #endif