2011-11-06 18:18:20 +01:00
|
|
|
// Copyright (c) 2011, Thomas Goyne <plorkyeran@aegisub.org>
|
2007-07-01 05:36:17 +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 05:36:17 +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 05:36:17 +02:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file visual_tool_clip.cpp
|
|
|
|
/// @brief Rectangular clipping visual typesetting tool
|
|
|
|
/// @ingroup visual_ts
|
2007-07-01 05:36:17 +02:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "visual_tool_clip.h"
|
2007-07-01 05:36:17 +02:00
|
|
|
|
2012-10-20 16:56:38 +02:00
|
|
|
#include "ass_dialogue.h"
|
|
|
|
#include "include/aegisub/context.h"
|
|
|
|
#include "selection_controller.h"
|
2011-11-06 18:18:20 +01:00
|
|
|
#include "utils.h"
|
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <boost/format.hpp>
|
|
|
|
#include <utility>
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
VisualToolClip::VisualToolClip(VideoDisplay *parent, agi::Context *context)
|
|
|
|
: VisualTool<ClipCorner>(parent, context)
|
|
|
|
, cur_1(0, 0)
|
|
|
|
, cur_2(video_res)
|
2007-07-01 05:36:17 +02:00
|
|
|
{
|
2011-11-06 18:18:20 +01:00
|
|
|
ClipCorner *feats[4];
|
2013-11-21 18:13:36 +01:00
|
|
|
for (auto& feat : feats) {
|
|
|
|
feat = new ClipCorner;
|
|
|
|
features.push_back(*feat);
|
2013-09-17 20:13:52 +02:00
|
|
|
}
|
2010-06-30 08:29:14 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
// Attach each feature to the two features it shares edges with
|
2010-06-30 08:29:14 +02:00
|
|
|
// Top-left
|
|
|
|
int i = 0;
|
|
|
|
feats[i]->horiz = feats[1];
|
|
|
|
feats[i]->vert = feats[2];
|
|
|
|
i++;
|
|
|
|
|
|
|
|
// Top-right
|
|
|
|
feats[i]->horiz = feats[0];
|
|
|
|
feats[i]->vert = feats[3];
|
|
|
|
i++;
|
|
|
|
|
|
|
|
// Bottom-left
|
|
|
|
feats[i]->horiz = feats[3];
|
|
|
|
feats[i]->vert = feats[0];
|
|
|
|
i++;
|
|
|
|
|
|
|
|
// Bottom-right
|
|
|
|
feats[i]->horiz = feats[2];
|
|
|
|
feats[i]->vert = feats[1];
|
2007-07-01 05:36:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualToolClip::Draw() {
|
2011-11-06 18:18:20 +01:00
|
|
|
if (!active_line) return;
|
2007-07-01 05:57:34 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
DrawAllFeatures();
|
2007-07-01 05:36:17 +02:00
|
|
|
|
|
|
|
// Draw rectangle
|
2011-11-06 18:18:20 +01:00
|
|
|
gl.SetLineColour(colour[3], 1.0f, 2);
|
|
|
|
gl.SetFillColour(colour[3], 0.0f);
|
|
|
|
gl.DrawRectangle(cur_1, cur_2);
|
2007-07-01 05:36:17 +02:00
|
|
|
|
|
|
|
// Draw outside area
|
2011-11-06 18:18:20 +01:00
|
|
|
gl.SetLineColour(colour[3], 0.0f);
|
|
|
|
gl.SetFillColour(*wxBLACK, 0.5f);
|
2008-09-10 18:13:54 +02:00
|
|
|
if (inverse) {
|
2011-11-06 18:18:20 +01:00
|
|
|
gl.DrawRectangle(cur_1, cur_2);
|
2008-09-10 18:13:54 +02:00
|
|
|
}
|
|
|
|
else {
|
2011-11-12 02:23:40 +01:00
|
|
|
Vector2D v_min = video_pos;
|
|
|
|
Vector2D v_max = video_pos + video_res;
|
|
|
|
Vector2D c_min = cur_1.Min(cur_2);
|
|
|
|
Vector2D c_max = cur_1.Max(cur_2);
|
|
|
|
gl.DrawRectangle(v_min, Vector2D(v_max, c_min));
|
|
|
|
gl.DrawRectangle(Vector2D(v_min, c_max), v_max);
|
|
|
|
gl.DrawRectangle(Vector2D(v_min, c_min), Vector2D(c_min, c_max));
|
|
|
|
gl.DrawRectangle(Vector2D(c_max, c_min), Vector2D(v_max, c_max));
|
2008-09-10 18:13:54 +02:00
|
|
|
}
|
2007-07-01 05:36:17 +02:00
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:35 +02:00
|
|
|
bool VisualToolClip::InitializeHold() {
|
|
|
|
return true;
|
2007-07-01 05:36:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualToolClip::UpdateHold() {
|
2007-07-01 05:57:34 +02:00
|
|
|
// Limit to video area
|
2011-12-05 04:22:33 +01:00
|
|
|
cur_1 = video_pos.Max((video_pos + video_res).Min(drag_start));
|
|
|
|
cur_2 = video_pos.Max((video_pos + video_res).Min(mouse_pos));
|
2010-06-28 09:13:15 +02:00
|
|
|
|
2010-06-30 08:29:14 +02:00
|
|
|
SetFeaturePositions();
|
2011-11-06 18:18:20 +01:00
|
|
|
CommitHold();
|
2007-07-01 05:36:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualToolClip::CommitHold() {
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string value = str(boost::format("(%s,%s)") % ToScriptCoords(cur_1.Min(cur_2)).Str() % ToScriptCoords(cur_1.Max(cur_2)).Str());
|
2012-10-20 16:56:38 +02:00
|
|
|
|
2012-11-04 04:53:03 +01:00
|
|
|
for (auto line : c->selectionController->GetSelectedSet()) {
|
2012-10-20 16:56:38 +02:00
|
|
|
// This check is technically not correct as it could be outside of an
|
|
|
|
// override block... but that's rather unlikely
|
2013-01-04 16:01:50 +01:00
|
|
|
bool has_iclip = line->Text.get().find("\\iclip") != std::string::npos;
|
2012-11-04 04:53:03 +01:00
|
|
|
SetOverride(line, has_iclip ? "\\iclip" : "\\clip", value);
|
2012-10-20 16:56:38 +02:00
|
|
|
}
|
2007-07-01 05:36:17 +02:00
|
|
|
}
|
2007-07-04 07:22:35 +02:00
|
|
|
|
2013-09-17 20:13:52 +02:00
|
|
|
void VisualToolClip::UpdateDrag(ClipCorner *feature) {
|
2011-11-06 18:18:20 +01:00
|
|
|
// Update features which share an edge with the dragged one
|
|
|
|
feature->horiz->pos = Vector2D(feature->horiz->pos, feature->pos);
|
|
|
|
feature->vert->pos = Vector2D(feature->pos, feature->vert->pos);
|
|
|
|
|
|
|
|
cur_1 = features.front().pos;
|
|
|
|
cur_2 = features.back().pos;
|
2007-07-04 07:22:35 +02:00
|
|
|
|
|
|
|
CommitHold();
|
|
|
|
}
|
2010-06-27 09:53:08 +02:00
|
|
|
|
2010-06-30 08:29:14 +02:00
|
|
|
void VisualToolClip::SetFeaturePositions() {
|
2013-09-17 20:13:52 +02:00
|
|
|
auto it = features.begin();
|
2011-11-06 18:18:20 +01:00
|
|
|
(it++)->pos = cur_1; // Top-left
|
|
|
|
(it++)->pos = Vector2D(cur_2, cur_1); // Top-right
|
|
|
|
(it++)->pos = Vector2D(cur_1, cur_2); // Bottom-left
|
|
|
|
it->pos = cur_2; // Bottom-right
|
2010-06-28 09:13:15 +02:00
|
|
|
}
|
|
|
|
|
2010-06-30 08:29:14 +02:00
|
|
|
void VisualToolClip::DoRefresh() {
|
2011-11-06 18:18:20 +01:00
|
|
|
if (active_line) {
|
|
|
|
GetLineClip(active_line, cur_1, cur_2, inverse);
|
|
|
|
cur_1 = FromScriptCoords(cur_1);
|
|
|
|
cur_2 = FromScriptCoords(cur_2);
|
2010-06-30 08:29:14 +02:00
|
|
|
SetFeaturePositions();
|
2010-06-28 09:13:15 +02:00
|
|
|
}
|
2010-06-27 09:53:08 +02:00
|
|
|
}
|