- some basic error catching to avoid application crash when errors occur

This commit is contained in:
Mark Vejvoda 2011-01-20 19:47:33 +00:00
parent 685c338f97
commit d32a52a072

View File

@ -225,183 +225,241 @@ void MainWindow::onClose(wxCloseEvent &event){
// for the mousewheel // for the mousewheel
void MainWindow::onMouseWheelDown(wxMouseEvent &event) { void MainWindow::onMouseWheelDown(wxMouseEvent &event) {
wxPaintEvent paintEvent; try {
zoom*= 1.1f; wxPaintEvent paintEvent;
zoom= clamp(zoom, 0.1f, 10.0f); zoom*= 1.1f;
onPaint(paintEvent); zoom= clamp(zoom, 0.1f, 10.0f);
onPaint(paintEvent);
}
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
} }
void MainWindow::onMouseWheelUp(wxMouseEvent &event) { void MainWindow::onMouseWheelUp(wxMouseEvent &event) {
wxPaintEvent paintEvent; try {
zoom*= 0.90909f; wxPaintEvent paintEvent;
zoom= clamp(zoom, 0.1f, 10.0f); zoom*= 0.90909f;
onPaint(paintEvent); zoom= clamp(zoom, 0.1f, 10.0f);
onPaint(paintEvent);
}
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
} }
void MainWindow::onMouseMove(wxMouseEvent &event){ void MainWindow::onMouseMove(wxMouseEvent &event){
int x= event.GetX(); try {
int y= event.GetY(); int x= event.GetX();
wxPaintEvent paintEvent; int y= event.GetY();
wxPaintEvent paintEvent;
if(event.LeftIsDown()){ if(event.LeftIsDown()){
rotX+= clamp(lastX-x, -10, 10); rotX+= clamp(lastX-x, -10, 10);
rotY+= clamp(lastY-y, -10, 10); rotY+= clamp(lastY-y, -10, 10);
onPaint(paintEvent); onPaint(paintEvent);
} }
else if(event.RightIsDown()){ else if(event.RightIsDown()){
zoom*= 1.0f+(lastX-x+lastY-y)/100.0f; zoom*= 1.0f+(lastX-x+lastY-y)/100.0f;
zoom= clamp(zoom, 0.1f, 10.0f); zoom= clamp(zoom, 0.1f, 10.0f);
onPaint(paintEvent); onPaint(paintEvent);
} }
lastX= x; lastX= x;
lastY= y; lastY= y;
}
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
} }
void MainWindow::OnChangeColor(wxCommandEvent &event) { void MainWindow::OnChangeColor(wxCommandEvent &event) {
//wxColour color = colorPicker->GetColour(); try {
wxColourData data; //wxColour color = colorPicker->GetColour();
data.SetChooseFull(true); wxColourData data;
for (int i = 0; i < 16; i++) data.SetChooseFull(true);
{ for (int i = 0; i < 16; i++)
wxColour colour(i*16, i*16, i*16); {
data.SetCustomColour(i, colour); wxColour colour(i*16, i*16, i*16);
data.SetCustomColour(i, colour);
}
wxColourDialog dialog(this, &data);
if (dialog.ShowModal() == wxID_OK)
{
wxColourData retData = dialog.GetColourData();
wxColour col = retData.GetColour();
renderer->setBackgroundColor(col.Red()/255.0f, col.Green()/255.0f, col.Blue()/255.0f, col.Alpha()/255.0f);
//wxBrush brush(col, wxSOLID);
//myWindow->SetBackground(brush);
//myWindow->Clear();
//myWindow->Refresh();
}
} }
catch(std::runtime_error e) {
wxColourDialog dialog(this, &data); std::cout << e.what() << std::endl;
if (dialog.ShowModal() == wxID_OK) wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
{
wxColourData retData = dialog.GetColourData();
wxColour col = retData.GetColour();
renderer->setBackgroundColor(col.Red()/255.0f, col.Green()/255.0f, col.Blue()/255.0f, col.Alpha()/255.0f);
//wxBrush brush(col, wxSOLID);
//myWindow->SetBackground(brush);
//myWindow->Clear();
//myWindow->Refresh();
} }
} }
void MainWindow::onMenuFileLoad(wxCommandEvent &event){ void MainWindow::onMenuFileLoad(wxCommandEvent &event){
string fileName; try {
string fileName;
fileDialog->SetWildcard(wxT("G3D files (*.g3d)|*.g3d"));
fileDialog->SetMessage(wxT("Selecting Glest Model for current view."));
fileDialog->SetWildcard(wxT("G3D files (*.g3d)|*.g3d")); if(fileDialog->ShowModal()==wxID_OK){
modelPathList.clear();
fileDialog->SetMessage(wxT("Selecting Glest Model for current view.")); loadModel((const char*)wxFNCONV(fileDialog->GetPath().c_str()));
}
if(fileDialog->ShowModal()==wxID_OK){ isControlKeyPressed = false;
modelPathList.clear(); }
loadModel((const char*)wxFNCONV(fileDialog->GetPath().c_str())); catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
} }
isControlKeyPressed = false;
} }
void MainWindow::onMenuFileLoadParticleXML(wxCommandEvent &event){ void MainWindow::onMenuFileLoadParticleXML(wxCommandEvent &event){
string fileName; try {
fileDialog->SetWildcard(wxT("XML files (*.xml)|*.xml")); string fileName;
fileDialog->SetWildcard(wxT("XML files (*.xml)|*.xml"));
if(isControlKeyPressed == true) { if(isControlKeyPressed == true) {
fileDialog->SetMessage(wxT("Adding Mega-Glest particle to current view.")); fileDialog->SetMessage(wxT("Adding Mega-Glest particle to current view."));
} }
else { else {
fileDialog->SetMessage(wxT("Selecting Mega-Glest particle for current view.")); fileDialog->SetMessage(wxT("Selecting Mega-Glest particle for current view."));
} }
if(fileDialog->ShowModal()==wxID_OK){ if(fileDialog->ShowModal()==wxID_OK){
string path = (const char*)wxFNCONV(fileDialog->GetPath().c_str()); string path = (const char*)wxFNCONV(fileDialog->GetPath().c_str());
loadParticle(path); loadParticle(path);
}
isControlKeyPressed = false;
}
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
} }
isControlKeyPressed = false;
} }
void MainWindow::onMenuFileLoadProjectileParticleXML(wxCommandEvent &event){ void MainWindow::onMenuFileLoadProjectileParticleXML(wxCommandEvent &event){
string fileName; try {
fileDialog->SetWildcard(wxT("XML files (*.xml)|*.xml")); string fileName;
fileDialog->SetWildcard(wxT("XML files (*.xml)|*.xml"));
if(isControlKeyPressed == true) { if(isControlKeyPressed == true) {
fileDialog->SetMessage(wxT("Adding Mega-Glest projectile particle to current view.")); fileDialog->SetMessage(wxT("Adding Mega-Glest projectile particle to current view."));
} }
else { else {
fileDialog->SetMessage(wxT("Selecting Mega-Glest projectile particle for current view.")); fileDialog->SetMessage(wxT("Selecting Mega-Glest projectile particle for current view."));
} }
if(fileDialog->ShowModal()==wxID_OK){ if(fileDialog->ShowModal()==wxID_OK){
string path = (const char*)wxFNCONV(fileDialog->GetPath().c_str()); string path = (const char*)wxFNCONV(fileDialog->GetPath().c_str());
loadProjectileParticle(path); loadProjectileParticle(path);
}
isControlKeyPressed = false;
}
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
} }
isControlKeyPressed = false;
} }
void MainWindow::onMenuFileLoadSplashParticleXML(wxCommandEvent &event){ void MainWindow::onMenuFileLoadSplashParticleXML(wxCommandEvent &event){
string fileName; try {
fileDialog->SetWildcard(wxT("XML files (*.xml)|*.xml")); string fileName;
fileDialog->SetWildcard(wxT("XML files (*.xml)|*.xml"));
if(isControlKeyPressed == true) { if(isControlKeyPressed == true) {
fileDialog->SetMessage(wxT("Adding Mega-Glest splash particle to current view.")); fileDialog->SetMessage(wxT("Adding Mega-Glest splash particle to current view."));
} }
else { else {
fileDialog->SetMessage(wxT("Selecting Mega-Glest splash particle for current view.")); fileDialog->SetMessage(wxT("Selecting Mega-Glest splash particle for current view."));
} }
if(fileDialog->ShowModal()==wxID_OK){ if(fileDialog->ShowModal()==wxID_OK){
string path = (const char*)wxFNCONV(fileDialog->GetPath().c_str()); string path = (const char*)wxFNCONV(fileDialog->GetPath().c_str());
loadSplashParticle(path); loadSplashParticle(path);
}
isControlKeyPressed = false;
}
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
} }
isControlKeyPressed = false;
} // is it possible to join loadParticle(), loadProjectileParticle() and loadSplashParticle() to one method? } // is it possible to join loadParticle(), loadProjectileParticle() and loadSplashParticle() to one method?
void MainWindow::onMenuFileSaveScreenshot(wxCommandEvent &event) { void MainWindow::onMenuFileSaveScreenshot(wxCommandEvent &event) {
string path = "screens/"; try {
if(isdir(path.c_str()) == true) { string path = "screens/";
//Config &config= Config::getInstance(); if(isdir(path.c_str()) == true) {
//string fileFormat = config.getString("ScreenShotFileType","png"); //Config &config= Config::getInstance();
string fileFormat = "png"; //string fileFormat = config.getString("ScreenShotFileType","png");
string fileFormat = "png";
for(int i=0; i < 1000; ++i) { for(int i=0; i < 1000; ++i) {
path = "screens/"; path = "screens/";
path += string("screen") + intToStr(i) + string(".") + fileFormat; path += string("screen") + intToStr(i) + string(".") + fileFormat;
FILE *f= fopen(path.c_str(), "rb"); FILE *f= fopen(path.c_str(), "rb");
if(f == NULL) { if(f == NULL) {
renderer->saveScreen(path); renderer->saveScreen(path);
break; break;
} }
else { else {
fclose(f); fclose(f);
}
} }
} }
} }
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
} }
void MainWindow::onMenuFileClearAll(wxCommandEvent &event) { void MainWindow::onMenuFileClearAll(wxCommandEvent &event) {
modelPathList.clear(); try {
particlePathList.clear(); modelPathList.clear();
particleProjectilePathList.clear(); particlePathList.clear();
particleSplashPathList.clear(); // as above particleProjectilePathList.clear();
particleSplashPathList.clear(); // as above
timer->Stop(); timer->Stop();
renderer->end(); renderer->end();
unitParticleSystems.clear(); unitParticleSystems.clear();
unitParticleSystemTypes.clear(); unitParticleSystemTypes.clear();
projectileParticleSystems.clear(); projectileParticleSystems.clear();
projectileParticleSystemTypes.clear(); projectileParticleSystemTypes.clear();
splashParticleSystems.clear(); // as above splashParticleSystems.clear(); // as above
splashParticleSystemTypes.clear(); splashParticleSystemTypes.clear();
delete model; delete model;
model = NULL; model = NULL;
loadModel(""); loadModel("");
loadParticle(""); loadParticle("");
loadProjectileParticle(""); loadProjectileParticle("");
loadSplashParticle(""); // as above loadSplashParticle(""); // as above
GetStatusBar()->SetStatusText(ToUnicode(statusbarText.c_str())); GetStatusBar()->SetStatusText(ToUnicode(statusbarText.c_str()));
timer->Start(100); timer->Start(100);
isControlKeyPressed = false; isControlKeyPressed = false;
}
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
} }
void MainWindow::onMenuFileExit(wxCommandEvent &event) { void MainWindow::onMenuFileExit(wxCommandEvent &event) {
@ -513,7 +571,7 @@ void MainWindow::loadParticle(string path) {
} }
catch(std::runtime_error e) { catch(std::runtime_error e) {
std::cout << e.what() << std::endl; std::cout << e.what() << std::endl;
wxMessageBox( ToUnicode(e.what()), wxT("Not a Mega-Glest particle XML file, or broken"), wxICON_ERROR); wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Not a Mega-Glest particle XML file, or broken"), wxOK | wxICON_ERROR).ShowModal();
} }
timer->Start(100); timer->Start(100);
} }
@ -619,7 +677,7 @@ void MainWindow::loadProjectileParticle(string path) {
} }
catch(std::runtime_error e) { catch(std::runtime_error e) {
std::cout << e.what() << std::endl; std::cout << e.what() << std::endl;
wxMessageBox( ToUnicode(e.what()), wxT("Not a Mega-Glest projectile particle XML file, or broken"), wxICON_ERROR); wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Not a Mega-Glest projectile particle XML file, or broken"), wxOK | wxICON_ERROR).ShowModal();
} }
timer->Start(100); timer->Start(100);
} }
@ -718,145 +776,223 @@ void MainWindow::loadSplashParticle(string path) { // uses ParticleSystemTypeSp
} }
catch(std::runtime_error e) { catch(std::runtime_error e) {
std::cout << e.what() << std::endl; std::cout << e.what() << std::endl;
wxMessageBox( ToUnicode(e.what()), wxT("Not a Mega-Glest splash particle XML file, or broken"), wxICON_ERROR); wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Not a Mega-Glest projectile particle XML file, or broken"), wxOK | wxICON_ERROR).ShowModal();
} }
timer->Start(100); timer->Start(100);
} }
void MainWindow::onMenuModeNormals(wxCommandEvent &event){ void MainWindow::onMenuModeNormals(wxCommandEvent &event){
renderer->toggleNormals(); try {
menuMode->Check(miModeNormals, renderer->getNormals()); renderer->toggleNormals();
menuMode->Check(miModeNormals, renderer->getNormals());
}
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
} }
void MainWindow::onMenuModeWireframe(wxCommandEvent &event){ void MainWindow::onMenuModeWireframe(wxCommandEvent &event){
renderer->toggleWireframe(); try {
menuMode->Check(miModeWireframe, renderer->getWireframe()); renderer->toggleWireframe();
menuMode->Check(miModeWireframe, renderer->getWireframe());
}
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
} }
void MainWindow::onMenuModeGrid(wxCommandEvent &event){ void MainWindow::onMenuModeGrid(wxCommandEvent &event){
renderer->toggleGrid(); try {
menuMode->Check(miModeGrid, renderer->getGrid()); renderer->toggleGrid();
menuMode->Check(miModeGrid, renderer->getGrid());
}
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
} }
void MainWindow::onMenuSpeedSlower(wxCommandEvent &event){ void MainWindow::onMenuSpeedSlower(wxCommandEvent &event){
speed /= 1.5f; try {
if(speed < 0) { speed /= 1.5f;
speed = 0; if(speed < 0) {
} speed = 0;
}
string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0); string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0);
GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str())); GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str()));
}
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
} }
void MainWindow::onMenuSpeedFaster(wxCommandEvent &event){ void MainWindow::onMenuSpeedFaster(wxCommandEvent &event){
speed *= 1.5f; try {
if(speed > 1) { speed *= 1.5f;
speed = 1; if(speed > 1) {
} speed = 1;
}
string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0 ); string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0 );
GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str())); GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str()));
}
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
} }
// set menu checkboxes to what player color is used // set menu checkboxes to what player color is used
void MainWindow::onMenuColorRed(wxCommandEvent &event){ void MainWindow::onMenuColorRed(wxCommandEvent &event) {
playerColor= Renderer::pcRed; try {
menuCustomColor->Check(miColorRed, true); playerColor= Renderer::pcRed;
menuCustomColor->Check(miColorBlue, false); menuCustomColor->Check(miColorRed, true);
menuCustomColor->Check(miColorGreen, false); menuCustomColor->Check(miColorBlue, false);
menuCustomColor->Check(miColorYellow, false); menuCustomColor->Check(miColorGreen, false);
menuCustomColor->Check(miColorWhite, false); menuCustomColor->Check(miColorYellow, false);
menuCustomColor->Check(miColorCyan, false); menuCustomColor->Check(miColorWhite, false);
menuCustomColor->Check(miColorOrange, false); menuCustomColor->Check(miColorCyan, false);
menuCustomColor->Check(miColorMagenta, false); menuCustomColor->Check(miColorOrange, false);
menuCustomColor->Check(miColorMagenta, false);
}
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
} }
void MainWindow::onMenuColorBlue(wxCommandEvent &event){ void MainWindow::onMenuColorBlue(wxCommandEvent &event) {
playerColor= Renderer::pcBlue; try {
menuCustomColor->Check(miColorRed, false); playerColor= Renderer::pcBlue;
menuCustomColor->Check(miColorBlue, true); menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorGreen, false); menuCustomColor->Check(miColorBlue, true);
menuCustomColor->Check(miColorYellow, false); menuCustomColor->Check(miColorGreen, false);
menuCustomColor->Check(miColorWhite, false); menuCustomColor->Check(miColorYellow, false);
menuCustomColor->Check(miColorCyan, false); menuCustomColor->Check(miColorWhite, false);
menuCustomColor->Check(miColorOrange, false); menuCustomColor->Check(miColorCyan, false);
menuCustomColor->Check(miColorMagenta, false); menuCustomColor->Check(miColorOrange, false);
menuCustomColor->Check(miColorMagenta, false);
}
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
} }
void MainWindow::onMenuColorGreen(wxCommandEvent &event){ void MainWindow::onMenuColorGreen(wxCommandEvent &event) {
playerColor= Renderer::pcGreen; try {
menuCustomColor->Check(miColorRed, false); playerColor= Renderer::pcGreen;
menuCustomColor->Check(miColorBlue, false); menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorGreen, true); menuCustomColor->Check(miColorBlue, false);
menuCustomColor->Check(miColorYellow, false); menuCustomColor->Check(miColorGreen, true);
menuCustomColor->Check(miColorWhite, false); menuCustomColor->Check(miColorYellow, false);
menuCustomColor->Check(miColorCyan, false); menuCustomColor->Check(miColorWhite, false);
menuCustomColor->Check(miColorOrange, false); menuCustomColor->Check(miColorCyan, false);
menuCustomColor->Check(miColorMagenta, false); menuCustomColor->Check(miColorOrange, false);
menuCustomColor->Check(miColorMagenta, false);
}
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
} }
void MainWindow::onMenuColorYellow(wxCommandEvent &event){ void MainWindow::onMenuColorYellow(wxCommandEvent &event) {
playerColor= Renderer::pcYellow; try {
menuCustomColor->Check(miColorRed, false); playerColor= Renderer::pcYellow;
menuCustomColor->Check(miColorBlue, false); menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorGreen, false); menuCustomColor->Check(miColorBlue, false);
menuCustomColor->Check(miColorYellow, true); menuCustomColor->Check(miColorGreen, false);
menuCustomColor->Check(miColorWhite, false); menuCustomColor->Check(miColorYellow, true);
menuCustomColor->Check(miColorCyan, false); menuCustomColor->Check(miColorWhite, false);
menuCustomColor->Check(miColorOrange, false); menuCustomColor->Check(miColorCyan, false);
menuCustomColor->Check(miColorMagenta, false); menuCustomColor->Check(miColorOrange, false);
menuCustomColor->Check(miColorMagenta, false);
}
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
} }
void MainWindow::onMenuColorWhite(wxCommandEvent &event){ void MainWindow::onMenuColorWhite(wxCommandEvent &event) {
playerColor= Renderer::pcWhite; try {
menuCustomColor->Check(miColorRed, false); playerColor= Renderer::pcWhite;
menuCustomColor->Check(miColorBlue, false); menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorGreen, false); menuCustomColor->Check(miColorBlue, false);
menuCustomColor->Check(miColorYellow, false); menuCustomColor->Check(miColorGreen, false);
menuCustomColor->Check(miColorWhite, true); menuCustomColor->Check(miColorYellow, false);
menuCustomColor->Check(miColorCyan, false); menuCustomColor->Check(miColorWhite, true);
menuCustomColor->Check(miColorOrange, false); menuCustomColor->Check(miColorCyan, false);
menuCustomColor->Check(miColorMagenta, false); menuCustomColor->Check(miColorOrange, false);
menuCustomColor->Check(miColorMagenta, false);
}
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
} }
void MainWindow::onMenuColorCyan(wxCommandEvent &event){ void MainWindow::onMenuColorCyan(wxCommandEvent &event) {
playerColor= Renderer::pcCyan; try {
menuCustomColor->Check(miColorRed, false); playerColor= Renderer::pcCyan;
menuCustomColor->Check(miColorBlue, false); menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorGreen, false); menuCustomColor->Check(miColorBlue, false);
menuCustomColor->Check(miColorYellow, false); menuCustomColor->Check(miColorGreen, false);
menuCustomColor->Check(miColorWhite, false); menuCustomColor->Check(miColorYellow, false);
menuCustomColor->Check(miColorCyan, true); menuCustomColor->Check(miColorWhite, false);
menuCustomColor->Check(miColorOrange, false); menuCustomColor->Check(miColorCyan, true);
menuCustomColor->Check(miColorMagenta, false); menuCustomColor->Check(miColorOrange, false);
menuCustomColor->Check(miColorMagenta, false);
}
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
} }
void MainWindow::onMenuColorOrange(wxCommandEvent &event){ void MainWindow::onMenuColorOrange(wxCommandEvent &event) {
playerColor= Renderer::pcOrange; try {
menuCustomColor->Check(miColorRed, false); playerColor= Renderer::pcOrange;
menuCustomColor->Check(miColorBlue, false); menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorGreen, false); menuCustomColor->Check(miColorBlue, false);
menuCustomColor->Check(miColorYellow, false); menuCustomColor->Check(miColorGreen, false);
menuCustomColor->Check(miColorWhite, false); menuCustomColor->Check(miColorYellow, false);
menuCustomColor->Check(miColorCyan, false); menuCustomColor->Check(miColorWhite, false);
menuCustomColor->Check(miColorOrange, true); menuCustomColor->Check(miColorCyan, false);
menuCustomColor->Check(miColorMagenta, false); menuCustomColor->Check(miColorOrange, true);
menuCustomColor->Check(miColorMagenta, false);
}
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
} }
void MainWindow::onMenuColorMagenta(wxCommandEvent &event){ void MainWindow::onMenuColorMagenta(wxCommandEvent &event) {
playerColor= Renderer::pcMagenta; try {
menuCustomColor->Check(miColorRed, false); playerColor= Renderer::pcMagenta;
menuCustomColor->Check(miColorBlue, false); menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorGreen, false); menuCustomColor->Check(miColorBlue, false);
menuCustomColor->Check(miColorYellow, false); menuCustomColor->Check(miColorGreen, false);
menuCustomColor->Check(miColorWhite, false); menuCustomColor->Check(miColorYellow, false);
menuCustomColor->Check(miColorCyan, false); menuCustomColor->Check(miColorWhite, false);
menuCustomColor->Check(miColorOrange, false); menuCustomColor->Check(miColorCyan, false);
menuCustomColor->Check(miColorMagenta, true); menuCustomColor->Check(miColorOrange, false);
menuCustomColor->Check(miColorMagenta, true);
}
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
} }
void MainWindow::onTimer(wxTimerEvent &event){ void MainWindow::onTimer(wxTimerEvent &event) {
wxPaintEvent paintEvent; wxPaintEvent paintEvent;
anim = anim + speed; anim = anim + speed;
@ -866,7 +1002,7 @@ void MainWindow::onTimer(wxTimerEvent &event){
onPaint(paintEvent); onPaint(paintEvent);
} }
string MainWindow::getModelInfo(){ string MainWindow::getModelInfo() {
string str; string str;
if(model!=NULL){ if(model!=NULL){
@ -881,90 +1017,102 @@ string MainWindow::getModelInfo(){
void MainWindow::onKeyDown(wxKeyEvent &e) { void MainWindow::onKeyDown(wxKeyEvent &e) {
// std::cout << "e.ControlDown() = " << e.ControlDown() << " e.GetKeyCode() = " << e.GetKeyCode() << " isCtrl = " << (e.GetKeyCode() == WXK_CONTROL) << std::endl; try {
// std::cout << "e.ControlDown() = " << e.ControlDown() << " e.GetKeyCode() = " << e.GetKeyCode() << " isCtrl = " << (e.GetKeyCode() == WXK_CONTROL) << std::endl;
// Note: This ctrl-key handling is buggy since it never resests when ctrl is released later, so I reset it at end of loadcommands for now. // Note: This ctrl-key handling is buggy since it never resests when ctrl is released later, so I reset it at end of loadcommands for now.
if(e.ControlDown() == true || e.GetKeyCode() == WXK_CONTROL) { if(e.ControlDown() == true || e.GetKeyCode() == WXK_CONTROL) {
isControlKeyPressed = true; isControlKeyPressed = true;
} }
else { else {
isControlKeyPressed = false; isControlKeyPressed = false;
}
// std::cout << "isControlKeyPressed = " << isControlKeyPressed << std::endl;
// here also because + and - hotkeys don't work for numpad automaticly
if (e.GetKeyCode() == 388) {
speed *= 1.5f; //numpad+
if(speed > 1.0) {
speed = 1.0;
} }
string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0); // std::cout << "isControlKeyPressed = " << isControlKeyPressed << std::endl;
GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str()));
// here also because + and - hotkeys don't work for numpad automaticly
if (e.GetKeyCode() == 388) {
speed *= 1.5f; //numpad+
if(speed > 1.0) {
speed = 1.0;
}
string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0);
GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str()));
}
else if (e.GetKeyCode() == 390) {
speed /= 1.5f; //numpad-
if(speed < 0) {
speed = 0;
} }
string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0); else if (e.GetKeyCode() == 390) {
GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str())); speed /= 1.5f; //numpad-
} if(speed < 0) {
else if (e.GetKeyCode() == 87) { speed = 0;
glClearColor(0.6f, 0.6f, 0.6f, 1.0f); //w key //backgroundcolor constant 0.3 -> 0.6 }
string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0);
GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str()));
}
else if (e.GetKeyCode() == 87) {
glClearColor(0.6f, 0.6f, 0.6f, 1.0f); //w key //backgroundcolor constant 0.3 -> 0.6
} }
// some posibility to adjust brightness: // some posibility to adjust brightness:
/* /*
else if (e.GetKeyCode() == 322) { // Ins - Grid else if (e.GetKeyCode() == 322) { // Ins - Grid
gridBrightness += 0.1f; if (gridBrightness >1.0) gridBrightness =1.0; gridBrightness += 0.1f; if (gridBrightness >1.0) gridBrightness =1.0;
}
else if (e.GetKeyCode() == 127) { // Del
gridBrightness -= 0.1f; if (gridBrightness <0) gridBrightness =0;
}
*/
else if (e.GetKeyCode() == 313) { // Home - Background
backBrightness += 0.1f; if (backBrightness >1.0) backBrightness=1.0;
glClearColor(backBrightness, backBrightness, backBrightness, 1.0f);
}
else if (e.GetKeyCode() == 312) { // End
backBrightness -= 0.1f; if (backBrightness<0) backBrightness=0;
glClearColor(backBrightness, backBrightness, backBrightness, 1.0f);
}
else if (e.GetKeyCode() == 366) { // PgUp - Lightning of model
lightBrightness += 0.1f; if (lightBrightness >1.0) lightBrightness =1.0;
Vec4f ambientNEW= Vec4f(lightBrightness, lightBrightness, lightBrightness, 1.0f);
glLightfv(GL_LIGHT0,GL_AMBIENT, ambientNEW.ptr());
}
else if (e.GetKeyCode() == 367) { // pgDn
lightBrightness -= 0.1f; if (lightBrightness <0) lightBrightness =0;
Vec4f ambientNEW= Vec4f(lightBrightness, lightBrightness, lightBrightness, 1.0f);
glLightfv(GL_LIGHT0,GL_AMBIENT, ambientNEW.ptr());
}
} }
else if (e.GetKeyCode() == 127) { // Del catch(std::runtime_error e) {
gridBrightness -= 0.1f; if (gridBrightness <0) gridBrightness =0; std::cout << e.what() << std::endl;
} wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
*/
else if (e.GetKeyCode() == 313) { // Home - Background
backBrightness += 0.1f; if (backBrightness >1.0) backBrightness=1.0;
glClearColor(backBrightness, backBrightness, backBrightness, 1.0f);
}
else if (e.GetKeyCode() == 312) { // End
backBrightness -= 0.1f; if (backBrightness<0) backBrightness=0;
glClearColor(backBrightness, backBrightness, backBrightness, 1.0f);
}
else if (e.GetKeyCode() == 366) { // PgUp - Lightning of model
lightBrightness += 0.1f; if (lightBrightness >1.0) lightBrightness =1.0;
Vec4f ambientNEW= Vec4f(lightBrightness, lightBrightness, lightBrightness, 1.0f);
glLightfv(GL_LIGHT0,GL_AMBIENT, ambientNEW.ptr());
}
else if (e.GetKeyCode() == 367) { // pgDn
lightBrightness -= 0.1f; if (lightBrightness <0) lightBrightness =0;
Vec4f ambientNEW= Vec4f(lightBrightness, lightBrightness, lightBrightness, 1.0f);
glLightfv(GL_LIGHT0,GL_AMBIENT, ambientNEW.ptr());
} }
} }
void MainWindow::onMenuRestart(wxCommandEvent &event){ void MainWindow::onMenuRestart(wxCommandEvent &event) {
// std::cout << "pressed R (restart particle animation)" << std::endl; try {
renderer->end(); // std::cout << "pressed R (restart particle animation)" << std::endl;
renderer->end();
unitParticleSystems.clear(); unitParticleSystems.clear();
unitParticleSystemTypes.clear(); unitParticleSystemTypes.clear();
projectileParticleSystems.clear(); projectileParticleSystems.clear();
projectileParticleSystemTypes.clear(); projectileParticleSystemTypes.clear();
splashParticleSystems.clear(); // as above splashParticleSystems.clear(); // as above
splashParticleSystemTypes.clear(); splashParticleSystemTypes.clear();
loadModel(""); loadModel("");
loadParticle(""); loadParticle("");
loadProjectileParticle(""); loadProjectileParticle("");
loadSplashParticle(""); // as above loadSplashParticle(""); // as above
renderer->initModelManager(); renderer->initModelManager();
renderer->initTextureManager(); renderer->initTextureManager();
}
catch(std::runtime_error e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
} }
BEGIN_EVENT_TABLE(MainWindow, wxFrame) BEGIN_EVENT_TABLE(MainWindow, wxFrame)