2011-11-06 18:18:20 +01:00
|
|
|
// Copyright (c) 2011, Thomas Goyne <plorkyeran@aegisub.org>
|
2007-07-01 04:23:57 +02:00
|
|
|
//
|
2011-11-06 18:18:20 +01:00
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
2007-07-01 04:23:57 +02:00
|
|
|
//
|
2011-11-06 18:18:20 +01:00
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2007-07-01 04:23:57 +02:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @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-06-28 09:13:15 +02:00
|
|
|
#include <cmath>
|
2010-05-19 05:24:01 +02:00
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "visual_tool_rotatez.h"
|
2007-07-01 04:23:57 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
#include "utils.h"
|
|
|
|
|
2010-06-28 09:13:15 +02:00
|
|
|
static const float deg2rad = 3.1415926536f / 180.f;
|
|
|
|
static const float rad2deg = 180.f / 3.1415926536f;
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
VisualToolRotateZ::VisualToolRotateZ(VideoDisplay *parent, agi::Context *context)
|
|
|
|
: VisualTool<VisualDraggableFeature>(parent, context)
|
2012-10-15 06:37:14 +02:00
|
|
|
, angle(0)
|
|
|
|
, orig_angle(0)
|
|
|
|
, rotation_x(0)
|
|
|
|
, rotation_y(0)
|
2007-07-01 04:23:57 +02:00
|
|
|
{
|
2010-06-30 08:29:14 +02:00
|
|
|
features.resize(1);
|
|
|
|
org = &features.back();
|
|
|
|
org->type = DRAG_BIG_TRIANGLE;
|
2007-07-01 04:23:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualToolRotateZ::Draw() {
|
2011-11-06 18:18:20 +01:00
|
|
|
if (!active_line) return;
|
2007-07-01 04:23:57 +02:00
|
|
|
|
2007-07-04 23:47:26 +02:00
|
|
|
DrawAllFeatures();
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
float radius = (pos - org->pos).Len();
|
|
|
|
float oRadius = radius;
|
|
|
|
if (radius < 50)
|
|
|
|
radius = 50;
|
2007-07-01 04:23:57 +02:00
|
|
|
|
|
|
|
// Set up the projection
|
2011-11-06 18:18:20 +01:00
|
|
|
gl.SetOrigin(org->pos);
|
|
|
|
gl.SetRotation(rotation_x, rotation_y, 0);
|
|
|
|
gl.SetScale(scale);
|
2007-07-01 04:23:57 +02:00
|
|
|
|
|
|
|
// Draw the circle
|
2011-11-06 18:18:20 +01:00
|
|
|
gl.SetLineColour(colour[0]);
|
|
|
|
gl.SetFillColour(colour[1], 0.3f);
|
2011-12-07 00:13:06 +01:00
|
|
|
gl.DrawRing(Vector2D(0, 0), radius + 4, radius - 4);
|
2007-07-01 04:23:57 +02:00
|
|
|
|
|
|
|
// Draw markers around circle
|
|
|
|
int markers = 6;
|
2010-06-28 09:13:15 +02:00
|
|
|
float markStart = -90.f / markers;
|
2011-11-06 18:18:20 +01:00
|
|
|
float markEnd = markStart + (180.f / markers);
|
|
|
|
for (int i = 0; i < markers; ++i) {
|
|
|
|
float angle = i * (360.f / markers);
|
2011-12-07 00:13:06 +01:00
|
|
|
gl.DrawRing(Vector2D(0, 0), radius+30, radius+12, 1.0, angle+markStart, angle+markEnd);
|
2007-07-01 04:23:57 +02:00
|
|
|
}
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
// Draw the baseline through the origin showing current rotation
|
|
|
|
Vector2D angle_vec(Vector2D::FromAngle(angle * deg2rad));
|
|
|
|
gl.SetLineColour(colour[3], 1, 2);
|
|
|
|
gl.DrawLine(angle_vec * -radius, angle_vec * radius);
|
|
|
|
|
|
|
|
if (org->pos != pos) {
|
|
|
|
Vector2D rotated_pos = Vector2D::FromAngle(angle * deg2rad - (pos - org->pos).Angle()) * oRadius;
|
|
|
|
|
|
|
|
// Draw the line from origin to rotated position
|
|
|
|
gl.DrawLine(Vector2D(), rotated_pos);
|
|
|
|
|
|
|
|
// Draw the line under the text
|
|
|
|
gl.DrawLine(rotated_pos - angle_vec * 20, rotated_pos + angle_vec * 20);
|
2007-07-01 04:23:57 +02:00
|
|
|
}
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
// Draw the fake features on the ring
|
|
|
|
gl.SetLineColour(colour[0], 1.f, 1);
|
|
|
|
gl.SetFillColour(colour[1], 0.3f);
|
|
|
|
gl.DrawCircle(angle_vec * radius, 4);
|
|
|
|
gl.DrawCircle(angle_vec * -radius, 4);
|
2007-07-01 04:23:57 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
// Clear the projection
|
|
|
|
gl.ResetTransform();
|
2007-07-01 04:23:57 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
// Draw line to mouse if it isn't over the origin feature
|
|
|
|
if (mouse_pos && (mouse_pos - org->pos).SquareLen() > 100) {
|
|
|
|
gl.SetLineColour(colour[0]);
|
|
|
|
gl.DrawLine(org->pos, mouse_pos);
|
2007-07-01 04:23:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:35 +02:00
|
|
|
bool VisualToolRotateZ::InitializeHold() {
|
2011-11-06 18:18:20 +01:00
|
|
|
orig_angle = angle + (org->pos - mouse_pos).Angle() * rad2deg;
|
2010-05-20 10:55:35 +02:00
|
|
|
return true;
|
2007-07-01 04:23:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualToolRotateZ::UpdateHold() {
|
2011-11-06 18:18:20 +01:00
|
|
|
angle = orig_angle - (org->pos - mouse_pos).Angle() * rad2deg;
|
2010-05-19 05:24:01 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
if (ctrl_down)
|
|
|
|
angle = floorf(angle / 30.f + .5f) * 30.f;
|
2007-07-01 04:23:57 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
angle = fmodf(angle + 360.f, 360.f);
|
|
|
|
|
2011-12-22 22:23:26 +01:00
|
|
|
SetSelectedOverride("\\frz", wxString::Format("%.4g", angle));
|
2007-07-01 04:23:57 +02:00
|
|
|
}
|
2007-07-04 23:47:26 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
void VisualToolRotateZ::UpdateDrag(feature_iterator feature) {
|
|
|
|
SetOverride(active_line, "\\org", ToScriptCoords(feature->pos).PStr());
|
2007-07-04 23:47:26 +02:00
|
|
|
}
|
2007-07-27 06:50:15 +02:00
|
|
|
|
|
|
|
void VisualToolRotateZ::DoRefresh() {
|
2011-11-06 18:18:20 +01:00
|
|
|
if (!active_line) return;
|
|
|
|
|
|
|
|
pos = FromScriptCoords(GetLinePosition(active_line));
|
|
|
|
if (!(org->pos = GetLineOrigin(active_line)))
|
|
|
|
org->pos = pos;
|
|
|
|
else
|
|
|
|
org->pos = FromScriptCoords(org->pos);
|
|
|
|
|
|
|
|
GetLineRotation(active_line, rotation_x, rotation_y, angle);
|
|
|
|
GetLineScale(active_line, scale);
|
2007-07-27 06:50:15 +02:00
|
|
|
}
|