~ubuntu-branches/ubuntu/trusty/aegisub/trusty

« back to all changes in this revision

Viewing changes to src/visual_tool_rotatez.cpp

  • Committer: Package Import Robot
  • Author(s): Sebastian Reichel
  • Date: 2012-03-16 22:58:00 UTC
  • Revision ID: package-import@ubuntu.com-20120316225800-yfb8h9e5n04rk46a
Tags: upstream-2.1.9
ImportĀ upstreamĀ versionĀ 2.1.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2007, Rodrigo Braz Monteiro
 
2
// All rights reserved.
 
3
//
 
4
// Redistribution and use in source and binary forms, with or without
 
5
// modification, are permitted provided that the following conditions are met:
 
6
//
 
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.
 
15
//
 
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.
 
27
//
 
28
// -----------------------------------------------------------------------------
 
29
//
 
30
// AEGISUB
 
31
//
 
32
// Website: http://aegisub.cellosoft.com
 
33
// Contact: mailto:zeratul@cellosoft.com
 
34
//
 
35
 
 
36
 
 
37
///////////
 
38
// Headers
 
39
#include "config.h"
 
40
 
 
41
#include "visual_tool_rotatez.h"
 
42
#include "subs_grid.h"
 
43
#include "subs_edit_box.h"
 
44
#include "ass_file.h"
 
45
#include "ass_dialogue.h"
 
46
#include "utils.h"
 
47
 
 
48
 
 
49
///////////////
 
50
// Constructor
 
51
VisualToolRotateZ::VisualToolRotateZ(VideoDisplay *_parent)
 
52
: VisualTool(_parent)
 
53
{
 
54
        _parent->ShowCursor(false);
 
55
        DoRefresh();
 
56
}
 
57
 
 
58
 
 
59
//////////
 
60
// Update
 
61
void VisualToolRotateZ::Update() {
 
62
        // Render parent
 
63
        GetParent()->Render();
 
64
}
 
65
 
 
66
 
 
67
////////
 
68
// Draw
 
69
void VisualToolRotateZ::Draw() {
 
70
        // Get line to draw
 
71
        AssDialogue *line = GetActiveDialogueLine();
 
72
        if (!line) return;
 
73
 
 
74
        // Draw pivot
 
75
        DrawAllFeatures();
 
76
 
 
77
        // Radius
 
78
        int dx=0,dy=0;
 
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)));
 
82
        int oRadius = radius;
 
83
        if (radius < 50) radius = 50;
 
84
 
 
85
        // Pivot coordinates
 
86
        int odx = dx;
 
87
        int ody = dy;
 
88
        dx = orgx;
 
89
        dy = orgy;
 
90
 
 
91
        // Rotation
 
92
        float rz;
 
93
        GetLineRotation(line,rx,ry,rz);
 
94
        if (line == curDiag) rz = curAngle;
 
95
 
 
96
        // Get scale
 
97
        float scalX = 100.0f;
 
98
        float scalY = 100.0f;
 
99
        GetLineScale(line,scalX,scalY);
 
100
 
 
101
        // Get deltas
 
102
        int deltax = int(cos(rz*3.1415926536/180.0)*radius);
 
103
        int deltay = int(-sin(rz*3.1415926536/180.0)*radius);
 
104
 
 
105
        // Set colours
 
106
        SetLineColour(colour[0]);
 
107
        SetFillColour(colour[1],0.3f);
 
108
 
 
109
        // Set up the projection
 
110
        glMatrixMode(GL_MODELVIEW);
 
111
        glPushMatrix();
 
112
        glLoadIdentity();
 
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);
 
120
 
 
121
        // Draw the circle
 
122
        DrawRing(0,0,radius+4,radius-4);
 
123
 
 
124
        // Draw markers around circle
 
125
        int markers = 6;
 
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);
 
131
        }
 
132
 
 
133
        // Draw the baseline
 
134
        SetLineColour(colour[3],1.0f,2);
 
135
        DrawLine(deltax,deltay,-deltax,-deltay);
 
136
 
 
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);
 
142
                DrawLine(0,0,fx,fy);
 
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);
 
146
        }
 
147
 
 
148
        // Draw the rotation line
 
149
        SetLineColour(colour[0],1.0f,1);
 
150
        SetFillColour(colour[1],0.3f);
 
151
        DrawCircle(deltax,deltay,4);
 
152
 
 
153
        // Restore
 
154
        glPopMatrix();
 
155
 
 
156
        // Draw line to mouse
 
157
        if (mouseX != -1 && !dragging && GetHighlightedFeature() == -1) {
 
158
                SetLineColour(colour[0]);
 
159
                DrawLine(dx,dy,mx,my);
 
160
        }
 
161
}
 
162
 
 
163
 
 
164
/////////////////
 
165
// Start holding
 
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"));
 
173
}
 
174
 
 
175
 
 
176
///////////////
 
177
// Update hold
 
178
void VisualToolRotateZ::UpdateHold() {
 
179
        // Find angle
 
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;
 
184
 
 
185
        // Snap
 
186
        if (shiftDown) {
 
187
                curAngle = (float)((int)((curAngle+15.0f)/30.0f))*30.0f;
 
188
                if (curAngle == 360.0f) curAngle = 0.0f;
 
189
        }
 
190
}
 
191
 
 
192
 
 
193
///////////////
 
194
// Commit hold
 
195
void VisualToolRotateZ::CommitHold() {
 
196
        SetOverride(_T("\\frz"),PrettyFloat(wxString::Format(_T("(%0.3f)"),curAngle)));
 
197
}
 
198
 
 
199
 
 
200
//////////////////
 
201
// Get \org pivot
 
202
void VisualToolRotateZ::PopulateFeatureList() {
 
203
        // Get line
 
204
        curDiag = GetActiveDialogueLine();
 
205
        GetLinePosition(curDiag,odx,ody,orgx,orgy);
 
206
 
 
207
        // Set features
 
208
        features.resize(1);
 
209
        VisualDraggableFeature &feat = features.back();
 
210
        feat.x = orgx;
 
211
        feat.y = orgy;
 
212
        feat.line = curDiag;
 
213
        feat.type = DRAG_BIG_TRIANGLE;
 
214
}
 
215
 
 
216
 
 
217
///////////////////////////
 
218
// Update dragging of \org
 
219
void VisualToolRotateZ::UpdateDrag(VisualDraggableFeature &feature) {
 
220
        orgx = feature.x;
 
221
        orgy = feature.y;
 
222
}
 
223
 
 
224
 
 
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));
 
229
}
 
230
 
 
231
 
 
232
///////////
 
233
// Refresh
 
234
void VisualToolRotateZ::DoRefresh() {
 
235
        AssDialogue *line = GetActiveDialogueLine();
 
236
        GetLinePosition(line,odx,ody,orgx,orgy);
 
237
        GetLineRotation(line,rx,ry,curAngle);
 
238
}