Simplify the VisualTool interface a bit.
Originally committed to SVN as r4318.
This commit is contained in:
parent
e023831134
commit
40a0c8994a
12 changed files with 115 additions and 169 deletions
|
@ -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();
|
||||
|
|
|
@ -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<VisualDraggableFeature> 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() {}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -64,8 +64,7 @@ private:
|
|||
|
||||
/// @brief DOCME
|
||||
///
|
||||
bool CanHold() { return true; }
|
||||
void InitializeHold();
|
||||
bool InitializeHold();
|
||||
void UpdateHold();
|
||||
void CommitHold();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue