2007-07-01 04:23:57 +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 04:23:57 +02:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file visual_tool_rotatez.cpp
|
|
|
|
/// @brief 2D rotation in Z axis visual typesetting tool
|
|
|
|
/// @ingroup visual_ts
|
2007-07-01 04:23:57 +02:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2010-05-19 05:24:01 +02:00
|
|
|
#ifndef AGI_PRE
|
2010-06-28 09:13:15 +02:00
|
|
|
#include <cmath>
|
2010-05-19 05:24:01 +02:00
|
|
|
#endif
|
|
|
|
|
2007-07-01 04:23:57 +02:00
|
|
|
#include "ass_dialogue.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "ass_file.h"
|
|
|
|
#include "subs_edit_box.h"
|
|
|
|
#include "subs_grid.h"
|
2007-07-01 04:23:57 +02:00
|
|
|
#include "utils.h"
|
2010-06-18 09:14:00 +02:00
|
|
|
#include "video_context.h"
|
2009-09-10 03:41:34 +02:00
|
|
|
#include "video_display.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "visual_tool_rotatez.h"
|
2007-07-01 04:23:57 +02:00
|
|
|
|
2010-06-28 09:13:15 +02:00
|
|
|
static const float deg2rad = 3.1415926536f / 180.f;
|
|
|
|
static const float rad2deg = 180.f / 3.1415926536f;
|
|
|
|
|
2010-05-16 08:39:11 +02:00
|
|
|
VisualToolRotateZ::VisualToolRotateZ(VideoDisplay *parent, VideoState const& video, wxToolBar *)
|
2010-05-20 10:55:58 +02:00
|
|
|
: VisualTool<VisualDraggableFeature>(parent, video)
|
2007-07-01 04:23:57 +02:00
|
|
|
{
|
2007-07-27 06:50:15 +02:00
|
|
|
DoRefresh();
|
2007-07-01 04:23:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualToolRotateZ::Draw() {
|
2010-06-28 09:13:15 +02:00
|
|
|
if (!curDiag) return;
|
2007-07-01 04:23:57 +02:00
|
|
|
|
2007-07-04 23:47:26 +02:00
|
|
|
// Draw pivot
|
|
|
|
DrawAllFeatures();
|
|
|
|
|
2010-06-28 09:13:15 +02:00
|
|
|
int radius = (int)sqrt(double((posx-orgx)*(posx-orgx)+(posy-orgy)*(posy-orgy)));
|
2007-07-01 04:23:57 +02:00
|
|
|
int oRadius = radius;
|
|
|
|
if (radius < 50) radius = 50;
|
|
|
|
|
2010-06-28 09:13:15 +02:00
|
|
|
int deltax = int(cos(curAngle*deg2rad)*radius);
|
|
|
|
int deltay = int(-sin(curAngle*deg2rad)*radius);
|
2007-07-01 04:23:57 +02:00
|
|
|
|
|
|
|
// Set colours
|
|
|
|
SetLineColour(colour[0]);
|
|
|
|
SetFillColour(colour[1],0.3f);
|
|
|
|
|
|
|
|
// Set up the projection
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glPushMatrix();
|
|
|
|
glLoadIdentity();
|
2010-06-28 09:13:15 +02:00
|
|
|
glTranslatef(orgx,orgy,-1.f);
|
2007-07-01 04:23:57 +02:00
|
|
|
float matrix[16] = { 2500, 0, 0, 0, 0, 2500, 0, 0, 0, 0, 1, 1, 0, 0, 2500, 2500 };
|
|
|
|
glMultMatrixf(matrix);
|
2010-06-28 09:13:15 +02:00
|
|
|
glScalef(1.f,1.f,8.f);
|
|
|
|
glRotatef(ry,0.f,-1.f,0.f);
|
|
|
|
glRotatef(rx,-1.f,0.f,0.f);
|
|
|
|
glScalef(scaleX/100.f,scaleY/100.f,1.f);
|
2007-07-01 04:23:57 +02:00
|
|
|
|
|
|
|
// Draw the circle
|
|
|
|
DrawRing(0,0,radius+4,radius-4);
|
|
|
|
|
|
|
|
// Draw markers around circle
|
|
|
|
int markers = 6;
|
2010-06-28 09:13:15 +02:00
|
|
|
float markStart = -90.f / markers;
|
|
|
|
float markEnd = markStart+(180.f/markers);
|
2007-07-01 04:23:57 +02:00
|
|
|
for (int i=0;i<markers;i++) {
|
2010-06-28 09:13:15 +02:00
|
|
|
float angle = i*(360.f/markers);
|
2007-07-01 04:23:57 +02:00
|
|
|
DrawRing(0,0,radius+30,radius+12,radius/radius,angle+markStart,angle+markEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the baseline
|
2010-06-28 09:13:15 +02:00
|
|
|
SetLineColour(colour[3],1.f,2);
|
2007-07-01 04:23:57 +02:00
|
|
|
DrawLine(deltax,deltay,-deltax,-deltay);
|
|
|
|
|
|
|
|
// Draw the connection line
|
2010-06-28 09:13:15 +02:00
|
|
|
if (orgx != posx || orgy != posy) {
|
|
|
|
double angle = atan2(double(orgy-posy),double(posx-orgx)) + curAngle*deg2rad;
|
2007-07-01 04:23:57 +02:00
|
|
|
int fx = int(cos(angle)*oRadius);
|
|
|
|
int fy = -int(sin(angle)*oRadius);
|
|
|
|
DrawLine(0,0,fx,fy);
|
2010-06-28 09:13:15 +02:00
|
|
|
int mdx = int(cos(curAngle*deg2rad)*20);
|
|
|
|
int mdy = int(-sin(curAngle*deg2rad)*20);
|
2007-07-01 04:46:12 +02:00
|
|
|
DrawLine(fx-mdx,fy-mdy,fx+mdx,fy+mdy);
|
2007-07-01 04:23:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the rotation line
|
2010-06-28 09:13:15 +02:00
|
|
|
SetLineColour(colour[0],1.f,1);
|
2007-07-01 04:23:57 +02:00
|
|
|
SetFillColour(colour[1],0.3f);
|
|
|
|
DrawCircle(deltax,deltay,4);
|
|
|
|
|
|
|
|
glPopMatrix();
|
|
|
|
|
|
|
|
// Draw line to mouse
|
2010-06-07 09:24:37 +02:00
|
|
|
if (!dragging && !curFeature && video.x > INT_MIN && video.y > INT_MIN) {
|
2007-07-01 04:23:57 +02:00
|
|
|
SetLineColour(colour[0]);
|
2010-06-28 09:13:15 +02:00
|
|
|
DrawLine(orgx,orgy,video.x,video.y);
|
2007-07-01 04:23:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:35 +02:00
|
|
|
bool VisualToolRotateZ::InitializeHold() {
|
2010-06-28 09:13:15 +02:00
|
|
|
startAngle = atan2(double(orgy-video.y),double(video.x-orgx)) * rad2deg;
|
|
|
|
origAngle = curAngle;
|
2010-05-16 08:39:11 +02:00
|
|
|
curDiag->StripTag(L"\\frz");
|
|
|
|
curDiag->StripTag(L"\\fr");
|
2010-05-20 10:55:35 +02:00
|
|
|
|
|
|
|
return true;
|
2007-07-01 04:23:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualToolRotateZ::UpdateHold() {
|
2010-06-28 09:13:15 +02:00
|
|
|
float screenAngle = atan2(double(orgy-video.y),double(video.x-orgx)) * rad2deg;
|
2010-05-19 05:24:01 +02:00
|
|
|
curAngle = fmodf(screenAngle - startAngle + origAngle + 360.f, 360.f);
|
|
|
|
|
|
|
|
// Oh Snap
|
|
|
|
if (ctrlDown) {
|
2010-06-28 09:13:15 +02:00
|
|
|
curAngle = floorf(curAngle/30.f+.5f)*30.f;
|
|
|
|
if (curAngle > 359.f) curAngle = 0.f;
|
2007-07-01 04:23:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualToolRotateZ::CommitHold() {
|
2010-06-18 09:14:00 +02:00
|
|
|
wxArrayInt sel = grid->GetSelection();
|
|
|
|
for (wxArrayInt::const_iterator cur = sel.begin(); cur != sel.end(); ++cur) {
|
|
|
|
AssDialogue* line = grid->GetDialogue(*cur);
|
|
|
|
assert(line);
|
|
|
|
SetOverride(line, L"\\frz",wxString::Format(L"(%0.3g)",curAngle));
|
|
|
|
}
|
2007-07-01 04:23:57 +02:00
|
|
|
}
|
2007-07-04 23:47:26 +02:00
|
|
|
|
|
|
|
void VisualToolRotateZ::PopulateFeatureList() {
|
2010-06-24 03:23:43 +02:00
|
|
|
if (!curDiag) return;
|
2007-07-04 23:47:26 +02:00
|
|
|
|
|
|
|
// Set features
|
|
|
|
features.resize(1);
|
|
|
|
VisualDraggableFeature &feat = features.back();
|
|
|
|
feat.x = orgx;
|
|
|
|
feat.y = orgy;
|
|
|
|
feat.line = curDiag;
|
|
|
|
feat.type = DRAG_BIG_TRIANGLE;
|
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:58 +02:00
|
|
|
void VisualToolRotateZ::UpdateDrag(VisualDraggableFeature* feature) {
|
|
|
|
orgx = feature->x;
|
|
|
|
orgy = feature->y;
|
2007-07-04 23:47:26 +02:00
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:58 +02:00
|
|
|
void VisualToolRotateZ::CommitDrag(VisualDraggableFeature* feature) {
|
|
|
|
int x = feature->x;
|
|
|
|
int y = feature->y;
|
2010-05-16 08:39:11 +02:00
|
|
|
parent->ToScriptCoords(&x, &y);
|
2010-05-20 10:55:58 +02:00
|
|
|
SetOverride(feature->line, L"\\org",wxString::Format(L"(%i,%i)",x,y));
|
2007-07-04 23:47:26 +02:00
|
|
|
}
|
2007-07-27 06:50:15 +02:00
|
|
|
|
|
|
|
void VisualToolRotateZ::DoRefresh() {
|
2010-06-28 09:13:15 +02:00
|
|
|
if (!curDiag) return;
|
|
|
|
GetLinePosition(curDiag, posx, posy, orgx, orgy);
|
|
|
|
GetLineRotation(curDiag, rx, ry, curAngle);
|
|
|
|
GetLineScale(curDiag, scaleX, scaleY);
|
2007-07-27 06:50:15 +02:00
|
|
|
}
|