forked from mia/Aegisub
Make several methods in BaseGrid static or const and clean up some of the implementations.
Originally committed to SVN as r4362.
This commit is contained in:
parent
acc1e93728
commit
d2a81d871b
3 changed files with 47 additions and 65 deletions
|
@ -40,6 +40,7 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#ifndef AGI_PRE
|
#ifndef AGI_PRE
|
||||||
|
#include <algorithm>
|
||||||
#include <wx/sizer.h>
|
#include <wx/sizer.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -205,27 +206,23 @@ void BaseGrid::MakeCellVisible(int row, int col,bool center) {
|
||||||
/// @param select
|
/// @param select
|
||||||
///
|
///
|
||||||
void BaseGrid::SelectRow(int row, bool addToSelected, bool 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();
|
if (!addToSelected) ClearSelection();
|
||||||
try {
|
|
||||||
bool cur = selMap.at(row);
|
|
||||||
if (select != cur) {
|
|
||||||
selMap.at(row) = select;
|
|
||||||
|
|
||||||
if (!addToSelected) Refresh(false);
|
if (row < 0 || (size_t)row >= selMap.size()) return;
|
||||||
|
|
||||||
else {
|
if (select != selMap[row]) {
|
||||||
int w = 0;
|
selMap[row] = select;
|
||||||
int h = 0;
|
|
||||||
GetClientSize(&w,&h);
|
if (!addToSelected) {
|
||||||
RefreshRect(wxRect(0,(row+1-yPos)*lineHeight,w,lineHeight),false);
|
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
|
/// @param col
|
||||||
/// @return
|
/// @return
|
||||||
///
|
///
|
||||||
bool BaseGrid::IsInSelection(int row, int col) const {
|
bool BaseGrid::IsInSelection(int row, int) const {
|
||||||
if (row >= GetRows() || row < 0) return false;
|
if ((size_t)row >= selMap.size() || row < 0) return false;
|
||||||
(void) col;
|
return selMap[row];
|
||||||
try {
|
|
||||||
return selMap.at(row);
|
|
||||||
}
|
|
||||||
catch (...) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -284,13 +275,8 @@ bool BaseGrid::IsInSelection(int row, int col) const {
|
||||||
/// @brief Number of selected rows
|
/// @brief Number of selected rows
|
||||||
/// @return
|
/// @return
|
||||||
///
|
///
|
||||||
int BaseGrid::GetNumberSelection() {
|
int BaseGrid::GetNumberSelection() const {
|
||||||
int count = 0;
|
return std::count(selMap.begin(), selMap.end(), true);
|
||||||
int rows = selMap.size();
|
|
||||||
for (int i=0;i<rows;i++) {
|
|
||||||
if (selMap[i]) count++;
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -298,14 +284,10 @@ int BaseGrid::GetNumberSelection() {
|
||||||
/// @brief Gets first selected row
|
/// @brief Gets first selected row
|
||||||
/// @return
|
/// @return
|
||||||
///
|
///
|
||||||
int BaseGrid::GetFirstSelRow() {
|
int BaseGrid::GetFirstSelRow() const {
|
||||||
int nrows = GetRows();
|
std::vector<bool>::const_iterator first = std::find(selMap.begin(), selMap.end(), true);
|
||||||
for (int i=0;i<nrows;i++) {
|
if (first == selMap.end()) return -1;
|
||||||
if (IsInSelection(i,0)) {
|
return std::distance(selMap.begin(), first);
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -313,7 +295,7 @@ int BaseGrid::GetFirstSelRow() {
|
||||||
/// @brief Gets last selected row from first block selection
|
/// @brief Gets last selected row from first block selection
|
||||||
/// @return
|
/// @return
|
||||||
///
|
///
|
||||||
int BaseGrid::GetLastSelRow() {
|
int BaseGrid::GetLastSelRow() const {
|
||||||
int frow = GetFirstSelRow();
|
int frow = GetFirstSelRow();
|
||||||
while (IsInSelection(frow)) {
|
while (IsInSelection(frow)) {
|
||||||
frow++;
|
frow++;
|
||||||
|
@ -324,10 +306,10 @@ int BaseGrid::GetLastSelRow() {
|
||||||
|
|
||||||
|
|
||||||
/// @brief Gets all selected rows
|
/// @brief Gets all selected rows
|
||||||
/// @param cont
|
/// @param[out] cont
|
||||||
/// @return
|
/// @return
|
||||||
///
|
///
|
||||||
wxArrayInt BaseGrid::GetSelection(bool *cont) {
|
wxArrayInt BaseGrid::GetSelection(bool *cont) const {
|
||||||
// Prepare
|
// Prepare
|
||||||
int nrows = GetRows();
|
int nrows = GetRows();
|
||||||
int last = -1;
|
int last = -1;
|
||||||
|
@ -973,13 +955,10 @@ void BaseGrid::SetColumnWidths() {
|
||||||
/// @param n
|
/// @param n
|
||||||
/// @return
|
/// @return
|
||||||
///
|
///
|
||||||
AssDialogue *BaseGrid::GetDialogue(int n) {
|
AssDialogue *BaseGrid::GetDialogue(int n) const {
|
||||||
try {
|
try {
|
||||||
if (n < 0) return NULL;
|
if (n < 0 || (size_t)n >= diagMap.size()) return NULL;
|
||||||
if ((size_t)n >= diagMap.size()) return NULL;
|
return dynamic_cast<AssDialogue*>(*diagMap.at(n));
|
||||||
AssEntry *e = *diagMap.at(n);
|
|
||||||
if (e->GetType() != ENTRY_DIALOGUE) return NULL;
|
|
||||||
return dynamic_cast<AssDialogue*>(e);
|
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -993,10 +972,11 @@ AssDialogue *BaseGrid::GetDialogue(int n) {
|
||||||
/// @return
|
/// @return
|
||||||
///
|
///
|
||||||
bool BaseGrid::IsDisplayed(AssDialogue *line) {
|
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 f1 = VFR_Output.GetFrameAtTime(line->Start.GetMS(),true);
|
||||||
int f2 = VFR_Output.GetFrameAtTime(line->End.GetMS(),false);
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1188,7 +1168,7 @@ void BaseGrid::SetByFrame (bool state) {
|
||||||
/// @param n1
|
/// @param n1
|
||||||
/// @param n2
|
/// @param n2
|
||||||
///
|
///
|
||||||
wxArrayInt BaseGrid::GetRangeArray(int n1,int n2) {
|
wxArrayInt BaseGrid::GetRangeArray(int n1,int n2) const {
|
||||||
// Swap if in wrong order
|
// Swap if in wrong order
|
||||||
if (n2 < n1) {
|
if (n2 < n1) {
|
||||||
int aux = n1;
|
int aux = n1;
|
||||||
|
|
|
@ -118,6 +118,9 @@ protected:
|
||||||
/// DOCME
|
/// DOCME
|
||||||
int yPos;
|
int yPos;
|
||||||
|
|
||||||
|
/// DOCME
|
||||||
|
std::vector<bool> selMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// DOCME
|
/// DOCME
|
||||||
|
@ -133,9 +136,6 @@ public:
|
||||||
/// DOCME
|
/// DOCME
|
||||||
std::vector<AssDialogue *> diagPtrMap;
|
std::vector<AssDialogue *> diagPtrMap;
|
||||||
|
|
||||||
/// DOCME
|
|
||||||
std::vector<bool> selMap;
|
|
||||||
|
|
||||||
void AdjustScrollbar();
|
void AdjustScrollbar();
|
||||||
void SetColumnWidths();
|
void SetColumnWidths();
|
||||||
void BeginBatch();
|
void BeginBatch();
|
||||||
|
@ -145,22 +145,22 @@ public:
|
||||||
void SelectRow(int row, bool addToSelected = false, bool select=true);
|
void SelectRow(int row, bool addToSelected = false, bool select=true);
|
||||||
void ClearSelection();
|
void ClearSelection();
|
||||||
bool IsInSelection(int row, int col=0) const;
|
bool IsInSelection(int row, int col=0) const;
|
||||||
bool IsDisplayed(AssDialogue *line);
|
static bool IsDisplayed(AssDialogue *line);
|
||||||
int GetNumberSelection();
|
int GetNumberSelection() const;
|
||||||
int GetFirstSelRow();
|
int GetFirstSelRow() const;
|
||||||
int GetLastSelRow();
|
int GetLastSelRow() const;
|
||||||
void SelectVisible();
|
void SelectVisible();
|
||||||
wxArrayInt GetSelection(bool *continuous=NULL);
|
wxArrayInt GetSelection(bool *continuous=NULL) const;
|
||||||
|
|
||||||
void Clear();
|
void Clear();
|
||||||
void UpdateMaps();
|
void UpdateMaps();
|
||||||
void UpdateStyle();
|
void UpdateStyle();
|
||||||
|
|
||||||
int GetRows() const;
|
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);
|
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(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxWANTS_CHARS, const wxString& name = wxPanelNameStr);
|
||||||
~BaseGrid();
|
~BaseGrid();
|
||||||
|
|
|
@ -179,8 +179,10 @@ void VisualToolDrag::PopulateFeatureList() {
|
||||||
features.clear();
|
features.clear();
|
||||||
|
|
||||||
// Get video data
|
// Get video data
|
||||||
int numRows = VideoContext::Get()->grid->GetRows();
|
VideoContext* con = VideoContext::Get();
|
||||||
int framen = VideoContext::Get()->GetFrameN();
|
int numRows = con->grid->GetRows();
|
||||||
|
int framen = con->GetFrameN();
|
||||||
|
wxArrayInt sel = GetSelection();
|
||||||
|
|
||||||
// For each line
|
// For each line
|
||||||
AssDialogue *diag;
|
AssDialogue *diag;
|
||||||
|
|
Loading…
Reference in a new issue