2011-11-06 18:18:20 +01:00
|
|
|
// Copyright (c) 2011, 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/
|
2007-07-01 02:19:55 +02:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file visual_tool.cpp
|
|
|
|
/// @brief Base class for visual typesetting functions
|
|
|
|
/// @ingroup visual_ts
|
2007-07-01 02:19:55 +02:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#ifndef AGI_PRE
|
2010-06-14 21:26:27 +02:00
|
|
|
#include <algorithm>
|
2009-09-10 15:06:40 +02:00
|
|
|
#endif
|
|
|
|
|
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_override.h"
|
|
|
|
#include "ass_style.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "ass_time.h"
|
2011-01-16 08:17:08 +01:00
|
|
|
#include "include/aegisub/context.h"
|
2010-05-21 03:13:36 +02:00
|
|
|
#include "main.h"
|
2007-07-01 02:19:55 +02:00
|
|
|
#include "utils.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "video_context.h"
|
|
|
|
#include "video_display.h"
|
|
|
|
#include "video_provider_manager.h"
|
2010-05-20 10:55:46 +02:00
|
|
|
#include "visual_feature.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
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
template<class C, class F>
|
|
|
|
static void for_each(C &range, F func) {
|
|
|
|
std::for_each(range.begin(), range.end(), func);
|
|
|
|
}
|
|
|
|
|
|
|
|
using std::tr1::placeholders::_1;
|
2010-05-16 08:39:11 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
const wxColour VisualToolBase::colour[4] = {wxColour(106,32,19), wxColour(255,169,40), wxColour(255,253,185), wxColour(187,0,0)};
|
|
|
|
|
|
|
|
VisualToolBase::VisualToolBase(VideoDisplay *parent, agi::Context *context)
|
|
|
|
: c(context)
|
2010-05-20 10:55:58 +02:00
|
|
|
, parent(parent)
|
2010-05-16 08:39:11 +02:00
|
|
|
, holding(false)
|
2011-11-06 18:18:20 +01:00
|
|
|
, active_line(0)
|
2010-05-16 08:39:11 +02:00
|
|
|
, dragging(false)
|
2011-11-06 18:18:20 +01:00
|
|
|
, frame_number(c->videoController->GetFrameN())
|
|
|
|
, left_click(false)
|
|
|
|
, left_double(false)
|
|
|
|
, shift_down(false)
|
|
|
|
, ctrl_down(false)
|
|
|
|
, alt_down(false)
|
|
|
|
, file_changed_connection(c->ass->AddCommitListener(&VisualToolBase::OnCommit, this))
|
|
|
|
, commit_id(-1)
|
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();
|
2011-01-16 08:17:36 +01:00
|
|
|
c->selectionController->AddSelectionListener(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
|
|
|
VisualToolBase::~VisualToolBase() {
|
2011-01-16 08:17:36 +01:00
|
|
|
c->selectionController->RemoveSelectionListener(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;
|
|
|
|
left_click = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualToolBase::OnActiveLineChanged(AssDialogue *new_line) {
|
|
|
|
if (!IsDisplayed(new_line))
|
|
|
|
new_line = 0;
|
|
|
|
|
|
|
|
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();
|
|
|
|
return
|
|
|
|
line &&
|
2011-12-22 22:28:51 +01:00
|
|
|
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;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
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)
|
|
|
|
, sel_changed(false)
|
|
|
|
{
|
|
|
|
active_feature = features.begin();
|
|
|
|
}
|
|
|
|
|
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) {
|
2011-11-06 18:18:20 +01:00
|
|
|
left_click = event.LeftDown();
|
|
|
|
left_double = event.LeftDClick();
|
|
|
|
shift_down = event.ShiftDown();
|
|
|
|
ctrl_down = event.CmdDown();
|
|
|
|
alt_down = event.AltDown();
|
|
|
|
|
|
|
|
mouse_pos = event.GetPosition();
|
|
|
|
|
|
|
|
bool need_render = false;
|
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
|
|
|
|
2012-05-05 04:11:15 +02:00
|
|
|
if (event.Entering() && OPT_GET("Tool/Visual/Autohide")->GetBool())
|
2011-11-06 18:18:20 +01:00
|
|
|
need_render = true;
|
2007-07-01 04:23:57 +02:00
|
|
|
|
2010-05-26 09:17:39 +02:00
|
|
|
if (!dragging) {
|
2011-11-06 18:18:20 +01:00
|
|
|
feature_iterator prev_feature = active_feature;
|
|
|
|
|
|
|
|
int max_layer = INT_MIN;
|
|
|
|
active_feature = features.end();
|
|
|
|
for (feature_iterator cur = features.begin(); cur != features.end(); ++cur) {
|
|
|
|
if (cur->IsMouseOver(mouse_pos) && cur->layer >= max_layer) {
|
|
|
|
active_feature = cur;
|
|
|
|
max_layer = cur->layer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
need_render |= active_feature != prev_feature;
|
2010-05-26 09:17:39 +02:00
|
|
|
}
|
2010-05-20 10:55:35 +02:00
|
|
|
|
|
|
|
if (dragging) {
|
|
|
|
// continue drag
|
|
|
|
if (event.LeftIsDown()) {
|
2011-11-06 18:18:20 +01:00
|
|
|
for_each(sel_features, bind(&FeatureType::UpdateDrag, _1,
|
|
|
|
mouse_pos - drag_start, shift_down));
|
|
|
|
for_each(sel_features, bind(&VisualTool<FeatureType>::UpdateDrag, this, _1));
|
2010-10-26 06:12:10 +02:00
|
|
|
Commit();
|
2011-11-06 18:18:20 +01:00
|
|
|
need_render = true;
|
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
|
2011-11-06 18:18:20 +01:00
|
|
|
if (active_feature != features.end() && !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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
active_feature = features.end();
|
2010-05-20 10:55:35 +02:00
|
|
|
parent->ReleaseMouse();
|
|
|
|
parent->SetFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (holding) {
|
|
|
|
if (event.LeftIsDown()) {
|
|
|
|
UpdateHold();
|
2011-11-06 18:18:20 +01:00
|
|
|
need_render = true;
|
2007-07-07 07:51:18 +02:00
|
|
|
}
|
2010-05-20 10:55:35 +02:00
|
|
|
// end hold
|
|
|
|
else {
|
|
|
|
holding = false;
|
|
|
|
|
|
|
|
parent->ReleaseMouse();
|
|
|
|
parent->SetFocus();
|
|
|
|
}
|
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
|
2011-11-06 18:18:20 +01:00
|
|
|
if (active_feature != features.end()) {
|
|
|
|
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)) {
|
|
|
|
for_each(sel_features, bind(&VisualDraggableFeature::StartDrag, _1));
|
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();
|
2010-06-28 09:13:15 +02:00
|
|
|
Selection sel;
|
2011-01-16 08:17:36 +01:00
|
|
|
sel.insert(c->selectionController->GetActiveLine());
|
|
|
|
c->selectionController->SetSelectedSet(sel);
|
2011-11-06 18:18:20 +01:00
|
|
|
need_render = true;
|
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
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
//if (need_render)
|
|
|
|
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() {
|
2011-11-06 18:18:20 +01:00
|
|
|
gl.SetLineColour(colour[0], 1.0f, 2);
|
2010-06-30 08:29:14 +02:00
|
|
|
for (feature_iterator cur = features.begin(); cur != features.end(); ++cur) {
|
2011-11-06 18:18:20 +01:00
|
|
|
int fill = 1;
|
|
|
|
if (cur == active_feature)
|
2010-05-26 09:17:39 +02:00
|
|
|
fill = 2;
|
2011-11-06 18:18:20 +01:00
|
|
|
else if (sel_features.count(cur))
|
2010-05-26 09:17:39 +02:00
|
|
|
fill = 3;
|
2011-11-06 18:18:20 +01:00
|
|
|
gl.SetFillColour(colour[fill], 0.6f);
|
|
|
|
cur->Draw(gl);
|
2007-07-01 09:09:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
template<class FeatureType>
|
2011-11-06 18:18:20 +01:00
|
|
|
void VisualTool<FeatureType>::SetSelection(feature_iterator feat, bool clear) {
|
|
|
|
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) {
|
|
|
|
Selection sel;
|
|
|
|
if (!clear)
|
|
|
|
sel = c->selectionController->GetSelectedSet();
|
|
|
|
if (sel.insert(feat->line).second)
|
|
|
|
c->selectionController->SetSelectedSet(sel);
|
2010-06-28 09:13:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class FeatureType>
|
2011-11-06 18:18:20 +01:00
|
|
|
void VisualTool<FeatureType>::RemoveSelection(feature_iterator feat) {
|
|
|
|
if (!sel_features.erase(feat) || !feat->line) return;
|
2010-06-28 09:13:15 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
for (selection_iterator it = sel_features.begin(); it != sel_features.end(); ++it) {
|
|
|
|
if ((*it)->line == feat->line) return;
|
|
|
|
}
|
2010-06-28 09:13:15 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
Selection 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
|
|
|
|
2012-05-05 04:11:09 +02:00
|
|
|
c->selectionController->SetSelectionAndActive(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
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
typedef const std::vector<AssOverrideParameter*> * param_vec;
|
2010-05-26 09:17:39 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
// Parse line on creation and unparse at the end of scope
|
|
|
|
struct scoped_tag_parse {
|
|
|
|
AssDialogue *diag;
|
|
|
|
scoped_tag_parse(AssDialogue *diag) : diag(diag) { diag->ParseASSTags(); }
|
|
|
|
~scoped_tag_parse() { diag->ClearBlocks(); }
|
2010-06-24 03:23:43 +02:00
|
|
|
};
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
// Find a tag's parameters in a line or return NULL if it's not found
|
|
|
|
static param_vec find_tag(const AssDialogue *line, wxString tag_name) {
|
|
|
|
for (size_t i = 0; i < line->Blocks.size(); ++i) {
|
2010-06-24 03:23:43 +02:00
|
|
|
const AssDialogueBlockOverride *ovr = dynamic_cast<const AssDialogueBlockOverride*>(line->Blocks[i]);
|
|
|
|
if (!ovr) continue;
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
for (size_t j = 0; j < ovr->Tags.size(); ++j) {
|
|
|
|
if (ovr->Tags[j]->Name == tag_name)
|
|
|
|
return &ovr->Tags[j]->Params;
|
2010-06-24 03:23:43 +02:00
|
|
|
}
|
|
|
|
}
|
2011-11-06 18:18:20 +01:00
|
|
|
|
|
|
|
return 0;
|
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 ||
|
|
|
|
(*tag)[x_idx]->omitted || (*tag)[y_idx]->omitted ||
|
|
|
|
(*tag)[x_idx]->GetType() == VARDATA_NONE || (*tag)[y_idx]->GetType() == VARDATA_NONE)
|
|
|
|
{
|
2011-12-07 00:13:06 +01:00
|
|
|
return Vector2D();
|
2011-11-06 18:18:20 +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) {
|
|
|
|
scoped_tag_parse parse(diag);
|
|
|
|
|
|
|
|
if (Vector2D ret = vec_or_bad(find_tag(diag, "\\pos"), 0, 1)) return ret;
|
|
|
|
if (Vector2D ret = vec_or_bad(find_tag(diag, "\\move"), 0, 1)) return ret;
|
|
|
|
|
|
|
|
// Get default position
|
2007-07-01 02:19:55 +02:00
|
|
|
int margin[4];
|
2011-11-06 18:18:20 +01:00
|
|
|
std::copy(diag->Margin, diag->Margin + 4, margin);
|
2007-07-01 02:19:55 +02:00
|
|
|
int align = 2;
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
if (AssStyle *style = c->ass->GetStyle(diag->Style)) {
|
2007-07-01 02:19:55 +02:00
|
|
|
align = style->alignment;
|
2011-11-06 18:18:20 +01:00
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
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;
|
2011-11-06 18:18:20 +01:00
|
|
|
if ((align_tag = find_tag(diag, "\\an")) && !(*align_tag)[0]->omitted)
|
2012-03-09 01:23:22 +01:00
|
|
|
ovr_align = (*align_tag)[0]->Get<int>();
|
2012-03-25 06:04:54 +02:00
|
|
|
else if ((align_tag = find_tag(diag, "\\a")))
|
|
|
|
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) {
|
|
|
|
scoped_tag_parse parse(diag);
|
|
|
|
return vec_or_bad(find_tag(diag, "\\org"), 0, 1);
|
|
|
|
}
|
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) {
|
|
|
|
scoped_tag_parse parse(diag);
|
2010-06-24 03:23:43 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
param_vec tag = find_tag(diag, "\\move");
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2011-11-06 18:18:20 +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
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
scoped_tag_parse parse(diag);
|
2010-06-24 03:23:43 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
if (param_vec tag = find_tag(diag, "\\frx"))
|
|
|
|
rx = tag->front()->Get<float>(rx);
|
|
|
|
if (param_vec tag = find_tag(diag, "\\fry"))
|
|
|
|
ry = tag->front()->Get<float>(ry);
|
|
|
|
if (param_vec tag = find_tag(diag, "\\frz"))
|
|
|
|
rz = tag->front()->Get<float>(rz);
|
2011-12-28 22:27:22 +01:00
|
|
|
else if ((tag = find_tag(diag, "\\fr")))
|
2011-11-06 18:18:20 +01:00
|
|
|
rz = tag->front()->Get<float>(rz);
|
2007-07-01 02:19:55 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
if (AssStyle *style = c->ass->GetStyle(diag->Style)) {
|
|
|
|
x = style->scalex;
|
|
|
|
y = style->scaley;
|
2007-07-01 02:19:55 +02:00
|
|
|
}
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
scoped_tag_parse parse(diag);
|
2010-06-24 03:23:43 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
if (param_vec tag = find_tag(diag, "\\fscx"))
|
|
|
|
x = tag->front()->Get<float>(x);
|
|
|
|
if (param_vec tag = find_tag(diag, "\\fscy"))
|
|
|
|
y = tag->front()->Get<float>(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
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
scoped_tag_parse parse(diag);
|
|
|
|
param_vec tag = find_tag(diag, "\\iclip");
|
|
|
|
if (tag)
|
|
|
|
inverse = true;
|
|
|
|
else
|
|
|
|
tag = find_tag(diag, "\\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
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
wxString VisualToolBase::GetLineVectorClip(AssDialogue *diag, int &scale, bool &inverse) {
|
|
|
|
scoped_tag_parse parse(diag);
|
|
|
|
|
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
|
|
|
|
|
|
|
param_vec tag = find_tag(diag, "\\iclip");
|
|
|
|
if (tag)
|
|
|
|
inverse = true;
|
|
|
|
else
|
|
|
|
tag = find_tag(diag, "\\clip");
|
|
|
|
|
|
|
|
if (tag && tag->size() == 4) {
|
|
|
|
return wxString::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-01-26 01:29:08 +01:00
|
|
|
scale = std::max((*tag)[0]->Get(scale), 1);
|
2011-11-06 18:18:20 +01:00
|
|
|
return (*tag)[1]->Get<wxString>("");
|
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
|
|
|
}
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
void VisualToolBase::SetSelectedOverride(wxString const& tag, wxString const& value) {
|
|
|
|
for_each(c->selectionController->GetSelectedSet(),
|
|
|
|
bind(&VisualToolBase::SetOverride, this, _1, tag, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualToolBase::SetOverride(AssDialogue* line, wxString const& tag, wxString const& value) {
|
2010-05-20 10:55:29 +02:00
|
|
|
if (!line) return;
|
|
|
|
|
|
|
|
wxString 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
|
|
|
|
|
|
|
wxString insert = tag + value;
|
|
|
|
|
|
|
|
// Get block at start
|
|
|
|
line->ParseASSTags();
|
2011-11-06 18:18:20 +01:00
|
|
|
AssDialogueBlock *block = line->Blocks.front();
|
2010-05-20 10:55:29 +02:00
|
|
|
|
|
|
|
// Get current block as plain or override
|
2010-06-04 05:08:04 +02:00
|
|
|
assert(dynamic_cast<AssDialogueBlockDrawing*>(block) == NULL);
|
2010-05-20 10:55:29 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
if (dynamic_cast<AssDialogueBlockPlain*>(block))
|
2011-09-28 21:43:11 +02:00
|
|
|
line->Text = "{" + insert + "}" + line->Text;
|
2011-11-06 18:18:20 +01:00
|
|
|
else if (AssDialogueBlockOverride *ovr = dynamic_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++) {
|
|
|
|
wxString name = ovr->Tags[i]->Name;
|
2010-05-20 10:55:29 +02:00
|
|
|
if (tag == name || removeTag == name) {
|
2010-06-04 05:08:04 +02:00
|
|
|
delete ovr->Tags[i];
|
2010-05-20 10:55:29 +02:00
|
|
|
ovr->Tags.erase(ovr->Tags.begin() + i);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
2010-06-04 05:08:04 +02:00
|
|
|
ovr->AddTag(insert);
|
2010-05-20 10:55:29 +02:00
|
|
|
|
|
|
|
line->UpdateText();
|
|
|
|
}
|
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>;
|