diff --git a/p-designer/ass_drawing.cpp b/p-designer/ass_drawing.cpp new file mode 100644 index 000000000..1f9901e7d --- /dev/null +++ b/p-designer/ass_drawing.cpp @@ -0,0 +1,194 @@ +// Copyright (c) 2006, Niels Martin Hansen +// 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. + +#include "ass_drawing.h" +#include + + +// Point Four on the roadmap: code the ToString function + +wxString AssDrawing::ToString() +{ + return wxString(_T("")); +} + + +// Point Two on the roadmap: code the FromString function +// "Steal" some ideas from RTS.cpp :P + +// Attempt to read a point from string src. +// On success: Add point to target, "eat" point from src, increase where by chars eaten, return true. +// Assume first char is a non-space +static bool ReadPoint(wxString &src, int &where, std::vector &target) +{ + AssDrawingPoint p; + + int i = 0; + bool isneg = false; + + // Check for negativity + if (src[i] == '+') isneg = false, i++; + if (src[i] == '-') isneg = true, i++; + + // Faster exit for non-digit things + if (!isdigit(src[i])) return false; + + // This loop should terminate even if it hits end of string, since isdigit('\0')==false + while (isdigit(src[i])) i++; + p.x = src.Mid(0, i).ToLong(); + if (isneg) p.x = -p.x; + + // Error checking + if (!isspace(src[i])) return false; + + // Find start of next number + while (isspace(src[i])) i++; + + // Get second number + int j = i; + isneg = false; + if (src[j] == '+') isneg = false, j++; + if (src[j] == '-') isneg = true, j++; + while (isdigit(src[j])) j++; + p.y = src.Mid(j, j-i).ToLong(); + if (isneg) p.y = -p.y; + if (!isspace(src[j])) return false; + while (isspace(src[j])) j++; + + // Finish off + src = src.Mid(j); + target.push_back(p); + where += j; + return true; +} + +int AssDrawing::FromString(wxString src) +{ + data.clear(); + + // Counter for number of chars eaten + int where = 0; + + src.Trim(false); + + while (src.Len() > 0) { + AssDrawingSegment seg; + int i = 0; + + // Next character should be a letter, read it + switch (src[i]) { + case 'm': + seg.type = SEGMENT_MOVE; + break; + case 'n': + seg.type = SEGMENT_MOVE_NOCLOSE; + break; + case 'l': + seg.type = SEGMENT_LINE; + break; + case 'b': + seg.type = SEGMENT_BEZIER; + break; + case 's': + seg.type = SEGMENT_BSPLINE; + break; + case 'p': + seg.type = SEGMENT_BSPLINE_EXTEND; + break; + case 'c': + seg.type = SEGMENT_BSPLINE_CLOSE; + goto skippoints; + default: + // something unknown, stop parsing + return where+1; + } + where++, i++; + while (isspace(src[i])) where++, i++; + src = src.Mid(i); + while (ReadPoint(src, where, seg.points); +skippoints: + data.push_back(seg); + } + + return 0; +} + + +// These might be a bit redundant... save them for last + +void AssDrawing::Collapse() +{ + // TODO +} + +void AssDrawing::Expand() +{ + // TODO +} + + +// I suppose Rescale is just a matter of calculating the new scale, calling Stretch and setting the scale field + +void AssDrawing::Rescale(int new_scale) +{ + // TODO +} + +void AssDrawing::Stretch(float factor) +{ + // TODO +} + + +// A note on the following functions: +// According to VSFilter (last time I checked), the width and height of a drawing are calculated just by looking +// at the min and max X and Y values that appear in the drawing string. This is technically wrong (because of +// splines, those do funny things) but better do as the Romans do. + +AssDrawingPoint AssDrawing::GetMinXY() +{ + // TODO + return AssDrawingPoint(0, 0); +} + +AssDrawingPoint AssDrawing::GetMaxXY() +{ + // TODO + return AssDrawingPoint(0, 0); +} + +AssDrawingPoint AssDrawing::GetExtents() +{ + // TODO + return AssDrawingPoint(0, 0); +} + +AssDrawingPoint AssDrawing::GetCenterXY() +{ + // TODO + return AssDrawingPoint(0, 0); +} diff --git a/p-designer/ass_drawing.h b/p-designer/ass_drawing.h index 1e8237d7a..91acc984e 100644 --- a/p-designer/ass_drawing.h +++ b/p-designer/ass_drawing.h @@ -35,18 +35,19 @@ #include enum AssDrawingSegmentType { - SEGMENT_MOVE, // m - SEGMENT_MOVE_NOCLOSE, // n - SEGMENT_LINE, // l - SEGMENT_BEZIER, // b - SEGMENT_SPLINE, // s [... ] - SEGMENT_SPLINE_EXTEND, // p - SEGMENT_SPLINE_CLOSE, // c - // thought: maybe join the three last into one? + SEGMENT_MOVE, // m + SEGMENT_MOVE_NOCLOSE, // n + SEGMENT_LINE, // l + SEGMENT_BEZIER, // b + SEGMENT_BSPLINE, // s [... ] + SEGMENT_BSPLINE_EXTEND, // p + SEGMENT_BSPLINE_CLOSE, // c + // thought: maybe join the three last into one? (gabest doesn't) }; struct AssDrawingPoint { int x, y; + AssDrawingPoint(int _x, int _y) { x = _x; y = _y; } }; struct AssDrawingSegment { @@ -59,13 +60,18 @@ struct AssDrawing { std::vector data; wxString ToString(); // stupid conversion to string, doesn't try to shorten things out - int FromString(wxString &src); // returns 0 on success, index+1 of offending character on fail + int FromString(wxString src); // returns 0 on success, index+1 of offending character on fail void Collapse(); // try to join as many segments together as possible, without affecting the actual shape (eg. join "l 1 2 l 3 4" into "l 1 2 3 4") void Expand(); // split into as many segments as possible, without creating any meaningless ones, such as null-moves (ie. expand "l 1 2 3 4" into "l 1 2 l 3 4") void Rescale(int new_scale); // change the scale value, stretching the drawing to match the new one void Stretch(float factor); // up/down scale the drawing by a factor + + AssDrawingPoint GetMinXY(); // get the lowest x and y coordinates present + AssDrawingPoint GetMaxXY(); // get the highest x and y coordinates present + AssDrawingPoint GetExtents(); // get the extents of the drawing as seen by VSFilter + AssDrawingPoint GetCenterXY(); // get the "center" of the drawing (as seen by VSFilter) }; #endif diff --git a/p-designer/p-designer.vcproj b/p-designer/p-designer.vcproj index ce795a837..3219b7ced 100644 --- a/p-designer/p-designer.vcproj +++ b/p-designer/p-designer.vcproj @@ -15,11 +15,11 @@ OutputDirectory="Debug" IntermediateDirectory="Debug" ConfigurationType="1" - CharacterSet="2"> + CharacterSet="1"> + CharacterSet="1"> + +