1
// Copyright (c) 2007, Rodrigo Braz Monteiro
2
// All rights reserved.
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are met:
7
// * Redistributions of source code must retain the above copyright notice,
8
// this list of conditions and the following disclaimer.
9
// * Redistributions in binary form must reproduce the above copyright notice,
10
// this list of conditions and the following disclaimer in the documentation
11
// and/or other materials provided with the distribution.
12
// * Neither the name of the Aegisub Group nor the names of its contributors
13
// may be used to endorse or promote products derived from this software
14
// without specific prior written permission.
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
// POSSIBILITY OF SUCH DAMAGE.
28
// -----------------------------------------------------------------------------
32
// Website: http://aegisub.cellosoft.com
33
// Contact: mailto:zeratul@cellosoft.com
41
#include "visual_tool_rotatez.h"
42
#include "subs_grid.h"
43
#include "subs_edit_box.h"
45
#include "ass_dialogue.h"
51
VisualToolRotateZ::VisualToolRotateZ(VideoDisplay *_parent)
54
_parent->ShowCursor(false);
61
void VisualToolRotateZ::Update() {
63
GetParent()->Render();
69
void VisualToolRotateZ::Draw() {
71
AssDialogue *line = GetActiveDialogueLine();
79
if (dragging) GetLinePosition(line,dx,dy);
80
else GetLinePosition(line,dx,dy,orgx,orgy);
81
int radius = (int) sqrt(double((dx-orgx)*(dx-orgx)+(dy-orgy)*(dy-orgy)));
83
if (radius < 50) radius = 50;
93
GetLineRotation(line,rx,ry,rz);
94
if (line == curDiag) rz = curAngle;
99
GetLineScale(line,scalX,scalY);
102
int deltax = int(cos(rz*3.1415926536/180.0)*radius);
103
int deltay = int(-sin(rz*3.1415926536/180.0)*radius);
106
SetLineColour(colour[0]);
107
SetFillColour(colour[1],0.3f);
109
// Set up the projection
110
glMatrixMode(GL_MODELVIEW);
113
glTranslatef(dx,dy,-1.0f);
114
float matrix[16] = { 2500, 0, 0, 0, 0, 2500, 0, 0, 0, 0, 1, 1, 0, 0, 2500, 2500 };
115
glMultMatrixf(matrix);
116
glScalef(1.0f,1.0f,8.0f);
117
glRotatef(ry,0.0f,-1.0f,0.0f);
118
glRotatef(rx,-1.0f,0.0f,0.0f);
119
glScalef(scalX/100.0f,scalY/100.0f,1.0f);
122
DrawRing(0,0,radius+4,radius-4);
124
// Draw markers around circle
126
float markStart = -90.0f / markers;
127
float markEnd = markStart+(180.0f/markers);
128
for (int i=0;i<markers;i++) {
129
float angle = i*(360.0f/markers);
130
DrawRing(0,0,radius+30,radius+12,radius/radius,angle+markStart,angle+markEnd);
134
SetLineColour(colour[3],1.0f,2);
135
DrawLine(deltax,deltay,-deltax,-deltay);
137
// Draw the connection line
138
if (orgx != odx && orgy != ody) {
139
double angle = atan2(double(dy-ody),double(odx-dx)) + rz*3.1415926536/180.0;
140
int fx = int(cos(angle)*oRadius);
141
int fy = -int(sin(angle)*oRadius);
143
int mdx = int(cos(rz*3.1415926536/180.0)*20);
144
int mdy = int(-sin(rz*3.1415926536/180.0)*20);
145
DrawLine(fx-mdx,fy-mdy,fx+mdx,fy+mdy);
148
// Draw the rotation line
149
SetLineColour(colour[0],1.0f,1);
150
SetFillColour(colour[1],0.3f);
151
DrawCircle(deltax,deltay,4);
156
// Draw line to mouse
157
if (mouseX != -1 && !dragging && GetHighlightedFeature() == -1) {
158
SetLineColour(colour[0]);
159
DrawLine(dx,dy,mx,my);
166
void VisualToolRotateZ::InitializeHold() {
167
GetLinePosition(curDiag,odx,ody,orgx,orgy);
168
startAngle = atan2(double(orgy-mouseY*sh/h),double(mouseX*sw/w-orgx)) * 180.0 / 3.1415926535897932;
169
GetLineRotation(curDiag,rx,ry,origAngle);
170
curAngle = origAngle;
171
curDiag->StripTag(_T("\\frz"));
172
curDiag->StripTag(_T("\\fr"));
178
void VisualToolRotateZ::UpdateHold() {
180
float screenAngle = atan2(double(orgy-mouseY*sh/h),double(mouseX*sw/w-orgx)) * 180.0 / 3.1415926535897932;
181
curAngle = screenAngle - startAngle + origAngle;
182
while (curAngle < 0.0f) curAngle += 360.0f;
183
while (curAngle >= 360.0f) curAngle -= 360.0f;
187
curAngle = (float)((int)((curAngle+15.0f)/30.0f))*30.0f;
188
if (curAngle == 360.0f) curAngle = 0.0f;
195
void VisualToolRotateZ::CommitHold() {
196
SetOverride(_T("\\frz"),PrettyFloat(wxString::Format(_T("(%0.3f)"),curAngle)));
202
void VisualToolRotateZ::PopulateFeatureList() {
204
curDiag = GetActiveDialogueLine();
205
GetLinePosition(curDiag,odx,ody,orgx,orgy);
209
VisualDraggableFeature &feat = features.back();
213
feat.type = DRAG_BIG_TRIANGLE;
217
///////////////////////////
218
// Update dragging of \org
219
void VisualToolRotateZ::UpdateDrag(VisualDraggableFeature &feature) {
225
///////////////////////////
226
// Commit dragging of \org
227
void VisualToolRotateZ::CommitDrag(VisualDraggableFeature &feature) {
228
SetOverride(_T("\\org"),wxString::Format(_T("(%i,%i)"),feature.x,feature.y));
234
void VisualToolRotateZ::DoRefresh() {
235
AssDialogue *line = GetActiveDialogueLine();
236
GetLinePosition(line,odx,ody,orgx,orgy);
237
GetLineRotation(line,rx,ry,curAngle);