From 029eabcbd46be2b6b1ccf4edaf6788f17831cb34 Mon Sep 17 00:00:00 2001 From: Aleksey Lobanov Date: Sat, 6 Jun 2015 17:22:15 +0300 Subject: [PATCH] There is error in project configuration in previous commits. This commit is fixed it. Dict caching and one-time drawing of letters now working --- src/crossgen.hpp | 10 +++++----- wxCrossGen/main.cpp | 13 ++++++------- wxCrossGen/wxCrossGen.project | 4 ++-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/crossgen.hpp b/src/crossgen.hpp index 7171d45..13ef766 100644 --- a/src/crossgen.hpp +++ b/src/crossgen.hpp @@ -9,7 +9,7 @@ typedef std::map DictType; typedef std::vector< std::vector > GridType; typedef std::vector< std::vector > CurGridType; -// Первый индекс -- длина слова +// Fisrt index is a word length typedef std::vector< std::vector > AllWordsType; typedef std::set< size_t > UsedWords; @@ -181,10 +181,10 @@ bool procCross(UsedWords used, AllWordsType &words, CurGridType grid, void generateCross(GridType &grid, DictType &dict, std::vector &words_out){ AllWordsType words; - for (DictType::iterator i = dict.begin(); i != dict.end(); ++i){ - if (words.size() <= i->first.size()) - words.resize(i->first.size() + 2); - words.at(i->first.size()).push_back(i->first); + for (DictType::iterator it = dict.begin(); it != dict.end(); ++it){ + if (words.size() <= it->first.size()) + words.resize(it->first.size() + 2); + words.at(it->first.size()).push_back(it->first); } for (size_t i = 2; i < words.size(); ++i){ wxLogDebug(wxT("Number of words with length %d is %d"), i, words.at(i).size()); diff --git a/wxCrossGen/main.cpp b/wxCrossGen/main.cpp index cf2b3e0..3c053c1 100644 --- a/wxCrossGen/main.cpp +++ b/wxCrossGen/main.cpp @@ -130,26 +130,25 @@ void MainFrame::SetGridImage(GridType &grid, size_t w) { for (size_t i = 0; i < winfos.size(); ++i){ if (winfos.at(i).direct == true){ for (size_t j = 0; j < winfos.at(i).len; ++j) - if ( !usedCells.at(i).at(j) ){ + if ( !usedCells.at(winfos.at(i).x+j).at(winfos.at(i).y) ) { dc.DrawText( _words.at(i).at(j), sq_w*(winfos.at(i).x+j) + sq_w*0.24, sq_h*winfos.at(i).y ); - usedCells.at(i).at(j) = true; + usedCells.at(winfos.at(i).x+j).at(winfos.at(i).y) = true; } } else { for (size_t j = 0; j < winfos.at(i).len; ++j) - if ( !usedCells.at(i).at(j) ){ + if ( !usedCells.at(winfos.at(i).x).at(winfos.at(i).y+j) ) { dc.DrawText( _words.at(i).at(j), sq_w*winfos.at(i).x + sq_w*0.24, sq_h*(winfos.at(i).y+j) ); - usedCells.at(i).at(j) = true; + usedCells.at(winfos.at(i).x).at(winfos.at(i).y+j) = true; } } - } } @@ -206,11 +205,11 @@ void MainFrame::OnbtnGenerateClick(wxCommandEvent &event) { SetGridImage(grid); _words.clear(); } - catch (...){ + catch ( ... ){ tOutput->Clear(); - this->Refresh(); wxMessageBox( wxT("Не могу создать кроссворд"), wxT("Ошибка"), wxICON_ERROR ); } + this->Refresh(); } diff --git a/wxCrossGen/wxCrossGen.project b/wxCrossGen/wxCrossGen.project index 242ca1f..76f1dad 100644 --- a/wxCrossGen/wxCrossGen.project +++ b/wxCrossGen/wxCrossGen.project @@ -47,7 +47,7 @@ - + @@ -85,7 +85,7 @@ - +