2006-02-18 22:55:58 +01:00
|
|
|
// Copyright (c) 2006, Rodrigo Braz Monteiro
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file base_grid.cpp
|
|
|
|
/// @brief Base for subtitle grid in main UI
|
|
|
|
/// @ingroup main_ui
|
|
|
|
///
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2010-07-20 05:11:11 +02:00
|
|
|
#include "base_grid.h"
|
|
|
|
|
2011-01-16 08:17:36 +01:00
|
|
|
#include "include/aegisub/context.h"
|
|
|
|
#include "include/aegisub/hotkey.h"
|
2011-11-08 01:24:41 +01:00
|
|
|
#include "include/aegisub/menu.h"
|
2011-01-16 08:17:36 +01:00
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
#include "ass_dialogue.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "ass_file.h"
|
2006-02-18 22:55:58 +01:00
|
|
|
#include "ass_style.h"
|
2012-02-08 00:17:26 +01:00
|
|
|
#include "audio_box.h"
|
2010-05-21 03:13:36 +02:00
|
|
|
#include "compat.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "frame_main.h"
|
2013-01-07 02:50:09 +01:00
|
|
|
#include "options.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "utils.h"
|
2014-03-25 01:15:14 +01:00
|
|
|
#include "selection_controller.h"
|
2013-01-26 02:57:46 +01:00
|
|
|
#include "subs_controller.h"
|
2007-01-21 18:01:22 +01:00
|
|
|
#include "video_context.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "video_slider.h"
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2013-09-16 19:43:21 +02:00
|
|
|
#include <algorithm>
|
2013-09-16 21:02:17 +02:00
|
|
|
#include <boost/range/algorithm.hpp>
|
2013-09-16 19:43:21 +02:00
|
|
|
#include <cmath>
|
|
|
|
#include <iterator>
|
|
|
|
#include <numeric>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
#include <wx/dcbuffer.h>
|
|
|
|
#include <wx/kbdstate.h>
|
|
|
|
#include <wx/menu.h>
|
2013-09-16 21:02:17 +02:00
|
|
|
#include <wx/scrolbar.h>
|
2013-09-16 19:43:21 +02:00
|
|
|
#include <wx/sizer.h>
|
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
enum {
|
2011-11-08 01:24:41 +01:00
|
|
|
GRID_SCROLLBAR = 1730,
|
|
|
|
MENU_SHOW_COL = 1250 // Needs 15 IDs after this
|
2011-07-15 06:05:43 +02:00
|
|
|
};
|
|
|
|
|
2011-11-08 01:24:53 +01:00
|
|
|
enum RowColor {
|
|
|
|
COLOR_DEFAULT = 0,
|
|
|
|
COLOR_HEADER,
|
|
|
|
COLOR_SELECTION,
|
|
|
|
COLOR_COMMENT,
|
|
|
|
COLOR_VISIBLE,
|
2012-01-31 01:43:15 +01:00
|
|
|
COLOR_SELECTED_COMMENT,
|
|
|
|
COLOR_LEFT_COL
|
2011-11-08 01:24:53 +01:00
|
|
|
};
|
|
|
|
|
2013-09-16 19:43:21 +02:00
|
|
|
namespace std {
|
|
|
|
template <typename T>
|
|
|
|
struct hash<boost::flyweight<T>> {
|
|
|
|
size_t operator()(boost::flyweight<T> const& ss) const {
|
|
|
|
return hash<const void*>()(&ss.get());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-03-25 01:15:14 +01:00
|
|
|
BaseGrid::BaseGrid(wxWindow* parent, agi::Context *context)
|
|
|
|
: wxWindow(parent, -1, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS | wxSUNKEN_BORDER)
|
2011-07-16 07:01:36 +02:00
|
|
|
, scrollBar(new wxScrollBar(this, GRID_SCROLLBAR, wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL))
|
2012-11-13 17:51:01 +01:00
|
|
|
, seek_listener(context->videoController->AddSeekListener(std::bind(&BaseGrid::Refresh, this, false, nullptr)))
|
2011-12-22 22:09:31 +01:00
|
|
|
, context(context)
|
2006-02-18 22:55:58 +01:00
|
|
|
{
|
2007-01-04 00:29:03 +01:00
|
|
|
scrollBar->SetScrollbar(0,10,100,10);
|
|
|
|
|
2013-11-21 18:13:36 +01:00
|
|
|
auto scrollbarpositioner = new wxBoxSizer(wxHORIZONTAL);
|
2009-07-27 01:24:21 +02:00
|
|
|
scrollbarpositioner->AddStretchSpacer();
|
|
|
|
scrollbarpositioner->Add(scrollBar, 0, wxEXPAND, 0);
|
|
|
|
|
|
|
|
SetSizerAndFit(scrollbarpositioner);
|
|
|
|
|
2012-01-31 01:42:58 +01:00
|
|
|
SetBackgroundStyle(wxBG_STYLE_PAINT);
|
|
|
|
|
2007-01-04 00:29:03 +01:00
|
|
|
UpdateStyle();
|
2011-11-08 01:24:41 +01:00
|
|
|
OnHighlightVisibleChange(*OPT_GET("Subtitle/Grid/Highlight Subtitles in Frame"));
|
2010-08-26 20:38:37 +02:00
|
|
|
|
2014-03-25 01:15:14 +01:00
|
|
|
connections.push_back(context->ass->AddCommitListener(&BaseGrid::OnSubtitlesCommit, this));
|
|
|
|
connections.push_back(context->subsController->AddFileOpenListener(&BaseGrid::OnSubtitlesOpen, this));
|
|
|
|
connections.push_back(context->subsController->AddFileSaveListener(&BaseGrid::OnSubtitlesSave, this));
|
|
|
|
|
|
|
|
connections.push_back(context->selectionController->AddActiveLineListener(&BaseGrid::OnActiveLineChanged, this));
|
|
|
|
connections.push_back(context->selectionController->AddSelectionListener([&]{ Refresh(false); }));
|
|
|
|
|
|
|
|
connections.push_back(OPT_SUB("Subtitle/Grid/Font Face", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Subtitle/Grid/Font Size", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Active Border", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Background/Background", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Background/Comment", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Background/Inframe", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Background/Selected Comment", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Background/Selection", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Collision", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Header", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Left Column", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Lines", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Selection", &BaseGrid::UpdateStyle, this));
|
|
|
|
connections.push_back(OPT_SUB("Colour/Subtitle Grid/Standard", &BaseGrid::UpdateStyle, this));
|
|
|
|
|
|
|
|
connections.push_back(OPT_SUB("Subtitle/Grid/Highlight Subtitles in Frame", &BaseGrid::OnHighlightVisibleChange, this));
|
|
|
|
connections.push_back(OPT_SUB("Subtitle/Grid/Hide Overrides", [&](agi::OptionValue const&) { Refresh(false); }));
|
2011-08-31 06:17:37 +02:00
|
|
|
|
|
|
|
Bind(wxEVT_CONTEXT_MENU, &BaseGrid::OnContextMenu, this);
|
2007-01-04 00:29:03 +01:00
|
|
|
}
|
|
|
|
|
2014-03-05 02:36:02 +01:00
|
|
|
BaseGrid::~BaseGrid() { }
|
2011-11-08 01:24:41 +01:00
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(BaseGrid,wxWindow)
|
|
|
|
EVT_PAINT(BaseGrid::OnPaint)
|
|
|
|
EVT_SIZE(BaseGrid::OnSize)
|
|
|
|
EVT_COMMAND_SCROLL(GRID_SCROLLBAR,BaseGrid::OnScroll)
|
|
|
|
EVT_MOUSE_EVENTS(BaseGrid::OnMouseEvent)
|
|
|
|
EVT_KEY_DOWN(BaseGrid::OnKeyDown)
|
2012-04-27 21:07:49 +02:00
|
|
|
EVT_CHAR_HOOK(BaseGrid::OnCharHook)
|
2011-11-08 01:24:41 +01:00
|
|
|
EVT_MENU_RANGE(MENU_SHOW_COL,MENU_SHOW_COL+15,BaseGrid::OnShowColMenu)
|
2011-12-28 22:27:06 +01:00
|
|
|
END_EVENT_TABLE()
|
2011-11-08 01:24:41 +01:00
|
|
|
|
|
|
|
void BaseGrid::OnSubtitlesCommit(int type) {
|
2014-03-05 02:36:02 +01:00
|
|
|
if (type == AssFile::COMMIT_NEW || type & AssFile::COMMIT_ORDER || type & AssFile::COMMIT_DIAG_ADDREM)
|
|
|
|
UpdateMaps();
|
2011-11-08 01:24:41 +01:00
|
|
|
|
|
|
|
if (type & AssFile::COMMIT_DIAG_META) {
|
|
|
|
SetColumnWidths();
|
|
|
|
Refresh(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (type & AssFile::COMMIT_DIAG_TIME)
|
2012-01-26 23:27:57 +01:00
|
|
|
Refresh(false);
|
|
|
|
else if (type & AssFile::COMMIT_DIAG_TEXT)
|
2011-11-08 01:24:41 +01:00
|
|
|
RefreshRect(wxRect(text_col_x, 0, text_col_w, GetClientSize().GetHeight()), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::OnSubtitlesOpen() {
|
2013-10-08 02:42:09 +02:00
|
|
|
ScrollTo(context->ass->GetUIStateAsInt("Scroll Position"));
|
2011-11-08 01:24:41 +01:00
|
|
|
}
|
|
|
|
|
2012-01-25 20:07:36 +01:00
|
|
|
void BaseGrid::OnSubtitlesSave() {
|
2013-10-08 02:42:09 +02:00
|
|
|
context->ass->SaveUIState("Scroll Position", std::to_string(yPos));
|
2012-01-25 20:07:36 +01:00
|
|
|
}
|
|
|
|
|
2011-11-08 01:24:41 +01:00
|
|
|
void BaseGrid::OnShowColMenu(wxCommandEvent &event) {
|
|
|
|
int item = event.GetId() - MENU_SHOW_COL;
|
|
|
|
showCol[item] = !showCol[item];
|
|
|
|
|
2014-03-31 18:24:56 +02:00
|
|
|
OPT_SET("Subtitle/Grid/Column")->SetListBool(std::vector<bool>(std::begin(showCol), std::end(showCol)));
|
2011-11-08 01:24:41 +01:00
|
|
|
|
|
|
|
SetColumnWidths();
|
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::OnHighlightVisibleChange(agi::OptionValue const& opt) {
|
2013-09-16 21:02:17 +02:00
|
|
|
if (opt.GetBool())
|
2011-11-08 01:24:41 +01:00
|
|
|
seek_listener.Unblock();
|
2013-09-16 21:02:17 +02:00
|
|
|
else
|
2011-11-08 01:24:41 +01:00
|
|
|
seek_listener.Block();
|
2007-01-04 00:29:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::UpdateStyle() {
|
2013-12-10 18:08:30 +01:00
|
|
|
wxString fontname = FontFace("Subtitle/Grid");
|
2011-07-15 06:05:43 +02:00
|
|
|
if (fontname.empty()) fontname = "Tahoma";
|
2006-02-18 22:55:58 +01:00
|
|
|
font.SetFaceName(fontname);
|
2010-05-21 03:13:36 +02:00
|
|
|
font.SetPointSize(OPT_GET("Subtitle/Grid/Font Size")->GetInt());
|
2006-02-18 22:55:58 +01:00
|
|
|
font.SetWeight(wxFONTWEIGHT_NORMAL);
|
|
|
|
|
|
|
|
// Set line height
|
|
|
|
{
|
|
|
|
wxClientDC dc(this);
|
|
|
|
dc.SetFont(font);
|
|
|
|
int fw,fh;
|
2012-11-13 17:51:01 +01:00
|
|
|
dc.GetTextExtent("#TWFfgGhH", &fw, &fh, nullptr, nullptr, &font);
|
2011-07-15 06:05:43 +02:00
|
|
|
lineHeight = fh + 4;
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
2012-01-31 01:43:15 +01:00
|
|
|
// Set row brushes
|
|
|
|
assert(sizeof(rowColors) / sizeof(rowColors[0]) >= COLOR_LEFT_COL);
|
2012-10-26 16:09:14 +02:00
|
|
|
rowColors[COLOR_DEFAULT].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Background")->GetColor()));
|
|
|
|
rowColors[COLOR_HEADER].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Header")->GetColor()));
|
|
|
|
rowColors[COLOR_SELECTION].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Selection")->GetColor()));
|
|
|
|
rowColors[COLOR_COMMENT].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Comment")->GetColor()));
|
|
|
|
rowColors[COLOR_VISIBLE].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Inframe")->GetColor()));
|
|
|
|
rowColors[COLOR_SELECTED_COMMENT].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Background/Selected Comment")->GetColor()));
|
|
|
|
rowColors[COLOR_LEFT_COL].SetColour(to_wx(OPT_GET("Colour/Subtitle Grid/Left Column")->GetColor()));
|
2012-01-31 01:43:15 +01:00
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
// Set column widths
|
2011-11-04 20:42:31 +01:00
|
|
|
std::vector<bool> column_array(OPT_GET("Subtitle/Grid/Column")->GetListBool());
|
2013-09-16 21:02:17 +02:00
|
|
|
assert(column_array.size() == boost::size(showCol));
|
|
|
|
boost::copy(column_array, std::begin(showCol));
|
2006-02-18 22:55:58 +01:00
|
|
|
SetColumnWidths();
|
|
|
|
|
2007-01-04 00:29:03 +01:00
|
|
|
AdjustScrollbar();
|
2013-09-16 21:02:17 +02:00
|
|
|
Refresh(false);
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
2014-03-05 02:36:02 +01:00
|
|
|
void BaseGrid::UpdateMaps() {
|
2010-07-13 07:29:08 +02:00
|
|
|
index_line_map.clear();
|
|
|
|
|
2014-03-31 16:41:57 +02:00
|
|
|
for (auto& curdiag : context->ass->Events)
|
2014-03-07 19:58:51 +01:00
|
|
|
index_line_map.push_back(&curdiag);
|
2010-07-13 07:29:08 +02:00
|
|
|
|
2011-10-23 19:00:26 +02:00
|
|
|
SetColumnWidths();
|
2014-03-28 02:49:16 +01:00
|
|
|
AdjustScrollbar();
|
2010-07-13 07:29:08 +02:00
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
|
2014-03-25 01:15:14 +01:00
|
|
|
void BaseGrid::OnActiveLineChanged(AssDialogue *new_active) {
|
|
|
|
if (new_active) {
|
2014-03-31 16:41:57 +02:00
|
|
|
int row = new_active->Row;
|
2014-03-25 01:15:14 +01:00
|
|
|
MakeRowVisible(row);
|
|
|
|
extendRow = row;
|
|
|
|
Refresh(false);
|
2010-06-26 17:40:10 +02:00
|
|
|
}
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
2013-09-16 21:02:17 +02:00
|
|
|
void BaseGrid::MakeRowVisible(int row) {
|
2012-05-04 04:52:52 +02:00
|
|
|
int h = GetClientSize().GetHeight();
|
2006-02-19 00:00:09 +01:00
|
|
|
|
2013-09-16 21:02:17 +02:00
|
|
|
if (row < yPos + 1)
|
|
|
|
ScrollTo(row - 1);
|
|
|
|
else if (row > yPos + h/lineHeight - 3)
|
|
|
|
ScrollTo(row - h/lineHeight + 3);
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
2006-02-22 06:30:09 +01:00
|
|
|
void BaseGrid::SelectRow(int row, bool addToSelected, bool select) {
|
2010-06-26 09:26:27 +02:00
|
|
|
if (row < 0 || (size_t)row >= index_line_map.size()) return;
|
|
|
|
|
|
|
|
AssDialogue *line = index_line_map[row];
|
Remove the SelectionChangeSubscriber mechanism from the grid and implement some basic selection change notification through SelectionController.
Change SelectionListener interface so it receives the set of lines added and removed from selection, instead of just the complete new selection.
Update VisualTool<> to use SelectionListener to receive selection change notifications.
This change (temporarily, I hope) breaks feature selection in visual drag mode, when changing selection via the grid. This is caused by the grid selection change first clearing the entire selection, which sends a separate notification about selection clear. This causes the last visual feature to be deselected, and then the visual tool base reselects the active line, causing a new notification for selection to be sent. The active line happens to be the newly clicked line, and the selection notification enters during the externalChange guard being set, and is then ignored for feature update purposes. When control returns to the original SelectRow call in the grid, the line to be selected has already been selected and then nothing happens.
The best fix is to avoid two notifications being required to deselect all then reselect one line in the first place, so making the grid selection handling saner is the best fix.
Originally committed to SVN as r4602.
2010-06-26 06:38:02 +02:00
|
|
|
|
|
|
|
if (!addToSelected) {
|
2014-03-25 01:15:14 +01:00
|
|
|
context->selectionController->SetSelectedSet(Selection{line});
|
2011-07-15 06:05:43 +02:00
|
|
|
return;
|
Remove the SelectionChangeSubscriber mechanism from the grid and implement some basic selection change notification through SelectionController.
Change SelectionListener interface so it receives the set of lines added and removed from selection, instead of just the complete new selection.
Update VisualTool<> to use SelectionListener to receive selection change notifications.
This change (temporarily, I hope) breaks feature selection in visual drag mode, when changing selection via the grid. This is caused by the grid selection change first clearing the entire selection, which sends a separate notification about selection clear. This causes the last visual feature to be deselected, and then the visual tool base reselects the active line, causing a new notification for selection to be sent. The active line happens to be the newly clicked line, and the selection notification enters during the externalChange guard being set, and is then ignored for feature update purposes. When control returns to the original SelectRow call in the grid, the line to be selected has already been selected and then nothing happens.
The best fix is to avoid two notifications being required to deselect all then reselect one line in the first place, so making the grid selection handling saner is the best fix.
Originally committed to SVN as r4602.
2010-06-26 06:38:02 +02:00
|
|
|
}
|
2010-05-26 09:17:34 +02:00
|
|
|
|
2014-03-25 01:15:14 +01:00
|
|
|
bool selected = !!context->selectionController->GetSelectedSet().count(line);
|
|
|
|
if (select != selected) {
|
|
|
|
auto selection = context->selectionController->GetSelectedSet();
|
|
|
|
if (select)
|
|
|
|
selection.insert(line);
|
|
|
|
else
|
|
|
|
selection.erase(line);
|
|
|
|
context->selectionController->SetSelectedSet(std::move(selection));
|
2006-02-22 06:30:09 +01:00
|
|
|
}
|
2011-07-15 06:05:43 +02:00
|
|
|
}
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2011-12-22 22:09:31 +01:00
|
|
|
void BaseGrid::OnPaint(wxPaintEvent &) {
|
2011-07-15 06:05:43 +02:00
|
|
|
// Get size and pos
|
2011-11-08 01:24:53 +01:00
|
|
|
wxSize cs = GetClientSize();
|
|
|
|
cs.SetWidth(cs.GetWidth() - scrollBar->GetSize().GetWidth());
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-08-27 08:52:42 +02:00
|
|
|
// Find which columns need to be repainted
|
2013-09-16 21:02:17 +02:00
|
|
|
bool paint_columns[11] = {0};
|
|
|
|
for (wxRegionIterator region(GetUpdateRegion()); region; ++region) {
|
2011-08-27 08:52:42 +02:00
|
|
|
wxRect updrect = region.GetRect();
|
|
|
|
int x = 0;
|
|
|
|
for (size_t i = 0; i < 11; ++i) {
|
2012-01-31 01:43:06 +01:00
|
|
|
if (updrect.x < x + colWidth[i] && updrect.x + updrect.width > x && colWidth[i])
|
2011-08-27 08:52:42 +02:00
|
|
|
paint_columns[i] = true;
|
|
|
|
x += colWidth[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-31 01:42:58 +01:00
|
|
|
wxAutoBufferedPaintDC dc(this);
|
|
|
|
DrawImage(dc, paint_columns);
|
2011-07-15 06:05:43 +02:00
|
|
|
}
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2011-08-27 08:52:42 +02:00
|
|
|
void BaseGrid::DrawImage(wxDC &dc, bool paint_columns[]) {
|
2006-02-18 22:55:58 +01:00
|
|
|
int w = 0;
|
|
|
|
int h = 0;
|
|
|
|
GetClientSize(&w,&h);
|
2007-04-08 08:01:41 +02:00
|
|
|
w -= scrollBar->GetSize().GetWidth();
|
2006-02-18 22:55:58 +01:00
|
|
|
|
|
|
|
dc.SetFont(font);
|
|
|
|
|
2012-01-31 01:43:15 +01:00
|
|
|
dc.SetBackground(rowColors[COLOR_DEFAULT]);
|
2006-02-18 22:55:58 +01:00
|
|
|
dc.Clear();
|
|
|
|
|
|
|
|
// Draw labels
|
|
|
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
2012-01-31 01:43:15 +01:00
|
|
|
dc.SetBrush(rowColors[COLOR_LEFT_COL]);
|
2006-02-18 22:55:58 +01:00
|
|
|
dc.DrawRectangle(0,lineHeight,colWidth[0],h-lineHeight);
|
|
|
|
|
|
|
|
// Visible lines
|
|
|
|
int drawPerScreen = h/lineHeight + 1;
|
2010-12-31 22:03:03 +01:00
|
|
|
int nDraw = mid(0,drawPerScreen,GetRows()-yPos);
|
2006-02-18 22:55:58 +01:00
|
|
|
int maxH = (nDraw+1) * lineHeight;
|
|
|
|
|
|
|
|
// Row colors
|
2012-10-26 16:09:14 +02:00
|
|
|
wxColour text_standard(to_wx(OPT_GET("Colour/Subtitle Grid/Standard")->GetColor()));
|
|
|
|
wxColour text_selection(to_wx(OPT_GET("Colour/Subtitle Grid/Selection")->GetColor()));
|
|
|
|
wxColour text_collision(to_wx(OPT_GET("Colour/Subtitle Grid/Collision")->GetColor()));
|
2011-07-15 06:05:43 +02:00
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
// First grid row
|
2012-10-26 16:09:14 +02:00
|
|
|
wxPen grid_pen(to_wx(OPT_GET("Colour/Subtitle Grid/Lines")->GetColor()));
|
2011-07-15 06:05:43 +02:00
|
|
|
dc.SetPen(grid_pen);
|
|
|
|
dc.DrawLine(0, 0, w, 0);
|
|
|
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-11-08 01:24:53 +01:00
|
|
|
wxString strings[] = {
|
|
|
|
_("#"), _("L"), _("Start"), _("End"), _("Style"), _("Actor"),
|
|
|
|
_("Effect"), _("Left"), _("Right"), _("Vert"), _("Text")
|
2011-08-27 08:52:42 +02:00
|
|
|
};
|
|
|
|
|
2012-01-31 01:43:32 +01:00
|
|
|
int override_mode = OPT_GET("Subtitle/Grid/Hide Overrides")->GetInt();
|
|
|
|
wxString replace_char;
|
|
|
|
if (override_mode == 1)
|
2012-12-23 00:18:38 +01:00
|
|
|
replace_char = to_wx(OPT_GET("Subtitle/Grid/Hide Overrides Char")->GetString());
|
2012-01-31 01:43:32 +01:00
|
|
|
|
2014-03-25 01:15:14 +01:00
|
|
|
auto active_line = context->selectionController->GetActiveLine();
|
|
|
|
auto const& selection = context->selectionController->GetSelectedSet();
|
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
for (int i = 0; i < nDraw + 1; i++) {
|
|
|
|
int curRow = i + yPos - 1;
|
2011-11-08 01:24:53 +01:00
|
|
|
RowColor curColor = COLOR_DEFAULT;
|
2014-03-25 01:15:14 +01:00
|
|
|
AssDialogue *curDiag = nullptr;
|
2006-02-20 23:54:23 +01:00
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
// Header
|
|
|
|
if (i == 0) {
|
2011-11-08 01:24:53 +01:00
|
|
|
curColor = COLOR_HEADER;
|
2011-07-15 06:05:43 +02:00
|
|
|
dc.SetTextForeground(text_standard);
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
// Lines
|
2014-03-25 01:15:14 +01:00
|
|
|
else if ((curDiag = GetDialogue(curRow))) {
|
2012-01-31 01:43:32 +01:00
|
|
|
GetRowStrings(curRow, curDiag, paint_columns, strings, !!override_mode, replace_char);
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-09-15 07:17:36 +02:00
|
|
|
bool inSel = !!selection.count(curDiag);
|
2011-11-08 01:24:53 +01:00
|
|
|
if (inSel && curDiag->Comment)
|
|
|
|
curColor = COLOR_SELECTED_COMMENT;
|
|
|
|
else if (inSel)
|
|
|
|
curColor = COLOR_SELECTION;
|
|
|
|
else if (curDiag->Comment)
|
|
|
|
curColor = COLOR_COMMENT;
|
|
|
|
else if (OPT_GET("Subtitle/Grid/Highlight Subtitles in Frame")->GetBool() && IsDisplayed(curDiag))
|
|
|
|
curColor = COLOR_VISIBLE;
|
|
|
|
else
|
|
|
|
curColor = COLOR_DEFAULT;
|
|
|
|
|
|
|
|
if (active_line != curDiag && curDiag->CollidesWith(active_line))
|
2011-07-15 06:05:43 +02:00
|
|
|
dc.SetTextForeground(text_collision);
|
2011-11-08 01:24:53 +01:00
|
|
|
else if (inSel)
|
2011-07-15 06:05:43 +02:00
|
|
|
dc.SetTextForeground(text_selection);
|
2011-11-08 01:24:53 +01:00
|
|
|
else
|
2011-07-15 06:05:43 +02:00
|
|
|
dc.SetTextForeground(text_standard);
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-08-27 08:52:42 +02:00
|
|
|
assert(false);
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw row background color
|
|
|
|
if (curColor) {
|
|
|
|
dc.SetBrush(rowColors[curColor]);
|
|
|
|
dc.DrawRectangle((curColor == 1) ? 0 : colWidth[0],i*lineHeight+1,w,lineHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw text
|
2010-11-08 03:52:54 +01:00
|
|
|
int dx = 0;
|
|
|
|
int dy = i*lineHeight;
|
2011-07-15 06:05:43 +02:00
|
|
|
for (int j = 0; j < 11; j++) {
|
2006-06-27 07:13:41 +02:00
|
|
|
if (colWidth[j] == 0) continue;
|
|
|
|
|
2011-08-27 08:52:42 +02:00
|
|
|
if (paint_columns[j]) {
|
|
|
|
wxSize ext = dc.GetTextExtent(strings[j]);
|
|
|
|
|
|
|
|
int left = dx + 4;
|
|
|
|
int top = dy + (lineHeight - ext.GetHeight()) / 2;
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-08-27 08:52:42 +02:00
|
|
|
// Centered columns
|
|
|
|
if (!(j == 4 || j == 5 || j == 6 || j == 10)) {
|
|
|
|
left += (colWidth[j] - 6 - ext.GetWidth()) / 2;
|
|
|
|
}
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-08-27 08:52:42 +02:00
|
|
|
dc.DrawText(strings[j], left, top);
|
|
|
|
}
|
2006-02-18 22:55:58 +01:00
|
|
|
dx += colWidth[j];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw grid
|
|
|
|
dc.DestroyClippingRegion();
|
2014-03-25 01:15:14 +01:00
|
|
|
if (curDiag == active_line) {
|
|
|
|
dc.SetPen(wxPen(to_wx(OPT_GET("Colour/Subtitle Grid/Active Border")->GetColor())));
|
|
|
|
dc.SetBrush(*wxTRANSPARENT_BRUSH);
|
|
|
|
dc.DrawRectangle(0, dy, w, lineHeight + 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dc.SetPen(grid_pen);
|
|
|
|
dc.DrawLine(0, dy + lineHeight, w , dy + lineHeight);
|
|
|
|
}
|
2011-07-15 06:05:43 +02:00
|
|
|
dc.SetPen(*wxTRANSPARENT_PEN);
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw grid columns
|
2011-07-15 06:05:43 +02:00
|
|
|
int dx = 0;
|
2012-01-31 01:43:15 +01:00
|
|
|
dc.SetPen(grid_pen);
|
2014-03-25 01:15:14 +01:00
|
|
|
for (int i = 0; i < 10; ++i) {
|
2011-07-15 06:05:43 +02:00
|
|
|
dx += colWidth[i];
|
2014-03-25 01:15:14 +01:00
|
|
|
dc.DrawLine(dx, 0, dx, maxH);
|
2010-06-26 13:32:16 +02:00
|
|
|
}
|
2014-03-25 01:15:14 +01:00
|
|
|
dc.DrawLine(0, 0, 0, maxH);
|
|
|
|
dc.DrawLine(w-1, 0, w-1, maxH);
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
2012-01-31 01:43:32 +01:00
|
|
|
void BaseGrid::GetRowStrings(int row, AssDialogue *line, bool *paint_columns, wxString *strings, bool replace, wxString const& rep_char) const {
|
2013-09-18 17:31:26 +02:00
|
|
|
if (paint_columns[0]) strings[0] = std::to_wstring(row + 1);
|
|
|
|
if (paint_columns[1]) strings[1] = std::to_wstring(line->Layer);
|
2011-11-08 01:24:53 +01:00
|
|
|
if (byFrame) {
|
2013-09-18 17:31:26 +02:00
|
|
|
if (paint_columns[2]) strings[2] = std::to_wstring(context->videoController->FrameAtTime(line->Start, agi::vfr::START));
|
|
|
|
if (paint_columns[3]) strings[3] = std::to_wstring(context->videoController->FrameAtTime(line->End, agi::vfr::END));
|
2011-11-08 01:24:53 +01:00
|
|
|
}
|
|
|
|
else {
|
2013-01-04 16:01:50 +01:00
|
|
|
if (paint_columns[2]) strings[2] = to_wx(line->Start.GetAssFormated());
|
|
|
|
if (paint_columns[3]) strings[3] = to_wx(line->End.GetAssFormated());
|
2011-11-08 01:24:53 +01:00
|
|
|
}
|
2013-01-04 16:01:50 +01:00
|
|
|
if (paint_columns[4]) strings[4] = to_wx(line->Style);
|
|
|
|
if (paint_columns[5]) strings[5] = to_wx(line->Actor);
|
|
|
|
if (paint_columns[6]) strings[6] = to_wx(line->Effect);
|
2014-01-05 17:10:08 +01:00
|
|
|
if (paint_columns[7]) strings[7] = line->Margin[0] ? wxString(std::to_wstring(line->Margin[0])) : wxString();
|
|
|
|
if (paint_columns[8]) strings[8] = line->Margin[1] ? wxString(std::to_wstring(line->Margin[1])) : wxString();
|
|
|
|
if (paint_columns[9]) strings[9] = line->Margin[2] ? wxString(std::to_wstring(line->Margin[2])) : wxString();
|
2011-11-08 01:24:53 +01:00
|
|
|
|
|
|
|
if (paint_columns[10]) {
|
|
|
|
strings[10].clear();
|
|
|
|
|
2013-09-16 21:02:17 +02:00
|
|
|
// Show overrides
|
|
|
|
if (!replace)
|
|
|
|
strings[10] = to_wx(line->Text);
|
2011-11-08 01:24:53 +01:00
|
|
|
// Hidden overrides
|
2013-09-16 21:02:17 +02:00
|
|
|
else {
|
2012-12-04 23:35:59 +01:00
|
|
|
strings[10].reserve(line->Text.get().size());
|
2011-11-08 01:24:53 +01:00
|
|
|
size_t start = 0, pos;
|
2013-01-04 16:01:50 +01:00
|
|
|
while ((pos = line->Text.get().find('{', start)) != std::string::npos) {
|
|
|
|
strings[10] += to_wx(line->Text.get().substr(start, pos - start));
|
2012-01-31 01:43:32 +01:00
|
|
|
strings[10] += rep_char;
|
2012-12-04 23:35:59 +01:00
|
|
|
start = line->Text.get().find('}', pos);
|
2013-01-04 16:01:50 +01:00
|
|
|
if (start != std::string::npos) ++start;
|
2011-11-08 01:24:53 +01:00
|
|
|
}
|
2013-01-04 16:01:50 +01:00
|
|
|
if (start != std::string::npos)
|
|
|
|
strings[10] += to_wx(line->Text.get().substr(start));
|
2011-11-08 01:24:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cap length and set text
|
|
|
|
if (strings[10].size() > 512)
|
|
|
|
strings[10] = strings[10].Left(512) + "...";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-22 22:09:31 +01:00
|
|
|
void BaseGrid::OnSize(wxSizeEvent &) {
|
2006-02-18 22:55:58 +01:00
|
|
|
AdjustScrollbar();
|
2013-09-16 19:26:41 +02:00
|
|
|
|
|
|
|
int w, h;
|
|
|
|
GetClientSize(&w, &h);
|
|
|
|
colWidth[10] = text_col_w = w - text_col_x;
|
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::OnScroll(wxScrollEvent &event) {
|
|
|
|
int newPos = event.GetPosition();
|
|
|
|
if (yPos != newPos) {
|
|
|
|
yPos = newPos;
|
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
|
2012-05-04 04:52:52 +02:00
|
|
|
int h = GetClientSize().GetHeight();
|
2011-10-01 20:35:00 +02:00
|
|
|
bool shift = event.ShiftDown();
|
|
|
|
bool alt = event.AltDown();
|
|
|
|
bool ctrl = event.CmdDown();
|
2006-02-18 22:55:58 +01:00
|
|
|
|
|
|
|
// Row that mouse is over
|
2011-08-31 06:17:37 +02:00
|
|
|
bool click = event.LeftDown();
|
2006-03-01 05:32:00 +01:00
|
|
|
bool dclick = event.LeftDClick();
|
2012-05-04 04:52:52 +02:00
|
|
|
int row = event.GetY() / lineHeight + yPos - 1;
|
2013-09-16 21:02:17 +02:00
|
|
|
if (holding && !click)
|
|
|
|
row = mid(0, row, GetRows()-1);
|
2010-06-26 13:32:16 +02:00
|
|
|
AssDialogue *dlg = GetDialogue(row);
|
|
|
|
if (!dlg) row = 0;
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2012-05-04 04:52:52 +02:00
|
|
|
if (event.ButtonDown() && OPT_GET("Subtitle/Grid/Focus Allow")->GetBool())
|
|
|
|
SetFocus();
|
2006-02-22 03:25:45 +01:00
|
|
|
|
2006-02-18 23:44:12 +01:00
|
|
|
if (holding) {
|
2012-05-04 04:52:52 +02:00
|
|
|
if (!event.LeftIsDown()) {
|
|
|
|
if (dlg)
|
2013-09-16 21:02:17 +02:00
|
|
|
MakeRowVisible(row);
|
2012-05-04 04:52:52 +02:00
|
|
|
holding = false;
|
|
|
|
ReleaseMouse();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Only scroll if the mouse has moved to a different row to avoid
|
|
|
|
// scrolling on sloppy clicks
|
|
|
|
if (row != extendRow) {
|
|
|
|
if (row <= yPos)
|
|
|
|
ScrollTo(yPos - 3);
|
|
|
|
// When dragging down we give a 3 row margin to make it easier
|
|
|
|
// to see what's going on, but we don't want to scroll down if
|
|
|
|
// the user clicks on the bottom row and drags up
|
|
|
|
else if (row > yPos + h / lineHeight - (row > extendRow ? 3 : 1))
|
|
|
|
ScrollTo(yPos + 3);
|
2006-06-21 01:32:01 +02:00
|
|
|
}
|
|
|
|
}
|
2006-02-18 23:44:12 +01:00
|
|
|
}
|
2012-05-04 04:52:52 +02:00
|
|
|
else if (click && dlg) {
|
|
|
|
holding = true;
|
|
|
|
CaptureMouse();
|
|
|
|
}
|
2006-02-18 23:44:12 +01:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
if ((click || holding || dclick) && dlg) {
|
2012-01-25 05:59:17 +01:00
|
|
|
int old_extend = extendRow;
|
2012-05-04 04:52:52 +02:00
|
|
|
|
|
|
|
// SetActiveLine will scroll the grid if the row is only half-visible,
|
|
|
|
// but we don't want to scroll until the mouse moves or the button is
|
|
|
|
// released, to avoid selecting multiple lines on a click
|
|
|
|
int old_y_pos = yPos;
|
2014-03-25 01:15:14 +01:00
|
|
|
context->selectionController->SetActiveLine(dlg);
|
2012-05-04 04:52:52 +02:00
|
|
|
ScrollTo(old_y_pos);
|
2014-03-25 01:15:14 +01:00
|
|
|
extendRow = row;
|
|
|
|
|
|
|
|
auto const& selection = context->selectionController->GetSelectedSet();
|
2012-01-25 05:59:17 +01:00
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
// Toggle selected
|
2006-02-22 00:27:34 +01:00
|
|
|
if (click && ctrl && !shift && !alt) {
|
2011-09-15 07:17:36 +02:00
|
|
|
bool isSel = !!selection.count(dlg);
|
2010-06-27 06:55:19 +02:00
|
|
|
if (isSel && selection.size() == 1) return;
|
2012-01-25 05:59:17 +01:00
|
|
|
SelectRow(row, true, !isSel);
|
2006-02-18 23:09:03 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Normal click
|
2006-03-01 05:32:00 +01:00
|
|
|
if ((click || dclick) && !shift && !ctrl && !alt) {
|
2012-02-08 00:17:26 +01:00
|
|
|
if (dclick) {
|
|
|
|
context->audioBox->ScrollToActiveLine();
|
|
|
|
context->videoController->JumpToTime(dlg->Start);
|
|
|
|
}
|
2012-01-25 05:59:17 +01:00
|
|
|
SelectRow(row, false);
|
2006-02-18 23:09:03 +01:00
|
|
|
return;
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
2012-01-25 05:59:17 +01:00
|
|
|
// Change active line only
|
2012-05-04 04:52:52 +02:00
|
|
|
if (click && !shift && !ctrl && alt)
|
2010-06-28 09:12:36 +02:00
|
|
|
return;
|
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
// Block select
|
2012-05-04 04:52:58 +02:00
|
|
|
if ((click && shift && !alt) || holding) {
|
2012-01-25 05:59:17 +01:00
|
|
|
extendRow = old_extend;
|
|
|
|
int i1 = row;
|
|
|
|
int i2 = extendRow;
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2012-01-25 05:59:17 +01:00
|
|
|
if (i1 > i2)
|
|
|
|
std::swap(i1, i2);
|
|
|
|
|
|
|
|
// Toggle each
|
|
|
|
Selection newsel;
|
|
|
|
if (ctrl) newsel = selection;
|
2013-12-12 00:11:06 +01:00
|
|
|
for (int i = i1; i <= i2; i++)
|
2012-01-25 05:59:17 +01:00
|
|
|
newsel.insert(GetDialogue(i));
|
2014-03-25 01:15:14 +01:00
|
|
|
context->selectionController->SetSelectedSet(std::move(newsel));
|
2006-02-18 23:09:03 +01:00
|
|
|
return;
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mouse wheel
|
|
|
|
if (event.GetWheelRotation() != 0) {
|
2011-10-25 21:40:45 +02:00
|
|
|
if (ForwardMouseWheelEvent(this, event)) {
|
2012-01-26 23:46:09 +01:00
|
|
|
int step = shift ? h / lineHeight - 2 : 3;
|
|
|
|
ScrollTo(yPos - step * event.GetWheelRotation() / event.GetWheelDelta());
|
2011-10-25 21:40:45 +02:00
|
|
|
}
|
2006-02-18 22:55:58 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2011-08-31 06:17:37 +02:00
|
|
|
void BaseGrid::OnContextMenu(wxContextMenuEvent &evt) {
|
|
|
|
wxPoint pos = evt.GetPosition();
|
2011-11-08 01:24:41 +01:00
|
|
|
if (pos == wxDefaultPosition || ScreenToClient(pos).y > lineHeight) {
|
|
|
|
if (!context_menu) context_menu = menu::GetMenu("grid_context", context);
|
2013-06-10 15:58:13 +02:00
|
|
|
menu::OpenPopupMenu(context_menu.get(), this);
|
2011-11-08 01:24:41 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
const wxString strings[] = {
|
|
|
|
_("Line Number"),
|
|
|
|
_("Layer"),
|
|
|
|
_("Start"),
|
|
|
|
_("End"),
|
|
|
|
_("Style"),
|
|
|
|
_("Actor"),
|
|
|
|
_("Effect"),
|
|
|
|
_("Left"),
|
|
|
|
_("Right"),
|
|
|
|
_("Vert"),
|
|
|
|
};
|
|
|
|
|
|
|
|
wxMenu menu;
|
2013-09-16 21:02:17 +02:00
|
|
|
for (size_t i = 0; i < boost::size(showCol); ++i)
|
2011-11-08 01:24:41 +01:00
|
|
|
menu.Append(MENU_SHOW_COL + i, strings[i], "", wxITEM_CHECK)->Check(showCol[i]);
|
|
|
|
PopupMenu(&menu);
|
|
|
|
}
|
2011-08-31 06:17:37 +02:00
|
|
|
}
|
|
|
|
|
2006-02-19 04:10:03 +01:00
|
|
|
void BaseGrid::ScrollTo(int y) {
|
2012-10-20 17:26:38 +02:00
|
|
|
int nextY = mid(0, y, GetRows() - 1);
|
2006-02-19 04:10:03 +01:00
|
|
|
if (yPos != nextY) {
|
|
|
|
yPos = nextY;
|
2012-10-20 17:26:38 +02:00
|
|
|
scrollBar->SetThumbPosition(yPos);
|
2006-02-19 04:10:03 +01:00
|
|
|
Refresh(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
void BaseGrid::AdjustScrollbar() {
|
2012-10-20 17:26:38 +02:00
|
|
|
wxSize clientSize = GetClientSize();
|
|
|
|
wxSize scrollbarSize = scrollBar->GetSize();
|
2006-02-22 07:08:35 +01:00
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
scrollBar->Freeze();
|
2012-10-20 17:26:38 +02:00
|
|
|
scrollBar->SetSize(clientSize.GetWidth() - scrollbarSize.GetWidth(), 0, scrollbarSize.GetWidth(), clientSize.GetHeight());
|
|
|
|
|
|
|
|
if (GetRows() <= 1) {
|
|
|
|
scrollBar->Enable(false);
|
|
|
|
scrollBar->Thaw();
|
|
|
|
return;
|
|
|
|
}
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2013-09-16 21:02:17 +02:00
|
|
|
if (!scrollBar->IsEnabled())
|
2012-10-20 17:26:38 +02:00
|
|
|
scrollBar->Enable(true);
|
|
|
|
|
|
|
|
int drawPerScreen = clientSize.GetHeight() / lineHeight;
|
|
|
|
int rows = GetRows();
|
|
|
|
|
|
|
|
yPos = mid(0, yPos, rows - 1);
|
|
|
|
|
|
|
|
scrollBar->SetScrollbar(yPos, drawPerScreen, rows + drawPerScreen - 1, drawPerScreen - 2, true);
|
2006-02-18 22:55:58 +01:00
|
|
|
scrollBar->Thaw();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::SetColumnWidths() {
|
2011-10-01 20:35:06 +02:00
|
|
|
int w, h;
|
2013-09-16 21:02:17 +02:00
|
|
|
GetClientSize(&w, &h);
|
2006-02-18 22:55:58 +01:00
|
|
|
|
|
|
|
// DC for text extents test
|
|
|
|
wxClientDC dc(this);
|
|
|
|
dc.SetFont(font);
|
|
|
|
|
|
|
|
// O(1) widths
|
2011-10-01 20:35:06 +02:00
|
|
|
int marginLen = dc.GetTextExtent("0000").GetWidth();
|
|
|
|
|
2013-09-18 17:31:26 +02:00
|
|
|
int labelLen = dc.GetTextExtent(std::to_wstring(GetRows())).GetWidth();
|
2006-02-18 22:55:58 +01:00
|
|
|
int startLen = 0;
|
|
|
|
int endLen = 0;
|
2011-10-01 20:35:06 +02:00
|
|
|
if (!byFrame)
|
2013-01-04 16:01:50 +01:00
|
|
|
startLen = endLen = dc.GetTextExtent(to_wx(AssTime().GetAssFormated())).GetWidth();
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2013-09-16 19:43:21 +02:00
|
|
|
std::unordered_map<boost::flyweight<std::string>, int> widths;
|
|
|
|
auto get_width = [&](boost::flyweight<std::string> const& str) -> int {
|
2014-03-07 19:58:51 +01:00
|
|
|
if (str.get().empty()) return 0;
|
2013-09-16 19:43:21 +02:00
|
|
|
auto it = widths.find(str);
|
|
|
|
if (it != end(widths)) return it->second;
|
|
|
|
int width = dc.GetTextExtent(to_wx(str)).GetWidth();
|
|
|
|
widths[str] = width;
|
|
|
|
return width;
|
|
|
|
};
|
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
// O(n) widths
|
2011-07-15 06:05:43 +02:00
|
|
|
bool showMargin[3] = { false, false, false };
|
2006-12-30 19:19:54 +01:00
|
|
|
int styleLen = 0;
|
2006-02-18 22:55:58 +01:00
|
|
|
int actorLen = 0;
|
|
|
|
int effectLen = 0;
|
2006-02-22 06:30:09 +01:00
|
|
|
int maxLayer = 0;
|
|
|
|
int maxStart = 0;
|
|
|
|
int maxEnd = 0;
|
2014-03-07 19:58:51 +01:00
|
|
|
for (auto const& diag : context->ass->Events) {
|
|
|
|
maxLayer = std::max(maxLayer, diag.Layer);
|
|
|
|
actorLen = std::max(actorLen, get_width(diag.Actor));
|
|
|
|
styleLen = std::max(styleLen, get_width(diag.Style));
|
|
|
|
effectLen = std::max(effectLen, get_width(diag.Effect));
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
// Margins
|
2011-10-01 20:35:06 +02:00
|
|
|
for (int j = 0; j < 3; j++) {
|
2014-03-07 19:58:51 +01:00
|
|
|
if (diag.Margin[j])
|
2011-10-01 20:35:06 +02:00
|
|
|
showMargin[j] = true;
|
2011-07-15 06:05:43 +02:00
|
|
|
}
|
2007-07-03 03:48:04 +02:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
// Times
|
|
|
|
if (byFrame) {
|
2014-03-07 19:58:51 +01:00
|
|
|
maxStart = std::max(maxStart, context->videoController->FrameAtTime(diag.Start, agi::vfr::START));
|
|
|
|
maxEnd = std::max(maxEnd, context->videoController->FrameAtTime(diag.End, agi::vfr::END));
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
}
|
2006-02-22 06:30:09 +01:00
|
|
|
|
|
|
|
// Finish layer
|
2013-09-18 17:31:26 +02:00
|
|
|
int layerLen = maxLayer ? dc.GetTextExtent(std::to_wstring(maxLayer)).GetWidth() : 0;
|
2006-02-22 06:30:09 +01:00
|
|
|
|
|
|
|
// Finish times
|
|
|
|
if (byFrame) {
|
2013-09-18 17:31:26 +02:00
|
|
|
startLen = dc.GetTextExtent(std::to_wstring(maxStart)).GetWidth();
|
|
|
|
endLen = dc.GetTextExtent(std::to_wstring(maxEnd)).GetWidth();
|
2006-02-22 06:30:09 +01:00
|
|
|
}
|
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
// Set column widths
|
|
|
|
colWidth[0] = labelLen;
|
2011-07-15 06:05:43 +02:00
|
|
|
colWidth[1] = layerLen;
|
2006-02-18 22:55:58 +01:00
|
|
|
colWidth[2] = startLen;
|
|
|
|
colWidth[3] = endLen;
|
|
|
|
colWidth[4] = styleLen;
|
|
|
|
colWidth[5] = actorLen;
|
|
|
|
colWidth[6] = effectLen;
|
2011-10-01 20:35:06 +02:00
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
colWidth[i + 7] = showMargin[i] ? marginLen : 0;
|
2012-01-18 21:08:06 +01:00
|
|
|
colWidth[10] = 1;
|
2006-02-18 22:55:58 +01:00
|
|
|
|
2006-06-27 07:13:41 +02:00
|
|
|
// Hide columns
|
2013-09-16 21:02:17 +02:00
|
|
|
for (size_t i = 0; i < boost::size(showCol); ++i) {
|
2011-10-01 20:35:06 +02:00
|
|
|
if (!showCol[i])
|
|
|
|
colWidth[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString col_names[11] = {
|
|
|
|
_("#"),
|
|
|
|
_("L"),
|
|
|
|
_("Start"),
|
|
|
|
_("End"),
|
|
|
|
_("Style"),
|
|
|
|
_("Actor"),
|
|
|
|
_("Effect"),
|
|
|
|
_("Left"),
|
|
|
|
_("Right"),
|
|
|
|
_("Vert"),
|
|
|
|
_("Text")
|
|
|
|
};
|
|
|
|
|
|
|
|
// Ensure every visible column is at least as big as its header
|
|
|
|
for (size_t i = 0; i < 11; ++i) {
|
|
|
|
if (colWidth[i])
|
|
|
|
colWidth[i] = std::max(colWidth[i], dc.GetTextExtent(col_names[i]).GetWidth());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add padding to all non-empty columns
|
|
|
|
for (size_t i = 0; i < 10; ++i) {
|
|
|
|
if (colWidth[i])
|
|
|
|
colWidth[i] += 10;
|
2006-06-27 07:13:41 +02:00
|
|
|
}
|
|
|
|
|
2006-02-18 22:55:58 +01:00
|
|
|
// Set size of last
|
2011-10-01 20:35:06 +02:00
|
|
|
int total = std::accumulate(colWidth, colWidth + 10, 0);
|
2013-09-16 19:26:41 +02:00
|
|
|
colWidth[10] = std::max(w - total, 0);
|
2011-09-15 07:16:32 +02:00
|
|
|
|
2011-10-13 01:07:38 +02:00
|
|
|
time_cols_x = colWidth[0] + colWidth[1];
|
|
|
|
time_cols_w = colWidth[2] + colWidth[3];
|
2011-09-15 07:16:32 +02:00
|
|
|
text_col_x = total;
|
|
|
|
text_col_w = colWidth[10];
|
2006-02-18 22:55:58 +01:00
|
|
|
}
|
|
|
|
|
2010-05-26 09:17:34 +02:00
|
|
|
AssDialogue *BaseGrid::GetDialogue(int n) const {
|
2013-11-21 18:13:36 +01:00
|
|
|
if (static_cast<size_t>(n) >= index_line_map.size()) return nullptr;
|
2010-06-26 09:26:27 +02:00
|
|
|
return index_line_map[n];
|
|
|
|
}
|
|
|
|
|
2011-01-16 08:17:36 +01:00
|
|
|
bool BaseGrid::IsDisplayed(const AssDialogue *line) const {
|
|
|
|
if (!context->videoController->IsLoaded()) return false;
|
|
|
|
int frame = context->videoController->GetFrameN();
|
2013-09-16 21:02:17 +02:00
|
|
|
return context->videoController->FrameAtTime(line->Start,agi::vfr::START) <= frame
|
|
|
|
&& context->videoController->FrameAtTime(line->End,agi::vfr::END) >= frame;
|
2006-02-19 01:54:35 +01:00
|
|
|
}
|
2006-02-21 03:01:42 +01:00
|
|
|
|
2012-04-27 21:07:49 +02:00
|
|
|
void BaseGrid::OnCharHook(wxKeyEvent &event) {
|
2012-03-13 00:34:34 +01:00
|
|
|
if (hotkey::check("Subtitle Grid", context, event))
|
2011-01-19 04:12:46 +01:00
|
|
|
return;
|
|
|
|
|
2012-04-27 21:07:49 +02:00
|
|
|
int key = event.GetKeyCode();
|
|
|
|
|
|
|
|
if (key == WXK_UP || key == WXK_DOWN ||
|
|
|
|
key == WXK_PAGEUP || key == WXK_PAGEDOWN ||
|
|
|
|
key == WXK_HOME || key == WXK_END)
|
|
|
|
{
|
|
|
|
event.Skip();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hotkey::check("Audio", context, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseGrid::OnKeyDown(wxKeyEvent &event) {
|
2006-02-22 04:38:23 +01:00
|
|
|
int w,h;
|
2013-09-16 21:02:17 +02:00
|
|
|
GetClientSize(&w, &h);
|
2006-02-22 04:38:23 +01:00
|
|
|
|
2007-01-22 20:31:49 +01:00
|
|
|
int key = event.GetKeyCode();
|
2011-07-15 06:05:43 +02:00
|
|
|
bool ctrl = event.CmdDown();
|
|
|
|
bool alt = event.AltDown();
|
|
|
|
bool shift = event.ShiftDown();
|
2006-02-22 03:25:45 +01:00
|
|
|
|
|
|
|
int dir = 0;
|
2006-02-22 04:38:23 +01:00
|
|
|
int step = 1;
|
2006-02-22 03:25:45 +01:00
|
|
|
if (key == WXK_UP) dir = -1;
|
2011-07-15 06:05:43 +02:00
|
|
|
else if (key == WXK_DOWN) dir = 1;
|
|
|
|
else if (key == WXK_PAGEUP) {
|
2006-02-22 04:38:23 +01:00
|
|
|
dir = -1;
|
2011-07-15 06:05:43 +02:00
|
|
|
step = h / lineHeight - 2;
|
2006-02-22 04:38:23 +01:00
|
|
|
}
|
2011-07-15 06:05:43 +02:00
|
|
|
else if (key == WXK_PAGEDOWN) {
|
2006-02-22 04:38:23 +01:00
|
|
|
dir = 1;
|
2011-07-15 06:05:43 +02:00
|
|
|
step = h / lineHeight - 2;
|
2006-02-22 04:38:23 +01:00
|
|
|
}
|
2011-07-15 06:05:43 +02:00
|
|
|
else if (key == WXK_HOME) {
|
2006-02-22 04:38:23 +01:00
|
|
|
dir = -1;
|
|
|
|
step = GetRows();
|
|
|
|
}
|
2011-07-15 06:05:43 +02:00
|
|
|
else if (key == WXK_END) {
|
2006-02-22 04:38:23 +01:00
|
|
|
dir = 1;
|
|
|
|
step = GetRows();
|
|
|
|
}
|
2006-02-22 03:25:45 +01:00
|
|
|
|
2012-04-27 21:07:49 +02:00
|
|
|
if (!dir) {
|
|
|
|
event.Skip();
|
|
|
|
return;
|
|
|
|
}
|
2012-04-06 05:53:38 +02:00
|
|
|
|
2014-03-31 16:41:57 +02:00
|
|
|
auto active_line = context->selectionController->GetActiveLine();
|
2012-04-27 21:07:49 +02:00
|
|
|
int old_extend = extendRow;
|
2014-03-31 16:41:57 +02:00
|
|
|
int next = mid(0, (active_line ? active_line->Row : 0) + dir * step, GetRows() - 1);
|
2014-03-25 01:15:14 +01:00
|
|
|
context->selectionController->SetActiveLine(GetDialogue(next));
|
2012-01-25 05:59:17 +01:00
|
|
|
|
2012-04-27 21:07:49 +02:00
|
|
|
// Move selection
|
|
|
|
if (!ctrl && !shift && !alt) {
|
|
|
|
SelectRow(next);
|
|
|
|
return;
|
|
|
|
}
|
2006-02-22 03:25:45 +01:00
|
|
|
|
2012-04-27 21:07:49 +02:00
|
|
|
// Move active only
|
2014-03-25 01:15:14 +01:00
|
|
|
if (alt && !shift && !ctrl)
|
2012-04-27 21:07:49 +02:00
|
|
|
return;
|
2006-02-22 03:25:45 +01:00
|
|
|
|
2012-04-27 21:07:49 +02:00
|
|
|
// Shift-selection
|
|
|
|
if (shift && !ctrl && !alt) {
|
|
|
|
extendRow = old_extend;
|
|
|
|
// Set range
|
|
|
|
int begin = next;
|
|
|
|
int end = extendRow;
|
|
|
|
if (end < begin)
|
|
|
|
std::swap(begin, end);
|
2006-02-22 03:25:45 +01:00
|
|
|
|
2012-04-27 21:07:49 +02:00
|
|
|
// Select range
|
|
|
|
Selection newsel;
|
|
|
|
for (int i = begin; i <= end; i++)
|
|
|
|
newsel.insert(GetDialogue(i));
|
2012-01-25 05:59:17 +01:00
|
|
|
|
2014-03-25 01:15:14 +01:00
|
|
|
context->selectionController->SetSelectedSet(std::move(newsel));
|
2006-02-22 03:25:45 +01:00
|
|
|
|
2013-09-16 21:02:17 +02:00
|
|
|
MakeRowVisible(next);
|
2012-04-27 21:07:49 +02:00
|
|
|
return;
|
2006-02-22 03:25:45 +01:00
|
|
|
}
|
|
|
|
}
|
2006-02-22 05:59:39 +01:00
|
|
|
|
2011-07-15 06:05:43 +02:00
|
|
|
void BaseGrid::SetByFrame(bool state) {
|
2006-02-22 05:59:39 +01:00
|
|
|
if (byFrame == state) return;
|
|
|
|
byFrame = state;
|
|
|
|
SetColumnWidths();
|
|
|
|
Refresh(false);
|
|
|
|
}
|