From 40a0c8994aaa600fd3e056a8577db4bd46ee0763 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Thu, 20 May 2010 08:55:35 +0000 Subject: [PATCH] Simplify the VisualTool interface a bit. Originally committed to SVN as r4318. --- aegisub/src/visual_tool.cpp | 144 +++++++++++------------- aegisub/src/visual_tool.h | 49 ++------ aegisub/src/visual_tool_clip.cpp | 16 +-- aegisub/src/visual_tool_clip.h | 6 +- aegisub/src/visual_tool_rotatexy.cpp | 4 +- aegisub/src/visual_tool_rotatexy.h | 4 +- aegisub/src/visual_tool_rotatez.cpp | 4 +- aegisub/src/visual_tool_rotatez.h | 4 +- aegisub/src/visual_tool_scale.cpp | 4 +- aegisub/src/visual_tool_scale.h | 3 +- aegisub/src/visual_tool_vector_clip.cpp | 36 +++--- aegisub/src/visual_tool_vector_clip.h | 10 +- 12 files changed, 115 insertions(+), 169 deletions(-) diff --git a/aegisub/src/visual_tool.cpp b/aegisub/src/visual_tool.cpp index 7fb4cc0c4..f04015288 100644 --- a/aegisub/src/visual_tool.cpp +++ b/aegisub/src/visual_tool.cpp @@ -79,7 +79,7 @@ VisualTool::VisualTool(VideoDisplay *parent, VideoState const& video) frame_n = VideoContext::Get()->GetFrameN(); } - if (CanDrag()) PopulateFeatureList(); + PopulateFeatureList(); } /// @brief Destructor @@ -106,25 +106,72 @@ void VisualTool::OnMouseEvent (wxMouseEvent &event) { #endif altDown = event.m_altDown; - // Drag a feature - if (CanDrag()) { - if (!dragListOK) { - PopulateFeatureList(); - dragListOK = true; - } + if (!dragListOK) { + PopulateFeatureList(); + dragListOK = true; + } - // Click on feature - if (!dragging && leftClick && !DragEnabled()) { - curFeature = GetHighlightedFeature(); - if (curFeature != -1) { - ClickedFeature(features[curFeature]); + if (dragging) { + // continue drag + if (event.LeftIsDown()) { + features[curFeature].x = (video.x - dragStartX + dragOrigX); + features[curFeature].y = (video.y - dragStartY + dragOrigY); + if (shiftDown) { + if (abs(video.x - dragStartX) > abs(video.y - dragStartY)) { + features[curFeature].y = dragOrigY; + } + else { + features[curFeature].x = dragOrigX; + } + } + UpdateDrag(features[curFeature]); + + if (realTime) { + CommitDrag(features[curFeature]); + Commit(); } } + // end drag + else { + if (realTime) AssLimitToVisibleFilter::SetFrame(-1); - if (!dragging && leftClick && DragEnabled()) { - curFeature = GetHighlightedFeature(); - if (curFeature != -1) { - InitializeDrag(features[curFeature]); + dragging = false; + CommitDrag(features[curFeature]); + Commit(true); + + curFeature = -1; + parent->ReleaseMouse(); + parent->SetFocus(); + } + } + else if (holding) { + // continue hold + if (event.LeftIsDown()) { + UpdateHold(); + + if (realTime) { + CommitHold(); + Commit(); + } + } + // end hold + else { + if (realTime) AssLimitToVisibleFilter::SetFrame(-1); + + holding = false; + CommitHold(); + Commit(true); + + curDiag = NULL; + parent->ReleaseMouse(); + parent->SetFocus(); + } + } + else if (leftClick) { + curFeature = GetHighlightedFeature(); + // start drag + if (curFeature > -1) { + if (InitializeDrag(features[curFeature])) { if (features[curFeature].lineN != -1) { VideoContext::Get()->grid->editBox->SetToLine(features[curFeature].lineN,true); VideoContext::Get()->grid->SelectRow(features[curFeature].lineN); @@ -140,74 +187,15 @@ void VisualTool::OnMouseEvent (wxMouseEvent &event) { if (realTime) AssLimitToVisibleFilter::SetFrame(frame_n); } } - - if (dragging) { - if (event.LeftIsDown()) { - features[curFeature].x = (video.x - dragStartX + dragOrigX); - features[curFeature].y = (video.y - dragStartY + dragOrigY); - if (shiftDown) { - if (abs(video.x - dragStartX) > abs(video.y - dragStartY)) { - features[curFeature].y = dragOrigY; - } - else { - features[curFeature].x = dragOrigX; - } - } - UpdateDrag(features[curFeature]); - - if (realTime) { - CommitDrag(features[curFeature]); - Commit(); - } - } - else { - if (realTime) AssLimitToVisibleFilter::SetFrame(-1); - - dragging = false; - CommitDrag(features[curFeature]); - Commit(true); - - curFeature = -1; - parent->ReleaseMouse(); - parent->SetFocus(); - } - } - } - - // Hold - if (!dragging && CanHold()) { - if (!holding && event.LeftIsDown() && HoldEnabled()) { + // start hold + else { curDiag = GetActiveDialogueLine(); - if (curDiag) { - InitializeHold(); - + if (curDiag && InitializeHold()) { holding = true; parent->CaptureMouse(); if (realTime) AssLimitToVisibleFilter::SetFrame(frame_n); } } - - if (holding) { - if (event.LeftIsDown()) { - UpdateHold(); - - if (realTime) { - CommitHold(); - Commit(); - } - } - else { - if (realTime) AssLimitToVisibleFilter::SetFrame(-1); - - holding = false; - CommitHold(); - Commit(true); - - curDiag = NULL; - parent->ReleaseMouse(); - parent->SetFocus(); - } - } } Update(); diff --git a/aegisub/src/visual_tool.h b/aegisub/src/visual_tool.h index 9e217a8d5..aa3b372d3 100644 --- a/aegisub/src/visual_tool.h +++ b/aegisub/src/visual_tool.h @@ -66,6 +66,15 @@ struct VideoState; /// @brief DOCME /// DOCME class VisualTool : public OpenGLWrapper { +private: + /// DOCME + + /// DOCME + + /// DOCME + + /// DOCME + int dragStartX,dragStartY,dragOrigX,dragOrigY; int GetHighlightedFeature(); protected: /// DOCME @@ -89,15 +98,6 @@ protected: /// DOCME std::vector features; - /// DOCME - - /// DOCME - - /// DOCME - - /// DOCME - int dragStartX,dragStartY,dragOrigX,dragOrigY; - /// DOCME bool dragListOK; @@ -135,18 +135,8 @@ protected: void Commit(bool full=false); /// @brief DOCME - /// @return /// - virtual bool CanHold() { return false; } - - /// @brief DOCME - /// @return - /// - virtual bool HoldEnabled() { return true; } - - /// @brief DOCME - /// - virtual void InitializeHold() {} + virtual bool InitializeHold() { return false; } /// @brief DOCME /// @@ -158,23 +148,13 @@ protected: virtual void CommitHold() {} /// @brief DOCME - /// @return /// - virtual bool CanDrag() { return false; } - - /// @brief DOCME - /// @return - /// - virtual bool DragEnabled() { return true; } - - /// @brief DOCME - /// - virtual void PopulateFeatureList() { wxLogMessage(_T("wtf?")); } + virtual void PopulateFeatureList() { } /// @brief DOCME /// @param feature /// - virtual void InitializeDrag(VisualDraggableFeature &feature) {} + virtual bool InitializeDrag(VisualDraggableFeature &feature) { return true; } /// @brief DOCME /// @param feature @@ -186,11 +166,6 @@ protected: /// virtual void CommitDrag(VisualDraggableFeature &feature) {} - /// @brief DOCME - /// @param feature - /// - virtual void ClickedFeature(VisualDraggableFeature &feature) {} - /// @brief DOCME /// virtual void DoRefresh() {} diff --git a/aegisub/src/visual_tool_clip.cpp b/aegisub/src/visual_tool_clip.cpp index 49f05d26c..b340afff3 100644 --- a/aegisub/src/visual_tool_clip.cpp +++ b/aegisub/src/visual_tool_clip.cpp @@ -93,21 +93,16 @@ void VisualToolClip::Draw() { // Draw circles SetLineColour(colour[0]); SetFillColour(colour[1],0.5); - if (CanDrag()) DrawAllFeatures(); - else { - DrawCircle(dx1,dy1,4); - DrawCircle(dx2,dy1,4); - DrawCircle(dx2,dy2,4); - DrawCircle(dx1,dy2,4); - } + DrawAllFeatures(); } /// @brief Start holding -void VisualToolClip::InitializeHold() { +bool VisualToolClip::InitializeHold() { startX = video.x; startY = video.y; curDiag->StripTag(L"\\clip"); curDiag->StripTag(L"\\iclip"); + return true; } /// @brief Update hold @@ -129,7 +124,7 @@ void VisualToolClip::UpdateHold() { curY2 = MID(0,curY2,video.h); // Features - if (CanDrag()) PopulateFeatureList(); + PopulateFeatureList(); } /// @brief Commit hold @@ -191,10 +186,11 @@ void VisualToolClip::PopulateFeatureList() { /// @brief Initialize /// @param feature -void VisualToolClip::InitializeDrag(VisualDraggableFeature &feature) { +bool VisualToolClip::InitializeDrag(VisualDraggableFeature &feature) { curDiag = GetActiveDialogueLine(); curDiag->StripTag(L"\\clip"); curDiag->StripTag(L"\\iclip"); + return true; } /// @brief Update drag diff --git a/aegisub/src/visual_tool_clip.h b/aegisub/src/visual_tool_clip.h index d67a38436..4631ffcea 100644 --- a/aegisub/src/visual_tool_clip.h +++ b/aegisub/src/visual_tool_clip.h @@ -70,17 +70,15 @@ private: /// @brief DOCME /// @return /// - bool CanHold() { return true; } - void InitializeHold(); + bool InitializeHold(); void UpdateHold(); void CommitHold(); /// @brief DOCME /// - bool CanDrag() { return true; } void PopulateFeatureList(); - void InitializeDrag(VisualDraggableFeature &feature); + bool InitializeDrag(VisualDraggableFeature &feature); void UpdateDrag(VisualDraggableFeature &feature); void CommitDrag(VisualDraggableFeature &feature); diff --git a/aegisub/src/visual_tool_rotatexy.cpp b/aegisub/src/visual_tool_rotatexy.cpp index 06fb0e308..1032a09a6 100644 --- a/aegisub/src/visual_tool_rotatexy.cpp +++ b/aegisub/src/visual_tool_rotatexy.cpp @@ -166,7 +166,7 @@ void VisualToolRotateXY::Draw() { } /// @brief Start holding -void VisualToolRotateXY::InitializeHold() { +bool VisualToolRotateXY::InitializeHold() { GetLinePosition(curDiag,odx,ody,orgx,orgy); GetLineRotation(curDiag,origAngleX,origAngleY,rz); startAngleX = (orgy-video.x)*2.0; @@ -175,6 +175,8 @@ void VisualToolRotateXY::InitializeHold() { curAngleY = origAngleY; curDiag->StripTag(L"\\frx"); curDiag->StripTag(L"\\fry"); + + return true; } /// @brief Update hold diff --git a/aegisub/src/visual_tool_rotatexy.h b/aegisub/src/visual_tool_rotatexy.h index ee8c9758c..ce56de478 100644 --- a/aegisub/src/visual_tool_rotatexy.h +++ b/aegisub/src/visual_tool_rotatexy.h @@ -72,15 +72,13 @@ private: /// @brief DOCME /// @return /// - bool CanHold() { return true; } - void InitializeHold(); + bool InitializeHold(); void UpdateHold(); void CommitHold(); /// @brief DOCME /// - bool CanDrag() { return true; } void PopulateFeatureList(); void UpdateDrag(VisualDraggableFeature &feature); void CommitDrag(VisualDraggableFeature &feature); diff --git a/aegisub/src/visual_tool_rotatez.cpp b/aegisub/src/visual_tool_rotatez.cpp index 212c47b4b..fd05bbe73 100644 --- a/aegisub/src/visual_tool_rotatez.cpp +++ b/aegisub/src/visual_tool_rotatez.cpp @@ -151,13 +151,15 @@ void VisualToolRotateZ::Draw() { } /// @brief Start holding -void VisualToolRotateZ::InitializeHold() { +bool VisualToolRotateZ::InitializeHold() { GetLinePosition(curDiag,odx,ody,orgx,orgy); startAngle = atan2(double(orgy-video.y),double(video.x-orgx)) * 180.0 / 3.1415926535897932; GetLineRotation(curDiag,rx,ry,origAngle); curAngle = origAngle; curDiag->StripTag(L"\\frz"); curDiag->StripTag(L"\\fr"); + + return true; } /// @brief Update hold diff --git a/aegisub/src/visual_tool_rotatez.h b/aegisub/src/visual_tool_rotatez.h index 571e52ac1..d23483dfa 100644 --- a/aegisub/src/visual_tool_rotatez.h +++ b/aegisub/src/visual_tool_rotatez.h @@ -70,15 +70,13 @@ private: /// @brief DOCME /// @return /// - bool CanHold() { return true; } - void InitializeHold(); + bool InitializeHold(); void UpdateHold(); void CommitHold(); /// @brief DOCME /// - bool CanDrag() { return true; } void PopulateFeatureList(); void UpdateDrag(VisualDraggableFeature &feature); void CommitDrag(VisualDraggableFeature &feature); diff --git a/aegisub/src/visual_tool_scale.cpp b/aegisub/src/visual_tool_scale.cpp index ef07a315f..ff1747df0 100644 --- a/aegisub/src/visual_tool_scale.cpp +++ b/aegisub/src/visual_tool_scale.cpp @@ -124,7 +124,7 @@ void VisualToolScale::Draw() { } /// @brief Start holding -void VisualToolScale::InitializeHold() { +bool VisualToolScale::InitializeHold() { startX = video.x; startY = video.y; GetLineScale(curDiag,origScaleX,origScaleY); @@ -132,6 +132,8 @@ void VisualToolScale::InitializeHold() { curScaleY = origScaleY; curDiag->StripTag(_T("\\fscx")); curDiag->StripTag(_T("\\fscy")); + + return true; } /// @brief Update hold diff --git a/aegisub/src/visual_tool_scale.h b/aegisub/src/visual_tool_scale.h index 51d2ec8b8..cccb51672 100644 --- a/aegisub/src/visual_tool_scale.h +++ b/aegisub/src/visual_tool_scale.h @@ -64,8 +64,7 @@ private: /// @brief DOCME /// - bool CanHold() { return true; } - void InitializeHold(); + bool InitializeHold(); void UpdateHold(); void CommitHold(); diff --git a/aegisub/src/visual_tool_vector_clip.cpp b/aegisub/src/visual_tool_vector_clip.cpp index da85dbe12..c65933f0f 100644 --- a/aegisub/src/visual_tool_vector_clip.cpp +++ b/aegisub/src/visual_tool_vector_clip.cpp @@ -262,12 +262,6 @@ void VisualToolVectorClip::PopulateFeatureList() { } } -/// @brief Can drag? -/// @return -bool VisualToolVectorClip::DragEnabled() { - return mode <= 4; -} - /// @brief Update /// @param feature void VisualToolVectorClip::UpdateDrag(VisualDraggableFeature &feature) { @@ -283,7 +277,7 @@ void VisualToolVectorClip::CommitDrag(VisualDraggableFeature &feature) { /// @brief Clicked a feature /// @param feature /// @return -void VisualToolVectorClip::ClickedFeature(VisualDraggableFeature &feature) { +bool VisualToolVectorClip::InitializeDrag(VisualDraggableFeature &feature) { // Delete a control point if (mode == 5) { int i = 0; @@ -301,21 +295,16 @@ void VisualToolVectorClip::ClickedFeature(VisualDraggableFeature &feature) { CommitDrag(feature); curFeature = -1; Commit(true); - return; + return false; } } } -} - -/// @brief Can hold? -/// @return -bool VisualToolVectorClip::HoldEnabled() { - return mode <= 4 || mode == 6 || mode == 7; + return true; } /// @brief Initialize hold /// @return -void VisualToolVectorClip::InitializeHold() { +bool VisualToolVectorClip::InitializeHold() { // Insert line/bicubic if (mode == 1 || mode == 2) { SplineCurve curve; @@ -338,10 +327,12 @@ void VisualToolVectorClip::InitializeHold() { // Insert spline.AppendCurve(curve); + UpdateHold(); + return true; } // Convert and insert - else if (mode == 3 || mode == 4) { + if (mode == 3 || mode == 4) { // Get closest point Vector2D pt; int curve; @@ -371,7 +362,7 @@ void VisualToolVectorClip::InitializeHold() { // Insert else { // Check if there is at least one curve to split - if (spline.curves.size() == 0) return; + if (spline.curves.size() == 0) return false; // Split the curve SplineCurve *c1 = spline.GetCurve(curve); @@ -393,15 +384,18 @@ void VisualToolVectorClip::InitializeHold() { // Commit SetOverride(GetActiveDialogueLine(), inverse ? L"\\iclip" : L"\\clip", L"(" + spline.EncodeToASS() + L")"); Commit(true); + return false; } // Freehand - else if (mode == 6 || mode == 7) { + if (mode == 6 || mode == 7) { features.clear(); spline.curves.clear(); - lastX = -100000; - lastY = -100000; + lastX = INT_MIN; + lastY = INT_MIN; + return true; } + return false; } /// @brief Update hold @@ -434,7 +428,7 @@ void VisualToolVectorClip::UpdateHold() { // Freehand if (mode == 6 || mode == 7) { - if (lastX != -100000 && lastY != -100000) { + if (lastX != INT_MIN && lastY != INT_MIN) { // See if distance is enough Vector2D delta(lastX-video.x,lastY-video.y); int len = (int)delta.Len(); diff --git a/aegisub/src/visual_tool_vector_clip.h b/aegisub/src/visual_tool_vector_clip.h index 8e29fda7b..71dadfbc5 100644 --- a/aegisub/src/visual_tool_vector_clip.h +++ b/aegisub/src/visual_tool_vector_clip.h @@ -68,21 +68,15 @@ private: /// @brief DOCME /// @return /// - bool CanHold() { return true; } - bool HoldEnabled(); - void InitializeHold(); + bool InitializeHold(); void UpdateHold(); void CommitHold(); - /// @brief DOCME - /// - bool CanDrag() { return true; } - bool DragEnabled(); void PopulateFeatureList(); void UpdateDrag(VisualDraggableFeature &feature); void CommitDrag(VisualDraggableFeature &feature); - void ClickedFeature(VisualDraggableFeature &feature); + bool InitializeDrag(VisualDraggableFeature &feature); void DoRefresh();