2007-07-01 02:19:55 +02:00
|
|
|
// Copyright (c) 2007, 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/
|
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>
|
2007-07-01 02:19:55 +02:00
|
|
|
#include <wx/glcanvas.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#endif
|
|
|
|
|
2007-09-12 01:22:26 +02:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <OpenGL/GL.h>
|
|
|
|
#else
|
|
|
|
#include <GL/gl.h>
|
|
|
|
#endif
|
2009-09-10 15:06:40 +02:00
|
|
|
|
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"
|
|
|
|
#include "export_visible_lines.h"
|
2010-05-21 03:13:36 +02:00
|
|
|
#include "main.h"
|
2007-07-01 02:19:55 +02:00
|
|
|
#include "options.h"
|
|
|
|
#include "subs_edit_box.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "subs_grid.h"
|
2007-07-01 02:19:55 +02:00
|
|
|
#include "utils.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "vfr.h"
|
|
|
|
#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"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "visual_tool.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
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
const wxColour IVisualTool::colour[4] = {wxColour(106,32,19), wxColour(255,169,40), wxColour(255,253,185), wxColour(187,0,0)};
|
2010-05-16 08:39:11 +02:00
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
template<class FeatureType>
|
|
|
|
VisualTool<FeatureType>::VisualTool(VideoDisplay *parent, VideoState const& video)
|
2010-06-04 05:07:33 +02:00
|
|
|
: realtime(OPT_GET("Video/Visual Realtime"))
|
|
|
|
, dragStartX(0)
|
2010-05-20 10:55:58 +02:00
|
|
|
, dragStartY(0)
|
|
|
|
, selChanged(false)
|
|
|
|
, parent(parent)
|
2010-05-16 08:39:11 +02:00
|
|
|
, holding(false)
|
|
|
|
, curDiag(NULL)
|
|
|
|
, dragging(false)
|
2010-05-26 09:17:39 +02:00
|
|
|
, externalChange(true)
|
2010-05-20 10:55:58 +02:00
|
|
|
, curFeature(NULL)
|
2010-05-16 08:39:11 +02:00
|
|
|
, dragListOK(false)
|
|
|
|
, frame_n(0)
|
2010-05-20 10:55:58 +02:00
|
|
|
, video(video)
|
|
|
|
, leftClick(false)
|
|
|
|
, leftDClick(false)
|
|
|
|
, shiftDown(false)
|
|
|
|
, ctrlDown(false)
|
|
|
|
, altDown(false)
|
2010-05-16 08:39:11 +02:00
|
|
|
{
|
2007-07-04 07:22:35 +02:00
|
|
|
if (VideoContext::Get()->IsLoaded()) {
|
|
|
|
frame_n = VideoContext::Get()->GetFrameN();
|
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
|
|
|
VideoContext::Get()->grid->AddSelectionListener(this);
|
2007-07-04 07:22:35 +02:00
|
|
|
}
|
2007-07-01 09:09:37 +02:00
|
|
|
|
2010-05-20 10:55:35 +02:00
|
|
|
PopulateFeatureList();
|
2007-07-01 02:19:55 +02:00
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
template<class FeatureType>
|
|
|
|
VisualTool<FeatureType>::~VisualTool() {
|
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
|
|
|
VideoContext::Get()->grid->RemoveSelectionListener(this);
|
2007-07-01 02:19:55 +02:00
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
template<class FeatureType>
|
|
|
|
void VisualTool<FeatureType>::OnMouseEvent (wxMouseEvent &event) {
|
2010-06-04 05:07:33 +02:00
|
|
|
bool realTime = realtime->GetBool();
|
2010-06-07 09:24:30 +02:00
|
|
|
bool needRender = false;
|
2007-07-01 04:23:57 +02:00
|
|
|
|
|
|
|
if (event.Leaving()) {
|
2007-07-08 21:50:54 +02:00
|
|
|
Update();
|
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
|
|
|
}
|
2010-06-18 09:14:06 +02:00
|
|
|
else if (event.Entering() && !OPT_GET("Tool/Visual/Always Show")->GetBool()) {
|
|
|
|
needRender = true;
|
|
|
|
}
|
2010-05-20 10:55:58 +02:00
|
|
|
externalChange = false;
|
|
|
|
|
2007-07-01 04:23:57 +02:00
|
|
|
leftClick = event.ButtonDown(wxMOUSE_BTN_LEFT);
|
|
|
|
leftDClick = event.LeftDClick();
|
|
|
|
shiftDown = event.m_shiftDown;
|
2007-09-22 00:56:44 +02:00
|
|
|
#ifdef __APPLE__
|
|
|
|
ctrlDown = event.m_metaDown; // Cmd key
|
|
|
|
#else
|
2007-07-01 04:23:57 +02:00
|
|
|
ctrlDown = event.m_controlDown;
|
2007-09-22 00:56:44 +02:00
|
|
|
#endif
|
2007-07-01 04:23:57 +02:00
|
|
|
altDown = event.m_altDown;
|
|
|
|
|
2010-05-20 10:55:35 +02:00
|
|
|
if (!dragListOK) {
|
|
|
|
PopulateFeatureList();
|
|
|
|
dragListOK = true;
|
|
|
|
}
|
2010-05-26 09:17:39 +02:00
|
|
|
if (!dragging) {
|
2010-06-11 04:24:59 +02:00
|
|
|
unsigned oldHigh = curFeatureI;
|
2010-05-26 09:17:39 +02:00
|
|
|
GetHighlightedFeature();
|
2010-06-07 09:24:30 +02:00
|
|
|
if (curFeatureI != oldHigh) needRender = true;
|
2010-05-26 09:17:39 +02:00
|
|
|
}
|
2010-05-20 10:55:35 +02:00
|
|
|
|
|
|
|
if (dragging) {
|
|
|
|
// continue drag
|
|
|
|
if (event.LeftIsDown()) {
|
2010-05-26 09:17:39 +02:00
|
|
|
for (selection_iterator cur = selFeatures.begin(); cur != selFeatures.end(); ++cur) {
|
|
|
|
features[*cur].x = (video.x - dragStartX + features[*cur].origX);
|
|
|
|
features[*cur].y = (video.y - dragStartY + features[*cur].origY);
|
2010-05-20 10:55:58 +02:00
|
|
|
if (shiftDown) {
|
|
|
|
if (abs(video.x - dragStartX) > abs(video.y - dragStartY)) {
|
2010-05-26 09:17:39 +02:00
|
|
|
features[*cur].y = features[*cur].origY;
|
2010-05-20 10:55:58 +02:00
|
|
|
}
|
|
|
|
else {
|
2010-05-26 09:17:39 +02:00
|
|
|
features[*cur].x = features[*cur].origX;
|
2010-05-20 10:55:58 +02:00
|
|
|
}
|
2010-05-20 10:55:35 +02:00
|
|
|
}
|
2010-05-26 09:17:39 +02:00
|
|
|
UpdateDrag(&features[*cur]);
|
2010-05-20 10:55:35 +02:00
|
|
|
|
2010-05-20 10:55:58 +02:00
|
|
|
if (realTime) {
|
2010-05-26 09:17:39 +02:00
|
|
|
CommitDrag(&features[*cur]);
|
2010-05-20 10:55:58 +02:00
|
|
|
}
|
2010-05-20 10:55:35 +02:00
|
|
|
}
|
2010-06-07 09:24:30 +02:00
|
|
|
if (realTime) {
|
|
|
|
Commit();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
needRender = true;
|
|
|
|
}
|
2007-07-01 09:09:37 +02:00
|
|
|
}
|
2010-05-20 10:55:35 +02:00
|
|
|
// end drag
|
|
|
|
else {
|
|
|
|
if (realTime) AssLimitToVisibleFilter::SetFrame(-1);
|
2007-07-01 09:09:37 +02:00
|
|
|
|
2010-05-20 10:55:35 +02:00
|
|
|
dragging = false;
|
|
|
|
|
2010-05-20 10:55:58 +02:00
|
|
|
// mouse didn't move, fiddle with selection
|
|
|
|
if (curFeature->x == curFeature->origX && curFeature->y == curFeature->origY) {
|
|
|
|
// Don't deselect stuff that was selected in this click's mousedown event
|
|
|
|
if (!selChanged) {
|
|
|
|
if (ctrlDown) {
|
|
|
|
// deselect this feature
|
2010-05-26 09:17:39 +02:00
|
|
|
RemoveSelection(curFeatureI);
|
2010-05-20 10:55:58 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// deselect everything else
|
|
|
|
ClearSelection();
|
2010-05-26 09:17:39 +02:00
|
|
|
AddSelection(curFeatureI);
|
2010-05-20 10:55:58 +02:00
|
|
|
}
|
2010-06-02 09:22:48 +02:00
|
|
|
SetEditbox();
|
2010-05-20 10:55:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2010-05-26 09:17:39 +02:00
|
|
|
for (selection_iterator cur = selFeatures.begin(); cur != selFeatures.end(); ++cur) {
|
|
|
|
CommitDrag(&features[*cur]);
|
2010-05-20 10:55:58 +02:00
|
|
|
}
|
|
|
|
Commit(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
curFeature = NULL;
|
2010-05-20 10:55:35 +02:00
|
|
|
parent->ReleaseMouse();
|
|
|
|
parent->SetFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (holding) {
|
|
|
|
// continue hold
|
|
|
|
if (event.LeftIsDown()) {
|
|
|
|
UpdateHold();
|
|
|
|
|
|
|
|
if (realTime) {
|
|
|
|
CommitHold();
|
|
|
|
Commit();
|
2007-07-07 07:51:18 +02:00
|
|
|
}
|
2010-06-07 09:24:30 +02:00
|
|
|
else {
|
|
|
|
needRender = true;
|
|
|
|
}
|
2007-07-07 07:51:18 +02:00
|
|
|
}
|
2010-05-20 10:55:35 +02:00
|
|
|
// end hold
|
|
|
|
else {
|
|
|
|
if (realTime) AssLimitToVisibleFilter::SetFrame(-1);
|
2007-07-07 07:51:18 +02:00
|
|
|
|
2010-05-20 10:55:35 +02:00
|
|
|
holding = false;
|
|
|
|
CommitHold();
|
|
|
|
Commit(true);
|
|
|
|
|
|
|
|
curDiag = NULL;
|
|
|
|
parent->ReleaseMouse();
|
|
|
|
parent->SetFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (leftClick) {
|
|
|
|
// start drag
|
2010-05-20 10:55:58 +02:00
|
|
|
if (curFeature) {
|
|
|
|
if (InitializeDrag(curFeature)) {
|
2010-05-26 09:17:39 +02:00
|
|
|
if (selFeatures.find(curFeatureI) == selFeatures.end()) {
|
2010-05-20 10:55:58 +02:00
|
|
|
selChanged = true;
|
|
|
|
if (!ctrlDown) {
|
|
|
|
ClearSelection();
|
|
|
|
}
|
2010-05-26 09:17:39 +02:00
|
|
|
AddSelection(curFeatureI);
|
2010-05-20 10:55:58 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
selChanged = false;
|
2010-05-26 09:17:39 +02:00
|
|
|
}
|
2010-06-02 09:22:48 +02:00
|
|
|
SetEditbox(curFeature->lineN);
|
2007-07-01 09:09:37 +02:00
|
|
|
|
2010-05-16 08:39:11 +02:00
|
|
|
dragStartX = video.x;
|
|
|
|
dragStartY = video.y;
|
2010-05-26 09:17:39 +02:00
|
|
|
for (selection_iterator cur = selFeatures.begin(); cur != selFeatures.end(); ++cur) {
|
|
|
|
features[*cur].origX = features[*cur].x;
|
|
|
|
features[*cur].origY = features[*cur].y;
|
2010-05-20 10:55:58 +02:00
|
|
|
}
|
2007-07-01 09:09:37 +02:00
|
|
|
|
|
|
|
dragging = true;
|
|
|
|
parent->CaptureMouse();
|
|
|
|
if (realTime) AssLimitToVisibleFilter::SetFrame(frame_n);
|
|
|
|
}
|
|
|
|
}
|
2010-05-20 10:55:35 +02:00
|
|
|
// start hold
|
|
|
|
else {
|
2010-05-26 09:17:39 +02:00
|
|
|
if (!altDown) {
|
|
|
|
ClearSelection();
|
|
|
|
SetEditbox();
|
2010-06-07 09:24:30 +02:00
|
|
|
needRender = true;
|
2010-05-26 09:17:39 +02:00
|
|
|
}
|
2007-07-01 04:23:57 +02:00
|
|
|
curDiag = GetActiveDialogueLine();
|
2010-05-20 10:55:35 +02:00
|
|
|
if (curDiag && InitializeHold()) {
|
2007-07-01 04:23:57 +02:00
|
|
|
holding = true;
|
|
|
|
parent->CaptureMouse();
|
|
|
|
if (realTime) AssLimitToVisibleFilter::SetFrame(frame_n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-07 09:24:30 +02:00
|
|
|
if (Update() || needRender) parent->Render();
|
2010-05-20 10:55:58 +02:00
|
|
|
externalChange = true;
|
2007-07-01 04:23:57 +02:00
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
template<class FeatureType>
|
2010-05-26 09:17:39 +02:00
|
|
|
void VisualTool<FeatureType>::Commit(bool full, wxString message) {
|
2007-07-07 09:27:28 +02:00
|
|
|
SubtitlesGrid *grid = VideoContext::Get()->grid;
|
2010-05-26 09:17:39 +02:00
|
|
|
if (full) {
|
|
|
|
if (message.empty()) {
|
|
|
|
message = _("visual typesetting");
|
|
|
|
}
|
|
|
|
grid->ass->FlagAsModified(message);
|
|
|
|
}
|
2007-07-07 09:27:28 +02:00
|
|
|
grid->CommitChanges(false,!full);
|
2010-06-04 05:07:41 +02:00
|
|
|
if (full)
|
|
|
|
grid->editBox->Update(false, true, false);
|
2007-07-07 09:27:28 +02:00
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
template<class FeatureType>
|
|
|
|
AssDialogue* VisualTool<FeatureType>::GetActiveDialogueLine() {
|
2007-07-01 04:23:57 +02:00
|
|
|
SubtitlesGrid *grid = VideoContext::Get()->grid;
|
2010-06-26 13:32:16 +02:00
|
|
|
AssDialogue *diag = grid->GetActiveLine();
|
2010-05-26 09:17:39 +02:00
|
|
|
if (grid->IsDisplayed(diag))
|
|
|
|
return diag;
|
|
|
|
return NULL;
|
2007-07-01 04:23:57 +02:00
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
template<class FeatureType>
|
2010-05-26 09:17:39 +02:00
|
|
|
void VisualTool<FeatureType>::GetHighlightedFeature() {
|
2010-05-16 08:39:11 +02:00
|
|
|
int highestLayerFound = INT_MIN;
|
2010-05-26 09:17:39 +02:00
|
|
|
curFeature = NULL;
|
|
|
|
curFeatureI = -1;
|
|
|
|
unsigned i = 0;
|
|
|
|
for (feature_iterator cur = features.begin(); cur != features.end(); ++cur, ++i) {
|
2010-05-20 10:55:58 +02:00
|
|
|
if (cur->IsMouseOver(video.x, video.y) && cur->layer > highestLayerFound) {
|
2010-05-26 09:17:39 +02:00
|
|
|
curFeature = &*cur;
|
|
|
|
curFeatureI = i;
|
2010-05-20 10:55:58 +02:00
|
|
|
highestLayerFound = cur->layer;
|
2007-07-01 09:09:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
template<class FeatureType>
|
|
|
|
void VisualTool<FeatureType>::DrawAllFeatures() {
|
2007-07-01 09:09:37 +02:00
|
|
|
if (!dragListOK) {
|
|
|
|
PopulateFeatureList();
|
|
|
|
dragListOK = true;
|
|
|
|
}
|
2007-07-04 08:50:03 +02:00
|
|
|
|
2010-06-04 05:07:46 +02:00
|
|
|
SetLineColour(colour[0],1.0f,2);
|
2010-05-26 09:17:39 +02:00
|
|
|
for (unsigned i = 0; i < features.size(); ++i) {
|
|
|
|
int fill;
|
|
|
|
if (&features[i] == curFeature)
|
|
|
|
fill = 2;
|
|
|
|
else if (selFeatures.find(i) != selFeatures.end())
|
|
|
|
fill = 3;
|
|
|
|
else
|
|
|
|
fill = 1;
|
2010-05-20 10:55:58 +02:00
|
|
|
SetFillColour(colour[fill],0.6f);
|
2010-05-26 09:17:39 +02:00
|
|
|
features[i].Draw(*this);
|
2007-07-01 09:09:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
template<class FeatureType>
|
|
|
|
void VisualTool<FeatureType>::Refresh() {
|
2007-07-01 09:09:37 +02:00
|
|
|
frame_n = VideoContext::Get()->GetFrameN();
|
2010-05-26 09:17:39 +02:00
|
|
|
if (externalChange) {
|
|
|
|
dragListOK = false;
|
|
|
|
DoRefresh();
|
|
|
|
}
|
2007-07-01 09:09:37 +02:00
|
|
|
}
|
2010-05-26 09:17:39 +02:00
|
|
|
template<class FeatureType>
|
|
|
|
void VisualTool<FeatureType>::AddSelection(unsigned i) {
|
|
|
|
assert(i < features.size());
|
|
|
|
|
|
|
|
if (selFeatures.insert(i).second && features[i].line) {
|
|
|
|
lineSelCount[features[i].lineN] += 1;
|
|
|
|
|
|
|
|
SubtitlesGrid *grid = VideoContext::Get()->grid;
|
|
|
|
grid->SelectRow(features[i].lineN, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class FeatureType>
|
|
|
|
void VisualTool<FeatureType>::RemoveSelection(unsigned i) {
|
|
|
|
assert(i < features.size());
|
|
|
|
|
|
|
|
if (selFeatures.erase(i) > 0 && features[i].line) {
|
|
|
|
// Deselect a line only if all features for that line have been
|
|
|
|
// deselected
|
|
|
|
int lineN = features[i].lineN;
|
|
|
|
lineSelCount[lineN] -= 1;
|
|
|
|
assert(lineSelCount[lineN] >= 0);
|
|
|
|
if (lineSelCount[lineN] <= 0) {
|
|
|
|
SubtitlesGrid *grid = VideoContext::Get()->grid;
|
|
|
|
grid->SelectRow(lineN, true, false);
|
|
|
|
|
|
|
|
// We may have just deselected the active line, so make sure the
|
|
|
|
// edit box is set to something sane
|
|
|
|
SetEditbox();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class FeatureType>
|
|
|
|
wxArrayInt VisualTool<FeatureType>::GetSelection() {
|
|
|
|
return VideoContext::Get()->grid->GetSelection();
|
|
|
|
}
|
|
|
|
|
2007-07-01 09:09:37 +02:00
|
|
|
|
2010-05-20 10:55:58 +02:00
|
|
|
template<class FeatureType>
|
2010-05-26 09:17:39 +02:00
|
|
|
void VisualTool<FeatureType>::ClearSelection(bool hard) {
|
|
|
|
if (hard) {
|
2010-06-27 09:53:25 +02:00
|
|
|
Selection sel;
|
|
|
|
VideoContext::Get()->grid->SetSelectedSet(sel);
|
2010-05-20 10:55:58 +02:00
|
|
|
}
|
|
|
|
selFeatures.clear();
|
2010-05-26 09:17:39 +02:00
|
|
|
lineSelCount.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class FeatureType>
|
|
|
|
void VisualTool<FeatureType>::SetEditbox(int lineN) {
|
|
|
|
VideoContext* con = VideoContext::Get();
|
|
|
|
if (lineN > -1) {
|
2010-06-26 13:32:16 +02:00
|
|
|
con->grid->SetActiveLine(con->grid->GetDialogue(lineN));
|
2010-05-26 09:17:39 +02:00
|
|
|
con->grid->SelectRow(lineN, true);
|
|
|
|
}
|
|
|
|
else {
|
2010-06-26 13:32:16 +02:00
|
|
|
Selection sel;
|
|
|
|
con->grid->GetSelectedSet(sel);
|
2010-05-26 09:17:39 +02:00
|
|
|
// If there is a selection and the edit box's line is in it, do nothing
|
|
|
|
// Otherwise set the edit box if there is a selection or the selection
|
|
|
|
// to the edit box if there is no selection
|
|
|
|
if (sel.empty()) {
|
2010-06-26 13:32:16 +02:00
|
|
|
sel.insert(con->grid->GetActiveLine());
|
|
|
|
con->grid->SetSelectedSet(sel);
|
2010-05-26 09:17:39 +02:00
|
|
|
}
|
2010-06-26 13:32:16 +02:00
|
|
|
else if (sel.find(con->grid->GetActiveLine()) == sel.end()) {
|
|
|
|
con->grid->SetActiveLine(con->grid->GetDialogue(con->grid->GetFirstSelRow()));
|
2010-05-26 09:17:39 +02:00
|
|
|
}
|
|
|
|
}
|
2010-05-20 10:55:58 +02:00
|
|
|
}
|
|
|
|
|
2010-06-24 03:23:43 +02:00
|
|
|
enum TagFoundType {
|
|
|
|
TAG_NOT_FOUND = 0,
|
|
|
|
PRIMARY_TAG_FOUND,
|
|
|
|
ALT_TAG_FOUND
|
|
|
|
};
|
|
|
|
|
|
|
|
/// @brief Get the first value set for a tag
|
|
|
|
/// @param line Line to get the value from
|
|
|
|
/// @param tag Tag to get the value of
|
|
|
|
/// @param n Number of parameters passed
|
|
|
|
/// @return Which tag (if any) was found
|
|
|
|
template<class T>
|
|
|
|
static TagFoundType get_value(const AssDialogue *line, wxString tag, size_t n, ...) {
|
|
|
|
wxString alt;
|
|
|
|
if (tag == L"\\pos") alt = L"\\move";
|
|
|
|
else if (tag == L"\\an") alt = L"\\a";
|
|
|
|
else if (tag == L"\\clip") alt = L"\\iclip";
|
|
|
|
|
|
|
|
for (size_t i = 0; i < line->Blocks.size(); i++) {
|
|
|
|
const AssDialogueBlockOverride *ovr = dynamic_cast<const AssDialogueBlockOverride*>(line->Blocks[i]);
|
|
|
|
if (!ovr) continue;
|
|
|
|
|
|
|
|
for (size_t j=0; j < ovr->Tags.size(); j++) {
|
|
|
|
const AssOverrideTag *cur = ovr->Tags[j];
|
|
|
|
if ((cur->Name == tag || cur->Name == alt) && cur->Params.size() >= n) {
|
|
|
|
va_list argp;
|
|
|
|
va_start(argp, n);
|
|
|
|
for (size_t j = 0; j < n; j++) {
|
|
|
|
T *val = va_arg(argp, T *);
|
|
|
|
*val = cur->Params[j]->Get<T>(*val);
|
|
|
|
}
|
|
|
|
va_end(argp);
|
|
|
|
return cur->Name == alt ? ALT_TAG_FOUND : PRIMARY_TAG_FOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TAG_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
template<class FeatureType>
|
|
|
|
void VisualTool<FeatureType>::GetLinePosition(AssDialogue *diag,int &x, int &y) {
|
2010-05-20 10:55:58 +02:00
|
|
|
int orgx,orgy;
|
2007-07-01 02:19:55 +02:00
|
|
|
GetLinePosition(diag,x,y,orgx,orgy);
|
|
|
|
}
|
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
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
template<class FeatureType>
|
|
|
|
void VisualTool<FeatureType>::GetLinePosition(AssDialogue *diag,int &x, int &y, int &orgx, int &orgy) {
|
2007-07-01 02:19:55 +02:00
|
|
|
int margin[4];
|
|
|
|
for (int i=0;i<4;i++) margin[i] = diag->Margin[i];
|
|
|
|
int align = 2;
|
|
|
|
|
|
|
|
AssStyle *style = VideoContext::Get()->grid->ass->GetStyle(diag->Style);
|
|
|
|
if (style) {
|
|
|
|
align = style->alignment;
|
|
|
|
for (int i=0;i<4;i++) {
|
|
|
|
if (margin[i] == 0) margin[i] = style->Margin[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int sw,sh;
|
|
|
|
VideoContext::Get()->GetScriptSize(sw,sh);
|
|
|
|
|
|
|
|
// Process margins
|
|
|
|
margin[1] = sw - margin[1];
|
2010-06-24 03:23:43 +02:00
|
|
|
margin[3] = sh - margin[2];
|
2007-07-01 02:19:55 +02:00
|
|
|
|
|
|
|
// Overrides processing
|
|
|
|
diag->ParseASSTags();
|
|
|
|
|
2010-06-24 03:23:43 +02:00
|
|
|
if (!get_value<int>(diag, "\\pos", 2, &x, &y)) {
|
|
|
|
if (get_value<int>(diag, "\\an", 1, &align) == ALT_TAG_FOUND) {
|
|
|
|
switch(align) {
|
|
|
|
case 1: case 2: case 3:
|
|
|
|
break;
|
|
|
|
case 5: case 6: case 7:
|
|
|
|
align += 2;
|
|
|
|
break;
|
|
|
|
case 9: case 10: case 11:
|
|
|
|
align -= 5;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
align = 2;
|
|
|
|
break;
|
2007-07-01 02:19:55 +02:00
|
|
|
}
|
|
|
|
}
|
2010-05-16 08:39:11 +02:00
|
|
|
// Alignment type
|
|
|
|
int hor = (align - 1) % 3;
|
|
|
|
int vert = (align - 1) / 3;
|
|
|
|
|
|
|
|
// Calculate positions
|
|
|
|
if (hor == 0) x = margin[0];
|
|
|
|
else if (hor == 1) x = (margin[0] + margin[1])/2;
|
|
|
|
else if (hor == 2) x = margin[1];
|
|
|
|
if (vert == 0) y = margin[3];
|
|
|
|
else if (vert == 1) y = (margin[2] + margin[3])/2;
|
|
|
|
else if (vert == 2) y = margin[2];
|
2007-07-01 02:19:55 +02:00
|
|
|
}
|
|
|
|
|
2010-05-16 08:39:11 +02:00
|
|
|
parent->FromScriptCoords(&x, &y);
|
2007-07-01 02:19:55 +02:00
|
|
|
|
2010-06-24 03:23:43 +02:00
|
|
|
if (!get_value<int>(diag, "\\org", 2, &orgx, &orgy)) {
|
2007-07-01 02:19:55 +02:00
|
|
|
orgx = x;
|
|
|
|
orgy = y;
|
|
|
|
}
|
2010-06-24 03:23:43 +02:00
|
|
|
else {
|
|
|
|
parent->FromScriptCoords(&orgx, &orgy);
|
|
|
|
}
|
|
|
|
|
|
|
|
diag->ClearBlocks();
|
2007-07-01 02:19:55 +02:00
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
template<class FeatureType>
|
|
|
|
void VisualTool<FeatureType>::GetLineMove(AssDialogue *diag,bool &hasMove,int &x1,int &y1,int &x2,int &y2,int &t1,int &t2) {
|
2007-07-04 02:36:04 +02:00
|
|
|
diag->ParseASSTags();
|
2010-06-24 03:23:43 +02:00
|
|
|
|
|
|
|
hasMove =
|
|
|
|
get_value<int>(diag, "\\move", 6, &x1, &y1, &x2, &y2, &t1, &t2) ||
|
|
|
|
get_value<int>(diag, "\\move", 4, &x1, &y1, &x2, &y2);
|
|
|
|
|
|
|
|
if (hasMove) {
|
|
|
|
parent->FromScriptCoords(&x1, &y1);
|
|
|
|
parent->FromScriptCoords(&x2, &y2);
|
2007-07-04 02:36:04 +02:00
|
|
|
}
|
2010-06-24 03:23:43 +02:00
|
|
|
|
2007-07-04 02:36:04 +02:00
|
|
|
diag->ClearBlocks();
|
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
template<class FeatureType>
|
|
|
|
void VisualTool<FeatureType>::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
|
|
|
|
2010-06-01 05:21:20 +02:00
|
|
|
AssStyle *style = VideoContext::Get()->grid->ass->GetStyle(diag->Style);
|
|
|
|
if (style) {
|
|
|
|
rz = style->angle;
|
|
|
|
}
|
|
|
|
|
2007-07-01 02:19:55 +02:00
|
|
|
diag->ParseASSTags();
|
|
|
|
|
2010-06-27 09:53:31 +02:00
|
|
|
get_value<float>(diag, L"\\frx", 1, &rx);
|
|
|
|
get_value<float>(diag, L"\\fry", 1, &ry);
|
|
|
|
get_value<float>(diag, L"\\frz", 1, &rz);
|
2010-06-24 03:23:43 +02:00
|
|
|
|
2007-07-01 02:19:55 +02:00
|
|
|
diag->ClearBlocks();
|
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
template<class FeatureType>
|
|
|
|
void VisualTool<FeatureType>::GetLineScale(AssDialogue *diag,float &scalX,float &scalY) {
|
2010-06-24 03:23:43 +02:00
|
|
|
scalX = scalY = 100.f;
|
2007-07-01 02:19:55 +02:00
|
|
|
|
2010-06-24 03:23:43 +02:00
|
|
|
AssStyle *style = VideoContext::Get()->grid->ass->GetStyle(diag->Style);
|
|
|
|
if (style) {
|
|
|
|
scalX = style->scalex;
|
|
|
|
scalY = style->scaley;
|
2007-07-01 02:19:55 +02:00
|
|
|
}
|
|
|
|
|
2010-06-24 03:23:43 +02:00
|
|
|
diag->ParseASSTags();
|
|
|
|
|
2010-06-27 09:53:31 +02:00
|
|
|
get_value<float>(diag, L"\\fscx", 1, &scalX);
|
|
|
|
get_value<float>(diag, L"\\fscy", 1, &scalY);
|
2010-06-24 03:23:43 +02:00
|
|
|
|
2007-07-01 02:19:55 +02:00
|
|
|
diag->ClearBlocks();
|
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
template<class FeatureType>
|
|
|
|
void VisualTool<FeatureType>::GetLineClip(AssDialogue *diag,int &x1,int &y1,int &x2,int &y2,bool &inverse) {
|
2007-07-01 02:19:55 +02:00
|
|
|
x1 = y1 = 0;
|
|
|
|
int sw,sh;
|
|
|
|
VideoContext::Get()->GetScriptSize(sw,sh);
|
|
|
|
x2 = sw-1;
|
|
|
|
y2 = sh-1;
|
2008-09-10 18:13:54 +02:00
|
|
|
inverse = false;
|
2007-07-01 02:19:55 +02:00
|
|
|
|
|
|
|
diag->ParseASSTags();
|
2010-06-24 03:23:43 +02:00
|
|
|
inverse = get_value<int>(diag, L"\\clip", 4, &x1, &y1, &x2, &y2) == ALT_TAG_FOUND;
|
2007-07-01 02:19:55 +02:00
|
|
|
diag->ClearBlocks();
|
2010-05-16 08:39:11 +02:00
|
|
|
|
|
|
|
parent->FromScriptCoords(&x1, &y1);
|
|
|
|
parent->FromScriptCoords(&x2, &y2);
|
2007-07-01 02:19:55 +02:00
|
|
|
}
|
2007-07-01 05:57:34 +02:00
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
template<class FeatureType>
|
|
|
|
wxString VisualTool<FeatureType>::GetLineVectorClip(AssDialogue *diag,int &scale,bool &inverse) {
|
2007-07-05 06:32:46 +02:00
|
|
|
scale = 1;
|
2008-09-10 18:13:54 +02:00
|
|
|
inverse = false;
|
2007-07-05 06:32:46 +02:00
|
|
|
diag->ParseASSTags();
|
2010-06-24 03:23:43 +02:00
|
|
|
|
|
|
|
int x1, y1, x2, y2;
|
|
|
|
TagFoundType res = get_value<int>(diag, L"\\clip", 4, &x1, &y1, &x2, &y2);
|
|
|
|
if (res) {
|
|
|
|
inverse = res == ALT_TAG_FOUND;
|
2007-07-05 06:32:46 +02:00
|
|
|
diag->ClearBlocks();
|
2010-06-24 03:23:43 +02:00
|
|
|
return wxString::Format(L"m %d %d l %d %d %d %d %d %d", x1, y1, x2, y1, x2, y2, x1, y2);
|
2007-07-05 06:32:46 +02:00
|
|
|
}
|
2010-06-24 03:23:43 +02:00
|
|
|
wxString result;
|
|
|
|
wxString scaleStr;
|
|
|
|
res = get_value<wxString>(diag, L"\\clip", 2, &scaleStr, &result);
|
|
|
|
inverse = res == ALT_TAG_FOUND;
|
|
|
|
if (!scaleStr.empty()) {
|
|
|
|
long s;
|
|
|
|
scaleStr.ToLong(&s);
|
|
|
|
scale = s;
|
2007-07-05 06:32:46 +02:00
|
|
|
}
|
|
|
|
diag->ClearBlocks();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/// @brief Set override
|
|
|
|
/// @param tag
|
|
|
|
/// @param value
|
2010-05-20 10:55:46 +02:00
|
|
|
template<class FeatureType>
|
|
|
|
void VisualTool<FeatureType>::SetOverride(AssDialogue* line, wxString tag, wxString value) {
|
2010-05-20 10:55:29 +02:00
|
|
|
if (!line) return;
|
|
|
|
|
|
|
|
wxString removeTag;
|
|
|
|
if (tag == L"\\1c") removeTag = L"\\c";
|
|
|
|
else if (tag == L"\\fr") removeTag = L"\\frz";
|
|
|
|
else if (tag == L"\\pos") removeTag = L"\\move";
|
|
|
|
else if (tag == L"\\move") removeTag = L"\\pos";
|
|
|
|
else if (tag == L"\\clip") removeTag = L"\\iclip";
|
|
|
|
else if (tag == L"\\iclip") removeTag = L"\\clip";
|
|
|
|
|
|
|
|
wxString insert = tag + value;
|
|
|
|
|
|
|
|
// Get block at start
|
|
|
|
line->ParseASSTags();
|
|
|
|
AssDialogueBlock *block = line->Blocks.at(0);
|
|
|
|
|
|
|
|
// Get current block as plain or override
|
|
|
|
AssDialogueBlockPlain *plain = dynamic_cast<AssDialogueBlockPlain*>(block);
|
|
|
|
AssDialogueBlockOverride *ovr = dynamic_cast<AssDialogueBlockOverride*>(block);
|
2010-06-04 05:08:04 +02:00
|
|
|
assert(dynamic_cast<AssDialogueBlockDrawing*>(block) == NULL);
|
2010-05-20 10:55:29 +02:00
|
|
|
|
|
|
|
if (plain) {
|
|
|
|
line->Text = L"{" + insert + L"}" + line->Text;
|
|
|
|
}
|
|
|
|
else if (ovr) {
|
|
|
|
// 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();
|
|
|
|
}
|
|
|
|
|
|
|
|
parent->SetFocus();
|
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>;
|