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-09-10 15:06:40 +02:00
|
|
|
#include "visual_tool_rotatez.h"
|
2007-07-01 04:23:57 +02:00
|
|
|
|
2018-04-15 23:59:32 +02:00
|
|
|
#include "compat.h"
|
2014-06-29 20:39:51 +02:00
|
|
|
#include "include/aegisub/context.h"
|
2018-04-15 23:59:32 +02:00
|
|
|
#include "options.h"
|
2014-06-29 20:39:51 +02:00
|
|
|
#include "selection_controller.h"
|
|
|
|
|
2014-05-29 00:19:05 +02:00
|
|
|
#include <libaegisub/format.h>
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <cmath>
|
2014-05-23 00:40:16 +02:00
|
|
|
#include <wx/colour.h>
|
2013-01-04 16:01:50 +01: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;
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
VisualToolRotateZ::VisualToolRotateZ(VideoDisplay *parent, agi::Context *context)
|
|
|
|
: VisualTool<VisualDraggableFeature>(parent, context)
|
2013-09-17 20:13:52 +02:00
|
|
|
, org(new Feature)
|
2007-07-01 04:23:57 +02:00
|
|
|
{
|
2013-09-17 20:13:52 +02:00
|
|
|
features.push_back(*org);
|
2010-06-30 08:29:14 +02:00
|
|
|
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();
|
|
|
|
|
2018-04-15 23:59:32 +02:00
|
|
|
// Load colors from options
|
|
|
|
wxColour line_color_primary = to_wx(line_color_primary_opt->GetColor());
|
|
|
|
wxColour line_color_secondary = to_wx(line_color_secondary_opt->GetColor());
|
|
|
|
wxColour highlight_color = to_wx(highlight_color_primary_opt->GetColor());
|
|
|
|
|
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
|
2018-04-15 23:59:32 +02:00
|
|
|
gl.SetLineColour(line_color_secondary);
|
|
|
|
gl.SetFillColour(highlight_color, 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));
|
2018-04-15 23:59:32 +02:00
|
|
|
gl.SetLineColour(line_color_primary, 1, 2);
|
2011-11-06 18:18:20 +01:00
|
|
|
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
|
2018-04-15 23:59:32 +02:00
|
|
|
gl.SetLineColour(line_color_secondary, 1.f, 1);
|
|
|
|
gl.SetFillColour(highlight_color, 0.3f);
|
2011-11-06 18:18:20 +01:00
|
|
|
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) {
|
2018-04-15 23:59:32 +02:00
|
|
|
gl.SetLineColour(line_color_secondary);
|
2011-11-06 18:18:20 +01:00
|
|
|
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);
|
|
|
|
|
2014-05-29 00:19:05 +02:00
|
|
|
SetSelectedOverride("\\frz", agi::format("%.4g", angle));
|
2007-07-01 04:23:57 +02:00
|
|
|
}
|
2007-07-04 23:47:26 +02:00
|
|
|
|
2013-09-17 20:13:52 +02:00
|
|
|
void VisualToolRotateZ::UpdateDrag(Feature *feature) {
|
2014-06-29 20:39:51 +02:00
|
|
|
auto org = GetLineOrigin(active_line);
|
|
|
|
if (!org) org = GetLinePosition(active_line);
|
|
|
|
auto d = ToScriptCoords(feature->pos) - org;
|
|
|
|
|
|
|
|
for (auto line : c->selectionController->GetSelectedSet()) {
|
|
|
|
org = GetLineOrigin(line);
|
|
|
|
if (!org) org = GetLinePosition(line);
|
|
|
|
SetOverride(line, "\\org", (d + org).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
|
|
|
}
|