// 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 Project http://www.aegisub.org/ // // $Id$ /// @file visual_tool_rotatez.cpp /// @brief 2D rotation in Z axis visual typesetting tool /// @ingroup visual_ts #include "config.h" #ifndef AGI_PRE #include #endif #include "ass_dialogue.h" #include "ass_file.h" #include "subs_edit_box.h" #include "subs_grid.h" #include "utils.h" #include "video_context.h" #include "video_display.h" #include "visual_tool_rotatez.h" static const float deg2rad = 3.1415926536f / 180.f; static const float rad2deg = 180.f / 3.1415926536f; VisualToolRotateZ::VisualToolRotateZ(VideoDisplay *parent, VideoState const& video, wxToolBar *) : VisualTool(parent, video) { DoRefresh(); } void VisualToolRotateZ::Draw() { if (!curDiag) return; // Draw pivot DrawAllFeatures(); int radius = (int)sqrt(double((posx-orgx)*(posx-orgx)+(posy-orgy)*(posy-orgy))); int oRadius = radius; if (radius < 50) radius = 50; int deltax = int(cos(curAngle*deg2rad)*radius); int deltay = int(-sin(curAngle*deg2rad)*radius); // Set colours SetLineColour(colour[0]); SetFillColour(colour[1],0.3f); // Set up the projection glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glTranslatef(orgx,orgy,-1.f); float matrix[16] = { 2500, 0, 0, 0, 0, 2500, 0, 0, 0, 0, 1, 1, 0, 0, 2500, 2500 }; glMultMatrixf(matrix); glScalef(1.f,1.f,8.f); glRotatef(ry,0.f,-1.f,0.f); glRotatef(rx,-1.f,0.f,0.f); glScalef(scaleX/100.f,scaleY/100.f,1.f); // Draw the circle DrawRing(0,0,radius+4,radius-4); // Draw markers around circle int markers = 6; float markStart = -90.f / markers; float markEnd = markStart+(180.f/markers); for (int i=0;i INT_MIN && video.y > INT_MIN) { SetLineColour(colour[0]); DrawLine(orgx,orgy,video.x,video.y); } } bool VisualToolRotateZ::InitializeHold() { startAngle = atan2(double(orgy-video.y),double(video.x-orgx)) * rad2deg; origAngle = curAngle; curDiag->StripTag(L"\\frz"); curDiag->StripTag(L"\\fr"); return true; } void VisualToolRotateZ::UpdateHold() { float screenAngle = atan2(double(orgy-video.y),double(video.x-orgx)) * rad2deg; curAngle = fmodf(screenAngle - startAngle + origAngle + 360.f, 360.f); // Oh Snap if (ctrlDown) { curAngle = floorf(curAngle/30.f+.5f)*30.f; if (curAngle > 359.f) curAngle = 0.f; } } void VisualToolRotateZ::CommitHold() { Selection sel = grid->GetSelectedSet(); for (Selection::const_iterator cur = sel.begin(); cur != sel.end(); ++cur) { SetOverride(*cur, L"\\frz",wxString::Format(L"(%0.3g)",curAngle)); } } void VisualToolRotateZ::PopulateFeatureList() { if (!curDiag) return; // Set features features.resize(1); VisualDraggableFeature &feat = features.back(); feat.x = orgx; feat.y = orgy; feat.line = curDiag; feat.type = DRAG_BIG_TRIANGLE; } void VisualToolRotateZ::UpdateDrag(VisualDraggableFeature* feature) { orgx = feature->x; orgy = feature->y; } void VisualToolRotateZ::CommitDrag(VisualDraggableFeature* feature) { int x = feature->x; int y = feature->y; parent->ToScriptCoords(&x, &y); SetOverride(feature->line, L"\\org",wxString::Format(L"(%i,%i)",x,y)); } void VisualToolRotateZ::DoRefresh() { if (!curDiag) return; GetLinePosition(curDiag, posx, posy, orgx, orgy); GetLineRotation(curDiag, rx, ry, curAngle); GetLineScale(curDiag, scaleX, scaleY); }