From: Markus R. <rol...@us...> - 2006-01-08 14:15:43
|
Update of /cvsroot/simspark/simspark/contrib/rsgedit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21348 Modified Files: mainframe.cpp mainframe.h simspark.cpp simspark.h sparkglcanvas.cpp sparkglcanvas.h Log Message: - rsgedit no longer crashes, when window is closed via it's decoration - added toolbar buttons and menu entries to start and pause the simulation - the simulation is initially paused Index: mainframe.h =================================================================== RCS file: /cvsroot/simspark/simspark/contrib/rsgedit/mainframe.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** mainframe.h 4 Jan 2006 20:31:58 -0000 1.2 --- mainframe.h 8 Jan 2006 14:15:27 -0000 1.3 *************** *** 12,15 **** --- 12,18 ---- // end wxGlade + #define ID_SIM_START (wxID_HIGHEST+1) + #define ID_SIM_PAUSE (wxID_HIGHEST+2) + class mainframe: public wxFrame { public: *************** *** 19,24 **** mainframe(wxWindow* parent, int id, const wxString& title, const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE); - void OnExit(wxCommandEvent& event); - private: // begin wxGlade: mainframe::methods --- 22,25 ---- *************** *** 28,43 **** protected: ! void OnTimer(wxTimerEvent& event); protected: // begin wxGlade: mainframe::attributes wxMenuBar* MainFrame_menubar; SparkGLCanvas* mCanvas; wxPanel* panel_1; - wxStatusBar* MainFrame_statusbar; // end wxGlade protected: wxTimer mTimer; DECLARE_EVENT_TABLE() --- 29,61 ---- protected: ! /** start and run simulation */ ! void StartSimulation(); ! ! /** pause a running simulation */ ! void PauseSimulation(); ! ! void OnUpdateStartSimulation(wxUpdateUIEvent& event); ! void OnStartSimulation(wxCommandEvent& event); ! ! void OnUpdatePauseSimulation(wxUpdateUIEvent& event); ! void OnPauseSimulation(wxCommandEvent& event); ! ! void OnExit(wxCommandEvent& event); ! void OnClose( wxCloseEvent& event ); ! ! /** returns true iff its safe to close this frame now */ ! bool CanClose(); protected: // begin wxGlade: mainframe::attributes wxMenuBar* MainFrame_menubar; + wxStatusBar* MainFrame_statusbar; SparkGLCanvas* mCanvas; wxPanel* panel_1; // end wxGlade protected: wxTimer mTimer; + wxToolBar* mToolBar; DECLARE_EVENT_TABLE() Index: sparkglcanvas.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/contrib/rsgedit/sparkglcanvas.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** sparkglcanvas.cpp 2 Jan 2006 20:28:49 -0000 1.2 --- sparkglcanvas.cpp 8 Jan 2006 14:15:27 -0000 1.3 *************** *** 22,26 **** #include "sparkglcanvas.h" #include "simspark.h" - #include "inputwx.h" //! wxWidgets and zeitgeist both use a 'DECLARE_CLASS' macro --- 22,25 ---- *************** *** 140,150 **** { event.Skip(); ! if (mInputSystem.get() == 0) ! { ! return; ! } ! ! wxInput input(event,true); ! mInputSystem->AddInput(input); } --- 139,143 ---- { event.Skip(); ! AddInput(wxInput(event,true)); } *************** *** 152,162 **** { event.Skip(); ! if (mInputSystem.get() == 0) ! { ! return; ! } ! ! wxInput input(event,false); ! mInputSystem->AddInput(input); } --- 145,149 ---- { event.Skip(); ! AddInput(wxInput(event,false)); } *************** *** 164,175 **** { event.Skip(); - if (mInputSystem.get() == 0) - { - return; - } Input input(Input::eButton, Input::IC_MOUSE_LEFT, 1); input.mData.l = 1; ! mInputSystem->AddInput(input); } --- 151,159 ---- { event.Skip(); Input input(Input::eButton, Input::IC_MOUSE_LEFT, 1); input.mData.l = 1; ! ! AddInput(input); } *************** *** 177,188 **** { event.Skip(); - if (mInputSystem.get() == 0) - { - return; - } Input input(Input::eButton, Input::IC_MOUSE_LEFT); input.mData.l = 0; ! mInputSystem->AddInput(input); } --- 161,169 ---- { event.Skip(); Input input(Input::eButton, Input::IC_MOUSE_LEFT); input.mData.l = 0; ! ! AddInput(input); } *************** *** 190,201 **** { event.Skip(); - if (mInputSystem.get() == 0) - { - return; - } - Input input(Input::eButton, Input::IC_MOUSE_MIDDLE); input.mData.l = 1; ! mInputSystem->AddInput(input); } --- 171,178 ---- { event.Skip(); Input input(Input::eButton, Input::IC_MOUSE_MIDDLE); input.mData.l = 1; ! ! AddInput(input); } *************** *** 203,214 **** { event.Skip(); - if (mInputSystem.get() == 0) - { - return; - } Input input(Input::eButton, Input::IC_MOUSE_MIDDLE); input.mData.l = 0; ! mInputSystem->AddInput(input); } --- 180,188 ---- { event.Skip(); Input input(Input::eButton, Input::IC_MOUSE_MIDDLE); input.mData.l = 0; ! ! AddInput(input); } *************** *** 216,227 **** { event.Skip(); - if (mInputSystem.get() == 0) - { - return; - } Input input(Input::eButton, Input::IC_MOUSE_RIGHT); input.mData.l = 1; ! mInputSystem->AddInput(input); } --- 190,198 ---- { event.Skip(); Input input(Input::eButton, Input::IC_MOUSE_RIGHT); input.mData.l = 1; ! ! AddInput(input); } *************** *** 229,240 **** { event.Skip(); - if (mInputSystem.get() == 0) - { - return; - } Input input(Input::eButton, Input::IC_MOUSE_RIGHT, 0); input.mData.l = 0; ! mInputSystem->AddInput(input); } --- 200,208 ---- { event.Skip(); Input input(Input::eButton, Input::IC_MOUSE_RIGHT, 0); input.mData.l = 0; ! ! AddInput(input); } *************** *** 255,267 **** } - if (mInputSystem.get() == 0) - { - return; - } - { Input input(Input::eAxis, Input::IC_AXISX); input.mData.l = (event.GetX() - lastX); ! mInputSystem->AddInput(input); } --- 223,230 ---- } { Input input(Input::eAxis, Input::IC_AXISX); input.mData.l = (event.GetX() - lastX); ! AddInput(input); } *************** *** 269,273 **** Input input(Input::eAxis, Input::IC_AXISY); input.mData.l = (event.GetY() - lastY); ! mInputSystem->AddInput(input); } --- 232,236 ---- Input input(Input::eAxis, Input::IC_AXISY); input.mData.l = (event.GetY() - lastY); ! AddInput(input); } *************** *** 276,277 **** --- 239,258 ---- } + void SparkGLCanvas::AddInput(const kerosin::Input& input) + { + if (mInputSystem.get() == 0) + { + return; + } + + shared_ptr<SimSpark> spark = wxGetApp().GetSpark(); + if ( + (spark.get() == 0) || + (spark->GetSimState() != SimSpark::S_RUNNING) + ) + { + return; + } + + mInputSystem->AddInput(input); + } Index: simspark.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/contrib/rsgedit/simspark.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** simspark.cpp 25 Dec 2005 15:06:28 -0000 1.1 --- simspark.cpp 8 Jan 2006 14:15:27 -0000 1.2 *************** *** 29,32 **** --- 29,33 ---- Spark(relPathPrefix) { + mState = S_PAUSED; } *************** *** 60,61 **** --- 61,72 ---- return true; } + + SimSpark::ESimState SimSpark::GetSimState() const + { + return mState; + } + + void SimSpark::SetSimState(ESimState state) + { + mState = state; + } Index: mainframe.cpp =================================================================== RCS file: /cvsroot/simspark/simspark/contrib/rsgedit/mainframe.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** mainframe.cpp 4 Jan 2006 20:31:58 -0000 1.3 --- mainframe.cpp 8 Jan 2006 14:15:27 -0000 1.4 *************** *** 1,8 **** // -*- C++ -*- generated by wxGlade 0.4 on Wed Jan 4 20:26:10 2006 - #include "mainframe.h" #include "sparkglcanvas.h" #include "main.h" //! wxWidgets and zeitgeist both use a 'DECLARE_CLASS' macro #undef DECLARE_CLASS --- 1,11 ---- + /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ // -*- C++ -*- generated by wxGlade 0.4 on Wed Jan 4 20:26:10 2006 #include "mainframe.h" #include "sparkglcanvas.h" #include "main.h" + #include <rsgedit/res/xpm_play.xpm> + #include <rsgedit/res/xpm_pause.xpm> + //! wxWidgets and zeitgeist both use a 'DECLARE_CLASS' macro #undef DECLARE_CLASS *************** *** 15,19 **** BEGIN_EVENT_TABLE(mainframe, wxFrame) EVT_MENU(wxID_EXIT, mainframe::OnExit) ! EVT_TIMER(1, mainframe::OnTimer) END_EVENT_TABLE() --- 18,28 ---- BEGIN_EVENT_TABLE(mainframe, wxFrame) EVT_MENU(wxID_EXIT, mainframe::OnExit) ! EVT_CLOSE(mainframe::OnClose) ! ! EVT_UPDATE_UI(ID_SIM_START, mainframe::OnUpdateStartSimulation) ! EVT_MENU(ID_SIM_START, mainframe::OnStartSimulation) ! ! EVT_UPDATE_UI(ID_SIM_PAUSE, mainframe::OnUpdatePauseSimulation) ! EVT_MENU(ID_SIM_PAUSE, mainframe::OnPauseSimulation) END_EVENT_TABLE() *************** *** 33,38 **** wxglade_tmp_menu_1->Append(wxID_EXIT, wxT("&Exit"), wxT(""), wxITEM_NORMAL); MainFrame_menubar->Append(wxglade_tmp_menu_1, wxT("&File")); ! mCanvas = new SparkGLCanvas(panel_1, -1); MainFrame_statusbar = CreateStatusBar(1, 0); set_properties(); --- 42,51 ---- wxglade_tmp_menu_1->Append(wxID_EXIT, wxT("&Exit"), wxT(""), wxITEM_NORMAL); MainFrame_menubar->Append(wxglade_tmp_menu_1, wxT("&File")); ! wxMenu* wxglade_tmp_menu_2 = new wxMenu(); ! wxglade_tmp_menu_2->Append(ID_SIM_START, wxT("&Start"), wxT("Start simulation"), wxITEM_NORMAL); ! wxglade_tmp_menu_2->Append(ID_SIM_PAUSE, wxT("&Pause"), wxT("Pause Simulation"), wxITEM_NORMAL); ! MainFrame_menubar->Append(wxglade_tmp_menu_2, wxT("&Simulation")); MainFrame_statusbar = CreateStatusBar(1, 0); + mCanvas = new SparkGLCanvas(panel_1, -1); set_properties(); *************** *** 40,46 **** // end wxGlade ! // this is a one shot timer to kick off the rendering loop in ! // response to an event ! mTimer.Start(1,true); } --- 53,63 ---- // end wxGlade ! mToolBar = new wxToolBar(this,-1); ! SetToolBar(mToolBar); ! ! mToolBar->AddTool(ID_SIM_START, wxT("Start"), wxBitmap(xpm_play)); ! mToolBar->AddTool(ID_SIM_PAUSE, wxT("Pause"), wxBitmap(xpm_pause)); ! ! mToolBar->Realize(); } *************** *** 61,65 **** } - void mainframe::do_layout() { --- 78,81 ---- *************** *** 79,92 **** } void mainframe::OnExit( wxCommandEvent& WXUNUSED(event) ) { ! // true is to force the frame to close ! Close(true); } ! void mainframe::OnTimer(wxTimerEvent& /*event*/) { shared_ptr<SimSpark> spark = wxGetApp().GetSpark(); ! if (spark.get() == 0) { return; --- 95,170 ---- } + bool mainframe::CanClose() + { + shared_ptr<SimSpark> spark = wxGetApp().GetSpark(); + if ( + (spark.get() != 0) && + (spark->GetSimState() == SimSpark::S_RUNNING) + ) + { + return false; + } + + return true; + } + + void mainframe::OnClose( wxCloseEvent& event ) + { + if (! CanClose()) + { + PauseSimulation(); + event.Veto(); + return; + } + + event.Skip(); + Destroy(); + } + void mainframe::OnExit( wxCommandEvent& WXUNUSED(event) ) { ! Close(); } ! void mainframe::OnUpdateStartSimulation(wxUpdateUIEvent& event) { shared_ptr<SimSpark> spark = wxGetApp().GetSpark(); ! bool enable = ( ! (spark.get() != 0) && ! (spark->GetSimState() == SimSpark::S_PAUSED) ! ); ! ! event.Enable(enable); ! } ! ! void mainframe::OnStartSimulation(wxCommandEvent& /*event*/) ! { ! StartSimulation(); ! } ! ! void mainframe::OnUpdatePauseSimulation(wxUpdateUIEvent& event) ! { ! shared_ptr<SimSpark> spark = wxGetApp().GetSpark(); ! bool enable = ( ! (spark.get() != 0) && ! (spark->GetSimState() == SimSpark::S_RUNNING) ! ); ! ! event.Enable(enable); ! } ! ! void mainframe::OnPauseSimulation(wxCommandEvent& /*event*/) ! { ! PauseSimulation(); ! } ! ! void mainframe::PauseSimulation() ! { ! shared_ptr<SimSpark> spark = wxGetApp().GetSpark(); ! ! if ( ! (spark.get() == 0) || ! (spark->GetSimState() != SimSpark::S_RUNNING) ! ) { return; *************** *** 99,102 **** --- 177,202 ---- } + sim->Quit(); + } + + void mainframe::StartSimulation() + { + shared_ptr<SimSpark> spark = wxGetApp().GetSpark(); + if ( + (spark.get() == 0) || + (spark->GetSimState() != SimSpark::S_PAUSED) + ) + { + return; + } + + shared_ptr<SimulationServer> sim = spark->GetSimulationServer(); + if (sim.get() == 0) + { + return; + } + + spark->SetSimState(SimSpark::S_RUNNING); + // tell the inputControl node the loaction of our camera shared_ptr<InputControl> inputCtr = spark->GetInputControl(); *************** *** 130,136 **** sim->Done(); ! Close(true); } --- 230,237 ---- sim->Done(); ! spark->SetSimState(SimSpark::S_PAUSED); } + Index: sparkglcanvas.h =================================================================== RCS file: /cvsroot/simspark/simspark/contrib/rsgedit/sparkglcanvas.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** sparkglcanvas.h 2 Jan 2006 20:28:49 -0000 1.2 --- sparkglcanvas.h 8 Jan 2006 14:15:27 -0000 1.3 *************** *** 23,26 **** --- 23,27 ---- #include <wx/glcanvas.h> #include "sparkglrender.h" + #include "inputwx.h" namespace kerosin *************** *** 62,65 **** --- 63,67 ---- protected: bool Init(); + void AddInput(const kerosin::Input& input); protected: Index: simspark.h =================================================================== RCS file: /cvsroot/simspark/simspark/contrib/rsgedit/simspark.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** simspark.h 25 Dec 2005 15:06:28 -0000 1.1 --- simspark.h 8 Jan 2006 14:15:27 -0000 1.2 *************** *** 7,11 **** This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by ! the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, --- 7,15 ---- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by ! the Free Software Founda shared_ptr<SimulationServer> sim = spark->GetSimulationServer(); ! if (sim.get() == 0) ! { ! return; ! tion; version 2 of the License. This program is distributed in the hope that it will be useful, *************** *** 26,29 **** --- 30,40 ---- { public: + enum ESimState + { + S_PAUSED, + S_RUNNING + }; + + public: SimSpark(const std::string& relPathPrefix); *************** *** 39,42 **** --- 50,63 ---- /** process command line options */ bool ProcessCmdLine(int argc, char* argv[]); + + /** get the current simulation state */ + ESimState GetSimState() const; + + /** set the current simulationm state */ + void SetSimState(ESimState state); + + protected: + //! the state of the current simulation + ESimState mState; }; |