2011-11-06 18:18:20 +01:00
|
|
|
// Copyright (c) 2011, Thomas Goyne <plorkyeran@aegisub.org>
|
2007-01-08 22:11:06 +01:00
|
|
|
//
|
2011-11-06 18:18:20 +01:00
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
2007-01-08 22:11:06 +01:00
|
|
|
//
|
2011-11-06 18:18:20 +01:00
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2007-01-08 22:11:06 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
2007-01-08 22:11:06 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file visual_tool.h
|
|
|
|
/// @see visual_tool.cpp
|
|
|
|
/// @ingroup visual_ts
|
2007-01-08 22:11:06 +01:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2009-09-11 04:36:34 +02:00
|
|
|
#ifndef AGI_PRE
|
2011-11-06 18:18:20 +01:00
|
|
|
#include <deque>
|
2011-11-07 05:14:09 +01:00
|
|
|
#include <list>
|
2010-06-14 21:26:27 +02:00
|
|
|
#include <map>
|
2010-05-26 09:17:39 +02:00
|
|
|
#include <set>
|
2010-06-14 21:26:27 +02:00
|
|
|
#include <vector>
|
2009-09-11 04:36:34 +02:00
|
|
|
|
2007-09-12 01:22:26 +02:00
|
|
|
#include <wx/log.h>
|
2009-09-10 07:25:25 +02:00
|
|
|
#include <wx/event.h>
|
|
|
|
#include <wx/button.h>
|
2009-09-11 04:36:34 +02:00
|
|
|
#endif
|
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
#include <libaegisub/signal.h>
|
|
|
|
|
2007-01-21 07:30:19 +01:00
|
|
|
#include "gl_wrap.h"
|
2011-11-06 18:18:20 +01:00
|
|
|
#include "selection_controller.h"
|
|
|
|
#include "vector2d.h"
|
2007-01-21 07:30:19 +01:00
|
|
|
|
2007-01-08 22:11:06 +01:00
|
|
|
class AssDialogue;
|
2010-06-28 09:13:15 +02:00
|
|
|
class SubtitlesGrid;
|
2011-01-16 08:17:08 +01:00
|
|
|
class VideoDisplay;
|
2011-11-06 18:18:20 +01:00
|
|
|
class wxToolBar;
|
2010-06-04 05:07:33 +02:00
|
|
|
namespace agi {
|
2011-01-16 08:17:08 +01:00
|
|
|
struct Context;
|
2010-06-04 05:07:33 +02:00
|
|
|
class OptionValue;
|
|
|
|
}
|
2007-07-04 06:24:47 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
/// @class VisualToolBase
|
|
|
|
/// @brief Base class for visual tools containing all functionality that doesn't interact with features
|
|
|
|
///
|
|
|
|
/// This is required so that visual tools can be used polymorphically, as
|
|
|
|
/// different VisualTool<T>s are unrelated types otherwise. In addition, as much
|
|
|
|
/// functionality as possible is implemented here to avoid having four copies
|
|
|
|
/// of each method for no good reason (and four times as many error messages)
|
|
|
|
class VisualToolBase : protected SelectionListener<AssDialogue> {
|
|
|
|
std::deque<agi::signal::Connection> connections;
|
|
|
|
|
|
|
|
void OnCommit(int type);
|
|
|
|
void OnSeek(int new_frame);
|
|
|
|
|
|
|
|
void OnMouseCaptureLost(wxMouseCaptureLostEvent &);
|
|
|
|
|
|
|
|
/// @brief Get the dialogue line currently in the edit box
|
|
|
|
/// @return NULL if the line is not active on the current frame
|
|
|
|
AssDialogue *GetActiveDialogueLine();
|
|
|
|
|
|
|
|
// SubtitleSelectionListener implementation
|
|
|
|
void OnActiveLineChanged(AssDialogue *new_line);
|
|
|
|
void OnSelectedSetChanged(const Selection &lines_added, const Selection &lines_removed) { }
|
|
|
|
|
|
|
|
// Below here are the virtuals that must be implemented
|
|
|
|
|
|
|
|
/// Called when the script, video or screen resolutions change
|
|
|
|
virtual void OnCoordinateSystemsChanged() { DoRefresh(); }
|
|
|
|
|
|
|
|
/// Called when the file is changed by something other than a visual tool
|
|
|
|
virtual void OnFileChanged() { DoRefresh(); }
|
|
|
|
|
|
|
|
/// Called when the frame number changes
|
|
|
|
virtual void OnFrameChanged() { }
|
|
|
|
|
|
|
|
/// Called when the active line changes
|
|
|
|
virtual void OnLineChanged() { DoRefresh(); }
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
/// Generic refresh to simplify tools which have no interesting state and
|
|
|
|
/// can simply do do the same thing for any external change (i.e. most of
|
|
|
|
/// them). Called only by the above virtual methods.
|
|
|
|
virtual void DoRefresh() { }
|
2007-07-07 07:51:18 +02:00
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
protected:
|
2011-11-06 18:18:20 +01:00
|
|
|
OpenGLWrapper gl;
|
|
|
|
|
|
|
|
/// Called when the user double-clicks
|
|
|
|
virtual void OnDoubleClick() { }
|
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
static const wxColour colour[4];
|
2011-11-06 18:18:20 +01:00
|
|
|
|
|
|
|
agi::Context *c;
|
|
|
|
VideoDisplay *parent;
|
|
|
|
|
|
|
|
bool holding; ///< Is a hold currently in progress?
|
|
|
|
AssDialogue *active_line; ///< Active dialogue line; NULL if it is not visible on the current frame
|
|
|
|
bool dragging; ///< Is a drag currently in progress?
|
|
|
|
|
|
|
|
int frame_number; ///< Current frame number
|
|
|
|
|
|
|
|
bool left_click; ///< Is a left click event currently being processed?
|
|
|
|
bool left_double; ///< Is a left double click event currently being processed?
|
|
|
|
bool shift_down; ///< Is shift down?
|
|
|
|
bool ctrl_down; ///< Is ctrl down?
|
|
|
|
bool alt_down; ///< Is alt down?
|
|
|
|
|
|
|
|
Vector2D mouse_pos; ///< Last seen mouse position
|
|
|
|
Vector2D drag_start; ///< Mouse position at the beginning of the last drag
|
|
|
|
Vector2D script_res; ///< Script resolution
|
|
|
|
Vector2D video_pos; ///< Top-left corner of the video in the display area
|
|
|
|
Vector2D video_res; ///< Video resolution
|
|
|
|
|
|
|
|
agi::signal::Connection file_changed_connection;
|
|
|
|
int commit_id; ///< Last used commit id for coalescing
|
|
|
|
|
|
|
|
/// @brief Commit the current file state
|
|
|
|
/// @param message Description of changes for undo
|
|
|
|
void Commit(wxString message = "");
|
|
|
|
bool IsDisplayed(AssDialogue *line) const;
|
|
|
|
|
|
|
|
/// Get the line's position if it's set, or it's default based on style if not
|
|
|
|
Vector2D GetLinePosition(AssDialogue *diag);
|
|
|
|
/// Get the line's origin if it's set, or Vector2D::Bad() if not
|
|
|
|
Vector2D GetLineOrigin(AssDialogue *diag);
|
|
|
|
bool GetLineMove(AssDialogue *diag, Vector2D &p1, Vector2D &p2, int &t1, int &t2);
|
|
|
|
void GetLineRotation(AssDialogue *diag, float &rx, float &ry, float &rz);
|
|
|
|
void GetLineScale(AssDialogue *diag, Vector2D &scale);
|
|
|
|
void GetLineClip(AssDialogue *diag, Vector2D &p1, Vector2D &p2, bool &inverse);
|
|
|
|
wxString GetLineVectorClip(AssDialogue *diag, int &scale, bool &inverse);
|
|
|
|
|
|
|
|
void SetOverride(AssDialogue* line, wxString const& tag, wxString const& value);
|
|
|
|
void SetSelectedOverride(wxString const& tag, wxString const& value);
|
|
|
|
|
|
|
|
VisualToolBase(VideoDisplay *parent, agi::Context *context);
|
|
|
|
|
2010-05-20 10:55:46 +02:00
|
|
|
public:
|
2011-11-06 18:18:20 +01:00
|
|
|
/// Convert a point from video to script coordinates
|
|
|
|
Vector2D ToScriptCoords(Vector2D point) const;
|
|
|
|
/// Convert a point from script to video coordinates
|
|
|
|
Vector2D FromScriptCoords(Vector2D point) const;
|
|
|
|
|
|
|
|
// Stuff called by VideoDisplay
|
2010-05-20 10:55:46 +02:00
|
|
|
virtual void OnMouseEvent(wxMouseEvent &event)=0;
|
|
|
|
virtual void Draw()=0;
|
2011-11-06 18:18:20 +01:00
|
|
|
virtual void SetDisplayArea(int x, int y, int w, int h);
|
|
|
|
virtual void SetToolbar(wxToolBar *tb) { }
|
|
|
|
virtual ~VisualToolBase();
|
2010-05-20 10:55:46 +02:00
|
|
|
};
|
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @class VisualTool
|
2011-11-06 18:18:20 +01:00
|
|
|
/// @brief Visual tool base class containing all common feature-related functionality
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// DOCME
|
2010-05-20 10:55:46 +02:00
|
|
|
template<class FeatureType>
|
2011-11-06 18:18:20 +01:00
|
|
|
class VisualTool : public VisualToolBase {
|
2010-06-30 08:29:14 +02:00
|
|
|
protected:
|
2010-07-06 21:33:09 +02:00
|
|
|
typedef FeatureType Feature;
|
2010-06-30 08:29:14 +02:00
|
|
|
typedef typename std::list<FeatureType>::iterator feature_iterator;
|
|
|
|
typedef typename std::list<FeatureType>::const_iterator feature_const_iterator;
|
2010-11-01 05:36:13 +01:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
private:
|
|
|
|
struct ltaddr {
|
|
|
|
template<class T>
|
|
|
|
bool operator()(T lft, T rgt) const {
|
|
|
|
return &*lft < &*rgt;
|
|
|
|
}
|
|
|
|
};
|
2007-01-08 22:11:06 +01:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
std::list<agi::signal::Connection> slots;
|
2010-06-28 09:13:15 +02:00
|
|
|
|
2010-06-30 08:29:14 +02:00
|
|
|
typedef typename std::set<feature_iterator, ltaddr>::iterator selection_iterator;
|
2010-05-16 08:39:11 +02:00
|
|
|
|
2011-11-06 18:18:20 +01:00
|
|
|
bool sel_changed; /// Has the selection already been changed in the current click?
|
2010-06-28 09:13:15 +02:00
|
|
|
|
|
|
|
/// @brief Called when a hold is begun
|
|
|
|
/// @return Should the hold actually happen?
|
|
|
|
virtual bool InitializeHold() { return false; }
|
|
|
|
/// @brief Called on every mouse event during a hold
|
|
|
|
virtual void UpdateHold() { }
|
|
|
|
|
|
|
|
/// @brief Called at the beginning of a drag
|
|
|
|
/// @param feature The visual feature clicked on
|
|
|
|
/// @return Should the drag happen?
|
2010-06-30 08:29:14 +02:00
|
|
|
virtual bool InitializeDrag(feature_iterator feature) { return true; }
|
2010-06-28 09:13:15 +02:00
|
|
|
/// @brief Called on every mouse event during a drag
|
|
|
|
/// @param feature The current feature to process; not necessarily the one clicked on
|
2010-06-30 08:29:14 +02:00
|
|
|
virtual void UpdateDrag(feature_iterator feature) { }
|
2010-06-28 09:13:15 +02:00
|
|
|
|
|
|
|
/// @brief Draw stuff
|
|
|
|
virtual void Draw()=0;
|
|
|
|
|
2010-05-20 10:55:58 +02:00
|
|
|
protected:
|
2011-11-06 18:18:20 +01:00
|
|
|
std::set<feature_iterator, ltaddr> sel_features; ///< Currently selected visual features
|
2010-06-30 08:29:14 +02:00
|
|
|
typedef typename std::set<feature_iterator, ltaddr>::const_iterator sel_iterator;
|
2011-11-06 18:18:20 +01:00
|
|
|
|
|
|
|
/// Topmost feature under the mouse; generally only valid during a drag
|
|
|
|
feature_iterator active_feature;
|
|
|
|
/// List of features which are drawn and can be clicked on
|
|
|
|
/// List is used here for the iterator invalidation properties
|
|
|
|
std::list<FeatureType> features;
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2010-05-26 09:17:39 +02:00
|
|
|
/// Draw all of the features in the list
|
2007-07-01 09:09:37 +02:00
|
|
|
void DrawAllFeatures();
|
2010-06-28 09:13:15 +02:00
|
|
|
|
2010-05-26 09:17:39 +02:00
|
|
|
/// @brief Remove a feature from the selection
|
|
|
|
/// @param i Index in the feature list
|
|
|
|
/// Also deselects lines if all features for that line have been deselected
|
2010-06-30 08:29:14 +02:00
|
|
|
void RemoveSelection(feature_iterator feat);
|
2010-06-28 09:13:15 +02:00
|
|
|
|
|
|
|
/// @brief Set the selection to a single feature, deselecting everything else
|
|
|
|
/// @param i Index in the feature list
|
2011-11-06 18:18:20 +01:00
|
|
|
void SetSelection(feature_iterator feat, bool clear);
|
Remove the SelectionChangeSubscriber mechanism from the grid and implement some basic selection change notification through SelectionController.
Change SelectionListener interface so it receives the set of lines added and removed from selection, instead of just the complete new selection.
Update VisualTool<> to use SelectionListener to receive selection change notifications.
This change (temporarily, I hope) breaks feature selection in visual drag mode, when changing selection via the grid. This is caused by the grid selection change first clearing the entire selection, which sends a separate notification about selection clear. This causes the last visual feature to be deselected, and then the visual tool base reselects the active line, causing a new notification for selection to be sent. The active line happens to be the newly clicked line, and the selection notification enters during the externalChange guard being set, and is then ignored for feature update purposes. When control returns to the original SelectRow call in the grid, the line to be selected has already been selected and then nothing happens.
The best fix is to avoid two notifications being required to deselect all then reselect one line in the first place, so making the grid selection handling saner is the best fix.
Originally committed to SVN as r4602.
2010-06-26 06:38:02 +02:00
|
|
|
|
2007-01-08 22:11:06 +01:00
|
|
|
public:
|
2010-05-20 10:55:58 +02:00
|
|
|
/// @brief Handler for all mouse events
|
|
|
|
/// @param event Shockingly enough, the mouse event
|
2007-07-01 02:19:55 +02:00
|
|
|
void OnMouseEvent(wxMouseEvent &event);
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2010-05-20 10:55:58 +02:00
|
|
|
/// @brief Constructor
|
|
|
|
/// @param parent The VideoDisplay to use for coordinate conversion
|
|
|
|
/// @param video Video and mouse information passing blob
|
2011-11-06 18:18:20 +01:00
|
|
|
VisualTool(VideoDisplay *parent, agi::Context *context);
|
2007-01-08 22:11:06 +01:00
|
|
|
};
|