From bd3cb7f9bb0edb364c43098bf466f2f56000ac41 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sun, 18 Jul 2010 05:09:30 +0000 Subject: [PATCH] - map editor bugfixes (proper deletion of arrays and tooltip painting) - updated vc++ 2008 project files (and new win32 dependency archive uploaded to sourceforge) so that all projects can be built in debug mode now --- mk/windoze/glest_configurator.vcproj | 10 +-- source/glest_map_editor/main.cpp | 92 ++++++++++++++++------------ source/glest_map_editor/map.cpp | 29 +++++---- 3 files changed, 75 insertions(+), 56 deletions(-) diff --git a/mk/windoze/glest_configurator.vcproj b/mk/windoze/glest_configurator.vcproj index 2b104b9a..d6ae00dc 100644 --- a/mk/windoze/glest_configurator.vcproj +++ b/mk/windoze/glest_configurator.vcproj @@ -40,14 +40,14 @@ panel = new wxPanel(this, wxID_ANY); @@ -332,11 +334,16 @@ void MainWindow::onClose(wxCloseEvent &event) { } MainWindow::~MainWindow() { - delete glCanvas; delete program; + program = NULL; + + delete glCanvas; + glCanvas = NULL; } void MainWindow::setDirty(bool val) { + wxPaintEvent ev; + onPaint(ev); if (fileModified && val) { return; } @@ -380,16 +387,20 @@ void MainWindow::onMouseDown(wxMouseEvent &event, int x, int y) { } void MainWindow::onMouseMove(wxMouseEvent &event, int x, int y) { + bool repaint = false; int dif; if (event.LeftIsDown()) { change(x, y); + repaint = true; } else if (event.MiddleIsDown()) { dif = (y - lastY); if (dif != 0) { program->incCellSize(dif / abs(dif)); + repaint = true; } } else if (event.RightIsDown()) { program->setOfset(x - lastX, y - lastY); + repaint = true; } else { int currResource = program->getResource(x, y); if (currResource > 0) { @@ -406,8 +417,10 @@ void MainWindow::onMouseMove(wxMouseEvent &event, int x, int y) { lastX = x; lastY = y; - wxPaintEvent ev; - onPaint(ev); + if (repaint) { + wxPaintEvent ev; + onPaint(ev); + } event.Skip(); } @@ -423,6 +436,7 @@ void MainWindow::onPaint(wxPaintEvent &event) { program->renderMap(glCanvas->GetClientSize().x, glCanvas->GetClientSize().y); glCanvas->SwapBuffers(); + event.Skip(); } void MainWindow::onMenuFileLoad(wxCommandEvent &event) { @@ -1021,42 +1035,42 @@ int App::OnExit() { return 0; } -MsgDialog::MsgDialog(wxWindow *parent, - const wxString& message, - const wxString& caption, - long style, +MsgDialog::MsgDialog(wxWindow *parent, + const wxString& message, + const wxString& caption, + long style, const wxPoint& pos) { - - m_sizerText = NULL; - // TODO: should we use main frame as parent by default here? - if ( !wxDialog::Create(parent, wxID_ANY, caption, - pos, wxDefaultSize, - style) ) { - return; - } - m_sizerText = new wxBoxSizer(wxVERTICAL); - wxStaticText *label = new wxStaticText(this, wxID_ANY, message); - wxFont font(*wxNORMAL_FONT); - font.SetPointSize(font.GetPointSize()); - font.SetWeight(wxFONTWEIGHT_NORMAL); - label->SetFont(font); - - m_sizerText->Add(label, wxSizerFlags().Centre().Border()); - - wxSizer *sizerIconAndText = new wxBoxSizer(wxHORIZONTAL); - sizerIconAndText->Add(m_sizerText, wxSizerFlags(1).Expand()); - - wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); - sizerTop->Add(sizerIconAndText, wxSizerFlags(1).Expand().Border()); - - wxSizer *sizerBtns = CreateButtonSizer(wxOK); - if ( sizerBtns ) - { - sizerTop->Add(sizerBtns, wxSizerFlags().Expand().Border()); - } - - SetSizerAndFit(sizerTop); - CentreOnScreen(); + + m_sizerText = NULL; + // TODO: should we use main frame as parent by default here? + if ( !wxDialog::Create(parent, wxID_ANY, caption, + pos, wxDefaultSize, + style) ) { + return; + } + m_sizerText = new wxBoxSizer(wxVERTICAL); + wxStaticText *label = new wxStaticText(this, wxID_ANY, message); + wxFont font(*wxNORMAL_FONT); + font.SetPointSize(font.GetPointSize()); + font.SetWeight(wxFONTWEIGHT_NORMAL); + label->SetFont(font); + + m_sizerText->Add(label, wxSizerFlags().Centre().Border()); + + wxSizer *sizerIconAndText = new wxBoxSizer(wxHORIZONTAL); + sizerIconAndText->Add(m_sizerText, wxSizerFlags(1).Expand()); + + wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); + sizerTop->Add(sizerIconAndText, wxSizerFlags(1).Expand().Border()); + + wxSizer *sizerBtns = CreateButtonSizer(wxOK); + if ( sizerBtns ) + { + sizerTop->Add(sizerBtns, wxSizerFlags().Expand().Border()); + } + + SetSizerAndFit(sizerTop); + CentreOnScreen(); } MsgDialog::~MsgDialog() { diff --git a/source/glest_map_editor/map.cpp b/source/glest_map_editor/map.cpp index 6ad32ca8..9509c5a4 100644 --- a/source/glest_map_editor/map.cpp +++ b/source/glest_map_editor/map.cpp @@ -41,10 +41,13 @@ Map::Map() { Map::~Map() { delete [] startLocations; + startLocations = NULL; + for (int i = 0; i < h; i++) { - delete cells[i]; + delete [] cells[i]; } - delete cells; + delete [] cells; + cells = NULL; } @@ -284,9 +287,9 @@ void Map::flipX() { } for (int i = 0; i < w; i++) { - delete oldCells[i]; + delete [] oldCells[i]; } - delete oldCells; + delete [] oldCells; } void Map::flipY() { @@ -308,9 +311,9 @@ void Map::flipY() { } for (int i = 0; i < w; i++) { - delete oldCells[i]; + delete [] oldCells[i]; } - delete oldCells; + delete [] oldCells; } void Map::changeSurface(int x, int y, int surface, int radius) { @@ -411,9 +414,9 @@ void Map::reset(int w, int h, float alt, int surf) { if (cells != NULL) { for (int i = 0; i < this->w; i++) { - delete cells[i]; + delete [] cells[i]; } - delete cells; + delete [] cells; } this->w = w; @@ -493,8 +496,8 @@ void Map::resize(int w, int h, float alt, int surf) { //delete old cells if (oldCells != NULL) { for (int i = 0; i < oldW; i++) - delete oldCells[i]; - delete oldCells; + delete [] oldCells[i]; + delete [] oldCells; } } @@ -503,8 +506,10 @@ void Map::resetFactions(int maxPlayers) { throw runtime_error("Max Players must be in the range 1-8"); } - if (startLocations != NULL) - delete startLocations; + if (startLocations != NULL) { + delete [] startLocations; + startLocations = NULL; + } maxFactions = maxPlayers;