2007-07-01 05:36:17 +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.
|
|
|
|
//
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// AEGISUB
|
|
|
|
//
|
|
|
|
// Website: http://aegisub.cellosoft.com
|
|
|
|
// Contact: mailto:zeratul@cellosoft.com
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
// Headers
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2007-07-01 05:36:17 +02:00
|
|
|
#include "visual_tool_drag.h"
|
|
|
|
#include "subs_grid.h"
|
|
|
|
#include "subs_edit_box.h"
|
|
|
|
#include "ass_file.h"
|
|
|
|
#include "ass_dialogue.h"
|
|
|
|
#include "utils.h"
|
2007-07-01 09:09:37 +02:00
|
|
|
#include "vfr.h"
|
2007-07-01 05:36:17 +02:00
|
|
|
|
|
|
|
|
2007-07-04 06:24:47 +02:00
|
|
|
///////
|
|
|
|
// IDs
|
|
|
|
enum {
|
2007-07-07 07:51:18 +02:00
|
|
|
BUTTON_TOGGLE_MOVE = VISUAL_SUB_TOOL_START
|
2007-07-04 06:24:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-07-01 05:36:17 +02:00
|
|
|
///////////////
|
|
|
|
// Constructor
|
2007-07-07 05:21:52 +02:00
|
|
|
VisualToolDrag::VisualToolDrag(VideoDisplay *_parent,wxToolBar *toolBar)
|
2007-07-01 05:36:17 +02:00
|
|
|
: VisualTool(_parent)
|
|
|
|
{
|
|
|
|
_parent->ShowCursor(false);
|
2007-07-07 05:21:52 +02:00
|
|
|
//toolBar->AddTool(BUTTON_TOGGLE_MOVE,_T("Toggle Move/Pos"),wxBITMAP(visual_move_conv_move));
|
|
|
|
toggleMove = new wxBitmapButton(toolBar,BUTTON_TOGGLE_MOVE,wxBITMAP(visual_move_conv_move),wxDefaultPosition);
|
2007-07-04 06:24:47 +02:00
|
|
|
ConnectButton(toggleMove);
|
2007-07-07 05:21:52 +02:00
|
|
|
toolBar->AddControl(toggleMove);
|
2007-07-04 06:24:47 +02:00
|
|
|
toggleMoveOnMove = true;
|
2007-07-07 05:21:52 +02:00
|
|
|
//UpdateToggleButtons();
|
|
|
|
toolBar->Realize();
|
|
|
|
toolBar->Show(true);
|
2007-07-04 06:24:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////
|
|
|
|
// Update toggle buttons
|
|
|
|
void VisualToolDrag::UpdateToggleButtons() {
|
|
|
|
// Check which bitmap to use
|
|
|
|
bool toMove = true;
|
|
|
|
AssDialogue *line = GetActiveDialogueLine();
|
|
|
|
if (line) {
|
|
|
|
int x1,y1,x2,y2,t1,t2;
|
|
|
|
bool hasMove;
|
|
|
|
GetLineMove(line,hasMove,x1,y1,x2,y2,t1,t2);
|
|
|
|
toMove = !hasMove;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No change needed
|
|
|
|
if (toMove == toggleMoveOnMove) return;
|
|
|
|
|
|
|
|
// Change bitmap
|
|
|
|
if (toMove) toggleMove->SetBitmapLabel(wxBITMAP(visual_move_conv_move));
|
|
|
|
else toggleMove->SetBitmapLabel(wxBITMAP(visual_move_conv_pos));
|
|
|
|
toggleMoveOnMove = toMove;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////
|
|
|
|
// Toggle button pressed
|
|
|
|
void VisualToolDrag::OnButton(wxCommandEvent &event) {
|
|
|
|
// Get line
|
|
|
|
AssDialogue *line = GetActiveDialogueLine();
|
|
|
|
if (!line) return;
|
|
|
|
|
|
|
|
// Toggle \move <-> \pos
|
|
|
|
if (event.GetId() == BUTTON_TOGGLE_MOVE) {
|
|
|
|
// Get coordinates
|
|
|
|
int x1,y1,x2,y2,t1,t2;
|
|
|
|
bool hasMove;
|
|
|
|
GetLinePosition(line,x1,y1);
|
|
|
|
GetLineMove(line,hasMove,x1,y1,x2,y2,t1,t2);
|
|
|
|
|
|
|
|
// Replace tag
|
|
|
|
if (hasMove) SetOverride(_T("\\pos"),wxString::Format(_T("(%i,%i)"),x1,y1));
|
|
|
|
else SetOverride(_T("\\move"),wxString::Format(_T("(%i,%i,%i,%i,%i,%i)"),x1,y1,x1,y1,0,line->End.GetMS() - line->Start.GetMS()));
|
|
|
|
SubtitlesGrid *grid = VideoContext::Get()->grid;
|
|
|
|
grid->editBox->CommitText();
|
|
|
|
grid->ass->FlagAsModified(_("visual typesetting"));
|
|
|
|
grid->CommitChanges(false,true);
|
|
|
|
|
|
|
|
// Update display
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////
|
|
|
|
// Refresh
|
|
|
|
void VisualToolDrag::DoRefresh() {
|
|
|
|
UpdateToggleButtons();
|
2007-07-01 05:36:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////
|
|
|
|
// Update
|
|
|
|
void VisualToolDrag::Update() {
|
|
|
|
GetParent()->Render();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////
|
|
|
|
// Draw
|
|
|
|
void VisualToolDrag::Draw() {
|
2007-07-01 09:09:37 +02:00
|
|
|
DrawAllFeatures();
|
2007-07-04 02:36:04 +02:00
|
|
|
|
|
|
|
// Draw arrows
|
|
|
|
for (size_t i=0;i<features.size();i++) {
|
2007-07-04 22:25:24 +02:00
|
|
|
if (features[i].brother[0] != -1 && (features[i].type == DRAG_BIG_CIRCLE || features[i].type == DRAG_BIG_TRIANGLE)) {
|
2007-07-04 02:36:04 +02:00
|
|
|
// Get features
|
|
|
|
VisualDraggableFeature *p1,*p2;
|
2007-07-04 22:25:24 +02:00
|
|
|
p2 = &features[i];
|
|
|
|
p1 = &features[p2->brother[0]];
|
2007-07-04 02:36:04 +02:00
|
|
|
|
2007-07-04 22:25:24 +02:00
|
|
|
// Has arrow?
|
|
|
|
bool hasArrow = p2->type == DRAG_BIG_CIRCLE;
|
|
|
|
int arrowLen = hasArrow ? 10 : 0;
|
|
|
|
|
|
|
|
// See if the distance between them is enough
|
2007-07-04 02:36:04 +02:00
|
|
|
int dx = p2->x - p1->x;
|
|
|
|
int dy = p2->y - p1->y;
|
|
|
|
int dist = (int)sqrt(double(dx*dx + dy*dy));
|
2007-07-04 22:25:24 +02:00
|
|
|
if (dist < 20+arrowLen) continue;
|
2007-07-04 02:36:04 +02:00
|
|
|
|
|
|
|
// Get end points
|
|
|
|
int x1 = p1->x + dx*10/dist;
|
2007-07-04 22:25:24 +02:00
|
|
|
int x2 = p2->x - dx*(10+arrowLen)/dist;
|
2007-07-04 02:36:04 +02:00
|
|
|
int y1 = p1->y + dy*10/dist;
|
2007-07-04 22:25:24 +02:00
|
|
|
int y2 = p2->y - dy*(10+arrowLen)/dist;
|
2007-07-04 02:36:04 +02:00
|
|
|
|
|
|
|
// Draw arrow
|
2007-07-04 22:25:24 +02:00
|
|
|
if (hasArrow) {
|
|
|
|
// Calculate angle
|
|
|
|
double angle = atan2(double(y2-y1),double(x2-x1))+1.570796;
|
|
|
|
int sx = int(cos(angle)*4);
|
|
|
|
int sy = int(-sin(angle)*4);
|
|
|
|
|
|
|
|
// Arrow line
|
|
|
|
SetLineColour(colour[3],0.8f,2);
|
|
|
|
DrawLine(x1,y1,x2,y2);
|
|
|
|
|
|
|
|
// Arrow head
|
|
|
|
DrawLine(x2+sx,y2-sy,x2-sx,y2+sy);
|
|
|
|
DrawLine(x2+sx,y2-sy,x2+dx*10/dist,y2+dy*10/dist);
|
|
|
|
DrawLine(x2-sx,y2+sy,x2+dx*10/dist,y2+dy*10/dist);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw dashed line
|
|
|
|
else {
|
|
|
|
SetLineColour(colour[3],0.5f,2);
|
2007-07-05 06:32:46 +02:00
|
|
|
DrawDashedLine(x1,y1,x2,y2,6);
|
2007-07-04 22:25:24 +02:00
|
|
|
}
|
2007-07-04 02:36:04 +02:00
|
|
|
}
|
|
|
|
}
|
2007-07-01 05:36:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////
|
2007-07-01 09:09:37 +02:00
|
|
|
// Populate list
|
|
|
|
void VisualToolDrag::PopulateFeatureList() {
|
|
|
|
// Clear features
|
|
|
|
features.clear();
|
|
|
|
|
|
|
|
// Get video data
|
|
|
|
int numRows = VideoContext::Get()->grid->GetRows();
|
|
|
|
int framen = VideoContext::Get()->GetFrameN();
|
|
|
|
|
|
|
|
// For each line
|
|
|
|
AssDialogue *diag;
|
|
|
|
for (int i=numRows;--i>=0;) {
|
|
|
|
diag = VideoContext::Get()->grid->GetDialogue(i);
|
|
|
|
if (diag) {
|
|
|
|
// Line visible?
|
|
|
|
int f1 = VFR_Output.GetFrameAtTime(diag->Start.GetMS(),true);
|
|
|
|
int f2 = VFR_Output.GetFrameAtTime(diag->End.GetMS(),false);
|
|
|
|
if (f1 <= framen && f2 >= framen) {
|
|
|
|
// Get position
|
2007-07-04 02:36:04 +02:00
|
|
|
int x1,x2,y1,y2;
|
|
|
|
int t1=0;
|
|
|
|
int t2=diag->End.GetMS()-diag->Start.GetMS();
|
2007-07-01 09:09:37 +02:00
|
|
|
int torgx,torgy;
|
2007-07-04 02:36:04 +02:00
|
|
|
bool hasMove;
|
|
|
|
GetLinePosition(diag,x1,y1,torgx,torgy);
|
|
|
|
GetLineMove(diag,hasMove,x1,y1,x2,y2,t1,t2);
|
2007-07-01 09:09:37 +02:00
|
|
|
|
|
|
|
// Create \pos feature
|
|
|
|
VisualDraggableFeature feat;
|
2007-07-04 02:36:04 +02:00
|
|
|
feat.x = x1;
|
|
|
|
feat.y = y1;
|
2007-07-01 09:09:37 +02:00
|
|
|
feat.layer = 0;
|
|
|
|
feat.type = DRAG_BIG_SQUARE;
|
2007-07-04 02:36:04 +02:00
|
|
|
feat.value = t1;
|
2007-07-01 09:09:37 +02:00
|
|
|
feat.line = diag;
|
|
|
|
feat.lineN = i;
|
|
|
|
features.push_back(feat);
|
2007-07-04 22:25:24 +02:00
|
|
|
int parentN = features.size()-1;
|
2007-07-04 02:36:04 +02:00
|
|
|
|
|
|
|
// Create move destination feature
|
|
|
|
if (hasMove) {
|
|
|
|
feat.x = x2;
|
|
|
|
feat.y = y2;
|
|
|
|
feat.layer = 1;
|
|
|
|
feat.type = DRAG_BIG_CIRCLE;
|
|
|
|
feat.value = t2;
|
|
|
|
feat.line = diag;
|
|
|
|
feat.lineN = i;
|
|
|
|
features.push_back(feat);
|
2007-07-04 03:22:10 +02:00
|
|
|
|
|
|
|
// Add each other as brothers.
|
|
|
|
int n = features.size();
|
2007-07-04 22:25:24 +02:00
|
|
|
features[n-1].brother[0] = parentN;
|
|
|
|
features[parentN].brother[0] = n-1;
|
2007-07-04 02:36:04 +02:00
|
|
|
}
|
2007-07-04 09:26:24 +02:00
|
|
|
|
|
|
|
// Create org feature
|
|
|
|
if (torgx != x1 || torgy != y1) {
|
|
|
|
feat.x = torgx;
|
|
|
|
feat.y = torgy;
|
|
|
|
feat.layer = -1;
|
|
|
|
feat.type = DRAG_BIG_TRIANGLE;
|
|
|
|
feat.value = 0;
|
|
|
|
feat.line = diag;
|
|
|
|
feat.lineN = i;
|
|
|
|
features.push_back(feat);
|
2007-07-04 22:25:24 +02:00
|
|
|
|
|
|
|
// Add each other as brothers.
|
|
|
|
int n = features.size();
|
|
|
|
features[n-1].brother[0] = parentN;
|
|
|
|
features[parentN].brother[1] = n-1;
|
2007-07-04 09:26:24 +02:00
|
|
|
}
|
2007-07-01 09:09:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-01 05:36:17 +02:00
|
|
|
|
2007-07-01 09:09:37 +02:00
|
|
|
//////////////////
|
|
|
|
// Start dragging
|
|
|
|
void VisualToolDrag::InitializeDrag(VisualDraggableFeature &feature) {
|
2007-07-01 05:36:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////
|
2007-07-01 09:09:37 +02:00
|
|
|
// Update drag
|
|
|
|
void VisualToolDrag::UpdateDrag(VisualDraggableFeature &feature) {
|
2007-07-04 02:36:04 +02:00
|
|
|
// Update "value" to reflect the time of the frame in which the feature is being dragged
|
|
|
|
int time = VFR_Output.GetTimeAtFrame(frame_n,true,true);
|
|
|
|
feature.value = MID(0,time - feature.line->Start.GetMS(),feature.line->End.GetMS()-feature.line->Start.GetMS());
|
2007-07-01 05:36:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
///////////////
|
2007-07-01 09:09:37 +02:00
|
|
|
// Commit drag
|
|
|
|
void VisualToolDrag::CommitDrag(VisualDraggableFeature &feature) {
|
2007-07-04 09:26:24 +02:00
|
|
|
// Origin
|
|
|
|
if (feature.type == DRAG_BIG_TRIANGLE) {
|
|
|
|
SetOverride(_T("\\org"),wxString::Format(_T("(%i,%i)"),feature.x,feature.y));
|
|
|
|
}
|
|
|
|
|
2007-07-04 02:36:04 +02:00
|
|
|
// Position
|
2007-07-04 09:26:24 +02:00
|
|
|
else if (feature.brother[0] == -1) {
|
2007-07-04 02:36:04 +02:00
|
|
|
SetOverride(_T("\\pos"),wxString::Format(_T("(%i,%i)"),feature.x,feature.y));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Move
|
|
|
|
else {
|
|
|
|
// Get source on p1 and dest on p2
|
|
|
|
VisualDraggableFeature *p1,*p2;
|
|
|
|
p1 = &feature;
|
2007-07-04 03:22:10 +02:00
|
|
|
if (p1->type == DRAG_BIG_CIRCLE) p1 = &features[p1->brother[0]];
|
|
|
|
p2 = &features[p1->brother[0]];
|
2007-07-04 02:36:04 +02:00
|
|
|
|
|
|
|
// Set override
|
|
|
|
SetOverride(_T("\\move"),wxString::Format(_T("(%i,%i,%i,%i,%i,%i)"),p1->x,p1->y,p2->x,p2->y,p1->value,p2->value));
|
|
|
|
}
|
2007-07-01 05:36:17 +02:00
|
|
|
}
|