From d2a81d871bc65a3d5aede81d76bfc30ed69d396a Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 26 May 2010 07:17:34 +0000 Subject: [PATCH] Make several methods in BaseGrid static or const and clean up some of the implementations. Originally committed to SVN as r4362. --- aegisub/src/base_grid.cpp | 86 ++++++++++++-------------------- aegisub/src/base_grid.h | 20 ++++---- aegisub/src/visual_tool_drag.cpp | 6 ++- 3 files changed, 47 insertions(+), 65 deletions(-) diff --git a/aegisub/src/base_grid.cpp b/aegisub/src/base_grid.cpp index 329caf23c..e8a098265 100644 --- a/aegisub/src/base_grid.cpp +++ b/aegisub/src/base_grid.cpp @@ -40,6 +40,7 @@ #include "config.h" #ifndef AGI_PRE +#include #include #endif @@ -205,27 +206,23 @@ void BaseGrid::MakeCellVisible(int row, int col,bool center) { /// @param select /// void BaseGrid::SelectRow(int row, bool addToSelected, bool select) { - // Sanity checking - if (row >= GetRows()) row = GetRows()-1; - else if (row < 0) row = 0; - if (!addToSelected) ClearSelection(); - try { - bool cur = selMap.at(row); - if (select != cur) { - selMap.at(row) = select; - - if (!addToSelected) Refresh(false); - else { - int w = 0; - int h = 0; - GetClientSize(&w,&h); - RefreshRect(wxRect(0,(row+1-yPos)*lineHeight,w,lineHeight),false); - } + if (row < 0 || (size_t)row >= selMap.size()) return; + + if (select != selMap[row]) { + selMap[row] = select; + + if (!addToSelected) { + Refresh(false); + } + else { + int w = 0; + int h = 0; + GetClientSize(&w,&h); + RefreshRect(wxRect(0,(row+1-yPos)*lineHeight,w,lineHeight),false); } } - catch (...) {} } @@ -268,15 +265,9 @@ void BaseGrid::ClearSelection() { /// @param col /// @return /// -bool BaseGrid::IsInSelection(int row, int col) const { - if (row >= GetRows() || row < 0) return false; - (void) col; - try { - return selMap.at(row); - } - catch (...) { - return false; - } +bool BaseGrid::IsInSelection(int row, int) const { + if ((size_t)row >= selMap.size() || row < 0) return false; + return selMap[row]; } @@ -284,13 +275,8 @@ bool BaseGrid::IsInSelection(int row, int col) const { /// @brief Number of selected rows /// @return /// -int BaseGrid::GetNumberSelection() { - int count = 0; - int rows = selMap.size(); - for (int i=0;i::const_iterator first = std::find(selMap.begin(), selMap.end(), true); + if (first == selMap.end()) return -1; + return std::distance(selMap.begin(), first); } @@ -313,7 +295,7 @@ int BaseGrid::GetFirstSelRow() { /// @brief Gets last selected row from first block selection /// @return /// -int BaseGrid::GetLastSelRow() { +int BaseGrid::GetLastSelRow() const { int frow = GetFirstSelRow(); while (IsInSelection(frow)) { frow++; @@ -324,10 +306,10 @@ int BaseGrid::GetLastSelRow() { /// @brief Gets all selected rows -/// @param cont +/// @param[out] cont /// @return /// -wxArrayInt BaseGrid::GetSelection(bool *cont) { +wxArrayInt BaseGrid::GetSelection(bool *cont) const { // Prepare int nrows = GetRows(); int last = -1; @@ -973,13 +955,10 @@ void BaseGrid::SetColumnWidths() { /// @param n /// @return /// -AssDialogue *BaseGrid::GetDialogue(int n) { +AssDialogue *BaseGrid::GetDialogue(int n) const { try { - if (n < 0) return NULL; - if ((size_t)n >= diagMap.size()) return NULL; - AssEntry *e = *diagMap.at(n); - if (e->GetType() != ENTRY_DIALOGUE) return NULL; - return dynamic_cast(e); + if (n < 0 || (size_t)n >= diagMap.size()) return NULL; + return dynamic_cast(*diagMap.at(n)); } catch (...) { return NULL; @@ -993,10 +972,11 @@ AssDialogue *BaseGrid::GetDialogue(int n) { /// @return /// bool BaseGrid::IsDisplayed(AssDialogue *line) { - if (!VideoContext::Get()->IsLoaded()) return false; + VideoContext* con = VideoContext::Get(); + if (!con->IsLoaded()) return false; int f1 = VFR_Output.GetFrameAtTime(line->Start.GetMS(),true); int f2 = VFR_Output.GetFrameAtTime(line->End.GetMS(),false); - if (f1 <= VideoContext::Get()->GetFrameN() && f2 >= VideoContext::Get()->GetFrameN()) return true; + if (f1 <= con->GetFrameN() && f2 >= con->GetFrameN()) return true; return false; } @@ -1188,7 +1168,7 @@ void BaseGrid::SetByFrame (bool state) { /// @param n1 /// @param n2 /// -wxArrayInt BaseGrid::GetRangeArray(int n1,int n2) { +wxArrayInt BaseGrid::GetRangeArray(int n1,int n2) const { // Swap if in wrong order if (n2 < n1) { int aux = n1; diff --git a/aegisub/src/base_grid.h b/aegisub/src/base_grid.h index f61e6e601..7b8598f67 100644 --- a/aegisub/src/base_grid.h +++ b/aegisub/src/base_grid.h @@ -118,6 +118,9 @@ protected: /// DOCME int yPos; + /// DOCME + std::vector selMap; + public: /// DOCME @@ -133,9 +136,6 @@ public: /// DOCME std::vector diagPtrMap; - /// DOCME - std::vector selMap; - void AdjustScrollbar(); void SetColumnWidths(); void BeginBatch(); @@ -145,22 +145,22 @@ public: void SelectRow(int row, bool addToSelected = false, bool select=true); void ClearSelection(); bool IsInSelection(int row, int col=0) const; - bool IsDisplayed(AssDialogue *line); - int GetNumberSelection(); - int GetFirstSelRow(); - int GetLastSelRow(); + static bool IsDisplayed(AssDialogue *line); + int GetNumberSelection() const; + int GetFirstSelRow() const; + int GetLastSelRow() const; void SelectVisible(); - wxArrayInt GetSelection(bool *continuous=NULL); + wxArrayInt GetSelection(bool *continuous=NULL) const; void Clear(); void UpdateMaps(); void UpdateStyle(); int GetRows() const; - wxArrayInt GetRangeArray(int n1,int n2); + wxArrayInt GetRangeArray(int n1,int n2) const; void MakeCellVisible(int row, int col,bool center=true); - AssDialogue *GetDialogue(int n); + AssDialogue *GetDialogue(int n) const; BaseGrid(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxWANTS_CHARS, const wxString& name = wxPanelNameStr); ~BaseGrid(); diff --git a/aegisub/src/visual_tool_drag.cpp b/aegisub/src/visual_tool_drag.cpp index 4ca705ea5..7e6defd63 100644 --- a/aegisub/src/visual_tool_drag.cpp +++ b/aegisub/src/visual_tool_drag.cpp @@ -179,8 +179,10 @@ void VisualToolDrag::PopulateFeatureList() { features.clear(); // Get video data - int numRows = VideoContext::Get()->grid->GetRows(); - int framen = VideoContext::Get()->GetFrameN(); + VideoContext* con = VideoContext::Get(); + int numRows = con->grid->GetRows(); + int framen = con->GetFrameN(); + wxArrayInt sel = GetSelection(); // For each line AssDialogue *diag;