2007-07-05 06:32:46 +02:00
|
|
|
// Copyright (c) 2007, Rodrigo Braz Monteiro
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
2007-07-05 06:32:46 +02:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file visual_tool_vector_clip.cpp
|
|
|
|
/// @brief Vector clipping visual typesetting tool
|
|
|
|
/// @ingroup visual_ts
|
2007-07-05 06:32:46 +02:00
|
|
|
|
2010-05-16 08:39:11 +02:00
|
|
|
#ifndef AGI_PRE
|
|
|
|
#include <wx/toolbar.h>
|
2010-06-14 21:26:27 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_APPLE_OPENGL_FRAMEWORK
|
|
|
|
#include <OpenGL/GL.h>
|
|
|
|
#include <OpenGL/glu.h>
|
|
|
|
#include <OpenGL/glext.h>
|
|
|
|
#else
|
|
|
|
#include <GL/gl.h>
|
|
|
|
#include <GL/glu.h>
|
2010-06-08 08:09:19 +02:00
|
|
|
#include "gl/glext.h"
|
2010-05-16 08:39:11 +02:00
|
|
|
#endif
|
2007-07-05 06:32:46 +02:00
|
|
|
|
2010-06-24 03:50:16 +02:00
|
|
|
#include <algorithm>
|
2010-06-14 21:26:27 +02:00
|
|
|
#endif
|
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2007-07-05 06:32:46 +02:00
|
|
|
#include "ass_dialogue.h"
|
2009-07-24 02:08:25 +02:00
|
|
|
#include "libresrc/libresrc.h"
|
2010-06-30 08:29:14 +02:00
|
|
|
#include "utils.h"
|
2009-09-10 03:41:34 +02:00
|
|
|
#include "video_display.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "visual_tool_vector_clip.h"
|
2007-07-05 06:32:46 +02:00
|
|
|
|
2010-06-28 09:13:15 +02:00
|
|
|
/// Button IDs
|
2007-07-05 08:13:22 +02:00
|
|
|
enum {
|
2007-07-07 07:51:18 +02:00
|
|
|
BUTTON_DRAG = VISUAL_SUB_TOOL_START,
|
2007-07-05 08:13:22 +02:00
|
|
|
BUTTON_LINE,
|
|
|
|
BUTTON_BICUBIC,
|
2007-07-07 09:27:28 +02:00
|
|
|
BUTTON_CONVERT,
|
2007-07-05 08:13:22 +02:00
|
|
|
BUTTON_INSERT,
|
|
|
|
BUTTON_REMOVE,
|
2007-07-07 07:51:18 +02:00
|
|
|
BUTTON_FREEHAND,
|
|
|
|
BUTTON_FREEHAND_SMOOTH,
|
2010-06-08 08:09:19 +02:00
|
|
|
BUTTON_LAST // Leave this at the end and don't use it
|
2007-07-05 08:13:22 +02:00
|
|
|
};
|
|
|
|
|
2010-06-30 08:29:14 +02:00
|
|
|
template<class C, class O, class M>
|
|
|
|
static void for_each_iter(C &container, O obj, M method) {
|
2010-07-06 21:33:09 +02:00
|
|
|
typename C::iterator end = container.end();
|
|
|
|
for (typename C::iterator cur = container.begin(); cur != end; ++cur) {
|
2010-06-30 08:29:14 +02:00
|
|
|
(obj ->* method)(cur);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-16 08:39:11 +02:00
|
|
|
VisualToolVectorClip::VisualToolVectorClip(VideoDisplay *parent, VideoState const& video, wxToolBar * toolBar)
|
2010-05-20 10:55:58 +02:00
|
|
|
: VisualTool<VisualToolVectorClipDraggableFeature>(parent, video)
|
|
|
|
, spline(*parent)
|
2010-06-03 22:32:10 +02:00
|
|
|
, toolBar(toolBar)
|
2007-07-05 06:32:46 +02:00
|
|
|
{
|
2009-07-25 06:49:59 +02:00
|
|
|
toolBar->AddTool(BUTTON_DRAG,_("Drag"),GETIMAGE(visual_vector_clip_drag_24),_("Drag control points."),wxITEM_CHECK);
|
|
|
|
toolBar->AddTool(BUTTON_LINE,_("Line"),GETIMAGE(visual_vector_clip_line_24),_("Appends a line."),wxITEM_CHECK);
|
|
|
|
toolBar->AddTool(BUTTON_BICUBIC,_("Bicubic"),GETIMAGE(visual_vector_clip_bicubic_24),_("Appends a bezier bicubic curve."),wxITEM_CHECK);
|
2007-07-07 05:21:52 +02:00
|
|
|
toolBar->AddSeparator();
|
2009-07-25 06:49:59 +02:00
|
|
|
toolBar->AddTool(BUTTON_CONVERT,_("Convert"),GETIMAGE(visual_vector_clip_convert_24),_("Converts a segment between line and bicubic."),wxITEM_CHECK);
|
|
|
|
toolBar->AddTool(BUTTON_INSERT,_("Insert"),GETIMAGE(visual_vector_clip_insert_24),_("Inserts a control point."),wxITEM_CHECK);
|
|
|
|
toolBar->AddTool(BUTTON_REMOVE,_("Remove"),GETIMAGE(visual_vector_clip_remove_24),_("Removes a control point."),wxITEM_CHECK);
|
2007-07-07 05:21:52 +02:00
|
|
|
toolBar->AddSeparator();
|
2009-07-25 06:49:59 +02:00
|
|
|
toolBar->AddTool(BUTTON_FREEHAND,_("Freehand"),GETIMAGE(visual_vector_clip_freehand_24),_("Draws a freehand shape."),wxITEM_CHECK);
|
|
|
|
toolBar->AddTool(BUTTON_FREEHAND_SMOOTH,_("Freehand smooth"),GETIMAGE(visual_vector_clip_freehand_smooth_24),_("Draws a smoothed freehand shape."),wxITEM_CHECK);
|
2007-07-07 07:51:18 +02:00
|
|
|
toolBar->ToggleTool(BUTTON_DRAG,true);
|
2007-07-07 05:21:52 +02:00
|
|
|
toolBar->Realize();
|
|
|
|
toolBar->Show(true);
|
2008-01-14 00:53:43 +01:00
|
|
|
|
2010-06-28 09:13:15 +02:00
|
|
|
DoRefresh();
|
|
|
|
SetMode(features.empty());
|
2007-07-05 06:32:46 +02:00
|
|
|
}
|
|
|
|
|
2007-07-07 07:51:18 +02:00
|
|
|
void VisualToolVectorClip::OnSubTool(wxCommandEvent &event) {
|
|
|
|
SetMode(event.GetId() - BUTTON_DRAG);
|
|
|
|
}
|
|
|
|
|
2010-06-08 08:09:19 +02:00
|
|
|
void VisualToolVectorClip::SetMode(int newMode) {
|
|
|
|
// Manually enforce radio behavior as we want one selection in the bar
|
|
|
|
// rather than one per group
|
2007-07-08 09:22:09 +02:00
|
|
|
for (int i=BUTTON_DRAG;i<BUTTON_LAST;i++) {
|
2010-06-08 08:09:19 +02:00
|
|
|
toolBar->ToggleTool(i,i == newMode + BUTTON_DRAG);
|
|
|
|
}
|
|
|
|
mode = newMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Substitute for glMultiDrawArrays for sub-1.4 OpenGL
|
|
|
|
static void APIENTRY glMultiDrawArraysFallback(GLenum mode, GLint *first, GLsizei *count, GLsizei primcount) {
|
|
|
|
for (int i = 0; i < primcount; ++i) {
|
|
|
|
glDrawArrays(mode, *first++, *count++);
|
2007-07-08 09:22:09 +02:00
|
|
|
}
|
2007-07-07 07:51:18 +02:00
|
|
|
}
|
|
|
|
|
2010-06-18 09:14:17 +02:00
|
|
|
static bool is_move(SplineCurve const& c) {
|
|
|
|
return c.type == CURVE_POINT;
|
|
|
|
}
|
|
|
|
|
2007-07-05 06:32:46 +02:00
|
|
|
void VisualToolVectorClip::Draw() {
|
2010-06-28 09:13:15 +02:00
|
|
|
if (!curDiag) return;
|
2010-06-08 08:09:19 +02:00
|
|
|
if (spline.empty()) return;
|
|
|
|
|
|
|
|
GL_EXT(PFNGLMULTIDRAWARRAYSPROC, glMultiDrawArrays);
|
2010-06-07 09:24:43 +02:00
|
|
|
|
2007-07-05 06:32:46 +02:00
|
|
|
// Parse vector
|
2010-06-07 09:24:43 +02:00
|
|
|
std::vector<float> points;
|
2010-06-08 08:09:19 +02:00
|
|
|
std::vector<int> start;
|
|
|
|
std::vector<int> count;
|
|
|
|
|
|
|
|
spline.GetPointList(points, start, count);
|
|
|
|
assert(!start.empty());
|
|
|
|
assert(!count.empty());
|
2010-06-07 09:24:43 +02:00
|
|
|
|
|
|
|
glEnableClientState(GL_VERTEX_ARRAY);
|
|
|
|
glVertexPointer(2, GL_FLOAT, 0, &points[0]);
|
2007-07-05 06:32:46 +02:00
|
|
|
|
2010-06-06 00:40:16 +02:00
|
|
|
// The following is nonzero winding-number PIP based on stencils
|
|
|
|
|
|
|
|
// Draw to stencil only
|
2007-07-05 06:32:46 +02:00
|
|
|
glEnable(GL_STENCIL_TEST);
|
2010-06-06 00:40:16 +02:00
|
|
|
glColorMask(0, 0, 0, 0);
|
|
|
|
|
|
|
|
// GL_INCR_WRAP was added in 1.4, so instead set the entire stencil to 128
|
|
|
|
// and wobble from there
|
|
|
|
glStencilFunc(GL_NEVER, 128, 0xFF);
|
|
|
|
glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
|
|
|
|
DrawRectangle(0,0,video.w,video.h);
|
|
|
|
|
|
|
|
// Increment the winding number for each forward facing triangle
|
|
|
|
glStencilOp(GL_INCR, GL_INCR, GL_INCR);
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
|
|
|
|
glCullFace(GL_BACK);
|
2010-06-08 08:09:19 +02:00
|
|
|
glMultiDrawArrays(GL_TRIANGLE_FAN, &start[0], &count[0], start.size());
|
2010-06-06 00:40:16 +02:00
|
|
|
|
|
|
|
// Decrement the winding number for each backfacing triangle
|
|
|
|
glStencilOp(GL_DECR, GL_DECR, GL_DECR);
|
|
|
|
glCullFace(GL_FRONT);
|
2010-06-08 08:09:19 +02:00
|
|
|
glMultiDrawArrays(GL_TRIANGLE_FAN, &start[0], &count[0], start.size());
|
2010-06-06 00:40:16 +02:00
|
|
|
glDisable(GL_CULL_FACE);
|
2007-07-05 06:32:46 +02:00
|
|
|
|
2010-06-06 00:40:16 +02:00
|
|
|
// Draw the actual rectangle
|
2007-07-05 06:32:46 +02:00
|
|
|
glColorMask(1,1,1,1);
|
2010-06-28 09:13:15 +02:00
|
|
|
SetLineColour(colour[3],0.f);
|
2007-07-05 06:32:46 +02:00
|
|
|
SetFillColour(wxColour(0,0,0),0.5f);
|
2010-06-06 00:40:16 +02:00
|
|
|
|
|
|
|
// VSFilter draws when the winding number is nonzero, so we want to draw the
|
|
|
|
// mask when the winding number is zero (where 128 is zero due to the lack of
|
|
|
|
// wrapping combined with unsigned numbers)
|
|
|
|
glStencilFunc(inverse ? GL_NOTEQUAL : GL_EQUAL, 128, 0xFF);
|
2010-05-16 08:39:11 +02:00
|
|
|
DrawRectangle(0,0,video.w,video.h);
|
2007-07-05 06:32:46 +02:00
|
|
|
glDisable(GL_STENCIL_TEST);
|
|
|
|
|
2007-07-08 09:22:09 +02:00
|
|
|
// Draw lines
|
2010-06-28 09:13:15 +02:00
|
|
|
SetFillColour(colour[3],0.f);
|
|
|
|
SetLineColour(colour[3],1.f,2);
|
2010-06-07 09:24:43 +02:00
|
|
|
SetModeLine();
|
2010-06-08 08:09:19 +02:00
|
|
|
glMultiDrawArrays(GL_LINE_LOOP, &start[0], &count[0], start.size());
|
|
|
|
|
|
|
|
Vector2D pt;
|
|
|
|
float t;
|
|
|
|
Spline::iterator highCurve;
|
|
|
|
spline.GetClosestParametricPoint(Vector2D(video.x, video.y), highCurve, t, pt);
|
2010-06-07 09:24:43 +02:00
|
|
|
|
|
|
|
// Draw highlighted line
|
2010-06-30 08:29:14 +02:00
|
|
|
if ((mode == 3 || mode == 4) && curFeature == features.end() && points.size() > 2) {
|
2010-06-08 08:09:19 +02:00
|
|
|
std::vector<float> highPoints;
|
|
|
|
spline.GetPointList(highPoints, highCurve);
|
|
|
|
if (!highPoints.empty()) {
|
|
|
|
glVertexPointer(2, GL_FLOAT, 0, &highPoints[0]);
|
2010-06-07 09:24:43 +02:00
|
|
|
SetLineColour(colour[2], 1.f, 2);
|
2010-06-08 08:09:19 +02:00
|
|
|
SetModeLine();
|
|
|
|
glDrawArrays(GL_LINE_STRIP, 0, highPoints.size() / 2);
|
2007-07-08 09:22:09 +02:00
|
|
|
}
|
|
|
|
}
|
2007-07-05 06:32:46 +02:00
|
|
|
|
2010-06-07 09:24:43 +02:00
|
|
|
glDisableClientState(GL_VERTEX_ARRAY);
|
|
|
|
|
2007-07-05 06:32:46 +02:00
|
|
|
// Draw lines connecting the bicubic features
|
|
|
|
SetLineColour(colour[3],0.9f,1);
|
2010-06-08 08:09:19 +02:00
|
|
|
for (Spline::iterator cur=spline.begin();cur!=spline.end();cur++) {
|
2007-07-05 06:32:46 +02:00
|
|
|
if (cur->type == CURVE_BICUBIC) {
|
2007-07-05 16:15:28 +02:00
|
|
|
DrawDashedLine(cur->p1.x,cur->p1.y,cur->p2.x,cur->p2.y,6);
|
|
|
|
DrawDashedLine(cur->p3.x,cur->p3.y,cur->p4.x,cur->p4.y,6);
|
2007-07-05 06:32:46 +02:00
|
|
|
}
|
|
|
|
}
|
2007-07-07 08:41:14 +02:00
|
|
|
|
2007-07-08 09:22:09 +02:00
|
|
|
DrawAllFeatures();
|
|
|
|
|
2007-07-07 08:41:14 +02:00
|
|
|
// Draw preview of inserted line
|
|
|
|
if (mode == 1 || mode == 2) {
|
2010-06-08 08:09:19 +02:00
|
|
|
if (spline.size() && video.x > INT_MIN && video.y > INT_MIN) {
|
2010-06-18 09:14:17 +02:00
|
|
|
Spline::reverse_iterator c0 = std::find_if(spline.rbegin(), spline.rend(), is_move);
|
2010-06-08 08:09:19 +02:00
|
|
|
SplineCurve *c1 = &spline.back();
|
2010-05-16 08:39:11 +02:00
|
|
|
DrawDashedLine(video.x,video.y,c0->p1.x,c0->p1.y,6);
|
2010-06-08 08:09:19 +02:00
|
|
|
DrawDashedLine(video.x,video.y,c1->EndPoint().x,c1->EndPoint().y,6);
|
2007-07-07 08:41:14 +02:00
|
|
|
}
|
|
|
|
}
|
2007-07-07 10:53:11 +02:00
|
|
|
|
|
|
|
// Draw preview of insert point
|
2007-07-08 09:22:09 +02:00
|
|
|
if (mode == 4) DrawCircle(pt.x,pt.y,4);
|
2007-07-05 06:32:46 +02:00
|
|
|
}
|
|
|
|
|
2010-06-18 09:14:23 +02:00
|
|
|
void VisualToolVectorClip::MakeFeature(Spline::iterator cur) {
|
2010-06-30 08:29:14 +02:00
|
|
|
Feature feat;
|
2010-06-18 09:14:23 +02:00
|
|
|
if (cur->type == CURVE_POINT) {
|
|
|
|
feat.x = (int)cur->p1.x;
|
|
|
|
feat.y = (int)cur->p1.y;
|
|
|
|
feat.type = DRAG_SMALL_CIRCLE;
|
|
|
|
feat.curve = cur;
|
|
|
|
feat.point = 0;
|
|
|
|
features.push_back(feat);
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (cur->type == CURVE_LINE) {
|
|
|
|
feat.x = (int)cur->p2.x;
|
|
|
|
feat.y = (int)cur->p2.y;
|
|
|
|
feat.type = DRAG_SMALL_CIRCLE;
|
|
|
|
feat.curve = cur;
|
|
|
|
feat.point = 1;
|
|
|
|
features.push_back(feat);
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (cur->type == CURVE_BICUBIC) {
|
|
|
|
// Control points
|
|
|
|
feat.x = (int)cur->p2.x;
|
|
|
|
feat.y = (int)cur->p2.y;
|
|
|
|
feat.curve = cur;
|
|
|
|
feat.point = 1;
|
|
|
|
feat.type = DRAG_SMALL_SQUARE;
|
|
|
|
features.push_back(feat);
|
2010-06-30 08:29:14 +02:00
|
|
|
|
2010-06-18 09:14:23 +02:00
|
|
|
feat.x = (int)cur->p3.x;
|
|
|
|
feat.y = (int)cur->p3.y;
|
|
|
|
feat.point = 2;
|
|
|
|
features.push_back(feat);
|
|
|
|
|
|
|
|
// End point
|
|
|
|
feat.x = (int)cur->p4.x;
|
|
|
|
feat.y = (int)cur->p4.y;
|
|
|
|
feat.type = DRAG_SMALL_CIRCLE;
|
|
|
|
feat.point = 3;
|
|
|
|
features.push_back(feat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-30 08:29:14 +02:00
|
|
|
void VisualToolVectorClip::MakeFeatures() {
|
|
|
|
ClearSelection();
|
2007-07-05 06:32:46 +02:00
|
|
|
features.clear();
|
2010-06-30 08:29:14 +02:00
|
|
|
for_each_iter(spline, this, &VisualToolVectorClip::MakeFeature);
|
|
|
|
}
|
2007-07-05 06:32:46 +02:00
|
|
|
|
2010-06-30 08:29:14 +02:00
|
|
|
void VisualToolVectorClip::Save() {
|
|
|
|
SetOverride(curDiag, inverse ? L"\\iclip" : L"\\clip", L"(" + spline.EncodeToASS() + L")");
|
2007-07-05 06:32:46 +02:00
|
|
|
}
|
|
|
|
|
2010-06-30 08:29:14 +02:00
|
|
|
void VisualToolVectorClip::UpdateDrag(feature_iterator feature) {
|
2010-06-08 08:09:19 +02:00
|
|
|
spline.MovePoint(feature->curve,feature->point,Vector2D(feature->x,feature->y));
|
2007-07-05 06:32:46 +02:00
|
|
|
}
|
|
|
|
|
2010-06-30 08:29:14 +02:00
|
|
|
void VisualToolVectorClip::CommitDrag(feature_iterator) {
|
|
|
|
Save();
|
2007-07-05 06:32:46 +02:00
|
|
|
}
|
|
|
|
|
2010-06-30 08:29:14 +02:00
|
|
|
bool VisualToolVectorClip::InitializeDrag(feature_iterator feature) {
|
|
|
|
if (mode != 5) return true;
|
|
|
|
|
|
|
|
if (feature->curve->type == CURVE_BICUBIC && (feature->point == 1 || feature->point == 2)) {
|
|
|
|
// Deleting bicubic curve handles, so convert to line
|
|
|
|
feature->curve->type = CURVE_LINE;
|
|
|
|
feature->curve->p2 = feature->curve->p4;
|
|
|
|
}
|
|
|
|
else {
|
2010-06-08 08:09:19 +02:00
|
|
|
Spline::iterator next = feature->curve;
|
|
|
|
next++;
|
|
|
|
if (next != spline.end()) {
|
|
|
|
if (feature->curve->type == CURVE_POINT) {
|
|
|
|
next->p1 = next->EndPoint();
|
|
|
|
next->type = CURVE_POINT;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
next->p1 = feature->curve->p1;
|
2007-07-07 09:27:28 +02:00
|
|
|
}
|
|
|
|
}
|
2010-06-08 08:09:19 +02:00
|
|
|
|
|
|
|
spline.erase(feature->curve);
|
2007-07-07 09:27:28 +02:00
|
|
|
}
|
2010-06-30 08:29:14 +02:00
|
|
|
curFeature = features.end();
|
|
|
|
|
|
|
|
Save();
|
|
|
|
MakeFeatures();
|
|
|
|
Commit(true, _("delete control point"));
|
|
|
|
|
|
|
|
return false;
|
2007-07-07 07:51:18 +02:00
|
|
|
}
|
|
|
|
|
2010-05-20 10:55:35 +02:00
|
|
|
bool VisualToolVectorClip::InitializeHold() {
|
2007-07-07 08:41:14 +02:00
|
|
|
// Insert line/bicubic
|
|
|
|
if (mode == 1 || mode == 2) {
|
|
|
|
SplineCurve curve;
|
|
|
|
|
|
|
|
// Set start position
|
2010-06-08 08:09:19 +02:00
|
|
|
if (!spline.empty()) {
|
|
|
|
curve.p1 = spline.back().EndPoint();
|
2010-06-30 08:29:14 +02:00
|
|
|
curve.type = mode == 1 ? CURVE_LINE : CURVE_BICUBIC;
|
2007-07-07 08:41:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// First point
|
|
|
|
else {
|
2010-05-16 08:39:11 +02:00
|
|
|
curve.p1 = Vector2D(video.x,video.y);
|
2007-07-07 08:41:14 +02:00
|
|
|
curve.type = CURVE_POINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert
|
2010-06-08 08:09:19 +02:00
|
|
|
spline.push_back(curve);
|
2010-06-28 09:13:15 +02:00
|
|
|
ClearSelection();
|
2010-06-18 09:14:23 +02:00
|
|
|
MakeFeature(--spline.end());
|
2010-05-20 10:55:35 +02:00
|
|
|
UpdateHold();
|
|
|
|
return true;
|
2007-07-07 08:41:14 +02:00
|
|
|
}
|
|
|
|
|
2007-07-07 23:13:20 +02:00
|
|
|
// Convert and insert
|
2010-05-20 10:55:35 +02:00
|
|
|
if (mode == 3 || mode == 4) {
|
2007-07-07 23:13:20 +02:00
|
|
|
// Get closest point
|
|
|
|
Vector2D pt;
|
2010-06-08 08:09:19 +02:00
|
|
|
Spline::iterator curve;
|
2007-07-07 23:13:20 +02:00
|
|
|
float t;
|
2010-05-16 08:39:11 +02:00
|
|
|
spline.GetClosestParametricPoint(Vector2D(video.x,video.y),curve,t,pt);
|
2007-07-07 23:13:20 +02:00
|
|
|
|
|
|
|
// Convert
|
|
|
|
if (mode == 3) {
|
2010-06-08 08:09:19 +02:00
|
|
|
if (curve != spline.end()) {
|
|
|
|
if (curve->type == CURVE_LINE) {
|
|
|
|
curve->type = CURVE_BICUBIC;
|
|
|
|
curve->p4 = curve->p2;
|
|
|
|
curve->p2 = curve->p1 * 0.75 + curve->p4 * 0.25;
|
|
|
|
curve->p3 = curve->p1 * 0.25 + curve->p4 * 0.75;
|
2007-07-08 09:22:09 +02:00
|
|
|
}
|
|
|
|
|
2010-06-08 08:09:19 +02:00
|
|
|
else if (curve->type == CURVE_BICUBIC) {
|
|
|
|
curve->type = CURVE_LINE;
|
|
|
|
curve->p2 = curve->p4;
|
2007-07-08 09:22:09 +02:00
|
|
|
}
|
|
|
|
}
|
2007-07-07 23:13:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Insert
|
|
|
|
else {
|
2007-08-03 19:22:06 +02:00
|
|
|
// Check if there is at least one curve to split
|
2010-06-08 08:09:19 +02:00
|
|
|
if (spline.empty()) return false;
|
2007-08-03 19:22:06 +02:00
|
|
|
|
2007-07-07 23:13:20 +02:00
|
|
|
// Split the curve
|
2010-06-08 08:09:19 +02:00
|
|
|
if (curve == spline.end()) {
|
2007-07-07 23:13:20 +02:00
|
|
|
SplineCurve ct;
|
|
|
|
ct.type = CURVE_LINE;
|
2010-06-08 08:09:19 +02:00
|
|
|
ct.p1 = spline.back().EndPoint();
|
|
|
|
ct.p2 = spline.front().p1;
|
2007-07-07 23:13:20 +02:00
|
|
|
ct.p2 = ct.p1*(1-t) + ct.p2*t;
|
2010-06-08 08:09:19 +02:00
|
|
|
spline.push_back(ct);
|
2007-07-07 23:13:20 +02:00
|
|
|
}
|
|
|
|
else {
|
2010-06-08 08:09:19 +02:00
|
|
|
SplineCurve c2;
|
|
|
|
curve->Split(*curve,c2,t);
|
|
|
|
spline.insert(++curve, c2);
|
2007-07-07 23:13:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Commit
|
2010-06-30 08:29:14 +02:00
|
|
|
Save();
|
|
|
|
MakeFeatures();
|
2007-07-07 23:13:20 +02:00
|
|
|
Commit(true);
|
2010-05-20 10:55:35 +02:00
|
|
|
return false;
|
2007-07-07 23:13:20 +02:00
|
|
|
}
|
|
|
|
|
2007-07-07 08:41:14 +02:00
|
|
|
// Freehand
|
2010-05-20 10:55:35 +02:00
|
|
|
if (mode == 6 || mode == 7) {
|
2010-06-28 09:13:15 +02:00
|
|
|
ClearSelection();
|
2007-07-08 09:22:09 +02:00
|
|
|
features.clear();
|
2010-06-08 08:09:19 +02:00
|
|
|
spline.clear();
|
|
|
|
SplineCurve curve;
|
|
|
|
curve.type = CURVE_POINT;
|
|
|
|
curve.p1.x = video.x;
|
|
|
|
curve.p1.y = video.y;
|
|
|
|
spline.push_back(curve);
|
2010-05-20 10:55:35 +02:00
|
|
|
return true;
|
2007-07-07 08:41:14 +02:00
|
|
|
}
|
2010-05-20 10:55:35 +02:00
|
|
|
return false;
|
2007-07-07 07:51:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualToolVectorClip::UpdateHold() {
|
2007-07-07 08:41:14 +02:00
|
|
|
// Insert line
|
|
|
|
if (mode == 1) {
|
2010-06-18 09:14:23 +02:00
|
|
|
spline.back().EndPoint() = Vector2D(video.x,video.y);
|
|
|
|
features.back().x = video.x;
|
|
|
|
features.back().y = video.y;
|
2007-07-07 08:41:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Insert bicubic
|
2010-06-18 09:14:23 +02:00
|
|
|
else if (mode == 2) {
|
2010-06-08 08:09:19 +02:00
|
|
|
SplineCurve &curve = spline.back();
|
2010-06-18 09:14:23 +02:00
|
|
|
curve.EndPoint() = Vector2D(video.x,video.y);
|
2007-07-07 08:41:14 +02:00
|
|
|
|
|
|
|
// Control points
|
2010-06-08 08:09:19 +02:00
|
|
|
if (spline.size() > 1) {
|
|
|
|
std::list<SplineCurve>::reverse_iterator iter = spline.rbegin();
|
2007-07-07 08:41:14 +02:00
|
|
|
iter++;
|
|
|
|
SplineCurve &c0 = *iter;
|
|
|
|
Vector2D prevVector;
|
|
|
|
float len = (curve.p4-curve.p1).Len();
|
|
|
|
if (c0.type == CURVE_LINE) prevVector = c0.p2-c0.p1;
|
|
|
|
else prevVector = c0.p4-c0.p3;
|
|
|
|
curve.p2 = prevVector.Unit() * (0.25f*len) + curve.p1;
|
|
|
|
}
|
|
|
|
else curve.p2 = curve.p1 * 0.75 + curve.p4 * 0.25;
|
|
|
|
curve.p3 = curve.p1 * 0.25 + curve.p4 * 0.75;
|
2010-06-30 08:29:14 +02:00
|
|
|
MakeFeatures();
|
2007-07-07 08:41:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Freehand
|
2010-06-18 09:14:23 +02:00
|
|
|
else if (mode == 6 || mode == 7) {
|
2010-06-08 08:09:19 +02:00
|
|
|
// See if distance is enough
|
|
|
|
Vector2D const& last = spline.back().EndPoint();
|
|
|
|
int len = (int)Vector2D(last.x-video.x, last.y-video.y).Len();
|
|
|
|
if (mode == 6 && len < 30) return;
|
|
|
|
if (mode == 7 && len < 60) return;
|
|
|
|
|
|
|
|
// Generate curve and add it
|
|
|
|
SplineCurve curve;
|
|
|
|
curve.type = CURVE_LINE;
|
|
|
|
curve.p1 = Vector2D(last.x,last.y);
|
|
|
|
curve.p2 = Vector2D(video.x,video.y);
|
|
|
|
spline.push_back(curve);
|
2010-06-18 09:14:23 +02:00
|
|
|
MakeFeature(--spline.end());
|
2007-07-07 07:51:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualToolVectorClip::CommitHold() {
|
2010-06-30 08:29:14 +02:00
|
|
|
if (mode == 3 || mode == 4) return;
|
|
|
|
|
2007-07-07 07:51:18 +02:00
|
|
|
// Smooth spline
|
2010-06-18 09:14:23 +02:00
|
|
|
if (!holding && mode == 7) {
|
|
|
|
spline.Smooth();
|
|
|
|
}
|
2007-07-07 07:51:18 +02:00
|
|
|
|
2010-06-30 08:29:14 +02:00
|
|
|
Save();
|
2007-07-08 09:22:09 +02:00
|
|
|
|
|
|
|
// End freedraw
|
2010-06-18 09:14:23 +02:00
|
|
|
if (!holding && (mode == 6 || mode == 7)) {
|
|
|
|
SetMode(0);
|
2010-06-30 08:29:14 +02:00
|
|
|
MakeFeatures();
|
2010-06-18 09:14:23 +02:00
|
|
|
}
|
2007-07-07 07:51:18 +02:00
|
|
|
}
|
|
|
|
|
2007-07-05 06:32:46 +02:00
|
|
|
void VisualToolVectorClip::DoRefresh() {
|
2010-06-28 09:13:15 +02:00
|
|
|
if (!curDiag) return;
|
|
|
|
|
|
|
|
wxString vect;
|
|
|
|
int scale;
|
|
|
|
vect = GetLineVectorClip(curDiag,scale,inverse);
|
|
|
|
spline.DecodeFromASS(vect);
|
2010-06-30 08:29:14 +02:00
|
|
|
|
|
|
|
MakeFeatures();
|
2010-06-28 09:13:15 +02:00
|
|
|
SelectAll();
|
2007-07-05 06:32:46 +02:00
|
|
|
}
|
2010-06-18 09:14:23 +02:00
|
|
|
|
|
|
|
void VisualToolVectorClip::SelectAll() {
|
2010-06-28 09:13:15 +02:00
|
|
|
ClearSelection();
|
2010-06-30 08:29:14 +02:00
|
|
|
for_each_iter(features, this, &VisualToolVectorClip::AddSelection);
|
2010-06-18 09:14:23 +02:00
|
|
|
}
|