2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
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
9 // PofView.cpp : Defines the class behaviors for the application.
14 #include "wx/filename.h"
19 #include "systemvars.h"
26 #include "res/pofview_ico.h"
27 #include "res/tool_about.xpm"
28 #include "res/tool_damaged.xpm"
29 #include "res/tool_debris.xpm"
30 #include "res/tool_detail1.xpm"
31 #include "res/tool_detail2.xpm"
32 #include "res/tool_detail3.xpm"
33 #include "res/tool_detail4.xpm"
34 #include "res/tool_detail5.xpm"
35 #include "res/tool_detail6.xpm"
36 #include "res/tool_lights.xpm"
37 #include "res/tool_tree.xpm"
40 int Pofview_running = 1;
42 bool in_dialog = false;
45 class PofViewApp: public wxApp
48 virtual bool OnInit();
52 IMPLEMENT_APP(PofViewApp)
54 bool PofViewApp::OnInit()
56 wxImage::AddHandler(new wxPNGHandler());
57 PofViewFrame *frame = new PofViewFrame(NULL);
64 BEGIN_EVENT_TABLE( PofViewFrame, wxFrame )
65 EVT_MENU( wxID_OPEN, PofViewFrame::OnFileOpen )
66 EVT_MENU( wxID_CLOSE, PofViewFrame::OnFileClose )
67 EVT_MENU( wxID_EXIT, PofViewFrame::OnExit )
68 EVT_MENU( ID_M_VIEW_TOOLBAR, PofViewFrame::OnViewToolbar )
69 EVT_MENU( ID_M_VIEW_STATUSBAR, PofViewFrame::OnViewStatusBar )
70 EVT_MENU( wxID_ABOUT, PofViewFrame::OnHelpAbout )
71 EVT_TOOL( ID_M_TOOLABOUT, PofViewFrame::OnHelpAbout )
72 EVT_TOOL_RANGE( ID_M_TOOLDEBRIS, ID_M_TOOLDETAIL6, PofViewFrame::OnSetDetail )
73 EVT_TOOL( ID_M_TOOLSHOWTREE, PofViewFrame::OnShowTree )
76 PofViewFrame::PofViewFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style )
77 : wxFrame( parent, id, title, pos, size, style )
83 pofview_initted = false;
85 this->SetSizeHints( wxSize( 640,480 ), wxDefaultSize );
88 icon.CopyFromBitmap( wxBITMAP_PNG_FROM_DATA(pofview_ico) );
89 this->SetIcon( icon );
98 m_statusBar1 = this->CreateStatusBar( 1, wxSTB_DEFAULT_STYLE, wxID_ANY );
100 this->Centre( wxBOTH );
103 PofViewFrame::~PofViewFrame()
110 void PofViewFrame::MakeMenuBar()
112 m_menubar1 = new wxMenuBar( 0 );
115 m_menuFile = new wxMenu();
117 m_menuFile->Append( wxID_OPEN );
118 m_menuFile->Append( wxID_CLOSE );
120 m_menuFile->AppendSeparator();
122 m_menuFile->Append( wxID_EXIT );
124 m_menubar1->Append( m_menuFile, wxT("File") );
127 m_menuView = new wxMenu();
129 m_menuView->AppendCheckItem( ID_M_VIEW_TOOLBAR, "&Toolbar", "Show or hide the toolbar" );
130 m_menuView->AppendCheckItem( ID_M_VIEW_STATUSBAR, "&Status Bar", "Show or hide the status bar" );
132 m_menuView->Check( ID_M_VIEW_TOOLBAR, true );
133 m_menuView->Check( ID_M_VIEW_STATUSBAR, true );
135 m_menuView->AppendSeparator();
137 m_menuView->AppendCheckItem( ID_M_VIEW_OUTLINE, "&Outline", "Toggles outline mode" );
138 m_menuView->AppendCheckItem( ID_M_VIEW_LIGHTING, "&Lighting", "Toggle lighting" );
139 m_menuView->AppendCheckItem( ID_M_VIEW_PIVTOS, "&Pivots/Bounding Boxes", "Toggle pivots and bounding boxes" );
140 m_menuView->AppendCheckItem( ID_M_VIEW_PATHS, "P&aths", "Show all the paths" );
141 m_menuView->AppendCheckItem( ID_M_VIEW_RADIUS, "&Radius", "Show the object's radius." );
142 m_menuView->AppendCheckItem( ID_M_VIEW_THRUSTERS, "T&hrusters", "Toggles thrusters" );
143 m_menuView->AppendCheckItem( ID_M_VIEW_TEXTURING, "Texturing" );
144 m_menuView->AppendCheckItem( ID_M_VIEW_SMOOTHING, "Smoothing" );
145 m_menuView->AppendCheckItem( ID_M_VIEW_SHIELDS, "Shields" );
146 m_menuView->AppendCheckItem( ID_M_VIEW_INVISIBLE, "Invisible Faces" );
147 m_menuView->AppendCheckItem( ID_M_VIEW_BAYPATHS, "Bay Paths" );
148 m_menuView->AppendCheckItem( ID_M_VIEW_AUTOCENTER, "Autocenter" );
150 m_menubar1->Append( m_menuView, wxT("View") );
153 m_menuHelp = new wxMenu();
155 m_menuHelp->Append( wxID_ABOUT, "&About PofView...");
157 m_menubar1->Append( m_menuHelp, wxT("Help") );
160 this->SetMenuBar( m_menubar1 );
163 void PofViewFrame::MakeToolBar()
165 m_toolBar1 = this->CreateToolBar( wxTB_HORIZONTAL, wxID_ANY );
167 m_toolBar1->AddTool( wxID_OPEN, wxEmptyString, wxArtProvider::GetBitmap( wxART_FILE_OPEN, wxART_TOOLBAR ), wxNullBitmap, wxITEM_NORMAL, wxT("Open an existing document"), wxEmptyString, NULL );
169 m_toolBar1->AddSeparator();
171 m_toolBar1->AddTool( ID_M_TOOLABOUT, wxEmptyString, wxBitmap( tool_about_xpm ), wxNullBitmap, wxITEM_NORMAL, wxT("Display program information, version number and copyright"), wxEmptyString, NULL );
173 m_toolBar1->AddSeparator();
175 m_toolBar1->AddTool( ID_M_TOOLDEBRIS, wxEmptyString, wxBitmap( tool_debris_xpm ), wxNullBitmap, wxITEM_CHECK, wxT("Show debris pieces"), wxEmptyString, NULL );
176 m_toolBar1->AddTool( ID_M_TOOLDETAIL1, wxEmptyString, wxBitmap( tool_detail1_xpm ), wxNullBitmap, wxITEM_CHECK, wxT("Set to Detail Level 1"), wxEmptyString, NULL );
177 m_toolBar1->AddTool( ID_M_TOOLDETAIL2, wxEmptyString, wxBitmap( tool_detail2_xpm ), wxNullBitmap, wxITEM_CHECK, wxT("Set to Detail Level 2"), wxEmptyString, NULL );
178 m_toolBar1->AddTool( ID_M_TOOLDETAIL3, wxEmptyString, wxBitmap( tool_detail3_xpm ), wxNullBitmap, wxITEM_CHECK, wxT("Set to Detail Level 3"), wxEmptyString, NULL );
179 m_toolBar1->AddTool( ID_M_TOOLDETAIL4, wxEmptyString, wxBitmap( tool_detail4_xpm ), wxNullBitmap, wxITEM_CHECK, wxT("Set to Detail Level 4"), wxEmptyString, NULL );
180 m_toolBar1->AddTool( ID_M_TOOLDETAIL5, wxEmptyString, wxBitmap( tool_detail5_xpm ), wxNullBitmap, wxITEM_CHECK, wxT("Set to Detail Level 5"), wxEmptyString, NULL );
181 m_toolBar1->AddTool( ID_M_TOOLDETAIL6, wxEmptyString, wxBitmap( tool_detail6_xpm ), wxNullBitmap, wxITEM_CHECK, wxT("Set to Detail Level 6"), wxEmptyString, NULL );
183 m_toolBar1->AddSeparator();
185 m_toolBar1->AddTool( ID_M_TOOLSHOWTREE, wxEmptyString, wxBitmap( tool_tree_xpm ), wxNullBitmap, wxITEM_NORMAL, wxEmptyString, wxEmptyString, NULL );
186 m_toolBar1->AddTool( ID_M_TOOLSHOWDAMAGED, wxEmptyString, wxBitmap( tool_damaged_xpm ), wxNullBitmap, wxITEM_CHECK, wxT("Toggles damaged subobjects on/off"), wxEmptyString, NULL );
188 m_toolBar1->AddSeparator();
190 m_toolBar1->AddTool( ID_M_TOOLTOGGLELIGHTS, wxEmptyString, wxBitmap( tool_lights_xpm ), wxNullBitmap, wxITEM_CHECK, wxT("Toggles lights"), wxEmptyString, NULL );
192 m_toolBar1->Realize();
195 void PofViewFrame::SetToolDefaults()
197 m_toolBar1->EnableTool( ID_M_TOOLDEBRIS, false );
198 m_toolBar1->EnableTool( ID_M_TOOLDETAIL1, false );
199 m_toolBar1->EnableTool( ID_M_TOOLDETAIL2, false );
200 m_toolBar1->EnableTool( ID_M_TOOLDETAIL3, false );
201 m_toolBar1->EnableTool( ID_M_TOOLDETAIL4, false );
202 m_toolBar1->EnableTool( ID_M_TOOLDETAIL5, false );
203 m_toolBar1->EnableTool( ID_M_TOOLDETAIL6, false );
205 m_toolBar1->ToggleTool( ID_M_TOOLDEBRIS, false );
206 m_toolBar1->ToggleTool( ID_M_TOOLDETAIL1, false );
207 m_toolBar1->ToggleTool( ID_M_TOOLDETAIL2, false );
208 m_toolBar1->ToggleTool( ID_M_TOOLDETAIL3, false );
209 m_toolBar1->ToggleTool( ID_M_TOOLDETAIL4, false );
210 m_toolBar1->ToggleTool( ID_M_TOOLDETAIL5, false );
211 m_toolBar1->ToggleTool( ID_M_TOOLDETAIL6, false );
213 m_toolBar1->EnableTool( ID_M_TOOLSHOWTREE, false );
214 m_toolBar1->EnableTool( ID_M_TOOLSHOWDAMAGED, false );
216 m_toolBar1->ToggleTool( ID_M_TOOLSHOWDAMAGED, false );
218 m_toolBar1->EnableTool( ID_M_TOOLTOGGLELIGHTS, false );
220 m_toolBar1->ToggleTool( ID_M_TOOLTOGGLELIGHTS, true );
222 m_menuFile->Enable( wxID_CLOSE, false );
224 m_menuView->Enable( ID_M_VIEW_OUTLINE, false );
225 m_menuView->Enable( ID_M_VIEW_LIGHTING, false );
226 m_menuView->Enable( ID_M_VIEW_PIVTOS, false );
227 m_menuView->Enable( ID_M_VIEW_PATHS, false );
228 m_menuView->Enable( ID_M_VIEW_RADIUS, false );
229 m_menuView->Enable( ID_M_VIEW_THRUSTERS, false );
231 m_menuView->Check( ID_M_VIEW_OUTLINE, false );
232 m_menuView->Check( ID_M_VIEW_LIGHTING, false );
233 m_menuView->Check( ID_M_VIEW_PIVTOS, false );
234 m_menuView->Check( ID_M_VIEW_PATHS, false );
235 m_menuView->Check( ID_M_VIEW_RADIUS, false );
236 m_menuView->Check( ID_M_VIEW_THRUSTERS, false );
238 m_menuView->Enable( ID_M_VIEW_TEXTURING, false );
239 m_menuView->Enable( ID_M_VIEW_SMOOTHING, false );
241 m_menuView->Check( ID_M_VIEW_TEXTURING, true );
242 m_menuView->Check( ID_M_VIEW_SMOOTHING, true );
244 m_menuView->Enable( ID_M_VIEW_SHIELDS, false );
245 m_menuView->Enable( ID_M_VIEW_INVISIBLE, false );
246 m_menuView->Enable( ID_M_VIEW_BAYPATHS, false );
247 m_menuView->Enable( ID_M_VIEW_AUTOCENTER, false );
249 m_menuView->Check( ID_M_VIEW_SHIELDS, false );
250 m_menuView->Check( ID_M_VIEW_INVISIBLE, false );
251 m_menuView->Check( ID_M_VIEW_BAYPATHS, false );
252 m_menuView->Check( ID_M_VIEW_AUTOCENTER, false );
255 void PofViewFrame::SetTools()
257 polymodel *pm = model_get(m_model_num);
259 if (pm->num_debris_objects > 0) {
260 m_toolBar1->EnableTool( ID_M_TOOLDEBRIS, true );
263 switch (pm->n_detail_levels) {
265 m_toolBar1->EnableTool( ID_M_TOOLDETAIL6, true );
267 m_toolBar1->EnableTool( ID_M_TOOLDETAIL5, true );
269 m_toolBar1->EnableTool( ID_M_TOOLDETAIL4, true );
271 m_toolBar1->EnableTool( ID_M_TOOLDETAIL3, true );
273 m_toolBar1->EnableTool( ID_M_TOOLDETAIL2, true );
275 m_toolBar1->EnableTool( ID_M_TOOLDETAIL1, true );
282 if (pm->n_detail_levels >= 1) {
283 m_toolBar1->ToggleTool( ID_M_TOOLDETAIL1, true );
286 m_toolBar1->EnableTool( ID_M_TOOLSHOWTREE, true );
287 m_toolBar1->EnableTool( ID_M_TOOLSHOWDAMAGED, true );
289 m_toolBar1->EnableTool( ID_M_TOOLTOGGLELIGHTS, true );
291 m_menuFile->Enable( wxID_CLOSE, true );
293 m_menuView->Enable( ID_M_VIEW_OUTLINE, true );
294 m_menuView->Enable( ID_M_VIEW_LIGHTING, true );
295 m_menuView->Enable( ID_M_VIEW_PIVTOS, true );
296 m_menuView->Enable( ID_M_VIEW_PATHS, true );
297 m_menuView->Enable( ID_M_VIEW_RADIUS, true );
298 m_menuView->Enable( ID_M_VIEW_THRUSTERS, true );
300 m_menuView->Enable( ID_M_VIEW_TEXTURING, true );
301 m_menuView->Enable( ID_M_VIEW_SMOOTHING, true );
303 m_menuView->Enable( ID_M_VIEW_SHIELDS, true );
304 m_menuView->Enable( ID_M_VIEW_INVISIBLE, true );
305 m_menuView->Enable( ID_M_VIEW_BAYPATHS, true );
306 m_menuView->Enable( ID_M_VIEW_AUTOCENTER, true );
309 void PofViewFrame::PofviewInit()
313 if (pofview_initted) {
325 // palette_load_table( "gamepalette1-01" );
330 m_canvas->GetClientSize(&w, &h);
333 gr_set_viewport(w, h);
336 gr_init_font( "font01.vf" );
340 pofview_initted = true;
343 void PofViewFrame::OnFileOpen( wxCommandEvent& event )
345 wxFileDialog openFileDialog(this, _("Open POF File"), wxEmptyString,
346 wxEmptyString, _("POF Files (*.pof)|*.pof"),
347 wxFD_OPEN|wxFD_FILE_MUST_EXIST);
349 if (openFileDialog.ShowModal() == wxID_OK) {
350 // close existing model and reset, if anything is open already
363 // now setup for new model
364 m_canvas = new PofViewCanvas(this, wxID_ANY, wxDefaultPosition, this->GetClientSize(), wxSUNKEN_BORDER);
368 // reuse the GL context so that we don't have to re-init the graphics
369 // code between model loads
370 if ( !m_glContext ) {
371 m_glContext = new wxGLContext(m_canvas);
374 m_canvas->SetCurrent(*m_glContext);
378 m_model_num = model_load(openFileDialog.GetPath().ToAscii(), 0, NULL);
379 m_current_detail_level = 1;
381 if (m_model_num < 0) {
386 failmsg.Printf("Failed to open: '%s'",openFileDialog.GetPath());
388 wxMessageDialog failDialog(this, failmsg, _("ERROR"), wxOK|wxCENTRE|wxICON_ERROR);
389 failDialog.ShowModal();
391 SetDetailLevel(m_current_detail_level);
394 m_file_name = wxFileName(openFileDialog.GetPath()).GetName();
396 SetTitle( wxString::Format("%s - PofView", m_file_name) );
401 void PofViewFrame::OnFileClose( wxCommandEvent& event )
414 void PofViewFrame::OnExit(wxCommandEvent& WXUNUSED(event) )
422 void PofViewFrame::OnViewToolbar( wxCommandEvent& event )
424 bool show_it = event.IsChecked();
426 m_toolBar1->Show(show_it);
429 void PofViewFrame::OnViewStatusBar( wxCommandEvent& event )
431 bool show_it = event.IsChecked();
433 m_statusBar1->Show(show_it);
436 void PofViewFrame::OnHelpAbout( wxCommandEvent& WXUNUSED(event) )
438 AboutBox about(this);
447 void PofViewFrame::OnSetDetail( wxCommandEvent& event )
449 int detail_lvl = event.GetId() - ID_M_TOOLDEBRIS;
451 polymodel *pm = model_get(m_model_num);
457 if (detail_lvl > pm->n_detail_levels) {
462 m_current_detail_level = detail_lvl;
464 for (int i = ID_M_TOOLDEBRIS; i <= ID_M_TOOLDETAIL6; i++) {
467 if ( i == event.GetId() ) {
471 m_toolBar1->ToggleTool(i, bval);
475 // m_canvas->Render();
478 void PofViewFrame::OnShowTree( wxCommandEvent& WXUNUSED(event) )
480 SubobjectsDialog tree(this);
491 void PofViewFrame::SetDetailLevel(int detail_lvl)
493 if (m_model_num < 0) {
497 if (detail_lvl < 0) {
501 if (detail_lvl == m_current_detail_level) {
505 polymodel *pm = model_get(m_model_num);
507 if (detail_lvl > pm->n_detail_levels) {
511 m_current_detail_level = detail_lvl;
513 for (int i = ID_M_TOOLDEBRIS; i <= ID_M_TOOLDETAIL6; i++) {
516 if ( i == (ID_M_TOOLDEBRIS + m_current_detail_level) ) {
520 m_toolBar1->ToggleTool(i, bval);