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