2013-09-17 20:13:52 +02:00
|
|
|
// Copyright (c) 2013, Thomas Goyne <plorkyeran@aegisub.org>
|
2007-07-01 02:19:55 +02:00
|
|
|
//
|
2011-11-06 18:18:20 +01:00
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
2007-07-01 02:19:55 +02:00
|
|
|
//
|
2011-11-06 18:18:20 +01:00
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2007-07-01 02:19:55 +02:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file visual_tool.cpp
|
|
|
|
/// @brief Base class for visual typesetting functions
|
|
|
|
/// @ingroup visual_ts
|
2007-07-01 02:19:55 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
#include "visual_tool.h"
|
|
|
|
|
2007-07-01 02:19:55 +02:00
|
|
|
#include "ass_dialogue.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "ass_file.h"
|
2007-07-01 02:19:55 +02:00
|
|
|
#include "ass_style.h"
|
2018-04-15 23:59:32 +02:00
|
|
|
#include "compat.h"
|
2011-01-16 08:17:08 +01:00
|
|
|
#include "include/aegisub/context.h"
|
2018-04-15 23:59:32 +02:00
|
|
|
#include "options.h"
|
2014-03-25 01:15:14 +01:00
|
|
|
#include "selection_controller.h"
|
2014-05-22 01:23:28 +02:00
|
|
|
#include "video_controller.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "video_display.h"
|
2010-05-20 10:55:52 +02:00
|
|
|
#include "visual_tool_clip.h"
|
|
|
|
#include "visual_tool_drag.h"
|
|
|
|
#include "visual_tool_vector_clip.h"
|
2007-07-01 02:19:55 +02:00
|
|
|
|
2014-07-06 16:28:58 +02:00
|
|
|
#include <libaegisub/ass/time.h>
|
2014-05-29 00:19:05 +02:00
|
|
|
#include <libaegisub/format.h>
|
2012-11-05 17:20:58 +01:00
|
|
|
#include <libaegisub/of_type_adaptor.h>
|
2011-11-06 18:18:20 +01:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <algorithm>
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
VisualToolBase::VisualToolBase(VideoDisplay *parent, agi::Context *context)
|
|
|
|
: c(context)
|
2010-05-20 10:55:58 +02:00
|
|
|
, parent(parent)
|
2011-11-06 18:18:20 +01:00
|
|
|
, frame_number(c->videoController->GetFrameN())
|
2018-04-15 23:59:32 +02:00
|
|
|
, highlight_color_primary_opt(OPT_GET("Colour/Visual Tools/Highlight Primary"))
|
|
|
|
, highlight_color_secondary_opt(OPT_GET("Colour/Visual Tools/Highlight Secondary"))
|
|
|
|
, line_color_primary_opt(OPT_GET("Colour/Visual Tools/Lines Primary"))
|
|
|
|
, line_color_secondary_opt(OPT_GET("Colour/Visual Tools/Lines Secondary"))
|
|
|
|
, shaded_area_alpha_opt(OPT_GET("Colour/Visual Tools/Shaded Area Alpha"))
|
2011-11-06 18:18:20 +01:00
|
|
|
, file_changed_connection(c->ass->AddCommitListener(&VisualToolBase::OnCommit, this))
|
2010-05-16 08:39:11 +02:00
|
|
|
{
|
2011-11-06 18:18:20 +01:00
|
|
|
int script_w, script_h;
|
|
|
|
c->ass->GetResolution(script_w, script_h);
|
|
|
|
script_res = Vector2D(script_w, script_h);
|
|
|
|
active_line = GetActiveDialogueLine();
|
2012-10-05 05:22:54 +02:00
|
|
|
connections.push_back(c->selectionController->AddActiveLineListener(&VisualToolBase::OnActiveLineChanged, this));
|
2011-11-06 18:18:20 +01:00
|
|
|
connections.push_back(c->videoController->AddSeekListener(&VisualToolBase::OnSeek, this));
|
|
|
|
parent->Bind(wxEVT_MOUSE_CAPTURE_LOST, &VisualToolBase::OnMouseCaptureLost, this);
|
2007-07-01 02:19:55 +02:00
|
|
|
}
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
void VisualToolBase::OnCommit(int type) {
|
|
|
|
holding = false;
|
|
|
|
dragging = false;
|
|
|
|
|
2011-11-16 20:54:35 +01:00
|
|
|
if (type == AssFile::COMMIT_NEW || type & AssFile::COMMIT_SCRIPTINFO) {
|
2011-11-06 18:18:20 +01:00
|
|
|
int script_w, script_h;
|
|
|
|
c->ass->GetResolution(script_w, script_h);
|
|
|
|
script_res = Vector2D(script_w, script_h);
|
|
|
|
OnCoordinateSystemsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type & AssFile::COMMIT_DIAG_FULL || type & AssFile::COMMIT_DIAG_ADDREM) {
|
|
|
|
active_line = GetActiveDialogueLine();
|
|
|
|
OnFileChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualToolBase::OnSeek(int new_frame) {
|
|
|
|
if (frame_number == new_frame) return;
|
|
|
|
|
|
|
|
frame_number = new_frame;
|
|
|
|
OnFrameChanged();
|
|
|
|
|
|
|
|
AssDialogue *new_line = GetActiveDialogueLine();
|
|
|
|
if (new_line != active_line) {
|
2011-12-27 02:38:00 +01:00
|
|
|
dragging = false;
|
2011-11-06 18:18:20 +01:00
|
|
|
active_line = new_line;
|
|
|
|
OnLineChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualToolBase::OnMouseCaptureLost(wxMouseCaptureLostEvent &) {
|
|
|
|
holding = false;
|
|
|
|
dragging = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualToolBase::OnActiveLineChanged(AssDialogue *new_line) {
|
|
|
|
if (!IsDisplayed(new_line))
|
2013-11-21 18:13:36 +01:00
|
|
|
new_line = nullptr;
|
2011-11-06 18:18:20 +01:00
|
|
|
|
|
|
|
holding = false;
|
|
|
|
dragging = false;
|
|
|
|
if (new_line != active_line) {
|
|
|
|
active_line = new_line;
|
|
|
|
OnLineChanged();
|
2012-01-12 23:49:24 +01:00
|
|
|
parent->Render();
|
2011-11-06 18:18:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisualToolBase::IsDisplayed(AssDialogue *line) const {
|
|
|
|
int frame = c->videoController->GetFrameN();
|
2014-01-15 17:00:20 +01:00
|
|
|
return line
|
|
|
|
&& !line->Comment
|
|
|
|
&& c->videoController->FrameAtTime(line->Start, agi::vfr::START) <= frame
|
|
|
|
&& c->videoController->FrameAtTime(line->End, agi::vfr::END) >= frame;
|
2011-11-06 18:18:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualToolBase::Commit(wxString message) {
|
|
|
|
file_changed_connection.Block();
|
|
|
|
if (message.empty())
|
|
|
|
message = _("visual typesetting");
|
|
|
|
|
|
|
|
commit_id = c->ass->Commit(message, AssFile::COMMIT_DIAG_TEXT, commit_id);
|
|
|
|
file_changed_connection.Unblock();
|
|
|
|
}
|
|
|
|
|
|
|
|
AssDialogue* VisualToolBase::GetActiveDialogueLine() {
|
|
|
|
AssDialogue *diag = c->selectionController->GetActiveLine();
|
|
|
|
if (IsDisplayed(diag))
|
|
|
|
return diag;
|
2013-11-21 18:13:36 +01:00
|
|
|
return nullptr;
|
2011-11-06 18:18:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualToolBase::SetDisplayArea(int x, int y, int w, int h) {
|
2011-12-22 22:13:57 +01:00
|
|
|
if (x == video_pos.X() && y == video_pos.Y() && w == video_res.X() && h == video_res.Y()) return;
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
video_pos = Vector2D(x, y);
|
|
|
|
video_res = Vector2D(w, h);
|
|
|
|
|
|
|
|
holding = false;
|
|
|
|
dragging = false;
|
2013-02-09 05:37:43 +01:00
|
|
|
if (parent->HasCapture())
|
|
|
|
parent->ReleaseMouse();
|
2011-11-06 18:18:20 +01:00
|
|
|
OnCoordinateSystemsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector2D VisualToolBase::ToScriptCoords(Vector2D point) const {
|
|
|
|
return (point - video_pos) * script_res / video_res;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector2D VisualToolBase::FromScriptCoords(Vector2D point) const {
|
|
|
|
return (point * video_res / script_res) + video_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class FeatureType>
|
|
|
|
VisualTool<FeatureType>::VisualTool(VideoDisplay *parent, agi::Context *context)
|
|
|
|
: VisualToolBase(parent, context)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
template<class FeatureType>
|
2010-06-28 09:13:15 +02:00
|
|
|
void VisualTool<FeatureType>::OnMouseEvent(wxMouseEvent &event) {
|
2013-02-09 05:37:43 +01:00
|
|
|
bool left_click = event.LeftDown();
|
|
|
|
bool left_double = event.LeftDClick();
|
2011-11-06 18:18:20 +01:00
|
|
|
shift_down = event.ShiftDown();
|
|
|
|
ctrl_down = event.CmdDown();
|
|
|
|
alt_down = event.AltDown();
|
|
|
|
|
|
|
|
mouse_pos = event.GetPosition();
|
|
|
|
|
2007-07-01 04:23:57 +02:00
|
|
|
if (event.Leaving()) {
|
2011-12-07 00:13:06 +01:00
|
|
|
mouse_pos = Vector2D();
|
2010-06-07 09:24:30 +02:00
|
|
|
parent->Render();
|
2007-07-08 09:22:09 +02:00
|
|
|
return;
|
2007-07-01 04:23:57 +02:00
|
|
|
}
|
2011-11-06 18:18:20 +01:00
|
|
|
|
2010-05-26 09:17:39 +02:00
|
|
|
if (!dragging) {
|
2011-11-06 18:18:20 +01:00
|
|
|
int max_layer = INT_MIN;
|
2013-09-17 20:13:52 +02:00
|
|
|
active_feature = nullptr;
|
|
|
|
for (auto& feature : features) {
|
|
|
|
if (feature.IsMouseOver(mouse_pos) && feature.layer >= max_layer) {
|
|
|
|
active_feature = &feature;
|
|
|
|
max_layer = feature.layer;
|
2011-11-06 18:18:20 +01:00
|
|
|
}
|
|
|
|
}
|
2010-05-26 09:17:39 +02:00
|
|
|
}
|
2010-05-20 10:55:35 +02:00
|
|
|
|
|
|
|
if (dragging) {
|
|
|
|
// continue drag
|
|
|
|
if (event.LeftIsDown()) {
|
2012-11-05 17:20:58 +01:00
|
|
|
for (auto sel : sel_features)
|
|
|
|
sel->UpdateDrag(mouse_pos - drag_start, shift_down);
|
|
|
|
for (auto sel : sel_features)
|
|
|
|
UpdateDrag(sel);
|
2010-10-26 06:12:10 +02:00
|
|
|
Commit();
|
2007-07-01 09:09:37 +02:00
|
|
|
}
|
2010-05-20 10:55:35 +02:00
|
|
|
// end drag
|
|
|
|
else {
|
|
|
|
dragging = false;
|
|
|
|
|
2010-05-20 10:55:58 +02:00
|
|
|
// mouse didn't move, fiddle with selection
|
2013-09-17 20:13:52 +02:00
|
|
|
if (active_feature && !active_feature->HasMoved()) {
|
2010-05-20 10:55:58 +02:00
|
|
|
// Don't deselect stuff that was selected in this click's mousedown event
|
2011-11-06 18:18:20 +01:00
|
|
|
if (!sel_changed) {
|
|
|
|
if (ctrl_down)
|
|
|
|
RemoveSelection(active_feature);
|
|
|
|
else
|
|
|
|
SetSelection(active_feature, true);
|
2010-05-20 10:55:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-17 20:13:52 +02:00
|
|
|
active_feature = nullptr;
|
2010-05-20 10:55:35 +02:00
|
|
|
parent->ReleaseMouse();
|
|
|
|
parent->SetFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (holding) {
|
2012-05-11 04:47:18 +02:00
|
|
|
if (!event.LeftIsDown()) {
|
2010-05-20 10:55:35 +02:00
|
|
|
holding = false;
|
|
|
|
|
|
|
|
parent->ReleaseMouse();
|
|
|
|
parent->SetFocus();
|
|
|
|
}
|
2012-05-11 04:47:18 +02:00
|
|
|
|
|
|
|
UpdateHold();
|
2010-10-26 06:12:10 +02:00
|
|
|
Commit();
|
|
|
|
|
2010-05-20 10:55:35 +02:00
|
|
|
}
|
2011-11-06 18:18:20 +01:00
|
|
|
else if (left_click) {
|
|
|
|
drag_start = mouse_pos;
|
|
|
|
|
2010-05-20 10:55:35 +02:00
|
|
|
// start drag
|
2013-09-17 20:13:52 +02:00
|
|
|
if (active_feature) {
|
2011-11-06 18:18:20 +01:00
|
|
|
if (!sel_features.count(active_feature)) {
|
|
|
|
sel_changed = true;
|
|
|
|
SetSelection(active_feature, !ctrl_down);
|
2010-06-30 08:29:14 +02:00
|
|
|
}
|
2011-11-06 18:18:20 +01:00
|
|
|
else
|
|
|
|
sel_changed = false;
|
|
|
|
|
|
|
|
if (active_feature->line)
|
|
|
|
c->selectionController->SetActiveLine(active_feature->line);
|
2007-07-01 09:09:37 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
if (InitializeDrag(active_feature)) {
|
2012-11-05 17:20:58 +01:00
|
|
|
for (auto sel : sel_features) sel->StartDrag();
|
2007-07-01 09:09:37 +02:00
|
|
|
dragging = true;
|
|
|
|
parent->CaptureMouse();
|
|
|
|
}
|
|
|
|
}
|
2010-05-20 10:55:35 +02:00
|
|
|
// start hold
|
|
|
|
else {
|
2012-05-04 04:53:09 +02:00
|
|
|
if (!alt_down && features.size() > 1) {
|
2011-11-06 18:18:20 +01:00
|
|
|
sel_features.clear();
|
2013-12-12 00:11:06 +01:00
|
|
|
c->selectionController->SetSelectedSet({ c->selectionController->GetActiveLine() });
|
2010-05-26 09:17:39 +02:00
|
|
|
}
|
2011-11-06 18:18:20 +01:00
|
|
|
if (active_line && InitializeHold()) {
|
2007-07-01 04:23:57 +02:00
|
|
|
holding = true;
|
|
|
|
parent->CaptureMouse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
if (active_line && left_double)
|
|
|
|
OnDoubleClick();
|
2010-11-01 05:36:13 +01:00
|
|
|
|
2013-09-17 20:13:52 +02:00
|
|
|
parent->Render();
|
2007-07-01 04:23:57 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
// Only coalesce the changes made in a single drag
|
|
|
|
if (!event.LeftIsDown())
|
|
|
|
commit_id = -1;
|
2007-07-01 09:09:37 +02:00
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
template<class FeatureType>
|
|
|
|
void VisualTool<FeatureType>::DrawAllFeatures() {
|
2018-04-15 23:59:32 +02:00
|
|
|
wxColour grid_color = to_wx(line_color_secondary_opt->GetColor());
|
|
|
|
gl.SetLineColour(grid_color, 1.0f, 1);
|
2019-05-17 00:10:43 +02:00
|
|
|
wxColour base_fill = to_wx(highlight_color_primary_opt->GetColor());
|
2018-04-15 23:59:32 +02:00
|
|
|
wxColour active_fill = to_wx(highlight_color_secondary_opt->GetColor());
|
|
|
|
wxColour alt_fill = to_wx(line_color_primary_opt->GetColor());
|
2013-09-17 20:13:52 +02:00
|
|
|
for (auto& feature : features) {
|
2018-04-15 23:59:32 +02:00
|
|
|
wxColour fill = base_fill;
|
2013-09-17 20:13:52 +02:00
|
|
|
if (&feature == active_feature)
|
2018-04-15 23:59:32 +02:00
|
|
|
fill = active_fill;
|
2013-09-17 20:13:52 +02:00
|
|
|
else if (sel_features.count(&feature))
|
2018-04-15 23:59:32 +02:00
|
|
|
fill = alt_fill;
|
|
|
|
gl.SetFillColour(fill, 0.3f);
|
2013-09-17 20:13:52 +02:00
|
|
|
feature.Draw(gl);
|
2007-07-01 09:09:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
template<class FeatureType>
|
2013-09-17 20:13:52 +02:00
|
|
|
void VisualTool<FeatureType>::SetSelection(FeatureType *feat, bool clear) {
|
2011-11-06 18:18:20 +01:00
|
|
|
if (clear)
|
|
|
|
sel_features.clear();
|
2010-06-28 09:13:15 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
if (sel_features.insert(feat).second && feat->line) {
|
2014-03-25 01:15:14 +01:00
|
|
|
Selection sel;
|
2011-11-06 18:18:20 +01:00
|
|
|
if (!clear)
|
|
|
|
sel = c->selectionController->GetSelectedSet();
|
|
|
|
if (sel.insert(feat->line).second)
|
2014-03-12 23:10:47 +01:00
|
|
|
c->selectionController->SetSelectedSet(std::move(sel));
|
2010-06-28 09:13:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class FeatureType>
|
2013-09-17 20:13:52 +02:00
|
|
|
void VisualTool<FeatureType>::RemoveSelection(FeatureType *feat) {
|
2011-11-06 18:18:20 +01:00
|
|
|
if (!sel_features.erase(feat) || !feat->line) return;
|
2013-09-17 20:13:52 +02:00
|
|
|
for (auto sel : sel_features)
|
2012-11-04 04:53:03 +01:00
|
|
|
if (sel->line == feat->line) return;
|
2010-06-28 09:13:15 +02:00
|
|
|
|
2014-03-25 01:15:14 +01:00
|
|
|
auto sel = c->selectionController->GetSelectedSet();
|
2010-06-28 09:13:15 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
// Don't deselect the only selected line
|
|
|
|
if (sel.size() <= 1) return;
|
2010-06-30 08:29:14 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
sel.erase(feat->line);
|
2010-06-28 09:13:15 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
// Set the active line to an arbitrary selected line if we just
|
|
|
|
// deselected the active line
|
2012-05-05 04:11:09 +02:00
|
|
|
AssDialogue *new_active = c->selectionController->GetActiveLine();
|
|
|
|
if (feat->line == new_active)
|
|
|
|
new_active = *sel.begin();
|
2010-06-28 09:13:15 +02:00
|
|
|
|
2014-03-12 23:10:47 +01:00
|
|
|
c->selectionController->SetSelectionAndActive(std::move(sel), new_active);
|
2010-05-26 09:17:39 +02:00
|
|
|
}
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
//////// PARSERS
|
2010-06-28 09:13:15 +02:00
|
|
|
|
2012-12-09 17:29:02 +01:00
|
|
|
typedef const std::vector<AssOverrideParameter> * param_vec;
|
2010-05-26 09:17:39 +02:00
|
|
|
|
2012-11-13 17:51:01 +01:00
|
|
|
// Find a tag's parameters in a line or return nullptr if it's not found
|
2014-04-14 19:58:46 +02:00
|
|
|
static param_vec find_tag(std::vector<std::unique_ptr<AssDialogueBlock>>& blocks, std::string const& tag_name) {
|
2012-12-02 19:24:49 +01:00
|
|
|
for (auto ovr : blocks | agi::of_type<AssDialogueBlockOverride>()) {
|
2012-12-11 00:32:36 +01:00
|
|
|
for (auto const& tag : ovr->Tags) {
|
|
|
|
if (tag.Name == tag_name)
|
|
|
|
return &tag.Params;
|
2010-06-24 03:23:43 +02:00
|
|
|
}
|
|
|
|
}
|
2011-11-06 18:18:20 +01:00
|
|
|
|
2013-11-21 18:13:36 +01:00
|
|
|
return nullptr;
|
2010-06-24 03:23:43 +02:00
|
|
|
}
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
// Get a Vector2D from the given tag parameters, or Vector2D::Bad() if they are not valid
|
|
|
|
static Vector2D vec_or_bad(param_vec tag, size_t x_idx, size_t y_idx) {
|
|
|
|
if (!tag ||
|
|
|
|
tag->size() <= x_idx || tag->size() <= y_idx ||
|
2012-12-10 23:19:28 +01:00
|
|
|
(*tag)[x_idx].omitted || (*tag)[y_idx].omitted)
|
2011-11-06 18:18:20 +01:00
|
|
|
{
|
2011-12-07 00:13:06 +01:00
|
|
|
return Vector2D();
|
2011-11-06 18:18:20 +01:00
|
|
|
}
|
2012-12-09 17:29:02 +01:00
|
|
|
return Vector2D((*tag)[x_idx].Get<float>(), (*tag)[y_idx].Get<float>());
|
2007-07-01 02:19:55 +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-11-06 18:18:20 +01:00
|
|
|
Vector2D VisualToolBase::GetLinePosition(AssDialogue *diag) {
|
2014-04-14 19:58:46 +02:00
|
|
|
auto blocks = diag->ParseTags();
|
2011-11-06 18:18:20 +01:00
|
|
|
|
2012-12-02 19:24:49 +01:00
|
|
|
if (Vector2D ret = vec_or_bad(find_tag(blocks, "\\pos"), 0, 1)) return ret;
|
|
|
|
if (Vector2D ret = vec_or_bad(find_tag(blocks, "\\move"), 0, 1)) return ret;
|
2011-11-06 18:18:20 +01:00
|
|
|
|
|
|
|
// Get default position
|
2014-03-04 17:32:29 +01:00
|
|
|
auto margin = diag->Margin;
|
2007-07-01 02:19:55 +02:00
|
|
|
int align = 2;
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
if (AssStyle *style = c->ass->GetStyle(diag->Style)) {
|
2007-07-01 02:19:55 +02:00
|
|
|
align = style->alignment;
|
2012-10-10 16:04:44 +02:00
|
|
|
for (int i = 0; i < 3; i++) {
|
2011-11-06 18:18:20 +01:00
|
|
|
if (margin[i] == 0)
|
|
|
|
margin[i] = style->Margin[i];
|
2007-07-01 02:19:55 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
param_vec align_tag;
|
2012-03-09 01:23:22 +01:00
|
|
|
int ovr_align = 0;
|
2012-12-10 23:19:28 +01:00
|
|
|
if ((align_tag = find_tag(blocks, "\\an")))
|
|
|
|
ovr_align = (*align_tag)[0].Get<int>(ovr_align);
|
2012-12-02 19:24:49 +01:00
|
|
|
else if ((align_tag = find_tag(blocks, "\\a")))
|
2012-12-09 17:29:02 +01:00
|
|
|
ovr_align = AssStyle::SsaToAss((*align_tag)[0].Get<int>(2));
|
2010-06-24 03:23:43 +02:00
|
|
|
|
2012-03-09 01:23:22 +01:00
|
|
|
if (ovr_align > 0 && ovr_align <= 9)
|
|
|
|
align = ovr_align;
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
// Alignment type
|
|
|
|
int hor = (align - 1) % 3;
|
|
|
|
int vert = (align - 1) / 3;
|
|
|
|
|
|
|
|
// Calculate positions
|
|
|
|
int x, y;
|
|
|
|
if (hor == 0)
|
|
|
|
x = margin[0];
|
|
|
|
else if (hor == 1)
|
|
|
|
x = (script_res.X() + margin[0] - margin[1]) / 2;
|
2011-11-07 05:14:09 +01:00
|
|
|
else
|
2012-02-16 04:52:50 +01:00
|
|
|
x = script_res.X() - margin[1];
|
2011-11-06 18:18:20 +01:00
|
|
|
|
|
|
|
if (vert == 0)
|
|
|
|
y = script_res.Y() - margin[2];
|
|
|
|
else if (vert == 1)
|
|
|
|
y = script_res.Y() / 2;
|
2011-11-07 05:14:09 +01:00
|
|
|
else
|
2011-11-06 18:18:20 +01:00
|
|
|
y = margin[2];
|
|
|
|
|
|
|
|
return Vector2D(x, y);
|
2007-07-01 02:19:55 +02:00
|
|
|
}
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
Vector2D VisualToolBase::GetLineOrigin(AssDialogue *diag) {
|
2014-04-14 19:58:46 +02:00
|
|
|
auto blocks = diag->ParseTags();
|
2012-12-02 19:24:49 +01:00
|
|
|
return vec_or_bad(find_tag(blocks, "\\org"), 0, 1);
|
2011-11-06 18:18:20 +01:00
|
|
|
}
|
2010-06-24 03:23:43 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
bool VisualToolBase::GetLineMove(AssDialogue *diag, Vector2D &p1, Vector2D &p2, int &t1, int &t2) {
|
2014-04-14 19:58:46 +02:00
|
|
|
auto blocks = diag->ParseTags();
|
2010-06-24 03:23:43 +02:00
|
|
|
|
2012-12-02 19:24:49 +01:00
|
|
|
param_vec tag = find_tag(blocks, "\\move");
|
2011-11-06 18:18:20 +01:00
|
|
|
if (!tag)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
p1 = vec_or_bad(tag, 0, 1);
|
|
|
|
p2 = vec_or_bad(tag, 2, 3);
|
|
|
|
// VSFilter actually defaults to -1, but it uses <= 0 to check for default and 0 seems less bug-prone
|
2012-12-09 17:29:02 +01:00
|
|
|
t1 = (*tag)[4].Get<int>(0);
|
|
|
|
t2 = (*tag)[5].Get<int>(0);
|
2010-06-24 03:23:43 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
return p1 && p2;
|
2007-07-04 02:36:04 +02:00
|
|
|
}
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
void VisualToolBase::GetLineRotation(AssDialogue *diag, float &rx, float &ry, float &rz) {
|
2010-06-24 03:23:43 +02:00
|
|
|
rx = ry = rz = 0.f;
|
2007-07-29 11:15:32 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
if (AssStyle *style = c->ass->GetStyle(diag->Style))
|
2010-06-01 05:21:20 +02:00
|
|
|
rz = style->angle;
|
2007-07-01 02:19:55 +02:00
|
|
|
|
2014-04-14 19:58:46 +02:00
|
|
|
auto blocks = diag->ParseTags();
|
2010-06-24 03:23:43 +02:00
|
|
|
|
2012-12-02 19:24:49 +01:00
|
|
|
if (param_vec tag = find_tag(blocks, "\\frx"))
|
2012-12-10 23:19:28 +01:00
|
|
|
rx = tag->front().Get(rx);
|
2012-12-02 19:24:49 +01:00
|
|
|
if (param_vec tag = find_tag(blocks, "\\fry"))
|
2012-12-10 23:19:28 +01:00
|
|
|
ry = tag->front().Get(ry);
|
2012-12-02 19:24:49 +01:00
|
|
|
if (param_vec tag = find_tag(blocks, "\\frz"))
|
2012-12-10 23:19:28 +01:00
|
|
|
rz = tag->front().Get(rz);
|
2012-12-02 19:24:49 +01:00
|
|
|
else if ((tag = find_tag(blocks, "\\fr")))
|
2012-12-10 23:19:28 +01:00
|
|
|
rz = tag->front().Get(rz);
|
2007-07-01 02:19:55 +02:00
|
|
|
}
|
|
|
|
|
2013-12-14 16:45:26 +01:00
|
|
|
void VisualToolBase::GetLineShear(AssDialogue *diag, float& fax, float& fay) {
|
|
|
|
fax = fay = 0.f;
|
|
|
|
|
2014-04-14 19:58:46 +02:00
|
|
|
auto blocks = diag->ParseTags();
|
2013-12-14 16:45:26 +01:00
|
|
|
|
|
|
|
if (param_vec tag = find_tag(blocks, "\\fax"))
|
|
|
|
fax = tag->front().Get(fax);
|
|
|
|
if (param_vec tag = find_tag(blocks, "\\fay"))
|
|
|
|
fay = tag->front().Get(fay);
|
|
|
|
}
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
void VisualToolBase::GetLineScale(AssDialogue *diag, Vector2D &scale) {
|
|
|
|
float x = 100.f, y = 100.f;
|
2007-07-01 02:19:55 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
if (AssStyle *style = c->ass->GetStyle(diag->Style)) {
|
2011-11-06 18:18:20 +01:00
|
|
|
x = style->scalex;
|
|
|
|
y = style->scaley;
|
2007-07-01 02:19:55 +02:00
|
|
|
}
|
|
|
|
|
2014-04-14 19:58:46 +02:00
|
|
|
auto blocks = diag->ParseTags();
|
2010-06-24 03:23:43 +02:00
|
|
|
|
2012-12-02 19:24:49 +01:00
|
|
|
if (param_vec tag = find_tag(blocks, "\\fscx"))
|
2012-12-10 23:19:28 +01:00
|
|
|
x = tag->front().Get(x);
|
2012-12-02 19:24:49 +01:00
|
|
|
if (param_vec tag = find_tag(blocks, "\\fscy"))
|
2012-12-10 23:19:28 +01:00
|
|
|
y = tag->front().Get(y);
|
2010-06-24 03:23:43 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
scale = Vector2D(x, y);
|
2007-07-01 02:19:55 +02:00
|
|
|
}
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
void VisualToolBase::GetLineClip(AssDialogue *diag, Vector2D &p1, Vector2D &p2, bool &inverse) {
|
2008-09-10 18:13:54 +02:00
|
|
|
inverse = false;
|
2007-07-01 02:19:55 +02:00
|
|
|
|
2014-04-14 19:58:46 +02:00
|
|
|
auto blocks = diag->ParseTags();
|
2012-12-02 19:24:49 +01:00
|
|
|
param_vec tag = find_tag(blocks, "\\iclip");
|
2011-11-06 18:18:20 +01:00
|
|
|
if (tag)
|
|
|
|
inverse = true;
|
|
|
|
else
|
2012-12-02 19:24:49 +01:00
|
|
|
tag = find_tag(blocks, "\\clip");
|
2010-05-16 08:39:11 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
if (tag && tag->size() == 4) {
|
|
|
|
p1 = vec_or_bad(tag, 0, 1);
|
|
|
|
p2 = vec_or_bad(tag, 2, 3);
|
|
|
|
}
|
|
|
|
else {
|
2011-12-07 00:13:06 +01:00
|
|
|
p1 = Vector2D(0, 0);
|
2011-11-06 18:18:20 +01:00
|
|
|
p2 = script_res - 1;
|
|
|
|
}
|
2007-07-01 02:19:55 +02:00
|
|
|
}
|
2007-07-01 05:57:34 +02:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string VisualToolBase::GetLineVectorClip(AssDialogue *diag, int &scale, bool &inverse) {
|
2014-04-14 19:58:46 +02:00
|
|
|
auto blocks = diag->ParseTags();
|
2011-11-06 18:18:20 +01:00
|
|
|
|
2007-07-05 06:32:46 +02:00
|
|
|
scale = 1;
|
2008-09-10 18:13:54 +02:00
|
|
|
inverse = false;
|
2011-11-06 18:18:20 +01:00
|
|
|
|
2012-12-02 19:24:49 +01:00
|
|
|
param_vec tag = find_tag(blocks, "\\iclip");
|
2011-11-06 18:18:20 +01:00
|
|
|
if (tag)
|
|
|
|
inverse = true;
|
|
|
|
else
|
2012-12-02 19:24:49 +01:00
|
|
|
tag = find_tag(blocks, "\\clip");
|
2011-11-06 18:18:20 +01:00
|
|
|
|
|
|
|
if (tag && tag->size() == 4) {
|
2014-05-29 00:19:05 +02:00
|
|
|
return agi::format("m %d %d l %d %d %d %d %d %d"
|
|
|
|
, (*tag)[0].Get<int>(), (*tag)[1].Get<int>()
|
|
|
|
, (*tag)[2].Get<int>(), (*tag)[1].Get<int>()
|
|
|
|
, (*tag)[2].Get<int>(), (*tag)[3].Get<int>()
|
|
|
|
, (*tag)[0].Get<int>(), (*tag)[3].Get<int>());
|
2007-07-05 06:32:46 +02:00
|
|
|
}
|
2011-11-06 18:18:20 +01:00
|
|
|
if (tag) {
|
2012-12-09 17:29:02 +01:00
|
|
|
scale = std::max((*tag)[0].Get(scale), 1);
|
2013-01-04 16:01:50 +01:00
|
|
|
return (*tag)[1].Get<std::string>("");
|
2007-07-05 06:32:46 +02:00
|
|
|
}
|
2011-11-06 18:18:20 +01:00
|
|
|
|
|
|
|
return "";
|
2007-07-05 06:32:46 +02:00
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
void VisualToolBase::SetSelectedOverride(std::string const& tag, std::string const& value) {
|
2012-11-05 17:20:58 +01:00
|
|
|
for (auto line : c->selectionController->GetSelectedSet())
|
|
|
|
SetOverride(line, tag, value);
|
2011-11-06 18:18:20 +01:00
|
|
|
}
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
void VisualToolBase::SetOverride(AssDialogue* line, std::string const& tag, std::string const& value) {
|
2010-05-20 10:55:29 +02:00
|
|
|
if (!line) return;
|
|
|
|
|
2012-12-30 00:53:56 +01:00
|
|
|
std::string removeTag;
|
2011-09-28 21:43:11 +02:00
|
|
|
if (tag == "\\1c") removeTag = "\\c";
|
2011-11-06 18:18:20 +01:00
|
|
|
else if (tag == "\\frz") removeTag = "\\fr";
|
2011-09-28 21:43:11 +02:00
|
|
|
else if (tag == "\\pos") removeTag = "\\move";
|
|
|
|
else if (tag == "\\move") removeTag = "\\pos";
|
|
|
|
else if (tag == "\\clip") removeTag = "\\iclip";
|
|
|
|
else if (tag == "\\iclip") removeTag = "\\clip";
|
2010-05-20 10:55:29 +02:00
|
|
|
|
|
|
|
// Get block at start
|
2014-04-14 19:58:46 +02:00
|
|
|
auto blocks = line->ParseTags();
|
|
|
|
AssDialogueBlock *block = blocks.front().get();
|
2010-05-20 10:55:29 +02:00
|
|
|
|
2014-12-26 17:51:14 +01:00
|
|
|
if (block->GetType() == AssBlockType::OVERRIDE) {
|
|
|
|
auto ovr = static_cast<AssDialogueBlockOverride*>(block);
|
2010-05-20 10:55:29 +02:00
|
|
|
// Remove old of same
|
2010-06-04 05:08:04 +02:00
|
|
|
for (size_t i = 0; i < ovr->Tags.size(); i++) {
|
2012-12-30 00:53:56 +01:00
|
|
|
std::string const& name = ovr->Tags[i].Name;
|
2010-05-20 10:55:29 +02:00
|
|
|
if (tag == name || removeTag == name) {
|
|
|
|
ovr->Tags.erase(ovr->Tags.begin() + i);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
2013-01-04 16:01:50 +01:00
|
|
|
ovr->AddTag(tag + value);
|
2010-05-20 10:55:29 +02:00
|
|
|
|
2012-12-02 19:24:49 +01:00
|
|
|
line->UpdateText(blocks);
|
2010-05-20 10:55:29 +02:00
|
|
|
}
|
2012-12-30 18:04:43 +01:00
|
|
|
else
|
2013-01-04 16:01:50 +01:00
|
|
|
line->Text = "{" + tag + value + "}" + line->Text.get();
|
2007-07-01 05:57:34 +02:00
|
|
|
}
|
2010-05-20 10:55:46 +02:00
|
|
|
|
2010-05-20 10:55:52 +02:00
|
|
|
// If only export worked
|
2010-05-20 10:55:46 +02:00
|
|
|
template class VisualTool<VisualDraggableFeature>;
|
2010-05-20 10:55:52 +02:00
|
|
|
template class VisualTool<ClipCorner>;
|
|
|
|
template class VisualTool<VisualToolDragDraggableFeature>;
|
|
|
|
template class VisualTool<VisualToolVectorClipDraggableFeature>;
|