Clean up base_grid a bit

Reduce the visibilty of many members and document some of them

Cut down on recreation of wxPen and wxBrush objects in DrawImage,
probably speeding up painting somewhat

Simplify handling of extendRow

Move event IDs to base_grid.cpp

Remove worthless comments and dead code

Assorted cosmetic changes

Originally committed to SVN as r5462.
This commit is contained in:
Thomas Goyne 2011-07-15 04:05:43 +00:00
parent fdb6d108f8
commit 95cadb5226
5 changed files with 246 additions and 531 deletions

File diff suppressed because it is too large Load diff

View file

@ -67,26 +67,33 @@ typedef SelectionListener<AssDialogue> SubtitleSelectionListener;
/// ///
/// DOCME /// DOCME
class BaseGrid : public wxWindow, public BaseSelectionController<AssDialogue> { class BaseGrid : public wxWindow, public BaseSelectionController<AssDialogue> {
/// DOCME int lineHeight; ///< Height of a line in pixels in the current font
int lineHeight; int lastRow; ///< ?
bool holding; ///< Is a drag selection in process?
/// DOCME wxFont font; ///< Current grid font
int lastRow; wxScrollBar *scrollBar; ///< The grid's scrollbar
wxBitmap *bmp; ///< Back buffer which the grid is rendered into
/// DOCME bool byFrame; ///< Should times be displayed as frame numbers
/// Row from which the selection shrinks/grows from when selecting via the
/// keyboard. Equal to the active row except for when using shift+up/down.
int extendRow; int extendRow;
/// DOCME Selection selection; ///< Currently selected lines
bool holding; AssDialogue *active_line; ///< The currently active line or 0 if none
std::vector<AssDialogue*> index_line_map; ///< Row number -> dialogue line
std::map<AssDialogue*,int> line_index_map; ///< Dialogue line -> row number
/// DOCME /// Selection batch nesting depth; changes are commited only when this
wxFont font; /// hits zero
int batch_level;
/// DOCME /// Has the active line been changed in the current batch?
wxScrollBar *scrollBar; bool batch_active_line_changed;
/// Lines which will be added to the selection when the current batch is
/// DOCME /// completed; should be disjoint from selection
wxBitmap *bmp; Selection batch_selection_added;
/// Lines which will be removed from the selection when the current batch
/// is completed; should be a subset of selection
Selection batch_selection_removed;
void OnPaint(wxPaintEvent &event); void OnPaint(wxPaintEvent &event);
void OnSize(wxSizeEvent &event); void OnSize(wxSizeEvent &event);
@ -95,66 +102,43 @@ class BaseGrid : public wxWindow, public BaseSelectionController<AssDialogue> {
void OnKeyDown(wxKeyEvent &event); void OnKeyDown(wxKeyEvent &event);
void DrawImage(wxDC &dc); void DrawImage(wxDC &dc);
Selection selection;
AssDialogue *active_line;
std::vector<AssDialogue*> index_line_map;
std::map<AssDialogue*,int> line_index_map;
int batch_level;
bool batch_active_line_changed;
Selection batch_selection_added;
Selection batch_selection_removed;
protected:
/// DOCME
int colWidth[16];
agi::Context *context;
/// DOCME
static const int columns = 10;
bool showCol[columns];
/// @brief DOCME
/// @param alternate
///
virtual void OnPopupMenu(bool alternate=false) {}
void ScrollTo(int y); void ScrollTo(int y);
/// DOCME virtual void OnPopupMenu(bool alternate = false) { }
protected:
int colWidth[16]; ///< Width in pixels of each column
agi::Context *context; ///< Current project context
static const int columns = 10; ///< Total number of columns
bool showCol[columns]; ///< Column visibility mask
int yPos; int yPos;
void AdjustScrollbar();
void SetColumnWidths();
// Re-implement functions from BaseSelectionController to add batching // Re-implement functions from BaseSelectionController to add batching
void AnnounceActiveLineChanged(AssDialogue *new_line); void AnnounceActiveLineChanged(AssDialogue *new_line);
void AnnounceSelectedSetChanged(const Selection &lines_added, const Selection &lines_removed); void AnnounceSelectedSetChanged(const Selection &lines_added, const Selection &lines_removed);
public: public:
// SelectionController implementation // SelectionController implementation
virtual void SetActiveLine(AssDialogue *new_line); void SetActiveLine(AssDialogue *new_line);
virtual AssDialogue * GetActiveLine() const { return active_line; } AssDialogue * GetActiveLine() const { return active_line; }
virtual void SetSelectedSet(const Selection &new_selection); void SetSelectedSet(const Selection &new_selection);
virtual void GetSelectedSet(Selection &res) const { res = selection; } void GetSelectedSet(Selection &res) const { res = selection; }
virtual Selection const& GetSelectedSet() const { return selection; } Selection const& GetSelectedSet() const { return selection; }
virtual void NextLine(); void NextLine();
virtual void PrevLine(); void PrevLine();
public:
/// DOCME
bool byFrame;
void AdjustScrollbar();
void SetColumnWidths();
void BeginBatch(); void BeginBatch();
void EndBatch(); void EndBatch();
void SetByFrame (bool state); void SetByFrame(bool state);
void SelectRow(int row, bool addToSelected = false, bool select=true);
void ClearSelection();
bool IsInSelection(int row, int col=0) const;
bool IsDisplayed(const AssDialogue *line) const; bool IsDisplayed(const AssDialogue *line) const;
int GetNumberSelection() const; void SelectRow(int row, bool addToSelected = false, bool select=true);
bool IsInSelection(int row) const;
int GetFirstSelRow() const; int GetFirstSelRow() const;
int GetLastSelRow() const; int GetLastSelRow() const;
void SelectVisible(); void SelectVisible();
@ -167,8 +151,7 @@ public:
void UpdateMaps(bool preserve_selected_rows = false); void UpdateMaps(bool preserve_selected_rows = false);
void UpdateStyle(); void UpdateStyle();
int GetRows() const; int GetRows() const { return index_line_map.size(); }
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) const; AssDialogue *GetDialogue(int n) const;
@ -179,14 +162,3 @@ public:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
///////
// IDs
enum {
/// DOCME
GRID_SCROLLBAR = 1730
};

View file

@ -270,7 +270,6 @@ void DialogSelection::Process() {
// Select for modes 2 and 3 // Select for modes 2 and 3
if (action == 2 || action == 3) { if (action == 2 || action == 3) {
SubtitleSelectionController::Selection newsel; SubtitleSelectionController::Selection newsel;
grid->ClearSelection();
int count = sels.Count(); int count = sels.Count();
for (int i=0;i<count;i++) { for (int i=0;i<count;i++) {
newsel.insert(grid->GetDialogue(sels[i])); newsel.insert(grid->GetDialogue(sels[i]));

View file

@ -256,7 +256,7 @@ void DialogShiftTimes::OnOK(wxCommandEvent &event) {
// Shift // Shift
for (int i=0;i<nrows;i++) { for (int i=0;i<nrows;i++) {
if (allrows || (i >= firstSel && selOnward) || context->subsGrid->IsInSelection(i,0)) { if (allrows || (i >= firstSel && selOnward) || context->subsGrid->IsInSelection(i)) {
if (byTime) context->subsGrid->ShiftLineByTime(i,len,type); if (byTime) context->subsGrid->ShiftLineByTime(i,len,type);
else context->subsGrid->ShiftLineByFrames(i,len,type); else context->subsGrid->ShiftLineByFrames(i,len,type);
didSomething = true; didSomething = true;

View file

@ -680,11 +680,10 @@ void SubtitlesGrid::SetVideoToSubs(bool start) {
/// @return /// @return
/// ///
std::vector<int> SubtitlesGrid::GetAbsoluteSelection() { std::vector<int> SubtitlesGrid::GetAbsoluteSelection() {
std::vector<int> result; Selection sel = GetSelectedSet();
result.reserve(GetNumberSelection());
Selection sel; std::vector<int> result;
GetSelectedSet(sel); result.reserve(sel.size());
int line_index = 0; int line_index = 0;
for (entryIter it = context->ass->Line.begin(); it != context->ass->Line.end(); ++it, ++line_index) { for (entryIter it = context->ass->Line.begin(); it != context->ass->Line.end(); ++it, ++line_index) {