]> icculus.org git repositories - taylor/freespace2.git/blob - src/fred2/grid.cpp
Initial revision
[taylor/freespace2.git] / src / fred2 / grid.cpp
1 /*
2  * $Logfile: /Freespace2/code/FRED2/Grid.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * Grid dialog box created by Mike.  Probably will never be used again.
8  *
9  * $Log$
10  * Revision 1.1  2002/05/03 03:28:08  root
11  * Initial revision
12  *
13  * 
14  * 2     10/07/98 6:28p Dave
15  * Initial checkin. Renamed all relevant stuff to be Fred2 instead of
16  * Fred. Globalized mission and campaign file extensions. Removed Silent
17  * Threat specific code.
18  * 
19  * 1     10/07/98 3:01p Dave
20  * 
21  * 1     10/07/98 3:00p Dave
22  * 
23  * 5     6/18/97 11:36p Lawrance
24  * move grid rendering code to MissionGrid.cpp
25  * 
26  * 4     2/17/97 5:28p Hoffoss
27  * Checked RCS headers, added them were missing, changing description to
28  * something better, etc where needed.
29  *
30  * $NoKeywords: $
31  */
32
33 #include "stdafx.h"
34 #include "fred.h"
35 #include "grid.h"
36
37 #include "3d.h"
38 #include "object.h"
39 #include "editor.h"
40
41 #ifdef _DEBUG
42 #define new DEBUG_NEW
43 #undef THIS_FILE
44 static char THIS_FILE[] = __FILE__;
45 #endif
46
47 extern int double_fine_gridlines;
48
49 /////////////////////////////////////////////////////////////////////////////
50 // CGrid dialog
51
52 //      Modeless constructor, MK
53 CGrid::CGrid(CView* pView)
54 {
55         m_pGView = pView;
56 }
57
58
59 CGrid::CGrid(CWnd* pParent /*=NULL*/)
60         : CDialog(CGrid::IDD, pParent)
61 {
62         //{{AFX_DATA_INIT(CGrid)
63         m_GridSize = 0;
64         //}}AFX_DATA_INIT
65
66         m_pGView = NULL;
67
68 }
69
70
71 void CGrid::DoDataExchange(CDataExchange* pDX)
72 {
73         CDialog::DoDataExchange(pDX);
74         //{{AFX_DATA_MAP(CGrid)
75         DDX_Text(pDX, IDC_GRID_SIZE, m_GridSize);
76         DDV_MinMaxUInt(pDX, m_GridSize, 2, 20);
77         //}}AFX_DATA_MAP
78 }
79
80
81 BEGIN_MESSAGE_MAP(CGrid, CDialog)
82         //{{AFX_MSG_MAP(CGrid)
83         ON_BN_CLICKED(IDC_GRID_XY_PLANE, OnGridXyPlane)
84         ON_BN_CLICKED(IDC_GRID_XZ_PLANE, OnGridXzPlane)
85         ON_BN_CLICKED(IDC_GRID_YZ_PLANE, OnGridYzPlane)
86         ON_WM_CLOSE()
87         ON_WM_DESTROY()
88         ON_WM_KILLFOCUS()
89         ON_WM_VSCROLL()
90         //}}AFX_MSG_MAP
91 END_MESSAGE_MAP()
92
93 /////////////////////////////////////////////////////////////////////////////
94 // CGrid message handlers
95
96 extern grid *The_grid;
97
98 void GridOrient(vector *forward, vector *right)
99 {
100         vector  center;
101         int             nrows, ncols;
102         float   square_size;
103
104         if (The_grid != NULL){
105                 center = The_grid->center;
106                 nrows = The_grid->nrows;
107                 ncols = The_grid->ncols;
108                 square_size = The_grid->square_size;
109         } else {
110                 vm_vec_make(&center, 0.0f, 0.0f, 0.0f);
111                 nrows = 20;
112                 ncols = 20;
113                 square_size = 2.0f;
114         }
115
116         The_grid = create_grid(The_grid, forward,
117                 right,
118                 &center,
119                 nrows, ncols,
120                 square_size);
121
122         physics_init(&The_grid->physics);
123 }
124
125 void CGrid::OnGridXyPlane() 
126 {
127         vector  forward, right;
128
129         vm_vec_make(&forward, 0.0f, 1.0f, 0.0f);
130         vm_vec_make(&right, 1.0f, 0.0f, 0.0f);
131
132         GridOrient(&forward, &right);
133 }
134
135 void CGrid::OnGridXzPlane() 
136 {
137         vector  forward, right;
138
139         vm_vec_make(&forward, 0.0f, 0.0f, 1.0f);
140         vm_vec_make(&right, 1.0f, 0.0f, 0.0f);
141
142         GridOrient(&forward, &right);
143 }
144
145 void CGrid::OnGridYzPlane() 
146 {
147         vector  forward, right;
148
149         vm_vec_make(&forward, 0.0f, 1.0f, 0.0f);
150         vm_vec_make(&right, 0.0f, 0.0f, 1.0f);
151
152         GridOrient(&forward, &right);   
153 }
154
155 BOOL CGrid::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext) 
156 {
157         return CDialog::Create(IDD, pParentWnd);
158 }
159
160 BOOL CGrid::Create()
161 {
162         return CDialog::Create(CGrid::IDD);
163 }
164
165
166 void CGrid::OnClose() 
167 {
168         DestroyWindow();
169 }
170
171 void CGrid::OnDestroy() 
172 {
173         UpdateData(TRUE);
174
175         CDialog::OnDestroy();
176         
177 }
178
179 void CGrid::OnKillFocus(CWnd* pNewWnd) 
180 {
181         CDialog::OnKillFocus(pNewWnd);
182         
183         DestroyWindow();
184
185 }
186
187 BOOL CGrid::DestroyWindow() 
188 {
189         // TODO: Add your specialized code here and/or call the base class
190
191         UpdateData(TRUE);
192         
193         return CDialog::DestroyWindow();
194 }
195
196 BOOL CGrid::OnInitDialog() 
197 {
198         CDialog::OnInitDialog();
199         
200         CSpinButtonCtrl* pSpin = (CSpinButtonCtrl*) GetDlgItem(IDC_SPIN_GRID_SIZE);
201         pSpin->SetRange(2, 20);
202         if ((m_GridSize < 2) || (m_GridSize > 20))
203                 m_GridSize = The_grid->ncols/5;
204         pSpin->SetPos(m_GridSize);
205         
206         return TRUE;  // return TRUE unless you set the focus to a control
207                       // EXCEPTION: OCX Property Pages should return FALSE
208 }
209
210 void CGrid::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
211 {
212         CString strValue;
213
214         CSpinButtonCtrl* pSpin = (CSpinButtonCtrl*) GetDlgItem(IDC_SPIN_GRID_SIZE);
215         strValue.Format("%i", pSpin->GetPos());
216         pSpin->GetBuddy()->SetWindowText(strValue);
217
218         The_grid->nrows = pSpin->GetPos()*5;
219         The_grid->ncols = The_grid->nrows;
220
221         modify_grid(The_grid);
222
223         CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
224 }