From 5e25ffe30be5cdf52240d24192359141739e1cbc Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Thu, 5 Jul 2007 02:01:12 +0000 Subject: [PATCH] Unused, incomplete and untested spline class added. Originally committed to SVN as r1363. --- aegisub/Makefile.am | 1 + aegisub/spline.cpp | 207 ++++++++++++++++++++++++++++++++++ aegisub/spline.h | 90 +++++++++++++++ aegisub/visual_tool_cross.cpp | 1 + 4 files changed, 299 insertions(+) create mode 100644 aegisub/spline.cpp create mode 100644 aegisub/spline.h diff --git a/aegisub/Makefile.am b/aegisub/Makefile.am index 284e3e456..50d516797 100644 --- a/aegisub/Makefile.am +++ b/aegisub/Makefile.am @@ -177,6 +177,7 @@ aegisub_SOURCES = \ options.cpp \ scintilla_text_ctrl.cpp \ spellchecker.cpp \ + spline.cpp \ standard_paths.cpp \ static_bmp.cpp \ string_codec.cpp \ diff --git a/aegisub/spline.cpp b/aegisub/spline.cpp new file mode 100644 index 000000000..fe62577ce --- /dev/null +++ b/aegisub/spline.cpp @@ -0,0 +1,207 @@ +// 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. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB +// +// Website: http://aegisub.cellosoft.com +// Contact: mailto:zeratul@cellosoft.com +// + + +/////////// +// Headers +#include "spline.h" + + +///////////////////// +// Curve constructor +SplineCurve::SplineCurve() { + x1=x2=x3=x4=y1=y2=y3=y4=0; + type = CURVE_INVALID; +} + + +////////////////////// +// Spline constructor +Spline::Spline() { +} + + +///////////////// +// Encode to ASS +wxString Spline::EncodeToASS() { + wxString result; + char lastCommand = 0; + + // At least one element? + bool isFirst = true; + + // Insert each element + for (std::list::iterator cur = curves.begin();cur!=curves.end();cur++) { + // Start of spline + if (isFirst) { + result = wxString::Format(_T("m %i %i"),cur->x1,cur->y1); + lastCommand = 'm'; + isFirst = false; + } + + // Each curve + switch (cur->type) { + case CURVE_LINE: + if (lastCommand != 'l') { + result += _T("l "); + lastCommand = 'l'; + } + result += wxString::Format(_T("%i %i"),cur->x2,cur->y2); + break; + case CURVE_BICUBIC: + if (lastCommand != 'b') { + result += _T("b "); + lastCommand = 'b'; + } + result += wxString::Format(_T("%i %i %i %i"),cur->x2,cur->y2,cur->x3,cur->y3,cur->x4,cur->y4); + break; + default: break; + } + } + return result; +} + + +/////////////////// +// Decode from ASS +void Spline::DecodeFromASS(wxString str) { + // Clear current + curves.clear(); +} + + +//////////////////////////////// +// Append a curve to the spline +void Spline::AppendCurve(SplineCurve &curve) { + curves.push_back(curve); +} + + +//////////////////////////////////////// +// Moves a specific point in the spline +void Spline::MovePoint(int curveIndex,int point,wxPoint pos) { + int i = 0; + for (std::list::iterator cur = curves.begin();cur!=curves.end();cur++) { + if (i == curveIndex) { + switch (point) { + case 0: + cur->x1 = pos.x; + cur->y1 = pos.y; + break; + case 1: + cur->x2 = pos.x; + cur->y2 = pos.y; + break; + case 2: + cur->x3 = pos.x; + cur->y3 = pos.y; + break; + case 3: + cur->x4 = pos.x; + cur->y4 = pos.y; + break; + } + return; + } + i++; + } +} + + +////////////////////////////////////// +// Gets a list of points in the curve +void Spline::GetPointList(std::vector &points) { + // Prepare + points.clear(); + wxPoint pt; + bool isFirst = true; + + // Generate points for each curve + for (std::list::iterator cur = curves.begin();cur!=curves.end();cur++) { + // First point + if (isFirst) { + pt.x = cur->x1; + pt.y = cur->y1; + points.push_back(pt); + } + + // Line + if (cur->type == CURVE_LINE) { + pt.x = cur->x2; + pt.y = cur->y2; + points.push_back(pt); + } + + // Bicubic + else if (cur->type == CURVE_BICUBIC) { + // Get the control points + int x1 = cur->x1; + int x2 = cur->x2; + int x3 = cur->x3; + int x4 = cur->x4; + int y1 = cur->y1; + int y2 = cur->y2; + int y3 = cur->y3; + int y4 = cur->y4; + + // Hardcoded at 10 steps for now + int steps = 10; + for (int i=0;i +#include +#include + + +/////////////// +// Curve types +enum CurveType { + CURVE_INVALID, + CURVE_POINT, + CURVE_LINE, + CURVE_BICUBIC +}; + + +//////////////// +// Spline curve +class SplineCurve { +public: + int x1,y1; + int x2,y2; + int x3,y3; + int x4,y4; + CurveType type; + + SplineCurve(); +}; + + +///////////////////////// +// Spline managing class +class Spline { +private: + std::list curves; + +public: + Spline(); + + wxString EncodeToASS(); + void DecodeFromASS(wxString str); + + void AppendCurve(SplineCurve &curve); + void MovePoint(int curveIndex,int point,wxPoint pos); + + void GetPointList(std::vector &points); + + wxPoint GetClosestPoint(wxPoint reference); + wxPoint GetClosestControlPoint(wxPoint reference); +}; diff --git a/aegisub/visual_tool_cross.cpp b/aegisub/visual_tool_cross.cpp index 5871ad5d2..0c305c4b5 100644 --- a/aegisub/visual_tool_cross.cpp +++ b/aegisub/visual_tool_cross.cpp @@ -91,6 +91,7 @@ void VisualToolCross::Draw() { glDisable(GL_LINE_SMOOTH); glEnable(GL_COLOR_LOGIC_OP); glLogicOp(GL_INVERT); + glLineWidth(1); glBegin(GL_LINES); glColor3f(1.0f,1.0f,1.0f); glVertex2f(0,my);